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 (!Object.op_Equality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null) && (double)time - (double)npcContext.Memory.PrimaryKnownEnemyPlayer.Time <= (double)npcContext.Body.AiDefinition.Memory.NoSeeReturnToSpawnTime)
                {
                    return;
                }
                npcContext.SetFact(Facts.IsReturningHome, true, true, true, true);
            }
            else
            {
                if (!npcContext.IsFact(Facts.CanSeeEnemy) && (double)time - (double)npcContext.Body.lastAttackedTime >= 2.0 && !npcContext.IsFact(Facts.AtLocationHome))
                {
                    return;
                }
                npcContext.SetFact(Facts.IsReturningHome, false, true, true, true);
            }
        }
Esempio n. 2
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null || !npcContext.IsFact(Facts.CanSeeEnemy) || !npcContext.IsFact(Facts.MaintainCover) && !npcContext.IsFact(Facts.IsReloading) && !npcContext.IsFact(Facts.IsApplyingMedical) || (npcContext.ReservedCoverPoint != null && !npcContext.ReservedCoverPoint.IsCompromised && (!npcContext.IsFact(Facts.AtLocationCover) && (double)time - (double)npcContext.ReservedCoverTime < 1.0) || !ScientistAStarDomain.AStarCanNavigateToCoverLocation.Try(CoverTactic.Retreat, npcContext)))
            {
                return;
            }
            Vector3 coverPosition = ScientistAStarDomain.AStarNavigateToCover.GetCoverPosition(CoverTactic.Retreat, npcContext);

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

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Facts.HasNearbyCover, (npcContext.CoverPoints.Count > 0 ? 1 : 0), true, true, true);
            if (!npcContext.IsFact(Facts.HasEnemyTarget))
            {
                npcContext.ReserveCoverPoint(null);
                return;
            }
            HTNPlayer hTNPlayer = npc as HTNPlayer;

            if (hTNPlayer == null)
            {
                return;
            }
            float single  = 0f;
            float single1 = 0f;
            float single2 = 0f;

            foreach (CoverPoint coverPoint in npcContext.CoverPoints)
            {
                if (coverPoint.IsCompromised || coverPoint.IsReserved && !coverPoint.ReservedFor.EqualNetID(hTNPlayer))
                {
                    continue;
                }
                float single3 = -0.8f;
                BaseNpcMemory.EnemyPlayerInfo primaryKnownEnemyPlayer = npcContext.Memory.PrimaryKnownEnemyPlayer;
                if (!coverPoint.ProvidesCoverFromPoint(primaryKnownEnemyPlayer.LastKnownPosition, single3))
                {
                    continue;
                }
                Vector3 position          = coverPoint.Position - npc.BodyPosition;
                Vector3 lastKnownPosition = primaryKnownEnemyPlayer.LastKnownPosition - npc.BodyPosition;
                float   single4           = Vector3.Dot(position.normalized, lastKnownPosition.normalized);
                if (single < 1f)
                {
                    CoverPointsReasoner.EvaluateAdvancement(npc, npcContext, ref single, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, single4);
                }
                if (single2 < 1f)
                {
                    CoverPointsReasoner.EvaluateRetreat(npc, npcContext, ref single2, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, ref single4);
                }
                if (single1 >= 1f)
                {
                    continue;
                }
                CoverPointsReasoner.EvaluateFlanking(npc, npcContext, ref single1, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, single4);
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null || !npcContext.IsFact(Facts.Frustration) || (double)time - (double)this._lastFrustrationDecrementTime <= 5.0)
            {
                return;
            }
            this._lastFrustrationDecrementTime = time;
            npcContext.IncrementFact(Facts.Frustration, -1, true, true, true);
        }
Esempio n. 5
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);
            }
        }
        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);
                            }
                        }
                    }
                }
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.IsFact(Facts.Frustration) && time - this._lastFrustrationDecrementTime > 5f)
            {
                this._lastFrustrationDecrementTime = time;
                npcContext.IncrementFact(Facts.Frustration, -1, 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);
        }
