public static AIInformationZone GetForPoint(Vector3 point, BaseEntity from = null)
    {
        AIInformationZone aIInformationZone;

        if (AIInformationZone.zones == null || AIInformationZone.zones.Count == 0)
        {
            return(null);
        }
        List <AIInformationZone> .Enumerator enumerator = AIInformationZone.zones.GetEnumerator();
        try
        {
            while (enumerator.MoveNext())
            {
                AIInformationZone current = enumerator.Current;
                if (!current.areaBox.Contains(point))
                {
                    continue;
                }
                aIInformationZone = current;
                return(aIInformationZone);
            }
            return(AIInformationZone.zones[0]);
        }
        finally
        {
            ((IDisposable)enumerator).Dispose();
        }
        return(aIInformationZone);
    }
Exemplo n.º 2
0
    public void Init()
    {
        AIInformationZone component = GetComponent <AIInformationZone>();

        if (component == null)
        {
            Debug.LogWarning("Unable to Init AIInformationGrid, no AIInformationZone found!");
            return;
        }
        BoundingBox        = component.bounds;
        BoundingBox.center = base.transform.position + component.bounds.center + new Vector3(0f, BoundingBox.extents.y, 0f);
        float num  = BoundingBox.extents.x * 2f;
        float num2 = BoundingBox.extents.z * 2f;

        xCellCount = (int)Mathf.Ceil(num / (float)CellSize);
        zCellCount = (int)Mathf.Ceil(num2 / (float)CellSize);
        Cells      = new AIInformationCell[xCellCount * zCellCount];
        Vector3 vector = (origin = BoundingBox.min);

        vector.x = BoundingBox.min.x + (float)CellSize / 2f;
        vector.z = BoundingBox.min.z + (float)CellSize / 2f;
        for (int i = 0; i < zCellCount; i++)
        {
            for (int j = 0; j < xCellCount; j++)
            {
                Vector3 center = vector;
                Bounds  bounds = new Bounds(center, new Vector3(CellSize, BoundingBox.extents.y * 2f, CellSize));
                Cells[GetIndex(j, i)] = new AIInformationCell(bounds, base.gameObject, j, i);
                vector.x += CellSize;
            }
            vector.x  = BoundingBox.min.x + (float)CellSize / 2f;
            vector.z += CellSize;
        }
    }
Exemplo n.º 3
0
        public override void StateEnter()
        {
            base.StateEnter();
            status = StateStatus.Error;
            brain.Navigator.SetBrakingEnabled(false);
            path = brain.Navigator.Path;
            T entity = GetEntity();

            if (path == null)
            {
                AIInformationZone forPoint = AIInformationZone.GetForPoint(entity.ServerPosition);
                if (forPoint == null)
                {
                    return;
                }
                path = forPoint.GetNearestPath(entity.ServerPosition);
                if (path == null)
                {
                    return;
                }
            }
            currentTargetPoint = path.FindNearestPoint(entity.ServerPosition);
            if (!(currentTargetPoint == null))
            {
                status          = StateStatus.Running;
                currentWaitTime = 0f;
                brain.Navigator.SetDestination(currentTargetPoint.transform.position, BaseNavigator.NavigationSpeed.Slow);
            }
        }
Exemplo n.º 4
0
    public virtual void InitializeAI()
    {
        T entity = GetEntity();

        entity.HasBrain = true;
        Navigator       = GetComponent <BaseNavigator>();
        if (UseAIDesign)
        {
            AIDesign = new AIDesign();
            AIDesign.SetAvailableStates(GetStateList());
            if (Events == null)
            {
                Events = new AIEvents();
            }
            bool senseFriendlies = MaxGroupSize > 0;
            Senses.Init(entity, SenseRange, TargetLostRange, VisionCone, CheckVisionCone, CheckLOS, IgnoreNonVisionSneakers, ListenRange, HostileTargetsOnly, senseFriendlies, IgnoreSafeZonePlayers, SenseTypes);
            if (DefaultDesignSO == null)
            {
                Debug.LogWarning("Brain on " + base.gameObject.name + " is trying to load a null AI design!");
                return;
            }
            Events.Memory.Position.Set(base.transform.position, 4);
            LoadAIDesign(AIDesigns.GetByNameOrInstance(DefaultDesignSO.Filename, InstanceSpecificDesign), null);
            AIInformationZone forPoint = AIInformationZone.GetForPoint(base.transform.position, false);
            if (forPoint != null)
            {
                forPoint.RegisterSleepableEntity(this);
            }
        }
        BaseEntity.Query.Server.AddBrain(entity);
        StartMovementTick();
    }
