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

            if (npcContext == null)
            {
                return;
            }
            NpcPlayerInfo primaryEnemyPlayerTarget = npcContext.GetPrimaryEnemyPlayerTarget();

            if (primaryEnemyPlayerTarget.Player != null)
            {
                if (PreferredFightingRangeReasoner.IsAtPreferredRange(npcContext, ref primaryEnemyPlayerTarget, npcContext.Domain.GetFirearm()))
                {
                    npcContext.SetFact(Facts.AtLocationPreferredFightingRange, 1, true, true, true);
                    return;
                }
                npcContext.SetFact(Facts.AtLocationPreferredFightingRange, 0, true, true, true);
            }
        }
Beispiel #2
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            if (!npcContext.IsFact(Facts.IsReturningHome))
            {
                if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null || time - npcContext.Memory.PrimaryKnownEnemyPlayer.Time > npcContext.Body.AiDefinition.Memory.NoSeeReturnToSpawnTime)
                {
                    npcContext.SetFact(Facts.IsReturningHome, true, true, true, true);
                    return;
                }
            }
            else if (npcContext.IsFact(Facts.CanSeeEnemy) || time - npcContext.Body.lastAttackedTime < 2f || npcContext.IsFact(Facts.AtLocationHome))
            {
                npcContext.SetFact(Facts.IsReturningHome, false, true, true, true);
            }
        }
Beispiel #3
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            if ((npcContext.BodyPosition - npcContext.Domain.SpawnPosition).sqrMagnitude < 3f)
            {
                npcContext.SetFact(Facts.AtLocationHome, true, true, true, true);
                return;
            }
            BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(npcContext.Domain.SpawnPosition);

            if (closestToPoint != null && closestToPoint.transform != null && (npcContext.BodyPosition - closestToPoint.transform.position).sqrMagnitude < 3f)
            {
                npcContext.SetFact(Facts.AtLocationHome, true, true, true, true);
            }
            npcContext.SetFact(Facts.AtLocationHome, false, true, true, true);
        }
Beispiel #4
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.ReservedCoverPoint == null)
            {
                npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationCover, false, true, true, true);
                npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.CoverState, Rust.Ai.HTN.ScientistAStar.CoverState.None, true, true, true);
            }
            else
            {
                Vector3      position       = npcContext.ReservedCoverPoint.Position;
                BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(position);
                if (Object.op_Inequality((Object)closestToPoint, (Object)null) && Object.op_Inequality((Object)((Component)closestToPoint).get_transform(), (Object)null))
                {
                    Vector3 vector3 = Vector3.op_Subtraction(((Component)closestToPoint).get_transform().get_position(), npcContext.BodyPosition);
                    if ((double)((Vector3) ref vector3).get_sqrMagnitude() < 1.0)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationCover, true, true, true, true);
                        npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.CoverState, npcContext.ReservedCoverPoint.NormalCoverType == CoverPoint.CoverType.Partial ? Rust.Ai.HTN.ScientistAStar.CoverState.Partial : Rust.Ai.HTN.ScientistAStar.CoverState.Full, true, true, true);
                        return;
                    }
                }
                npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationCover, false, true, true, true);
                npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.CoverState, Rust.Ai.HTN.ScientistAStar.CoverState.None, true, true, true);
            }
        }
