Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Scripts/Entities/EntityMeleeRangedBanditSDX.cs
Nathaniel Cosford 062dfab2cd Patched
2025-05-30 01:04:40 +09:30

652 lines
21 KiB
C#

using System.Globalization;
using Random = System.Random;
public class EntityMeleeRangedBanditSDX : EntityEnemyRebirthSDX
{
public float flEyeHeight = -1f;
public Random random = new Random();
public float StaticSizeScale = 1;
public string lootDropEntityClass = "";
public string otherTags = "";
public override void CopyPropertiesFromEntityClass()
{
base.CopyPropertiesFromEntityClass();
EntityClass entityClass = EntityClass.list[this.entityClass];
if (entityClass.Properties.Values.ContainsKey("StaticSizeScale"))
{
this.StaticSizeScale = StringParsers.ParseFloat(entityClass.Properties.Values["StaticSizeScale"], 0, -1, NumberStyles.Any);
}
}
public override void fallHitGround(float _distance, Vector3 _fallMotion)
{
this.SetScale(this.StaticSizeScale);
base.fallHitGround(_distance, _fallMotion);
if (_distance > 2f)
{
int num = (int)((-_fallMotion.y - 0.85f) * 160f);
if (num > 0)
{
this.DamageEntity(DamageSource.fall, num, false, 1f);
}
}
}
public override void OnUpdateLive()
{
if (this.bDead)
{
if (this.lootContainer != null)
{
if (this.lootContainer.bTouched && this.lootContainer.IsEmpty())
{
this.MarkToUnload();
this.KillLootContainer();
}
}
}
try
{
base.OnUpdateLive();
}
catch (Exception ex)
{
Log.Out("EntityMeleeRangedBanditSDX-OnUpdateLive ERROR: " + ex.Message);
}
if (!this.bDead)
{
if (this.ticksUntilVisible > 0)
{
this.ticksUntilVisible--;
}
if (!this.isEntityRemote)
{
if (!this.IsDead() && this.world.worldTime >= this.timeToDie && !this.attackTarget)
{
this.Kill(DamageResponse.New(true));
}
}
}
}
public override int DamageEntity(DamageSource _damageSource, int _strength, bool _criticalHit, float _impulseScale = 1f)
{
if ((_damageSource.GetDamageType() == EnumDamageTypes.Falling))
{
if (this.GetWeight() == 69)
{
return 0;
}
else
{
_strength = (_strength + 1) / 2;
int num = (this.GetMaxHealth() + 2) / 3;
if (_strength > num)
{
_strength = num;
}
}
}
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 0");
EnumDamageSource source = _damageSource.GetSource();
if (_damageSource.IsIgnoreConsecutiveDamages() && source != EnumDamageSource.Internal)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 0a");
if (this.damageSourceTimeouts.ContainsKey(source) && GameTimer.Instance.ticks - this.damageSourceTimeouts[source] < 30UL)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 0b");
return 0;
}
this.damageSourceTimeouts[source] = GameTimer.Instance.ticks;
}
EntityAlive entityAlive = this.world.GetEntity(_damageSource.getEntityId()) as EntityAlive;
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 1");
bool flag = _damageSource.GetDamageType() == EnumDamageTypes.Heat;
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 2");
if (!flag && entityAlive is EntityMeleeRangedBanditSDX && this is EntityMeleeRangedBanditSDX)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 2a");
return 0;
}
if (this.IsGodMode.Value)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 2b");
return 0;
}
bool flagSuicide = _damageSource.GetDamageType() == EnumDamageTypes.Suicide;
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this, entityAlive, true);
//Log.Out("EntityMeleeCyborgRebirth-DamageEntity 3");
if (!flagSuicide && !shouldAttack/*myRelationship == FactionManager.Relationship.Love*/)
{
//Log.Out("EntityMeleeCyborgRebirth-DamageEntity 3a");
return 0;
}
if (!flagSuicide && !shouldAttack/*myRelationship == FactionManager.Relationship.Like*/)
{
//Log.Out("EntityMeleeCyborgRebirth-DamageEntity 3b");
return 0;
}
if (entityAlive != null)
{
if (!flagSuicide && !shouldAttack /*myRelationship == FactionManager.Relationship.Neutral*/ && (this.entityClass == entityAlive.entityClass))
{
//Log.Out("EntityMeleeCyborgRebirth-DamageEntity 3c");
return 0;
}
}
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 4");
if (!this.IsDead() && entityAlive)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 4a");
float value = EffectManager.GetValue(PassiveEffects.DamageBonus, null, 0f, entityAlive, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1);
if (value > 0f)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 4b");
_damageSource.DamageMultiplier = value;
_damageSource.BonusDamageType = EnumDamageBonusType.Sneak;
}
}
DamageResponse damageResponse = this.damageEntityLocal(_damageSource, _strength, _criticalHit, _impulseScale);
NetPackage package = NetPackageManager.GetPackage<NetPackageDamageEntity>().Setup(this.entityId, damageResponse);
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 5");
if (this.world.IsRemote())
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 5a");
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(package, false);
}
else
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 5b");
int excludePlayer = -1;
if (!flag && _damageSource.CreatorEntityId != -2)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 5c");
excludePlayer = _damageSource.getEntityId();
if (_damageSource.CreatorEntityId != -1)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 5d");
Entity entity = this.world.GetEntity(_damageSource.CreatorEntityId);
if (entity && !entity.isEntityRemote)
{
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 5e");
excludePlayer = -1;
}
}
}
this.world.entityDistributer.SendPacketToTrackedPlayersAndTrackedEntity(this.entityId, excludePlayer, package);
}
//Log.Out("EntityMeleeRangedBanditSDX-DamageEntity 6");
return damageResponse.ModStrength;
}
public override void OnAddedToWorld()
{
base.OnAddedToWorld();
this.timeToDie = this.world.worldTime + 1800UL + (ulong)(22000f * this.rand.RandomFloat);
if (this.IsFeral && base.GetSpawnerSource() == EnumSpawnerSource.Biome)
{
int num = (int)SkyManager.GetDawnTime();
int num2 = (int)SkyManager.GetDuskTime();
int num3 = GameUtils.WorldTimeToHours(this.WorldTimeBorn);
if (num3 < num || num3 >= num2)
{
int num4 = GameUtils.WorldTimeToDays(this.world.worldTime);
if (GameUtils.WorldTimeToHours(this.world.worldTime) >= num2)
{
num4++;
}
this.timeToDie = GameUtils.DayTimeToWorldTime(num4, num, 0);
}
}
}
public override bool IsSavedToFile()
{
// If they have a cvar persist, keep them around.
if (Buffs.HasCustomVar("Persist")) return true;
// If its dynamic spawn, don't let them stay.
if (GetSpawnerSource() == EnumSpawnerSource.Dynamic) return false;
return true;
}
public override void Init(int _entityClass)
{
base.Init(_entityClass);
this.emodel.SetVisible(false, false);
}
public override void InitFromPrefab(int _entityClass)
{
base.InitFromPrefab(_entityClass);
this.emodel.SetVisible(false, false);
}
public override void VisiblityCheck(float _distanceSqr, bool _masterIsZooming)
{
bool bVisible = this.ticksUntilVisible <= 0 && _distanceSqr < (float)(_masterIsZooming ? 14400 : 8100);
this.emodel.SetVisible(bVisible, false);
}
public override void PostInit()
{
base.PostInit();
if (!this.isEntityRemote)
{
this.IsBloodMoon = this.world.aiDirector.BloodMoonComponent.BloodMoonActive;
}
}
public override bool IsDrawMapIcon()
{
return true;
}
public override bool isRadiationSensitive()
{
return false;
}
public override bool isDetailedHeadBodyColliders()
{
return true;
}
public override void OnEntityTargeted(EntityAlive target)
{
base.OnEntityTargeted(target);
if (!this.isEntityRemote && base.GetSpawnerSource() != EnumSpawnerSource.Dynamic && target is EntityPlayer)
{
this.world.aiDirector.NotifyIntentToAttack(this, target as EntityPlayer);
}
}
public override bool isGameMessageOnDeath()
{
return false;
}
public override void Awake()
{
base.Awake();
//this.MaxLedgeHeight = 20;
}
public override Ray GetLookRay()
{
Ray result;
if (base.IsBreakingBlocks)
{
result = new Ray(this.position + new Vector3(0f, this.GetEyeHeight(), 0f), this.GetLookVector());
}
else if (base.GetWalkType() == 8)
{
result = new Ray(this.getHeadPosition(), this.GetLookVector());
}
else
{
result = new Ray(this.getHeadPosition(), this.GetLookVector());
}
return result;
}
public override Vector3 GetLookVector()
{
if (this.lookAtPosition.Equals(Vector3.zero))
{
return base.GetLookVector();
}
return this.lookAtPosition - this.getHeadPosition();
}
public override bool IsRunning
{
get
{
EnumGamePrefs eProperty = EnumGamePrefs.ZombieMove;
if (this.IsBloodMoon)
{
eProperty = EnumGamePrefs.ZombieBMMove;
}
else if (this.IsFeral)
{
eProperty = EnumGamePrefs.ZombieFeralMove;
}
else if (this.world.IsDark())
{
eProperty = EnumGamePrefs.ZombieMoveNight;
}
return GamePrefs.GetInt(eProperty) >= 2;
}
}
public override float GetMoveSpeedAggro()
{
EnumGamePrefs eProperty = EnumGamePrefs.ZombieMove;
if (this.IsBloodMoon)
{
eProperty = EnumGamePrefs.ZombieBMMove;
}
else if (this.IsFeral)
{
eProperty = EnumGamePrefs.ZombieFeralMove;
}
else if (this.world.IsDark())
{
eProperty = EnumGamePrefs.ZombieMoveNight;
}
int @int = GamePrefs.GetInt(eProperty);
float num = moveSpeeds[@int];
if (this.moveSpeedRagePer > 1f)
{
num = moveSuperRageSpeeds[@int];
}
else if (this.moveSpeedRagePer > 0f)
{
float num2 = moveRageSpeeds[@int];
num = num * (1f - this.moveSpeedRagePer) + num2 * this.moveSpeedRagePer;
}
if (num < 1f)
{
num = this.moveSpeedAggro * (1f - num) + this.moveSpeedAggroMax * num;
}
else
{
num = this.moveSpeedAggroMax * num;
}
return EffectManager.GetValue(PassiveEffects.RunSpeed, null, num, this, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1);
}
public override float getNextStepSoundDistance()
{
if (!this.IsRunning)
{
return 0.5f;
}
return 1.5f;
}
public override void MoveEntityHeaded(Vector3 _direction, bool _isDirAbsolute)
{
if (this.walkType == 4 && this.Jumping)
{
this.motion = this.accumulatedRootMotion;
this.accumulatedRootMotion = Vector3.zero;
this.IsRotateToGroundFlat = true;
if (this.moveHelper != null)
{
Vector3 vector = this.moveHelper.JumpToPos - this.position;
if (Utils.FastAbs(vector.y) < 0.2f)
{
this.motion.y = vector.y * 0.2f;
}
if (Utils.FastAbs(vector.x) < 0.3f)
{
this.motion.x = vector.x * 0.2f;
}
if (Utils.FastAbs(vector.z) < 0.3f)
{
this.motion.z = vector.z * 0.2f;
}
if (vector.sqrMagnitude < 0.010000001f)
{
if (this.emodel && this.emodel.avatarController)
{
this.emodel.avatarController.StartAnimationJump(AnimJumpMode.Land);
}
this.Jumping = false;
}
}
this.entityCollision(this.motion);
return;
}
base.MoveEntityHeaded(_direction, _isDirAbsolute);
}
public override void UpdateJump()
{
if (this.walkType == 4 && !this.isSwimming)
{
base.FaceJumpTo();
this.jumpState = EntityAlive.JumpState.Climb;
if (!this.emodel.avatarController || !this.emodel.avatarController.IsAnimationJumpRunning())
{
this.Jumping = false;
}
if (this.jumpTicks == 0 && this.accumulatedRootMotion.y > 0.005f)
{
this.jumpTicks = 30;
}
return;
}
base.UpdateJump();
if (this.isSwimming)
{
return;
}
this.accumulatedRootMotion.y = 0f;
}
public override void EndJump()
{
base.EndJump();
this.IsRotateToGroundFlat = false;
}
public override bool ExecuteFallBehavior(EntityAlive.FallBehavior behavior, float _distance, Vector3 _fallMotion)
{
if (behavior == null || !this.emodel)
{
return false;
}
AvatarController avatarController = this.emodel.avatarController;
if (!avatarController)
{
return false;
}
avatarController.UpdateInt("RandomSelector", this.rand.RandomRange(0, 64));
switch (behavior.ResponseOp)
{
case EntityAlive.FallBehavior.Op.None:
avatarController.UpdateInt(AvatarController.jumpLandResponseHash, -1);
break;
case EntityAlive.FallBehavior.Op.Land:
avatarController.UpdateInt(AvatarController.jumpLandResponseHash, 0);
break;
case EntityAlive.FallBehavior.Op.LandLow:
avatarController.UpdateInt(AvatarController.jumpLandResponseHash, 1);
break;
case EntityAlive.FallBehavior.Op.LandHard:
avatarController.UpdateInt(AvatarController.jumpLandResponseHash, 2);
break;
case EntityAlive.FallBehavior.Op.Stumble:
avatarController.UpdateInt(AvatarController.jumpLandResponseHash, 3);
break;
case EntityAlive.FallBehavior.Op.Ragdoll:
this.emodel.DoRagdoll(this.rand.RandomFloat * 2f, EnumBodyPartHit.None, _fallMotion * 20f, Vector3.zero, false);
break;
}
if (this.attackTarget != null && behavior.RagePer.IsSet() && behavior.RageTime.IsSet() && this.StartRage(behavior.RagePer.Random(this.rand), behavior.RageTime.Random(this.rand)))
{
avatarController.StartAnimationRaging();
}
return true;
}
public override bool ExecuteDestroyBlockBehavior(EntityAlive.DestroyBlockBehavior behavior, ItemActionAttack.AttackHitInfo attackHitInfo)
{
if (behavior == null || attackHitInfo == null || this.moveHelper == null || this.emodel == null || this.emodel.avatarController == null)
{
return false;
}
if (this.walkType == 4)
{
return false;
}
this.moveHelper.ClearBlocked();
this.moveHelper.ClearTempMove();
this.emodel.avatarController.UpdateInt("RandomSelector", this.rand.RandomRange(0, 64));
switch (behavior.ResponseOp)
{
case EntityAlive.DestroyBlockBehavior.Op.Ragdoll:
this.emodel.avatarController.BeginStun(EnumEntityStunType.StumbleBreakThroughRagdoll, EnumBodyPartHit.LeftLowerLeg, Utils.EnumHitDirection.None, false, 1f);
base.SetStun(EnumEntityStunType.StumbleBreakThroughRagdoll);
break;
case EntityAlive.DestroyBlockBehavior.Op.Stumble:
this.emodel.avatarController.BeginStun(EnumEntityStunType.StumbleBreakThrough, EnumBodyPartHit.LeftLowerLeg, Utils.EnumHitDirection.None, false, 1f);
base.SetStun(EnumEntityStunType.StumbleBreakThrough);
this.bodyDamage.StunDuration = 1f;
break;
}
if (this.attackTarget != null && behavior.RagePer.IsSet() && behavior.RageTime.IsSet())
{
this.StartRage(behavior.RagePer.Random(this.rand), behavior.RageTime.Random(this.rand));
}
return true;
}
public override void ProcessDamageResponseLocal(DamageResponse _dmResponse)
{
base.ProcessDamageResponseLocal(_dmResponse);
if (!this.isEntityRemote)
{
int @int = GameStats.GetInt(EnumGameStats.GameDifficulty);
float num = (float)_dmResponse.Strength / 40f;
if (num > 1f)
{
num = Mathf.Pow(num, 0.29f);
}
float num2 = rageChances[@int] * num;
if (this.rand.RandomFloat < num2)
{
if (this.rand.RandomFloat < superRageChances[@int])
{
this.StartRage(2f, 30f);
this.PlayOneShot(this.GetSoundAlert(), false);
return;
}
this.StartRage(0.5f + this.rand.RandomFloat * 0.5f, 4f + this.rand.RandomFloat * 6f);
}
}
}
public override Vector3i dropCorpseBlock()
{
if (this.lootContainer != null && this.lootContainer.IsUserAccessing())
{
return Vector3i.zero;
}
Vector3i vector3i = base.dropCorpseBlock();
if (vector3i == Vector3i.zero)
{
return Vector3i.zero;
}
TileEntityLootContainer tileEntityLootContainer = this.world.GetTileEntity(0, vector3i) as TileEntityLootContainer;
if (tileEntityLootContainer == null)
{
return Vector3i.zero;
}
if (this.lootContainer != null)
{
tileEntityLootContainer.CopyLootContainerDataFromOther(this.lootContainer);
}
else
{
tileEntityLootContainer.lootListName = this.lootListOnDeath;
tileEntityLootContainer.SetContainerSize(LootContainer.GetLootContainer(this.lootListOnDeath, true).size, true);
}
tileEntityLootContainer.SetModified();
return vector3i;
}
public override void AnalyticsSendDeath(DamageResponse _dmResponse)
{
DamageSource source = _dmResponse.Source;
if (source == null)
{
return;
}
string name;
if (source.BuffClass != null)
{
name = source.BuffClass.Name;
}
else
{
if (source.ItemClass == null)
{
return;
}
name = source.ItemClass.Name;
}
GameSparksCollector.IncrementCounter(GameSparksCollector.GSDataKey.ZombiesKilledBy, name, 1, true, GameSparksCollector.GSDataCollection.SessionUpdates);
}
public override void BuffAdded(BuffValue _buff)
{
if (_buff.BuffClass.DamageType == EnumDamageTypes.Electrical)
{
this.Electrocuted = true;
}
}
private int ticksUntilVisible = 2;
private float moveSpeedRagePer;
private float moveSpeedScaleTime;
private float fallTime;
private float fallThresholdTime;
private static float[] moveSpeeds = new float[]
{
0f,
0.35f,
0.7f,
1f,
1.35f
};
private static float[] moveRageSpeeds = new float[]
{
0.75f,
0.8f,
0.9f,
1.15f,
1.7f
};
private static float[] moveSuperRageSpeeds = new float[]
{
0.88f,
0.92f,
1f,
1.2f,
1.7f
};
private static float[] rageChances = new float[]
{
0f,
0.15f,
0.3f,
0.35f,
0.4f,
0.5f
};
private static float[] superRageChances = new float[]
{
0f,
0.01f,
0.03f,
0.05f,
0.08f,
0.15f
};
}