World changes
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
using GameServer.Dungeon;
|
||||
using GameServer.Shared;
|
||||
|
||||
namespace GameServer.World;
|
||||
|
||||
/// <summary>
|
||||
/// Implements IPlayerTarget for a world player, built from character stats on spawn.
|
||||
/// Position delegates to the WorldSessionState so movement updates are reflected in combat.
|
||||
/// </summary>
|
||||
public sealed class WorldPlayerCombatState : IPlayerTarget
|
||||
{
|
||||
private readonly WorldSessionState _session;
|
||||
|
||||
public ulong CharacterId => _session.CharacterId;
|
||||
public string CharacterName => _session.Name;
|
||||
|
||||
// Position delegates to session
|
||||
public float X => _session.X;
|
||||
public float Y => _session.Y;
|
||||
|
||||
// Vitals
|
||||
public float Health { get; set; }
|
||||
public float MaxHealth { get; private set; }
|
||||
public bool IsAlive { get; set; } = true;
|
||||
public bool IsInvulnerable { get; set; }
|
||||
|
||||
// Combat stats (computed from character + gear at spawn)
|
||||
public int Strength { get; set; }
|
||||
public int Intelligence { get; set; }
|
||||
public int Endurance { get; set; }
|
||||
public int Dexterity { get; set; }
|
||||
public int Armor { get; set; }
|
||||
public string WeaponDamageTypeKey { get; set; } = "physical";
|
||||
public Dictionary<string, float> Resistances { get; set; } = new();
|
||||
|
||||
// Status effects
|
||||
public List<PlayerStatusEffect> StatusEffects { get; set; } = new();
|
||||
public bool IsStunned => StatusEffects.Any(e => e.EffectType == "stun" && e.Duration > 0);
|
||||
public bool IsRooted => StatusEffects.Any(e => e.EffectType == "root" && e.Duration > 0);
|
||||
public bool IsFeared => StatusEffects.Any(e => e.EffectType == "fear" && e.Duration > 0);
|
||||
|
||||
// Combat tracking
|
||||
public bool IsInCombat { get; set; }
|
||||
public long LastCombatTick { get; set; }
|
||||
|
||||
// Invulnerability timer (for respawn protection)
|
||||
public float InvulnerabilityTimer { get; set; }
|
||||
|
||||
// Reference to the session for direct access
|
||||
public WorldSessionState Session => _session;
|
||||
|
||||
public WorldPlayerCombatState(WorldSessionState session)
|
||||
{
|
||||
_session = session;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize combat state from character stats.
|
||||
/// Called when player enters a zone with active simulation.
|
||||
/// </summary>
|
||||
public void InitializeFromCharacter(
|
||||
int strength, int intelligence, int endurance, int dexterity,
|
||||
int armor, float maxHealth, string weaponDamageTypeKey,
|
||||
Dictionary<string, float> resistances)
|
||||
{
|
||||
Strength = strength;
|
||||
Intelligence = intelligence;
|
||||
Endurance = endurance;
|
||||
Dexterity = dexterity;
|
||||
Armor = armor;
|
||||
MaxHealth = maxHealth;
|
||||
Health = maxHealth;
|
||||
WeaponDamageTypeKey = weaponDamageTypeKey;
|
||||
Resistances = resistances;
|
||||
IsAlive = true;
|
||||
IsInvulnerable = false;
|
||||
InvulnerabilityTimer = 0;
|
||||
StatusEffects.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update per tick (status effect durations, invulnerability timer, combat timeout)
|
||||
/// </summary>
|
||||
public void Update(float deltaTime, long currentTick)
|
||||
{
|
||||
// Update invulnerability timer
|
||||
if (InvulnerabilityTimer > 0)
|
||||
{
|
||||
InvulnerabilityTimer -= deltaTime;
|
||||
if (InvulnerabilityTimer <= 0)
|
||||
{
|
||||
InvulnerabilityTimer = 0;
|
||||
IsInvulnerable = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update status effects
|
||||
var expired = new List<PlayerStatusEffect>();
|
||||
foreach (var effect in StatusEffects)
|
||||
{
|
||||
effect.Duration -= deltaTime;
|
||||
if (effect.Duration <= 0)
|
||||
expired.Add(effect);
|
||||
}
|
||||
foreach (var e in expired)
|
||||
StatusEffects.Remove(e);
|
||||
|
||||
// Combat timeout (5 seconds out of combat)
|
||||
if (IsInCombat && currentTick - LastCombatTick > 50)
|
||||
{
|
||||
IsInCombat = false;
|
||||
}
|
||||
|
||||
// Passive health regen when not in combat
|
||||
if (!IsInCombat && IsAlive && Health < MaxHealth)
|
||||
{
|
||||
Health = Math.Min(MaxHealth, Health + MaxHealth * 0.02f * deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user