90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
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")
|
|
}
|
|
}
|