77 lines
2.7 KiB
Go
77 lines
2.7 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) }
|
|
func (w *World) HousingEntrancePosition() p.Vec3 {
|
|
return w.terrain.Position(w.Balance.Entrances.HousingX, w.Balance.Entrances.HousingZ)
|
|
}
|
|
|
|
// Interactions use the same authoritative terrain height, distance and obstruction
|
|
// rules as other world actions. A client click never supplies the server position.
|
|
func (w *World) NearEntrance(c *Character, position p.Vec3) bool {
|
|
if c == nil || HouseID(c) != "" || length3(c.View.Entity.Position, position) > w.Balance.GatherRange {
|
|
return false
|
|
}
|
|
_, blocked := w.combatLine(body(c.View.Entity.Position), body(position), "")
|
|
return !blocked
|
|
}
|
|
|
|
// 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 {
|
|
return errors.New("character cannot travel")
|
|
}
|
|
if HouseID(c) != "" {
|
|
return errors.New("leave the house before traveling")
|
|
}
|
|
if !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")
|
|
}
|
|
if !w.NearEntrance(c, w.PortalPosition()) {
|
|
return errors.New("stand next to the hub world portal")
|
|
}
|
|
return nil
|
|
}
|
|
if w.Phase == "won" && c.View.Entity.State == "eligible" {
|
|
if route != "portal" || !w.NearEntrance(c, w.PortalPosition()) {
|
|
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)
|
|
}
|