356 lines
22 KiB
C#
356 lines
22 KiB
C#
namespace Harmony.NavObjectPatches
|
|
{
|
|
internal class NavObjectPatches
|
|
{
|
|
[HarmonyPatch(typeof(NetEntityDistributionEntry))]
|
|
[HarmonyPatch("updatePlayerEntity")]
|
|
public class updatePlayerEntityPatch
|
|
{
|
|
public static bool Prefix(NetEntityDistributionEntry __instance, EntityPlayer _ep,
|
|
Entity ___trackedEntity,
|
|
bool ___shouldSendMotionUpdates
|
|
)
|
|
{
|
|
if (__instance.trackedPlayers.Contains(_ep) && __instance.trackedEntity is EntityNPCRebirth)
|
|
{
|
|
EntityNPCRebirth npc = (EntityNPCRebirth)__instance.trackedEntity;
|
|
|
|
if (npc.LeaderUtils.Owner != null && npc.bIsChunkObserver)
|
|
{
|
|
//Log.Out("NavObjectPatches-updatePlayerEntity 9, entity: " + __instance.trackedEntity.EntityClass.entityClassName);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(NavObject))]
|
|
[HarmonyPatch("IsValidEntity")]
|
|
public class IsValidEntityPatch
|
|
{
|
|
public static bool Prefix(ref NavObject __instance, ref bool __result, EntityPlayerLocal player, Entity entity, NavObjectClass navObjectClass)
|
|
{
|
|
if (entity == null)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 1");
|
|
__result = true;
|
|
return false;
|
|
}
|
|
if (player == null)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 2");
|
|
__result = true;
|
|
return false;
|
|
}
|
|
|
|
if (entity is global::EntityAlive)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 3");
|
|
global::EntityAlive entityAlive = entity as global::EntityAlive;
|
|
|
|
bool purge = RebirthVariables.customScenario == "purge" && navObjectClass.NavObjectClassName == "purge_sleeper";
|
|
|
|
bool canSee = false;
|
|
|
|
if (purge)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 4");
|
|
|
|
if (!(entity is EntityPlayer || entity is EntityTrader))
|
|
{
|
|
__result = false;
|
|
|
|
//Log.Out("NavObjectPatches-IsValidEntity player.EntityName: " + player.EntityName);
|
|
|
|
//Log.Out("NavObjectPatches-IsValidEntity =====================");
|
|
//Log.Out("NavObjectPatches-IsValidEntity navObjectClass.NavObjectClassName: " + navObjectClass.NavObjectClassName);
|
|
//Log.Out("NavObjectPatches-IsValidEntity navObjectClass.RequirementName: " + navObjectClass.RequirementName);
|
|
//Log.Out("NavObjectPatches-IsValidEntity navObjectClass.RequirementType: " + navObjectClass.RequirementType);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entity: " + entity.EntityClass.entityClassName);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsSleeper: " + entityAlive.IsSleeper);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.sleepingOrWakingUp: " + entityAlive.sleepingOrWakingUp);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsSleeperPassive: " + entityAlive.IsSleeperPassive);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsSleeping: " + entityAlive.IsSleeping);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.pendingSleepTrigger: " + entityAlive.pendingSleepTrigger);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.EntityTags: " + entityAlive.EntityTags);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.bSpawned: " + entityAlive.bSpawned);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsAlive(): " + entityAlive.IsAlive());
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.hasHome(): " + entityAlive.hasHome());
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.isSnore: " + entityAlive.isSnore);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.sleepingOrWakingUp: " + entityAlive.sleepingOrWakingUp);
|
|
|
|
//Log.Out("NavObjectPatches-IsValidEntity RebirthVariables.maxSleeperVolumeCount: " + RebirthVariables.maxSleeperVolumeCount);
|
|
//Log.Out("NavObjectPatches-IsValidEntity RebirthVariables.currentSleeperVolumeCount: " + RebirthVariables.currentSleeperVolumeCount);
|
|
//Log.Out("NavObjectPatches-IsValidEntity RebirthVariables.currentSleeperVolumePerc: " + RebirthVariables.currentSleeperVolumePerc);
|
|
|
|
//float currentSleeperEntityCount = player.Buffs.GetCustomVar("$currentSleeperEntityCount");
|
|
float currentSleeperVolumeCount = RebirthVariables.currentSleeperVolumeCount;
|
|
float maxSleeperVolumeCount = RebirthVariables.maxSleeperVolumeCount;
|
|
float currentSleeperVolumePerc = RebirthVariables.currentSleeperVolumePerc;
|
|
float clearedSleeperVolumeCount = RebirthVariables.clearedSleeperVolumeCount;
|
|
float totalSleeperVolumeCount = RebirthVariables.totalSleeperVolumeCount;
|
|
|
|
float ratio = 0;
|
|
bool canProceed = false;
|
|
|
|
if (totalSleeperVolumeCount > 0)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 1");
|
|
/*ratio = (clearedSleeperVolumeCount / totalSleeperVolumeCount) * 100;
|
|
canProceed = ratio >= 50 && clearedSleeperVolumeCount > 0;
|
|
|
|
if (totalSleeperVolumeCount >= 10)
|
|
{
|
|
if (canProceed && currentSleeperVolumePerc > 0 && currentSleeperVolumePerc <= 20)
|
|
{
|
|
canSee = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (canProceed && currentSleeperVolumeCount <= 1)
|
|
{
|
|
canSee = true;
|
|
}
|
|
}*/
|
|
if (RebirthVariables.currentPOITier < 4)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 1");
|
|
if ((RebirthVariables.totalSleeperVolumeCount > 2) && (RebirthVariables.totalSleeperVolumeCount - RebirthVariables.clearedSleeperVolumeCount) <= 1)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 2");
|
|
canSee = true;
|
|
}
|
|
}
|
|
else if (RebirthVariables.currentPOITier == 4)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 3");
|
|
if ((RebirthVariables.totalSleeperVolumeCount - RebirthVariables.clearedSleeperVolumeCount) <= 2)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 4");
|
|
canSee = true;
|
|
}
|
|
}
|
|
else if (RebirthVariables.currentPOITier == 5)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 5");
|
|
if ((RebirthVariables.totalSleeperVolumeCount - RebirthVariables.clearedSleeperVolumeCount) <= 3)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 6");
|
|
canSee = true;
|
|
}
|
|
}
|
|
else if (RebirthVariables.currentPOITier >= 6)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 7");
|
|
if ((RebirthVariables.totalSleeperVolumeCount - RebirthVariables.clearedSleeperVolumeCount) <= 4)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 8");
|
|
canSee = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool flag1 = canSee && maxSleeperVolumeCount > 1 && entityAlive.IsSleeper;
|
|
bool flag2 = currentSleeperVolumeCount > 0 && entityAlive.IsSleeper && !entityAlive.IsSleeperPassive;
|
|
|
|
if (false && entityAlive.IsSleeper && entityAlive.IsAlive())
|
|
{
|
|
Log.Out("===============================================================================");
|
|
Log.Out("NavObjectPatches-IsValidEntity RebirthVariables.currentPOITier: " + RebirthVariables.currentPOITier);
|
|
Log.Out("NavObjectPatches-IsValidEntity entity: " + entity.EntityClass.entityClassName);
|
|
Log.Out("NavObjectPatches-IsValidEntity maxSleeperVolumeCount: " + maxSleeperVolumeCount);
|
|
Log.Out("NavObjectPatches-IsValidEntity currentSleeperVolumeCount: " + currentSleeperVolumeCount);
|
|
Log.Out("NavObjectPatches-IsValidEntity currentSleeperVolumePerc: " + currentSleeperVolumePerc);
|
|
Log.Out("NavObjectPatches-IsValidEntity clearedSleeperVolumeCount: " + clearedSleeperVolumeCount);
|
|
Log.Out("NavObjectPatches-IsValidEntity totalSleeperVolumeCount: " + totalSleeperVolumeCount);
|
|
//Log.Out("NavObjectPatches-IsValidEntity RebirthVariables.currentPrefab: " + RebirthVariables.currentPrefab);
|
|
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsSleeper: " + entityAlive.IsSleeper);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.sleepingOrWakingUp: " + entityAlive.sleepingOrWakingUp);
|
|
Log.Out("NavObjectPatches-IsValidEntity sleeperActivated: " + entityAlive.Buffs.GetCustomVar("$sleeperActivated"));
|
|
Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsSleeperPassive: " + entityAlive.IsSleeperPassive);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsSleeping: " + entityAlive.IsSleeping);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.pendingSleepTrigger: " + entityAlive.pendingSleepTrigger);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.EntityTags: " + entityAlive.EntityTags);
|
|
//Log.Out("NavObjectPatches-IsValidEntity entityAlive.bSpawned: " + entityAlive.bSpawned);
|
|
|
|
Log.Out("NavObjectPatches-IsValidEntity ratio: " + ratio);
|
|
Log.Out("NavObjectPatches-IsValidEntity canProceed: " + canProceed);
|
|
Log.Out("NavObjectPatches-IsValidEntity canSee: " + canSee);
|
|
Log.Out("NavObjectPatches-IsValidEntity flag1: " + flag1);
|
|
Log.Out("NavObjectPatches-IsValidEntity flag2: " + flag2);
|
|
|
|
Log.Out("NavObjectPatches-IsValidEntity maxSleeperVolumeCount > 0: " + (maxSleeperVolumeCount > 0));
|
|
Log.Out("NavObjectPatches-IsValidEntity !player.IsFlyMode.Value: " + !player.IsFlyMode.Value);
|
|
Log.Out("NavObjectPatches-IsValidEntity navObjectClass.RequirementType == NavObjectClass.RequirementTypes.QuestBounds: " + (navObjectClass.RequirementType == NavObjectClass.RequirementTypes.QuestBounds));
|
|
Log.Out("NavObjectPatches-IsValidEntity entityAlive.IsAlive(): " + entityAlive.IsAlive());
|
|
Log.Out("NavObjectPatches-IsValidEntity flag2: " + flag2);
|
|
|
|
}
|
|
|
|
if (maxSleeperVolumeCount > 0 &&
|
|
!player.IsFlyMode.Value && navObjectClass.RequirementType == NavObjectClass.RequirementTypes.QuestBounds &&
|
|
entityAlive.IsAlive())
|
|
{
|
|
if (canSee && maxSleeperVolumeCount > 1 && entityAlive.IsSleeper)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity A");
|
|
float sleeperActivated = entityAlive.Buffs.GetCustomVar("$sleeperActivated");
|
|
|
|
if (sleeperActivated == 0f)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity A1");
|
|
entityAlive.Buffs.SetCustomVar("$sleeperActivated", 1f);
|
|
return false;
|
|
}
|
|
else if (sleeperActivated == 2f)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity A2");
|
|
__result = true;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity A3");
|
|
return false;
|
|
}
|
|
}
|
|
else if (currentSleeperVolumeCount > 0 && entityAlive.IsSleeper && canSee) //) && !entityAlive.IsSleeperPassive)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity B");
|
|
float sleeperActivated = entityAlive.Buffs.GetCustomVar("$sleeperActivated");
|
|
if (sleeperActivated == 0f)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity A1");
|
|
entityAlive.Buffs.SetCustomVar("$sleeperActivated", 1f);
|
|
return false;
|
|
}
|
|
else if (sleeperActivated == 2f)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity A2");
|
|
__result = true;
|
|
return false;
|
|
}
|
|
}
|
|
/*else
|
|
{
|
|
Log.Out("NavObjectPatches-IsValidEntity C");
|
|
}*/
|
|
}
|
|
}
|
|
}
|
|
|
|
if (navObjectClass.RequirementType == NavObjectClass.RequirementTypes.None)
|
|
{
|
|
__result = entityAlive.IsAlive() && !entityAlive.IsSleeperPassive;
|
|
return false;
|
|
}
|
|
if (!entityAlive.IsAlive() || entityAlive.IsSleeperPassive)
|
|
{
|
|
__result = false;
|
|
return false;
|
|
}
|
|
switch (navObjectClass.RequirementType)
|
|
{
|
|
case NavObjectClass.RequirementTypes.CVar:
|
|
__result = entityAlive.GetCVar(navObjectClass.RequirementName) > 0f;
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.QuestBounds:
|
|
if (player.QuestJournal.ActiveQuest != null && entityAlive.IsSleeper)
|
|
{
|
|
|
|
Vector3 position = entity.position;
|
|
position.y = position.z;
|
|
if (player.ZombieCompassBounds.Contains(position))
|
|
{
|
|
if (purge)
|
|
{
|
|
if (canSee)
|
|
{
|
|
__result = true;
|
|
}
|
|
else
|
|
{
|
|
__result = false;
|
|
}
|
|
//Log.Out("NavObjectPatches-IsValidEntity QuestBounds __result: " + __result);
|
|
}
|
|
else
|
|
{
|
|
__result = true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
__result = false;
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.Tracking:
|
|
__result = EffectManager.GetValue(PassiveEffects.Tracking, null, 0f, player, null, entity.EntityTags, true, true, true, true, true, 1, false) > 0f;
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.InParty:
|
|
bool inParty = player.Party != null && player.Party.MemberList.Contains(entity as EntityPlayer) && entity != player && !(entity as EntityPlayer).IsSpectator;
|
|
bool isHire = false;
|
|
|
|
if (entity is EntityNPCRebirth)
|
|
{
|
|
EntityNPCRebirth npc = (EntityNPCRebirth)entity;
|
|
|
|
if (npc.LeaderUtils.Owner != null)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 9");
|
|
|
|
if (npc.LeaderUtils.Owner.entityId == player.entityId)
|
|
{
|
|
//Log.Out("NavObjectPatches-IsValidEntity 10");
|
|
isHire = true;
|
|
}
|
|
}
|
|
}
|
|
__result = inParty || isHire;
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.IsAlly:
|
|
__result = entity as EntityPlayer != null && (entity as EntityPlayer).IsFriendOfLocalPlayer && entity != player && !(entity as EntityPlayer).IsSpectator;
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.IsPlayer:
|
|
__result = entity == player;
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.IsVehicleOwner:
|
|
__result = (entity as EntityVehicle != null && (entity as EntityVehicle).HasOwnedEntity(player.entityId)) || (entity as EntityTurret != null && (entity as EntityTurret).belongsPlayerId == player.entityId);
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.NoActiveQuests:
|
|
__result = entity as EntityNPC == null || player.QuestJournal.FindReadyForTurnInQuestByGiver(entity.entityId) == null;
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.IsTwitchSpawnedSelf:
|
|
__result = entity.spawnById == player.entityId && !string.IsNullOrEmpty(entity.spawnByName);
|
|
return false;
|
|
case NavObjectClass.RequirementTypes.IsTwitchSpawnedOther:
|
|
__result = entity.spawnById > 0 && entity.spawnById != player.entityId && !string.IsNullOrEmpty(entity.spawnByName);
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NavObjectClass.RequirementTypes requirementType = navObjectClass.RequirementType;
|
|
if (requirementType == NavObjectClass.RequirementTypes.IsTwitchSpawnedSelf)
|
|
{
|
|
__result = entity.spawnById == player.entityId;
|
|
return false;
|
|
}
|
|
if (requirementType == NavObjectClass.RequirementTypes.IsTwitchSpawnedOther)
|
|
{
|
|
__result = entity.spawnById > 0 && entity.spawnById != player.entityId;
|
|
return false;
|
|
}
|
|
}
|
|
__result = true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|