Add spells, weapon abilities, and durable corpse resurrection

This commit is contained in:
dingo
2026-09-09 18:15:23 -04:00
parent b3c5482558
commit 897c5745bc
49 changed files with 2277 additions and 137 deletions
+9
View File
@@ -12,6 +12,10 @@ combat:
- { id: blast_shot, name: Blast shot, description: A projectile with a damage burst., delivery: projectile, effect: damage, stat: rangedDamage, multiplier: 1, range: 35, cooldown: 3, stamina: 8, speed: 25, dexteritySpeed: 0.1, strengthSpeed: 0.05, radius: 6, duration: 0, interval: 1 }
- { id: healing_field, name: Healing field, description: A projectile that creates a stationary healing area., delivery: projectile, effect: heal, stat: magicDamage, multiplier: 1, range: 30, cooldown: 8, stamina: 10, speed: 25, dexteritySpeed: 0.1, strengthSpeed: 0.05, radius: 6, duration: 5, interval: 1 }
- { id: sentinel_strike, name: Sentinel strike, description: Close range damage., delivery: melee, effect: damage, stat: meleeDamage, multiplier: 1, range: 3, cooldown: 1.8, stamina: 0, speed: 1, radius: 0, duration: 0, interval: 1 }
- {"id": "arc_bolt", "name": "Arc bolt", "description": "Arc bolt", "delivery": "projectile", "effect": "damage", "stat": "magicDamage", "multiplier": 1, "range": 30, "cooldown": 2, "stamina": 0, "speed": 25, "radius": 0, "duration": 0, "interval": 1}
- {"id": "mend", "name": "Mend", "description": "Mend", "delivery": "melee", "effect": "heal", "stat": "magicDamage", "multiplier": 1, "range": 30, "cooldown": 2, "stamina": 0, "speed": 25, "radius": 0, "duration": 0, "interval": 1}
- {"id": "renewal_aura", "name": "Renewal aura", "description": "Renewal aura", "delivery": "melee", "effect": "heal", "stat": "magicDamage", "multiplier": 1, "range": 30, "cooldown": 2, "stamina": 0, "speed": 25, "radius": 6, "duration": 8, "interval": 1}
- {"id": "cleave", "name": "Cleave", "description": "Cleave", "delivery": "melee", "effect": "damage", "stat": "meleeDamage", "multiplier": 1, "range": 3, "cooldown": 2, "stamina": 5, "speed": 25, "radius": 3, "duration": 0, "interval": 1}
mobs:
- { id: ash_guard, name: Ash guard, description: A territorial guardian., model: sentinel, behavior: aggressive, level: 1, hp: 54, damage: 6, defence: 0, speed: 4, aggroRange: 24, leashRange: 160, scalePerDay: 0.1, xp: 50, attackId: sentinel_strike, lootId: common_mob_loot }
loot:
@@ -188,6 +192,7 @@ stats:
luck: { criticalChance: 0.1, dropRate: 1, gatherRate: 1, dodgeChance: 0.1 }
items:
- id: knife
weaponType: blades
name: Knife
description: A starting close-combat weapon.
slot: weapon
@@ -195,6 +200,7 @@ items:
requirements: { level: 1, stats: {}, titles: [] }
modifiers: []
- id: spear
weaponType: polearms
craftRolls: 1
craftPool:
- { stat: meleeDamage, min: 1, max: 6, percent: false, weight: 2 }
@@ -238,3 +244,6 @@ crafting:
- {"id": "recipe_trap", "revision": 1, "name": "Trap parts", "description": "Starter trap parts recipe.", "profession": "trap_master", "level": 1, "xp": 20, "inputs": {"wood": 2, "ore": 1}, "outputs": {"trap_parts": 1}, "stats": {}, "titles": []}
- {"id": "recipe_ration", "revision": 1, "name": "Ration", "description": "Starter ration recipe.", "profession": "cook", "level": 1, "xp": 20, "inputs": {"herb": 3}, "outputs": {"ration": 1}, "stats": {}, "titles": []}
- {"id": "recipe_component", "revision": 1, "name": "Building component", "description": "Starter building component recipe.", "profession": "builder", "level": 1, "xp": 20, "inputs": {"wood": 4, "ore": 1}, "outputs": {"building_component": 1}, "stats": {}, "titles": []}
# Milestone 7 provisional progression and resurrection tuning.
powers: {"weapons": [{"id": "blades", "name": "Blades", "description": "Blades proficiency", "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000}, {"id": "polearms", "name": "Polearms", "description": "Polearms proficiency", "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000}], "powers": [{"id": "arc_bolt", "name": "Arc bolt", "description": "Arc bolt", "kind": "spell", "attackId": "arc_bolt", "targeting": "target", "resurrection": false, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {}, "book": true, "mana": 5, "castSeconds": 0.5, "cooldown": 2, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 10}, {"id": "mend", "name": "Mend", "description": "Mend", "kind": "spell", "attackId": "mend", "targeting": "target", "resurrection": false, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {}, "book": true, "mana": 5, "castSeconds": 0, "cooldown": 2, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 10}, {"id": "renewal", "name": "Renewal aura", "description": "Renewal aura", "kind": "spell", "attackId": "renewal_aura", "targeting": "aura", "resurrection": false, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {"mend": 2}, "book": false, "mana": 10, "castSeconds": 0, "cooldown": 10, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 10}, {"id": "revive", "name": "Resurrection", "description": "Resurrection", "kind": "spell", "attackId": "", "targeting": "target", "resurrection": true, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {}, "book": true, "mana": 20, "castSeconds": 0, "cooldown": 30, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 0}, {"id": "cleave", "name": "Cleave", "description": "Cleave", "kind": "ability", "attackId": "cleave", "targeting": "target", "resurrection": false, "weapon": "blades", "weaponLevel": 2, "requirements": {"level": 1, "stats": {"strength": 2}, "titles": []}, "parents": {}, "book": false, "mana": 0, "castSeconds": 0, "cooldown": 2, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1, "basePower": 0}], "weaponXp": 10, "spellXp": 10, "revivalRange": 3, "revivalHealth": 0.25}
+3
View File
@@ -129,6 +129,9 @@ func (c Catalog) validateCombat() error {
attacks[a.ID] = true
}
items := map[string]bool{}
for id := range c.PowerItems() {
items[id] = true
}
if c.Crafting != nil {
for _, m := range c.Crafting.Materials {
items[m.ID] = true
+6 -2
View File
@@ -19,6 +19,7 @@ type Recipe struct {
}
type Balance struct {
Powers *PowerContent `yaml:"powers"`
Crafting *CraftingContent `yaml:"crafting"`
Combat *CombatContent `yaml:"combat"`
CombatRules *CombatRules `yaml:"combatRules"`
@@ -81,7 +82,10 @@ func Parse(data []byte) (Balance, error) {
return b, b.Validate()
}
func (b Balance) Validate() error {
if err := (Catalog{Crafting: b.Crafting, Items: b.Items, Titles: b.Titles, Gathering: b.Gathering}).validateCrafting(); err != nil {
if err := (Catalog{Powers: b.Powers, Combat: b.Combat, Items: b.Items, Titles: b.Titles}).validatePowers(); err != nil {
return err
}
if err := (Catalog{Powers: b.Powers, Crafting: b.Crafting, Items: b.Items, Titles: b.Titles, Gathering: b.Gathering}).validateCrafting(); err != nil {
return err
}
if b.CombatRules != nil {
@@ -89,7 +93,7 @@ func (b Balance) Validate() error {
return err
}
}
if err := (Catalog{Crafting: b.Crafting, Combat: b.Combat, Items: b.Items, Gathering: b.Gathering}).validateCombat(); err != nil {
if err := (Catalog{Powers: b.Powers, Crafting: b.Crafting, Combat: b.Combat, Items: b.Items, Gathering: b.Gathering}).validateCombat(); err != nil {
return err
}
if b.Gathering != nil {
+3
View File
@@ -83,6 +83,9 @@ func SkillLevel(s GatheringSkill, xp int64) (int64, int64) {
}
func (c Catalog) StackIDs() map[string]bool {
ids := map[string]bool{}
for id := range c.PowerItems() {
ids[id] = true
}
for _, id := range []string{"axe", "flint_and_steel", "fishing_pole", "wood", "ore", "herb", "bandage", "escape_stone"} {
ids[id] = true
}
+182
View File
@@ -0,0 +1,182 @@
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
}
}
}
}
+34
View File
@@ -0,0 +1,34 @@
package content
import "testing"
func TestPowerCatalogValidation(t *testing.T) {
for _, mutate := range []func(*Catalog){
func(c *Catalog) { c.Powers.Powers[0].Parents = map[string]int64{"arc_bolt": 1} },
func(c *Catalog) { c.Powers.Powers[0].AttackID = "missing" },
func(c *Catalog) { c.Powers.Powers[0].Requirements.Stats = map[string]float64{"unknown": 1} },
func(c *Catalog) { c.Powers.Powers[4].Weapon = "missing" },
func(c *Catalog) { c.Powers.Powers[3].CastSeconds = 1 },
func(c *Catalog) { c.Powers.Powers[2].Parents = map[string]int64{"mend": 1001} },
} {
c, e := DefaultCatalog()
if e != nil {
t.Fatal(e)
}
mutate(&c)
if c.Validate() == nil {
t.Fatal("invalid power catalog accepted")
}
}
c, e := DefaultCatalog()
if e != nil {
t.Fatal(e)
}
c.Powers = nil
c.Combat.Attacks = c.Combat.Attacks[:4]
b, _ := Load()
c.RestorePowers(b)
if e = c.Validate(); e != nil {
t.Fatal("legacy catalog power upgrade failed", e)
}
}
+6 -1
View File
@@ -35,6 +35,7 @@ type ItemRequirements struct {
Titles []string `json:"titles" yaml:"titles"`
}
type ItemDefinition struct {
WeaponType string `json:"weaponType,omitempty" yaml:"weaponType"`
CraftPool []CraftStat `json:"craftPool,omitempty" yaml:"craftPool"`
CraftRolls int64 `json:"craftRolls,omitempty" yaml:"craftRolls"`
AttackID string `json:"attackId,omitempty" yaml:"attackId"`
@@ -48,6 +49,7 @@ type ItemDefinition struct {
Modifiers []StatModifier `json:"modifiers" yaml:"modifiers"`
}
type Catalog struct {
Powers *PowerContent `json:"powers,omitempty"`
Crafting *CraftingContent `json:"crafting,omitempty"`
Combat *CombatContent `json:"combat,omitempty"`
Gathering *GatheringContent `json:"gathering,omitempty"`
@@ -132,6 +134,9 @@ func (item ItemDefinition) Validate() error {
return ValidateModifiers(item.Modifiers)
}
func (c Catalog) Validate() error {
if err := c.validatePowers(); err != nil {
return err
}
if err := c.validateCrafting(); err != nil {
return err
}
@@ -210,5 +215,5 @@ func DefaultCatalog() (Catalog, error) {
if err != nil {
return Catalog{}, err
}
return Catalog{Crafting: b.Crafting, Combat: b.Combat, Gathering: b.Gathering, Version: 1, Titles: b.Titles, Items: b.Items, Stats: *b.Stats}, nil
return Catalog{Powers: b.Powers, Crafting: b.Crafting, Combat: b.Combat, Gathering: b.Gathering, Version: 1, Titles: b.Titles, Items: b.Items, Stats: *b.Stats}, nil
}