113 lines
3.1 KiB
Go
113 lines
3.1 KiB
Go
package game
|
|
|
|
import (
|
|
p "aeternalis/server/internal/protocol"
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestHubRulesAndDailyLimit(t *testing.T) {
|
|
w, c := fixture(t)
|
|
w.Kind = "hub"
|
|
w.Phase = "hub"
|
|
if _, err := w.Join("new", "New"); err == nil {
|
|
t.Fatal("new life began in hub")
|
|
}
|
|
c.View.Inventory["herb"] = 4
|
|
xp, craft := c.View.Experience, c.View.Skills["crafting"]
|
|
if err := w.craft(c, "bandage"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
w.grantXP(c, 1000)
|
|
if c.View.Inventory["herb"] != 2 || c.View.Inventory["bandage"] < 1 || c.View.Experience != xp || c.View.Skills["crafting"] != craft {
|
|
t.Fatal("hub crafting must spend resources without granting XP")
|
|
}
|
|
if w.attack(c, "boss") == nil || w.gather(c, "tree") == nil || w.TriggerBoss() == nil || w.Control("end-world", "", "", "test") == nil || w.SpawnMobs("", "") == nil {
|
|
t.Fatal("hub allowed combat, gathering or destruction")
|
|
}
|
|
w.Advance(w.CreatedAt.Add(30*24*time.Hour), .05)
|
|
if w.Phase != "hub" || len(w.Mobs) != 0 {
|
|
t.Fatal("hub decayed or spawned mobs")
|
|
}
|
|
for _, chunk := range w.Snapshot(c.View.Entity.ID, nil).Chunks {
|
|
if len(chunk.Resources) != 0 {
|
|
t.Fatal("hub spawned gathering resources")
|
|
}
|
|
}
|
|
w.Balance.DailyPlaySeconds = 1
|
|
w.Advance(w.now.Add(2*time.Second), 2)
|
|
if c.Online || c.View.RemainingSeconds != 0 {
|
|
t.Fatal("hub bypassed daily time cap")
|
|
}
|
|
if w.Departure(c, "hub") == nil {
|
|
t.Fatal("capped character traveled")
|
|
}
|
|
}
|
|
|
|
func TestVictoryPortalAndTravelEligibility(t *testing.T) {
|
|
w, c := fixture(t)
|
|
if w.Departure(c, "escape") == nil {
|
|
t.Fatal("escaped without item")
|
|
}
|
|
c.View.Inventory["escape_stone"] = 1
|
|
if e := w.Departure(c, "escape"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
c.Online = false
|
|
if w.Departure(c, "escape") == nil {
|
|
t.Fatal("offline escape")
|
|
}
|
|
c.Online = true
|
|
c.Sheltered = true
|
|
if w.Departure(c, "escape") == nil {
|
|
t.Fatal("sheltered escape")
|
|
}
|
|
c.Sheltered = false
|
|
c.View.Entity.State = "dead"
|
|
if w.Departure(c, "escape") == nil {
|
|
t.Fatal("dead character escaped")
|
|
}
|
|
c.View.Entity.State = "alive"
|
|
w.Phase = "cataclysm"
|
|
w.damageBoss(c, w.BossHP)
|
|
c.View.Entity.Position = w.terrain.Position(100, 100)
|
|
if w.Departure(c, "portal") == nil {
|
|
t.Fatal("remote portal use")
|
|
}
|
|
if err := w.Intent(c.View.Entity.ID, p.Intent{Op: "move", Seq: 1, X: 1}); err != nil {
|
|
t.Fatal("survivor cannot walk to portal", err)
|
|
}
|
|
if err := w.Intent(c.View.Entity.ID, p.Intent{Op: "attack", Seq: 2, Target: "boss"}); err == nil {
|
|
t.Fatal("combat continued after victory")
|
|
}
|
|
c.View.Entity.Position = w.PortalPosition()
|
|
if e := w.Departure(c, "portal"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
found := false
|
|
for _, entity := range w.Snapshot(c.View.Entity.ID, nil).Entities {
|
|
if entity.Kind == "portal" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("victory portal missing from snapshot")
|
|
}
|
|
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 e := restored.Connect(rc.View.Entity.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if e := restored.Departure(rc, "portal"); e != nil {
|
|
t.Fatal("portal was not preserved across restart", e)
|
|
}
|
|
}
|