Working on projectiles

This commit is contained in:
dingo
2026-01-18 17:30:03 -05:00
parent d0fa87ef5d
commit 54ccad240e
3 changed files with 80 additions and 1 deletions
+42
View File
@@ -42,6 +42,8 @@ public partial class DungeonSimulation
private readonly List<DamageEvent> _pendingDamageEvents = new();
private readonly List<DeathEvent> _pendingDeathEvents = new();
private readonly List<AbilityEvent> _pendingAbilityEvents = new();
private readonly List<ProjectileHitEvent> _pendingProjectileHitEvents = new();
private readonly List<ProjectileExpiredEvent> _pendingProjectileExpiredEvents = new();
private int _nextDroppedItemId = 1;
private readonly Dictionary<int, DungeonMobDefinition> _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<DamageEvent>(_pendingDamageEvents),
DeathEvents = new List<DeathEvent>(_pendingDeathEvents),
AbilityEvents = new List<AbilityEvent>(_pendingAbilityEvents),
ProjectileHitEvents = new List<ProjectileHitEvent>(_pendingProjectileHitEvents),
ProjectileExpiredEvents = new List<ProjectileExpiredEvent>(_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);
}
}