[#12779] Lightning fix
自动翻译暂时不可用
本帖暂时展示 GitHub 原始内容。
I have read the contribution guidelines.
I have ensured that any new features or fixes in this PR function correctly in-game, if applicable.
I affirm that this code follows Mindustry's AI policy.
Fix owner attribution for bullets created by lightning
Problem
Bullets created by Lightning.createLightningInternal() do not inherit the owner of the bullet that triggered the lightning.
In the current implementation, hitCreate.create() is called with null as its first argument, which represents the owner of the newly created bullet. Although the original bullet (hitter) is passed as the final argument, this does not assign its owner to the newly created bullet.
As a result, lightning bullets can have a null owner even when the lightning was triggered by a bullet fired by a unit.
Impact
This causes incorrect ownership attribution for damage dealt by lightning.
For example, when a unit fires a projectile that triggers lightning, the lightning can destroy an enemy unit, but the resulting UnitBulletDestroyEvent contains a bullet whose owner is null. Systems that rely on this event to identify the killer cannot correctly attribute the kill to the unit that fired the original projectile.
This also affects server plugins that implement kill rewards, kill statistics, or other mechanics based on bullet ownership.
Root cause
The issue is in the call to hitCreate.create() inside Lightning.createLightningInternal():
hitCreate.create(null, team, x, y, rotation,
damage * (hitter == null ? 1f : hitter.damageMultiplier()),
1f, 1f, null);The first argument is the owner of the created bullet, but it is always null, regardless of whether an original bullet exists.
The original bullet's owner is available through hitter.owner, so the ownership information is already accessible at this point.
Proposed fix
Pass the original bullet's owner to hitCreate.create() when an original bullet exists:
hitCreate.create(hitter == null ? null : hitter.owner, team, x, y,
rotation, damage * (hitter == null ? 1f : hitter.damageMultiplier()),
1f, 1f, null);This preserves the existing behavior for lightning created without an originating bullet, while ensuring that lightning bullets inherit the owner of the original projectile when one is available.
Resulting behavior
Lightning bullets inherit the owner of the original projectile when one exists.
UnitBulletDestroyEventprovides the correct bullet ownership information when a unit is destroyed by lightning.Kill attribution and server-side mechanics that depend on bullet ownership work correctly for these kills.
Lightning created without an originating bullet retains a
nullowner.Damage calculation and all other arguments passed to
hitCreate.create()remain unchanged.
由 MDT GitHub 同步机器人自动同步。