Files
necromants-tome-7d2d-3-2/HarmonySrc/DamagePatch.cs
T
Alex CubeandClaude Opus 5 e8f064f5ec Книга некроманта 1.0 — первая публичная версия
Мод для 7 Days to Die 3.2: навык «Некромантия», растущий от счётчика убитых
зомби, тёмное оружие с шестью собственными модами, призывная нежить, пирамида
духов и сюжетный финал через Чёрный портал. Локализация на 13 языках.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MaNro5hAGTzcQ7rJNN2tCX
2026-09-09 21:13:03 +03:00

58 lines
2.5 KiB
C#
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using HarmonyLib;
namespace NecromancerTome
{
/// <summary>
/// Lets a charmed ("Devi­ator"-hit) zombie actually hurt other zombies.
///
/// EntityAlive.DamageEntity has a hardcoded block, independent of anything AI/targeting
/// related: `if (!isHeatDamage &amp;&amp; (entityFlags &amp; attacker.entityFlags &amp; EntityFlags.Zombie) != None)
/// return -1;` - i.e. any two entities that are BOTH flagged EntityFlags.Zombie (which is
/// every zombie, always) simply cannot damage each other, full stop, no matter what
/// CharmPatch.cs did to the attacker's AI targeting. Without this, a charmed zombie would
/// walk up to another zombie and "attack" it forever with every hit landing as a no-op.
///
/// Fix: for the duration of a single DamageEntity call where the attacker currently has
/// buffNecroDeviatorCharm and the target is also a zombie, temporarily clear
/// EntityFlags.Zombie on the ATTACKER only (never the target, never persisted) so the AND
/// check in the original method comes up empty and damage proceeds normally. Restored
/// immediately afterward, so nothing else about that zombie (kill-counting via its Tags
/// property, quest tracking, anything else keyed off EntityFlags) is ever affected outside
/// this one call. A Stack (not a single field) survives re-entrant DamageEntity calls
/// correctly (e.g. explosions/knockback triggering further damage inside the same callstack).
/// </summary>
[HarmonyPatch(typeof(EntityAlive), "DamageEntity")]
public static class Patch_EntityAlive_DamageEntity_CharmedZombieVsZombie
{
public static readonly Stack<EntityZombie> ToggledAttackers = new Stack<EntityZombie>();
public static void Prefix(EntityAlive __instance, DamageSource _damageSource)
{
EntityZombie toggled = null;
if (__instance is EntityZombie && __instance.world != null)
{
EntityAlive attacker = __instance.world.GetEntity(_damageSource.getEntityId()) as EntityAlive;
if (attacker is EntityZombie attackerZombie
&& attackerZombie.Buffs != null
&& attackerZombie.Buffs.HasBuff(Patch_EntityBuffs_AddBuff_DeviatorCharm.CharmBuffName)
&& (attackerZombie.entityFlags & EntityFlags.Zombie) != EntityFlags.None)
{
attackerZombie.entityFlags &= ~EntityFlags.Zombie;
toggled = attackerZombie;
}
}
ToggledAttackers.Push(toggled);
}
public static void Postfix()
{
EntityZombie toggled = ToggledAttackers.Pop();
if (toggled != null)
{
toggled.entityFlags |= EntityFlags.Zombie;
}
}
}
}