From 54ccad240eb665f7b9ac52997eac98a4acaba1f0 Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 18 Jan 2026 17:30:03 -0500 Subject: [PATCH] Working on projectiles --- Game/Dungeon/DungeonHandler.cs | 20 ++++++++++++++- Game/Dungeon/DungeonSimulation.cs | 42 +++++++++++++++++++++++++++++++ Game/Dungeon/TickResult.cs | 19 ++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index 4ee62d9..9400f04 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -3617,7 +3617,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler sourceId = e.SourceId, targetType = e.TargetType.ToString().ToLower(), targetId = e.TargetId, - damage = e.Damage + damage = e.Damage, + damageTypeKey = e.DamageTypeKey, + wasResisted = e.WasResisted, + wasWeakness = e.WasWeakness }), deaths = tickResult.DeathEvents.Select(e => new { @@ -3628,6 +3631,21 @@ public sealed partial class DungeonHandler : IClientMessageHandler killerId = e.KillerId, killerName = e.KillerName, xp = e.XpReward + }), + projectileHits = tickResult.ProjectileHitEvents.Select(e => new + { + projectileId = e.ProjectileId, + targetType = e.TargetType.ToString().ToLower(), + targetId = e.TargetId, + x = e.X, + y = e.Y + }), + projectileExpired = tickResult.ProjectileExpiredEvents.Select(e => new + { + projectileId = e.ProjectileId, + x = e.X, + y = e.Y, + reason = e.Reason }) }, diff --git a/Game/Dungeon/DungeonSimulation.cs b/Game/Dungeon/DungeonSimulation.cs index e74254c..7d72c30 100644 --- a/Game/Dungeon/DungeonSimulation.cs +++ b/Game/Dungeon/DungeonSimulation.cs @@ -42,6 +42,8 @@ public partial class DungeonSimulation private readonly List _pendingDamageEvents = new(); private readonly List _pendingDeathEvents = new(); private readonly List _pendingAbilityEvents = new(); + private readonly List _pendingProjectileHitEvents = new(); + private readonly List _pendingProjectileExpiredEvents = new(); private int _nextDroppedItemId = 1; private readonly Dictionary _mobDefinitions; @@ -332,6 +334,8 @@ public partial class DungeonSimulation _pendingDamageEvents.Clear(); _pendingDeathEvents.Clear(); _pendingAbilityEvents.Clear(); + _pendingProjectileHitEvents.Clear(); + _pendingProjectileExpiredEvents.Clear(); // Update all mobs (AI) foreach (var mob in Mobs.Values.Where(m => m.IsAlive)) @@ -377,6 +381,8 @@ public partial class DungeonSimulation DamageEvents = new List(_pendingDamageEvents), DeathEvents = new List(_pendingDeathEvents), AbilityEvents = new List(_pendingAbilityEvents), + ProjectileHitEvents = new List(_pendingProjectileHitEvents), + ProjectileExpiredEvents = new List(_pendingProjectileExpiredEvents), Phase = Phase }; } @@ -538,6 +544,13 @@ public partial class DungeonSimulation // Check max range if (projectile.MaxRange > 0 && projectile.DistanceTraveled > projectile.MaxRange) { + _pendingProjectileExpiredEvents.Add(new ProjectileExpiredEvent + { + ProjectileId = projectile.Id, + X = projectile.X, + Y = projectile.Y, + Reason = "range" + }); toRemove.Add(projectile.Id); continue; } @@ -621,6 +634,16 @@ public partial class DungeonSimulation }); } + // Add projectile hit event + _pendingProjectileHitEvents.Add(new ProjectileHitEvent + { + ProjectileId = projectile.Id, + TargetType = EntityType.Mob, + TargetId = mob.Id, + X = projectile.X, + Y = projectile.Y + }); + toRemove.Add(projectile.Id); break; } @@ -650,6 +673,17 @@ public partial class DungeonSimulation ApplyDamageToPlayer(sourceMob, player, result.FinalDamage, projectile.DamageTypeKey, result.WasResisted, result.WasWeakness); } } + + // Add projectile hit event + _pendingProjectileHitEvents.Add(new ProjectileHitEvent + { + ProjectileId = projectile.Id, + TargetType = EntityType.Player, + TargetId = (int)player.CharacterId, + X = projectile.X, + Y = projectile.Y + }); + toRemove.Add(projectile.Id); break; } @@ -663,6 +697,14 @@ public partial class DungeonSimulation { ProcessAoeAbilityAtLocation(projectile, projectile.X, projectile.Y); } + + _pendingProjectileExpiredEvents.Add(new ProjectileExpiredEvent + { + ProjectileId = projectile.Id, + X = projectile.X, + Y = projectile.Y, + Reason = "wall" + }); toRemove.Add(projectile.Id); } } diff --git a/Game/Dungeon/TickResult.cs b/Game/Dungeon/TickResult.cs index c401a09..793af94 100644 --- a/Game/Dungeon/TickResult.cs +++ b/Game/Dungeon/TickResult.cs @@ -5,6 +5,8 @@ public class TickResult public List DamageEvents { get; set; } = new(); public List DeathEvents { get; set; } = new(); public List AbilityEvents { get; set; } = new(); + public List ProjectileHitEvents { get; set; } = new(); + public List ProjectileExpiredEvents { get; set; } = new(); public DungeonPhase Phase { get; set; } } @@ -54,3 +56,20 @@ public enum EntityType Mob, Chest } + +public class ProjectileHitEvent +{ + public int ProjectileId { get; set; } + public EntityType TargetType { get; set; } + public int TargetId { get; set; } + public float X { get; set; } + public float Y { get; set; } +} + +public class ProjectileExpiredEvent +{ + public int ProjectileId { get; set; } + public float X { get; set; } + public float Y { get; set; } + public string Reason { get; set; } = "range"; // "range", "wall", or "hit" +}