Exemplo n.º 5
0
 public AIInformationZone GetInformationZone()
 {
     if (Object.op_Equality((Object)this.cachedInfoZone, (Object)null) || (double)Time.get_time() > (double)this.nextZoneSearchTime)
     {
         this.cachedInfoZone     = AIInformationZone.GetForPoint(this.ServerPosition, (BaseEntity)this);
         this.nextZoneSearchTime = Time.get_time() + 5f;
     }
     return(this.cachedInfoZone);
 }
Exemplo n.º 6
0
 public AIInformationZone GetInformationZone()
 {
     if (this.cachedInfoZone == null || UnityEngine.Time.time > this.nextZoneSearchTime)
     {
         this.cachedInfoZone     = AIInformationZone.GetForPoint(this.ServerPosition, this);
         this.nextZoneSearchTime = UnityEngine.Time.time + 5f;
     }
     return(this.cachedInfoZone);
 }
Exemplo n.º 7
0
 public AIInformationZone GetInformationZone(Vector3 pos)
 {
     if (cachedInfoZone == null || UnityEngine.Time.time > nextZoneSearchTime)
     {
         cachedInfoZone     = AIInformationZone.GetForPoint(pos);
         nextZoneSearchTime = UnityEngine.Time.time + 5f;
     }
     return(cachedInfoZone);
 }
Exemplo n.º 8
0
 public AIInformationZone GetInformationZone(Vector3 pos)
 {
     if (VirtualInfoZone != null)
     {
         return(VirtualInfoZone);
     }
     if (cachedInfoZone == null || Time.time > nextZoneSearchTime)
     {
         cachedInfoZone     = AIInformationZone.GetForPoint(pos);
         nextZoneSearchTime = Time.time + 5f;
     }
     return(cachedInfoZone);
 }
Exemplo n.º 9
0
        public override void StateEnter()
        {
            base.StateEnter();
            GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            AIInformationZone informationZone = GetEntity().GetInformationZone(GetEntity().transform.position);

            if (informationZone != null)
            {
                AICoverPoint bestCoverPoint = informationZone.GetBestCoverPoint(GetEntity().transform.position, GetEntity().transform.position, 25f, 50f, GetEntity());
                if ((bool)bestCoverPoint)
                {
                    bestCoverPoint.SetUsedBy(GetEntity(), 10f);
                }
                Vector3 vector = ((bestCoverPoint == null) ? GetEntity().transform.position : bestCoverPoint.transform.position);
                GetEntity().SetDestination(vector);
                brain.mainInterestPoint = vector;
            }
        }
Exemplo n.º 10
0
        public override void StateEnter()
        {
            base.StateEnter();
            base.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            AIInformationZone informationZone = base.GetEntity().GetInformationZone();

            if (informationZone != null)
            {
                AICoverPoint bestCoverPoint = informationZone.GetBestCoverPoint(base.GetEntity().ServerPosition, base.GetEntity().ServerPosition, 25f, 50f, base.GetEntity());
                if (bestCoverPoint)
                {
                    bestCoverPoint.SetUsedBy(base.GetEntity(), 10f);
                }
                Vector3 vector3 = (bestCoverPoint == null ? base.GetEntity().ServerPosition : bestCoverPoint.transform.position);
                base.GetEntity().SetDestination(vector3);
                this.brain.mainInterestPoint = vector3;
            }
        }
Exemplo n.º 11
0
    public AIMovePoint GetBestRoamPosition(Vector3 start)
    {
        AIInformationZone informationZone = this.GetInformationZone();

        if (informationZone == null)
        {
            return(null);
        }
        float       single      = -1f;
        AIMovePoint aIMovePoint = null;

        foreach (AIMovePoint movePoint in informationZone.movePoints)
        {
            if (!movePoint.transform.parent.gameObject.activeSelf)
            {
                continue;
            }
            float single1 = 0f;
            float single2 = Vector3.Dot(this.eyes.BodyForward(), Vector3Ex.Direction2D(movePoint.transform.position, this.eyes.position));
            single1 = single1 + Mathf.InverseLerp(-1f, 1f, single2) * 100f;
            float single3 = Vector3.Distance(this.ServerPosition, movePoint.transform.position);
            if (movePoint.IsUsedForRoaming())
            {
                continue;
            }
            float single4 = Mathf.Abs(this.ServerPosition.y - movePoint.transform.position.y);
            single1 = single1 + (1f - Mathf.InverseLerp(1f, 10f, single4)) * 100f;
            if (single4 > 5f)
            {
                continue;
            }
            if (single3 > 5f)
            {
                single1 = single1 + (1f - Mathf.InverseLerp(5f, 20f, single3)) * 50f;
            }
            if (single1 <= single)
            {
                continue;
            }
            aIMovePoint = movePoint;
            single      = single1;
        }
        return(aIMovePoint);
    }
