Barotrauma icon indicating copy to clipboard operation
Barotrauma copied to clipboard

MeleeWeapon does not specify the target component when creating EntityEvent

Open zhu-rengong opened this issue 1 year ago • 2 comments

Disclaimers

  • [X] I have searched the issue tracker to check if the issue has already been reported.
  • [ ] My issue happened while using mods.

What happened?

As the title said, check the following code: https://github.com/FakeFishGames/Barotrauma/blob/0c433eb187b20f4bd24a1919b478529b387ee0bf/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Holdable/MeleeWeapon.cs#L477-L478 It will cause async on the client side Should change it to:

server.CreateEntityEvent(item, new Item.ApplyStatusEffectEventData(conditionalActionType, targetItemComponent: this, targetCharacter, targetLimb, useTarget: targetEntity));
server.CreateEntityEvent(item, new Item.ApplyStatusEffectEventData(ActionType.OnUse, targetItemComponent: this, targetCharacter, targetLimb, useTarget: targetEntity));

Reproduction steps

  1. Subscribe the mod(OTFX): https://steamcommunity.com/sharedfiles/filedetails/?id=2986787106
  2. Host a server and start game
  3. Enter cheat code: spawnitem otfx_assaultrifle2 inventory
  4. Double click RMB to switch attack mode for using its melee weapon
  5. Melee attack at something, you will notice your screen is shaking
  6. Shaking will not happen in single player mode

https://github.com/FakeFishGames/Barotrauma/assets/73634685/4f27760b-0172-44db-ab3d-283e48ccb687

Bug prevalence

Happens every now and then

Single player or multiplayer?

Multiplayer hosted from the in-game menu (= using a listen server)

-

No response

Version

v1.2.8.0 (Winter Update hotfix 2)

-

No response

Which operating system did you encounter this bug on?

Windows

Relevant error messages and crash reports

No response

zhu-rengong avatar Feb 07 '24 15:02 zhu-rengong

Reproduction steps

  1. Subscribe the mod(OTFX): https://steamcommunity.com/sharedfiles/filedetails/?id=2986787106
  2. Host a server and start game
  3. Enter cheat code: spawnitem otfx_assaultrifle2 inventory
  4. Double click RMB to switch attack mode for using its melee weapon
  5. Melee attack at something, you will notice your screen is shaking
  6. Shaking will not happen in single player mode

Please note that I have fixed this problem in the otfx mod through a workaround; if you need to use this mod for testing, you need to find the xml code with the identifier otfx_assaultrifle2 and replace the following code:

  1. Replace
<StatusEffect type="OnUse" target="This" targetitemcomponent="RangedWeapon" reloadtimer="+0.5" isactive="true" disabledeltatime="true">
  <Explosion range="150.0" force="2" shockwave="false" smoke="false" flames="false" flash="true" sparks="false" underwaterbubble="false" applyfireeffects="false" camerashake="6.0" />
  <!-- Workaround to fix async on client side by this way here and other places, the issue has been reporeted in https://github.com/FakeFishGames/Barotrauma/issues/13405 -->
  <RequiredItems items="otfx_assaultrifle2rw" type="Contained" />
</StatusEffect>

With

<StatusEffect type="OnUse" target="This" targetitemcomponent="RangedWeapon" reloadtimer="+0.5" isactive="true" disabledeltatime="true">
  <Explosion range="150.0" force="2" shockwave="false" smoke="false" flames="false" flash="true" sparks="false" underwaterbubble="false" applyfireeffects="false" camerashake="6.0" />
</StatusEffect>
  1. Replace
<StatusEffect type="OnUse">
  <ParticleEmitter particle="casingfirearm" particleamount="1" copyentityangle="true" anglemin="90" anglemax="150" velocitymin="50" velocitymax="250" />
  <Explosion range="150.0" force="1" shockwave="false" smoke="false" flames="false" sparks="false" underwaterbubble="false" camerashake="12.0" />
  <RequiredItems items="otfx_assaultrifle2rw" type="Contained" />
</StatusEffect>

With

<StatusEffect type="OnUse">
  <ParticleEmitter particle="casingfirearm" particleamount="1" copyentityangle="true" anglemin="90" anglemax="150" velocitymin="50" velocitymax="250" />
  <Explosion range="150.0" force="1" shockwave="false" smoke="false" flames="false" sparks="false" underwaterbubble="false" camerashake="12.0" />
</StatusEffect>

zhu-rengong avatar Feb 14 '24 17:02 zhu-rengong

Fixed in https://github.com/FakeFishGames/Barotrauma-development/commit/538899695494acc73730df348723572791cfdd90

Regalis11 avatar Feb 19 '24 10:02 Regalis11

Merged, closing

Regalis11 avatar Jun 25 '24 06:06 Regalis11