Esempio n. 9
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;
            }
            NpcOrientation npcOrientation = NpcOrientation.Heading;

            if (npc.IsDestroyed || htnPlayer.IsDead() || htnPlayer.IsWounded())
            {
                npcOrientation = NpcOrientation.None;
            }
            else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownAnimal.Animal, (Object)null))
            {
                npcOrientation = !Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null) ? NpcOrientation.LookAtAnimal : ((double)npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= (double)npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance ? (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation)) : NpcOrientation.LookAtAnimal);
            }
            else if (Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null))
            {
                npcOrientation = npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation);
            }
            else if (Object.op_Inequality((Object)htnPlayer.lastAttacker, (Object)null) && (double)htnPlayer.lastAttackedTime > 0.0 && (double)time - (double)htnPlayer.lastAttackedTime < 2.0)
            {
                npcOrientation = NpcOrientation.LastAttackedDirection;
            }
            else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null))
            {
                npcOrientation = npcContext.GetFact(Rust.Ai.HTN.ScientistAStar.Facts.IsSearching) <= (byte)0 || npcContext.GetFact(Rust.Ai.HTN.ScientistAStar.Facts.IsNavigating) != (byte)0 ? (npcContext.GetFact(Rust.Ai.HTN.ScientistAStar.Facts.IsIdle) <= (byte)0 ? NpcOrientation.LastKnownPrimaryTargetLocation : (!npcContext.IsFact(Rust.Ai.HTN.ScientistAStar.Facts.CanHearEnemy) ? NpcOrientation.LastKnownPrimaryTargetLocation : NpcOrientation.AudibleTargetDirection)) : NpcOrientation.LookAround;
            }
            else if (npcContext.IsFact(Rust.Ai.HTN.ScientistAStar.Facts.CanHearEnemy))
            {
                npcOrientation = NpcOrientation.AudibleTargetDirection;
            }
            npcContext.OrientationType = npcOrientation;
        }
        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;
            }
            if (time - hTNPlayer.lastAttackedTime > 3f && npcContext.IsFact(Facts.Vulnerability) && time - this._lastVulnerabilityDecrementTime > 2f)
            {
                this._lastVulnerabilityDecrementTime = time;
                npcContext.IncrementFact(Facts.Vulnerability, -1, true, true, true);
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            NpcOrientation        npcOrientation;
            NpcOrientation        npcOrientation1;
            ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext;

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

            if (hTNPlayer == null)
            {
                return;
            }
            NpcOrientation npcOrientation2 = NpcOrientation.Heading;

            if (npc.IsDestroyed || hTNPlayer.IsDead() || hTNPlayer.IsWounded())
            {
                npcOrientation2 = NpcOrientation.None;
            }
            else if (npcContext.Memory.PrimaryKnownAnimal.Animal != null)
            {
                if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player == null)
                {
                    npcOrientation2 = NpcOrientation.LookAtAnimal;
                }
                else if (npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance)
                {
                    if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible)
                    {
                        npcOrientation1 = NpcOrientation.PrimaryTargetBody;
                    }
                    else
                    {
                        npcOrientation1 = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation);
                    }
                    npcOrientation2 = npcOrientation1;
                }
                else
                {
                    npcOrientation2 = NpcOrientation.LookAtAnimal;
                }
            }
            else if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player != null)
            {
                if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible)
                {
                    npcOrientation = NpcOrientation.PrimaryTargetBody;
                }
                else
                {
                    npcOrientation = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation);
                }
                npcOrientation2 = npcOrientation;
            }
            else if (hTNPlayer.lastAttacker != null && hTNPlayer.lastAttackedTime > 0f && time - hTNPlayer.lastAttackedTime < 2f)
            {
                npcOrientation2 = NpcOrientation.LastAttackedDirection;
            }
            else if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null)
            {
                if (npcContext.IsFact(Facts.CanHearEnemy))
                {
                    npcOrientation2 = NpcOrientation.AudibleTargetDirection;
                }
            }
            else if (npcContext.GetFact(Facts.IsSearching) > 0 && npcContext.GetFact(Facts.IsNavigating) == 0)
            {
                npcOrientation2 = NpcOrientation.LookAround;
            }
            else if (npcContext.GetFact(Facts.IsIdle) <= 0)
            {
                npcOrientation2 = NpcOrientation.LastKnownPrimaryTargetLocation;
            }
            else
            {
                npcOrientation2 = (!npcContext.IsFact(Facts.CanHearEnemy) ? NpcOrientation.LastKnownPrimaryTargetLocation : NpcOrientation.AudibleTargetDirection);
            }
            npcContext.OrientationType = npcOrientation2;
        }
        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) || (double)time - (double)htnPlayer.lastAttackedTime <= 3.0 || (!npcContext.IsFact(Rust.Ai.HTN.ScientistAStar.Facts.Vulnerability) || (double)time - (double)this._lastVulnerabilityDecrementTime <= 2.0))
            {
                return;
            }
            this._lastVulnerabilityDecrementTime = time;
            npcContext.IncrementFact(Rust.Ai.HTN.ScientistAStar.Facts.Vulnerability, -1, true, true, true);
        }