private static bool EvaluateRetreat(
            IHTNAgent npc,
            ScientistAStarContext c,
            ref float bestScore,
            ref BaseNpcMemory.EnemyPlayerInfo enemyInfo,
            CoverPoint option,
            Vector3 dirCover,
            Vector3 dirDanger,
            ref float directness)
        {
            float sqrMagnitude = ((Vector3) ref dirCover).get_sqrMagnitude();

            if ((double)directness <= -0.200000002980232)
            {
                float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
                float num = (float)((double)directness * -1.0 + ((double)allowedCoverRangeSqr - (double)sqrMagnitude) / (double)allowedCoverRangeSqr) + option.Score;
                if ((double)num > (double)bestScore)
                {
                    bestScore          = num;
                    c.BestRetreatCover = option;
                    return(true);
                }
            }
            return(false);
        }
 private static bool EvaluateAdvancement(
     IHTNAgent npc,
     ScientistAStarContext c,
     ref float bestScore,
     ref BaseNpcMemory.EnemyPlayerInfo enemyInfo,
     CoverPoint option,
     Vector3 dirCover,
     Vector3 dirDanger,
     float directness)
 {
     if ((double)directness >= 0.200000002980232)
     {
         float sqrMagnitude1 = ((Vector3) ref dirCover).get_sqrMagnitude();
         if ((double)sqrMagnitude1 > (double)((Vector3) ref dirDanger).get_sqrMagnitude() || (double)sqrMagnitude1 < 0.5)
         {
             return(false);
         }
         Vector3 vector3_1            = Vector3.op_Subtraction(option.Position, enemyInfo.LastKnownPosition);
         float   sqrMagnitude2        = ((Vector3) ref vector3_1).get_sqrMagnitude();
         float   allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
         float   num = (float)((double)directness + ((double)allowedCoverRangeSqr - (double)sqrMagnitude1) / (double)allowedCoverRangeSqr + (double)option.Score + ((double)sqrMagnitude2 < (double)sqrMagnitude1 ? 1.0 : 0.0));
         if ((double)num > (double)bestScore && (!AI.npc_cover_use_path_distance || npc == null || c.Domain.PathDistanceIsValid(enemyInfo.LastKnownPosition, option.Position, false)))
         {
             Vector3 vector3_2 = Vector3.op_Subtraction(option.Position, enemyInfo.LastKnownPosition);
             if ((double)((Vector3) ref vector3_2).get_sqrMagnitude() < (double)sqrMagnitude1)
             {
                 num *= 0.9f;
             }
             bestScore          = num;
             c.BestAdvanceCover = option;
             return(true);
         }
     }
     return(false);
 }
 protected override void OnSetPrimaryKnownEnemyPlayer(ref BaseNpcMemory.EnemyPlayerInfo info)
 {
     base.OnSetPrimaryKnownEnemyPlayer(ref info);
     if ((info.LastKnownPosition - this.MurdererContext.BodyPosition).sqrMagnitude > 1f)
     {
         this.MurdererContext.HasVisitedLastKnownEnemyPlayerLocation = false;
     }
 }
Exemplo n.º 4
0
        protected override void OnSetPrimaryKnownEnemyPlayer(ref BaseNpcMemory.EnemyPlayerInfo info)
        {
            base.OnSetPrimaryKnownEnemyPlayer(ref info);
            Vector3 vector3 = Vector3.op_Subtraction(info.LastKnownPosition, ((Component)this.BearContext.Body).get_transform().get_position());

            if ((double)((Vector3) ref vector3).get_sqrMagnitude() <= 1.0)
            {
                return;
            }
            this.BearContext.HasVisitedLastKnownEnemyPlayerLocation = false;
        }
Exemplo n.º 5
0
        public override Vector3 GetDirectionLookAround()
        {
            BaseNpcMemory.EnemyPlayerInfo knownEnemyPlayer = this.Memory.PrimaryKnownEnemyPlayer;
            if (!Object.op_Inequality((Object)knownEnemyPlayer.PlayerInfo.Player, (Object)null))
            {
                return(((Component)this.Body).get_transform().get_forward());
            }
            Vector3 vector3 = Vector3.op_Subtraction(knownEnemyPlayer.PlayerInfo.Player.CenterPoint(), this.Body.CenterPoint());

            return(((Vector3) ref vector3).get_normalized());
        }
Exemplo n.º 6
0
        public override Vector3 GetDirectionLookAround()
        {
            BaseNpcMemory.EnemyPlayerInfo primaryKnownEnemyPlayer = this.Memory.PrimaryKnownEnemyPlayer;
            if (primaryKnownEnemyPlayer.PlayerInfo.Player == null)
            {
                return(this.Body.transform.forward);
            }
            Vector3 vector3 = primaryKnownEnemyPlayer.PlayerInfo.Player.CenterPoint() - this.Body.CenterPoint();

            return(vector3.normalized);
        }
        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);
            }
        }