Exemplo n.º 12
0
 public static void ProcessQueue(QueueType queueType)
 {
     if (queueType == QueueType.Human)
     {
         DoRemoval(_removalQueue, _processQueue);
         AIInformationZone.BudgetedTick();
     }
     else
     {
         DoRemoval(_animalremovalQueue, _animalProcessQueue);
     }
     if (queueType == QueueType.Human)
     {
         DoProcessing(_processQueue, framebudgetms / 1000f, ref lastIndex);
     }
     else
     {
         DoProcessing(_animalProcessQueue, animalframebudgetms / 1000f, ref lastAnimalIndex);
     }
 }
Exemplo n.º 13
0
    public override AIMovePoint GetBestRoamPoint(Vector3 anchorPos, Vector3 currentPos, Vector3 currentDirection, float anchorClampDistance, float lookupMaxRange = 20f)
    {
        AIInformationZone aIInformationZone = null;
        HumanNPC          humanNPC;
        HumanNPCNew       humanNPCNew;

        if ((object)(humanNPC = npc as HumanNPC) != null)
        {
            aIInformationZone = humanNPC.GetInformationZone(currentPos);
        }
        else if ((object)(humanNPCNew = npc as HumanNPCNew) != null)
        {
            aIInformationZone = ((!(humanNPCNew.VirtualInfoZone != null)) ? humanNPCNew.GetInformationZone(currentPos) : humanNPCNew.VirtualInfoZone);
        }
        if (aIInformationZone == null)
        {
            return(null);
        }
        return(GetBestRoamPoint(aIInformationZone, anchorPos, currentPos, currentDirection, anchorClampDistance, lookupMaxRange));
    }
Exemplo n.º 14
0
        public override void StateEnter()
        {
            base.StateEnter();
            this.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            AIInformationZone informationZone = this.GetEntity().GetInformationZone();

            if (!Object.op_Inequality((Object)informationZone, (Object)null))
            {
                return;
            }
            AICoverPoint bestCoverPoint = informationZone.GetBestCoverPoint(this.GetEntity().ServerPosition, this.GetEntity().ServerPosition, 25f, 50f, (BaseEntity)this.GetEntity());

            if (Object.op_Implicit((Object)bestCoverPoint))
            {
                bestCoverPoint.SetUsedBy((BaseEntity)this.GetEntity(), 10f);
            }
            Vector3 newDestination = Object.op_Equality((Object)bestCoverPoint, (Object)null) ? this.GetEntity().ServerPosition : ((Component)bestCoverPoint).get_transform().get_position();

            this.GetEntity().SetDestination(newDestination);
            this.brain.mainInterestPoint = newDestination;
        }
Exemplo n.º 15
0
 public virtual void OnDestroy()
 {
     if (!Rust.Application.isQuitting)
     {
         BaseEntity.Query.Server.RemoveBrain(GetEntity());
         AIInformationZone aIInformationZone = null;
         HumanNPCNew       humanNPCNew       = GetEntity() as HumanNPCNew;
         if (humanNPCNew != null)
         {
             aIInformationZone = humanNPCNew.VirtualInfoZone;
         }
         if (aIInformationZone == null)
         {
             aIInformationZone = AIInformationZone.GetForPoint(base.transform.position);
         }
         if (aIInformationZone != null)
         {
             aIInformationZone.UnregisterSleepableEntity(this);
         }
         LeaveGroup();
     }
 }
