183 lines
6.5 KiB
Go
183 lines
6.5 KiB
Go
package content
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
)
|
|
|
|
// Powers reuse combat attacks. Knowledge is copied on acquisition; later catalog
|
|
// publications cannot rewrite a learned spell or weapon ability.
|
|
type PowerDefinition struct {
|
|
BasePower float64 `json:"basePower" yaml:"basePower"`
|
|
ID string `json:"id" yaml:"id"`
|
|
Name string `json:"name" yaml:"name"`
|
|
Description string `json:"description" yaml:"description"`
|
|
Kind string `json:"kind" yaml:"kind"`
|
|
AttackID string `json:"attackId" yaml:"attackId"`
|
|
Targeting string `json:"targeting" yaml:"targeting"`
|
|
Resurrection bool `json:"resurrection" yaml:"resurrection"`
|
|
Weapon string `json:"weapon" yaml:"weapon"`
|
|
WeaponLevel int64 `json:"weaponLevel" yaml:"weaponLevel"`
|
|
Requirements ItemRequirements `json:"requirements" yaml:"requirements"`
|
|
Parents map[string]int64 `json:"parents" yaml:"parents"`
|
|
Book bool `json:"book" yaml:"book"`
|
|
Mana float64 `json:"mana" yaml:"mana"`
|
|
CastSeconds float64 `json:"castSeconds" yaml:"castSeconds"`
|
|
Cooldown float64 `json:"cooldown" yaml:"cooldown"`
|
|
RankScaling float64 `json:"rankScaling" yaml:"rankScaling"`
|
|
BaseXP int64 `json:"baseXp" yaml:"baseXp"`
|
|
XPPerLevel int64 `json:"xpPerLevel" yaml:"xpPerLevel"`
|
|
MaxLevel int64 `json:"maxLevel" yaml:"maxLevel"`
|
|
}
|
|
type PowerContent struct {
|
|
Weapons []GatheringSkill `json:"weapons" yaml:"weapons"`
|
|
Powers []PowerDefinition `json:"powers" yaml:"powers"`
|
|
WeaponXP int64 `json:"weaponXp" yaml:"weaponXp"`
|
|
SpellXP int64 `json:"spellXp" yaml:"spellXp"`
|
|
RevivalRange float64 `json:"revivalRange" yaml:"revivalRange"`
|
|
RevivalHealth float64 `json:"revivalHealth" yaml:"revivalHealth"`
|
|
}
|
|
|
|
func (c Catalog) PowerItems() map[string]string {
|
|
out := map[string]string{"revival_stone": "Revival stone"}
|
|
if c.Powers != nil {
|
|
for _, p := range c.Powers.Powers {
|
|
if p.Book {
|
|
out["book_"+p.ID] = p.Name + " spell book"
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
func (c Catalog) validatePowers() error {
|
|
v := c.Powers
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
if len(v.Powers) > 256 || len(v.Weapons) > 64 || v.WeaponXP < 1 || v.WeaponXP > 1000 || v.SpellXP < 1 || v.SpellXP > 1000 || !finiteRange(v.RevivalRange, 1, 5) || !finiteRange(v.RevivalHealth, .01, 1) {
|
|
return fmt.Errorf("invalid power content limits")
|
|
}
|
|
weapons := map[string]bool{}
|
|
for _, s := range v.Weapons {
|
|
if !validSetIdentity(s.ID, s.Name, s.Description) || weapons[s.ID] || s.BaseXP < 1 || s.BaseXP > 1000000 || s.XPPerLevel < 1 || s.XPPerLevel > 1000000 || s.MaxLevel < 1 || s.MaxLevel > 1000 {
|
|
return fmt.Errorf("invalid weapon profession")
|
|
}
|
|
weapons[s.ID] = true
|
|
}
|
|
attacks := map[string]CombatAttack{}
|
|
if c.Combat != nil {
|
|
for _, a := range c.Combat.Attacks {
|
|
attacks[a.ID] = a
|
|
}
|
|
}
|
|
powers := map[string]PowerDefinition{}
|
|
titles := map[string]bool{}
|
|
for _, t := range c.Titles {
|
|
titles[t.ID] = true
|
|
}
|
|
for _, p := range v.Powers {
|
|
if !validSetIdentity(p.ID, p.Name, p.Description) || powers[p.ID].ID != "" || !slices.Contains([]string{"spell", "ability"}, p.Kind) || !slices.Contains([]string{"target", "self", "aura"}, p.Targeting) || !finiteRange(p.BasePower, 0, 100000) || !finiteRange(p.Mana, 0, 10000) || !finiteRange(p.CastSeconds, 0, 30) || !finiteRange(p.Cooldown, .1, 120) || !finiteRange(p.RankScaling, 0, 1) || p.BaseXP < 1 || p.BaseXP > 1000000 || p.XPPerLevel < 1 || p.XPPerLevel > 1000000 || p.MaxLevel < 1 || p.MaxLevel > 1000 || len(p.Parents) > 16 {
|
|
return fmt.Errorf("invalid spell/ability %q", p.Name)
|
|
}
|
|
if p.Resurrection {
|
|
if p.Kind != "spell" || p.Targeting != "target" || p.AttackID != "" || p.CastSeconds != 0 {
|
|
return fmt.Errorf("resurrection requires an instant corpse-targeted spell")
|
|
}
|
|
} else {
|
|
a, ok := attacks[p.AttackID]
|
|
if !ok || (p.Targeting == "aura" && (a.Radius <= 0 || a.Duration <= 0 || a.Delivery != "melee")) || (p.Targeting == "self" && a.Effect != "heal") {
|
|
return fmt.Errorf("invalid power attack/targeting")
|
|
}
|
|
}
|
|
if p.Kind == "ability" {
|
|
if !weapons[p.Weapon] || p.WeaponLevel < 1 || p.WeaponLevel > 1000 || p.Book || len(p.Parents) > 0 {
|
|
return fmt.Errorf("ability requires a weapon proficiency")
|
|
}
|
|
} else if p.Weapon != "" || (!p.Book && len(p.Parents) == 0) {
|
|
return fmt.Errorf("spell requires a book or predecessor")
|
|
}
|
|
r := p.Requirements
|
|
if r.Level < 1 || r.Level > 1000 || len(r.Stats) > 32 || len(r.Titles) > 16 {
|
|
return fmt.Errorf("invalid power requirements")
|
|
}
|
|
for stat, n := range r.Stats {
|
|
if !KnownStat(stat) || !finiteRange(n, 0, 1000000) {
|
|
return fmt.Errorf("invalid power stat requirement")
|
|
}
|
|
}
|
|
for _, id := range r.Titles {
|
|
if !titles[id] {
|
|
return fmt.Errorf("unknown power title")
|
|
}
|
|
}
|
|
powers[p.ID] = p
|
|
}
|
|
for _, p := range v.Powers {
|
|
for id, rank := range p.Parents {
|
|
parent, ok := powers[id]
|
|
if !ok || parent.Kind != "spell" || rank < 1 || rank > parent.MaxLevel {
|
|
return fmt.Errorf("invalid spell unlock predecessor")
|
|
}
|
|
}
|
|
}
|
|
visiting, done := map[string]bool{}, map[string]bool{}
|
|
var visit func(string) bool
|
|
visit = func(id string) bool {
|
|
if visiting[id] {
|
|
return false
|
|
}
|
|
if done[id] {
|
|
return true
|
|
}
|
|
visiting[id] = true
|
|
for parent := range powers[id].Parents {
|
|
if !visit(parent) {
|
|
return false
|
|
}
|
|
}
|
|
visiting[id] = false
|
|
done[id] = true
|
|
return true
|
|
}
|
|
for id := range powers {
|
|
if !visit(id) {
|
|
return fmt.Errorf("spell unlock graph contains a cycle")
|
|
}
|
|
}
|
|
for _, i := range c.Items {
|
|
if i.WeaponType != "" && !weapons[i.WeaponType] {
|
|
return fmt.Errorf("unknown equipment weapon type")
|
|
}
|
|
if _, ok := c.PowerItems()[i.ID]; ok {
|
|
return fmt.Errorf("equipment conflicts with power item")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
func (c *Catalog) RestorePowers(b Balance) {
|
|
if c.Powers != nil {
|
|
return
|
|
}
|
|
c.Powers = b.Powers
|
|
if c.Combat == nil {
|
|
c.Combat = b.Combat
|
|
} else {
|
|
combat := *c.Combat
|
|
combat.Attacks = slices.Clone(combat.Attacks)
|
|
for _, seed := range b.Combat.Attacks {
|
|
if !slices.ContainsFunc(combat.Attacks, func(a CombatAttack) bool { return a.ID == seed.ID }) {
|
|
combat.Attacks = append(combat.Attacks, seed)
|
|
}
|
|
}
|
|
c.Combat = &combat
|
|
}
|
|
c.Items = slices.Clone(c.Items)
|
|
for i := range c.Items {
|
|
for _, seed := range b.Items {
|
|
if c.Items[i].ID == seed.ID {
|
|
c.Items[i].WeaponType = seed.WeaponType
|
|
}
|
|
}
|
|
}
|
|
}
|