55 lines
1.9 KiB
Go
55 lines
1.9 KiB
Go
package game
|
|
|
|
import (
|
|
p "aeternalis/server/internal/protocol"
|
|
"errors"
|
|
)
|
|
|
|
func (w *World) IsHub() bool { return w.Kind == "hub" }
|
|
func (w *World) AllowsXP() bool {
|
|
return w.Kind == "survival" && (w.Phase == "gathering" || w.Phase == "cataclysm")
|
|
}
|
|
func (w *World) PortalPosition() p.Vec3 { return w.terrain.Position(0, 0) }
|
|
|
|
// Escape is an explicit one-item action. It grants no victory/survival credit.
|
|
func (w *World) Departure(c *Character, route string) error {
|
|
if c == nil || !c.Online || c.Sheltered || c.View.RemainingSeconds <= 0 || (c.View.Entity.State != "alive" && c.View.Entity.State != "eligible") {
|
|
return errors.New("character cannot travel")
|
|
}
|
|
if w.IsHub() {
|
|
if route != "hub" {
|
|
return errors.New("choose hub travel")
|
|
}
|
|
return nil
|
|
}
|
|
if w.Phase == "won" && c.View.Entity.State == "eligible" {
|
|
if route != "portal" || distance(c.View.Entity.Position, w.PortalPosition()) > w.Balance.GatherRange {
|
|
return errors.New("stand next to the victory portal")
|
|
}
|
|
return nil
|
|
}
|
|
if w.Phase != "gathering" && w.Phase != "cataclysm" {
|
|
return errors.New("world is no longer available")
|
|
}
|
|
if route != "escape" || c.View.Inventory["escape_stone"] < 1 {
|
|
return errors.New("an escape stone is required before victory")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Transfers arrive as the same life. Import retains progression, inventory and
|
|
// daily usage; its resets apply only to instance-local movement/cooldowns.
|
|
func (w *World) Arrive(c *Character) error {
|
|
if c.View.Entity.HP <= 0 || (c.View.Entity.State != "alive" && c.View.Entity.State != "eligible") {
|
|
return errors.New("only living characters can arrive")
|
|
}
|
|
if old := w.Characters[c.View.Entity.ID]; old != nil {
|
|
if old.View.Entity.State != "eligible" || old.Online {
|
|
return errors.New("character already present")
|
|
}
|
|
delete(w.Characters, c.View.Entity.ID) // Historical legacy passage copy.
|
|
}
|
|
c.View.Entity.State = "eligible"
|
|
return w.Import(c)
|
|
}
|