Exemplo n.º 16
0
    public AIMovePoint GetBestRoamPosition(Vector3 start)
    {
        AIInformationZone informationZone = this.GetInformationZone();

        if (Object.op_Equality((Object)informationZone, (Object)null))
        {
            return((AIMovePoint)null);
        }
        float       num1        = -1f;
        AIMovePoint aiMovePoint = (AIMovePoint)null;

        foreach (AIMovePoint movePoint in informationZone.movePoints)
        {
            if (((Component)((Component)movePoint).get_transform().get_parent()).get_gameObject().get_activeSelf())
            {
                float num2 = 0.0f + Mathf.InverseLerp(-1f, 1f, Vector3.Dot(this.eyes.BodyForward(), Vector3Ex.Direction2D(((Component)movePoint).get_transform().get_position(), this.eyes.position))) * 100f;
                float num3 = Vector3.Distance(this.ServerPosition, ((Component)movePoint).get_transform().get_position());
                if (!movePoint.IsUsedForRoaming())
                {
                    float num4 = Mathf.Abs((float)(this.ServerPosition.y - ((Component)movePoint).get_transform().get_position().y));
                    float num5 = num2 + (float)((1.0 - (double)Mathf.InverseLerp(1f, 10f, num4)) * 100.0);
                    if ((double)num4 <= 5.0)
                    {
                        if ((double)num3 > 5.0)
                        {
                            num5 += (float)((1.0 - (double)Mathf.InverseLerp(5f, 20f, num3)) * 50.0);
                        }
                        if ((double)num5 > (double)num1)
                        {
                            aiMovePoint = movePoint;
                            num1        = num5;
                        }
                    }
                }
            }
        }
        return(aiMovePoint);
    }
Exemplo n.º 17
0
    public static AIInformationZone GetForPoint(Vector3 point, bool fallBackToNearest = true)
    {
        if (zones == null || zones.Count == 0)
        {
            return(null);
        }
        foreach (AIInformationZone zone in zones)
        {
            if (!(zone == null) && !zone.Virtual && zone.areaBox.Contains(point))
            {
                return(zone);
            }
        }
        if (!fallBackToNearest)
        {
            return(null);
        }
        float             num = float.PositiveInfinity;
        AIInformationZone aIInformationZone = zones[0];

        foreach (AIInformationZone zone2 in zones)
        {
            if (!(zone2 == null) && !(zone2.transform == null) && !zone2.Virtual)
            {
                float num2 = Vector3.Distance(zone2.transform.position, point);
                if (num2 < num)
                {
                    num = num2;
                    aIInformationZone = zone2;
                }
            }
        }
        if (aIInformationZone.Virtual)
        {
            aIInformationZone = null;
        }
        return(aIInformationZone);
    }
Exemplo n.º 18
0
        public override void StateThink(float delta)
        {
            bool flag;

            base.StateThink(delta);
            float single  = 2f;
            float single1 = 0f;

            if (Time.time > this.lastCoverTime + single && !this.isFleeing)
            {
                Vector3           vector3         = (base.GetEntity().currentTarget ? base.GetEntity().currentTarget.ServerPosition : base.GetEntity().ServerPosition + (base.GetEntity().LastAttackedDir * 30f));
                float             single2         = (base.GetEntity().currentTarget != null ? base.GetEntity().DistanceToTarget() : 30f);
                AIInformationZone informationZone = base.GetEntity().GetInformationZone();
                if (informationZone != null)
                {
                    float        secondsSinceAttacked = base.GetEntity().SecondsSinceAttacked;
                    float        single3        = (secondsSinceAttacked < 2f ? 2f : 0f);
                    float        single4        = 20f;
                    AICoverPoint bestCoverPoint = informationZone.GetBestCoverPoint(base.GetEntity().ServerPosition, vector3, single3, single4, base.GetEntity());
                    if (bestCoverPoint)
                    {
                        bestCoverPoint.SetUsedBy(base.GetEntity(), 5f);
                    }
                    Vector3 vector31 = (bestCoverPoint == null ? base.GetEntity().ServerPosition : bestCoverPoint.transform.position);
                    base.GetEntity().SetDestination(vector31);
                    float single5 = Vector3.Distance(vector31, base.GetEntity().ServerPosition);
                    base.GetEntity().DistanceToTarget();
                    int num  = (int)((secondsSinceAttacked >= 4f ? false : base.GetEntity().AmmoFractionRemaining() <= 0.25f));
                    int num1 = (int)((base.GetEntity().healthFraction >= 0.5f || secondsSinceAttacked >= 1f ? false : Time.time > single1));
                    if (single2 > 6f && single5 > 6f || base.GetEntity().currentTarget == null)
                    {
                        this.isFleeing = true;
                        single1        = Time.time + UnityEngine.Random.Range(4f, 7f);
                    }
                    if (single5 > 1f)
                    {
                        base.GetEntity().ClearStationaryAimPoint();
                    }
                }
                this.lastCoverTime = Time.time;
            }
            bool flag1 = Vector3.Distance(base.GetEntity().ServerPosition, base.GetEntity().finalDestination) <= 0.25f;

            if (!this.inCover & flag1)
            {
                if (this.isFleeing)
                {
                    base.GetEntity().SetStationaryAimPoint(base.GetEntity().finalDestination + (-base.GetEntity().eyes.BodyForward() * 5f));
                }
                else if (base.GetEntity().currentTarget)
                {
                    base.GetEntity().SetStationaryAimPoint(base.GetEntity().ServerPosition + (Vector3Ex.Direction2D(base.GetEntity().currentTarget.ServerPosition, base.GetEntity().ServerPosition) * 5f));
                }
            }
            this.inCover = flag1;
            if (!this.inCover)
            {
                this.timeInCover = 0f;
            }
            else
            {
                this.timeInCover += delta;
            }
            base.GetEntity().SetDucked(this.inCover);
            if (this.inCover)
            {
                this.isFleeing = false;
            }
            if (base.GetEntity().AmmoFractionRemaining() == 0f || this.isFleeing)
            {
                flag = true;
            }
            else
            {
                flag = (base.GetEntity().CanSeeTarget() || !this.inCover || base.GetEntity().SecondsSinceDealtDamage <= 2f ? false : base.GetEntity().AmmoFractionRemaining() < 0.25f);
            }
            if (flag)
            {
                base.GetEntity().AttemptReload();
            }
            if (!this.inCover)
            {
                if (base.TimeInState() > 1f && this.isFleeing)
                {
                    base.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
                    return;
                }
                base.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Walk);
            }
        }
