public override void OnlyLoadoutWeapons(HTNPlayer target) { if (target == null || target.IsDestroyed || target.IsDead() || target.IsWounded() || target.inventory == null || target.inventory.containerBelt == null || target.inventory.containerMain == null || target.inventory.containerWear == null) { return; } if (this.loadouts == null || this.loadouts.Length == 0) { UnityEngine.Debug.LogWarning(string.Concat("Loadout for NPC ", base.name, " was empty.")); } else { PlayerInventoryProperties playerInventoryProperty = this.loadouts[UnityEngine.Random.Range(0, (int)this.loadouts.Length)]; if (playerInventoryProperty != null) { foreach (ItemAmount itemAmount in playerInventoryProperty.belt) { if (itemAmount.itemDef.category != ItemCategory.Weapon) { continue; } target.inventory.GiveItem(ItemManager.Create(itemAmount.itemDef, (int)itemAmount.amount, (ulong)0), target.inventory.containerBelt); } target.StartCoroutine(this.EquipWeapon(target)); return; } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { MurdererContext npcContext = npc.AiDomain.NpcContext as MurdererContext; if (npcContext == null) { return; } HTNPlayer htnPlayer = npc as HTNPlayer; if (Object.op_Equality((Object)htnPlayer, (Object)null)) { return; } NpcOrientation npcOrientation = NpcOrientation.Heading; if (npc.IsDestroyed || htnPlayer.IsDead() || htnPlayer.IsWounded()) { npcOrientation = NpcOrientation.None; } else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownAnimal.Animal, (Object)null)) { npcOrientation = !Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null) ? NpcOrientation.LookAtAnimal : ((double)npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= (double)npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance ? (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation)) : NpcOrientation.LookAtAnimal); } else if (Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null)) { npcOrientation = npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } else if (Object.op_Inequality((Object)htnPlayer.lastAttacker, (Object)null) && (double)htnPlayer.lastAttackedTime > 0.0 && (double)time - (double)htnPlayer.lastAttackedTime < 2.0) { npcOrientation = NpcOrientation.LastAttackedDirection; } else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null)) { npcOrientation = npcContext.GetFact(Rust.Ai.HTN.Murderer.Facts.IsSearching) <= (byte)0 || npcContext.GetFact(Rust.Ai.HTN.Murderer.Facts.IsNavigating) != (byte)0 ? (npcContext.GetFact(Rust.Ai.HTN.Murderer.Facts.IsIdle) <= (byte)0 ? NpcOrientation.LastKnownPrimaryTargetLocation : (!npcContext.IsFact(Rust.Ai.HTN.Murderer.Facts.CanHearEnemy) ? NpcOrientation.Heading : NpcOrientation.AudibleTargetDirection)) : NpcOrientation.LookAround; } else if (npcContext.IsFact(Rust.Ai.HTN.Murderer.Facts.CanHearEnemy)) { npcOrientation = NpcOrientation.AudibleTargetDirection; } if (npcContext.IsFact(Rust.Ai.HTN.Murderer.Facts.IsRoaming) && !npcContext.IsFact(Rust.Ai.HTN.Murderer.Facts.HasEnemyTarget)) { npcOrientation = NpcOrientation.Heading; } else if (npcContext.IsFact(Rust.Ai.HTN.Murderer.Facts.IsReturningHome) && !npcContext.IsFact(Rust.Ai.HTN.Murderer.Facts.HasEnemyTarget)) { npcOrientation = NpcOrientation.Home; } npcContext.OrientationType = npcOrientation; }
private IEnumerator EquipWeapon(HTNPlayer target) { yield return(CoroutineEx.waitForSeconds(0.25f)); if (target == null || target.IsDestroyed || target.IsDead() || target.IsWounded() || target.inventory == null || target.inventory.containerBelt == null) { yield break; } Item item = target.inventory.containerBelt.GetSlot(0); if (item == null) { yield break; } target.UpdateActiveItem(item.uid); yield return(CoroutineEx.waitForSeconds(0.25f)); ScientistAStarDomain aiDomain = target.AiDomain as ScientistAStarDomain; if (aiDomain) { if (item.info.category == ItemCategory.Weapon) { BaseEntity heldEntity = item.GetHeldEntity(); if (heldEntity is BaseProjectile) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.ProjectileWeapon, true, true, true); aiDomain.ReloadFirearm(); } else if (heldEntity is BaseMelee) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.MeleeWeapon, true, true, true); } else if (heldEntity is ThrownWeapon) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.ThrowableWeapon, true, true, true); } } else if (item.info.category == ItemCategory.Medical) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.HealingItem, true, true, true); } else if (item.info.category == ItemCategory.Tool) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.LightSourceItem, true, true, true); } } }
public override void Loadout(HTNPlayer target) { if (target == null || target.IsDestroyed || target.IsDead() || target.IsWounded() || target.inventory == null || target.inventory.containerBelt == null || target.inventory.containerMain == null || target.inventory.containerWear == null) { return; } if (this.loadouts == null || this.loadouts.Length == 0) { UnityEngine.Debug.LogWarning(string.Concat("Loadout for NPC ", base.name, " was empty.")); } else { PlayerInventoryProperties playerInventoryProperty = this.loadouts[UnityEngine.Random.Range(0, (int)this.loadouts.Length)]; if (playerInventoryProperty != null) { playerInventoryProperty.GiveToPlayer(target); target.StartCoroutine(this.EquipWeapon(target)); return; } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { NPCTurretContext npcContext = npc.AiDomain.NpcContext as NPCTurretContext; if (npcContext == null) { return; } HTNPlayer htnPlayer = npc as HTNPlayer; if (Object.op_Equality((Object)htnPlayer, (Object)null)) { return; } NpcOrientation npcOrientation = NpcOrientation.Heading; if (npc.IsDestroyed || htnPlayer.IsDead() || htnPlayer.IsWounded()) { npcOrientation = NpcOrientation.None; } else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownAnimal.Animal, (Object)null)) { npcOrientation = !Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null) ? NpcOrientation.LookAtAnimal : ((double)npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= (double)npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance ? (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation)) : NpcOrientation.LookAtAnimal); } else if (Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null)) { npcOrientation = npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } else if (Object.op_Inequality((Object)htnPlayer.lastAttacker, (Object)null) && (double)htnPlayer.lastAttackedTime > 0.0 && (double)time - (double)htnPlayer.lastAttackedTime < 2.0) { npcOrientation = NpcOrientation.LastAttackedDirection; } else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null)) { npcOrientation = NpcOrientation.LastKnownPrimaryTargetLocation; } npcContext.OrientationType = npcOrientation; }
private IEnumerator RadioChatter(HTNPlayer target) { ScientistAStarDefinition scientistAStarDefinition = null; while (scientistAStarDefinition._isRadioEffectRunning && target != null && target.transform != null && !target.IsDestroyed && !target.IsDead()) { if (scientistAStarDefinition.RadioEffect.isValid) { Effect.server.Run(scientistAStarDefinition.RadioEffect.resourcePath, target, StringPool.Get("head"), Vector3.zero, Vector3.zero, null, false); } float single = UnityEngine.Random.Range(scientistAStarDefinition.RadioEffectRepeatRange.x, scientistAStarDefinition.RadioEffectRepeatRange.y + 1f); yield return(CoroutineEx.waitForSeconds(single)); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { NpcOrientation npcOrientation; NpcOrientation npcOrientation1; ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } HTNPlayer hTNPlayer = npc as HTNPlayer; if (hTNPlayer == null) { return; } NpcOrientation npcOrientation2 = NpcOrientation.Heading; if (npc.IsDestroyed || hTNPlayer.IsDead() || hTNPlayer.IsWounded()) { npcOrientation2 = NpcOrientation.None; } else if (npcContext.Memory.PrimaryKnownAnimal.Animal != null) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player == null) { npcOrientation2 = NpcOrientation.LookAtAnimal; } else if (npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible) { npcOrientation1 = NpcOrientation.PrimaryTargetBody; } else { npcOrientation1 = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } npcOrientation2 = npcOrientation1; } else { npcOrientation2 = NpcOrientation.LookAtAnimal; } } else if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player != null) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible) { npcOrientation = NpcOrientation.PrimaryTargetBody; } else { npcOrientation = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } npcOrientation2 = npcOrientation; } else if (hTNPlayer.lastAttacker != null && hTNPlayer.lastAttackedTime > 0f && time - hTNPlayer.lastAttackedTime < 2f) { npcOrientation2 = NpcOrientation.LastAttackedDirection; } else if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null) { if (npcContext.IsFact(Facts.CanHearEnemy)) { npcOrientation2 = NpcOrientation.AudibleTargetDirection; } } else if (npcContext.GetFact(Facts.IsSearching) > 0 && npcContext.GetFact(Facts.IsNavigating) == 0) { npcOrientation2 = NpcOrientation.LookAround; } else if (npcContext.GetFact(Facts.IsIdle) <= 0) { npcOrientation2 = NpcOrientation.LastKnownPrimaryTargetLocation; } else { npcOrientation2 = (!npcContext.IsFact(Facts.CanHearEnemy) ? NpcOrientation.Heading : NpcOrientation.AudibleTargetDirection); } npcContext.OrientationType = npcOrientation2; }
private IEnumerator EquipWeapon(HTNPlayer target) { yield return((object)CoroutineEx.waitForSeconds(0.25f)); if (!Object.op_Equality((Object)target, (Object)null) && !target.IsDestroyed && (!target.IsDead() && !target.IsWounded()) && (!Object.op_Equality((Object)target.inventory, (Object)null) && target.inventory.containerBelt != null)) { Item slot = target.inventory.containerBelt.GetSlot(0); if (slot != null) { target.UpdateActiveItem(slot.uid); yield return((object)CoroutineEx.waitForSeconds(0.25f)); MurdererDomain aiDomain = target.AiDomain as MurdererDomain; if (Object.op_Implicit((Object)aiDomain)) { if (slot.info.category == ItemCategory.Weapon) { BaseEntity heldEntity = slot.GetHeldEntity(); if (heldEntity is BaseProjectile) { aiDomain.MurdererContext.SetFact(Facts.HeldItemType, ItemType.ProjectileWeapon, true, true, true); aiDomain.ReloadFirearm(); } else if (heldEntity is BaseMelee) { aiDomain.MurdererContext.SetFact(Facts.HeldItemType, ItemType.MeleeWeapon, true, true, true); Chainsaw chainsaw = heldEntity as Chainsaw; if (Object.op_Implicit((Object)chainsaw)) { chainsaw.ServerNPCStart(); } } else if (heldEntity is ThrownWeapon) { aiDomain.MurdererContext.SetFact(Facts.HeldItemType, ItemType.ThrowableWeapon, true, true, true); } } else if (slot.info.category == ItemCategory.Medical) { aiDomain.MurdererContext.SetFact(Facts.HeldItemType, ItemType.HealingItem, true, true, true); } else if (slot.info.category == ItemCategory.Tool) { BaseEntity heldEntity = slot.GetHeldEntity(); if (heldEntity is BaseMelee) { aiDomain.MurdererContext.SetFact(Facts.HeldItemType, ItemType.MeleeWeapon, true, true, true); Chainsaw chainsaw = heldEntity as Chainsaw; if (Object.op_Implicit((Object)chainsaw)) { chainsaw.ServerNPCStart(); } } else { aiDomain.MurdererContext.SetFact(Facts.HeldItemType, ItemType.LightSourceItem, true, true, true); } } } } } }
public override void OnlyLoadoutWeapons(HTNPlayer target) { if (Object.op_Equality((Object)target, (Object)null) || target.IsDestroyed || (target.IsDead() || target.IsWounded()) || (Object.op_Equality((Object)target.inventory, (Object)null) || target.inventory.containerBelt == null || (target.inventory.containerMain == null || target.inventory.containerWear == null))) { return; } if (this.loadouts != null && this.loadouts.Length != 0) { PlayerInventoryProperties loadout = this.loadouts[Random.Range(0, this.loadouts.Length)]; if (!Object.op_Inequality((Object)loadout, (Object)null)) { return; } foreach (ItemAmount itemAmount in loadout.belt) { if (itemAmount.itemDef.category == ItemCategory.Weapon) { target.inventory.GiveItem(ItemManager.Create(itemAmount.itemDef, (int)itemAmount.amount, 0UL), target.inventory.containerBelt); } } ((MonoBehaviour)target).StartCoroutine(this.EquipWeapon(target)); } else { Debug.LogWarning((object)("Loadout for NPC " + ((Object)this).get_name() + " was empty.")); } }
public override void Loadout(HTNPlayer target) { if (Object.op_Equality((Object)target, (Object)null) || target.IsDestroyed || (target.IsDead() || target.IsWounded()) || (Object.op_Equality((Object)target.inventory, (Object)null) || target.inventory.containerBelt == null || (target.inventory.containerMain == null || target.inventory.containerWear == null))) { return; } if (this.loadouts != null && this.loadouts.Length != 0) { PlayerInventoryProperties loadout = this.loadouts[Random.Range(0, this.loadouts.Length)]; if (!Object.op_Inequality((Object)loadout, (Object)null)) { return; } loadout.GiveToPlayer((BasePlayer)target); ((MonoBehaviour)target).StartCoroutine(this.EquipWeapon(target)); } else { Debug.LogWarning((object)("Loadout for NPC " + ((Object)this).get_name() + " was empty.")); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { NpcOrientation npcOrientation; NpcOrientation npcOrientation1; NPCTurretContext npcContext = npc.AiDomain.NpcContext as NPCTurretContext; if (npcContext == null) { return; } HTNPlayer hTNPlayer = npc as HTNPlayer; if (hTNPlayer == null) { return; } NpcOrientation npcOrientation2 = NpcOrientation.Heading; if (npc.IsDestroyed || hTNPlayer.IsDead() || hTNPlayer.IsWounded()) { npcOrientation2 = NpcOrientation.None; } else if (npcContext.Memory.PrimaryKnownAnimal.Animal != null) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player == null) { npcOrientation2 = NpcOrientation.LookAtAnimal; } else if (npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible) { npcOrientation1 = NpcOrientation.PrimaryTargetBody; } else { npcOrientation1 = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } npcOrientation2 = npcOrientation1; } else { npcOrientation2 = NpcOrientation.LookAtAnimal; } } else if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player != null) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible) { npcOrientation = NpcOrientation.PrimaryTargetBody; } else { npcOrientation = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } npcOrientation2 = npcOrientation; } else if (hTNPlayer.lastAttacker != null && hTNPlayer.lastAttackedTime > 0f && time - hTNPlayer.lastAttackedTime < 2f) { npcOrientation2 = NpcOrientation.LastAttackedDirection; } else if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player != null) { npcOrientation2 = NpcOrientation.LastKnownPrimaryTargetLocation; } npcContext.OrientationType = npcOrientation2; }
private IEnumerator RadioChatter(HTNPlayer target) { while (this._isRadioEffectRunning && Object.op_Inequality((Object)target, (Object)null) && (Object.op_Inequality((Object)((Component)target).get_transform(), (Object)null) && !target.IsDestroyed) && !target.IsDead()) { if (this.RadioEffect.isValid) { Effect.server.Run(this.RadioEffect.resourcePath, (BaseEntity)target, StringPool.Get("head"), Vector3.get_zero(), Vector3.get_zero(), (Connection)null, false); } yield return((object)CoroutineEx.waitForSeconds(Random.Range((float)this.RadioEffectRepeatRange.x, (float)(this.RadioEffectRepeatRange.y + 1.0)))); } }
private IEnumerator EquipTool(HTNPlayer target) { yield return((object)CoroutineEx.waitForSeconds(0.25f)); if (!Object.op_Equality((Object)target, (Object)null) && !target.IsDestroyed && (!target.IsDead() && !target.IsWounded()) && (!Object.op_Equality((Object)target.inventory, (Object)null) && target.inventory.containerBelt != null)) { int slot1 = 1; if (Object.op_Inequality((Object)TOD_Sky.get_Instance(), (Object)null) && TOD_Sky.get_Instance().get_IsNight()) { slot1 = 2; } Item slot = target.inventory.containerBelt.GetSlot(slot1); if (slot == null) { slot = target.inventory.containerBelt.GetSlot(0); if (slot == null) { yield break; } } target.UpdateActiveItem(slot.uid); yield return((object)CoroutineEx.waitForSeconds(0.25f)); ScientistJunkpileDomain aiDomain = target.AiDomain as ScientistJunkpileDomain; if (Object.op_Implicit((Object)aiDomain)) { if (slot.info.category == ItemCategory.Weapon) { BaseEntity heldEntity = slot.GetHeldEntity(); if (heldEntity is BaseProjectile) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.ProjectileWeapon, true, true, true); aiDomain.ReloadFirearm(); } else if (heldEntity is BaseMelee) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.MeleeWeapon, true, true, true); } else if (heldEntity is ThrownWeapon) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.ThrowableWeapon, true, true, true); } } else if (slot.info.category == ItemCategory.Medical) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.HealingItem, true, true, true); } else if (slot.info.category == ItemCategory.Tool) { HeldEntity heldEntity = target.GetHeldEntity(); if (Object.op_Inequality((Object)heldEntity, (Object)null) && heldEntity.LightsOn()) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.LightSourceItem, true, true, true); } else { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.ResearchItem, true, true, true); } } } } }