1package sim 2 3import ( 4 "math/rand/v2" 5 "slices" 6 7 "tinyadventure/internal/model" 8 "tinyadventure/internal/rng" 9) 10 11const ( 12 KindDamage = "damage" 13 KindAoE = "aoe" 14 KindHeal = "heal" 15 KindBuff = "buff" 16 KindDebuff = "debuff" 17 18 TargetEnemy = "enemy" 19 TargetAllEnemies = "all_enemies" 20 TargetAlly = "ally" 21 TargetAllAllies = "all_allies" 22 TargetSelf = "self" 23) 24 25const ( 26 Physical = "physical" 27 Poison = "poison" 28 Fire = "fire" 29 Frost = "frost" 30 Lightning = "lightning" 31 Holy = "holy" 32 Shadow = "shadow" 33) 34 35var Types = []string{Physical, Poison, Fire, Frost, Lightning, Holy, Shadow} 36 37var Elements = Types[1:] 38 39func usesAttack(t string) bool { return t == Physical || t == Poison } 40 41const StrikeID = "strike" 42 43const ( 44 strikePower, aoePower = 1.5, 0.7 45 strikeCD, aoeCD = 2, 3 46) 47 48var catalog = map[string]model.Ability{} 49 50func register(a model.Ability) { catalog[a.ID] = a } 51 52func damage(id, name, typ string) model.Ability { 53 return model.Ability{ID: id, Name: name, Kind: KindDamage, Type: typ, Power: strikePower, Cooldown: strikeCD, Target: TargetEnemy} 54} 55 56func area(id, name, typ string) model.Ability { 57 return model.Ability{ID: id, Name: name, Kind: KindAoE, Type: typ, Power: aoePower, Cooldown: aoeCD, Target: TargetAllEnemies} 58} 59 60func init() { 61 for _, a := range []model.Ability{ 62 {ID: StrikeID, Name: "Strike", Kind: KindDamage, Type: Physical, Power: 1.0, Target: TargetEnemy}, 63 damage("heavy-strike", "Heavy Strike", Physical), area("cleave", "Cleave", Physical), 64 damage("envenom", "Envenom", Poison), area("poison-cloud", "Poison Cloud", Poison), 65 damage("firebolt", "Firebolt", Fire), area("fireball", "Fireball", Fire), 66 damage("ice-lance", "Ice Lance", Frost), area("frost-nova", "Frost Nova", Frost), 67 damage("lightning-bolt", "Lightning Bolt", Lightning), area("chain-lightning", "Chain Lightning", Lightning), 68 damage("smite", "Smite", Holy), area("radiance", "Radiance", Holy), 69 damage("shadow-bolt", "Shadow Bolt", Shadow), area("shadow-wave", "Shadow Wave", Shadow), 70 {ID: "heal", Name: "Heal", Kind: KindHeal, Power: 1.6, Cooldown: 1, Target: TargetAlly}, 71 {ID: "prayer", Name: "Prayer", Kind: KindHeal, Power: 0.6, Cooldown: 3, Target: TargetAllAllies}, 72 {ID: "taunt", Name: "Taunt", Kind: KindDebuff, Cooldown: 2, Target: TargetAllEnemies}, 73 {ID: "rage", Name: "Rage", Kind: KindBuff, Power: 1, Cooldown: 2, Target: TargetSelf}, 74 {ID: "sneak", Name: "Sneak", Kind: KindBuff, Cooldown: 3, Target: TargetSelf}, 75 {ID: "dodge", Name: "Dodge", Kind: KindBuff, Cooldown: 2, Target: TargetSelf}, 76 {ID: "ward", Name: "Ward", Kind: KindBuff, Cooldown: 3, Target: TargetAllAllies}, 77 {ID: "rally", Name: "Rally", Kind: KindBuff, Power: 0.3, Cooldown: 3, Target: TargetAllAllies}, 78 {ID: "haste", Name: "Haste", Kind: KindBuff, Cooldown: 3, Target: TargetAlly}, 79 {ID: "mark", Name: "Mark", Kind: KindDebuff, Power: 0.3, Cooldown: 2, Target: TargetEnemy}, 80 } { 81 register(a) 82 } 83} 84 85func Lookup(id string) (model.Ability, bool) { 86 a, ok := catalog[id] 87 return a, ok 88} 89 90func mustAbility(id string) model.Ability { return catalog[id] } 91 92func Abilities(ids ...string) []model.Ability { 93 out := make([]model.Ability, len(ids)) 94 for i, id := range ids { 95 out[i] = mustAbility(id) 96 } 97 return out 98} 99 100func dealsDamage(id string) bool { 101 k := catalog[id].Kind 102 return k == KindDamage || k == KindAoE 103} 104 105func Draw(r *rand.Rand, pool []string, n int) []model.Ability { 106 ids := rng.Shuffled(r, pool)[:min(n, len(pool))] 107 if !slices.ContainsFunc(ids, dealsDamage) { 108 ids[len(ids)-1] = rng.Pick(r, slices.DeleteFunc(slices.Clone(pool), func(id string) bool { return !dealsDamage(id) })) 109 } 110 return Abilities(ids...) 111}