Unify XP progression and enable ability ranks
This commit is contained in:
@@ -46,7 +46,7 @@ func (w *World) restoreCrafting(c *Character) error {
|
||||
return errors.New("invalid crafting history")
|
||||
}
|
||||
for _, v := range c.View.Crafting {
|
||||
if v.XP < 0 || v.XP > 1000000000000 {
|
||||
if v.XP < 0 || v.XP > 10000000000000 {
|
||||
return errors.New("invalid crafting experience")
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func (w *World) AttemptCraft(c *Character, req p.CraftRequest) (p.CraftResult, e
|
||||
}
|
||||
}
|
||||
if w.AllowsXP() {
|
||||
progress.XP = min(int64(1000000000000), progress.XP+recipe.XP)
|
||||
progress.XP = min(int64(10000000000000), progress.XP+recipe.XP)
|
||||
c.View.Crafting[req.Profession] = progress
|
||||
c.View.Skills["crafting"] += w.Balance.SkillXpPerAction
|
||||
w.grantXP(c, w.Balance.Progression.CraftXP)
|
||||
|
||||
@@ -24,7 +24,7 @@ func stringValue(s *string) string {
|
||||
|
||||
func (w *World) restoreGathering(c *Character) error {
|
||||
for _, xp := range c.View.Skills {
|
||||
if xp < 0 || xp > 1000000000000 {
|
||||
if xp < 0 || xp > 10000000000000 {
|
||||
return errors.New("invalid persisted skill XP")
|
||||
}
|
||||
}
|
||||
@@ -107,20 +107,7 @@ func (w *World) refreshGathering(c *Character) {
|
||||
}
|
||||
for _, s := range w.Balance.Gathering.Skills {
|
||||
xp := max(0, c.View.Skills[s.ID])
|
||||
remaining := xp
|
||||
level := int64(1)
|
||||
for level < s.MaxLevel {
|
||||
cost := s.BaseXP + (level-1)*s.XPPerLevel
|
||||
if remaining < cost {
|
||||
break
|
||||
}
|
||||
remaining -= cost
|
||||
level++
|
||||
}
|
||||
next := s.BaseXP + (level-1)*s.XPPerLevel - remaining
|
||||
if level == s.MaxLevel {
|
||||
next = 0
|
||||
}
|
||||
level, next := content.SkillLevel(s, xp)
|
||||
lv := value(s.ID, "gatheringLevel", float64(level), 1, 10000)
|
||||
c.View.Gathering[s.ID] = p.SkillProgress{Name: s.Name, XP: xp, Level: level, XPToNextLevel: next, EffectiveLevel: int64(math.Floor(lv.Final)), LevelValue: lv, Yield: value(s.ID, "gatheringYield", c.View.Stats["gatherRate"].Final, 0, 100000), Speed: value(s.ID, "gatheringSpeed", 100, 10, 1000), Experience: value(s.ID, "gatheringXP", c.View.Stats["xpGain"].Final, 0, 100000)}
|
||||
}
|
||||
@@ -231,9 +218,9 @@ func (w *World) gather(c *Character, target string) error {
|
||||
}
|
||||
}
|
||||
xp := int64(math.Min(1000000000, float64(r.XP)*c.View.Gathering[r.SkillID].Experience.Final/100))
|
||||
c.View.Skills[r.SkillID] = min(int64(1000000000000), c.View.Skills[r.SkillID]+xp)
|
||||
c.View.Skills[r.SkillID] = min(int64(10000000000000), c.View.Skills[r.SkillID]+xp)
|
||||
// Keep the legacy aggregate for existing title predicates, never as a level.
|
||||
c.View.Skills["gathering"] = min(int64(1000000000000), c.View.Skills["gathering"]+w.Balance.SkillXpPerAction)
|
||||
c.View.Skills["gathering"] = min(int64(10000000000000), c.View.Skills["gathering"]+w.Balance.SkillXpPerAction)
|
||||
w.Depleted[target] = w.Age() + r.RespawnSeconds
|
||||
label := output
|
||||
if r.Output == "self" {
|
||||
|
||||
@@ -139,7 +139,7 @@ func TestGatheringProgressAndEffectsTravel(t *testing.T) {
|
||||
if err := dest.Import(c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.View.Skills["miner"] != 90 || c.View.Gathering["miner"].Level != 4 || c.View.Gathering["miner"].EffectiveLevel != 9 || c.DailySeconds != 123 || c.View.GatheringEffects[0].ExpiresAt != expiry {
|
||||
if c.View.Skills["miner"] != 90 || c.View.Gathering["miner"].Level != 1 || c.View.Gathering["miner"].EffectiveLevel != 6 || c.DailySeconds != 123 || c.View.GatheringEffects[0].ExpiresAt != expiry {
|
||||
t.Fatal("travel reset XP, usage, or renewed effects")
|
||||
}
|
||||
if err := dest.Connect(c.View.Entity.ID); err != nil {
|
||||
|
||||
@@ -59,7 +59,7 @@ func (w *World) restorePowers(c *Character) error {
|
||||
return errors.New("invalid learned power history")
|
||||
}
|
||||
for id, v := range c.View.Powers {
|
||||
if id != v.Definition.ID || v.XP < 0 || v.XP > 1000000000000 || !finiteCraft(v.ReadyAt) || v.Definition.BaseXP < 1 || v.Definition.XPPerLevel < 1 || v.Definition.MaxLevel < 1 || v.Definition.MaxLevel > 1000 {
|
||||
if id != v.Definition.ID || v.XP < 0 || v.XP > 10000000000000 || !finiteCraft(v.ReadyAt) || v.Definition.BaseXP < 1 || v.Definition.XPPerLevel < 1 || v.Definition.MaxLevel < 1 || v.Definition.MaxLevel > 1000 {
|
||||
return errors.New("invalid learned spell")
|
||||
}
|
||||
d := v.Definition
|
||||
@@ -76,7 +76,7 @@ func (w *World) restorePowers(c *Character) error {
|
||||
}
|
||||
}
|
||||
for _, v := range c.View.Weapons {
|
||||
if v.XP < 0 || v.XP > 1000000000000 {
|
||||
if v.XP < 0 || v.XP > 10000000000000 {
|
||||
return errors.New("invalid weapon XP")
|
||||
}
|
||||
}
|
||||
@@ -116,10 +116,13 @@ func (w *World) powerRequirements(c *Character, d p.PowerDefinition) bool {
|
||||
return true
|
||||
}
|
||||
func (w *World) acquirePower(c *Character, d content.PowerDefinition) {
|
||||
if d.Kind == "ability" && d.MaxLevel == 1 {
|
||||
d.MaxLevel = 1000
|
||||
}
|
||||
var definition p.PowerDefinition
|
||||
raw, _ := json.Marshal(d)
|
||||
_ = json.Unmarshal(raw, &definition)
|
||||
v := p.LearnedPower{Definition: definition, Level: 1, XPToNextLevel: d.BaseXP}
|
||||
v := p.LearnedPower{Definition: definition, Level: 1, XPToNextLevel: content.XPForLevel(2)}
|
||||
for _, a := range w.Balance.Combat.Attacks {
|
||||
if a.ID == d.AttackID {
|
||||
v.Attack = protocolAttack(a)
|
||||
@@ -215,15 +218,15 @@ func (w *World) awardCombatCredit(shot Projectile) {
|
||||
credit.Rewarded = true
|
||||
if credit.Power != "" {
|
||||
v, ok := c.View.Powers[credit.Power]
|
||||
if ok && v.Definition.Kind == "spell" {
|
||||
v.XP = min(int64(1000000000000), v.XP+w.Balance.Powers.SpellXP)
|
||||
if ok {
|
||||
v.XP = min(int64(10000000000000), v.XP+w.Balance.Powers.SpellXP)
|
||||
c.View.Powers[credit.Power] = v
|
||||
}
|
||||
}
|
||||
if credit.Weapon != "" {
|
||||
v, ok := c.View.Weapons[credit.Weapon]
|
||||
if ok {
|
||||
v.XP = min(int64(1000000000000), v.XP+w.Balance.Powers.WeaponXP)
|
||||
v.XP = min(int64(10000000000000), v.XP+w.Balance.Powers.WeaponXP)
|
||||
c.View.Weapons[credit.Weapon] = v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"aeternalis/server/content"
|
||||
p "aeternalis/server/internal/protocol"
|
||||
)
|
||||
|
||||
@@ -66,6 +67,9 @@ func (w *World) restoreProgression(c *Character) error {
|
||||
if c.View.Level < 1 || c.View.Level > c.Progression.MaxLevel || c.View.Experience < 0 || c.View.StatPoints < 0 {
|
||||
return errors.New("invalid persisted character progression")
|
||||
}
|
||||
if e := w.migrateXPCurve(c); e != nil {
|
||||
return e
|
||||
}
|
||||
c.View.ExperienceToNextLevel = c.nextLevelXP()
|
||||
if (c.View.ExperienceToNextLevel == 0 && c.View.Experience != 0) || (c.View.ExperienceToNextLevel > 0 && c.View.Experience >= c.View.ExperienceToNextLevel) {
|
||||
return errors.New("invalid persisted level XP")
|
||||
@@ -85,7 +89,7 @@ func (c *Character) nextLevelXP() int64 {
|
||||
if c.View.Level >= c.Progression.MaxLevel {
|
||||
return 0
|
||||
}
|
||||
return c.Progression.BaseXP + (c.View.Level-1)*c.Progression.XPPerLevel
|
||||
return content.XPForLevel(c.View.Level + 1)
|
||||
}
|
||||
|
||||
func (w *World) grantXP(c *Character, amount int64) {
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestLevelUpsBankPointsAndCap(t *testing.T) {
|
||||
t.Fatal("premature level")
|
||||
}
|
||||
w.grantXP(c, 151)
|
||||
if c.View.Level != 3 || c.View.Experience != 0 || c.View.StatPoints != 20 || c.View.ExperienceToNextLevel != 200 {
|
||||
if c.View.Level != 3 || c.View.Experience != 40 || c.View.StatPoints != 20 || c.View.ExperienceToNextLevel != 140 {
|
||||
t.Fatalf("multi-level award lost points or XP: %+v", c.View)
|
||||
}
|
||||
c.Progression.MaxLevel = 4
|
||||
@@ -110,7 +110,7 @@ func TestProgressionSurvivesRestartDeathAndTransfer(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded := restored.Characters[c.View.Entity.ID]
|
||||
if loaded.View.Level != 3 || loaded.View.Experience != 25 || loaded.View.StatPoints != 20 || !reflect.DeepEqual(loaded.View.Titles, c.View.Titles) {
|
||||
if loaded.View.Level != 3 || loaded.View.Experience != 65 || loaded.View.StatPoints != 20 || !reflect.DeepEqual(loaded.View.Titles, c.View.Titles) {
|
||||
t.Fatal("restart reset progression")
|
||||
}
|
||||
loaded.View.Entity.State = "eligible"
|
||||
@@ -123,12 +123,12 @@ func TestProgressionSurvivesRestartDeathAndTransfer(t *testing.T) {
|
||||
if err = destination.Import(loaded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if loaded.View.ExperienceToNextLevel != 200 || loaded.Progression.StatPointsPerLevel != 10 || loaded.DailySeconds != 123 || loaded.WorldKills != 0 || loaded.View.StatPoints != 20 || len(loaded.View.Titles) != 1 {
|
||||
if loaded.View.ExperienceToNextLevel != 140 || loaded.Progression.StatPointsPerLevel != 10 || loaded.DailySeconds != 123 || loaded.WorldKills != 0 || loaded.View.StatPoints != 20 || len(loaded.View.Titles) != 1 {
|
||||
t.Fatal("transfer altered progression, titles, or daily budget")
|
||||
}
|
||||
destination.kill(loaded, "test death")
|
||||
destination.grantXP(loaded, 1000)
|
||||
if loaded.View.StatPoints != 20 || loaded.View.Experience != 25 || len(loaded.View.Titles) != 1 {
|
||||
if loaded.View.StatPoints != 20 || loaded.View.Experience != 65 || len(loaded.View.Titles) != 1 {
|
||||
t.Fatal("death erased progression or allowed postmortem XP")
|
||||
}
|
||||
replacement, err := destination.Join(loaded.Account, "Replacement")
|
||||
@@ -252,7 +252,7 @@ func TestBossXPAndSurvivalMilestoneGrantedOnce(t *testing.T) {
|
||||
if err := w.Intent(c.View.Entity.ID, p.Intent{Op: "attack", Seq: 1, Target: "boss"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.BossKills != 1 || c.WorldsSurvived != 1 || offline.WorldsSurvived != 1 || dead.WorldsSurvived != 0 || c.View.Level != 4 || c.View.Experience != 50 || c.View.StatPoints != 30 {
|
||||
if c.BossKills != 1 || c.WorldsSurvived != 1 || offline.WorldsSurvived != 1 || dead.WorldsSurvived != 0 || c.View.Level != 4 || c.View.Experience != 150 || c.View.StatPoints != 30 {
|
||||
t.Fatal("incorrect boss progression")
|
||||
}
|
||||
if w.Intent(c.View.Entity.ID, p.Intent{Op: "attack", Seq: 2, Target: "boss"}) == nil {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
)
|
||||
|
||||
type Character struct {
|
||||
XPCurveVersion int `json:"xpCurveVersion"`
|
||||
PendingCast *PendingCast `json:"pendingCast,omitempty"`
|
||||
RevivalCorpse string `json:"revivalCorpse,omitempty"`
|
||||
RevivalAllowed bool `json:"revivalAllowed"`
|
||||
@@ -358,7 +359,7 @@ func (w *World) Join(account, name string) (*Character, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := &Character{Account: account, Day: w.now.UTC().Format(time.DateOnly), View: p.Character{Entity: p.Entity{ID: ID(), Kind: "player", Name: name, Position: pos, HP: w.Balance.PlayerHp, MaxHP: w.Balance.PlayerHp, State: "alive"}, Inventory: map[string]int64{}, Skills: map[string]int64{}, RemainingSeconds: w.Balance.DailyPlaySeconds}}
|
||||
c := &Character{XPCurveVersion: 1, Account: account, Day: w.now.UTC().Format(time.DateOnly), View: p.Character{Entity: p.Entity{ID: ID(), Kind: "player", Name: name, Position: pos, HP: w.Balance.PlayerHp, MaxHP: w.Balance.PlayerHp, State: "alive"}, Inventory: map[string]int64{}, Skills: map[string]int64{}, RemainingSeconds: w.Balance.DailyPlaySeconds}}
|
||||
if err := w.restoreProgression(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"aeternalis/server/content"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func (w *World) migrateXPCurve(c *Character) error {
|
||||
if c.XPCurveVersion == 1 {
|
||||
return nil
|
||||
}
|
||||
if c.XPCurveVersion != 0 {
|
||||
return errors.New("unsupported XP curve version")
|
||||
}
|
||||
if c.View.Level < c.Progression.MaxLevel {
|
||||
old := c.Progression.BaseXP + (c.View.Level-1)*c.Progression.XPPerLevel
|
||||
if c.View.Experience >= old {
|
||||
return errors.New("invalid legacy level XP")
|
||||
}
|
||||
c.View.Experience = content.RebaseLevelXP(c.View.Experience, old, content.XPForLevel(c.View.Level+1))
|
||||
}
|
||||
valid := func(xp int64) bool { return xp >= 0 && xp <= 1000000000000 }
|
||||
if w.Balance.Gathering != nil {
|
||||
for _, s := range w.Balance.Gathering.Skills {
|
||||
xp := c.View.Skills[s.ID]
|
||||
if !valid(xp) {
|
||||
return errors.New("invalid legacy skill XP")
|
||||
}
|
||||
if xp > 0 {
|
||||
c.View.Skills[s.ID] = content.RebaseSkillXP(s, xp)
|
||||
}
|
||||
}
|
||||
}
|
||||
if w.Balance.Crafting != nil {
|
||||
for _, s := range w.Balance.Crafting.Professions {
|
||||
v, ok := c.View.Crafting[s.ID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if !valid(v.XP) {
|
||||
return errors.New("invalid legacy crafting XP")
|
||||
}
|
||||
v.XP = content.RebaseSkillXP(s, v.XP)
|
||||
c.View.Crafting[s.ID] = v
|
||||
}
|
||||
}
|
||||
if w.Balance.Powers != nil {
|
||||
for _, s := range w.Balance.Powers.Weapons {
|
||||
v, ok := c.View.Weapons[s.ID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if !valid(v.XP) {
|
||||
return errors.New("invalid legacy weapon XP")
|
||||
}
|
||||
v.XP = content.RebaseSkillXP(s, v.XP)
|
||||
c.View.Weapons[s.ID] = v
|
||||
}
|
||||
}
|
||||
for id, v := range c.View.Powers {
|
||||
d := v.Definition
|
||||
if !valid(v.XP) || d.BaseXP < 1 || d.XPPerLevel < 1 || d.MaxLevel < 1 || d.MaxLevel > 1000 {
|
||||
return errors.New("invalid legacy power XP")
|
||||
}
|
||||
v.XP = content.RebaseSkillXP(content.GatheringSkill{BaseXP: d.BaseXP, XPPerLevel: d.XPPerLevel, MaxLevel: d.MaxLevel}, v.XP)
|
||||
if d.Kind == "ability" && d.MaxLevel == 1 {
|
||||
v.Definition.MaxLevel = 1000
|
||||
}
|
||||
c.View.Powers[id] = v
|
||||
}
|
||||
c.XPCurveVersion = 1
|
||||
w.dirty = true
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"aeternalis/server/content"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUniversalXPCurveAndLegacyMigration(t *testing.T) {
|
||||
for target, want := range map[int64]int64{2: 100, 3: 110, 4: 140, 5: 190, 10: 740, 100: 96140} {
|
||||
if got := content.XPForLevel(target); got != want {
|
||||
t.Fatal(target, got, want)
|
||||
}
|
||||
}
|
||||
w, c := fixture(t)
|
||||
c.XPCurveVersion = 0
|
||||
c.View.Level = 3
|
||||
c.View.Experience = 100
|
||||
c.View.StatPoints = 20
|
||||
c.View.PendingVitalChoices = 2
|
||||
c.View.Skills["miner"] = 110
|
||||
v := c.View.Crafting["builder"]
|
||||
v.XP = 175
|
||||
c.View.Crafting["builder"] = v
|
||||
weapon := c.View.Weapons["blades"]
|
||||
weapon.XP = 175
|
||||
c.View.Weapons["blades"] = weapon
|
||||
c.View.Inventory["book_mend"] = 1
|
||||
if e := w.LearnPower(c, "book_mend"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
power := c.View.Powers["mend"]
|
||||
power.XP = 175
|
||||
c.View.Powers["mend"] = power
|
||||
if e := w.restoreProgression(c); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
w.RefreshStats(c)
|
||||
if c.View.Level != 3 || c.View.Experience != 70 || c.View.StatPoints != 20 || c.View.PendingVitalChoices != 2 {
|
||||
t.Fatal("player migration changed level/rewards or lost half-level progress")
|
||||
}
|
||||
if c.View.Gathering["miner"].Level != 4 || c.View.Gathering["miner"].XPToNextLevel != 114 {
|
||||
t.Fatal("gathering migration", c.View.Gathering["miner"])
|
||||
}
|
||||
if c.View.Crafting["builder"].Level != 2 || c.View.Crafting["builder"].XPToNextLevel != 55 || c.View.Weapons["blades"].XP != 155 || c.View.Powers["mend"].XP != 155 {
|
||||
t.Fatal("tracks disagree on the shared curve")
|
||||
}
|
||||
before, _ := json.Marshal(c.View)
|
||||
if e := w.restoreProgression(c); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
w.RefreshStats(c)
|
||||
after, _ := json.Marshal(c.View)
|
||||
if string(before) != string(after) {
|
||||
t.Fatal("migration repeated on restore")
|
||||
}
|
||||
s := content.GatheringSkill{BaseXP: 20, XPPerLevel: 10, MaxLevel: 10000}
|
||||
xp := content.RebaseSkillXP(s, 1000000000000)
|
||||
if level, _ := content.SkillLevel(s, xp); level != 10000 || xp > 10000000000000 {
|
||||
t.Fatal("maximum rank migration overflow")
|
||||
}
|
||||
}
|
||||
func TestAbilityUsageLevelsAndSuppressesHubXP(t *testing.T) {
|
||||
w, c := fixture(t)
|
||||
d := w.Balance.Powers.Powers[len(w.Balance.Powers.Powers)-1]
|
||||
if d.Kind != "ability" {
|
||||
t.Fatal("ability fixture missing")
|
||||
}
|
||||
w.acquirePower(c, d)
|
||||
for range 21 {
|
||||
w.awardCombatCredit(Projectile{Source: c.View.Entity.ID, Player: true, Credit: &CombatCredit{Power: d.ID}})
|
||||
}
|
||||
if v := c.View.Powers[d.ID]; v.Level != 3 || v.XP != 210 || v.XPToNextLevel != 140 {
|
||||
t.Fatal("ability rank curve", v)
|
||||
}
|
||||
w.Kind = "hub"
|
||||
w.Phase = "hub"
|
||||
w.awardCombatCredit(Projectile{Source: c.View.Entity.ID, Player: true, Credit: &CombatCredit{Power: d.ID}})
|
||||
if c.View.Powers[d.ID].XP != 210 {
|
||||
t.Fatal("hub ability XP")
|
||||
}
|
||||
c.View.Entity.State = "dead"
|
||||
w.Kind = "survival"
|
||||
w.Phase = "gathering"
|
||||
w.awardCombatCredit(Projectile{Source: c.View.Entity.ID, Player: true, Credit: &CombatCredit{Power: d.ID}})
|
||||
if c.View.Powers[d.ID].XP != 210 {
|
||||
t.Fatal("dead ability XP")
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,14 @@ func decodeCatalog(version int64, raw string) (content.Catalog, error) {
|
||||
}
|
||||
catalog.RestoreFurniture(b)
|
||||
}
|
||||
if catalog.Powers != nil {
|
||||
for i := range catalog.Powers.Powers {
|
||||
d := &catalog.Powers.Powers[i]
|
||||
if d.Kind == "ability" && d.MaxLevel == 1 {
|
||||
d.MaxLevel = 1000
|
||||
}
|
||||
}
|
||||
}
|
||||
return catalog, catalog.Validate()
|
||||
}
|
||||
func (d *DB) Catalog(ctx context.Context) (content.Catalog, error) {
|
||||
|
||||
Reference in New Issue
Block a user