Exemplo n.º 19
0
    public override void ServerInit()
    {
        NavMeshBuildSettings settingsByIndex;

        base.ServerInit();
        if (Door.nonWalkableArea < 0)
        {
            Door.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
        }
        if (Door.animalAgentTypeId < 0)
        {
            settingsByIndex        = NavMesh.GetSettingsByIndex(1);
            Door.animalAgentTypeId = settingsByIndex.agentTypeID;
        }
        if (this.NavMeshVolumeAnimals == null)
        {
            this.NavMeshVolumeAnimals      = base.gameObject.AddComponent <NavMeshModifierVolume>();
            this.NavMeshVolumeAnimals.area = Door.nonWalkableArea;
            this.NavMeshVolumeAnimals.AddAgentType(Door.animalAgentTypeId);
            this.NavMeshVolumeAnimals.center = Vector3.zero;
            this.NavMeshVolumeAnimals.size   = Vector3.one;
        }
        if (this.HasSlot(BaseEntity.Slot.Lock))
        {
            this.canNpcOpen = false;
        }
        if (!this.canNpcOpen)
        {
            if (Door.humanoidAgentTypeId < 0)
            {
                settingsByIndex          = NavMesh.GetSettingsByIndex(0);
                Door.humanoidAgentTypeId = settingsByIndex.agentTypeID;
            }
            if (this.NavMeshVolumeHumanoids == null)
            {
                this.NavMeshVolumeHumanoids      = base.gameObject.AddComponent <NavMeshModifierVolume>();
                this.NavMeshVolumeHumanoids.area = Door.nonWalkableArea;
                this.NavMeshVolumeHumanoids.AddAgentType(Door.humanoidAgentTypeId);
                this.NavMeshVolumeHumanoids.center = Vector3.zero;
                this.NavMeshVolumeHumanoids.size   = (Vector3.one + Vector3.up) + Vector3.forward;
            }
        }
        else if (this.NpcTriggerBox == null)
        {
            if (this.isSecurityDoor)
            {
                NavMeshObstacle navMeshObstacle = base.gameObject.AddComponent <NavMeshObstacle>();
                navMeshObstacle.carving = true;
                navMeshObstacle.center  = Vector3.zero;
                navMeshObstacle.size    = Vector3.one;
                navMeshObstacle.shape   = NavMeshObstacleShape.Box;
            }
            this.NpcTriggerBox = (new GameObject("NpcTriggerBox")).AddComponent <NPCDoorTriggerBox>();
            this.NpcTriggerBox.Setup(this);
        }
        AIInformationZone forPoint = AIInformationZone.GetForPoint(base.transform.position, null);

        if (forPoint != null && this.NavMeshLink == null)
        {
            this.NavMeshLink = forPoint.GetClosestNavMeshLink(base.transform.position);
        }
    }
