86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
package game
|
|
|
|
import (
|
|
p "aeternalis/server/internal/protocol"
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestHubEntrancesScopeProximityAndMigration(t *testing.T) {
|
|
w, c := fixture(t)
|
|
entrances := func() map[string]p.Entity {
|
|
out := map[string]p.Entity{}
|
|
for _, e := range w.Snapshot(c.View.Entity.ID, nil).Entities {
|
|
if e.Kind == "portal" || e.Kind == "house-door" {
|
|
out[e.ID] = e
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
if len(entrances()) != 0 {
|
|
t.Fatal("survival world exposed hub entrances before victory")
|
|
}
|
|
w.Kind = "hub"
|
|
w.Phase = "hub"
|
|
c.View.Entity.Position = w.PortalPosition()
|
|
if e := w.Departure(c, "hub"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
visible := entrances()
|
|
if len(visible) != 2 || visible["housing-entrance"].Position != w.HousingEntrancePosition() || visible["hub-portal"].Position != w.PortalPosition() {
|
|
t.Fatal("hub entrance identity or location missing", visible)
|
|
}
|
|
c.View.Entity.Position.Y += w.Balance.GatherRange + 1
|
|
if w.Departure(c, "hub") == nil {
|
|
t.Fatal("portal ignored vertical distance")
|
|
}
|
|
c.View.Entity.Position = w.HousingEntrancePosition()
|
|
if !w.NearEntrance(c, w.HousingEntrancePosition()) || w.Departure(c, "hub") == nil {
|
|
t.Fatal("different entrance bypassed portal proximity")
|
|
}
|
|
c.View.HouseID = stringPtr(ID())
|
|
if len(entrances()) != 0 || w.Departure(c, "hub") == nil {
|
|
t.Fatal("indoor character accessed world entrances")
|
|
}
|
|
c.View.HouseID = nil
|
|
c.View.Entity.Position.X = 600
|
|
if len(entrances()) != 0 {
|
|
t.Fatal("entrances escaped chunk interest bounds")
|
|
}
|
|
c.View.Entity.Position = w.PortalPosition()
|
|
w.Balance.Entrances = nil
|
|
raw, _ := json.Marshal(w)
|
|
var restored World
|
|
_ = json.Unmarshal(raw, &restored)
|
|
if e := restored.Restore(w.now); e != nil {
|
|
t.Fatal("old snapshot migration failed", e)
|
|
}
|
|
rc := restored.Characters[c.View.Entity.ID]
|
|
_ = restored.Connect(rc.View.Entity.ID)
|
|
if restored.Balance.Entrances == nil || restored.Departure(rc, "hub") != nil {
|
|
t.Fatal("restore lost portal eligibility")
|
|
}
|
|
if restored.Departure(nil, "hub") == nil {
|
|
t.Fatal("missing character traveled")
|
|
}
|
|
}
|
|
|
|
func TestEntranceObstructionUsesServerGeometry(t *testing.T) {
|
|
w, c := fixture(t)
|
|
w.Kind = "hub"
|
|
w.Phase = "hub"
|
|
c.View.Entity.Position = w.PortalPosition()
|
|
c.View.Entity.Position.X -= 2
|
|
position := w.PortalPosition()
|
|
position.X -= 1
|
|
width, depth, height := .4, 3., 4.
|
|
w.Structures["obstacle"] = &Structure{Entity: p.Entity{ID: "obstacle", Kind: "structure", Position: position, Width: &width, Depth: &depth, Height: &height, HP: 100}}
|
|
if w.Departure(c, "hub") == nil {
|
|
t.Fatal("portal ignored an obstruction")
|
|
}
|
|
delete(w.Structures, "obstacle")
|
|
if e := w.Departure(c, "hub"); e != nil {
|
|
t.Fatal("clear portal remained blocked", e)
|
|
}
|
|
}
|