Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Core/Resources/Archives/Collection/ArchiveCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ public void ApplyDehackedPatch()
Definitions.DehackedDefinition.LoadActorDefinitions(EntityDefinitionComposer);
var dehackedApplier = new DehackedApplier(Definitions, Definitions.DehackedDefinition);
dehackedApplier.Apply(Definitions.DehackedDefinition, Definitions, EntityDefinitionComposer);

foreach (var ammo in Definitions.DehackedDefinition.AmmoNames)
EntityDefinitionComposer.GetByName(ammo)?.Properties.Inventory.IgnoreAmmoDroppedModifier = true;
foreach (var ammo in Definitions.DehackedDefinition.AmmoDoubleNames)
EntityDefinitionComposer.GetByName(ammo)?.Properties.Inventory.IgnoreAmmoDroppedModifier = true;

Definitions.DehackedDefinition.FinalizeData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public class InventoryProperty
public int PickupBonusCount = 6;
public bool MessageOnly;
public bool NoItem;
public bool IgnoreAmmoDroppedModifier;
public AmountModifier AmountModifier;
}
5 changes: 5 additions & 0 deletions Core/World/Entities/Inventories/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ public static int GetAmmoGiveAmount(EntityDefinition ammoDef, EntityDefinition b
if (multiplier.HasValue)
giveAmount = (int)(giveAmount * multiplier);
else
{
// Don't apply 0.5 skill dropped multiplier for ammo drops set by dehacked. Only weapons were hard coded to give half when dropped.
if (weaponDef == null && ammoDef.Properties.Inventory.IgnoreAmmoDroppedModifier)
flags = null;
giveAmount = WorldStatic.World.SkillDefinition.GetAmmoAmount(giveAmount, 1, flags);
}

return giveAmount;
}
Expand Down
3 changes: 3 additions & 0 deletions Core/World/Entities/Players/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,9 @@ private bool AddAmmo(EntityDefinition ammoDef, EntityDefinition? weaponDef, int
var baseAmmoDef = Inventory.GetBaseAmmoDef(ammoDef);
int giveAmount = Inventory.GetAmmoGiveAmount(ammoDef, baseAmmoDef, weaponDef, amount, flags);

if (giveAmount == 0)
return true;

int oldCount = Inventory.Amount(baseAmmoDef);
bool success = Inventory.Add(baseAmmoDef, giveAmount, flags);
if (success && autoSwitchWeapon && ShouldSwitch(weaponDef))
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Fix tracer lines drawing over sprites with software emulation.
- Fix to match boom behavior to parsing dehacked integers with failures defaulting to zero.
- Fix SBARDEF crash when children element was explicity set to null.
- Fix dehacked dropped ammo types only giving half ammo.

## Misc:
- Refactor of old Status Bar renderer to data-driven SBARDEF format.
Expand Down
28 changes: 20 additions & 8 deletions Tests/Unit/GameAction/DehackedPickup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Helion.Dehacked;
using Helion.Geometry.Vectors;
using Helion.Geometry.Vectors;
using Helion.Resources.IWad;
using Helion.Tests.Unit.GameAction;
using Helion.Tests.Unit.GameAction.Util;
using Helion.Util;
using Helion.World.Entities.Definition.Composer;
using Helion.World.Entities.Players;
using Helion.World.Impl.SinglePlayer;
using System;
using System.Linq;
using Xunit;

namespace Helion.Tests.Unit.GameAction;
Expand All @@ -22,15 +21,11 @@ public class DehackedPickup : IDisposable

public DehackedPickup()
{
World = WorldAllocator.LoadMap("Resources/box.zip", "box.WAD", "MAP01", GetType().Name, WorldInit, IWadType.Doom2);
World = WorldAllocator.LoadMap("Resources/box.zip", "box.WAD", "MAP01", GetType().Name, WorldInit, IWadType.Doom2, dehackedPatch: "");
}

private void WorldInit(SinglePlayerWorld world)
{
world.ArchiveCollection.Definitions.DehackedDefinition = new();
DehackedApplier applier = new(world.ArchiveCollection.Definitions, world.ArchiveCollection.Definitions.DehackedDefinition);
applier.Apply(world.ArchiveCollection.Definitions.DehackedDefinition, world.ArchiveCollection.Definitions, world.EntityManager.DefinitionComposer);

// Modify shotgun sprite to blue key.
// This should cause the player to pickup a blue key instead of the shotgun
var def = GameActions.GetEntityDefinition(world, Chaingun);
Expand All @@ -51,6 +46,7 @@ public void PickupItemWithModifiedSprite()
[Fact(DisplayName = "Modified dehacked pickup carries over dropped")]
public void ModifiedDehackedPickupCarriesOverDropped()
{
Player.Inventory.Clear();
InventoryUtil.AssertAmount(Player, "Shell", 0);
var shotgun = GameActions.CreateEntity(World, "Shotgun", Vec3D.Zero);
World.PerformItemPickup(Player, shotgun);
Expand All @@ -63,6 +59,22 @@ public void ModifiedDehackedPickupCarriesOverDropped()
InventoryUtil.AssertAmount(Player, "Shell", 12);
}

[Fact(DisplayName = "Dropped ammo is not modified by skill multiplier")]
public void DroppedAmmo()
{
var ammoNames = World.ArchiveCollection.Dehacked!.AmmoNames.Union(World.ArchiveCollection.Dehacked.AmmoDoubleNames);
foreach (var ammo in ammoNames)
{
Player.Inventory.Clear();
var droppedAmmo = GameActions.CreateEntity(World, ammo, Vec3D.Zero);
var droppedAmmoDef = droppedAmmo.Definition;
droppedAmmo.Flags.SetDropped();
World.PerformItemPickup(Player, droppedAmmo);
var baseDef = Helion.World.Entities.Inventories.Inventory.GetBaseAmmoDef(droppedAmmoDef);
InventoryUtil.AssertAmount(Player, baseDef.Name, droppedAmmoDef.Properties.Inventory.Amount);
}
}

public void Dispose()
{
GameActions.DestroyCreatedEntities(World);
Expand Down
Loading