using Audio; using Rebirth.RemoteCrafting; using System.Collections.Generic; using System.Linq; using static RebirthManager; public class EntityNPCRebirth : EntityAliveV2 { public string otherTags = ""; public string lootDropEntityClass = ""; public bool setSize = false; public bool setNavIcon = false; public EntityPlayer Owner = null; private float ownerCheck = 0f; private float ownerTick = 10f; public bool canShotgunTrigger = true; public bool hasSetOwner = false; public bool hasNotified = false; public bool bSoundCheck = false; public bool bSoundRandomCheck = false; public bool hasAttackTarget = false; public bool isOnFire = false; public int killingSpree = 0; public ulong tempSpawn = 60UL; public ulong tempSpawnTime = 0UL; public bool despawning = false; public float delta = 0f; public float updateCheck = 0f; public float positionCheck = 0f; public float bedrollCheck = 0f; public float positionTick = 5f; public float spawnCheck = 0f; public float ownerFastCheck = 0f; public float ownerMidCheck = 0f; public float ownerSlowCheck = 0f; public float spawnTick = 30f; public float hiredCheck = 0f; public float hiredTick = 60f; public float bedrollTick = 3f; public float ownerFastTick = 0.5f; public float ownerMidTick = 2f; public float ownerSlowTick = 10f; public string[,] strCouldNotRepair = new string[99999, 2]; public int numCouldNotRepair = 0; public string strSerialize = ""; public bool bRepair = false; public bool bRepairing = false; public int numRepairedBlocks = 0; public bool bMine = false; public float HideDuration = 0; public float followDuration = 0; public float followDurationTick = 1; public float roundsPerMinute = 0; public int numMagazineSize = 0; public List uniqueKeysUsed = new List(); public string rightHandTransformName; public ItemValue handItem; public int numReposition = 0; public Vector3i spawnBlockPosition = new Vector3i(); public Vector3 previousPosition = new Vector3(); public bool bSpwanBlockSet = false; public int previousOrder = 0; public string _currentWeapon = ""; private int _defaultTraderID; private string _strTitle; private List _startedThisFrame; private TileEntityTrader _tileEntityTrader; private float fallTime; private float fallThresholdTime; public string strWeaponType = "none"; private string strAmmoType = "none"; public ulong GameTimerTicks = 0UL; public ulong AccumulatedTicks = 0UL; public ulong AccumulatedTicksUpdate = 0UL; public ulong AccumulatedTicksSurvivor = 0UL; public ulong AccumulatedTicksZombieCompanion = 0UL; public ulong AccumulatedTicksDespawn = 0UL; public ulong AccumulatedTicksSound = 0UL; public ulong AccumulatedTicksSoundRandom = 0UL; public ulong AccumulatedTicksSoundKillingSpree = 0UL; public ulong AccumulatedTicksSoundTarget = 0UL; public ulong AccumulatedTicksFoundAttackTarget = 0UL; public ulong TickRate = 100UL; public System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); public override void Collect(int _playerId) { //Log.Out("EntityNPCRebirth-Collect START"); var entityPlayerLocal = world.GetEntity(_playerId) as EntityPlayerLocal; if (entityPlayerLocal == null) return; var uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal); var itemStack = new ItemStack(GetItemValue(), 1); if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack)) { GameManager.Instance.ItemDropServer(itemStack, entityPlayerLocal.GetPosition(), Vector3.zero, _playerId, 60f, false); } } public override void SetItemValue(ItemValue itemValue) { //Log.Out("EntityNPCRebirth-SetItemValue START"); if (itemValue.HasMetadata("NPCName")) { string newName = (string)itemValue.GetMetadata("NPCName"); SetEntityName(newName); //Log.Out("EntityNPCRebirth-SetItemValue EntityName: " + (string)itemValue.GetMetadata("NPCName")); SetEntityName((string)itemValue.GetMetadata("NPCName")); if (SingletonMonoBehaviour.Instance.IsServer && !SingletonMonoBehaviour.Instance.IsSinglePlayer) { SingletonMonoBehaviour.Instance.SendPackage(NetPackageManager.GetPackage().Setup(this.entityId, newName), false, this.belongsPlayerId, -1, -1, null, 192); } } if (itemValue.HasMetadata("health")) { //Log.Out("EntityNPCRebirth-SetItemValue $tempHealth: " + (int)itemValue.GetMetadata("health")); this.Buffs.SetCustomVar("$tempHealth", (int)itemValue.GetMetadata("health")); } if (itemValue.HasMetadata("numKills")) { //Log.Out("EntityNPCRebirth-SetItemValue $varNumKills: " + (int)itemValue.GetMetadata("numKills")); this.Buffs.SetCustomVar("$varNumKills", (int)itemValue.GetMetadata("numKills")); } if (itemValue.HasMetadata("NPCLevel")) { //Log.Out("EntityNPCRebirth-SetItemValue $FR_NPC_Level: " + (int)itemValue.GetMetadata("NPCLevel")); this.Buffs.SetCustomVar("$FR_NPC_Level", (int)itemValue.GetMetadata("NPCLevel")); } if (itemValue.HasMetadata("NPCMiningLevel")) { //Log.Out("EntityNPCRebirth-SetItemValue $FR_NPC_MiningLevel: " + (int)itemValue.GetMetadata("NPCMiningLevel")); this.Buffs.SetCustomVar("$FR_NPC_MiningLevel", (int)itemValue.GetMetadata("NPCMiningLevel")); } //this.Buffs.AddBuff("AdjustNPCStats"); GameManager.Instance.StartCoroutine(RebirthUtilities.adjustNPCStats(this)); } public ItemValue GetItemValue(ItemValue itemValue) { //Log.Out("EntityNPCRebirth-GetItemValue START"); itemValue.SetMetadata("NPCName", EntityName, TypedMetadataValue.TypeTag.String); itemValue.SetMetadata("health", (int)Stats.Health.Value, TypedMetadataValue.TypeTag.Integer); itemValue.SetMetadata("numKills", (int)this.Buffs.GetCustomVar("$varNumKills"), TypedMetadataValue.TypeTag.Integer); itemValue.SetMetadata("NPCLevel", (int)this.Buffs.GetCustomVar("$FR_NPC_Level"), TypedMetadataValue.TypeTag.Integer); itemValue.SetMetadata("NPCMiningLevel", (int)this.Buffs.GetCustomVar("$FR_NPC_MiningLevel"), TypedMetadataValue.TypeTag.Integer); return itemValue; } public override EntityActivationCommand[] GetActivationCommands(Vector3i _tePos, EntityAlive _entityFocusing) { //Log.Out("EntityNPCRebirth-GetActivationCommands-START"); // Don't allow you to interact with it when its dead. float flEntityRespawnCommandActivation = this.Buffs.GetCustomVar("$FR_NPC_RespawnCommandActivation"); float flEntityNoHire = this.Buffs.GetCustomVar("$FR_NPC_NoHire"); if (this.Buffs.HasBuff("FuriousRamsayRespawned")) { this.Buffs.SetCustomVar("$FR_NPC_RespawnCommandActivation", 0); flEntityRespawnCommandActivation = 0; } //Log.Out("EntityNPCRebirth-GetActivationCommands - flEntityNoHire: " + flEntityNoHire); if (IsDead() || NPCInfo == null || flEntityRespawnCommandActivation == 1 || flEntityNoHire == 1) { //Log.Out("EntityNPCRebirth-GetActivationCommands - NO COMMANDS"); return new EntityActivationCommand[0]; } else { ////Log.Out("EntityNPCRebirth-GetActivationCommands-IS ALIVE"); } if (this.IsDead() || NPCInfo == null) { //Debug.Log("NPC info == null."); return new EntityActivationCommand[0]; } return new EntityActivationCommand[] { new EntityActivationCommand("talk", "talk", true) }; /*return new EntityActivationCommand[] { new EntityActivationCommand("talk", "talk", true), new EntityActivationCommand("talk", "talk", true), new EntityActivationCommand("talk", "talk", true) };*/ } public override int DamageEntity(DamageSource _damageSource, int _strength, bool _criticalHit, float _impulseScale) { //Log.Out("EntityNPCRebirth-DamageEntity START, _damageSource.GetDamageType(): " + _damageSource.GetDamageType()); if (_damageSource.damageType == EnumDamageTypes.Falling || IsOnMission()) { return 0; } bool flag = _damageSource.GetDamageType() == EnumDamageTypes.Heat; if (flag && _damageSource.AttackingItem != null && _damageSource.AttackingItem.ItemClass.GetItemName() == "otherExplosion") { if (this.Buffs.GetCustomVar("$Leader") > 0) { if (HasAnyTags(FastTags.Parse("melee"))) { _strength = 20; } else { _strength = 50; } //Log.Out("EntityNPCRebirth-DamageEntity _strength: " + _strength); } } global::EntityAlive entityAlive = this.world.GetEntity(_damageSource.getEntityId()) as global::EntityAlive; if (this.EntityTags.Test_AnySet(FastTags.Parse("nanospawner"))) { float perc = this.Health / this.Stats.Health.ModifiedMax; float stage = this.Buffs.GetCustomVar("$NanoStage"); //Log.Out("EntityNPCRebirth-DamageEntity this.Health: " + this.Health); //Log.Out("EntityNPCRebirth-DamageEntity this.Stats.Health.ModifiedMax: " + this.Stats.Health.ModifiedMax); //Log.Out("EntityNPCRebirth-DamageEntity perc: " + perc); //Log.Out("EntityNPCRebirth-DamageEntity stage: " + stage); bool NanoCyborgFuriousRamsayStage1Spawns = stage == 0f && perc < .85f; bool NanoCyborgFuriousRamsayStage2Spawns = stage == 1f && perc < .65f; bool NanoCyborgFuriousRamsayStage3Spawns = stage == 2f && perc < .45f; int playerID = -1; if (entityAlive is EntityPlayer) { playerID = entityAlive.entityId; } if (NanoCyborgFuriousRamsayStage1Spawns) { this.Buffs.SetCustomVar("$NanoStage", 1f); Manager.BroadcastPlay(this.position, "FuriousRamsayNanoSpawn"); RebirthUtilities.SpawnEntity(this.entityId, "NanoCyborg002_FR", 2, "", "", "0", "static", "", "", 1, -1, true, false, true, playerID); } else if (NanoCyborgFuriousRamsayStage2Spawns) { this.Buffs.SetCustomVar("$NanoStage", 2f); Manager.BroadcastPlay(this.position, "FuriousRamsayNanoSpawn"); RebirthUtilities.SpawnEntity(this.entityId, "NanoCyborg003_FR", 2, "", "", "0", "static", "", "", 1, -1, true, false, true, playerID); } else if (NanoCyborgFuriousRamsayStage3Spawns) { this.Buffs.SetCustomVar("$NanoStage", 3f); Manager.BroadcastPlay(this.position, "FuriousRamsayNanoSpawn"); RebirthUtilities.SpawnEntity(this.entityId, "NanoCyborg004_FR", 2, "", "", "0", "static", "", "", 1, -1, true, false, true, playerID); } } return base.DamageEntity(_damageSource, _strength, _criticalHit, _impulseScale); } public override void OnAddedToWorld() { base.OnAddedToWorld(); if (this.Buffs.GetCustomVar("$FR_NPC_ContainerY") == 0) { ////Log.Out("EntityNPCRebirth-PostInit Container NOT Sized"); bool blIsEmpty = this.lootContainer.IsEmpty(); if (blIsEmpty) { ////Log.Out("EntityNPCRebirth-PostInit Container NOT Empty"); if (this.EntityTags.Test_AllSet(FastTags.Parse("allyanimal"))) { lootContainer.SetContainerSize(new Vector2i(10, 1)); } else { int numRandom = this.rand.RandomRange(3, 5); lootContainer.SetContainerSize(new Vector2i(8, numRandom)); } } this.Buffs.SetCustomVar("$FR_NPC_ContainerY", this.lootContainer.GetContainerSize().y); } } public override void CopyPropertiesFromEntityClass() { base.CopyPropertiesFromEntityClass(); var _entityClass = EntityClass.list[entityClass]; if (_entityClass.Properties.Values.ContainsKey("DespawnAfter")) { this.tempSpawn = Convert.ToUInt64(_entityClass.Properties.Values["DespawnAfter"]); } if (_entityClass.Properties.Values.ContainsKey("WeaponType")) strWeaponType = _entityClass.Properties.Values["WeaponType"]; if (_entityClass.Properties.Values.ContainsKey("Hirable")) isHirable = StringParsers.ParseBool(_entityClass.Properties.Values["Hirable"], 0, -1, true); flEyeHeight = EntityUtilities.GetFloatValue(entityId, "EyeHeight"); // Read in a list of names then pick one at random. if (_entityClass.Properties.Values.ContainsKey("Names")) { var text = _entityClass.Properties.Values["Names"]; var names = text.Split(','); string randomName = RebirthUtilities.GetRandomName(this); if (randomName != "") { _strMyName = randomName; } else { var index = UnityEngine.Random.Range(0, names.Length); _strMyName = names[index]; } } // By default, make the sleepers to always be awake, this solves the issue where entities in a Passive volume does not wake up fully // ie, buffs are not firing, but the uai is. isAlwaysAwake = false; if (_entityClass.Properties.Values.ContainsKey("SleeperInstantAwake")) isAlwaysAwake = StringParsers.ParseBool(_entityClass.Properties.Values["SleeperInstantAwake"], 0, -1, true); if (_entityClass.Properties.Values.ContainsKey("IsAlwaysAwake")) isAlwaysAwake = StringParsers.ParseBool(_entityClass.Properties.Values["IsAlwaysAwake"], 0, -1, true); if (_entityClass.Properties.Values.ContainsKey("Titles")) { var text = _entityClass.Properties.Values["Titles"]; var names = text.Split(','); var index = UnityEngine.Random.Range(0, names.Length); _strTitle = names[index]; } var component = gameObject.GetComponent(); if (component) { ////Log.Out(" Box Collider: " + component.size.ToCultureInvariantString()); ////Log.Out(" Current Boundary Box: " + boundingBox.ToCultureInvariantString()); } if (_entityClass.Properties.Classes.ContainsKey("Boundary")) { ////Log.Out(" Found Boundary Settings"); var strBoundaryBox = "0,0,0"; var strCenter = "0,0,0"; var dynamicProperties3 = _entityClass.Properties.Classes["Boundary"]; foreach (var keyValuePair in dynamicProperties3.Values.Dict) { ////Log.Out("Key: " + keyValuePair.Key); switch (keyValuePair.Key) { case "BoundaryBox": ////Log.Out(" Found a Boundary Box"); strBoundaryBox = dynamicProperties3.Values[keyValuePair.Key]; continue; case "Center": ////Log.Out(" Found a Center"); strCenter = dynamicProperties3.Values[keyValuePair.Key]; break; } } var box = StringParsers.ParseVector3(strBoundaryBox); var center = StringParsers.ParseVector3(strCenter); ConfigureBoundaryBox(box, center); } } public override bool IsDeadIfOutOfWorld() { if (this.LeaderUtils.Owner != null) { return false; } else { float flLeader = RebirthUtilities.GetLeader(this); if (flLeader > 0) { return false; } else { return true; } } } public override bool CanDamageEntity(int _sourceEntityId) { var canDamage = EntityTargetingUtilities.CanTakeDamage(this, (EntityAlive)world.GetEntity(_sourceEntityId)); ////Log.Out("EntityNPCRebirth-CanDamageEntity entity: " + this.EntityClass.entityClassName + " / canDamage: " + canDamage); return canDamage; } public override void MarkToUnload() { if (!bWillRespawn) { base.MarkToUnload(); } } public void HideNPC(bool send) { //Log.Out("EntityNPCRebirth-HideNPC send: " + send); if (send) { if (Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f) { return; } //Log.Out("EntityNPCRebirth-HideNPC HIDE"); //Log.Out("EntityNPCRebirth-HideNPC 1"); var enemy = GetRevengeTarget(); if (enemy != null) { //Log.Out("EntityNPCRebirth-HideNPC 2"); enemy.attackTarget = (EntityAlive) null; enemy.SetRevengeTarget((EntityAlive) null); enemy.DoRagdoll(new DamageResponse()); } // Don't let anything target you //isIgnoredByAI = true; /*var newFaction = FactionManager.Instance.GetFactionByName("none"); if (newFaction != null) { this.factionId = newFaction.ID; }*/ this.attackTarget = (EntityAlive) null; this.SetRevengeTarget((EntityAlive) null); // rescale to make it invisible. Buffs.SetCustomVar("$Scale", transform.localScale.y); //transform.localScale = new Vector3(0, 0, 0); //emodel.SetVisible(false, false); RebirthUtilities.toggleCollisions(false, this); //if (this.currentOrder == 1) { //enabled = false; } Buffs.SetCustomVar("onMission", 1f); Buffs.AddBuff("FuriousRamsayRespawned"); Buffs.AddBuff("FuriousRamsayResistFireShockSmoke"); // Turn off the compass if (this.NavObject != null) { //Log.Out("EntityNPCRebirth-HideNPC 3"); if (this.Buffs.GetCustomVar("$FR_NPC_Respawn") == 0) { this.NavObject.IsActive = false; } } // Clear the debug information, usually set from UAI this.DebugNameInfo = ""; // Turn off the display component SetupDebugNameHUD(false); Buffs.SetCustomVar("$FR_NPC_Hidden", 1f); } else { Buffs.SetCustomVar("$FR_NPC_Hidden", 0f); //Log.Out("EntityNPCRebirth-HideNPC SHOW 1"); //Log.Out("EntityNPCRebirth-HideNPC scale: " + scale); float oldScale = Buffs.GetCustomVar("$Scale"); //Log.Out($"EntityNPCRebirth-HideNPC {this.entityName}/{this.EntityClass.entityClassName} BEFORE oldScale: " + oldScale); if (oldScale == 0f) { oldScale = 1; } //Log.Out("EntityNPCRebirth-HideNPC AFTER oldScale: " + oldScale); //Log.Out("EntityNPCRebirth-HideNPC SHOW 2"); emodel.SetVisible(true, true); SetScale(oldScale); //Log.Out("EntityNPCRebirth-HideNPC SHOW 3"); RebirthUtilities.toggleCollisions(true, this); //enabled = true; //Log.Out("EntityNPCRebirth-HideNPC SHOW 4"); HideDuration = 0; //Log.Out("EntityNPCRebirth-HideNPC SHOW 5"); //Log.Out("EntityNPCRebirth-HideNPC SHOW 6"); if (this.LeaderUtils.Owner != null) { this.LeaderUtils.Owner.Buffs.RemoveBuff("FuriousRamsayHelpRepairBuff"); } this.Buffs.RemoveBuff("FuriousRamsayHelpRepair"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningLogs"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningNailandScrews"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningClay"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningScrapIron"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningCoal"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningNitrate"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningLead"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningSand"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningShale"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningSandPremium"); this.Buffs.RemoveBuff("FuriousRamsayGoMiningShalePremium"); bMine = false; bRepair = false; Buffs.CVars.Remove("$FR_NPC_Hidden"); //Log.Out("EntityNPCRebirth-HideNPC SHOW 22"); Buffs.SetCustomVar("onMission", 0f); //Log.Out("EntityNPCRebirth-HideNPC SHOW 23"); if (this.NavObject != null) { //Log.Out("EntityNPCRebirth-HideNPC SHOW 24"); //Log.Out("EntityNPCRebirth-HideNPC 5"); this.NavObject.IsActive = true; } //Log.Out("EntityNPCRebirth-HideNPC SHOW 25"); //isIgnoredByAI = false; //Log.Out("EntityNPCRebirth-HideNPC SHOW 26"); /*var newFaction = FactionManager.Instance.GetFactionByName("whiteriver"); Log.Out("EntityNPCRebirth-HideNPC SHOW 27"); if (newFaction != null) { //Log.Out("EntityNPCRebirth-HideNPC SHOW 28"); this.factionId = newFaction.ID; }*/ //Log.Out("EntityNPCRebirth-HideNPC SHOW 29"); this.attackTarget = (EntityAlive) null; //Log.Out("EntityNPCRebirth-HideNPC SHOW 30"); this.SetRevengeTarget((EntityAlive) null); //Log.Out("EntityNPCRebirth-HideNPC SHOW 31"); float flRespawn = this.Buffs.GetCustomVar("$FR_NPC_Respawn"); //Log.Out("EntityNPCRebirth-HideNPC SHOW 32"); if (flRespawn == 0) { //Log.Out("EntityNPCRebirth-HideNPC SHOW 33"); Buffs.RemoveBuff("FuriousRamsayRespawned"); Buffs.RemoveBuff("FuriousRamsayResistFireShockSmoke"); } //Log.Out("EntityNPCRebirth-HideNPC SHOW 34"); } } public override Vector3 GetLookVector() { if (!IsDead() && attackTarget != null && HasAnyTags(FastTags.Parse("ranged"))) { int npcLevel = (int)this.Buffs.GetCustomVar("$FR_NPC_Level"); int headshotChance = npcLevel - 1; int random = GameManager.Instance.World.GetGameRandom().RandomRange(1, 11); string tagName = "E_BP_Head"; if (headshotChance < random) { tagName = RebirthVariables.bodyTags[random]; } float numAccuracyModifier = float.Parse(RebirthVariables.customRangedNPCAccuracyModifier) / 100; float baseValue = 70 * numAccuracyModifier; if (numMagazineSize == 0) { ItemActionRanged myAction = null; myAction = (ItemActionRanged)inventory.holdingItem.Actions[1]; ItemActionData _actionData = inventory.holdingItemData.actionData[1]; ItemActionRanged.ItemActionDataRanged itemActionDataRanged = (ItemActionRanged.ItemActionDataRanged)_actionData; //float myDelay = 60f / EffectManager.GetValue(PassiveEffects.RoundsPerMinute, ItemClass.GetItem(inventory.holdingItem.GetItemName(), false), 60f / itemActionDataRanged.OriginalDelay, this, null, new FastTags(), true, true, true, true, true, 1, false); float myDelay = 60f / EffectManager.GetValue(PassiveEffects.RoundsPerMinute, itemActionDataRanged.invData.itemValue, 60f / itemActionDataRanged.OriginalDelay, this); roundsPerMinute = 60 / myDelay; //numMagazineSize = (int)EffectManager.GetValue(PassiveEffects.MagazineSize, ItemClass.GetItem(inventory.holdingItem.GetItemName(), false), myAction.BulletsPerMagazine, this, null, new FastTags(), true, true, true, true, true, 1); numMagazineSize = (int)EffectManager.GetValue(PassiveEffects.MagazineSize, itemActionDataRanged.invData.itemValue, myAction.BulletsPerMagazine, this); } if (numMagazineSize > 1) { baseValue = 60 * numAccuracyModifier; int baseRoundsPerMinute = 60; if (roundsPerMinute > baseRoundsPerMinute) { float multiplier = 1 - ((roundsPerMinute / baseRoundsPerMinute) / 15); baseValue *= multiplier; } } float missShotChance = baseValue + (npcLevel * 0.3f * numAccuracyModifier) * 10; //Log.Out("EntityNPCRebirth-GetLookVector level: " + this.Buffs.GetCustomVar("$FR_NPC_Level")); //Log.Out("EntityNPCRebirth-GetLookVector A random: " + random); //Log.Out("EntityNPCRebirth-GetLookVector missShotChance: " + missShotChance); random = GameManager.Instance.World.GetGameRandom().RandomRange(1, 101); //Log.Out("EntityNPCRebirth-GetLookVector B random: " + random); if (missShotChance < random) { //Log.Out("EntityNPCRebirth-GetLookVector MISS"); return new Vector3(0, 100, 0); } var col = attackTarget.GetComponentsInChildren().Where(x => x.CompareTag(tagName)).FirstOrDefault(); if (col != null) { return (col.transform.position - (transform.position + new Vector3(0f, GetEyeHeight(), 0f))); } } return base.GetLookVector(); } public override bool IsFriendlyPlayer(EntityPlayer player) { if (!RebirthUtilities.VerifyFactionStanding(this, player)) return true; return false; } public override void OnUpdateLive() { //Log.Out("EntityNPCRebirth-OnUpdateLive entityClassName: " + this.EntityClass.entityClassName); float respawned = this.Buffs.GetCustomVar("$FR_NPC_Respawn"); float flLeader = RebirthUtilities.GetLeader(this); if (SingletonMonoBehaviour.Instance.IsServer && (Time.time - ownerFastCheck) > ownerFastTick) { ownerFastCheck = Time.time; if (this.LeaderUtils.Owner != null) { if (!this.HasAnyTags(FastTags.Parse("allyanimal"))) { this.Crouching = this.LeaderUtils.Owner.Crouching; } } } if (SingletonMonoBehaviour.Instance.IsServer && (Time.time - ownerMidCheck) > ownerMidTick) { ownerMidCheck = Time.time; if (this.LeaderUtils.Owner != null && RebirthUtilities.IsPrimaryClass(this.LeaderUtils.Owner, 10) && RebirthUtilities.HasBuffLike(this.LeaderUtils.Owner, "FuriousRamsayRage")) { if (this.HasAnyTags(FastTags.Parse("allyanimal,melee")) && !this.Buffs.HasBuff("FuriousRamsayTempRageBuff")) { this.Buffs.AddBuff("FuriousRamsayTempRageBuff"); } } else if (this.Buffs.HasBuff("FuriousRamsayTempRageBuff")) { this.Buffs.RemoveBuff("FuriousRamsayTempRageBuff"); } } if (SingletonMonoBehaviour.Instance.IsServer && (Time.time - ownerSlowCheck) > ownerSlowTick) { ownerSlowCheck = Time.time; if (this.LeaderUtils.Owner != null) { if (!RebirthManager.hasHire(this.LeaderUtils.Owner.entityId, this.entityId) && !(this.EntityClass.Tags.Test_AnySet(FastTags.Parse("temp")))) { RebirthUtilities.DespawnEntity(this); } } } if (SingletonMonoBehaviour.Instance.IsServer && (Time.time - bedrollCheck) > bedrollTick) { //Log.Out("EntityNPCRebirth-OnUpdateLive bedrollTick, $FR_NPC_Respawn: " + respawned); bedrollCheck = Time.time; if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive Owner exists"); SpawnPosition spawnPoint = RebirthUtilities.GetSpawnPoint(this.LeaderUtils.Owner); if (!spawnPoint.IsUndef()) { //Log.Out("EntityNPCRebirth-OnUpdateLive spawnPoint: " + spawnPoint.position); float distance = Vector3.Distance(this.position, spawnPoint.position); //Log.Out("EntityNPCRebirth-OnUpdateLive distance: " + distance); if (distance < 3 && respawned == 1f) { //Log.Out("EntityNPCRebirth-OnUpdateLive Apply Buff"); this.Buffs.AddBuff("buffBedrollAOEEffect"); } } else { //Log.Out("EntityNPCRebirth-OnUpdateLive No Owner Spawnpoint"); } } } //Log.Out("EntityNPCRebirth-OnUpdateLive TempPause: " + this.Buffs.GetCustomVar(".TempPause") + $"[{this.EntityClass.entityClassName}]"); if (this.Buffs.GetCustomVar(".TempPause") == 0f) { if (this.IsSleeping) { if (this.Buffs.GetCustomVar("$FR_NPC_Respawn") == 0f) { this.ConditionalTriggerSleeperWakeUp(); } return; } else { if (this.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f && this.Buffs.GetCustomVar("$FR_NPC_RespawnCommandActivation") == 0f) { this.TriggerSleeperPose(0); } } } if (!setSize) { float sizeScale = this.Buffs.GetCustomVar("$StartScale"); //Log.Out("EntityNPCRebirth-OnUpdateLive sizeScale: " + sizeScale); if (sizeScale > 0f) { this.scale = new Vector3(sizeScale, sizeScale, sizeScale); this.SetScale(sizeScale); this.OverrideSize = sizeScale; } setSize = true; } if (!setNavIcon) { //Log.Out("EntityNPCRebirth-OnUpdateLive SET NAV ICON"); string navObjectName = ""; if (NavObject != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive NavObject.name: " + NavObject.name); NavObjectManager.Instance.UnRegisterNavObject(NavObject); NavObject = null; } if (RebirthVariables.customEventsNotification && this.Buffs.GetCustomVar("$varFuriousRamsaySupportMinion") == 1f) { //Log.Out("EntityNPCRebirth-OnUpdateLive SET NAV ICON SUPPORT NO HEALTH"); navObjectName = RebirthVariables.navIconSupportEventNoHealth; if (RebirthVariables.customTargetBarVisibility == "always") { //Log.Out("EntityNPCRebirth-OnUpdateLive SET NAV ICON SUPPORT"); navObjectName = RebirthVariables.navIconSupportEvent; } this.AddNavObject(navObjectName, "", ""); } else if (RebirthVariables.customEventsNotification && this.Buffs.GetCustomVar("$varFuriousRamsayBoss") == 1f) { //Log.Out("EntityNPCRebirth-OnUpdateLive SET NAV ICON BOSS NO HEALTH"); navObjectName = RebirthVariables.navIconBossEventNoHealthNPC; if (RebirthVariables.customTargetBarVisibility == "always") { //Log.Out("EntityNPCRebirth-OnUpdateLive SET NAV ICON BOSS"); navObjectName = RebirthVariables.navIconBossEventNPC; } this.AddNavObject(navObjectName, "", ""); } //Log.Out("EntityNPCRebirth-OnUpdateLive navObjectName: " + navObjectName); setNavIcon = true; } if (SingletonMonoBehaviour.Instance.IsServer && (Time.time - positionCheck) > positionTick) { positionCheck = Time.time; if (flLeader == 0) { ulong worldTime = GameManager.Instance.World.worldTime; ValueTuple valueTuple = GameUtils.WorldTimeToElements(worldTime); int day = valueTuple.Item1; int hour = valueTuple.Item2; float originalDayAlive = Buffs.GetCustomVar("$OriginalDayAlive"); if (originalDayAlive == 0) { Buffs.SetCustomVar("$OriginalDayAlive", day - 1); } else { if (originalDayAlive < day) { float numDaysAlive = day - originalDayAlive; float maxDaysAlive = Buffs.GetCustomVar("$MaxDaysAlive"); if (maxDaysAlive == 0) { maxDaysAlive = 2; } if (numDaysAlive >= maxDaysAlive) { bWillRespawn = false; GameManager.Instance.World.RemoveEntity(entityId, EnumRemoveEntityReason.Unloaded); return; } Buffs.SetCustomVar("$CurrentDayAlive", day); Buffs.SetCustomVar("$NumDaysAlive", numDaysAlive); } } } if (flLeader > 0) { if (respawned == 0) { //Log.Out("Entity [" + EntityName + "], POSITION: " + this.position); //Log.Out("Entity [" + EntityName + "], LOOK POSITION: " + this.position + this.GetLookVector()); //Log.Out("GUARD POSITION: " + this.guardPosition); //Log.Out("RESPAWN POSITION: " + RebirthUtilities.GetRespawnPosition(this)); if (this.LeaderUtils.Owner != null) { if (this.Buffs.GetCustomVar("CurrentOrder") == 10) { this.Buffs.SetCustomVar("CurrentOrder", 1f); HideNPC(false); } if (!this.LeaderUtils.Owner.AttachedToEntity) { this.Buffs.SetCustomVar("$traveling", 0f); } } if (NavObject == null) { NavObject = NavObjectManager.Instance.RegisterNavObject(EntityClass.list[this.entityClass].NavObject, this, "", false); NavObject.name = EntityName; } if (this.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Follow) { RebirthManager.UpdateHireInfo(this.entityId, "spawnPosition", "", this.position.ToString(), new Vector3(0, this.rotation.y, 0).ToString()); } /*Vector3 newPosition = this.position; if (this.position.y < 0) { if (this.LeaderUtils.Owner != null) { if (this.Buffs.GetCustomVar("CurrentOrder") == 1) { newPosition = this.LeaderUtils.Owner.position; } else { if (this.guardPosition != Vector3.zero) { newPosition = this.guardPosition; } else { newPosition = RebirthUtilities.GetRespawnPosition(this); } } } else { newPosition = RebirthUtilities.GetRespawnPosition(this); } Log.Out("EntityNPCRebirth-OnUpdateLive REPOSITION"); this.SetPosition(newPosition); bool foundHire = false; foreach (chunkObservers observer in observers) { if (observer.entityID == this.entityId) { foundHire = true; break; } } if (!foundHire) { //Log.Out("MinEventActionRespawnEntity-Execute ADDED CHUNK OBSERVER for: " + this.entityId); ChunkManager.ChunkObserver observerRef = GameManager.Instance.AddChunkObserver(newPosition, false, 3, -1); observers.Add(new chunkObservers(this.entityId, observerRef)); } }*/ } } } if (this.HasAllTags(FastTags.Parse("ignoreFactionChange")) || !this.enabled || respawned == 1) { //Log.Out($"EntityNPCRebirth-OnUpdateLive this Entity: {this} respawned: {respawned}"); base.OnUpdateLive(); return; } if (this.LeaderUtils.Owner != null && (Time.time - hiredCheck) > hiredTick) { //Log.Out("EntityNPCRebirth-OnUpdateLive EntityName: " + this.EntityName); hiredCheck = Time.time; bool foundMyself = false; int order = -1; if (this.Buffs.GetCustomVar("CurrentOrder") == 1) { foreach (hireInfo hire in playerHires) { if (hire.playerID == this.LeaderUtils.Owner.entityId && hire.hireID == this.entityId) { foundMyself = true; order = hire.order; break; } } if (!foundMyself) { //Log.Out("EntityNPCRebirth-OnUpdateLive ADDED MISSING HIRE entityName: " + this.entityName); if (!this.EntityClass.Tags.Test_AnySet(FastTags.Parse("temp"))) { RebirthManager.AddHire(this.LeaderUtils.Owner.entityId, this.entityId, this.EntityName, this.EntityClass.entityClassName, this.position, this.rotation, new Vector3(0, 0, 0), new Vector3(0, 0, 0), 0, 0, 0, true ); } } else { if (order > 0) { //Log.Out("EntityNPCRebirth-OnUpdateLive CHANGE ORDER TO FOLLOW"); RebirthManager.UpdateHireInfo(this.entityId, "order", "follow"); } //Log.Out("EntityNPCRebirth-OnUpdateLive HIRE ALREADY EXISTS entityName: " + this.entityName); } } } if (this.GetCVar("_stunned") == 1f && !this.emodel.avatarController.IsAnimationStunRunning()) { this.ClearStun(); } FastTags tagsToCompare = FastTags.Parse("survivor"); bool bHasTags = this.HasAllTags(tagsToCompare); bool isNPC = this.HasAllTags(FastTags.Parse("npc")); bool isAnimal = this.HasAnyTags(FastTags.Parse("allyanimal")); bool isPanther = this.HasAnyTags(FastTags.Parse("panther")); //Log.Out("EntityNPCRebirth-OnUpdateLive this.tempSpawn: " + this.tempSpawn); if (isAnimal) { ulong elpasedTimeUpdate = GameTimer.Instance.ticks - AccumulatedTicksUpdate; if (elpasedTimeUpdate >= 1200UL) { AccumulatedTicksUpdate = GameTimer.Instance.ticks; //Log.Out("EntityNPCRebirth-OnUpdateLive entity: " + this.entityId); if (this.lootContainer != null) { bool blIsEmpty = this.lootContainer.IsEmpty(); if (blIsEmpty && this.lootContainer.containerSize != new Vector2i(10, 1)) { lootContainer.SetContainerSize(new Vector2i(10, 1)); } if (this.LeaderUtils.Owner) { EntityPlayer entityPlayer = this.world.GetEntity(this.LeaderUtils.Owner.entityId) as EntityPlayer; if (entityPlayer != null) { SpawnPosition spawnPoint = RebirthUtilities.GetSpawnPoint(entityPlayer); this.Buffs.SetCustomVar("$SpawnPoint_X", spawnPoint.position.x); this.Buffs.SetCustomVar("$SpawnPoint_Y", spawnPoint.position.y); this.Buffs.SetCustomVar("$SpawnPoint_Z", spawnPoint.position.z); //Log.Out("EntityNPCRebirth-OnUpdateLive SET SPAWNPOINT"); } } } } } if (this.HasAnyTags(FastTags.Parse("temp"))) { ulong elpasedTimeDespawn = GameTimer.Instance.ticks - AccumulatedTicksDespawn; if (elpasedTimeDespawn >= 20UL) { AccumulatedTicksDespawn = GameTimer.Instance.ticks; tempSpawnTime = tempSpawnTime + 1UL; //Log.Out("EntityNPCRebirth-OnUpdateLive tempSpawnTime: " + tempSpawnTime); } if ((this.tempSpawnTime >= this.tempSpawn) && !despawning) { despawning = true; //Log.Out("EntityNPCRebirth-OnUpdateLive UNLOAD TEMP"); this.Buffs.AddBuff("FuriousRamsayDespawnEntity"); } } if (this.HasAnyTags(FastTags.Parse("zombieCompanion"))) { ulong elpasedTimeZombieCompanion = GameTimer.Instance.ticks - AccumulatedTicksZombieCompanion; if (elpasedTimeZombieCompanion >= 600UL) { AccumulatedTicksZombieCompanion = GameTimer.Instance.ticks; if (this.LeaderUtils.Owner) { ProgressionValue progressionValue = this.LeaderUtils.Owner.Progression.GetProgressionValue("FuriousRamsayPerkBlackMagic"); if (progressionValue != null) { float flZombieCompanion = this.Buffs.GetCustomVar("$FR_NPC_ZombieLvl"); this.Buffs.SetCustomVar("$FR_NPC_ZombieLvl", progressionValue.Level); //Log.Out("EntityAliveSDX-UpdateLive flZombieCompanion: " + flZombieCompanion); if (flZombieCompanion > 0f) { if (flZombieCompanion != progressionValue.Level) { this.Buffs.AddBuff("FuriousRamsayWitchDoctorZombies" + progressionValue.Level); for (int i = 1; i < 11; i++) { if (i != progressionValue.Level) { //Log.Out("EntityAliveSDX-UpdateLive REMOVE BUFF: " + flZombieCompanion); this.Buffs.RemoveBuff("FuriousRamsayWitchDoctorZombies" + flZombieCompanion); } } } } else { //Log.Out("EntityAliveSDX-UpdateLive ADD BUFF: " + progressionValue.Level); this.Buffs.AddBuff("FuriousRamsayWitchDoctorZombies" + progressionValue.Level); } //Log.Out("EntityAliveSDX-UpdateLive ZombieCompanion: " + "FuriousRamsayWitchDoctorZombies" + progressionValue.Level); } } } } if (this.bDead) { if (this.lootContainer != null) { if (this.lootContainer.bTouched && this.lootContainer.IsEmpty()) { this.MarkToUnload(); this.KillLootContainer(); } } } else { ulong elpasedTime = GameTimer.Instance.ticks - AccumulatedTicks; if (this.LeaderUtils.Owner && this.Buffs.GetCustomVar("CurrentOrder") == 1) { if (this.LeaderUtils.Owner.AttachedToEntity) { this.position.x = this.LeaderUtils.Owner.position.x; this.position.z = this.LeaderUtils.Owner.position.z; this.position.y = this.LeaderUtils.Owner.position.y + 100; this.IsFlyMode.Value = true; this.IsNoCollisionMode.Value = true; } else { this.IsNoCollisionMode.Value = false; this.IsFlyMode.Value = false; } } float flNotified = this.Buffs.GetCustomVar("$FR_ENTITY_NotifiedEvent"); if (flNotified == 1) { hasNotified = true; } if (this.attackTarget && !hasNotified && this.HasAllTags(FastTags.Parse("boss,eventspawn"))) { hasNotified = true; this.Buffs.SetCustomVar("$FR_ENTITY_NotifiedEvent", 1); this.attackTarget.Buffs.AddBuff("FuriousRamsayEventTrigger"); } if (elpasedTime > 100UL) { AccumulatedTicks = GameTimer.Instance.ticks; if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive this.NavObject == null: " + (this.NavObject == null)); if (this.NavObject != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive this.NavObject.IsActive: " + this.NavObject.IsActive); } //Log.Out("EntityNPCRebirth-OnUpdateLive entity: " + this.EntityClass.entityClassName); //Log.Out("EntityNPCRebirth-OnUpdateLive this.bIsChunkObserver: " + this.bIsChunkObserver); //Log.Out("EntityNPCRebirth-OnUpdateLive this.bWillRespawn: " + this.bWillRespawn); //Log.Out("EntityNPCRebirth-OnUpdateLive this.IsEntityUpdatedInUnloadedChunk: " + this.IsEntityUpdatedInUnloadedChunk); } } int randomProbability = 0; if (elpasedTime > 30UL) { bSoundCheck = true; AccumulatedTicksSound = GameTimer.Instance.ticks; } bool attackTargetCheck = false; ulong elpasedTimeSoundTarget = GameTimer.Instance.ticks - AccumulatedTicksSoundTarget; if (elpasedTimeSoundTarget > 20UL) { attackTargetCheck = true; AccumulatedTicksSoundTarget = GameTimer.Instance.ticks; randomProbability = UnityEngine.Random.Range(0, 20); //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target randomProbability: " + randomProbability); //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target attackTargetCheck: " + attackTargetCheck); } ulong elpasedTimeSoundRandom = GameTimer.Instance.ticks - AccumulatedTicksSoundRandom; if (elpasedTimeSoundRandom > 5000UL && randomProbability == 5) { //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target elpasedTimeSoundRandom: " + elpasedTimeSoundRandom); bSoundRandomCheck = true; AccumulatedTicksSoundRandom = GameTimer.Instance.ticks; } ulong elpasedTimeSoundKillingSpree = GameTimer.Instance.ticks - AccumulatedTicksSoundKillingSpree; if (elpasedTimeSoundKillingSpree > 600UL) { //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target elpasedTimeSoundRandom: " + elpasedTimeSoundRandom); killingSpree = 0; AccumulatedTicksSoundKillingSpree = GameTimer.Instance.ticks; } if (AccumulatedTicksFoundAttackTarget == 0UL) { //Log.Out("EntityNPCRebirth-OnUpdateLive SET AccumulatedTicksFoundAttackTarget"); AccumulatedTicksFoundAttackTarget = GameTimer.Instance.ticks; } bool canTalk = true; if (!this.enabled || this.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1) { canTalk = false; } bool hasBuffs = this.Buffs.HasBuff("FuriousRamsayNPCOtherAttackedSelf") || this.Buffs.HasBuff("FuriousRamsayNPCOtherDamagedSelf") || this.Buffs.HasBuff("FuriousRamsayNPCOnFire") || this.Buffs.HasBuff("FuriousRamsayNPCRandom"); if (!isAnimal && attackTargetCheck && !hasAttackTarget && canTalk && !hasBuffs) { //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target AccumulatedTicksFoundAttackTarget: " + AccumulatedTicksFoundAttackTarget); //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target AccumulatedTicksFoundAttackTarget + 200UL: " + (AccumulatedTicksFoundAttackTarget + 200UL)); //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target GameTimer.Instance.ticks: " + GameTimer.Instance.ticks); //Log.Out("EntityNPCRebirth-OnUpdateLive this.attackTarget: " + this.GetAttackTarget()); //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target this.attackTarget != null: " + (this.attackTarget != null)); if (this.GetAttackTarget() != null) { if (this.GetAttackTarget() is EntityNPCRebirth) { EntityNPCRebirth target = (EntityNPCRebirth)this.GetAttackTarget(); if (target.HasAllTags(FastTags.Parse("bandit,ranged"))) { hasAttackTarget = true; AccumulatedTicksFoundAttackTarget = GameTimer.Instance.ticks; //Log.Out("EntityNPCRebirth-OnUpdateLive Found Target: " + this.GetAttackTarget().EntityClass.entityClassName); List myTags = this.EntityTags.GetTagNames(); List myRandomSounds = new List(); if (!RebirthUtilities.IsHordeNight()) { foreach (string tag in myTags) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK tag: " + tag); if (tag.Contains("-CST-")) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3c"); myRandomSounds.Add(tag); } } if (myRandomSounds.Count > 0) { this.Buffs.AddBuff("FuriousRamsayNPCCanSeeTarget"); int index = UnityEngine.Random.Range(0, myRandomSounds.Count - 1); if (SingletonMonoBehaviour.Instance.IsSinglePlayer) { if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3d"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); //Manager.BroadcastPlay(leader.position, myRandomSounds[index], 0f); } else { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3e"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } } else { if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3f"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); //Manager.BroadcastPlay(leader.position, myRandomSounds[index], 0f); } else { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3g"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } } } } } } } } else { randomProbability = UnityEngine.Random.Range(0, 10); //Log.Out("EntityNPCRebirth-OnUpdateLive randomProbability: " + randomProbability); if (((AccumulatedTicksFoundAttackTarget + 1800UL) < GameTimer.Instance.ticks) && this.GetAttackTarget() == null && randomProbability == 5) { //Log.Out("EntityNPCRebirth-OnUpdateLive Cleared Target"); hasAttackTarget = false; } } hasBuffs = this.Buffs.HasBuff("FuriousRamsayNPCOtherAttackedSelf") || this.Buffs.HasBuff("FuriousRamsayNPCOtherDamagedSelf") || this.Buffs.HasBuff("FuriousRamsayNPCOnFire") || this.Buffs.HasBuff("FuriousRamsayNPCRandom"); if (!isAnimal && !isOnFire && !hasAttackTarget && bSoundRandomCheck && this.LeaderUtils.Owner && !RebirthUtilities.IsHordeNight() && canTalk && !hasBuffs) { List myTags = this.EntityTags.GetTagNames(); List myRandomSounds = new List(); foreach (string tag in myTags) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK tag: " + tag); if (tag.Contains("-R-")) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3c"); myRandomSounds.Add(tag); } } if (myRandomSounds.Count > 0) { this.Buffs.AddBuff("FuriousRamsayNPCRandom"); int index = UnityEngine.Random.Range(0, myRandomSounds.Count - 1); if (SingletonMonoBehaviour.Instance.IsSinglePlayer) { if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 4d"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } else { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 4e"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } } else { //var leader = EntityUtilities.GetLeaderOrOwner(entityId) as EntityAlive; if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 4f"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } else { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 4g"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } } } bSoundRandomCheck = false; } if (!isAnimal && bSoundCheck && this.LeaderUtils.Owner && canTalk) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 1"); bSoundCheck = false; //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 2"); bool hasFireBuff = this.Buffs.HasBuff("buffBurningFlamingArrow") || this.Buffs.HasBuff("buffBurningMolotov") || this.Buffs.HasBuff("buffBurningEnvironmentHack") || this.Buffs.HasBuff("buffBurningEnvironment") || this.Buffs.HasBuff("buffBurningElement") || this.Buffs.HasBuff("buffIsOnFire") || this.Buffs.HasBuff("FuriousRamsayFireZombieAoEDamage") || this.Buffs.HasBuff("FuriousRamsayFireZombieAoEDamageDisplay") || this.Buffs.HasBuff("FuriousRamsayAddBurningEnemyBoss") || this.Buffs.HasBuff("FuriousRamsayBurningTrapDamage"); // On Fire if (hasFireBuff) { List myTags = this.EntityTags.GetTagNames(); List myRandomSounds = new List(); //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3a"); hasBuffs = this.Buffs.HasBuff("FuriousRamsayNPCOtherAttackedSelf") || this.Buffs.HasBuff("FuriousRamsayNPCOtherDamagedSelf") || this.Buffs.HasBuff("FuriousRamsayNPCOnFire") || this.Buffs.HasBuff("FuriousRamsayNPCRandom"); if (!isOnFire && myTags.Count > 0 && !hasBuffs) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3b"); foreach (string tag in myTags) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK tag: " + tag); if (tag.Contains("-OF-")) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 3c"); myRandomSounds.Add(tag); //Manager.BroadcastPlay(this.position, tag, 0f); break; } } if (myRandomSounds.Count > 0) { this.Buffs.AddBuff("FuriousRamsayNPCOnFire"); int index = UnityEngine.Random.Range(0, myRandomSounds.Count - 1); if (SingletonMonoBehaviour.Instance.IsSinglePlayer) { if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 5d"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } else { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 5e"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } } else { if (this.LeaderUtils.Owner != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 5f"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } else { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 5g"); Manager.BroadcastPlay(this.position, myRandomSounds[index], 0f); } } } } isOnFire = true; } else { //Log.Out("EntityNPCRebirth-OnUpdateLive SOUND CHECK 4"); isOnFire = false; } } float updateTick = 5f; delta = 0; //Log.Out("EntityNPCRebirth-OnUpdateLive flHidden: " + Buffs.GetCustomVar("$FR_NPC_Hidden")); if (Buffs.GetCustomVar("$FR_NPC_Hidden") == 1) { int dayLength = GameStats.GetInt(EnumGameStats.DayLightLength); delta = HideDuration - ((int)GameManager.Instance.World.worldTime / GameStats.GetInt(EnumGameStats.TimeOfDayIncPerSec)); if (delta < 0) { delta = 0; } } /*if (delta > 0) { Log.Out("EntityNPCRebirth-OnUpdateLive delta: " + delta); Log.Out("EntityNPCRebirth-OnUpdateLive bRepair: " + bRepair); Log.Out("EntityNPCRebirth-OnUpdateLive bMine: " + bMine); }*/ if ((Time.time - updateCheck) > updateTick) { //Log.Out("EntityNPCRebirth-OnUpdateLive delta: " + delta); updateCheck = Time.time; float flMagazineSize = this.Buffs.GetCustomVar("$Magsize"); float flEntityLevel = this.Buffs.GetCustomVar("$FR_NPC_Level"); if (!isAnimal && flMagazineSize == 0) { int magazineSize = RebirthUtilities.GetNPCMagazineSize(this); //Log.Out("EntityNPCRebirth-OnUpdateLive INITIAL magazineSize: " + magazineSize); this.Buffs.SetCustomVar("$Magsize", magazineSize); this.Buffs.SetCustomVar("$roundsinmag", magazineSize); this.Buffs.SetCustomVar("$Burstsize", magazineSize); this.Buffs.SetCustomVar("$burstrate", magazineSize); } //if (flEntityLevel > 0) { float flNumKills = this.Buffs.GetCustomVar("$varNumKills"); //Log.Out("EntityNPCRebirth-OnUpdateLive flEntityLevel: " + flEntityLevel); //Log.Out("EntityNPCRebirth-OnUpdateLive flNumKills: " + flNumKills); //Log.Out("EntityNPCRebirth-OnUpdateLive BEFORE $Magsize: " + this.Buffs.GetCustomVar("$Magsize")); //Log.Out("EntityNPCRebirth-OnUpdateLive BEFORE $roundsinmag: " + this.Buffs.GetCustomVar("$roundsinmag")); //Log.Out("EntityNPCRebirth-OnUpdateLive BEFORE $Burstsize: " + this.Buffs.GetCustomVar("$Burstsize")); //Log.Out("EntityNPCRebirth-OnUpdateLive BEFORE $burstrate: " + this.Buffs.GetCustomVar("$burstrate")); bool levelHasChanged = false; int NPCLevel = 0; float multiplier = 1.5f; if (isAnimal && !isPanther) { multiplier = 1f; } if (flNumKills >= 0 && flNumKills <= 50 * multiplier) { NPCLevel = 1; } else if (flNumKills > 50 * multiplier && flNumKills <= 150 * multiplier) { NPCLevel = 2; } else if (flNumKills > 150 * multiplier && flNumKills <= 300 * multiplier) { NPCLevel = 3; } else if (flNumKills > 300 * multiplier && flNumKills <= 500 * multiplier) { NPCLevel = 4; } else if (flNumKills > 500 * multiplier && flNumKills <= 750 * multiplier) { NPCLevel = 5; } else if (flNumKills > 750 * multiplier && flNumKills <= 1050 * multiplier) { NPCLevel = 6; } else if (flNumKills > 1050 * multiplier && flNumKills <= 1400 * multiplier) { NPCLevel = 7; } else if (flNumKills > 1400 * multiplier && flNumKills <= 1800 * multiplier) { NPCLevel = 8; } else if (flNumKills > 1800 * multiplier && flNumKills <= 2250 * multiplier) { NPCLevel = 9; } else if (flNumKills > 2250 * multiplier) { NPCLevel = 10; } if (NPCLevel > flEntityLevel) { this.Buffs.SetCustomVar("$FR_NPC_Level", NPCLevel); levelHasChanged = true; } //Log.Out("EntityNPCRebirth-OnUpdateLive levelHasChanged: " + levelHasChanged); if (levelHasChanged) { int magazineSize = RebirthUtilities.GetNPCMagazineSize(this); //Log.Out("EntityNPCRebirth-OnUpdateLive magazineSize: " + magazineSize); this.Buffs.SetCustomVar("$Magsize", magazineSize); this.Buffs.SetCustomVar("$Burstsize", magazineSize); this.Buffs.SetCustomVar("$burstrate", magazineSize); //Log.Out("EntityNPCRebirth-OnUpdateLive AFTER $Magsize: " + this.Buffs.GetCustomVar("$Magsize")); //Log.Out("EntityNPCRebirth-OnUpdateLive AFTER $roundsinmag: " + this.Buffs.GetCustomVar("$roundsinmag")); //Log.Out("EntityNPCRebirth-OnUpdateLive AFTER $Burstsize: " + this.Buffs.GetCustomVar("$Burstsize")); //Log.Out("EntityNPCRebirth-OnUpdateLive AFTER $burstrate: " + this.Buffs.GetCustomVar("$burstrate")); } } //if (!isAnimal && delta == 0) if (delta == 0) { //Log.Out("EntityNPCRebirth-OnUpdateLive delta == 0"); //Log.Out("EntityNPCRebirth-OnUpdateLive transform.localScale: " + transform.localScale); if (bMine || bRepair) { //Log.Out("EntityNPCRebirth-OnUpdateLive bMine || bRepair"); HideNPC(false); return; } else { //Log.Out("EntityNPCRebirth-OnUpdateLive transform.localScale: " + transform.localScale); //Log.Out("EntityNPCRebirth-OnUpdateLive CurrentOrder: " + this.Buffs.GetCustomVar("CurrentOrder")); //Log.Out("EntityNPCRebirth-OnUpdateLive $traveling: " + this.Buffs.GetCustomVar("$traveling")); if (transform.localScale == new Vector3(0, 0, 0) && this.Buffs.GetCustomVar("$traveling") == 0f) { HideNPC(false); } } } } /*if (Buffs.GetCustomVar("$FR_NPC_Hidden") == 1) { //Log.Out("EntityNPCRebirth-OnUpdateLive flHidden == 1"); //Log.Out("EntityNPCRebirth-OnUpdateLive enabled: " + enabled); //Log.Out("EntityNPCRebirth-OnUpdateLive scale: " + scale); Log.Out("EntityNPCRebirth-OnUpdateLive HIDENPC 1"); HideNPC(true); if (!RebirthVariables.isHordeNight) { //float flGoneMining = this.Buffs.GetCustomVar("$FuriousRamsayGoneMining"); //float flRepairing = this.Buffs.GetCustomVar("$FR_NPC_Repairing"); //Log.Out("EntityNPCRebirth-OnUpdateLive bMine: " + bMine); //Log.Out("EntityNPCRebirth-OnUpdateLive bRepairing: " + bRepairing); if (!bMine && !bRepairing && delta == 0 ) { Log.Out("EntityNPCRebirth-OnUpdateLive UNHIDE NPC"); HideNPC(false); } } }*/ if (bRepair) { //Log.Out("EntityNPCRebirth-OnUpdateLive bRepairing: " + bRepairing); if (!this.bRepairing) { //Log.Out("EntityNPCRebirth-OnUpdateLive !this.bRepairing"); GameTimerTicks = GameTimer.Instance.ticks; bRepairing = true; numRepairedBlocks = 0; watch.Reset(); watch.Start(); if (strSerialize != null) { if (strSerialize.Length > 0) { //Log.Out("EntityNPCRebirth-OnUpdateLive strSerialize.Length: " + strSerialize.Length); //Log.Out("EntityNPCRebirth-OnUpdateLive strSerializeTmp LOAD: " + strSerialize); string[] array = strSerialize.Split(new char[] { '<' }); if (array.Length > 0) { for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[] { '|' }); for (int i2 = 0; i2 < array2.Length; i2++) { strCouldNotRepair[numCouldNotRepair, i2] = array2[i2]; //Log.Out("EntityNPCRebirth-OnUpdateLive RELOAD strCouldNotRepair[" + numCouldNotRepair + "," + i2 + "] i(" + i + "): " + strCouldNotRepair[numCouldNotRepair, i2]); } numCouldNotRepair++; } } } } strSerialize = ""; //Log.Out("EntityNPCRebirth-OnUpdateLive numCouldNotRepair: " + numCouldNotRepair); } float range = RebirthVariables.repairWidth; float rangeY = RebirthVariables.repairHeight; int blockCount = 0; numCouldNotRepair = 0; //Log.Out("EntityNPCRebirth-OnUpdateLive strSerialize: " + strSerialize); ////Log.Out("EntityNPCRebirth-OnUpdateLive AccumulatedTicks: " + AccumulatedTicks); ////Log.Out("EntityNPCRebirth-OnUpdateLive tempTickRate: " + tempTickRate); if (delta > 0) { if (this.LeaderUtils.Owner != null) { List tileEntities = RemoteCraftingUtils.GetTileEntities(this.LeaderUtils.Owner); GameTimerTicks = GameTimer.Instance.ticks; watch.Stop(); //Log.Out("EntityNPCRebirth-OnUpdateLive Execution Time: " + watch.ElapsedMilliseconds + " ms"); for (int x = -(int)range; x <= range; x++) { for (int z = -(int)range; z <= range; z++) { for (int y = (int)this.position.y - (int)rangeY; y <= (int)(this.position.y) + (int)rangeY; y++) { var blockPosition = new Vector3i(this.position.x + x, y, this.position.z + z); BlockValue block = this.world.GetBlock(blockPosition); if (!block.isair) { if (block.damage > 0 && block.Block.GetBlockName() != "terrAsphalt" && block.Block.GetBlockName() != "terrGravel" && block.Block.GetBlockName() != "terrForestGround" && block.Block.GetBlockName() != "terrDestroyedStone" && block.Block.GetBlockName() != "terrSnow" && block.Block.GetBlockName() != "terrDesertGround" && block.Block.GetBlockName() != "terrBurntForestGround" && block.Block.GetBlockName() != "terrDirt" && block.Block.GetBlockName() != "terrSand" && block.Block.GetBlockName() != "terrSandStone" && block.Block.GetBlockName() != "terrTopSoil" && block.Block.GetBlockName() != "terrDestroyedWoodDebris" ) { //Log.Out("=============================================================================="); //Log.Out("EntityNPCRebirth-OnUpdateLive blockCount: " + blockCount); //Log.Out("EntityNPCRebirth-OnUpdateLive position: " + blockPosition); //Log.Out("EntityNPCRebirth-OnUpdateLive block: " + block.Block.GetBlockName()); //Log.Out("EntityNPCRebirth-OnUpdateLive damage: " + block.damage); float damagePerc = (float)block.damage / (float)Block.list[block.type].MaxDamage; ; //Log.Out("EntityNPCRebirth-OnUpdateLive damagePerc: " + damagePerc); if (block.Block.RepairItems != null) { for (int i = 0; i < block.Block.RepairItems.Count; i++) { int needed = block.Block.RepairItems[i].Count; needed = (int)Mathf.Ceil(damagePerc * needed); ItemValue itemValue = new ItemValue(ItemClass.GetItem(block.Block.RepairItems[i].ItemName, false).type, true); bool bHaveItems = RebirthUtilities.ContainersHaveItem(tileEntities, needed, itemValue); if (!bHaveItems) { //Log.Out("EntityNPCRebirth-OnUpdateLive COULD NOT FIND, POSITION: " + numCouldNotRepair); strCouldNotRepair[numCouldNotRepair, 0] = block.Block.RepairItems[i].ItemName; strCouldNotRepair[numCouldNotRepair, 1] = needed.ToString(); //Log.Out("EntityNPCRebirth-OnUpdateLive ITEM: " + strCouldNotRepair[numCouldNotRepair, 0]); //Log.Out("EntityNPCRebirth-OnUpdateLive COUNT: " + strCouldNotRepair[numCouldNotRepair, 1]); numCouldNotRepair++; //Log.Out("EntityNPCRebirth-OnUpdateLive DON'T HAVE ENOUGH OF: " + block.Block.RepairItems[i].ItemName); } else { RebirthUtilities.RemoveContainerItems(tileEntities, needed, itemValue); block.damage = 0; Chunk chunk = (Chunk)this.world.GetChunkFromWorldPos(blockPosition); world.SetBlock(chunk.ClrIdx, blockPosition, block, false, false); world.SetBlockRPC(chunk.ClrIdx, blockPosition, block, block.Block.Density); //Log.Out("EntityNPCRebirth-OnUpdateLive REMOVED " + needed + " " + block.Block.RepairItems[i].ItemName); numRepairedBlocks++; } //Log.Out("EntityNPCRebirth-OnUpdateLive item: " + block.Block.RepairItems[i].ItemName); //Log.Out("EntityNPCRebirth-OnUpdateLive needed: " + needed); } } blockCount++; if (blockCount >= 100000) { //Log.Out("EntityNPCRebirth-OnUpdateLive Break"); break; } } } if (blockCount >= 100000) { break; } } if (blockCount >= 100000) { break; } } } if (blockCount < 100000) { bRepairing = false; bRepair = false; //Log.Out("EntityNPCRebirth-OnUpdateLive numRepairedBlocks: " + numRepairedBlocks); //Log.Out("EntityNPCRebirth-OnUpdateLive HideDuration END: " + HideDuration); if (this.LeaderUtils.Owner) { //Log.Out("EntityNPCRebirth-OnUpdateLive HAS LEADER"); //Log.Out("EntityNPCRebirth-OnUpdateLive LEADER HAS REPAIR BUFF"); int numDuration = (int)numRepairedBlocks; // / 20; //Log.Out("EntityNPCRebirth-OnUpdateLive numDuration: " + numDuration); this.LeaderUtils.Owner.Buffs.SetCustomVar("$varFuriousRamsayHelpRepairBuffDisplay", numDuration); this.LeaderUtils.Owner.Buffs.SetCustomVar("$FR_NPC_Repair", this.entityId); this.LeaderUtils.Owner.Buffs.AddBuff("FuriousRamsayHelpRepairBuff"); } else { //Log.Out("EntityNPCRebirth-OnUpdateLive HAS NO LEADER"); } if (numCouldNotRepair > 0) { string strSerializeTmp = ""; for (int numFind = 0; (numFind < numCouldNotRepair); numFind++) { if (strSerializeTmp.Length > 0) { strSerializeTmp = strSerializeTmp + "<"; } strSerializeTmp = strSerializeTmp + strCouldNotRepair[numFind, 0] + "|" + strCouldNotRepair[numFind, 1]; } //Log.Out("EntityNPCRebirth-OnUpdateLive strSerializeTmp A: " + strSerializeTmp); strSerialize = strSerializeTmp; string[,] strCouldNotRepairTmp = new string[numCouldNotRepair * 2, 2]; int numCouldNotRepairTmp = 0; string[] array = strSerializeTmp.Split(new char[] { '<' }); if (array.Length > 0) { for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[] { '|' }); for (int i2 = 0; i2 < array2.Length; i2++) { //Log.Out("EntityNPCRebirth-OnUpdateLive numCouldNotRepairTmp: " + numCouldNotRepairTmp); //Log.Out("EntityNPCRebirth-OnUpdateLive i2: " + i2); //Log.Out("EntityNPCRebirth-OnUpdateLive array2[i2]: " + array2[i2]); strCouldNotRepairTmp[numCouldNotRepairTmp, i2] = array2[i2]; //Log.Out("EntityNPCRebirth-OnUpdateLive RELOAD strCouldNotRepairTmp[" + numCouldNotRepairTmp + "," + i2 + "] i(" + i + "): " + strCouldNotRepairTmp[numCouldNotRepairTmp, i2]); } numCouldNotRepairTmp++; } } string[,] strCouldNotRepairTmp2 = new string[numCouldNotRepairTmp * 2, 2]; int numCouldNotRepairTmp2 = 0; for (int i = 0; i < numCouldNotRepairTmp; i++) { if (numCouldNotRepairTmp2 > 0) { bool bFound = false; for (int j = 0; j < numCouldNotRepairTmp2; j++) { if (strCouldNotRepairTmp2[j, 0] == strCouldNotRepairTmp[i, 0]) { bFound = true; int numRepair = 0; //Log.Out("EntityNPCRebirth-OnUpdateLive FOUND"); //Log.Out("EntityNPCRebirth-OnUpdateLive numCouldNotRepairTmp2: " + numCouldNotRepairTmp2); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp2[j, 0]: " + strCouldNotRepairTmp2[j, 0]); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp2[j, 1]: " + strCouldNotRepairTmp2[j, 1]); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp[i, 0]: " + strCouldNotRepairTmp[i, 0]); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp[i, 1]: " + strCouldNotRepairTmp[i, 1]); int numRepair1 = int.Parse(strCouldNotRepairTmp2[j, 1]); int numRepair2 = int.Parse(strCouldNotRepairTmp[i, 1]); numRepair = numRepair1 + numRepair2; strCouldNotRepairTmp2[j, 1] = numRepair.ToString(); } } if (!bFound) { //Log.Out("EntityNPCRebirth-OnUpdateLive DID NOT FIND"); strCouldNotRepairTmp2[numCouldNotRepairTmp2, 0] = strCouldNotRepairTmp[i, 0]; strCouldNotRepairTmp2[numCouldNotRepairTmp2, 1] = strCouldNotRepairTmp[i, 1]; //Log.Out("EntityNPCRebirth-OnUpdateLive numCouldNotRepairTmp2: " + numCouldNotRepairTmp2); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp2[numCouldNotRepairTmp2, 0]: " + strCouldNotRepairTmp2[numCouldNotRepairTmp2, 0]); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp2[numCouldNotRepairTmp2, 1]: " + strCouldNotRepairTmp2[numCouldNotRepairTmp2, 1]); numCouldNotRepairTmp2++; } } else { //Log.Out("EntityNPCRebirth-OnUpdateLive INITIAL ENTRY"); strCouldNotRepairTmp2[numCouldNotRepairTmp2, 0] = strCouldNotRepairTmp[i, 0]; strCouldNotRepairTmp2[numCouldNotRepairTmp2, 1] = strCouldNotRepairTmp[i, 1]; //Log.Out("EntityNPCRebirth-OnUpdateLive numCouldNotRepairTmp2: " + numCouldNotRepairTmp2); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp[i, 0]: " + strCouldNotRepairTmp[i, 0]); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp[i, 1]: " + strCouldNotRepairTmp[i, 1]); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp2[numCouldNotRepairTmp2, 0]: " + strCouldNotRepairTmp2[numCouldNotRepairTmp2, 0]); //Log.Out("EntityNPCRebirth-OnUpdateLive strCouldNotRepairTmp2[numCouldNotRepairTmp2, 1]: " + strCouldNotRepairTmp2[numCouldNotRepairTmp2, 1]); numCouldNotRepairTmp2++; } } string strSerializeTmp2 = ""; for (int numFind = 0; (numFind < numCouldNotRepairTmp2); numFind++) { if (strSerializeTmp2.Length > 0) { strSerializeTmp2 = strSerializeTmp2 + "<"; } strSerializeTmp2 = strSerializeTmp2 + strCouldNotRepairTmp2[numFind, 0] + "|" + strCouldNotRepairTmp2[numFind, 1]; } //Log.Out("EntityNPCRebirth-OnUpdateLive strSerializeTmp2 A2: " + strSerializeTmp2); strSerialize = strSerializeTmp2; } } else { if (numCouldNotRepair > 0) { string strSerializeTmp = ""; for (int numFind = 0; (numFind < numCouldNotRepair); numFind++) { if (strSerializeTmp.Length > 0) { strSerializeTmp = strSerializeTmp + "<"; } strSerializeTmp = strSerializeTmp + strCouldNotRepair[numFind, 0] + "|" + strCouldNotRepair[numFind, 1]; } //Log.Out("EntityNPCRebirth-OnUpdateLive strSerializeTmp B: " + strSerializeTmp); strSerialize = strSerializeTmp; //Log.Out("EntityNPCRebirth-OnUpdateLive strSerialize: " + strSerialize); } } } } } //Log.Out("EntityNPCRebirth-OnUpdateLive this.rotation.y: " + this.rotation.y); if (isNPC) { ulong elpasedTimeSurvivor = GameTimer.Instance.ticks - AccumulatedTicksSurvivor; float flEntityRespawn = this.Buffs.GetCustomVar("$FR_NPC_Respawn"); if (elpasedTimeSurvivor >= 60UL && this.LeaderUtils.Owner != null && flEntityRespawn == 0) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 1"); AccumulatedTicksSurvivor = GameTimer.Instance.ticks; //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor bag size: " + this.bag.SlotCount); if (this.lootContainer != null) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 2"); bool hasFireBuff = this.Buffs.HasBuff("FuriousRamsayFireZombieDamage") || this.Buffs.HasBuff("buffBurningFlamingArrow") || this.Buffs.HasBuff("buffBurningMolotov") || this.Buffs.HasBuff("buffBurningEnvironmentHack") || this.Buffs.HasBuff("buffBurningEnvironment") || this.Buffs.HasBuff("buffBurningElement") || this.Buffs.HasBuff("buffIsOnFire") || this.Buffs.HasBuff("FuriousRamsayFireZombieAoEDamage") || this.Buffs.HasBuff("FuriousRamsayFireZombieAoEDamageDisplay") || this.Buffs.HasBuff("FuriousRamsayAddBurningEnemyBoss") || this.Buffs.HasBuff("FuriousRamsayBurningTrapDamage"); bool blIsEmpty = this.lootContainer.IsEmpty(); //FIRE ItemValue itemFuriousRamsayModFireResist = ItemClass.GetItem("FuriousRamsayModFireResist", false); bool hasFuriousRamsayModFireResist = lootContainer.HasItem(itemFuriousRamsayModFireResist); //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor hasFuriousRamsayModFireResist: " + hasFuriousRamsayModFireResist); //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor hasFuriousRamsayModFireResist: " + hasFuriousRamsayModFireResist); if (hasFuriousRamsayModFireResist) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor HAS FIRE IMMUNITY"); this.Buffs.AddBuff("FuriousRamsayResistFire"); this.Buffs.AddBuff("FuriousRamsayAddFireBuffEffect"); } else { if (this.Buffs.HasBuff("FuriousRamsayResistFire")) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor NO LONGER HAS FIRE IMMUNITY"); this.Buffs.RemoveBuff("FuriousRamsayResistFire"); this.Buffs.RemoveBuff("FuriousRamsayAddFireBuffEffect"); } } //SHOCK ItemValue itemFuriousRamsayModShockResist = ItemClass.GetItem("FuriousRamsayModShockResist", false); bool hasFuriousRamsayModShockResist = lootContainer.HasItem(itemFuriousRamsayModShockResist); if (hasFuriousRamsayModShockResist) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor HAS SHOCK IMMUNITY"); this.Buffs.AddBuff("FuriousRamsayResistShock"); this.Buffs.AddBuff("FuriousRamsayAddShockBuffEffect"); } else { if (this.Buffs.HasBuff("FuriousRamsayResistShock")) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor NO LONGER HAS SHOCK IMMUNITY"); this.Buffs.RemoveBuff("FuriousRamsayResistShock"); this.Buffs.RemoveBuff("FuriousRamsayAddShockBuffEffect"); } } //EXPLOSION ItemValue itemFuriousRamsayModSmokeResist = ItemClass.GetItem("FuriousRamsayModSmokeResist", false); bool hasFuriousRamsayModSmokeResist = lootContainer.HasItem(itemFuriousRamsayModSmokeResist); if (hasFuriousRamsayModSmokeResist) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor HAS EXPLOSION IMMUNITY"); this.Buffs.AddBuff("FuriousRamsayResistSmoke"); this.Buffs.AddBuff("FuriousRamsayAddSmokeBuffEffect"); } else { if (this.Buffs.HasBuff("FuriousRamsayResistSmoke")) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor NO LONGER HAS EXPLOSION IMMUNITY"); this.Buffs.RemoveBuff("FuriousRamsayResistSmoke"); this.Buffs.RemoveBuff("FuriousRamsayAddSmokeBuffEffect"); } } //FIRE AND SHOCK ItemValue itemFuriousRamsayModResistFireShock = ItemClass.GetItem("FuriousRamsayModFireShockResist", false); bool hasFuriousRamsayModResistFireShock = lootContainer.HasItem(itemFuriousRamsayModResistFireShock); if (hasFuriousRamsayModResistFireShock) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor HAS FIRE/SHOCK IMMUNITY"); this.Buffs.AddBuff("FuriousRamsayResistFireShock"); this.Buffs.AddBuff("FuriousRamsayAddFireShockBuffEffect"); } else { if (this.Buffs.HasBuff("FuriousRamsayResistFireShock")) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor NO LONGER HAS FIRE/SHOCK IMMUNITY"); this.Buffs.RemoveBuff("FuriousRamsayResistFireShock"); this.Buffs.RemoveBuff("FuriousRamsayAddFireShockBuffEffect"); } } //FIRE, SHOCK AND EXPLOSION ItemValue itemFuriousRamsayModResistFireShockSmoke = ItemClass.GetItem("FuriousRamsayModFireShockSmokeResist", false); bool hasFuriousRamsayModResistFireShockSmoke = lootContainer.HasItem(itemFuriousRamsayModResistFireShockSmoke); if (hasFuriousRamsayModResistFireShockSmoke) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor HAS FIRE/SHOCK/EXPLOPSION IMMUNITY"); this.Buffs.AddBuff("FuriousRamsayResistFireShockSmoke"); this.Buffs.AddBuff("FuriousRamsayAddFireShockSmokeBuffEffect"); } else { if (this.Buffs.HasBuff("FuriousRamsayResistFireShockSmoke")) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor NO LONGER HAS FIRE/SHOCK/EXPLOPSION IMMUNITY"); this.Buffs.RemoveBuff("FuriousRamsayResistFireShockSmoke"); this.Buffs.RemoveBuff("FuriousRamsayAddFireShockSmokeBuffEffect"); } } if (bHasTags && blIsEmpty) { float flContainerY = this.Buffs.GetCustomVar("$FR_NPC_ContainerY"); if (flContainerY == 0) { this.Buffs.SetCustomVar("$FR_NPC_ContainerY", this.lootContainer.GetContainerSize().y); flContainerY = this.lootContainer.GetContainerSize().y; } int flCurrentContainerSizeY = this.lootContainer.GetContainerSize().y; float flEntityLevel = this.Buffs.GetCustomVar("$FR_NPC_Level"); int numAdd = (int)flContainerY + (int)flEntityLevel; if (numAdd > 10) { numAdd = 10; } if (numAdd > flCurrentContainerSizeY) { //Log.Out("EntityNPCRebirth-OnUpdateLive SET CONTAINER SIZE 8X" + numAdd); lootContainer.SetContainerSize(new Vector2i(8, numAdd)); } } if (bHasTags && !blIsEmpty) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 3"); if (hasFireBuff) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 4"); ItemValue itemMurkyWater = ItemClass.GetItem("drinkJarRiverWater", false); bool hasMurkyWater = lootContainer.HasItem(itemMurkyWater); ItemValue itemBoiledWater = ItemClass.GetItem("drinkJarBoiledWater", false); bool hasBoiledWater = lootContainer.HasItem(itemBoiledWater); ItemValue itemDistilledWater = ItemClass.GetItem("drinkJarPureMineralWater", false); bool hasDistilledWater = lootContainer.HasItem(itemDistilledWater); bool removeFire = false; ItemStack[] array = lootContainer.GetItems(); if (hasMurkyWater) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 5"); RebirthUtilities.takeFromEntityContainer(this, "drinkJarRiverWater"); removeFire = true; } else if (hasBoiledWater) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 6"); RebirthUtilities.takeFromEntityContainer(this, "drinkJarBoiledWater"); removeFire = true; } else if (hasDistilledWater) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 6"); RebirthUtilities.takeFromEntityContainer(this, "drinkJarPureMineralWater"); removeFire = true; } if (removeFire) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 7"); this.Buffs.AddBuff("buffExtinguishFire"); this.Buffs.RemoveBuff("FuriousRamsayFireZombieDamage"); this.Buffs.RemoveBuff("buffBurningFlamingArrow"); this.Buffs.RemoveBuff("buffBurningMolotov"); this.Buffs.RemoveBuff("buffBurningEnvironmentHack"); this.Buffs.RemoveBuff("buffBurningEnvironment"); this.Buffs.RemoveBuff("buffBurningElement"); this.Buffs.RemoveBuff("buffIsOnFire"); this.Buffs.RemoveBuff("FuriousRamsayFireZombieAoEDamage"); this.Buffs.RemoveBuff("FuriousRamsayFireZombieAoEDamageDisplay"); this.Buffs.RemoveBuff("FuriousRamsayAddBurningEnemyBoss"); this.Buffs.RemoveBuff("FuriousRamsayBurningTrapDamage"); this.Buffs.AddBuff("FuriousRamsayTempResistFire"); } } } if (!blIsEmpty) { //NPC self healing int healedAmount = 0; int survivorMaxHealth = this.GetMaxHealth(); int survivorHealth = this.Health; int survivorHealthModifier = (int)Math.Floor(this.Stats.Health.MaxModifier); int missingHealth = survivorMaxHealth - survivorHealth - healedAmount + survivorHealthModifier; bool bHealing = this.Buffs.HasBuff("buffHealHealth"); float numHealing = this.Buffs.GetCustomVar("medicalRegHealthAmount"); bool bPainKillers = this.Buffs.HasBuff("buffDrugPainkillers"); bool isSkeleton = this.HasAnyTags(FastTags.Parse("skeletonCompanion")); bool isZombie = this.HasAnyTags(FastTags.Parse("zombieCompanion")); float numHealingLeft = missingHealth - numHealing; if (numHealingLeft > 0 && missingHealth > 0 && !bHealing) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8"); ItemValue itemRawMeat = ItemClass.GetItem("foodRawMeat", false); bool hasRawMeat = lootContainer.HasItem(itemRawMeat); ItemValue itemBone = ItemClass.GetItem("resourceBone", false); bool hasBone = lootContainer.HasItem(itemBone); ItemValue itemBrains = ItemClass.GetItem("foodRottingFlesh", false); bool hasBrain = lootContainer.HasItem(itemBrains); ItemValue itemMedicalBandage = ItemClass.GetItem("medicalBandage", false); bool hasMedicalBandage = lootContainer.HasItem(itemMedicalBandage); ItemValue itemMedicalFirstAidBandage = ItemClass.GetItem("medicalFirstAidBandage", false); bool hasMedicalFirstAidBandage = lootContainer.HasItem(itemMedicalFirstAidBandage); ItemValue itemMedicalFirstAidKit = ItemClass.GetItem("medicalFirstAidKit", false); bool hasMedicalFirstAidKit = lootContainer.HasItem(itemMedicalFirstAidKit); ItemValue itemDrugPainkillers = ItemClass.GetItem("drugPainkillers", false); bool hasDrugPainkillers = lootContainer.HasItem(itemDrugPainkillers); //Log.Out("EntityNPCRebirth-OnUpdateLive survivorHealth: " + survivorHealth); //Log.Out("EntityNPCRebirth-OnUpdateLive numHealingLeft: " + numHealingLeft); //Log.Out("EntityNPCRebirth-OnUpdateLive missingHealth: " + missingHealth); //Log.Out("EntityNPCRebirth-OnUpdateLive hasMedicalBandage: " + hasMedicalBandage); //Log.Out("EntityNPCRebirth-OnUpdateLive hasMedicalFirstAidBandage: " + hasMedicalFirstAidBandage); //Log.Out("EntityNPCRebirth-OnUpdateLive hasMehasMedicalFirstAidKitdicalBandage: " + hasMedicalFirstAidKit); //Log.Out("EntityNPCRebirth-OnUpdateLive hasDrugPainkillers: " + hasDrugPainkillers); //Log.Out("EntityNPCRebirth-OnUpdateLive bPainKillers: " + bPainKillers); if (isZombie) { if (numHealingLeft >= 90 && hasBrain) { this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayRawMeatTrigger"); RebirthUtilities.takeFromEntityContainer(this, "foodRottingFlesh"); this.Buffs.AddBuff("FuriousRamsayBrainHealTrigger"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } } else if (isSkeleton) { if (numHealingLeft >= 70 && hasBone) { this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayRawMeatTrigger"); RebirthUtilities.takeFromEntityContainer(this, "resourceBone"); this.Buffs.AddBuff("FuriousRamsayBoneHealTrigger"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } } else if (isAnimal) { if (numHealingLeft >= 140 && hasRawMeat) { this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayRawMeatHealTrigger"); RebirthUtilities.takeFromEntityContainer(this, "foodRawMeat"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } } else { if (numHealingLeft >= 100 && !bPainKillers && survivorHealth < 50 && hasDrugPainkillers) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8a"); this.Buffs.SetCustomVar("$buffDrugPainkillersDuration", 583); this.Buffs.AddBuff("FuriousRamsayDrugPainkillersTrigger"); RebirthUtilities.takeFromEntityContainer(this, "drugPainkillers"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } else if (numHealingLeft >= 100 && hasMedicalFirstAidKit) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8b"); this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayMedicalFirstAidKitTrigger"); RebirthUtilities.takeFromEntityContainer(this, "medicalFirstAidKit"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } else if ((numHealingLeft >= 20 && numHealingLeft < 100) && hasMedicalFirstAidBandage) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8c"); this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayMedicalFirstAidBandageTrigger"); RebirthUtilities.takeFromEntityContainer(this, "medicalFirstAidBandage"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } else if ((numHealingLeft >= 6 && numHealingLeft < 20) && hasMedicalBandage) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8d"); this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayMedicalBandageTrigger"); RebirthUtilities.takeFromEntityContainer(this, "medicalBandage"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } else if (numHealingLeft >= 20 && hasMedicalFirstAidBandage) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8e"); this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayMedicalFirstAidBandageTrigger"); RebirthUtilities.takeFromEntityContainer(this, "medicalFirstAidBandage"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } else if (numHealingLeft >= 6 && hasMedicalBandage) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8f"); this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayMedicalBandageTrigger"); RebirthUtilities.takeFromEntityContainer(this, "medicalBandage"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } else if (numHealingLeft >= 30 && !bPainKillers && hasDrugPainkillers) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8g"); this.Buffs.SetCustomVar("$buffDrugPainkillersDuration", 583); this.Buffs.AddBuff("FuriousRamsayDrugPainkillersTrigger"); RebirthUtilities.takeFromEntityContainer(this, "drugPainkillers"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } else if (numHealingLeft >= 50 && hasMedicalFirstAidKit) { //Log.Out("EntityNPCRebirth-OnUpdateLive elpasedTimeSurvivor 8h"); this.Buffs.SetCustomVar("$medicRegHealthIncreaseSpeed", 4f); this.Buffs.AddBuff("FuriousRamsayMedicalFirstAidKitTrigger"); RebirthUtilities.takeFromEntityContainer(this, "medicalFirstAidKit"); this.Buffs.AddBuff("FuriousRamsayTriggerHealingAnim"); this.Buffs.AddBuff("FuriousRamsayHealParticle"); } } } } } } if (flEntityRespawn > 0) { //Log.Out("EntityNPCRebirth-OnUpdateLive flEntityRespawn: " + flEntityRespawn); this.isHirable = false; } else { if (!this.HasAnyTags(FastTags.Parse("ignoreFactionChange"))) { this.factionId = FactionManager.Instance.GetFactionByName("whiteriver").ID; } this.isHirable = true; numReposition = 0; } } } base.OnUpdateLive(); if (!isAnimal && !this.bDead) { //Log.Out("EntityNPCRebirth-OnUpdateLive strWeaponType: " + strWeaponType); if (bHasTags) { try { float numSupplyAmmo = this.Buffs.GetCustomVar("$varFuriousRamsaySupplyAmmo"); if (this.Buffs.HasCustomVar("NPCInteractedFlag") && strWeaponType != "none") { //Log.Out("EntityNPCRebirth-OnUpdateLive NPCInteractedFlag"); ItemValue item762Ammo = ItemClass.GetItem("ammo762mmBulletBall", false); ItemValue item9mmAmmo = ItemClass.GetItem("ammo9mmBulletBall", false); ItemValue item44Ammo = ItemClass.GetItem("ammo44MagnumBulletBall", false); ItemValue itemShellAmmo = ItemClass.GetItem("ammoShotgunShell", false); ItemValue gunNPCPistol = ItemClass.GetItem("gunNPCPistol", false); ItemValue gunNPCDPistol = ItemClass.GetItem("gunNPCDPistol", false); ItemValue gunNPCPShotgun = ItemClass.GetItem("gunNPCPShotgun", false); ItemValue gunNPCSMG5 = ItemClass.GetItem("gunNPCSMG5", false); ItemValue gunNPCSRifle = ItemClass.GetItem("gunNPCSRifle", false); ItemValue gunNPCTRifle = ItemClass.GetItem("gunNPCTRifle", false); ItemValue gunNPCM60 = ItemClass.GetItem("gunNPCM60", false); ItemValue gunNPCAk47 = ItemClass.GetItem("gunNPCAk47", false); if (this.inventory.holdingItem.GetItemName() == "meleeNPCEmptyHand") { //Log.Out("EntityNPCRebirth-OnUpdateLive Holding meleeNPCEmptyHand, Weapon: " + strWeaponType); //Log.Out("EntityNPCRebirth-OnUpdateLive Holding meleeNPCEmptyHand, HasItem item762Ammo: " + this.lootContainer.HasItem(item762Ammo)); if (strWeaponType == "PistolUser" && (this.lootContainer.HasItem(item9mmAmmo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCPistol"; string _strAmmo = "ammo9mmBulletBall"; strAmmoType = _strAmmo; ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt(_strRangedWeapon, 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (strWeaponType == "DPistolUser" && (this.lootContainer.HasItem(item44Ammo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCDPistol"; string _strAmmo = "ammo44MagnumBulletBall"; strAmmoType = _strAmmo; ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt(_strRangedWeapon, 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (strWeaponType == "PShotgunUser" && (this.lootContainer.HasItem(itemShellAmmo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCPShotgun"; string _strAmmo = "ammoShotgunShell"; strAmmoType = _strAmmo; ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt(_strRangedWeapon, 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (strWeaponType == "SMGUser" && (this.lootContainer.HasItem(item9mmAmmo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCSMG5"; string _strAmmo = "ammo9mmBulletBall"; strAmmoType = _strAmmo; ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt(_strRangedWeapon, 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (strWeaponType == "SRifleUser" && (this.lootContainer.HasItem(item762Ammo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCSRifle"; string _strAmmo = "ammo762mmBulletBall"; strAmmoType = _strAmmo; ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt(_strRangedWeapon, 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (strWeaponType == "TRifleUser" && (this.lootContainer.HasItem(item762Ammo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCTRifle"; string _strAmmo = "ammo762mmBulletBall"; strAmmoType = _strAmmo; ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt("ARUser", 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (strWeaponType == "M60User" && (this.lootContainer.HasItem(item762Ammo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCM60"; string _strAmmo = "ammo762mmBulletBall"; strAmmoType = _strAmmo; ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt(_strRangedWeapon, 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (strWeaponType == "AK47User" && (this.lootContainer.HasItem(item762Ammo) || numSupplyAmmo == 0)) { string _strRangedWeapon = strWeaponType; string _strRangedWeaponItem = "gunNPCAk47"; string _strAmmo = "ammo762mmBulletBall"; strAmmoType = _strAmmo; //Log.Out("EntityNPCRebirth-OnUpdateLive _strRangedWeapon: " + _strRangedWeapon + ", strWeaponType: " + strWeaponType + " and has ammo"); ItemStack[] array = this.lootContainer.GetItems(); this.Buffs.RemoveBuff("EmptyHandUser"); this.Buffs.AddBuff("buffReload"); this.Buffs.AddBuff("buffBurst"); this.Buffs.AddBuff(_strRangedWeapon); Transform transform2 = this.RootTransform.FindInChilds(_strRangedWeapon.Replace("User", ""), true); this.rightHandTransformName = _strRangedWeapon.Replace("User", ""); this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("EmptyHandUser", 0); this.emodel.avatarController.UpdateInt(_strRangedWeapon, 1); ItemStack itemStack = ItemStack.FromString(_strRangedWeaponItem); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString(_strAmmo); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } } else if (this.inventory.holdingItem.GetItemName() == "gunNPCPistol" && !this.lootContainer.HasItem(item9mmAmmo) && numSupplyAmmo == 1) { if (this.Buffs.HasBuff(strWeaponType)) { this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt(strWeaponType, 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammo9mmBulletBall"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (this.inventory.holdingItem.GetItemName() == "gunNPCDPistol" && !this.lootContainer.HasItem(item44Ammo) && numSupplyAmmo == 1) { if (this.Buffs.HasBuff(strWeaponType)) { this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt(strWeaponType, 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammo44MagnumBulletBall"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (this.inventory.holdingItem.GetItemName() == "gunNPCPShotgun" && !this.lootContainer.HasItem(itemShellAmmo) && numSupplyAmmo == 1) { if (this.Buffs.HasBuff(strWeaponType)) { this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt(strWeaponType, 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammoShotgunShell"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (this.inventory.holdingItem.GetItemName() == "gunNPCSMG5" && !this.lootContainer.HasItem(item9mmAmmo) && numSupplyAmmo == 1) { if (this.Buffs.HasBuff(strWeaponType)) { this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt(strWeaponType, 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammo9mmBulletBall"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (this.inventory.holdingItem.GetItemName() == "gunNPCSRifle" && !this.lootContainer.HasItem(item762Ammo) && numSupplyAmmo == 1) { if (this.Buffs.HasBuff(strWeaponType)) { this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt(strWeaponType, 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammo762mmBulletBall"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (this.inventory.holdingItem.GetItemName() == "gunNPCTRifle" && !this.lootContainer.HasItem(item762Ammo) && numSupplyAmmo == 1) { if (this.Buffs.HasBuff(strWeaponType)) { this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt("ARUser", 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammo762mmBulletBall"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (this.inventory.holdingItem.GetItemName() == "gunNPCM60" && !this.lootContainer.HasItem(item762Ammo) && numSupplyAmmo == 1) { if (this.Buffs.HasBuff(strWeaponType)) { this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt(strWeaponType, 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammo762mmBulletBall"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } else if (this.inventory.holdingItem.GetItemName() == "gunNPCAk47" && !this.lootContainer.HasItem(item762Ammo) && numSupplyAmmo == 1) { //Log.Out("EntityNPCRebirth-OnUpdateLive Holding gunNPCAk47 no ammo"); if (this.Buffs.HasBuff(strWeaponType)) { //Log.Out("EntityNPCRebirth-OnUpdateLive have buff: " + strWeaponType); this.Buffs.RemoveBuff(strWeaponType); this.Buffs.RemoveBuff("buffReload"); this.Buffs.RemoveBuff("buffBurst"); this.Buffs.AddBuff("EmptyHandUser"); } //Log.Out("EntityNPCRebirth-OnUpdateLive _strRangedWeapon: meleeNPCEmptyHand, strWeaponType: " + strWeaponType + " and has no ammo"); Transform transform2 = this.RootTransform.FindInChilds("RightWeapon", true); this.rightHandTransformName = "RightWeapon"; this.emodel.SetInRightHand(transform2); this.emodel.avatarController.UpdateInt(strWeaponType, 0); this.emodel.avatarController.UpdateInt("EmptyHandUser", 1); ItemStack itemStack = ItemStack.FromString("meleeNPCEmptyHand"); this.inventory.SetItem(0, itemStack); itemStack = ItemStack.FromString("ammo762mmBulletBall"); this.inventory.SetItem(1, itemStack); this.inventory.ForceHoldingItemUpdate(); } } } catch (Exception ex) { } } } } public override void Read(byte _version, BinaryReader _br) { base.Read(_version, _br); int npcHealth = _br.ReadInt32(); //Log.Out("EntityNPCRebirth-Read HEALTH: " + npcHealth); Health = npcHealth; this.Buffs.AddBuff("delayPickup"); if (this.Buffs.GetCustomVar("$updateStats") == 1f) { this.Buffs.SetCustomVar("$tempHealth", npcHealth); GameManager.Instance.StartCoroutine(RebirthUtilities.adjustNPCStats(this)); } this.Buffs.SetCustomVar("$updateStats", 1f); try { HideDuration = _br.ReadInt32(); } catch { HideDuration = 0; } //Log.Out("EntityNPCRebirth-Read HideDuration: " + HideDuration); try { bMine = _br.ReadBoolean(); } catch { bMine = false; } try { bRepair = _br.ReadBoolean(); } catch { bRepair = false; } try { this.strSerialize = _br.ReadString(); } catch { this.strSerialize = ""; } try { this.lootDropEntityClass = _br.ReadString(); } catch { this.lootDropEntityClass = ""; } //Log.Out("EntityNPCRebirth-Write AFTER currentOrder: " + this.currentOrder); try { this.otherTags = _br.ReadString(); } catch { this.otherTags = ""; } } // Saves the buff and quest information public override void Write(BinaryWriter _bw, bool _bNetworkWrite) { //Log.Out("StackTrace: '{0}'", Environment.StackTrace); base.Write(_bw, _bNetworkWrite); //Log.Out("EntityNPCRebirth-Write HEALTH: " + Health); _bw.Write(Health); //Log.Out("EntityNPCRebirth-Write HideDuration: " + (GameManager.Instance.World.worldTime / 20) + delta); _bw.Write((int)((GameManager.Instance.World.worldTime / 20) + delta)); _bw.Write(this.bMine); _bw.Write(this.bRepair); _bw.Write(this.strSerialize); _bw.Write(lootDropEntityClass); _bw.Write(otherTags); } public override string EntityName { get { if (_strMyName.Contains("REBIRTHREBIRTH")) { return _strMyName.Replace("REBIRTHREBIRTH", ""); } else { string name = Localization.Get(_strMyName); return name; } } } public override void TeleportToPlayer(EntityAlive target, bool randomPosition = false) { //Log.Out("EntityNPCRebirth-TeleportToPlayer START: " + this.EntityClass.entityClassName); if (target == null) { //Log.Out("EntityNPCRebirth-TeleportToPlayer 1"); return; } if (target.IsInElevator()) { //Log.Out("EntityNPCRebirth-TeleportToPlayer target.IsInElevator(): " + target.IsInElevator()); return; } if (this.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Stay || this.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.TempStay) { //Log.Out("EntityNPCRebirth-TeleportToPlayer 2"); return; } if (!(this.HasAnyTags(FastTags.Parse("survivor")) || this.HasAnyTags(FastTags.Parse("ally")))) { //Log.Out("EntityNPCRebirth-TeleportToPlayer 3a"); return; } var target2i = new Vector2(target.position.x, target.position.z); var mine2i = new Vector2(position.x, position.z); var distance = Vector2.Distance(target2i, mine2i); //Log.Out("EntityNPCRebirth-TeleportToPlayer distance: " + distance); //Log.Out("EntityNPCRebirth-TeleportToPlayer Math.Abs(target.position.y - this.position.y): " + Math.Abs(target.position.y - this.position.y)); if (LeaderUtils.IsTeleporting) { //Log.Out("EntityNPCRebirth-TeleportToPlayer 5"); return; } var myPosition = target.position - target.GetForwardVector(); var player = target as EntityPlayer; if (player != null) { //Log.Out("EntityNPCRebirth-TeleportToPlayer 6, player: " + player.position); //Log.Out("EntityNPCRebirth-TeleportToPlayer 6, myPosition: " + myPosition); // If my target distance is still way off from the player, teleport randomly. That means the bread crumb isn't accurate var distance2 = Vector3.Distance(myPosition, player.position); //Log.Out("EntityNPCRebirth-TeleportToPlayer 7, distance2: " + distance2); if (distance2 > 40f) { //Log.Out("EntityNPCRebirth-TeleportToPlayer 7"); randomPosition = true; } if (randomPosition) { //Log.Out("EntityNPCRebirth-TeleportToPlayer 8"); Vector3 dirV = target.position - this.position; myPosition = RandomPositionGenerator.CalcPositionInDirection(target, target.position, dirV, 5, 80f); } // Find the ground. //Log.Out("EntityNPCRebirth-TeleportToPlayer A player X: " + player.position.x); //Log.Out("EntityNPCRebirth-TeleportToPlayer A player Y: " + player.position.y); //Log.Out("EntityNPCRebirth-TeleportToPlayer A player Z: " + player.position.z); //Log.Out("EntityNPCRebirth-TeleportToPlayer A NPC X: " + this.position.x); //Log.Out("EntityNPCRebirth-TeleportToPlayer A NPC Y: " + this.position.y); //Log.Out("EntityNPCRebirth-TeleportToPlayer A NPC Z: " + this.position.z); //Log.Out("EntityNPCRebirth-TeleportToPlayer A myPosition X: " + myPosition.x); //Log.Out("EntityNPCRebirth-TeleportToPlayer A myPosition Y: " + myPosition.y); //Log.Out("EntityNPCRebirth-TeleportToPlayer A myPosition Z: " + myPosition.z); //Log.Out("EntityNPCRebirth-TeleportToPlayer A player ground: " + GameManager.Instance.World.GetHeightAt(player.position.x, player.position.z)); //Log.Out("EntityNPCRebirth-TeleportToPlayer A NPC ground: " + GameManager.Instance.World.GetHeightAt(target.position.x, target.position.z)); float positionY = player.position.y + 1f; if (player.position.y > this.position.y) { //Log.Out("EntityNPCRebirth-TeleportToPlayer A1"); //myPosition = player.position; myPosition.y = positionY; } else { //Log.Out("EntityNPCRebirth-TeleportToPlayer A2"); if (GameManager.Instance.World.GetHeightAt(myPosition.x, myPosition.z) <= player.position.y) { } else { positionY = GameManager.Instance.World.GetHeightAt(myPosition.x, myPosition.z) + 1f; } } myPosition.y = positionY;//(int)GameManager.Instance.World.GetHeightAt(myPosition.x, myPosition.z) + 1; if (this.Buffs.GetCustomVar("$FR_NPC_ForceTeleport") == 1f) { //Log.Out("EntityNPCRebirth-TeleportToPlayer C"); myPosition = player.position; myPosition.y = myPosition.y + 1f; this.Buffs.SetCustomVar("$FR_NPC_ForceTeleport", 0f); } } motion = Vector3.zero; navigator?.clearPath(); moveHelper?.Stop(); speedForward = 0; speedStrafe = 0; RebirthUtilities.toggleCollisions(false, this); //motion = Vector3.zero; //navigator?.clearPath(); //Log.Out("EntityNPCRebirth-TeleportToPlayer myPosition: " + myPosition); //Log.Out("EntityNPCRebirth-TeleportToPlayer REPOSITION"); this.SetPosition(myPosition, true); } public override void ProcessDamageResponseLocal(DamageResponse _dmResponse) { if (this.Buffs.GetCustomVar("$eventSpawn") == 1f && _dmResponse.Source.getEntityId() != -1) { Entity sourceEntity = this.world.GetEntity(_dmResponse.Source.getEntityId()); if (sourceEntity != null) { this.SetAttackTarget((EntityAlive)sourceEntity, 60); this.SetRevengeTarget((EntityAlive)sourceEntity); } } //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal HAS OWNER A: " + (this.LeaderUtils.Owner != null)); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal name: " + this.EntityClass.entityClassName); bool blEntityClass = false; float flEntityInvincible = this.Buffs.GetCustomVar("$FR_NPC_Invincible"); if (flEntityInvincible == 1) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 1"); return; } if (!isEntityRemote) { emodel.avatarController.UpdateBool("IsBusy", false); } float flLeader = this.Buffs.GetCustomVar("$Leader"); if (this.LeaderUtils.Owner == null && flLeader > 0) { EntityPlayer entityPlayer = (EntityPlayer)this.world.GetEntity((int)flLeader); if (entityPlayer != null) { this.LeaderUtils.Owner = entityPlayer; } } bool cannotRespawn = true; bool respawnAtBedroll = false; if (flLeader > 0) { if (this.EntityTags.Test_AllSet(FastTags.Parse("npc")) && !this.EntityTags.Test_AllSet(FastTags.Parse("temp")) /*&& !this.EntityTags.Test_AllSet(FastTags.Parse("allyanimal"))*/ ) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2"); blEntityClass = true; cannotRespawn = false; } } if (this.Buffs.HasBuff("FuriousRamsayTemp")) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2a1"); cannotRespawn = true; blEntityClass = false; } if ((this.EntityTags.Test_AllSet(FastTags.Parse("bedrollSpawn"))) ) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2a2"); respawnAtBedroll = true; } float flEntityRespawn = this.Buffs.GetCustomVar("$FR_NPC_Respawn"); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal flEntityRespawn: " + flEntityRespawn); Vector3 respawnPosition = new Vector3(0, 0, 0); Vector3 respawnRotation = new Vector3(0, 0, 0); if (flEntityRespawn == 0) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal flEntityRespawn IS 0"); bool letDie = false; if (cannotRespawn) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal Let Die"); letDie = true; } if (blEntityClass || respawnAtBedroll) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2a2"); if (!this.EntityTags.Test_AnySet(FastTags.Parse("allyanimal,zombieCompanion,skeletonCompanion"))) { foreach (hireInfo hire in playerHires) { if (hire.hireID == this.entityId && hire.reSpawnPosition != new Vector3(0, 0, 0)) { respawnPosition = hire.reSpawnPosition; respawnRotation = hire.reSpawnRotation; //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal respawnPosition: " + respawnPosition + "[" + this.EntityName + "]"); break; } } } if (respawnPosition == new Vector3(0, 0, 0)) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2c"); if (this.LeaderUtils.Owner) { if (this.LeaderUtils.Owner.IsSpawned()) { EntityPlayer entityPlayer = this.world.GetEntity(this.LeaderUtils.Owner.entityId) as EntityPlayer; if (entityPlayer != null) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2c-1"); SpawnPosition spawnPoint = RebirthUtilities.GetSpawnPoint(entityPlayer); if (spawnPoint.IsUndef()) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2c-2"); respawnPosition = this.position; // Vector3.zero; respawnRotation.y = this.rotation.y; //letDie = true; /*if (this.IsDead() && this.Buffs.GetCustomVar("$died") == 0f && this.EntityClass.Properties.Values.ContainsKey("SpawnBlock")) { this.Buffs.SetCustomVar("$died", 1f); //Log.Out("DialogActionNPCActionRebirth-PerformAction 7c"); string itemName = "FuriousRamsaySpawnCube" + this.EntityClass.Properties.Values["SpawnBlock"]; //Log.Out("DialogActionNPCActionRebirth-PerformAction 7d, itemName: " + itemName); var item = ItemClass.GetItem(itemName); if (item != null) { //Log.Out("DialogActionNPCActionRebirth-PerformAction 7e"); var itemStack = new ItemStack(item, 1); if (!entityPlayer.inventory.AddItem(itemStack)) { entityPlayer.bag.AddItem(itemStack); } } }*/ } else { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2c-3, respawnPosition: " + respawnPosition); respawnPosition = spawnPoint.position; respawnRotation.y = this.rotation.y; //RebirthManager.UpdateHireInfo(this.entityId, "reSpawnPosition", "", respawnPosition.ToString(), new Vector3(0, this.rotation.y, 0).ToString()); } } else { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2c-4"); } } else { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2c-5"); } } else { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 2c-6"); respawnPosition = this.position; respawnRotation.y = this.rotation.y; letDie = true; } } } if (((this.Health - _dmResponse.Strength) <= 0) && blEntityClass && !cannotRespawn) { if (letDie == true) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 3a"); if (!HasAnyTags(FastTags.Parse("bedrollSpawn"))) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 3b"); RebirthManager.RemoveHire(this.entityId); } base.ProcessDamageResponseLocal(_dmResponse); return; } //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 3"); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal DIED"); this.Buffs.SetCustomVar("$FR_NPC_Respawn", 1); this.Buffs.SetCustomVar("$FR_NPC_RespawnCommandActivation", 1); //this.Buffs.SetCustomVar("$FR_NPC_RespawnNav", 1); this.factionId = FactionManager.Instance.GetFactionByName("trader").ID; this.guardPosition = Vector3.zero; //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal SET TO STAY"); this.Buffs.SetCustomVar("CurrentOrder", (int)EntityUtilities.Orders.Stay); this.Buffs.AddBuff("FuriousRamsayRespawned"); this.Buffs.AddBuff("FuriousRamsayResistFireShockSmoke"); this.Health = 1; this.markedForUnload = false; this.bDead = false; if (this.emodel.HasRagdoll()) { this.emodel.DoRagdoll(_dmResponse, 999999f); } else { this.emodel.avatarController.TriggerEvent("DeathTrigger"); } PlayOneShot(soundDeath); attackTarget = null; attackTargetTime = 0; RebirthManager.UpdateHireInfo(this.entityId, "order", "guard", Vector3.zero.ToString(), Vector3.zero.ToString()); GameManager.Instance.StartCoroutine(RebirthUtilities.delayRespawn(this, respawnPosition, respawnRotation)); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal REPOSITION"); RebirthManager.UpdateHireInfo(this.entityId, "order", "stay", respawnPosition.ToString(), this.rotation.ToString()); bool foundHire = false; foreach (chunkObservers observer in observers) { if (observer.entityID == this.entityId) { foundHire = true; break; } } if (!foundHire) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal ADDED CHUNK OBSERVER for: " + this.entityId); ChunkManager.ChunkObserver observerRef = GameManager.Instance.AddChunkObserver(respawnPosition, false, 3, -1); observers.Add(new chunkObservers(this.entityId, observerRef)); } //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal HAS OWNER B: " + (this.LeaderUtils.Owner != null)); return; } else { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 8"); if (((this.Health - _dmResponse.Strength) <= 0)) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 9"); bool dontRespawn = false; if (this.spawnerSource == EnumSpawnerSource.Dynamic) { dontRespawn = true; } if (this.LeaderUtils.Owner && !dontRespawn) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 10"); if (this.LeaderUtils.Owner.IsSpawned()) { EntityPlayer entityPlayer = this.world.GetEntity(this.LeaderUtils.Owner.entityId) as EntityPlayer; if (entityPlayer != null) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 11"); SpawnPosition spawnPoint = RebirthUtilities.GetSpawnPoint(entityPlayer); if (spawnPoint.IsUndef()) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 12"); RebirthManager.UpdateHireInfo(this.entityId, "reSpawnPosition", "", Vector3.zero.ToString(), new Vector3(0, this.rotation.y, 0).ToString()); dontRespawn = true; } else { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 13"); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal cannotRespawn: " + cannotRespawn); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal respawnAtBedroll: " + respawnAtBedroll); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal dontRespawn: " + dontRespawn); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal spawnPoint.position: " + spawnPoint.position); //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal entityPlayer.position: " + entityPlayer.position); if (cannotRespawn && respawnAtBedroll && !dontRespawn) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 14A"); if (this.LeaderUtils.Owner) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 14B"); this.LeaderUtils.Owner.Companions.Remove(this); } RebirthManager.UpdateHireInfo(this.entityId, "order", "stay", spawnPoint.position.ToString(), this.rotation.ToString()); //RebirthManager.UpdateHireInfo(this.entityId, "reSpawnPosition", "", spawnPoint.position.ToString(), new Vector3(0, this.rotation.y, 0).ToString()); } } } } else { if (this.Buffs.HasCustomVar("$SpawnPoint_X")) { float spawnPointX = this.Buffs.GetCustomVar("$SpawnPoint_X"); float spawnPointY = this.Buffs.GetCustomVar("$SpawnPoint_Y"); float spawnPointZ = this.Buffs.GetCustomVar("$SpawnPoint_Z"); Vector3 spawnPoint = new Vector3(spawnPointX, spawnPointY, spawnPointZ); if (cannotRespawn && respawnAtBedroll && !dontRespawn) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 14B"); RebirthManager.UpdateHireInfo(this.entityId, "order", "stay", spawnPoint.ToString(), this.rotation.ToString()); RebirthManager.UpdateHireInfo(this.entityId, "reSpawnPosition", "", spawnPoint.ToString(), new Vector3(0, this.rotation.y, 0).ToString()); } } } } if (cannotRespawn && (!respawnAtBedroll || dontRespawn)) { this.bWillRespawn = false; //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal 16"); for (int i = 0; i < observers.Count; i++) { if (observers[i].entityID == this.entityId) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal REMOVED OBSERVER, hire: " + this.entityId); GameManager.Instance.RemoveChunkObserver(observers[i].observerRef); observers.RemoveAt(i); break; } } if (this.LeaderUtils.Owner && !HasAnyTags(FastTags.Parse("bedrollSpawn"))) { //Log.Out("EntityNPCRebirth-ProcessDamageResponseLocal REMOVED HIRE/OWNED ENTITY, hire: " + this.entityId); RebirthManager.RemoveHire(this.entityId); } } } base.ProcessDamageResponseLocal(_dmResponse); this.Buffs.AddBuff("FuriousRamsayHit"); } } } }