Beispiel #5
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.ReservedCoverPoint == null)
            {
                npcContext.SetFact(Facts.AtLocationCover, false, true, true, true);
                npcContext.SetFact(Facts.CoverState, CoverState.None, true, true, true);
                return;
            }
            Vector3      position       = npcContext.ReservedCoverPoint.Position;
            BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(position);

            if (!(closestToPoint != null) || !(closestToPoint.transform != null) || (closestToPoint.transform.position - npcContext.BodyPosition).sqrMagnitude >= 1f)
            {
                npcContext.SetFact(Facts.AtLocationCover, false, true, true, true);
                npcContext.SetFact(Facts.CoverState, CoverState.None, true, true, true);
                return;
            }
            npcContext.SetFact(Facts.AtLocationCover, true, true, true, true);
            npcContext.SetFact(Facts.CoverState, (npcContext.ReservedCoverPoint.NormalCoverType == CoverPoint.CoverType.Partial ? CoverState.Partial : CoverState.Full), true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.HasNearbyCover, npcContext.CoverPoints.Count > 0 ? 1 : 0, true, true, true);
            if (!npcContext.IsFact(Rust.Ai.HTN.ScientistAStar.Facts.HasEnemyTarget))
            {
                npcContext.ReserveCoverPoint((CoverPoint)null);
            }
            else
            {
                HTNPlayer htnPlayer = npc as HTNPlayer;
                if (Object.op_Equality((Object)htnPlayer, (Object)null))
                {
                    return;
                }
                float bestScore1 = 0.0f;
                float bestScore2 = 0.0f;
                float bestScore3 = 0.0f;
                foreach (CoverPoint coverPoint in npcContext.CoverPoints)
                {
                    if (!coverPoint.IsCompromised && (!coverPoint.IsReserved || coverPoint.ReservedFor.EqualNetID((BaseNetworkable)htnPlayer)))
                    {
                        float arcThreshold = -0.8f;
                        BaseNpcMemory.EnemyPlayerInfo knownEnemyPlayer = npcContext.Memory.PrimaryKnownEnemyPlayer;
                        if (coverPoint.ProvidesCoverFromPoint(knownEnemyPlayer.LastKnownPosition, arcThreshold))
                        {
                            Vector3 dirCover   = Vector3.op_Subtraction(coverPoint.Position, npc.BodyPosition);
                            Vector3 dirDanger  = Vector3.op_Subtraction(knownEnemyPlayer.LastKnownPosition, npc.BodyPosition);
                            float   directness = Vector3.Dot(((Vector3) ref dirCover).get_normalized(), ((Vector3) ref dirDanger).get_normalized());
                            if ((double)bestScore1 < 1.0)
                            {
                                CoverPointsReasoner.EvaluateAdvancement(npc, npcContext, ref bestScore1, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, directness);
                            }
                            if ((double)bestScore3 < 1.0)
                            {
                                CoverPointsReasoner.EvaluateRetreat(npc, npcContext, ref bestScore3, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, ref directness);
                            }
                            if ((double)bestScore2 < 1.0)
                            {
                                CoverPointsReasoner.EvaluateFlanking(npc, npcContext, ref bestScore2, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, directness);
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            Vector3 vector3 = Vector3.op_Subtraction(npcContext.BodyPosition, npcContext.Domain.SpawnPosition);

            if ((double)((Vector3) ref vector3).get_sqrMagnitude() < 3.0)
            {
                npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationHome, true, true, true, true);
            }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null))
            {
                Vector3      destination    = ScientistAStarDomain.AStarNavigateToLastKnownLocationOfPrimaryEnemyPlayer.GetDestination(npcContext);
                BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(destination);
                if (Object.op_Inequality((Object)closestToPoint, (Object)null) && Object.op_Inequality((Object)((Component)closestToPoint).get_transform(), (Object)null))
                {
                    Vector3 vector3 = Vector3.op_Subtraction(((Component)closestToPoint).get_transform().get_position(), npcContext.BodyPosition);
                    if ((double)((Vector3) ref vector3).get_sqrMagnitude() < 1.0)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 1, true, true, true);
                        return;
                    }
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 0, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            for (int i = 0; i < npcContext.Memory.KnownTimedExplosives.Count; i++)
            {
                BaseNpcMemory.EntityOfInterestInfo item = npcContext.Memory.KnownTimedExplosives[i];
                if (item.Entity != null)
                {
                    AttackEntity firearm = npcContext.Domain.GetFirearm();
                    if ((item.Entity.transform.position - npcContext.BodyPosition).sqrMagnitude < npcContext.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm))
                    {
                        npcContext.SetFact(Facts.NearbyExplosives, true, true, true, true);
                        npcContext.IncrementFact(Facts.Alertness, 2, true, true, true);
                        return;
                    }
                }
            }
            npcContext.SetFact(Facts.NearbyExplosives, false, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null || !npcContext.IsFact(Facts.Alertness))
            {
                return;
            }
            if (npcContext.GetFact(Facts.Alertness) > (byte)10)
            {
                npcContext.SetFact(Facts.Alertness, 10, true, false, true);
            }
            if ((double)time - (double)this._lastFrustrationDecrementTime <= 1.0)
            {
                return;
            }
            this._lastFrustrationDecrementTime = time;
            npcContext.IncrementFact(Facts.Alertness, -1, true, true, true);
        }
