Item modifications and dungeon bug fix for loot dropped

This commit is contained in:
dingo
2025-12-22 16:03:26 -05:00
parent 2c8acbd2e7
commit 6f1968943b
+39 -11
View File
@@ -1328,7 +1328,8 @@ public sealed class DungeonHandler : IClientMessageHandler
type = def.Type.ToString(),
rarity = def.Rarity.ToString(),
quantity = item.Quantity,
spriteId = def.SpriteId
spritePath = def.SpritePath,
tintColor = def.TintColor
};
}
}
@@ -1956,8 +1957,10 @@ public sealed class DungeonHandler : IClientMessageHandler
name = m.Name,
x = m.X,
y = m.Y,
rotation = m.Rotation,
health = m.Health,
maxHealth = m.MaxHealth,
state = m.State.ToString().ToLower(),
spriteConfig = string.IsNullOrEmpty(m.SpriteConfigJson) ? null :
System.Text.Json.JsonSerializer.Deserialize<object>(m.SpriteConfigJson),
tintColor = m.TintColor,
@@ -2048,31 +2051,53 @@ public sealed class DungeonHandler : IClientMessageHandler
/// <summary>
/// Respawn all mobs in a dungeon (called when dungeon was empty and player rejoins)
/// Preserves mobs that are carrying player loot from kills
/// </summary>
private void RespawnAllMobs(DungeonInstance instance)
{
// Check if any existing mobs have carried player loot - don't respawn those
var mobsWithLoot = instance.Simulation.Mobs.Values
.Where(m => m.HasCarriedLoot)
.ToDictionary(m => m.Id, m => m);
if (mobsWithLoot.Count > 0)
{
_log.LogInformation("Preserving {Count} mobs with carried player loot during respawn", mobsWithLoot.Count);
}
// Create a fresh simulation with the same parameters
var layout = DungeonGenerator.Generate(instance.Seed, instance.Tier);
var freshSimulation = new DungeonSimulation(layout, instance.Tier, _mobDefinitions, instance.LevelBracketMin);
// Copy fresh mobs to the existing simulation
// Clear and rebuild mobs, keeping those with loot
instance.Simulation.Mobs.Clear();
foreach (var mob in freshSimulation.Mobs)
{
instance.Simulation.Mobs.TryAdd(mob.Key, mob.Value);
// If we have a preserved mob with this ID (same spawn point), use the preserved one
if (mobsWithLoot.TryGetValue(mob.Key, out var preservedMob))
{
// Restore the preserved mob (keeps carried loot)
instance.Simulation.Mobs.TryAdd(mob.Key, preservedMob);
}
else
{
// Use the fresh mob
instance.Simulation.Mobs.TryAdd(mob.Key, mob.Value);
}
}
// Reset chest states (they respawn closed)
// Reset chest states (they respawn closed) - but NOT loot chests
foreach (var chest in instance.Simulation.Chests.Values)
{
chest.IsOpened = false;
}
// Clear any loot chests (personal drops don't persist through respawn)
instance.Simulation.LootChests.Clear();
// DON'T clear loot chests - these contain player death drops!
// instance.Simulation.LootChests.Clear();
// Clear dropped items
instance.Simulation.DroppedItems.Clear();
// DON'T clear dropped items - these might be important!
// instance.Simulation.DroppedItems.Clear();
// Reset portals (exit portal should be inactive until boss killed)
foreach (var portal in instance.Simulation.Portals.Values)
@@ -2083,7 +2108,8 @@ public sealed class DungeonHandler : IClientMessageHandler
}
}
_log.LogDebug("Respawned {MobCount} mobs in dungeon {Id}", instance.Simulation.Mobs.Count, instance.Id);
_log.LogDebug("Respawned {MobCount} mobs in dungeon {Id} (preserved {PreservedCount} with loot)",
instance.Simulation.Mobs.Count, instance.Id, mobsWithLoot.Count);
}
/// <summary>
@@ -2161,7 +2187,8 @@ public sealed class DungeonHandler : IClientMessageHandler
type = l.Item.Type.ToString(),
rarity = l.Item.Rarity.ToString(),
quantity = l.Quantity,
spriteId = l.Item.SpriteId,
spritePath = l.Item.SpritePath,
tintColor = l.Item.TintColor,
// Include stats for display
armor = l.Item.Armor,
minDamage = l.Item.MinDamage,
@@ -2219,7 +2246,8 @@ public sealed class DungeonHandler : IClientMessageHandler
bonusMana = def.BonusMana,
healAmount = def.HealAmount,
manaRestore = def.ManaRestore,
spriteId = def.SpriteId
spritePath = def.SpritePath,
tintColor = def.TintColor
};
}
}