Exemplo n.º 20
0
        public override StateStatus StateThink(float delta)
        {
            base.StateThink(delta);
            float num  = 2f;
            float num2 = 0f;

            if (Time.time > lastCoverTime + num && !isFleeing)
            {
                Vector3           hideFromPosition = (GetEntity().currentTarget ? GetEntity().currentTarget.transform.position : (GetEntity().transform.position + GetEntity().LastAttackedDir * 30f));
                float             num3             = ((GetEntity().currentTarget != null) ? GetEntity().DistanceToTarget() : 30f);
                AIInformationZone informationZone  = GetEntity().GetInformationZone(GetEntity().transform.position);
                if (informationZone != null)
                {
                    float secondsSinceAttacked = GetEntity().SecondsSinceAttacked;
                    float minRange             = ((secondsSinceAttacked < 2f) ? 2f : 0f);
                    float maxRange             = 25f;
                    if (currentCover != null)
                    {
                        currentCover.ClearIfUsedBy(GetEntity());
                        currentCover = null;
                    }
                    AICoverPoint bestCoverPoint = informationZone.GetBestCoverPoint(GetEntity().transform.position, hideFromPosition, minRange, maxRange, GetEntity());
                    if ((bool)bestCoverPoint)
                    {
                        bestCoverPoint.SetUsedBy(GetEntity(), 15f);
                        currentCover = bestCoverPoint;
                    }
                    Vector3 vector = ((bestCoverPoint == null) ? GetEntity().transform.position : bestCoverPoint.transform.position);
                    GetEntity().SetDestination(vector);
                    float num4 = Vector3.Distance(vector, GetEntity().transform.position);
                    bool  flag2;
                    int   num5;
                    if (secondsSinceAttacked < 4f)
                    {
                        flag2 = GetEntity().AmmoFractionRemaining() <= 0.25f;
                    }
                    else
                    {
                        num5 = 0;
                    }
                    bool flag3;
                    int  num6;
                    if (GetEntity().healthFraction < 0.5f && secondsSinceAttacked < 1f)
                    {
                        flag3 = Time.time > num2;
                    }
                    else
                    {
                        num6 = 0;
                    }
                    if ((num3 > 6f && num4 > 8f) || GetEntity().currentTarget == null)
                    {
                        isFleeing = true;
                        num2      = Time.time + Random.Range(4f, 7f);
                    }
                    if (num4 > 1f)
                    {
                        GetEntity().ClearStationaryAimPoint();
                    }
                }
                lastCoverTime = Time.time;
            }
            bool flag = Vector3.Distance(GetEntity().transform.position, GetEntity().finalDestination) <= 0.25f;

            if (!inCover && flag)
            {
                if (isFleeing)
                {
                    GetEntity().SetStationaryAimPoint(GetEntity().finalDestination + -GetEntity().eyes.BodyForward() * 5f);
                }
                else if ((bool)GetEntity().currentTarget)
                {
                    GetEntity().SetStationaryAimPoint(GetEntity().transform.position + Vector3Ex.Direction2D(GetEntity().currentTarget.transform.position, GetEntity().transform.position) * 5f);
                }
            }
            inCover = flag;
            if (inCover)
            {
                timeInCover += delta;
            }
            else
            {
                timeInCover = 0f;
            }
            GetEntity().SetDucked(inCover);
            if (inCover)
            {
                isFleeing = false;
            }
            if (GetEntity().AmmoFractionRemaining() == 0f || isFleeing || (!GetEntity().CanSeeTarget() && inCover && GetEntity().SecondsSinceDealtDamage > 2f && GetEntity().AmmoFractionRemaining() < 0.25f))
            {
                GetEntity().AttemptReload();
            }
            if (!inCover)
            {
                if (base.TimeInState > 1f && isFleeing)
                {
                    GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
                }
                else
                {
                    GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Walk);
                }
            }
            return(StateStatus.Running);
        }
