Exemple #1
0
        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.ScientistAStarPrefab.resourcePath, vector3, quaternion, false);
                    ScientistAStarDomain component  = baseEntity.GetComponent <ScientistAStarDomain>();
                    if (!component)
                    {
                        baseEntity.Kill(BaseNetworkable.DestroyMode.None);
                        return;
                    }
                    baseEntity.enableSaving = false;
                    baseEntity.gameObject.AwakeFromInstantiate();
                    baseEntity.Spawn();
                    component.InstallPath(this.Path);
                    this.Spawned.Add(component);
                }
            }
        }
 private bool IsAllSpawnedDead()
 {
     for (int index = 0; index < this.Spawned.Count; index = index - 1 + 1)
     {
         ScientistAStarDomain scientistAstarDomain = this.Spawned[index];
         if (!Object.op_Equality((Object)scientistAstarDomain, (Object)null) && !Object.op_Equality((Object)((Component)scientistAstarDomain).get_transform(), (Object)null) && (scientistAstarDomain.ScientistContext != null && !Object.op_Equality((Object)scientistAstarDomain.ScientistContext.Body, (Object)null)) && (!scientistAstarDomain.ScientistContext.Body.IsDestroyed && !scientistAstarDomain.ScientistContext.Body.IsDead()))
         {
             return(false);
         }
         this.Spawned.RemoveAt(index);
     }
     return(true);
 }
Exemple #3
0
 private bool IsAllSpawnedDead()
 {
     for (int i = 0; i < this.Spawned.Count; i++)
     {
         ScientistAStarDomain 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);
 }
Exemple #4
0
        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 void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarDomain aiDomain = npc.AiDomain as ScientistAStarDomain;

            if (Object.op_Equality((Object)aiDomain, (Object)null) || aiDomain.ScientistContext == null)
            {
                return;
            }
            if (this.coverPointComparer == null)
            {
                this.coverPointComparer = new CoverPointsInRangeSensor.CoverPointComparer(npc);
            }
            float allowedCoverRangeSqr = aiDomain.GetAllowedCoverRangeSqr();

            this._FindCoverPointsInVolume(npc, npc.transform.get_position(), aiDomain.ScientistContext.CoverPoints, ref aiDomain.ScientistContext.CoverVolume, ref this.nextCoverPosInfoTick, time, aiDomain.ScientistContext.Location, allowedCoverRangeSqr);
        }
        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));

                    ScientistAStarDomain aiDomain = target.AiDomain as ScientistAStarDomain;
                    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)
                        {
                            aiDomain.ScientistContext.SetFact(Facts.HeldItemType, ItemType.LightSourceItem, true, true, true);
                        }
                    }
                }
            }
        }
        public ScientistAStarContext(HTNPlayer body, ScientistAStarDomain 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 (ScientistAStarContext._worldStateChanges == null)
                {
                    ScientistAStarContext._worldStateChanges = new Stack <WorldStateInfo> [length];
                    for (int index = 0; index < length; ++index)
                    {
                        ScientistAStarContext._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.ScientistContext != this)
            {
                this.Memory = new ScientistAStarMemory(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;
                }
            }
        }
Exemple #8
0
        public ScientistAStarContext(HTNPlayer body, ScientistAStarDomain 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 (ScientistAStarContext._worldStateChanges == null)
                {
                    ScientistAStarContext._worldStateChanges = new Stack <WorldStateInfo> [length];
                    for (int i = 0; i < length; i++)
                    {
                        ScientistAStarContext._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.ScientistContext != this)
            {
                this.Memory = new ScientistAStarMemory(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()
 {
     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.ScientistAStarPrefab.resourcePath, pos, rot, false);
                 ScientistAStarDomain component = (ScientistAStarDomain)((Component)entity).GetComponent <ScientistAStarDomain>();
                 if (Object.op_Implicit((Object)component))
                 {
                     entity.enableSaving = false;
                     ((Component)entity).get_gameObject().AwakeFromInstantiate();
                     entity.Spawn();
                     component.InstallPath(this.Path);
                     this.Spawned.Add(component);
                 }
                 else
                 {
                     entity.Kill(BaseNetworkable.DestroyMode.None);
                     break;
                 }
             }
         }
     }
 }
Exemple #10
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarDomain aiDomain = npc.AiDomain as ScientistAStarDomain;

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

            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--;
                }
            }
        }