Group friendly fire: block at the source seams (3/4, part of #277) - #303
Open
Zaldaryon wants to merge 1 commit into
Open
Group friendly fire: block at the source seams (3/4, part of #277)#303Zaldaryon wants to merge 1 commit into
Zaldaryon wants to merge 1 commit into
Conversation
The #300 hook in EntityPlayer.ShouldReceiveDamage stops the damage but runs late: for melee it is already past the slap sound, the weapon durability tick in Collectible.OnAttackingWith, and the interact event that combat-tags both players. A blocked shot likewise still paid the arrow its durability and impact sound. This adds the group check at the two seams where an attack is decided: - HandleEntityInteraction, right after the vanilla PvP gate, through StratumFriendlyFireGuard. Returning there is exactly the vanilla PvP-off path: no interact event, so no slap, no durability loss, no combat-log tag. - EntityProjectileBase.CanDealDamage, beside the existing AllowPvP check. ImpactOnEntity then skips the sound, the damage, and the projectile durability hit. Both fire StratumFriendlyFireHook.OnBlockedAttack, which StratumFriendlyFireSystem points at a per-attacker throttled notice (FriendlyFire.NotifyBlockedAttacker / NotifyThrottleMs / BlockedMessage) and a blocked-hit counter shown in /friendlyfire status. The ShouldReceiveDamage hook stays as the catch-all for mod-authored damage and for the explosion test source. No combat tag on a blocked hit is deliberate: a hit that deals no damage is not combat, and letting a group mate tag you by spam-clicking would be an exploit. Part of #277
Zaldaryon
marked this pull request as ready for review
September 7, 2026 21:42
This was referenced Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third of four stacked follow-ups to #300. Moves the group friendly fire block from the health check up to the two seams where an attack is actually decided, which fixes three of #300's stated limitations at once.
Base branch is
feat/issue-277-ff-explosions(PR 2/4).Why
The #300 hook in
EntityPlayer.ShouldReceiveDamagestops the damage but runs late. By the time it fires, a melee swing has already:sounds/player/slap(EntityAgent.OnInteract),Collectible.OnAttackingWithcallsDamageItem),OnPlayerInteractEntity, which combat-tags both players (StratumCombatLogSystem).A blocked shot similarly still paid the arrow its durability and impact sound in
ImpactOnEntity.Change
sources/VintagestoryApi/Server/StratumFriendlyFireHook.cs: addsOnBlockedAttack, anAction<string,string>the seams call so the notice logic lives in one place.sources/VintagestoryLib/Vintagestory.Server/StratumFriendlyFireGuard.cs(new):BlocksMeleeAttack, so the vanilla patch stays a one-line call.patches/VintagestoryLib/Vintagestory.Server/ServerSystemEntitySimulation.cs.patch: the guard call inHandleEntityInteraction, right after the vanilla PvP gate, only for attacks (flag), never right-click interactions like healing a group mate. Returning there is exactly the vanilla PvP-off path: no interact event, so no slap, no durability, no combat tag.patches/VSEssentials/Entities/EntityProjectileBase.cs.patch: the same rule inlined inCanDealDamagenext to the existingAllowPvPcheck (VSEssentials cannot reference VintagestoryLib, so it uses the API-only types and fires the hook directly).sources/VintagestoryLib/Vintagestory.Server/StratumFriendlyFireSystem.cs:OnBlockedAttackpoints at a per-attacker throttled chat notice and a blocked-hit counter shown in/friendlyfire status.sources/VintagestoryLib/Vintagestory.Server/StratumFriendlyFireConfig.cs:NotifyBlockedAttacker(default true),NotifyThrottleMs(default 3000, clamped 500 to 60000),BlockedMessage.StratumConfigwires theEnsureSanecall.docs/commands/friendlyfire.md: the new config keys and the status counter.The
ShouldReceiveDamagehook from #300 stays as the catch-all for mod-authored damage that callsReceiveDamagenormally, and as the test source for the explosion filter.No combat tag on a blocked hit
This inverts what #300's body asked for. Today a blocked melee swing wrongly tags both players (the projectile path already does not tag, gated on
didDamage). A hit that deals no damage is not combat, and letting a group mate tag you by holding left-click is an exploit. The melee seam returning beforeTriggerPlayerInteractEntityfixes it for free, no change toStratumCombatLogSystem.Gates
NU1904.bash scripts/smoke-test.sh:PASS ... 13 console command(s) verified.scripts/extract-patches.sh:ServerSystemEntitySimulation.cs.patchandEntityProjectileBase.cs.patchonly. The SSE patch has one two-line brace reshuffle from the local decompiler in an unrelated adjacent hunk, otherwise the diff is the new melee hunk plus offset bumps.ServerMain.cs.patchfrom PR 2 is left untouched.Limitations
Entity.ReceiveDamage, the interaction handler, or the projectile path and skips the original still bypasses this. PR 4/4 logs a warning naming such a mod. No server platform can hard-prevent it./friendlyfire statuscounter is the visibility.Type
Checklist
scripts/extract-patches.shran clean.dotnet build VintageStory.slnx -c Release -p:EmbedPatchedFiles=trueis green.// Stratummarker.Related issues
Part of #277