534 lines
13 KiB
Go

package functions
import (
"fmt"
"eq2emu/internal/events"
)
// Movement and Position Functions
// SetPosition sets the spawn's position and heading
func SetPosition(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
x := ctx.GetParameterFloat("x", 0)
y := ctx.GetParameterFloat("y", 0)
z := ctx.GetParameterFloat("z", 0)
heading := ctx.GetParameterFloat("heading", float64(spawn.GetHeading()))
spawn.SetX(float32(x))
spawn.SetY(float32(y), false)
spawn.SetZ(float32(z))
spawn.SetHeadingFromFloat(float32(heading))
ctx.Debug("Set position to (%.2f, %.2f, %.2f, %.2f) for spawn %s",
x, y, z, heading, spawn.GetName())
return nil
}
// GetPosition gets the spawn's position and heading
func GetPosition(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
ctx.SetResult("x", spawn.GetX())
ctx.SetResult("y", spawn.GetY())
ctx.SetResult("z", spawn.GetZ())
ctx.SetResult("heading", spawn.GetHeading())
return nil
}
// GetX gets the spawn's X coordinate
func GetX(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
ctx.SetResult("x", spawn.GetX())
return nil
}
// GetY gets the spawn's Y coordinate
func GetY(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
ctx.SetResult("y", spawn.GetY())
return nil
}
// GetZ gets the spawn's Z coordinate
func GetZ(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
ctx.SetResult("z", spawn.GetZ())
return nil
}
// GetHeading gets the spawn's heading
func GetHeading(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
ctx.SetResult("heading", spawn.GetHeading())
return nil
}
// SetHeading sets the spawn's heading
func SetHeading(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
heading := ctx.GetParameterFloat("heading", 0)
spawn.SetHeadingFromFloat(float32(heading))
ctx.Debug("Set heading to %.2f for spawn %s", heading, spawn.GetName())
return nil
}
// GetOrigX gets the spawn's original X coordinate
func GetOrigX(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement original position tracking
ctx.SetResult("orig_x", spawn.GetX()) // Fallback to current position
return nil
}
// GetOrigY gets the spawn's original Y coordinate
func GetOrigY(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement original position tracking
ctx.SetResult("orig_y", spawn.GetY()) // Fallback to current position
return nil
}
// GetOrigZ gets the spawn's original Z coordinate
func GetOrigZ(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement original position tracking
ctx.SetResult("orig_z", spawn.GetZ()) // Fallback to current position
return nil
}
// GetDistance gets the distance between spawn and target
func GetDistance(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
target := ctx.GetTarget()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if target == nil {
return fmt.Errorf("no target in context")
}
// TODO: Implement proper distance calculation
// For now, return a placeholder distance
distance := 10.0
ctx.SetResult("distance", distance)
return nil
}
// FaceTarget makes the spawn face the target
func FaceTarget(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
target := ctx.GetTarget()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if target == nil {
return fmt.Errorf("no target in context")
}
// TODO: Implement face target calculation
ctx.Debug("Spawn %s facing target %s (not yet implemented)", spawn.GetName(), target.GetName())
return nil
}
// GetSpeed gets the spawn's movement speed
func GetSpeed(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement speed tracking
ctx.SetResult("speed", 5.0) // Default walking speed
return nil
}
// SetSpeed sets the spawn's movement speed
func SetSpeed(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
speed := ctx.GetParameterFloat("speed", 5.0)
if speed < 0 {
speed = 0
}
// TODO: Implement speed setting
ctx.Debug("Set speed to %.2f for spawn %s (not yet implemented)", speed, spawn.GetName())
return nil
}
// SetSpeedMultiplier sets a speed multiplier for the spawn
func SetSpeedMultiplier(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
multiplier := ctx.GetParameterFloat("multiplier", 1.0)
if multiplier < 0 {
multiplier = 0
}
// TODO: Implement speed multiplier
ctx.Debug("Set speed multiplier to %.2f for spawn %s (not yet implemented)", multiplier, spawn.GetName())
return nil
}
// HasMoved checks if the spawn has moved recently
func HasMoved(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement movement tracking
ctx.SetResult("has_moved", false) // Default value
return nil
}
// IsRunning checks if the spawn is currently running
func IsRunning(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement running state tracking
ctx.SetResult("is_running", false) // Default value
return nil
}
// MoveToLocation moves the spawn to a specific location
func MoveToLocation(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
x := ctx.GetParameterFloat("x", 0)
y := ctx.GetParameterFloat("y", 0)
z := ctx.GetParameterFloat("z", 0)
runningSpeed := ctx.GetParameterFloat("running_speed", 7.0)
// TODO: Implement actual movement/pathfinding
// For now, just teleport to the location
spawn.SetX(float32(x))
spawn.SetY(float32(y), false)
spawn.SetZ(float32(z))
ctx.Debug("Moved spawn %s to location (%.2f, %.2f, %.2f) at speed %.2f",
spawn.GetName(), x, y, z, runningSpeed)
return nil
}
// ClearRunningLocations clears any queued movement locations
func ClearRunningLocations(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement movement queue clearing
ctx.Debug("Cleared running locations for spawn %s (not yet implemented)", spawn.GetName())
return nil
}
// SpawnMove initiates spawn movement
func SpawnMove(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
x := ctx.GetParameterFloat("x", 0)
y := ctx.GetParameterFloat("y", 0)
z := ctx.GetParameterFloat("z", 0)
delay := ctx.GetParameterInt("delay", 0)
// TODO: Implement spawn movement with delay
ctx.Debug("Spawn %s moving to (%.2f, %.2f, %.2f) with delay %d (not yet implemented)",
spawn.GetName(), x, y, z, delay)
return nil
}
// MovementLoopAdd adds a movement loop point
func MovementLoopAdd(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
x := ctx.GetParameterFloat("x", 0)
y := ctx.GetParameterFloat("y", 0)
z := ctx.GetParameterFloat("z", 0)
delay := ctx.GetParameterInt("delay", 0)
// TODO: Implement movement loop system
ctx.Debug("Added movement loop point (%.2f, %.2f, %.2f) with delay %d for spawn %s (not yet implemented)",
x, y, z, delay, spawn.GetName())
return nil
}
// PauseMovement pauses the spawn's movement
func PauseMovement(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
duration := ctx.GetParameterInt("duration", 0)
// TODO: Implement movement pausing
ctx.Debug("Paused movement for spawn %s for %d ms (not yet implemented)", spawn.GetName(), duration)
return nil
}
// StopMovement stops the spawn's movement
func StopMovement(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement movement stopping
ctx.Debug("Stopped movement for spawn %s (not yet implemented)", spawn.GetName())
return nil
}
// SetMount sets the spawn's mount
func SetMount(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
mountID := ctx.GetParameterInt("mount_id", 0)
// TODO: Implement mount system
ctx.Debug("Set mount %d for spawn %s (not yet implemented)", mountID, spawn.GetName())
return nil
}
// GetMount gets the spawn's current mount
func GetMount(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement mount system
ctx.SetResult("mount_id", 0) // No mount
return nil
}
// SetMountColor sets the mount's color
func SetMountColor(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
colorR := ctx.GetParameterInt("red", 255)
colorG := ctx.GetParameterInt("green", 255)
colorB := ctx.GetParameterInt("blue", 255)
// TODO: Implement mount color system
ctx.Debug("Set mount color to RGB(%d, %d, %d) for spawn %s (not yet implemented)",
colorR, colorG, colorB, spawn.GetName())
return nil
}
// StartAutoMount starts auto-mounting
func StartAutoMount(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
// TODO: Implement auto-mount system
ctx.Debug("Started auto-mount for player %s (not yet implemented)", spawn.GetName())
return nil
}
// EndAutoMount ends auto-mounting
func EndAutoMount(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
// TODO: Implement auto-mount system
ctx.Debug("Ended auto-mount for player %s (not yet implemented)", spawn.GetName())
return nil
}
// IsOnAutoMount checks if spawn is on auto-mount
func IsOnAutoMount(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
// TODO: Implement auto-mount system
ctx.SetResult("is_on_auto_mount", false)
return nil
}
// AddWaypoint adds a waypoint for the player
func AddWaypoint(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
x := ctx.GetParameterFloat("x", 0)
y := ctx.GetParameterFloat("y", 0)
z := ctx.GetParameterFloat("z", 0)
waypointName := ctx.GetParameterString("name", "Waypoint")
// TODO: Implement waypoint system
ctx.Debug("Added waypoint '%s' at (%.2f, %.2f, %.2f) for player %s (not yet implemented)",
waypointName, x, y, z, spawn.GetName())
return nil
}
// RemoveWaypoint removes a waypoint for the player
func RemoveWaypoint(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
waypointID := ctx.GetParameterInt("waypoint_id", 0)
// TODO: Implement waypoint system
ctx.Debug("Removed waypoint %d for player %s (not yet implemented)", waypointID, spawn.GetName())
return nil
}
// SendWaypoints sends waypoints to the player
func SendWaypoints(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
// TODO: Implement waypoint system
ctx.Debug("Sent waypoints to player %s (not yet implemented)", spawn.GetName())
return nil
}
// Evac evacuates the player to safety
func Evac(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
// TODO: Implement evacuation to safe location
ctx.Debug("Evacuated player %s to safety (not yet implemented)", spawn.GetName())
return nil
}
// Bind binds the player to current location
func Bind(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
// TODO: Implement bind system
ctx.Debug("Bound player %s to current location (not yet implemented)", spawn.GetName())
return nil
}
// Gate gates the player to bind location
func Gate(ctx *events.EventContext) error {
spawn := ctx.GetSpawn()
if spawn == nil {
return fmt.Errorf("no spawn in context")
}
if !spawn.IsPlayer() {
return fmt.Errorf("spawn is not a player")
}
// TODO: Implement gate system
ctx.Debug("Gated player %s to bind location (not yet implemented)", spawn.GetName())
return nil
}