215 lines
6.2 KiB
Go
215 lines
6.2 KiB
Go
package game
|
|
|
|
import (
|
|
"aeternalis/server/content"
|
|
"encoding/json"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSpellBooksRanksAuraAndHubXP(t *testing.T) {
|
|
w, c := fixture(t)
|
|
c.View.Inventory["book_mend"] = 2
|
|
c.View.Mana = 100
|
|
if e := w.LearnPower(c, "book_mend"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if c.View.Powers["mend"].Level != 1 || c.View.Inventory["book_mend"] != 1 {
|
|
t.Fatal("book did not teach rank one exactly once")
|
|
}
|
|
if w.LearnPower(c, "book_mend") == nil || c.View.Inventory["book_mend"] != 1 {
|
|
t.Fatal("duplicate learning consumed book")
|
|
}
|
|
if e := w.CastPower(c, "mend", c.View.Entity.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if c.View.Powers["mend"].XP != 0 {
|
|
t.Fatal("full health healing gained XP")
|
|
}
|
|
for i := 0; i < 10; i++ {
|
|
w.now = w.now.Add(3 * time.Second)
|
|
c.View.Mana = 100
|
|
c.View.Entity.HP = 10
|
|
if e := w.CastPower(c, "mend", c.View.Entity.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
if c.View.Powers["mend"].Level != 2 || c.View.Powers["renewal"].Level != 1 {
|
|
t.Fatal("spell rank did not unlock successor", c.View.Powers)
|
|
}
|
|
w.now = w.now.Add(10 * time.Second)
|
|
c.View.Mana = 100
|
|
c.View.Entity.HP = 10
|
|
if e := w.CastPower(c, "renewal", ""); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if c.View.Powers["renewal"].XP != 10 {
|
|
t.Fatal("useful aura did not grant one award")
|
|
}
|
|
c.View.Entity.Position.X += 2
|
|
c.View.Entity.HP = 10
|
|
advanceProjectiles(w, 30)
|
|
for _, a := range w.Areas {
|
|
if a.MovingAura && a.Position != body(c.View.Entity.Position) {
|
|
t.Fatal("aura did not follow caster")
|
|
}
|
|
}
|
|
if c.View.Powers["renewal"].XP != 10 {
|
|
t.Fatal("aura tick multiplied XP")
|
|
}
|
|
raw, _ := json.Marshal(w)
|
|
var restored World
|
|
if e := json.Unmarshal(raw, &restored); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if e := restored.Restore(w.now); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
rc := restored.Characters[c.View.Entity.ID]
|
|
if !reflect.DeepEqual(rc.View.Powers, c.View.Powers) {
|
|
t.Fatal("restart changed learned powers")
|
|
}
|
|
w.Kind = "hub"
|
|
w.Phase = "hub"
|
|
w.now = w.now.Add(20 * time.Second)
|
|
c.View.Mana = 100
|
|
c.View.Entity.HP = 10
|
|
before := c.View.Powers["mend"].XP
|
|
if e := w.CastPower(c, "mend", c.View.Entity.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if c.View.Powers["mend"].XP != before || c.View.Mana >= 100 {
|
|
t.Fatal("hub spell gained XP or bypassed cost")
|
|
}
|
|
}
|
|
|
|
func TestCastingInterruptMissAndWeaponUnlock(t *testing.T) {
|
|
w, c, m := combatFixture(t)
|
|
c.View.Inventory["book_arc_bolt"] = 1
|
|
c.View.Mana = 100
|
|
if e := w.LearnPower(c, "book_arc_bolt"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if e := w.CastPower(c, "arc_bolt", m.Entity.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
c.View.Entity.Position.X += 1
|
|
w.updatePowers()
|
|
if c.PendingCast != nil || len(w.Projectiles) != 0 || c.View.Mana != 100 {
|
|
t.Fatal("movement failed to interrupt cast without cost")
|
|
}
|
|
if e := w.CastPower(c, "arc_bolt", m.Entity.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
w.now = w.now.Add(time.Second)
|
|
w.updatePowers()
|
|
if len(w.Projectiles) != 1 || c.View.Mana != 95 {
|
|
t.Fatal("cast did not release after delay")
|
|
}
|
|
m.Entity.Position.Z += 20
|
|
advanceProjectiles(w, 40)
|
|
if c.View.Powers["arc_bolt"].XP != 0 {
|
|
t.Fatal("miss gained spell XP")
|
|
}
|
|
w, c, m = combatFixture(t)
|
|
c.View.Equipment = map[string]string{}
|
|
for _, i := range c.View.Items {
|
|
if i.DefinitionID == "knife" {
|
|
c.View.Equipment["weapon"] = i.ID
|
|
}
|
|
}
|
|
w.RefreshStats(c)
|
|
m.Entity.Position = c.View.Entity.Position
|
|
m.Entity.Position.X += 1
|
|
m.Entity.HP = 10000
|
|
m.Entity.MaxHP = 10000
|
|
c.View.AllocatedStats["strength"] = 2
|
|
w.RefreshStats(c)
|
|
for i := 0; i < 10; i++ {
|
|
w.now = w.now.Add(3 * time.Second)
|
|
if e := w.attack(c, m.Entity.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
if c.View.Weapons["blades"].Level != 2 || c.View.Powers["cleave"].Definition.ID != "cleave" {
|
|
t.Fatal("meaningful weapon hits did not unlock ability")
|
|
}
|
|
if e := w.unequip(c, "weapon"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if w.CastPower(c, "cleave", m.Entity.ID) == nil {
|
|
t.Fatal("ability used without matching weapon")
|
|
}
|
|
w.kill(c, "test")
|
|
replacement, e := w.Join(c.Account, "Replacement")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if len(replacement.View.Powers) != 0 || replacement.View.Weapons["blades"].XP != 0 {
|
|
t.Fatal("replacement inherited powers")
|
|
}
|
|
}
|
|
|
|
func TestCorpseRevivalKeepsLootAndDailyBudget(t *testing.T) {
|
|
w, c := fixture(t)
|
|
appearance := *content.DefaultCharacterAppearance()
|
|
c.View.Entity.Appearance = &appearance
|
|
rescuer, e := w.Join("rescuer", "Rescuer")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
_ = w.Connect(rescuer.View.Entity.ID)
|
|
rescuer.View.Entity.Position = c.View.Entity.Position
|
|
rescuer.View.Inventory["revival_stone"] = 2
|
|
c.DailySeconds = 123
|
|
c.View.Inventory["wood"] = 7
|
|
w.kill(c, "test")
|
|
corpse := c.RevivalCorpse
|
|
if _, e = w.Revive(rescuer, corpse, "item"); e == nil {
|
|
t.Fatal("revived without consent")
|
|
}
|
|
c.RevivalAllowed = true
|
|
if e = w.lootCorpse(rescuer, corpse); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if w.Corpses[corpse] == nil || len(w.Corpses[corpse].Inventory) != 0 {
|
|
t.Fatal("fully looted corpse no longer targetable")
|
|
}
|
|
if _, e = w.Revive(rescuer, corpse, "item"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if len(c.View.Inventory) != 0 || len(c.View.Items) != 0 || c.DailySeconds != 123 || rescuer.View.Inventory["wood"] != 7 || rescuer.View.Inventory["revival_stone"] != 1 {
|
|
t.Fatal("revival recreated loot or daily time")
|
|
}
|
|
if !reflect.DeepEqual(c.View.Entity.Appearance, &appearance) {
|
|
t.Fatal("revival changed character appearance")
|
|
}
|
|
if _, e = w.Revive(rescuer, corpse, "item"); e == nil || rescuer.View.Inventory["revival_stone"] != 1 {
|
|
t.Fatal("revived twice")
|
|
}
|
|
w.kill(c, "again")
|
|
if c.RevivalCorpse == corpse {
|
|
t.Fatal("death reused corpse identity")
|
|
}
|
|
c.RevivalAllowed = true
|
|
rescuer.View.Inventory["book_revive"] = 1
|
|
rescuer.View.Mana = 100
|
|
if e = w.LearnPower(rescuer, "book_revive"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
c.DailySeconds = w.Balance.DailyPlaySeconds
|
|
if _, e = w.Revive(rescuer, c.RevivalCorpse, "revive"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if c.View.RemainingSeconds != 0 || !c.Sheltered || !c.View.HasKeystone || c.ReturnPosition == nil || rescuer.View.Mana != 80 || rescuer.View.Powers["revive"].XP != 10 {
|
|
t.Fatal("spell revival changed daily budget or costs")
|
|
}
|
|
w.kill(c, "final")
|
|
c.RevivalAllowed = true
|
|
w.Phase = "lost"
|
|
if _, e = w.Revive(rescuer, c.RevivalCorpse, "item"); e == nil {
|
|
t.Fatal("revived after destruction")
|
|
}
|
|
}
|