Upload from upload_mods.ps1
This commit is contained in:
147
Harmony/Harmony_AutoTurretFireController.cs
Normal file
147
Harmony/Harmony_AutoTurretFireController.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
namespace Harmony.AutoTurretFireControllerPatches
|
||||
{
|
||||
[HarmonyPatch(typeof(AutoTurretFireController))]
|
||||
[HarmonyPatch("shouldIgnoreTarget")]
|
||||
public class shouldIgnoreTargetPatch
|
||||
{
|
||||
public static bool Prefix(AutoTurretFireController __instance, ref bool __result, Entity _target,
|
||||
ref EntityAlive ___currentEntityTarget
|
||||
)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget START _target: " + _target.EntityClass.entityClassName);
|
||||
__result = false;
|
||||
|
||||
if (Vector3.Dot(_target.position - __instance.TileEntity.ToWorldPos().ToVector3(), __instance.Cone.transform.forward) > 0f)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 1");
|
||||
if (_target == ___currentEntityTarget)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 2");
|
||||
___currentEntityTarget = null;
|
||||
}
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (!_target.IsAlive())
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 3");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (_target is EntitySupplyCrate || _target is EntityTurret || _target is EntityDrone)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 4");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (_target is EntityVehicle)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 5");
|
||||
Entity attachedMainEntity = (_target as EntityVehicle).AttachedMainEntity;
|
||||
if (attachedMainEntity == null)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 6");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
_target = attachedMainEntity;
|
||||
}
|
||||
if (_target is EntityZombieSDX && !__instance.TileEntity.TargetZombies)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 7");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
PersistentPlayerList persistentPlayerList = GameManager.Instance.GetPersistentPlayerList();
|
||||
PersistentPlayerData playerData = persistentPlayerList.GetPlayerData(__instance.TileEntity.GetOwner());
|
||||
|
||||
if (_target is EntityPlayer)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 8");
|
||||
bool flag = false;
|
||||
bool flag2 = false;
|
||||
EnumPlayerKillingMode @int = (EnumPlayerKillingMode)GamePrefs.GetInt(EnumGamePrefs.PlayerKillingMode);
|
||||
if (persistentPlayerList != null && persistentPlayerList.EntityToPlayerMap.ContainsKey(_target.entityId) && __instance.TileEntity.IsOwner(persistentPlayerList.EntityToPlayerMap[_target.entityId].PrimaryId))
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 9");
|
||||
flag = true;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 10");
|
||||
if (playerData != null && persistentPlayerList.EntityToPlayerMap.ContainsKey(_target.entityId))
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 11");
|
||||
PersistentPlayerData persistentPlayerData = persistentPlayerList.EntityToPlayerMap[_target.entityId];
|
||||
if (playerData.ACL != null && persistentPlayerData != null && playerData.ACL.Contains(persistentPlayerData.PrimaryId))
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 12");
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (@int == EnumPlayerKillingMode.NoKilling)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 13");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (flag && !__instance.TileEntity.TargetSelf)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 14");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (flag2 && (!__instance.TileEntity.TargetAllies || (@int != EnumPlayerKillingMode.KillEveryone && @int != EnumPlayerKillingMode.KillAlliesOnly)))
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 15");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (!flag && !flag2 && (!__instance.TileEntity.TargetStrangers || (@int != EnumPlayerKillingMode.KillStrangersOnly && @int != EnumPlayerKillingMode.KillEveryone)))
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 16");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerData != null)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 17");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)GameManager.Instance.World.GetEntity(playerData.EntityId);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 18");
|
||||
__result = !RebirthUtilities.VerifyFactionStanding(entityPlayer, (EntityAlive)_target);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Owner is not online
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget 18");
|
||||
string sourceFaction = "";
|
||||
string targetFaction = "";
|
||||
|
||||
if (__instance.TileEntity.blockValue.Block.Properties.Values.ContainsKey("Faction"))
|
||||
{
|
||||
sourceFaction = __instance.TileEntity.blockValue.Block.Properties.Values["Faction"];
|
||||
}
|
||||
if (_target.EntityClass.Properties.Values.ContainsKey("Faction"))
|
||||
{
|
||||
targetFaction = _target.EntityClass.Properties.Values["Faction"];
|
||||
}
|
||||
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget sourceFaction: " + sourceFaction);
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget targetFaction: " + targetFaction);
|
||||
|
||||
__result = !RebirthUtilities.VerifyFactionStandingDetails(sourceFaction, targetFaction);
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("AutoTurretFireControllerPatches-shouldIgnoreTarget __result: " + __result);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user