Exemplo n.º 21
0
    public override void ServerInit()
    {
        base.ServerInit();
        if (Door.nonWalkableArea < 0)
        {
            Door.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
        }
        if (Door.animalAgentTypeId < 0)
        {
            NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(1);
            Door.animalAgentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID();
        }
        if (Object.op_Equality((Object)this.NavMeshVolumeAnimals, (Object)null))
        {
            this.NavMeshVolumeAnimals = (NavMeshModifierVolume)((Component)this).get_gameObject().AddComponent <NavMeshModifierVolume>();
            this.NavMeshVolumeAnimals.set_area(Door.nonWalkableArea);
            this.NavMeshVolumeAnimals.AddAgentType(Door.animalAgentTypeId);
            this.NavMeshVolumeAnimals.set_center(Vector3.get_zero());
            this.NavMeshVolumeAnimals.set_size(Vector3.get_one());
        }
        if (this.HasSlot(BaseEntity.Slot.Lock))
        {
            this.canNpcOpen = false;
        }
        if (!this.canNpcOpen)
        {
            if (Door.humanoidAgentTypeId < 0)
            {
                NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(0);
                Door.humanoidAgentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID();
            }
            if (Object.op_Equality((Object)this.NavMeshVolumeHumanoids, (Object)null))
            {
                this.NavMeshVolumeHumanoids = (NavMeshModifierVolume)((Component)this).get_gameObject().AddComponent <NavMeshModifierVolume>();
                this.NavMeshVolumeHumanoids.set_area(Door.nonWalkableArea);
                this.NavMeshVolumeHumanoids.AddAgentType(Door.humanoidAgentTypeId);
                this.NavMeshVolumeHumanoids.set_center(Vector3.get_zero());
                this.NavMeshVolumeHumanoids.set_size(Vector3.op_Addition(Vector3.op_Addition(Vector3.get_one(), Vector3.get_up()), Vector3.get_forward()));
            }
        }
        else if (Object.op_Equality((Object)this.NpcTriggerBox, (Object)null))
        {
            if (this.isSecurityDoor)
            {
                M0 m0 = ((Component)this).get_gameObject().AddComponent <NavMeshObstacle>();
                ((NavMeshObstacle)m0).set_carving(true);
                ((NavMeshObstacle)m0).set_center(Vector3.get_zero());
                ((NavMeshObstacle)m0).set_size(Vector3.get_one());
                ((NavMeshObstacle)m0).set_shape((NavMeshObstacleShape)1);
            }
            this.NpcTriggerBox = (NPCDoorTriggerBox) new GameObject("NpcTriggerBox").AddComponent <NPCDoorTriggerBox>();
            this.NpcTriggerBox.Setup(this);
        }
        AIInformationZone forPoint = AIInformationZone.GetForPoint(((Component)this).get_transform().get_position(), (BaseEntity)null);

        if (!Object.op_Inequality((Object)forPoint, (Object)null) || !Object.op_Equality((Object)this.NavMeshLink, (Object)null))
        {
            return;
        }
        this.NavMeshLink = forPoint.GetClosestNavMeshLink(((Component)this).get_transform().get_position());
    }
Exemplo n.º 22
0
    private AIMovePoint GetBestRoamPoint(AIInformationZone aiZone, Vector3 anchorPos, Vector3 currentPos, Vector3 currentDirection, float clampDistance, float lookupMaxRange)
    {
        if (aiZone == null)
        {
            return(null);
        }
        bool    flag    = clampDistance > -1f;
        float   num     = float.NegativeInfinity;
        AIPoint aIPoint = null;
        int     pointCount;

        AIPoint[] movePointsInRange = aiZone.GetMovePointsInRange(anchorPos, lookupMaxRange, out pointCount);
        if (movePointsInRange == null || pointCount <= 0)
        {
            return(null);
        }
        for (int i = 0; i < pointCount; i++)
        {
            AIPoint aIPoint2 = movePointsInRange[i];
            if (!aIPoint2.transform.parent.gameObject.activeSelf)
            {
                continue;
            }
            float num2  = Mathf.Abs(currentPos.y - aIPoint2.transform.position.y);
            bool  flag2 = currentPos.y < WaterSystem.OceanLevel;
            if (!flag2 && ((!flag2 && aIPoint2.transform.position.y < WaterSystem.OceanLevel) || (currentPos.y >= WaterSystem.OceanLevel && num2 > 5f)))
            {
                continue;
            }
            float num3  = 0f;
            float value = Vector3.Dot(currentDirection, Vector3Ex.Direction2D(aIPoint2.transform.position, currentPos));
            num3 += Mathf.InverseLerp(-1f, 1f, value) * 100f;
            if (!aIPoint2.InUse())
            {
                num3 += 1000f;
            }
            num3 += (1f - Mathf.InverseLerp(1f, 10f, num2)) * 100f;
            float num4 = Vector3.Distance(currentPos, aIPoint2.transform.position);
            if (num4 <= 1f)
            {
                num3 -= 3000f;
            }
            if (flag)
            {
                float num5 = Vector3.Distance(anchorPos, aIPoint2.transform.position);
                if (num5 <= clampDistance)
                {
                    num3 += 1000f;
                    num3 += (1f - Mathf.InverseLerp(0f, clampDistance, num5)) * 200f * Random.Range(0.8f, 1f);
                }
            }
            else if (num4 > 3f)
            {
                num3 += Mathf.InverseLerp(3f, lookupMaxRange, num4) * 50f;
            }
            if (num3 > num)
            {
                aIPoint = aIPoint2;
                num     = num3;
            }
        }
        return(aIPoint as AIMovePoint);
    }