Beispiel #11
0
        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;
            }
            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.ScientistAStar.Facts.AmmoState, AmmoState.FullClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.600000023841858)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AmmoState, AmmoState.HighClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.170000001788139)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AmmoState, AmmoState.MediumClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.0)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AmmoState, AmmoState.LowAmmo, true, true, true);
                        return;
                    }
                    npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AmmoState, AmmoState.EmptyClip, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AmmoState, AmmoState.DontRequireAmmo, true, true, true);
        }
Beispiel #12
0
        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 (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);
        }
Beispiel #13
0
        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 (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;
                    }
                }
                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);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Facts.CanHearEnemy, npcContext.EnemyPlayersAudible.Count > 0, true, true, true);
            float         single        = 0f;
            NpcPlayerInfo npcPlayerInfo = new NpcPlayerInfo();

            foreach (NpcPlayerInfo enemyPlayersAudible in npc.AiDomain.NpcContext.EnemyPlayersAudible)
            {
                if (enemyPlayersAudible.SqrDistance > npc.AiDefinition.Sensory.SqrHearingRange)
                {
                    continue;
                }
                float single1 = 1f - Mathf.Min(1f, enemyPlayersAudible.SqrDistance / npc.AiDefinition.Sensory.SqrHearingRange);
                float single2 = single1 * 2f;
                if (single2 > single)
                {
                    single        = single2;
                    npcPlayerInfo = enemyPlayersAudible;
                }
                NpcPlayerInfo npcPlayerInfo1 = enemyPlayersAudible;
                npcPlayerInfo1.AudibleScore = single2;
                npcContext.Memory.RememberEnemyPlayer(npc, ref npcPlayerInfo1, time, (1f - single1) * 20f, "SOUND!");
            }
            npcContext.PrimaryEnemyPlayerAudible = npcPlayerInfo;
            if (npcPlayerInfo.Player != null && (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null || npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.VisibilityScore < single))
            {
                npcContext.Memory.RememberPrimaryEnemyPlayer(npcPlayerInfo.Player);
                npcContext.IncrementFact(Facts.Alertness, 1, true, true, true);
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Facts.CanHearEnemy, npcContext.EnemyPlayersAudible.Count > 0, true, true, true);
            float         num1           = 0.0f;
            NpcPlayerInfo npcPlayerInfo1 = new NpcPlayerInfo();

            foreach (NpcPlayerInfo npcPlayerInfo2 in npc.AiDomain.NpcContext.EnemyPlayersAudible)
            {
                if ((double)npcPlayerInfo2.SqrDistance <= (double)npc.AiDefinition.Sensory.SqrHearingRange)
                {
                    float num2 = 1f - Mathf.Min(1f, npcPlayerInfo2.SqrDistance / npc.AiDefinition.Sensory.SqrHearingRange);
                    float num3 = num2 * 2f;
                    if ((double)num3 > (double)num1)
                    {
                        num1           = num3;
                        npcPlayerInfo1 = npcPlayerInfo2;
                    }
                    NpcPlayerInfo info = npcPlayerInfo2;
                    info.AudibleScore = num3;
                    npcContext.Memory.RememberEnemyPlayer(npc, ref info, time, (float)((1.0 - (double)num2) * 20.0), "SOUND!");
                }
            }
            npcContext.PrimaryEnemyPlayerAudible = npcPlayerInfo1;
            if (!Object.op_Inequality((Object)npcPlayerInfo1.Player, (Object)null) || !Object.op_Equality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null) && (double)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.VisibilityScore >= (double)num1)
            {
                return;
            }
            npcContext.Memory.RememberPrimaryEnemyPlayer(npcPlayerInfo1.Player);
            npcContext.IncrementFact(Facts.Alertness, 1, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            npcContext?.SetFact(Facts.HasEnemyTarget, Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null), true, true, true);
        }