Exemplo n.º 8
0
 public void RememberPrimaryEnemyPlayer(BasePlayer primaryTarget)
 {
     for (int index = 0; index < this.KnownEnemyPlayers.Count; ++index)
     {
         BaseNpcMemory.EnemyPlayerInfo knownEnemyPlayer = this.KnownEnemyPlayers[index];
         if (Object.op_Equality((Object)knownEnemyPlayer.PlayerInfo.Player, (Object)primaryTarget))
         {
             this.OnSetPrimaryKnownEnemyPlayer(ref knownEnemyPlayer);
             break;
         }
     }
 }
 protected override void OnSetPrimaryKnownEnemyPlayer(ref BaseNpcMemory.EnemyPlayerInfo info)
 {
     if (!this.MarkedEnemies.Contains(info.PlayerInfo.Player))
     {
         return;
     }
     base.OnSetPrimaryKnownEnemyPlayer(ref info);
     if ((info.LastKnownPosition - this.ScientistJunkpileContext.BodyPosition).sqrMagnitude > 1f)
     {
         this.ScientistJunkpileContext.HasVisitedLastKnownEnemyPlayerLocation = false;
     }
 }
        public override Vector3 GetDirectionLookAround()
        {
            BaseNpcMemory.EnemyPlayerInfo knownEnemyPlayer = this.Memory.PrimaryKnownEnemyPlayer;
            if (Object.op_Inequality((Object)knownEnemyPlayer.PlayerInfo.Player, (Object)null))
            {
                Vector3 vector3 = Vector3.op_Subtraction(knownEnemyPlayer.PlayerInfo.Player.CenterPoint(), this.Body.CenterPoint());
                return(((Vector3) ref vector3).get_normalized());
            }
            Quaternion rotation    = this.Body.eyes.rotation;
            Vector3    eulerAngles = ((Quaternion) ref rotation).get_eulerAngles();

            return(((Vector3) ref eulerAngles).get_normalized());
        }
        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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        protected override void OnSetPrimaryKnownEnemyPlayer(ref BaseNpcMemory.EnemyPlayerInfo info)
        {
            if (!this.MarkedEnemies.Contains(info.PlayerInfo.Player))
            {
                return;
            }
            base.OnSetPrimaryKnownEnemyPlayer(ref info);
            Vector3 vector3 = Vector3.op_Subtraction(info.LastKnownPosition, this.ScientistJunkpileContext.BodyPosition);

            if ((double)((Vector3) ref vector3).get_sqrMagnitude() <= 1.0)
            {
                return;
            }
            this.ScientistJunkpileContext.HasVisitedLastKnownEnemyPlayerLocation = false;
        }
Exemplo n.º 13
0
        public override Vector3 GetDirectionToMemoryOfPrimaryEnemyPlayerTarget()
        {
            BaseNpcMemory.EnemyPlayerInfo primaryKnownEnemyPlayer = this.Memory.PrimaryKnownEnemyPlayer;
            if (primaryKnownEnemyPlayer.PlayerInfo.Player == null)
            {
                return(this.Body.transform.forward);
            }
            Vector3 vector3           = this.Body.CenterPoint();
            float   body              = vector3.y - this.Body.transform.position.y;
            Vector3 lastKnownPosition = (primaryKnownEnemyPlayer.LastKnownPosition + (primaryKnownEnemyPlayer.PlayerInfo.Player.transform.up * body)) - vector3;

            if (lastKnownPosition.sqrMagnitude < 2f)
            {
                return(primaryKnownEnemyPlayer.LastKnownHeading);
            }
            return(lastKnownPosition.normalized);
        }
