package functions import ( "fmt" "eq2emu/internal/events" ) // Health and Power Management Functions // SetCurrentHP sets the spawn's current HP func SetCurrentHP(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } hp := ctx.GetParameterFloat("hp", 0) if hp < 0 { return fmt.Errorf("HP cannot be negative") } spawn.SetHP(int32(hp)) ctx.Debug("Set HP to %f for spawn %s", hp, spawn.GetName()) return nil } // SetMaxHP sets the spawn's maximum HP func SetMaxHP(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } maxHP := ctx.GetParameterFloat("max_hp", 0) if maxHP < 0 { return fmt.Errorf("max HP cannot be negative") } spawn.SetTotalHP(int32(maxHP)) ctx.Debug("Set Max HP to %f for spawn %s", maxHP, spawn.GetName()) return nil } // SetMaxHPBase sets the spawn's base maximum HP (before bonuses) func SetMaxHPBase(ctx *events.EventContext) error { // TODO: Implement base HP system when available return SetMaxHP(ctx) // Fallback to regular max HP for now } // SetCurrentPower sets the spawn's current power func SetCurrentPower(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } power := ctx.GetParameterFloat("power", 0) if power < 0 { return fmt.Errorf("power cannot be negative") } spawn.SetPower(int32(power)) ctx.Debug("Set Power to %f for spawn %s", power, spawn.GetName()) return nil } // SetMaxPower sets the spawn's maximum power func SetMaxPower(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } maxPower := ctx.GetParameterFloat("max_power", 0) if maxPower < 0 { return fmt.Errorf("max power cannot be negative") } spawn.SetTotalPower(int32(maxPower)) ctx.Debug("Set Max Power to %f for spawn %s", maxPower, spawn.GetName()) return nil } // SetMaxPowerBase sets the spawn's base maximum power (before bonuses) func SetMaxPowerBase(ctx *events.EventContext) error { // TODO: Implement base power system when available return SetMaxPower(ctx) // Fallback to regular max power for now } // ModifyMaxHP modifies the spawn's maximum HP by a relative amount func ModifyMaxHP(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } modifier := ctx.GetParameterFloat("modifier", 0) currentMax := float64(spawn.GetTotalHP()) newMax := currentMax + modifier if newMax < 0 { newMax = 0 } spawn.SetTotalHP(int32(newMax)) ctx.Debug("Modified Max HP by %f (new value: %f) for spawn %s", modifier, newMax, spawn.GetName()) return nil } // ModifyMaxPower modifies the spawn's maximum power by a relative amount func ModifyMaxPower(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } modifier := ctx.GetParameterFloat("modifier", 0) currentMax := float64(spawn.GetTotalPower()) newMax := currentMax + modifier if newMax < 0 { newMax = 0 } spawn.SetTotalPower(int32(newMax)) ctx.Debug("Modified Max Power by %f (new value: %f) for spawn %s", modifier, newMax, spawn.GetName()) return nil } // ModifyPower modifies the spawn's current power by a relative amount func ModifyPower(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } modifier := ctx.GetParameterFloat("modifier", 0) current := float64(spawn.GetPower()) newPower := current + modifier // Clamp between 0 and max power maxPower := float64(spawn.GetTotalPower()) if newPower < 0 { newPower = 0 } else if newPower > maxPower { newPower = maxPower } spawn.SetPower(int32(newPower)) ctx.Debug("Modified Power by %f (new value: %f) for spawn %s", modifier, newPower, spawn.GetName()) return nil } // ModifyHP modifies the spawn's current HP by a relative amount func ModifyHP(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } modifier := ctx.GetParameterFloat("modifier", 0) current := float64(spawn.GetHP()) newHP := current + modifier // Clamp between 0 and max HP maxHP := float64(spawn.GetTotalHP()) if newHP < 0 { newHP = 0 } else if newHP > maxHP { newHP = maxHP } spawn.SetHP(int32(newHP)) ctx.Debug("Modified HP by %f (new value: %f) for spawn %s", modifier, newHP, spawn.GetName()) // Update alive state based on HP if newHP <= 0 { spawn.SetAlive(false) ctx.Debug("Spawn %s is now dead", spawn.GetName()) } else if !spawn.IsAlive() { spawn.SetAlive(true) ctx.Debug("Spawn %s is now alive", spawn.GetName()) } return nil } // ModifyTotalHP modifies the spawn's total/max HP by a relative amount func ModifyTotalHP(ctx *events.EventContext) error { return ModifyMaxHP(ctx) // Alias for ModifyMaxHP } // ModifyTotalPower modifies the spawn's total/max power by a relative amount func ModifyTotalPower(ctx *events.EventContext) error { return ModifyMaxPower(ctx) // Alias for ModifyMaxPower } // GetCurrentHP gets the spawn's current HP func GetCurrentHP(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } hp := spawn.GetHP() ctx.SetResult("hp", hp) return nil } // GetMaxHP gets the spawn's maximum HP func GetMaxHP(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } maxHP := spawn.GetTotalHP() ctx.SetResult("max_hp", maxHP) return nil } // GetMaxHPBase gets the spawn's base maximum HP (before bonuses) func GetMaxHPBase(ctx *events.EventContext) error { // TODO: Implement base HP system when available return GetMaxHP(ctx) // Fallback to regular max HP for now } // GetCurrentPower gets the spawn's current power func GetCurrentPower(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } power := spawn.GetPower() ctx.SetResult("power", power) return nil } // GetMaxPower gets the spawn's maximum power func GetMaxPower(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } maxPower := spawn.GetTotalPower() ctx.SetResult("max_power", maxPower) return nil } // GetMaxPowerBase gets the spawn's base maximum power (before bonuses) func GetMaxPowerBase(ctx *events.EventContext) error { // TODO: Implement base power system when available return GetMaxPower(ctx) // Fallback to regular max power for now } // GetPCTOfHP gets the percentage of current HP relative to max HP func GetPCTOfHP(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } currentHP := float64(spawn.GetHP()) maxHP := float64(spawn.GetTotalHP()) var percentage float64 if maxHP > 0 { percentage = (currentHP / maxHP) * 100 } else { percentage = 0 } ctx.SetResult("hp_percentage", percentage) return nil } // GetPCTOfPower gets the percentage of current power relative to max power func GetPCTOfPower(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } currentPower := float64(spawn.GetPower()) maxPower := float64(spawn.GetTotalPower()) var percentage float64 if maxPower > 0 { percentage = (currentPower / maxPower) * 100 } else { percentage = 0 } ctx.SetResult("power_percentage", percentage) return nil } // SpellHeal heals the spawn for a specific amount func SpellHeal(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } amount := ctx.GetParameterFloat("amount", 0) if amount <= 0 { return fmt.Errorf("heal amount must be positive") } current := float64(spawn.GetHP()) maxHP := float64(spawn.GetTotalHP()) newHP := current + amount // Cap at max HP if newHP > maxHP { newHP = maxHP amount = maxHP - current // Adjust amount to actual healed } spawn.SetHP(int32(newHP)) ctx.SetResult("amount_healed", amount) ctx.Debug("Healed spawn %s for %f (new HP: %f)", spawn.GetName(), amount, newHP) // Update alive state if necessary if newHP > 0 && !spawn.IsAlive() { spawn.SetAlive(true) ctx.Debug("Spawn %s is now alive from healing", spawn.GetName()) } return nil } // SpellHealPct heals the spawn for a percentage of max HP func SpellHealPct(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } percentage := ctx.GetParameterFloat("percentage", 0) if percentage <= 0 { return fmt.Errorf("heal percentage must be positive") } maxHP := float64(spawn.GetTotalHP()) healAmount := maxHP * (percentage / 100.0) // Set the heal amount and delegate to SpellHeal ctx.WithParameter("amount", healAmount) return SpellHeal(ctx) } // IsAlive checks if the spawn is alive func IsAlive(ctx *events.EventContext) error { spawn := ctx.GetSpawn() if spawn == nil { return fmt.Errorf("no spawn in context") } ctx.SetResult("is_alive", spawn.IsAlive()) return nil }