private bool IsAllSpawnedDead() { for (int index = 0; index < this.Spawned.Count; index = index - 1 + 1) { ScientistJunkpileDomain scientistJunkpileDomain = this.Spawned[index]; if (!Object.op_Equality((Object)scientistJunkpileDomain, (Object)null) && !Object.op_Equality((Object)((Component)scientistJunkpileDomain).get_transform(), (Object)null) && (scientistJunkpileDomain.ScientistContext != null && !Object.op_Equality((Object)scientistJunkpileDomain.ScientistContext.Body, (Object)null)) && (!scientistJunkpileDomain.ScientistContext.Body.IsDestroyed && !scientistJunkpileDomain.ScientistContext.Body.IsDead())) { return(false); } this.Spawned.RemoveAt(index); } return(true); }
public void SpawnScientist() { Vector3 vector3; Quaternion quaternion; if (!ConVar.AI.npc_enable) { return; } if (this.Spawned == null || this.Spawned.Count >= this.MaxPopulation || !this.IsUnderGlobalSpawnThreshold()) { return; } float spawnBaseChance = this.SpawnBaseChance; ScientistJunkpileSpawner.JunkpileType spawnType = this.SpawnType; if (spawnType == ScientistJunkpileSpawner.JunkpileType.A) { spawnBaseChance = ConVar.AI.npc_junkpile_a_spawn_chance; } else if (spawnType == ScientistJunkpileSpawner.JunkpileType.G) { spawnBaseChance = ConVar.AI.npc_junkpile_g_spawn_chance; } if (UnityEngine.Random.@value > spawnBaseChance) { 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.ScientistPrefab.resourcePath, vector3, quaternion, false); ScientistJunkpileDomain component = baseEntity.GetComponent <ScientistJunkpileDomain>(); if (!component) { baseEntity.Kill(BaseNetworkable.DestroyMode.None); return; } baseEntity.enableSaving = false; baseEntity.gameObject.AwakeFromInstantiate(); baseEntity.Spawn(); component.Movement = this.Movement; component.MovementRadius = this.MovementRadius; component.ReducedLongRangeAccuracy = this.ReducedLongRangeAccuracy; this.Spawned.Add(component); } } }
public void SpawnScientist() { if (!AI.npc_enable || this.Spawned == null || (this.Spawned.Count >= this.MaxPopulation || !this.IsUnderGlobalSpawnThreshold())) { return; } float num1 = this.SpawnBaseChance; switch (this.SpawnType) { case ScientistJunkpileSpawner.JunkpileType.A: num1 = AI.npc_junkpile_a_spawn_chance; break; case ScientistJunkpileSpawner.JunkpileType.G: num1 = AI.npc_junkpile_g_spawn_chance; break; } if ((double)Random.get_value() > (double)num1) { return; } int num2 = this.MaxPopulation - this.Spawned.Count; for (int index = 0; index < num2; ++index) { Vector3 pos; Quaternion rot; if (!Object.op_Equality((Object)this.GetSpawnPoint(out pos, out rot), (Object)null)) { BaseEntity entity = GameManager.server.CreateEntity(this.ScientistPrefab.resourcePath, pos, rot, false); ScientistJunkpileDomain component = (ScientistJunkpileDomain)((Component)entity).GetComponent <ScientistJunkpileDomain>(); if (Object.op_Implicit((Object)component)) { entity.enableSaving = false; ((Component)entity).get_gameObject().AwakeFromInstantiate(); entity.Spawn(); component.Movement = this.Movement; component.MovementRadius = this.MovementRadius; component.ReducedLongRangeAccuracy = this.ReducedLongRangeAccuracy; this.Spawned.Add(component); } else { entity.Kill(BaseNetworkable.DestroyMode.None); break; } } } }
private bool IsAllSpawnedDead() { for (int i = 0; i < this.Spawned.Count; i++) { ScientistJunkpileDomain item = this.Spawned[i]; if (!(item == null) && !(item.transform == null) && item.ScientistContext != null && !(item.ScientistContext.Body == null) && !item.ScientistContext.Body.IsDestroyed && !item.ScientistContext.Body.IsDead()) { return(false); } this.Spawned.RemoveAt(i); i--; } return(true); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileDomain aiDomain = npc.AiDomain as ScientistJunkpileDomain; if (aiDomain == null || aiDomain.ScientistContext == null) { return; } if (this.coverPointComparer == null) { this.coverPointComparer = new CoverPointsInRangeSensor.CoverPointComparer(npc); } float allowedCoverRangeSqr = aiDomain.GetAllowedCoverRangeSqr(); this._FindCoverPointsInVolume(npc.transform.position, aiDomain.ScientistContext.CoverPoints, ref aiDomain.ScientistContext.CoverVolume, ref this.nextCoverPosInfoTick, time, aiDomain.ScientistContext.Location, allowedCoverRangeSqr); }
public ScientistJunkpileContext(HTNPlayer body, ScientistJunkpileDomain 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 (ScientistJunkpileContext._worldStateChanges == null) { ScientistJunkpileContext._worldStateChanges = new Stack <WorldStateInfo> [length]; for (int index = 0; index < length; ++index) { ScientistJunkpileContext._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.ScientistJunkpileContext != this) { this.Memory = new ScientistJunkpileMemory(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; } } if (!Object.op_Inequality((Object)this.Location, (Object)null)) { return; } this.Junkpile = (JunkPile)((Component)this.Location).GetComponent <JunkPile>(); }
public ScientistJunkpileContext(HTNPlayer body, ScientistJunkpileDomain 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 (ScientistJunkpileContext._worldStateChanges == null) { ScientistJunkpileContext._worldStateChanges = new Stack <WorldStateInfo> [length]; for (int i = 0; i < length; i++) { ScientistJunkpileContext._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.ScientistJunkpileContext != this) { this.Memory = new ScientistJunkpileMemory(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; } if (this.Location != null) { this.Junkpile = this.Location.GetComponent <JunkPile>(); } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileDomain aiDomain = npc.AiDomain as ScientistJunkpileDomain; if (aiDomain == null || aiDomain.ScientistContext == null) { return; } AttackEntity firearm = aiDomain.GetFirearm(); AnimalsInRangeSensor.QueryResultCount = BaseEntity.Query.Server.GetInSphere(npc.transform.position, npc.AiDefinition.Engagement.MediumRangeFirearm(firearm), 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.SqrMediumRangeFirearm(firearm)) { 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++) { AnimalInfo item1 = animalsInRange[j]; if (time - item1.Time > npc.AiDefinition.Memory.ForgetAnimalInRangeTime) { if (item1.Animal == aiDomain.ScientistContext.Memory.PrimaryKnownAnimal.Animal) { if (AnimalReasoner.IsNearby(aiDomain, item1.SqrDistance)) { goto Label0; } aiDomain.ScientistContext.Memory.ForgetPrimiaryAnimal(); } animalsInRange.RemoveAt(j); j--; } Label0: } }
public static bool IsNearby(ScientistJunkpileDomain domain, float sqrDistance) { AttackEntity firearm = domain.GetFirearm(); return((double)sqrDistance < (double)domain.ScientistDefinition.Engagement.SqrCloseRangeFirearm(firearm) + 4.0); }
private IEnumerator EquipTool(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; } int num = 1; if (TOD_Sky.Instance != null && TOD_Sky.Instance.IsNight) { num = 2; } Item item = target.inventory.containerBelt.GetSlot(num); if (item == null) { item = target.inventory.containerBelt.GetSlot(0); if (item == null) { yield break; } } target.UpdateActiveItem(item.uid); yield return(CoroutineEx.waitForSeconds(0.25f)); ScientistJunkpileDomain aiDomain = target.AiDomain as ScientistJunkpileDomain; 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) { HeldEntity heldEntity1 = target.GetHeldEntity(); if (!(heldEntity1 != null) || !heldEntity1.LightsOn()) { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.ResearchItem, true, true, true); } else { aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.LightSourceItem, true, true, true); } } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileDomain aiDomain = npc.AiDomain as ScientistJunkpileDomain; if (Object.op_Equality((Object)aiDomain, (Object)null) || aiDomain.ScientistContext == null) { return; } AttackEntity firearm = aiDomain.GetFirearm(); AnimalsInRangeSensor.QueryResultCount = BaseEntity.Query.Server.GetInSphere(npc.transform.get_position(), npc.AiDefinition.Engagement.MediumRangeFirearm(firearm), (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.SqrMediumRangeFirearm(firearm)) { 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) { if (Object.op_Equality((Object)animalInfo.Animal, (Object)aiDomain.ScientistContext.Memory.PrimaryKnownAnimal.Animal)) { if (!AnimalReasoner.IsNearby(aiDomain, animalInfo.SqrDistance)) { aiDomain.ScientistContext.Memory.ForgetPrimiaryAnimal(); } else { continue; } } animalsInRange.RemoveAt(index); --index; } } }
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); } } } } }