Exemplo n.º 23
0
        public override void StateThink(float delta)
        {
            base.StateThink(delta);
            float num1 = 2f;
            float num2 = 0.0f;

            if ((double)Time.get_time() > (double)this.lastCoverTime + (double)num1 && !this.isFleeing)
            {
                Vector3           hideFromPosition = Object.op_Implicit((Object)this.GetEntity().currentTarget) ? this.GetEntity().currentTarget.ServerPosition : Vector3.op_Addition(this.GetEntity().ServerPosition, Vector3.op_Multiply(this.GetEntity().LastAttackedDir, 30f));
                float             num3             = Object.op_Inequality((Object)this.GetEntity().currentTarget, (Object)null) ? this.GetEntity().DistanceToTarget() : 30f;
                AIInformationZone informationZone  = this.GetEntity().GetInformationZone();
                if (Object.op_Inequality((Object)informationZone, (Object)null))
                {
                    float        secondsSinceAttacked = this.GetEntity().SecondsSinceAttacked;
                    float        minRange             = (double)secondsSinceAttacked < 2.0 ? 2f : 0.0f;
                    float        maxRange             = 20f;
                    AICoverPoint bestCoverPoint       = informationZone.GetBestCoverPoint(this.GetEntity().ServerPosition, hideFromPosition, minRange, maxRange, (BaseEntity)this.GetEntity());
                    if (Object.op_Implicit((Object)bestCoverPoint))
                    {
                        bestCoverPoint.SetUsedBy((BaseEntity)this.GetEntity(), 5f);
                    }
                    Vector3 newDestination = Object.op_Equality((Object)bestCoverPoint, (Object)null) ? this.GetEntity().ServerPosition : ((Component)bestCoverPoint).get_transform().get_position();
                    this.GetEntity().SetDestination(newDestination);
                    float  num4   = Vector3.Distance(newDestination, this.GetEntity().ServerPosition);
                    double target = (double)this.GetEntity().DistanceToTarget();
                    int    num5   = (double)secondsSinceAttacked >= 4.0 ? 0 : ((double)this.GetEntity().AmmoFractionRemaining() <= 0.25 ? 1 : 0);
                    int    num6   = (double)this.GetEntity().healthFraction >= 0.5 || (double)secondsSinceAttacked >= 1.0 ? 0 : ((double)Time.get_time() > (double)num2 ? 1 : 0);
                    if ((double)num3 > 6.0 && (double)num4 > 6.0 || Object.op_Equality((Object)this.GetEntity().currentTarget, (Object)null))
                    {
                        this.isFleeing = true;
                        float num7 = Time.get_time() + Random.Range(4f, 7f);
                    }
                    if ((double)num4 > 1.0)
                    {
                        this.GetEntity().ClearStationaryAimPoint();
                    }
                }
                this.lastCoverTime = Time.get_time();
            }
            bool flag = (double)Vector3.Distance(this.GetEntity().ServerPosition, this.GetEntity().finalDestination) <= 0.25;

            if (!this.inCover & flag)
            {
                if (this.isFleeing)
                {
                    this.GetEntity().SetStationaryAimPoint(Vector3.op_Addition(this.GetEntity().finalDestination, Vector3.op_Multiply(Vector3.op_UnaryNegation(this.GetEntity().eyes.BodyForward()), 5f)));
                }
                else if (Object.op_Implicit((Object)this.GetEntity().currentTarget))
                {
                    this.GetEntity().SetStationaryAimPoint(Vector3.op_Addition(this.GetEntity().ServerPosition, Vector3.op_Multiply(Vector3Ex.Direction2D(this.GetEntity().currentTarget.ServerPosition, this.GetEntity().ServerPosition), 5f)));
                }
            }
            this.inCover = flag;
            if (this.inCover)
            {
                this.timeInCover += delta;
            }
            else
            {
                this.timeInCover = 0.0f;
            }
            this.GetEntity().SetDucked(this.inCover);
            if (this.inCover)
            {
                this.isFleeing = false;
            }
            if (((double)this.GetEntity().AmmoFractionRemaining() == 0.0 || this.isFleeing ? 1 : (this.GetEntity().CanSeeTarget() || !this.inCover || (double)this.GetEntity().SecondsSinceDealtDamage <= 2.0 ? 0 : ((double)this.GetEntity().AmmoFractionRemaining() < 0.25 ? 1 : 0))) != 0)
            {
                this.GetEntity().AttemptReload();
            }
            if (this.inCover)
            {
                return;
            }
            if ((double)this.TimeInState() > 1.0 && this.isFleeing)
            {
                this.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            }
            else
            {
                this.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Walk);
            }
        }