private bool IsAllSpawnedDead() { for (int index = 0; index < this.Spawned.Count; index = index - 1 + 1) { NPCTurretDomain npcTurretDomain = this.Spawned[index]; if (!Object.op_Equality((Object)npcTurretDomain, (Object)null) && !Object.op_Equality((Object)((Component)npcTurretDomain).get_transform(), (Object)null) && (npcTurretDomain.NPCTurretContext != null && !Object.op_Equality((Object)npcTurretDomain.NPCTurretContext.Body, (Object)null)) && (!npcTurretDomain.NPCTurretContext.Body.IsDestroyed && !npcTurretDomain.NPCTurretContext.Body.IsDead())) { return(false); } this.Spawned.RemoveAt(index); } return(true); }
private bool IsAllSpawnedDead() { for (int i = 0; i < this.Spawned.Count; i++) { NPCTurretDomain item = this.Spawned[i]; if (!(item == null) && !(item.transform == null) && item.NPCTurretContext != null && !(item.NPCTurretContext.Body == null) && !item.NPCTurretContext.Body.IsDestroyed && !item.NPCTurretContext.Body.IsDead()) { return(false); } this.Spawned.RemoveAt(i); i--; } return(true); }
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)); NPCTurretDomain aiDomain = target.AiDomain as NPCTurretDomain; if (aiDomain) { if (item.info.category == ItemCategory.Weapon) { BaseEntity heldEntity = item.GetHeldEntity(); if (heldEntity is BaseProjectile) { aiDomain.NPCTurretContext.SetFact(Facts.HeldItemType, ItemType.ProjectileWeapon, true, true, true); aiDomain.ReloadFirearm(); } else if (heldEntity is BaseMelee) { aiDomain.NPCTurretContext.SetFact(Facts.HeldItemType, ItemType.MeleeWeapon, true, true, true); } else if (heldEntity is ThrownWeapon) { aiDomain.NPCTurretContext.SetFact(Facts.HeldItemType, ItemType.ThrowableWeapon, true, true, true); } } else if (item.info.category == ItemCategory.Medical) { aiDomain.NPCTurretContext.SetFact(Facts.HeldItemType, ItemType.HealingItem, true, true, true); } else if (item.info.category == ItemCategory.Tool) { aiDomain.NPCTurretContext.SetFact(Facts.HeldItemType, ItemType.LightSourceItem, true, true, true); } } }
public void SpawnScientist() { if (this.Spawned == null || this.Spawned.Count >= this.MaxPopulation) { Debug.LogWarning((object)"Attempted to spawn an AStar Scientist, but the spawner was full!"); } else { if (!AI.npc_enable) { return; } int num = this.MaxPopulation - this.Spawned.Count; for (int index = 0; index < num; ++index) { Vector3 pos; Quaternion rot; if (!Object.op_Equality((Object)this.GetSpawnPoint(out pos, out rot), (Object)null)) { BaseEntity entity = GameManager.server.CreateEntity(this.NPCTurretPrefab.resourcePath, pos, rot, false); NPCTurretDomain component = (NPCTurretDomain)((Component)entity).GetComponent <NPCTurretDomain>(); if (Object.op_Implicit((Object)component)) { entity.enableSaving = false; ((Component)entity).get_gameObject().AwakeFromInstantiate(); entity.Spawn(); if (this.OnlyRotateAroundYAxis && component.NPCTurretContext != null && Object.op_Inequality((Object)component.NPCTurretContext.Body, (Object)null)) { component.NPCTurretContext.Body.OnlyRotateAroundYAxis = true; } component.ReducedLongRangeAccuracy = this.ReducedLongRangeAccuracy; component.BurstAtLongRange = this.BurstAtLongRange; this.Spawned.Add(component); } else { entity.Kill(BaseNetworkable.DestroyMode.None); break; } } } } }
public NPCTurretContext(HTNPlayer body, NPCTurretDomain domain) { int length = System.Enum.GetValues(typeof(Facts)).Length; if (this._worldState == null || this._worldState.Length != length) { this._worldState = new byte[length]; this._previousWorldState = new byte[length]; if (NPCTurretContext._worldStateChanges == null) { NPCTurretContext._worldStateChanges = new Stack <WorldStateInfo> [length]; for (int index = 0; index < length; ++index) { NPCTurretContext._worldStateChanges[index] = new Stack <WorldStateInfo>(5); } } } this._decompositionScore = int.MaxValue; this.Body = body; this.Domain = domain; this.PlanState = (PlanStateType)0; if (this.Memory == null || this.Memory.NPCTurretContext != this) { this.Memory = new NPCTurretMemory(this); } if (!Object.op_Equality((Object)this.Location, (Object)null)) { return; } float num = float.MaxValue; foreach (AiLocationManager manager in AiLocationManager.Managers) { Vector3 vector3 = Vector3.op_Subtraction(((Component)manager).get_transform().get_position(), ((Component)this.Body).get_transform().get_position()); float sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude(); if ((double)sqrMagnitude < (double)num) { num = sqrMagnitude; this.Location = manager; } } }
public NPCTurretContext(HTNPlayer body, NPCTurretDomain domain) { int length = Enum.GetValues(typeof(Facts)).Length; if (this._worldState == null || (int)this._worldState.Length != length) { this._worldState = new byte[length]; this._previousWorldState = new byte[length]; if (NPCTurretContext._worldStateChanges == null) { NPCTurretContext._worldStateChanges = new Stack <WorldStateInfo> [length]; for (int i = 0; i < length; i++) { NPCTurretContext._worldStateChanges[i] = new Stack <WorldStateInfo>(5); } } } this._decompositionScore = 2147483647; this.Body = body; this.Domain = domain; this.PlanState = PlanStateType.NoPlan; if (this.Memory == null || this.Memory.NPCTurretContext != this) { this.Memory = new NPCTurretMemory(this); } if (this.Location == null) { float single = Single.MaxValue; foreach (AiLocationManager manager in AiLocationManager.Managers) { Vector3 vector3 = manager.transform.position - this.Body.transform.position; float single1 = vector3.sqrMagnitude; if (single1 >= single) { continue; } single = single1; this.Location = manager; } } }
public void SpawnScientist() { Vector3 vector3; Quaternion quaternion; if (this.Spawned == null || this.Spawned.Count >= this.MaxPopulation) { Debug.LogWarning("Attempted to spawn an AStar Scientist, but the spawner was full!"); return; } if (!ConVar.AI.npc_enable) { return; } int maxPopulation = this.MaxPopulation - this.Spawned.Count; for (int i = 0; i < maxPopulation; i++) { if (this.GetSpawnPoint(out vector3, out quaternion) != null) { BaseEntity baseEntity = GameManager.server.CreateEntity(this.NPCTurretPrefab.resourcePath, vector3, quaternion, false); NPCTurretDomain component = baseEntity.GetComponent <NPCTurretDomain>(); if (!component) { baseEntity.Kill(BaseNetworkable.DestroyMode.None); return; } baseEntity.enableSaving = false; baseEntity.gameObject.AwakeFromInstantiate(); baseEntity.Spawn(); if (this.OnlyRotateAroundYAxis && component.NPCTurretContext != null && component.NPCTurretContext.Body != null) { component.NPCTurretContext.Body.OnlyRotateAroundYAxis = true; } component.ReducedLongRangeAccuracy = this.ReducedLongRangeAccuracy; component.BurstAtLongRange = this.BurstAtLongRange; this.Spawned.Add(component); } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { if (npc == null || npc.transform == null || npc.IsDestroyed || npc.AiDefinition == null || AnimalsInRangeSensor.QueryResults == null) { return; } NPCTurretDomain aiDomain = npc.AiDomain as NPCTurretDomain; if (aiDomain == null || aiDomain.NPCTurretContext == null) { return; } AttackEntity firearm = aiDomain.GetFirearm(); AnimalsInRangeSensor.QueryResultCount = BaseEntity.Query.Server.GetInSphere(npc.transform.position, npc.AiDefinition.Engagement.CloseRangeFirearm(firearm) + npc.AiDefinition.Engagement.CloseRange, AnimalsInRangeSensor.QueryResults, (BaseEntity entity) => { BaseNpc baseNpc = entity as BaseNpc; if (!(baseNpc == null) && baseNpc.isServer && !baseNpc.IsDestroyed && !(baseNpc.transform == null) && !baseNpc.IsDead()) { return(true); } return(false); }); List <AnimalInfo> animalsInRange = npc.AiDomain.NpcContext.AnimalsInRange; if (AnimalsInRangeSensor.QueryResultCount > 0) { for (int i = 0; i < AnimalsInRangeSensor.QueryResultCount; i++) { BaseNpc queryResults = AnimalsInRangeSensor.QueryResults[i]; Vector3 vector3 = queryResults.transform.position - npc.transform.position; float single = vector3.sqrMagnitude; if (single <= npc.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm) + npc.AiDefinition.Engagement.SqrCloseRange) { bool flag = false; int num = 0; while (num < animalsInRange.Count) { AnimalInfo item = animalsInRange[num]; if (item.Animal != queryResults) { num++; } else { item.Time = time; item.SqrDistance = single; animalsInRange[num] = item; flag = true; break; } } if (!flag) { AnimalInfo animalInfo = new AnimalInfo() { Animal = queryResults, Time = time, SqrDistance = single }; animalsInRange.Add(animalInfo); } } } } for (int j = 0; j < animalsInRange.Count; j++) { if (time - animalsInRange[j].Time > npc.AiDefinition.Memory.ForgetAnimalInRangeTime) { animalsInRange.RemoveAt(j); j--; } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { if (npc == null || Object.op_Equality((Object)npc.transform, (Object)null) || (npc.IsDestroyed || (BaseScriptableObject)npc.AiDefinition == (BaseScriptableObject)null) || AnimalsInRangeSensor.QueryResults == null) { return; } NPCTurretDomain aiDomain = npc.AiDomain as NPCTurretDomain; if (Object.op_Equality((Object)aiDomain, (Object)null) || aiDomain.NPCTurretContext == null) { return; } AttackEntity firearm = aiDomain.GetFirearm(); AnimalsInRangeSensor.QueryResultCount = BaseEntity.Query.Server.GetInSphere(npc.transform.get_position(), npc.AiDefinition.Engagement.CloseRangeFirearm(firearm) + npc.AiDefinition.Engagement.CloseRange, (BaseEntity[])AnimalsInRangeSensor.QueryResults, (Func <BaseEntity, bool>)(entity => { BaseNpc baseNpc = entity as BaseNpc; return(!Object.op_Equality((Object)baseNpc, (Object)null) && baseNpc.isServer && (!baseNpc.IsDestroyed && !Object.op_Equality((Object)((Component)baseNpc).get_transform(), (Object)null)) && !baseNpc.IsDead()); })); List <AnimalInfo> animalsInRange = npc.AiDomain.NpcContext.AnimalsInRange; if (AnimalsInRangeSensor.QueryResultCount > 0) { for (int index1 = 0; index1 < AnimalsInRangeSensor.QueryResultCount; ++index1) { BaseNpc queryResult = AnimalsInRangeSensor.QueryResults[index1]; Vector3 vector3 = Vector3.op_Subtraction(((Component)queryResult).get_transform().get_position(), npc.transform.get_position()); float sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude(); if ((double)sqrMagnitude <= (double)npc.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm) + (double)npc.AiDefinition.Engagement.SqrCloseRange) { bool flag = false; for (int index2 = 0; index2 < animalsInRange.Count; ++index2) { AnimalInfo animalInfo = animalsInRange[index2]; if (Object.op_Equality((Object)animalInfo.Animal, (Object)queryResult)) { animalInfo.Time = time; animalInfo.SqrDistance = sqrMagnitude; animalsInRange[index2] = animalInfo; flag = true; break; } } if (!flag) { animalsInRange.Add(new AnimalInfo() { Animal = queryResult, Time = time, SqrDistance = sqrMagnitude }); } } } } for (int index = 0; index < animalsInRange.Count; ++index) { AnimalInfo animalInfo = animalsInRange[index]; if ((double)time - (double)animalInfo.Time > (double)npc.AiDefinition.Memory.ForgetAnimalInRangeTime) { animalsInRange.RemoveAt(index); --index; } } }