Exemplo n.º 14
0
        public override Vector3 GetDirectionToMemoryOfPrimaryEnemyPlayerTarget()
        {
            BaseNpcMemory.EnemyPlayerInfo knownEnemyPlayer = this.Memory.PrimaryKnownEnemyPlayer;
            if (!Object.op_Inequality((Object)knownEnemyPlayer.PlayerInfo.Player, (Object)null))
            {
                return(((Component)this.Body).get_transform().get_forward());
            }
            Vector3 vector3_1 = this.Body.CenterPoint();
            float   num       = (float)(vector3_1.y - ((Component)this.Body).get_transform().get_position().y);
            Vector3 vector3_2 = Vector3.op_Subtraction(Vector3.op_Addition(knownEnemyPlayer.LastKnownPosition, Vector3.op_Multiply(((Component)knownEnemyPlayer.PlayerInfo.Player).get_transform().get_up(), num)), vector3_1);

            if ((double)((Vector3) ref vector3_2).get_sqrMagnitude() < 2.0)
            {
                return(knownEnemyPlayer.LastKnownHeading);
            }
            return(((Vector3) ref vector3_2).get_normalized());
        }
 private static bool EvaluateFlanking(
     IHTNAgent npc,
     ScientistAStarContext c,
     ref float bestScore,
     ref BaseNpcMemory.EnemyPlayerInfo enemyInfo,
     CoverPoint option,
     Vector3 dirCover,
     Vector3 dirDanger,
     float directness)
 {
     if ((double)directness > -0.200000002980232 && (double)directness < 0.200000002980232)
     {
         float sqrMagnitude         = ((Vector3) ref dirCover).get_sqrMagnitude();
         float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
         float num = (float)((0.200000002980232 - (double)Mathf.Abs(directness)) / 0.200000002980232 + ((double)allowedCoverRangeSqr - (double)sqrMagnitude) / (double)allowedCoverRangeSqr) + option.Score;
         if ((double)num > (double)bestScore && (!AI.npc_cover_use_path_distance || npc == null || c.Domain.PathDistanceIsValid(enemyInfo.LastKnownPosition, option.Position, false)))
         {
             bestScore        = 0.1f - Mathf.Abs(num);
             c.BestFlankCover = option;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 16
0
        public void Forget(float memoryTimeout)
        {
            float single = Time.time;

            for (int i = 0; i < this._failedDestinationMemory.Count; i++)
            {
                if (single - this._failedDestinationMemory[i].Time > memoryTimeout)
                {
                    this._failedDestinationMemory.RemoveAt(i);
                    i--;
                }
            }
            for (int j = 0; j < this.KnownEnemyPlayers.Count; j++)
            {
                BaseNpcMemory.EnemyPlayerInfo item = this.KnownEnemyPlayers[j];
                float time = single - item.Time;
                if (time > memoryTimeout)
                {
                    this.KnownEnemyPlayers.RemoveAt(j);
                    j--;
                    if (item.PlayerInfo.Player != null)
                    {
                        this.OnForget(item.PlayerInfo.Player);
                        if (this.PrimaryKnownEnemyPlayer.PlayerInfo.Player == item.PlayerInfo.Player)
                        {
                            this.ForgetPrimiaryEnemyPlayer();
                        }
                    }
                }
                else if (this.PrimaryKnownEnemyPlayer.PlayerInfo.Player == item.PlayerInfo.Player)
                {
                    ref float audibleScore = ref this.PrimaryKnownEnemyPlayer.PlayerInfo.AudibleScore;
                    audibleScore = audibleScore * (1f - time / memoryTimeout);
                    ref float visibilityScore = ref this.PrimaryKnownEnemyPlayer.PlayerInfo.VisibilityScore;
                    visibilityScore = visibilityScore * (1f - time / memoryTimeout);
                }
 private static bool EvaluateAdvancement(IHTNAgent npc, ScientistAStarContext c, ref float bestScore, ref BaseNpcMemory.EnemyPlayerInfo enemyInfo, CoverPoint option, Vector3 dirCover, Vector3 dirDanger, float directness)
 {
     if (directness >= 0.2f)
     {
         float single = dirCover.sqrMagnitude;
         if (single > dirDanger.sqrMagnitude || single < 0.5f)
         {
             return(false);
         }
         float position             = (option.Position - enemyInfo.LastKnownPosition).sqrMagnitude;
         float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
         float single1 = directness + (allowedCoverRangeSqr - single) / allowedCoverRangeSqr + option.Score + (position < single ? 1f : 0f);
         if (single1 > bestScore)
         {
             if (ConVar.AI.npc_cover_use_path_distance && npc != null && !c.Domain.PathDistanceIsValid(enemyInfo.LastKnownPosition, option.Position, false))
             {
                 return(false);
             }
             if ((option.Position - enemyInfo.LastKnownPosition).sqrMagnitude < single)
             {
                 single1 *= 0.9f;
             }
             bestScore          = single1;
             c.BestAdvanceCover = option;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 18
0
 protected virtual void OnSetPrimaryKnownEnemyPlayer(ref BaseNpcMemory.EnemyPlayerInfo info)
 {
     this.PrimaryKnownEnemyPlayer = info;
 }
 private static bool EvaluateFlanking(IHTNAgent npc, ScientistAStarContext c, ref float bestScore, ref BaseNpcMemory.EnemyPlayerInfo enemyInfo, CoverPoint option, Vector3 dirCover, Vector3 dirDanger, float directness)
 {
     if (directness > -0.2f && directness < 0.2f)
     {
         float single = dirCover.sqrMagnitude;
         float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
         float single1 = (0.2f - Mathf.Abs(directness)) / 0.2f + (allowedCoverRangeSqr - single) / allowedCoverRangeSqr + option.Score;
         if (single1 > bestScore)
         {
             if (ConVar.AI.npc_cover_use_path_distance && npc != null && !c.Domain.PathDistanceIsValid(enemyInfo.LastKnownPosition, option.Position, false))
             {
                 return(false);
             }
             bestScore        = 0.1f - Mathf.Abs(single1);
             c.BestFlankCover = option;
             return(true);
         }
     }
     return(false);
 }
        private static bool EvaluateRetreat(IHTNAgent npc, ScientistAStarContext c, ref float bestScore, ref BaseNpcMemory.EnemyPlayerInfo enemyInfo, CoverPoint option, Vector3 dirCover, Vector3 dirDanger, ref float directness)
        {
            float single = dirCover.sqrMagnitude;

            if (directness <= -0.2f)
            {
                float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
                float single1 = directness * -1f + (allowedCoverRangeSqr - single) / allowedCoverRangeSqr + option.Score;
                if (single1 > bestScore)
                {
                    bestScore          = single1;
                    c.BestRetreatCover = option;
                    return(true);
                }
            }
            return(false);
        }