public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer htnPlayer = npc as HTNPlayer;

            if (Object.op_Equality((Object)htnPlayer, (Object)null))
            {
                return;
            }
            FireTactic   fireTactic = FireTactic.Single;
            AttackEntity heldEntity = htnPlayer.GetHeldEntity() as AttackEntity;

            if (Object.op_Implicit((Object)heldEntity))
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                float          num            = float.MaxValue;
                if (Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null))
                {
                    num = npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance;
                    if (Mathf.Approximately(num, 0.0f))
                    {
                        num = float.MaxValue;
                    }
                }
                fireTactic = (double)heldEntity.attackLengthMin <0.0 || (double)num> (double) npcContext.Body.AiDefinition.Engagement.SqrCloseRangeFirearm((AttackEntity)baseProjectile) ? ((double)heldEntity.attackLengthMin <0.0 || (double)num> (double) npcContext.Body.AiDefinition.Engagement.SqrMediumRangeFirearm((AttackEntity)baseProjectile) ? FireTactic.Single : FireTactic.Burst) : FireTactic.FullAuto;
            }
            npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.FireTactic, fireTactic, true, true, true);
        }
 public static void TickFootstepHearingTest(IHTNAgent npc, ref NpcPlayerInfo info)
 {
     if (info.SqrDistance < npc.AiDefinition.Sensory.SqrHearingRange)
     {
         float player = info.Player.estimatedSpeed;
         if (player <= 2f)
         {
             return;
         }
         if (player > 5f)
         {
             npc.AiDomain.NpcContext.EnemyPlayersAudible.Add(info);
         }
         else
         {
             HTNPlayer hTNPlayer = npc as HTNPlayer;
             if (hTNPlayer)
             {
                 AttackEntity heldEntity = hTNPlayer.GetHeldEntity() as AttackEntity;
                 if (info.SqrDistance < npc.AiDefinition.Engagement.SqrCloseRangeFirearm(heldEntity))
                 {
                     npc.AiDomain.NpcContext.EnemyPlayersAudible.Add(info);
                     return;
                 }
             }
             else if (info.SqrDistance < npc.AiDefinition.Engagement.SqrCloseRange)
             {
                 npc.AiDomain.NpcContext.EnemyPlayersAudible.Add(info);
                 return;
             }
         }
     }
 }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer hTNPlayer = npc as HTNPlayer;

            if (hTNPlayer == null)
            {
                return;
            }
            FireTactic   fireTactic = FireTactic.Single;
            AttackEntity heldEntity = hTNPlayer.GetHeldEntity() as AttackEntity;

            if (heldEntity)
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                float          sqrDistance    = Single.MaxValue;
                if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player != null)
                {
                    sqrDistance = npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance;
                    if (Mathf.Approximately(sqrDistance, 0f))
                    {
                        sqrDistance = Single.MaxValue;
                    }
                }
                else if (npcContext.Memory.PrimaryKnownAnimal.Animal != null)
                {
                    sqrDistance = npcContext.Memory.PrimaryKnownAnimal.SqrDistance;
                    if (Mathf.Approximately(sqrDistance, 0f))
                    {
                        sqrDistance = Single.MaxValue;
                    }
                }
                if (heldEntity.attackLengthMin < 0f || sqrDistance > npcContext.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(baseProjectile))
                {
                    fireTactic = (heldEntity.attackLengthMin <0f || sqrDistance> npcContext.Body.AiDefinition.Engagement.SqrMediumRangeFirearm(baseProjectile) ? FireTactic.Single : FireTactic.Burst);
                }
                else
                {
                    fireTactic = FireTactic.FullAuto;
                }
            }
            npcContext.SetFact(Facts.FireTactic, fireTactic, true, true, true);
        }
Ejemplo n.º 4
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer hTNPlayer = npc as HTNPlayer;

            if (hTNPlayer == null)
            {
                return;
            }
            AttackEntity heldEntity = hTNPlayer.GetHeldEntity() as AttackEntity;

            if (heldEntity)
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                if (baseProjectile != null)
                {
                    float single = (float)baseProjectile.primaryMagazine.contents / (float)baseProjectile.primaryMagazine.capacity;
                    if (single > 0.9f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.FullClip, true, true, true);
                        return;
                    }
                    if (single > 0.6f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.HighClip, true, true, true);
                        return;
                    }
                    if (single > 0.17f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.MediumClip, true, true, true);
                        return;
                    }
                    if (single > 0f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.LowAmmo, true, true, true);
                        return;
                    }
                    npcContext.SetFact(Facts.AmmoState, AmmoState.EmptyClip, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Facts.AmmoState, AmmoState.DontRequireAmmo, true, true, true);
        }
Ejemplo n.º 5
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer htnPlayer = npc as HTNPlayer;

            if (Object.op_Equality((Object)htnPlayer, (Object)null))
            {
                return;
            }
            AttackEntity heldEntity = htnPlayer.GetHeldEntity() as AttackEntity;

            if (Object.op_Implicit((Object)heldEntity))
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                if (Object.op_Inequality((Object)baseProjectile, (Object)null))
                {
                    float num = (float)baseProjectile.primaryMagazine.contents / (float)baseProjectile.primaryMagazine.capacity;
                    if ((double)num > 0.899999976158142)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.FullClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.600000023841858)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.HighClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.170000001788139)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.MediumClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.0)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.LowAmmo, true, true, true);
                        return;
                    }
                    npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.EmptyClip, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.DontRequireAmmo, true, true, true);
        }
Ejemplo n.º 6
0
        public static void TickFootstepHearingTest(IHTNAgent npc, ref NpcPlayerInfo info)
        {
            if ((double)info.SqrDistance >= (double)npc.AiDefinition.Sensory.SqrHearingRange)
            {
                return;
            }
            float estimatedSpeed2D = info.Player.estimatedSpeed2D;

            if ((double)estimatedSpeed2D <= 2.0)
            {
                return;
            }
            if ((double)estimatedSpeed2D <= 5.0)
            {
                HTNPlayer htnPlayer = npc as HTNPlayer;
                if (Object.op_Implicit((Object)htnPlayer))
                {
                    AttackEntity heldEntity = htnPlayer.GetHeldEntity() as AttackEntity;
                    if ((double)info.SqrDistance >= (double)npc.AiDefinition.Engagement.SqrCloseRangeFirearm(heldEntity))
                    {
                        return;
                    }
                    npc.AiDomain.NpcContext.EnemyPlayersAudible.Add(info);
                }
                else
                {
                    if ((double)info.SqrDistance >= (double)npc.AiDefinition.Engagement.SqrCloseRange)
                    {
                        return;
                    }
                    npc.AiDomain.NpcContext.EnemyPlayersAudible.Add(info);
                }
            }
            else
            {
                npc.AiDomain.NpcContext.EnemyPlayersAudible.Add(info);
            }
        }
        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);
                    }
                }
            }
        }
Ejemplo n.º 8
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);
                        }
                    }
                }
            }
        }