Beispiel #1
0
            private void SpawnNpc(Vector3 position, Quaternion rotation)
            {
                NPCPlayerApex npc = (NPCPlayerApex)GameManager.server.CreateEntity(NPC_PREFAB, position, rotation);

                if (npc == null)
                {
                    return;
                }

                npc.enableSaving = false;
                npc.startHealth  = _settings.NpcHealth;
                npc.Spawn();
                npc.displayName = _settings.NpcName;
                npc.InitializeHealth(_settings.NpcHealth, _settings.NpcHealth);
                npc.Stats.VisionRange            = _settings.NpcAggression + 3f;
                npc.Stats.DeaggroRange           = _settings.NpcAggression + 2f;
                npc.Stats.AggressionRange        = _settings.NpcAggression + 1f;
                npc.Stats.LongRange              = _settings.NpcAggression;
                npc.Stats.MaxRoamRange           = _settings.NpcRadius;
                npc.Stats.Hostility              = 1f;
                npc.Stats.Defensiveness          = 1f;
                npc.Stats.OnlyAggroMarkedTargets = true;
                npc.InitFacts();

                npc.gameObject.AddComponent <NavigationComponent>()
                ?.SetDestination(position);

                CacheAdd(npc);

                npc.Invoke(() => GiveKit(npc, _settings.Kits.GetRandom(), _settings.UseKits), 2f);
            }
Beispiel #2
0
        public override void Execute(PlayerTargetContext c)
        {
            List <AiAnswer_ShareEnemyTarget> aiAnswerShareEnemyTargets;

            Memory.ExtendedInfo extendedInfo;
            NPCPlayerApex       self = c.Self as NPCPlayerApex;

            if (self != null)
            {
                if (self.AskQuestion(new AiQuestion_ShareEnemyTarget(), out aiAnswerShareEnemyTargets) > 0)
                {
                    foreach (AiAnswer_ShareEnemyTarget aiAnswerShareEnemyTarget in aiAnswerShareEnemyTargets)
                    {
                        if (!(aiAnswerShareEnemyTarget.PlayerTarget != null) || !aiAnswerShareEnemyTarget.LastKnownPosition.HasValue || !self.HostilityConsideration(aiAnswerShareEnemyTarget.PlayerTarget))
                        {
                            continue;
                        }
                        c.Target            = aiAnswerShareEnemyTarget.PlayerTarget;
                        c.Score             = 1f;
                        c.LastKnownPosition = aiAnswerShareEnemyTarget.LastKnownPosition.Value;
                        self.UpdateTargetMemory(c.Target, c.Score, c.LastKnownPosition, out extendedInfo);
                        return;
                    }
                }
            }
        }
        public static bool Evaluate(IAIAgent self, Vector3 optionPosition, out Vector3 dir, out float dot)
        {
            dir = optionPosition - self.Entity.ServerPosition;
            NPCPlayerApex nPCPlayerApex = self as NPCPlayerApex;

            if (nPCPlayerApex == null)
            {
                dir.Normalize();
                dot = Vector3.Dot(dir, self.Entity.transform.forward);
                if (dot < self.GetStats.VisionCone)
                {
                    dot = -1f;
                    return(false);
                }
            }
            else
            {
                if (nPCPlayerApex.ToEnemyRangeEnum(dir.sqrMagnitude) == NPCPlayerApex.EnemyRangeEnum.CloseAttackRange)
                {
                    dot = 1f;
                    dir.Normalize();
                    return(true);
                }
                dir.Normalize();
                dot = Vector3.Dot(dir, nPCPlayerApex.eyes.BodyForward());
                if (dot < self.GetStats.VisionCone)
                {
                    dot = -1f;
                    return(false);
                }
            }
            return(true);
        }
 private static bool EvaluateFlanking(
     CoverContext c,
     CoverPoint option,
     Vector3 dirCover,
     Vector3 dirDanger,
     float directness,
     out float result)
 {
     result = 0.0f;
     if ((double)directness > -0.5 && (double)directness < 0.5)
     {
         float num = 1f - Mathf.Abs(directness);
         if ((double)num > (double)c.BestFlankValue)
         {
             if (ConVar.AI.npc_cover_use_path_distance && c.Self.IsNavRunning() && Object.op_Inequality((Object)c.Self.AttackTarget, (Object)null))
             {
                 NPCPlayerApex self = c.Self as NPCPlayerApex;
                 if (Object.op_Inequality((Object)self, (Object)null) && !self.PathDistanceIsValid(c.Self.AttackTarget.ServerPosition, option.Position, false))
                 {
                     return(false);
                 }
             }
             c.BestFlankValue = 0.1f - Mathf.Abs(num);
             c.BestFlankCP    = option;
             result           = c.BestFlankValue;
             return(true);
         }
     }
     return(false);
 }
 private static bool EvaluateRetreat(
     CoverContext c,
     CoverPoint option,
     Vector3 dirCover,
     Vector3 dirDanger,
     ref float directness,
     out float result)
 {
     result = 0.0f;
     if ((double)directness <= -0.5)
     {
         NPCPlayerApex self = c.Self as NPCPlayerApex;
         if (Object.op_Equality((Object)self, (Object)null))
         {
             return(false);
         }
         if ((double)((Vector3) ref dirCover).get_sqrMagnitude() < (double)self.MinDistanceToRetreatCover * (double)self.MinDistanceToRetreatCover)
         {
             directness = -0.49f;
             return(false);
         }
         float num = directness * -1f;
         if ((double)num > (double)c.BestRetreatValue)
         {
             c.BestRetreatValue = num;
             c.BestRetreatCP    = option;
             result             = c.BestRetreatValue;
             return(true);
         }
     }
     return(false);
 }
 public void Setup(NPCPlayerApex human)
 {
     this.Retreat.Human = human;
     this.Flank.Human   = human;
     this.Advance.Human = human;
     this.Closest.Human = human;
 }
