459 lines
22 KiB
C#
459 lines
22 KiB
C#
using Audio;
|
|
|
|
namespace Harmony.EntityPlayerPatches
|
|
{
|
|
[HarmonyPatch(typeof(EntityPlayer))]
|
|
[HarmonyPatch("Teleport")]
|
|
public static class TeleportPatch
|
|
{
|
|
public static bool Prefix(EntityPlayer __instance, Vector3 _pos, float _dir)
|
|
{
|
|
__instance.Buffs.AddBuff("FuriousRamsayDelay-5");
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
[HarmonyPatch(typeof(EntityPlayer))]
|
|
[HarmonyPatch("unModifiedGameStage")]
|
|
[HarmonyPatch(MethodType.Getter)]
|
|
public static class unModifiedGameStagePatch
|
|
{
|
|
public static void Postfix(EntityPlayer __instance, ref int __result,
|
|
QuestJournal ___QuestJournal,
|
|
ulong ___gameStageBornAtWorldTime
|
|
)
|
|
{
|
|
float modifiedGamestage = __instance.Progression.Level * RebirthVariables.playerLevelGamestageMultiplier * GameStats.GetFloat(EnumGameStats.GameDifficultyBonus);
|
|
|
|
float adjustedGamestage = __instance.Buffs.GetCustomVar("$GamestageDecrease");
|
|
|
|
if (adjustedGamestage > 0)
|
|
{
|
|
modifiedGamestage = modifiedGamestage - (modifiedGamestage * adjustedGamestage);
|
|
}
|
|
|
|
__result = Mathf.FloorToInt(EffectManager.GetValue(PassiveEffects.GameStage, null, modifiedGamestage, __instance, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1, false));
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityPlayer))]
|
|
[HarmonyPatch("gameStage")]
|
|
[HarmonyPatch(MethodType.Getter)]
|
|
public static class gameStagePatch
|
|
{
|
|
public static void Postfix(EntityPlayer __instance, ref int __result,
|
|
QuestJournal ___QuestJournal,
|
|
ulong ___gameStageBornAtWorldTime
|
|
)
|
|
{
|
|
float modifiedGamestage = __instance.Progression.Level * RebirthVariables.playerLevelGamestageMultiplier * GameStats.GetFloat(EnumGameStats.GameDifficultyBonus);
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage __instance.Progression.Level: " + __instance.Progression.Level);
|
|
//Log.Out("EntityPlayerPatches-gameStage modifiedGamestage BEFORE: " + modifiedGamestage);
|
|
//Log.Out("EntityPlayerPatches-gameStage RebirthVariables.playerLevelGamestageMultiplier: " + RebirthVariables.playerLevelGamestageMultiplier);
|
|
//Log.Out("EntityPlayerPatches-gameStage GameStats.GetFloat(EnumGameStats.GameDifficultyBonus): " + GameStats.GetFloat(EnumGameStats.GameDifficultyBonus));
|
|
|
|
float adjustedGamestage = __instance.Buffs.GetCustomVar("$GamestageDecrease");
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage adjustedGamestage: " + adjustedGamestage);
|
|
|
|
/*PrefabInstance poiatPosition = RebirthUtilities.GetPrefabAtPosition(__instance.position); //__instance.world.GetPOIAtPosition(__instance.position, false);
|
|
|
|
int prefabGamestage = 0;
|
|
|
|
if (poiatPosition != null)
|
|
{
|
|
int tier = poiatPosition.prefab.DifficultyTier;
|
|
|
|
if (tier > 0)
|
|
{
|
|
prefabGamestage = RebirthUtilities.AdjustGamestage((int)modifiedGamestage, tier);
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage prefabGamestage: " + prefabGamestage);
|
|
|
|
modifiedGamestage = modifiedGamestage + prefabGamestage;*/
|
|
|
|
if (adjustedGamestage > 0)
|
|
{
|
|
modifiedGamestage = modifiedGamestage - (modifiedGamestage * adjustedGamestage);
|
|
}
|
|
|
|
if (RebirthUtilities.IsHordeNight())
|
|
{
|
|
modifiedGamestage = Mathf.FloorToInt(EffectManager.GetValue(PassiveEffects.GameStage, null, modifiedGamestage, __instance, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1, false));
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage modifiedGamestage HORDE NIGHT: " + modifiedGamestage);
|
|
|
|
__result = (int)modifiedGamestage;
|
|
return;
|
|
}
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage modifiedGamestage AFTER: " + modifiedGamestage);
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage __instance.Progression.Level: " + __instance.Progression.Level);
|
|
//Log.Out("EntityPlayerPatches-gameStage playerLevelGamestageMultiplier: " + RebirthVariables.playerLevelGamestageMultiplier);
|
|
|
|
float questGameStageMod = 0f;
|
|
float questGameStageBonus = 0f;
|
|
if (___QuestJournal.ActiveQuest != null)
|
|
{
|
|
questGameStageMod = ___QuestJournal.ActiveQuest.QuestClass.GameStageMod;
|
|
questGameStageBonus = ___QuestJournal.ActiveQuest.QuestClass.GameStageBonus;
|
|
}
|
|
|
|
float gamestageMod = 0f;
|
|
float gamestageBonus = 0f;
|
|
|
|
string biomeName = "";
|
|
|
|
if (__instance.biomeStandingOn != null)
|
|
{
|
|
gamestageMod = __instance.biomeStandingOn.GameStageMod;
|
|
gamestageBonus = __instance.biomeStandingOn.GameStageBonus;
|
|
}
|
|
else
|
|
{
|
|
BiomeDefinition biomeAt = GameManager.Instance.World.ChunkCache.ChunkProvider.GetBiomeProvider().GetBiomeAt((int)__instance.position.x, (int)__instance.position.z);
|
|
|
|
if (biomeAt != null)
|
|
{
|
|
gamestageMod = biomeAt.GameStageMod;
|
|
gamestageBonus = biomeAt.GameStageBonus;
|
|
}
|
|
}
|
|
|
|
//if (__instance.biomeStandingOn != null)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-gameStage questGameStageMod: " + questGameStageMod);
|
|
//Log.Out("EntityPlayerPatches-gameStage questGameStageBonus: " + questGameStageBonus);
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage GameStageMod: " + gamestageMod);
|
|
//Log.Out("EntityPlayerPatches-gameStage GameStageBonus: " + gamestageBonus);
|
|
|
|
modifiedGamestage = modifiedGamestage * (1f + questGameStageMod + gamestageMod) + (questGameStageBonus + gamestageBonus);
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage modifiedGamestage: " + modifiedGamestage);
|
|
|
|
__result = Mathf.FloorToInt(EffectManager.GetValue(PassiveEffects.GameStage, null, modifiedGamestage, __instance, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1, false));
|
|
//Log.Out("EntityPlayerPatches-gameStage A __result: " + __result);
|
|
|
|
return;
|
|
}
|
|
|
|
/*modifiedGamestage = modifiedGamestage * (1f + questGameStageMod) + (questGameStageBonus);
|
|
|
|
//Log.Out("EntityPlayerPatches-gameStage modifiedGamestage: " + modifiedGamestage);
|
|
|
|
__result = Mathf.FloorToInt(EffectManager.GetValue(PassiveEffects.GameStage, null, modifiedGamestage, __instance, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1, false));
|
|
//Log.Out("EntityPlayerPatches-gameStage B __result: " + __result);*/
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityPlayer))]
|
|
[HarmonyPatch("DamageEntity")]
|
|
public class DamageEntityPatch
|
|
{
|
|
private static bool Prefix(EntityPlayer __instance, ref int __result, DamageSource _damageSource, int _strength, bool _criticalHit, float _impulseScale,
|
|
ref float ___accumulatedDamageResisted
|
|
)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity __instance.EntityName: " + __instance.EntityName);
|
|
|
|
if (RebirthVariables.noHit)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity IsPlayerDamageEnabled: " + GameStats.GetBool(EnumGameStats.IsPlayerDamageEnabled));
|
|
}
|
|
|
|
if (_damageSource.AttackingItem != null)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity _damageSource.AttackingItem.ItemClass.GetItemName(): " + _damageSource.AttackingItem.ItemClass.GetItemName());
|
|
}
|
|
if (_damageSource.BuffClass != null)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity _damageSource.BuffClass.Name: " + _damageSource.BuffClass.Name);
|
|
}
|
|
if (_damageSource.ItemClass != null)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity _damageSource.ItemClass.Name: " + _damageSource.ItemClass.Name);
|
|
}
|
|
|
|
EntityAlive entityAlive = __instance.world.GetEntity(_damageSource.getEntityId()) as EntityAlive;
|
|
|
|
if (entityAlive != null)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity entityAlive.EntityName: " + entityAlive.EntityName);
|
|
}
|
|
|
|
bool canDamage = RebirthUtilities.VerifyFactionStanding(entityAlive, __instance);
|
|
|
|
if (__instance.Buffs.HasBuff("FuriousRamsayProcessRespawnDebuffs"))
|
|
{
|
|
canDamage = false;
|
|
}
|
|
|
|
//Log.Out("EntityPlayerPatches-DamageEntity canDamage: " + canDamage);
|
|
|
|
if (__instance.AttachedToEntity)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity IS ATTACHED");
|
|
if (canDamage)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity CAN DAMAGE");
|
|
EntityAlive vehicle = __instance.AttachedToEntity as EntityAlive;
|
|
|
|
if (vehicle != null)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity vehicle: " + vehicle.EntityName);
|
|
|
|
bool hasProtection = !vehicle.HasAnyTags(FastTags<TagGroup.Global>.Parse("noprotection"));
|
|
|
|
//Log.Out("EntityPlayerPatches-DamageEntity hasProtection: " + hasProtection);
|
|
//Log.Out("EntityPlayerPatches-DamageEntity BEFORE vehicle.Health: " + vehicle.Health);
|
|
|
|
if (!hasProtection ||
|
|
vehicle.Health <= 1)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity Direct Damage to the Player");
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityPlayerPatches-DamageEntity Direct Damage to the Vehicle, _strength: " + _strength);
|
|
vehicle.DamageEntity(_damageSource, _strength * 10, _criticalHit, _impulseScale);
|
|
//Log.Out("EntityPlayerPatches-DamageEntity AFTER vehicle.Health: " + vehicle.Health);
|
|
|
|
//if (entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("animal")))
|
|
{
|
|
}
|
|
|
|
if (entityAlive is EntityAliveV2)
|
|
{
|
|
if (entityAlive.inventory.holdingItem.HasAnyTags(FastTags<TagGroup.Global>.Parse("ranged")))
|
|
{
|
|
Manager.PlayInsidePlayerHead("bullethitmetal", __instance.entityId);
|
|
}
|
|
else if (entityAlive.inventory.holdingItem.HasAnyTags(FastTags<TagGroup.Global>.Parse("organic")))
|
|
{
|
|
Manager.PlayInsidePlayerHead("organichitmetal", __instance.entityId);
|
|
}
|
|
else if (entityAlive.inventory.holdingItem.HasAnyTags(FastTags<TagGroup.Global>.Parse("metal")))
|
|
{
|
|
Manager.PlayInsidePlayerHead("metalhitmetal", __instance.entityId);
|
|
}
|
|
else if (entityAlive.inventory.holdingItem.HasAnyTags(FastTags<TagGroup.Global>.Parse("wood")))
|
|
{
|
|
Manager.PlayInsidePlayerHead("woodhitmetal", __instance.entityId);
|
|
}
|
|
else if (entityAlive.inventory.holdingItem.HasAnyTags(FastTags<TagGroup.Global>.Parse("wood")))
|
|
{
|
|
Manager.PlayInsidePlayerHead("woodhitmetal", __instance.entityId);
|
|
}
|
|
//Manager.PlayInsidePlayerHead("stonehitmetal", __instance.entityId);
|
|
}
|
|
else
|
|
{
|
|
Manager.PlayInsidePlayerHead("organichitmetal", __instance.entityId);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (_damageSource.ItemClass != null && (_damageSource.ItemClass.GetItemName() == "auraExplosion" || _damageSource.ItemClass.GetItemName() == "otherExplosion"))
|
|
{
|
|
//Log.Out($"HarmonyPatch-EntityPlayer::DamageEntity this: {__instance} - returning 0 damage false. Dmg type Heat, auraExplosion - Dmg source: {entityAlive}, faction: {entityAlive.Buffs.GetCustomVar("$faction")}");
|
|
__result = 0;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (entityAlive != null && entityAlive is EntityAliveV2)
|
|
{
|
|
if (!canDamage)
|
|
{
|
|
//Log.Out($"HarmonyPatch-EntityPlayer::DamageEntity this: {__instance} - returning 0 damage false. !canDamage - Dmg source: {entityAlive}, faction: {entityAlive.Buffs.GetCustomVar("$faction")}");
|
|
__result = 0;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// REMOVE WHEN NO HIT IS FIXED - VANILLA CODE - SIMPLY RETURN TRUE
|
|
EnumDamageSource source = _damageSource.GetSource();
|
|
if (_damageSource.IsIgnoreConsecutiveDamages() && source != EnumDamageSource.Internal)
|
|
{
|
|
if (__instance.damageSourceTimeouts.ContainsKey(source) && GameTimer.Instance.ticks - __instance.damageSourceTimeouts[source] < 30UL)
|
|
{
|
|
if (RebirthVariables.noHit)
|
|
{
|
|
Log.Out("EntityPlayerPatches-DamageEntity NO HIT, damageSourceTimeouts");
|
|
}
|
|
__result = -1;
|
|
return false;
|
|
}
|
|
__instance.damageSourceTimeouts[source] = GameTimer.Instance.ticks;
|
|
}
|
|
EntityAlive entity1 = __instance.world.GetEntity(_damageSource.getEntityId()) as EntityAlive;
|
|
if (!__instance.FriendlyFireCheck(entity1))
|
|
{
|
|
if (RebirthVariables.noHit)
|
|
{
|
|
Log.Out("EntityPlayerPatches-DamageEntity NO HIT, FriendlyFireCheck: " + __instance.FriendlyFireCheck(entity1));
|
|
}
|
|
__result = -1;
|
|
return false;
|
|
}
|
|
bool flag = _damageSource.GetDamageType() == EnumDamageTypes.Heat;
|
|
if (!flag && (bool)(UnityEngine.Object)entity1 && (__instance.entityFlags & entity1.entityFlags & EntityFlags.Zombie) > EntityFlags.None || __instance.IsGodMode.Value)
|
|
{
|
|
if (RebirthVariables.noHit)
|
|
{
|
|
Log.Out("EntityPlayerPatches-DamageEntity NO HIT, entityFlags: " + __instance.entityFlags);
|
|
}
|
|
__result = -1;
|
|
return false;
|
|
}
|
|
if (!__instance.IsDead() && (bool)(UnityEngine.Object)entity1)
|
|
{
|
|
float num = EffectManager.GetValue(PassiveEffects.DamageBonus, _entity: entity1);
|
|
if ((double)num > 0.0)
|
|
{
|
|
_damageSource.DamageMultiplier = num;
|
|
_damageSource.BonusDamageType = EnumDamageBonusType.Sneak;
|
|
}
|
|
}
|
|
float num1 = EffectManager.GetValue(PassiveEffects.GeneralDamageResist, _entity: __instance);
|
|
float num2 = (float)_strength * num1 + __instance.accumulatedDamageResisted;
|
|
int num3 = (int)num2;
|
|
__instance.accumulatedDamageResisted = num2 - (float)num3;
|
|
_strength -= num3;
|
|
DamageResponse _dmResponse = __instance.damageEntityLocal(_damageSource, _strength, _criticalHit, _impulseScale);
|
|
NetPackage _package = (NetPackage)NetPackageManager.GetPackage<NetPackageDamageEntity>().Setup(__instance.entityId, _dmResponse);
|
|
if (__instance.world.IsRemote())
|
|
{
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(_package);
|
|
}
|
|
else
|
|
{
|
|
int _excludePlayer = -1;
|
|
if (!flag && _damageSource.CreatorEntityId != -2)
|
|
{
|
|
_excludePlayer = _damageSource.getEntityId();
|
|
if (_damageSource.CreatorEntityId != -1)
|
|
{
|
|
Entity entity2 = __instance.world.GetEntity(_damageSource.CreatorEntityId);
|
|
if ((bool)(UnityEngine.Object)entity2 && !entity2.isEntityRemote)
|
|
_excludePlayer = -1;
|
|
}
|
|
}
|
|
__instance.world.entityDistributer.SendPacketToTrackedPlayersAndTrackedEntity(__instance.entityId, _excludePlayer, _package);
|
|
}
|
|
|
|
if (RebirthVariables.noHit)
|
|
{
|
|
Log.Out("EntityPlayerPatches-DamageEntity NO HIT, __result: " + __result);
|
|
}
|
|
__result = _dmResponse.ModStrength;
|
|
// REMOVE WHEN NO HIT IS FIXED - VANILLA CODE - SIMPLY RETURN TRUE
|
|
|
|
return false;
|
|
}
|
|
|
|
private static void Postfix(EntityPlayer __instance, ref int __result, DamageSource _damageSource, int _strength, bool _criticalHit, float _impulseScale)
|
|
{
|
|
if (__instance.Health == 0)
|
|
{
|
|
EntityAlive entityAlive = __instance.world.GetEntity(_damageSource.getEntityId()) as EntityAlive;
|
|
|
|
if (entityAlive != null && entityAlive is EntityZombie)
|
|
{
|
|
if (entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("radiated")))
|
|
{
|
|
__instance.Buffs.SetCustomVar("$ZombieKilledMe", 3f);
|
|
}
|
|
else if (entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("feral")))
|
|
{
|
|
__instance.Buffs.SetCustomVar("$ZombieKilledMe", 2f);
|
|
}
|
|
else
|
|
{
|
|
__instance.Buffs.SetCustomVar("$ZombieKilledMe", 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityPlayer))]
|
|
[HarmonyPatch("AddKillXP")]
|
|
public class AddKillXPPatch
|
|
{
|
|
private static bool Prefix(EntityPlayer __instance, global::EntityAlive killedEntity, float xpModifier = 1f)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-AddKillXP START, xpModifier: " + xpModifier);
|
|
int num = EntityClass.list[killedEntity.entityClass].ExperienceValue;
|
|
num = (int)EffectManager.GetValue(PassiveEffects.ExperienceGain, killedEntity.inventory.holdingItemItemValue, (float)num, killedEntity, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1, false);
|
|
if (xpModifier != 1f)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-AddKillXP BEFORE 1, num: " + num);
|
|
num = (int)((float)num * xpModifier);
|
|
//Log.Out("EntityPlayerPatches-AddKillXP AFTER 1, num: " + num);
|
|
}
|
|
if (__instance.IsInParty())
|
|
{
|
|
num = __instance.Party.GetPartyXP(__instance, num);
|
|
//Log.Out("EntityPlayerPatches-AddKillXP 2 IN PARTY, num: " + num);
|
|
}
|
|
|
|
/*if (SkyManager.IsBloodMoonVisible())
|
|
{
|
|
ulong worldTime = GameManager.Instance.World.worldTime;
|
|
ValueTuple<int, int, int> valueTuple = GameUtils.WorldTimeToElements(worldTime);
|
|
|
|
int num1 = valueTuple.Item2;
|
|
int num2 = valueTuple.Item3;
|
|
|
|
int numDaylength = GamePrefs.GetInt(EnumGamePrefs.DayLightLength);
|
|
|
|
int numOpenTime = 22 - numDaylength;
|
|
|
|
if ((num1 == 22 && num2 >= 0) || (num1 >= 22) || num1 < numOpenTime)
|
|
{
|
|
num = (int)(num * 0.1);
|
|
Log.Out("EntityPlayerPatches-AddKillXP 2 HORDE NIGHT, num: " + num);
|
|
}
|
|
}*/
|
|
|
|
if (RebirthUtilities.IsHordeNight())
|
|
{
|
|
//Log.Out("EntityPlayerPatches-AddKillXP IS HORDE NIGHT, BEFORE num: " + num);
|
|
num = (int)(num * RebirthVariables.hordeNightXPMultiplier);
|
|
}
|
|
|
|
//Log.Out("EntityPlayerPatches-AddKillXP AFTER, num: " + num);
|
|
|
|
if (!__instance.isEntityRemote)
|
|
{
|
|
__instance.Progression.AddLevelExp(num, "_xpFromKill", global::Progression.XPTypes.Kill, true);
|
|
__instance.bPlayerStatsChanged = true;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityPlayerPatches-AddKillXP 4");
|
|
NetPackageEntityAddExpClient package = NetPackageManager.GetPackage<NetPackageEntityAddExpClient>().Setup(__instance.entityId, num, global::Progression.XPTypes.Kill);
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendPackage(package, false, __instance.entityId, -1, -1, null, 192);
|
|
}
|
|
if (xpModifier == 1f)
|
|
{
|
|
//Log.Out("EntityPlayerPatches-AddKillXP 5");
|
|
GameManager.Instance.SharedKillServer(killedEntity.entityId, __instance.entityId, xpModifier);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |