Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

fishroll.gno

1.21 Kb · 49 lines
 1package fishroll
 2
 3import (
 4	"crypto/sha256"
 5	"strconv"
 6)
 7
 8var (
 9	hpBase   = [6]int{100, 122, 148, 178, 214, 256}
10	biteBase = [6]int{24, 30, 37, 45, 54, 66}
11	spdBase  = [6]int{108, 104, 100, 96, 92, 88}
12	rarities = [6]string{"common", "uncommon", "rare", "epic", "legendary", "mythic"}
13	traits   = [3]string{"swift", "fang", "hide"}
14)
15
16func Version() string { return "roll-1" }
17
18func Roll(caller address, commitH int64, entropyH int64, id int) (rarity string, trait string, bite int, hp int, speed int) {
19	if id < 1 || commitH < 1 || entropyH != commitH+2 {
20		panic("roll")
21	}
22	raw := caller.String() + "|" + strconv.FormatInt(commitH, 10) + "|" + strconv.FormatInt(entropyH, 10) + "|" + strconv.Itoa(id)
23	sum := sha256.Sum256([]byte(raw))
24	n := (int(sum[0])<<8 | int(sum[1])) % 10000
25	tier := 0
26	if n == 0 {
27		tier = 5
28	} else if n < 4 {
29		tier = 4
30	} else if n < 14 {
31		tier = 3
32	} else if n < 54 {
33		tier = 2
34	} else if n < 254 {
35		tier = 1
36	}
37	kind := int(sum[2]) % 3
38	bite = biteBase[tier]
39	hp = hpBase[tier]
40	speed = spdBase[tier]
41	if kind == 0 {
42		speed = (speed*112 + 50) / 100
43	} else if kind == 1 {
44		bite = (bite*112 + 50) / 100
45	} else {
46		hp = (hp*112 + 50) / 100
47	}
48	return rarities[tier], traits[kind], bite, hp, speed
49}