Beispiel #7
0
        private int GetPlayersSensed(NPCPlayerApex npc, Vector3 position, float distance, BaseEntity[] targetList)
        {
            return(BaseEntity.Query.Server.GetInSphere(position, distance, targetList,
                                                       entity =>
            {
                BasePlayer target = entity as BasePlayer;
                object callHook = target != null && npc != null && target != npc ? Interface.CallHook("OnNpcTarget", npc, target) : null;
                if (callHook != null)
                {
                    foreach (Memory.SeenInfo seenInfo in npc.AiContext.Memory.All)
                    {
                        if (seenInfo.Entity == target)
                        {
                            npc.AiContext.Memory.All.Remove(seenInfo);
                            break;
                        }
                    }

                    foreach (Memory.ExtendedInfo extendedInfo in npc.AiContext.Memory.AllExtended)
                    {
                        if (extendedInfo.Entity == target)
                        {
                            npc.AiContext.Memory.AllExtended.Remove(extendedInfo);
                            break;
                        }
                    }
                }

                return target != null && callHook == null && target.isServer && !target.IsSleeping() && !target.IsDead() && target.Family != npc.Family;
            }));
        }
 private static bool EvaluateRetreat(CoverContext c, CoverPoint option, Vector3 dirCover, Vector3 dirDanger, ref float directness, out float result)
 {
     result = 0f;
     if (directness <= -0.5f)
     {
         NPCPlayerApex self = c.Self as NPCPlayerApex;
         if (self == null)
         {
             return(false);
         }
         if (dirCover.sqrMagnitude < self.MinDistanceToRetreatCover * self.MinDistanceToRetreatCover)
         {
             directness = -0.49f;
             return(false);
         }
         float single = directness * -1f;
         if (single > c.BestRetreatValue)
         {
             c.BestRetreatValue = single;
             c.BestRetreatCP    = option;
             result             = c.BestRetreatValue;
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
        private object IOnNpcPlayerSense(NPCPlayerApex npc)
        {
            BasePlayer[] targetList = { };
            float        distance   = 0f;

            if (NPCPlayerApex.GunshotSensationQueryResults.Length > 0)
            {
                targetList = NPCPlayerApex.GunshotSensationQueryResults;
                distance   = npc.Stats.CloseRange;
            }
            else if (NPCPlayerApex.PlayerQueryResults.Length > 0)
            {
                targetList = NPCPlayerApex.PlayerQueryResults;
                distance   = npc.Stats.VisionRange;
            }

            BaseEntity.Query.Server.GetPlayersInSphere(npc.ServerPosition, distance, targetList,
                                                       player =>
            {
                object callHook = Interface.CallHook("OnNpcPlayerTarget", npc, player);
                if (callHook != null)
                {
                    foreach (Memory.SeenInfo seenInfo in npc.AiContext.Memory.All)
                    {
                        if (seenInfo.Entity == player)
                        {
                            npc.AiContext.Memory.All.Remove(seenInfo);
                            break;
                        }
                    }

                    foreach (Memory.ExtendedInfo extendedInfo in npc.AiContext.Memory.AllExtended)
                    {
                        if (extendedInfo.Entity == player)
                        {
                            npc.AiContext.Memory.AllExtended.Remove(extendedInfo);
                            break;
                        }
                    }

                    npc.AiContext.AIAgent.AttackTarget = null;
                    npc.AiContext.EnemyNpc             = null;
                    npc.AiContext.EnemyPlayer          = null;
                    npc.CurrentBehaviour = BaseNpc.Behaviour.Idle;

                    npc.SetFact(NPCPlayerApex.Facts.IsAggro, 0);
                    npc.SetFact(NPCPlayerApex.Facts.HasEnemy, 0);
                    npc.SetFact(NPCPlayerApex.Facts.EnemyRange, 5);
                    npc.SetFact(NPCPlayerApex.Facts.AfraidRange, 1);
                    npc.SetFact(NPCPlayerApex.Facts.HasLineOfSight, 0);
                    npc.SetFact(NPCPlayerApex.Facts.HasLineOfSightCrouched, 0);
                    npc.SetFact(NPCPlayerApex.Facts.HasLineOfSightStanding, 0);
                }

                return(player != null && callHook == null && player.isServer && !player.IsSleeping() && !player.IsDead());
            });

            return(true);
        }
 public void AddNpc(NPCPlayerApex npc)
 {
     if (this._npcs == null)
     {
         this._npcs = new List <NPCPlayerApex>(1);
     }
     this._npcs.Add(npc);
 }
Beispiel #11
0
        private object OnNpcPlayerTarget(NPCPlayerApex npcPlayer, BaseEntity entity)
        {
            var player = entity as BasePlayer;

            return(player == null || player.IsNpc || player.net?.connection == null || !IsLimited(player)
                ? (object)null
                : false);
        }
Beispiel #12
0
 private object OnNpcPlayerTarget(NPCPlayerApex npcPlayer, BaseEntity entity)
 {
     if (entity.IsNpc)
     {
         return(false);
     }
     return(null);
 }
 public NPCHumanContext(NPCPlayerApex human) : base(human)
 {
     this.sampledCoverPoints     = new List <CoverPoint>();
     this.EnemyCoverPoints       = new List <CoverPoint>();
     this.CheckedHideoutPoints   = new List <NPCHumanContext.HideoutPoint>();
     this.sampledCoverPointTypes = new List <CoverPoint.CoverType>();
     this.CoverSet.Setup(human);
 }
Beispiel #14
0
        private object IOnNpcTarget(NPCPlayerApex npc, BaseEntity target)
        {
            if (Interface.CallHook("OnNpcTarget", npc, target) != null)
            {
                return(0f);
            }

            return(null);
        }
Beispiel #15
0
 public static byte Evaluate(
     NPCPlayerApex self,
     BasePlayer option,
     out int standing,
     out int crouched)
 {
     standing = self.IsVisibleStanding(option) ? 1 : 0;
     crouched = self.IsVisibleCrouched(option) ? 1 : 0;
     return((byte)(standing + crouched * 2));
 }
        public static bool Test(PlayerTargetContext c, AiLocationSpawner.SquadSpawnerLocation location)
        {
            NPCPlayerApex self = c.Self as NPCPlayerApex;

            if (Object.op_Inequality((Object)self, (Object)null) && Object.op_Inequality((Object)self.AiContext.AiLocationManager, (Object)null))
            {
                return(self.AiContext.AiLocationManager.LocationType == location);
            }
            return(false);
        }
 public static bool Evaluate(
     PlayerTargetContext context,
     IList <IOptionScorer <BasePlayer> > scorers,
     BasePlayer[] options,
     int numOptions,
     bool allScorersMustScoreAboveZero,
     out BasePlayer best,
     out float bestScore,
     out int bestIndex,
     out Vector3 bestLastKnownPosition)
 {
     bestScore             = float.MinValue;
     best                  = (BasePlayer)null;
     bestIndex             = -1;
     bestLastKnownPosition = Vector3.get_zero();
     for (int index1 = 0; index1 < numOptions; ++index1)
     {
         context.CurrentOptionsIndex = index1;
         float score = 0.0f;
         bool  flag  = true;
         for (int index2 = 0; index2 < ((ICollection <IOptionScorer <BasePlayer> >)scorers).Count; ++index2)
         {
             if (!((ICanBeDisabled)scorers[index2]).get_isDisabled())
             {
                 float num = scorers[index2].Score((IAIContext)context, options[index1]);
                 if (allScorersMustScoreAboveZero && (double)num <= 0.0)
                 {
                     flag = false;
                     break;
                 }
                 score += num;
             }
         }
         if (flag)
         {
             Vector3     vector3  = Vector3.get_zero();
             BaseContext context1 = context.Self.GetContext(Guid.Empty) as BaseContext;
             if (context1 != null)
             {
                 NPCPlayerApex       self = context.Self as NPCPlayerApex;
                 Memory.ExtendedInfo extendedInfo;
                 vector3 = context1.Memory.Update((BaseEntity)options[index1], score, context.Direction[index1], context.Dot[index1], context.DistanceSqr[index1], context.LineOfSight[index1], Object.op_Inequality((Object)self, (Object)null) && Object.op_Equality((Object)self.lastAttacker, (Object)options[index1]), Object.op_Inequality((Object)self, (Object)null) ? self.lastAttackedTime : 0.0f, out extendedInfo).Position;
             }
             if ((double)score > (double)bestScore)
             {
                 bestScore             = score;
                 best                  = options[index1];
                 bestIndex             = index1;
                 bestLastKnownPosition = vector3;
             }
         }
     }
     return(Object.op_Inequality((Object)best, (Object)null));
 }
Beispiel #18
0
        // Hide from scientist NPCs
        private object OnNpcPlayerTarget(NPCPlayerApex npc, BaseEntity entity)
        {
            BasePlayer basePlayer = entity as BasePlayer;

            if (IsInvisible(basePlayer))
            {
                return(true); // Cancel, not a bool hook
            }

            return(null);
        }
Beispiel #19
0
        // Hide from scientist NPCs
        private object OnNpcPlayerTarget(NPCPlayerApex npc, BaseEntity entity)
        {
            var basePlayer = entity as BasePlayer;

            if (basePlayer != null && IsInvisible(basePlayer))
            {
                return(0f);
            }

            return(null);
        }
Beispiel #20
0
        //scientist NPCs
        private object OnNpcPlayerTarget(NPCPlayerApex npc, BaseEntity entity)
        {
            var basePlayer = entity as BasePlayer;

            if (basePlayer != null && _data.Contains(basePlayer) && !IsNpc(basePlayer))
            {
                return(false);
            }

            return(null);
        }
Beispiel #21
0
            void CacheDel(NPCPlayerApex player)
            {
                if (player == null)
                {
                    return;
                }

                _npcPlayers.Remove(player);

                _plugin.DelEntity(player);
            }
 public override void DoExecute(BaseContext ctx)
 {
     if (this.crouch)
     {
         NPCPlayerApex aIAgent = ctx.AIAgent as NPCPlayerApex;
         if (aIAgent != null)
         {
             aIAgent.modelState.SetFlag(ModelState.Flag.Ducked, this.crouch);
         }
     }
 }
        private object OnNpcPlayerTarget(NPCPlayerApex npcPlayer, BaseEntity entity)
        {
            BasePlayer player = entity as BasePlayer;

            if (player != null && permission.UserHasPermission(player.UserIDString, permAllow) && (bool)Config["PlayerNPC"])
            {
                return(true);
            }

            return(null);
        }
 public static float Evaluate(CoverContext c, CoverPoint option)
 {
     if (c != null)
     {
         NPCPlayerApex entity = c.Self.Entity as NPCPlayerApex;
         if (Object.op_Inequality((Object)entity, (Object)null) && !entity.AiContext.HasCheckedHideout(option))
         {
             return(1f);
         }
     }
     return(0.0f);
 }
 public static float Evaluate(CoverContext c, CoverPoint option)
 {
     if (c != null)
     {
         NPCPlayerApex entity = c.Self.Entity as NPCPlayerApex;
         if (entity != null && !entity.AiContext.HasCheckedHideout(option))
         {
             return(1f);
         }
     }
     return(0f);
 }
        public override float GetScore(BaseContext c)
        {
            NPCPlayerApex aIAgent = c.AIAgent as NPCPlayerApex;

            if (aIAgent == null)
            {
                return(0f);
            }
            if (!aIAgent.modelState.ducked)
            {
                return(0f);
            }
            return(1f);
        }
Beispiel #27
0
    public virtual bool ShotTest()
    {
        AttackEntity heldEntity = base.GetHeldEntity() as AttackEntity;

        if (heldEntity == null)
        {
            return(false);
        }
        BaseProjectile baseProjectile = heldEntity as BaseProjectile;

        if (baseProjectile)
        {
            if (baseProjectile.primaryMagazine.contents <= 0)
            {
                baseProjectile.ServerReload();
                NPCPlayerApex nPCPlayerApex = this as NPCPlayerApex;
                if (nPCPlayerApex && nPCPlayerApex.OnReload != null)
                {
                    nPCPlayerApex.OnReload();
                }
                return(false);
            }
            if (baseProjectile.NextAttackTime > Time.time)
            {
                return(false);
            }
        }
        if (Mathf.Approximately(heldEntity.attackLengthMin, -1f))
        {
            heldEntity.ServerUse(this.damageScale);
            this.lastGunShotTime = Time.time;
            return(true);
        }
        NPCPlayer nPCPlayer = this;

        if (base.IsInvoking(new Action(nPCPlayer.TriggerDown)))
        {
            return(true);
        }
        if (Time.time < this.nextTriggerTime)
        {
            return(true);
        }
        NPCPlayer nPCPlayer1 = this;

        base.InvokeRepeating(new Action(nPCPlayer1.TriggerDown), 0f, 0.01f);
        this.triggerEndTime = Time.time + UnityEngine.Random.Range(heldEntity.attackLengthMin, heldEntity.attackLengthMax);
        this.TriggerDown();
        return(true);
    }
        public virtual float Score(IAIContext context, BasePlayer option)
        {
            PlayerTargetContext playerTargetContext = context as PlayerTargetContext;

            if (playerTargetContext != null)
            {
                NPCPlayerApex self = playerTargetContext.Self as NPCPlayerApex;
                if (Object.op_Implicit((Object)self) && self.HostilityConsideration(option))
                {
                    return(this.score);
                }
            }
            return(0.0f);
        }
        public static bool Evaluate(CoverContext c, CoverPoint option)
        {
            if (c == null || c.Self.AttackTarget == null)
            {
                return(false);
            }
            NPCPlayerApex entity = c.Self.Entity as NPCPlayerApex;

            if (entity == null)
            {
                return(false);
            }
            return(entity.PathDistanceIsValid(option.Position, c.DangerPoint, true));
        }
        public static bool Test(PlayerTargetContext c, AiLocationSpawner.SquadSpawnerLocation location)
        {
            NPCPlayerApex self = c.Self as NPCPlayerApex;

            if (self == null)
            {
                return(false);
            }
            if (self.AiContext.AiLocationManager == null)
            {
                return(false);
            }
            return(self.AiContext.AiLocationManager.LocationType == location);
        }