Item modifications and dungeon bug fix for loot dropped
This commit is contained in:
@@ -1328,7 +1328,8 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
type = def.Type.ToString(),
|
type = def.Type.ToString(),
|
||||||
rarity = def.Rarity.ToString(),
|
rarity = def.Rarity.ToString(),
|
||||||
quantity = item.Quantity,
|
quantity = item.Quantity,
|
||||||
spriteId = def.SpriteId
|
spritePath = def.SpritePath,
|
||||||
|
tintColor = def.TintColor
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1956,8 +1957,10 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
name = m.Name,
|
name = m.Name,
|
||||||
x = m.X,
|
x = m.X,
|
||||||
y = m.Y,
|
y = m.Y,
|
||||||
|
rotation = m.Rotation,
|
||||||
health = m.Health,
|
health = m.Health,
|
||||||
maxHealth = m.MaxHealth,
|
maxHealth = m.MaxHealth,
|
||||||
|
state = m.State.ToString().ToLower(),
|
||||||
spriteConfig = string.IsNullOrEmpty(m.SpriteConfigJson) ? null :
|
spriteConfig = string.IsNullOrEmpty(m.SpriteConfigJson) ? null :
|
||||||
System.Text.Json.JsonSerializer.Deserialize<object>(m.SpriteConfigJson),
|
System.Text.Json.JsonSerializer.Deserialize<object>(m.SpriteConfigJson),
|
||||||
tintColor = m.TintColor,
|
tintColor = m.TintColor,
|
||||||
@@ -2048,31 +2051,53 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Respawn all mobs in a dungeon (called when dungeon was empty and player rejoins)
|
/// Respawn all mobs in a dungeon (called when dungeon was empty and player rejoins)
|
||||||
|
/// Preserves mobs that are carrying player loot from kills
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void RespawnAllMobs(DungeonInstance instance)
|
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
|
// Create a fresh simulation with the same parameters
|
||||||
var layout = DungeonGenerator.Generate(instance.Seed, instance.Tier);
|
var layout = DungeonGenerator.Generate(instance.Seed, instance.Tier);
|
||||||
var freshSimulation = new DungeonSimulation(layout, instance.Tier, _mobDefinitions, instance.LevelBracketMin);
|
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();
|
instance.Simulation.Mobs.Clear();
|
||||||
|
|
||||||
foreach (var mob in freshSimulation.Mobs)
|
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)
|
foreach (var chest in instance.Simulation.Chests.Values)
|
||||||
{
|
{
|
||||||
chest.IsOpened = false;
|
chest.IsOpened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear any loot chests (personal drops don't persist through respawn)
|
// DON'T clear loot chests - these contain player death drops!
|
||||||
instance.Simulation.LootChests.Clear();
|
// instance.Simulation.LootChests.Clear();
|
||||||
|
|
||||||
// Clear dropped items
|
// DON'T clear dropped items - these might be important!
|
||||||
instance.Simulation.DroppedItems.Clear();
|
// instance.Simulation.DroppedItems.Clear();
|
||||||
|
|
||||||
// Reset portals (exit portal should be inactive until boss killed)
|
// Reset portals (exit portal should be inactive until boss killed)
|
||||||
foreach (var portal in instance.Simulation.Portals.Values)
|
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>
|
/// <summary>
|
||||||
@@ -2161,7 +2187,8 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
type = l.Item.Type.ToString(),
|
type = l.Item.Type.ToString(),
|
||||||
rarity = l.Item.Rarity.ToString(),
|
rarity = l.Item.Rarity.ToString(),
|
||||||
quantity = l.Quantity,
|
quantity = l.Quantity,
|
||||||
spriteId = l.Item.SpriteId,
|
spritePath = l.Item.SpritePath,
|
||||||
|
tintColor = l.Item.TintColor,
|
||||||
// Include stats for display
|
// Include stats for display
|
||||||
armor = l.Item.Armor,
|
armor = l.Item.Armor,
|
||||||
minDamage = l.Item.MinDamage,
|
minDamage = l.Item.MinDamage,
|
||||||
@@ -2219,7 +2246,8 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
bonusMana = def.BonusMana,
|
bonusMana = def.BonusMana,
|
||||||
healAmount = def.HealAmount,
|
healAmount = def.HealAmount,
|
||||||
manaRestore = def.ManaRestore,
|
manaRestore = def.ManaRestore,
|
||||||
spriteId = def.SpriteId
|
spritePath = def.SpritePath,
|
||||||
|
tintColor = def.TintColor
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user