public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistDomain aiDomain = npc.AiDomain as ScientistDomain; if (aiDomain == null || aiDomain.ScientistContext == 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) { ScientistDomain aiDomain = npc.AiDomain as ScientistDomain; 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.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; } } }