Ejemplo n.º 1
0
    private void SetupHookInWaterPos()
    {
        if (!this.m_Hook)
        {
            return;
        }
        float terrainY = MainLevel.GetTerrainY(this.m_FloatPos);

        if (terrainY >= this.m_FloatPos.y)
        {
            DebugUtils.Assert("[FishingRod:OnEnterState] Float is under terrain!", true, DebugUtils.AssertType.Info);
        }
        Vector3 floatPos = this.m_FloatPos;

        if (this.m_FishTank)
        {
            floatPos.y = this.m_FishTank.transform.position.y;
        }
        if (floatPos.y < terrainY + 0.2f)
        {
            floatPos.y = terrainY + 0.2f;
        }
        floatPos.y = Mathf.Min(floatPos.y, this.m_FloatPos.y);
        this.m_Hook.transform.position = floatPos;
        this.m_HookInWaterPos          = floatPos;
    }
Ejemplo n.º 2
0
        protected virtual bool SetupPath()
        {
            Vector3 a            = Vector3.zero;
            Vector3 normalized2D = (this.m_AI.transform.position - Player.Get().transform.position).GetNormalized2D();

            if (this.m_Direction == Direction.Right)
            {
                a = Vector3.Cross(Vector3.up, normalized2D);
            }
            else
            {
                a = Vector3.Cross(normalized2D, Vector3.up);
            }
            for (int i = 0; i < 10; i++)
            {
                Vector3 vector = Player.Get().transform.position + normalized2D * this.m_Range + a * 5f;
                vector.y = MainLevel.GetTerrainY(vector);
                NavMeshHit navMeshHit;
                if (NavMesh.SamplePosition(vector, out navMeshHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(this.m_AI.m_PathModule.m_Agent.nextPosition, navMeshHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                {
                    this.m_AI.m_PathModule.m_Agent.SetPath(this.m_TempPath);
                    return(true);
                }
                this.m_Range += this.ADD_RANGE;
            }
            this.m_AI.m_PerformEmergency = true;
            return(false);
        }
Ejemplo n.º 3
0
        private void AllignToTerrain()
        {
            Vector3 position = base.transform.position;

            position.y = MainLevel.GetTerrainY(position);
            base.transform.position = position;
            if (base.IsVisible())
            {
                Vector3 normalized2D = base.transform.forward.GetNormalized2D();
                Vector3 vector       = this.m_BoxCollider.bounds.center + normalized2D * this.m_BoxCollider.size.z + Vector3.up * this.m_BoxCollider.size.y;
                vector.y = MainLevel.GetTerrainY(vector);
                Vector3 vector2 = this.m_BoxCollider.bounds.center - normalized2D * this.m_BoxCollider.size.z + Vector3.up * this.m_BoxCollider.size.y;
                vector2.y = MainLevel.GetTerrainY(vector2);
                Vector3 vector3       = vector - vector2;
                Vector3 normalized2D2 = base.transform.right.GetNormalized2D();
                Vector3 vector4       = this.m_BoxCollider.bounds.center + normalized2D2 * this.m_BoxCollider.size.x + Vector3.up * this.m_BoxCollider.size.y;
                vector4.y = MainLevel.GetTerrainY(vector4);
                Vector3 vector5 = this.m_BoxCollider.bounds.center - normalized2D2 * this.m_BoxCollider.size.x + Vector3.up * this.m_BoxCollider.size.y;
                vector5.y = MainLevel.GetTerrainY(vector5);
                Vector3 vector6 = vector4 - vector5;
                Vector3 vector7 = Vector3.Cross(vector3.normalized, vector6.normalized);
                if (!vector7.IsZero())
                {
                    base.transform.rotation = Quaternion.Slerp(base.transform.rotation, Quaternion.LookRotation(vector3.normalized, vector7.normalized), 1f);
                }
            }
        }
Ejemplo n.º 4
0
    private Vector3?GetPosition(AmbientSounds.AmbientDefinition def)
    {
        if (def.m_DistanceMin > 0f)
        {
            switch (def.m_Position)
            {
            case AmbientSounds.EAmbientPositionType.Ground:
            {
                Vector3 randomPos2D = this.GetRandomPos2D(def);
                randomPos2D.y = MainLevel.GetTerrainY(randomPos2D);
                break;
            }

            case AmbientSounds.EAmbientPositionType.Bush:
                return(this.GetTagBasedPos(def));

            case AmbientSounds.EAmbientPositionType.HighInAir:
                this.GetRandomPos2D(def).y += UnityEngine.Random.Range(10f, 30f);
                break;

            case AmbientSounds.EAmbientPositionType.TreeTops:
            {
                Vector3?tagBasedPos = this.GetTagBasedPos(def);
                if (tagBasedPos != null)
                {
                    Vector3 value = tagBasedPos.Value;
                    value.y += this.m_AmbientSounds.m_BigTreeAdditionalY;
                    return(new Vector3?(value));
                }
                break;
            }
            }
        }
        return(null);
    }
Ejemplo n.º 5
0
        public Vector3 GetRandomPointInTankSpace(bool check_terrain = true, float range = 0.5f)
        {
            Vector3 vector = Vector3.zero;
            int     num    = 10000;
            bool    flag   = false;
            int     num2   = 0;

            while (num2 < num && !flag)
            {
                vector.x = UnityEngine.Random.Range(-range, range);
                vector.y = UnityEngine.Random.Range(-range, range);
                vector.z = UnityEngine.Random.Range(-range, range);
                vector   = base.gameObject.transform.TransformPoint(vector);
                if (check_terrain)
                {
                    float terrainY = MainLevel.GetTerrainY(vector);
                    flag = (terrainY < vector.y);
                }
                else
                {
                    flag = true;
                }
                num2++;
            }
            if (!flag)
            {
                return(base.transform.position);
            }
            return(vector);
        }
Ejemplo n.º 6
0
 private void Start()
 {
     if (MainLevel.GetTerrainY(base.transform.position) >= this.m_BoxCollider.bounds.max.y)
     {
         base.enabled = false;
         DebugUtils.Assert(false, "[FishTank::Start] Fish tank " + base.name + " is under terrain!", true, DebugUtils.AssertType.Info);
         return;
     }
 }
Ejemplo n.º 7
0
 protected override void UpdateSwimState()
 {
     base.UpdateSwimState();
     this.UpdateBlend();
     if (Time.time - this.m_LastIdleTime > 60f && base.transform.position.y - MainLevel.GetTerrainY(base.transform.position) <= 0f)
     {
         base.SetState(Fish.State.Idle);
     }
 }
Ejemplo n.º 8
0
 public void Deconstruct()
 {
     if (this.m_Fulfilled)
     {
         Vector3 position = base.transform.position;
         float   terrainY = MainLevel.GetTerrainY(position);
         position.y = Mathf.Max(position.y, terrainY);
         ItemsManager.Get().CreateItem(this.m_ItemID, true, position, Quaternion.identity);
     }
 }
Ejemplo n.º 9
0
        private void TrySpawnWave()
        {
            Vector3        position = Player.Get().transform.position;
            List <Vector3> list     = null;

            for (int i = 0; i < 20; i++)
            {
                Vector3 insideUnitSphere = UnityEngine.Random.insideUnitSphere;
                Vector3 vector           = position + insideUnitSphere.GetNormalized2D() * UnityEngine.Random.Range(this.m_MinRange, this.m_MaxRange);
                vector.y = MainLevel.GetTerrainY(vector);
                float num = Vector3.Distance(vector, position);
                for (int j = 0; j < this.m_Count; j++)
                {
                    NavMeshHit navMeshHit;
                    if (NavMesh.SamplePosition(vector, out navMeshHit, this.m_MaxSampleRange, AIManager.s_WalkableAreaMask))
                    {
                        if (NavMesh.CalculatePath(navMeshHit.position, position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                        {
                            if (list == null)
                            {
                                list = new List <Vector3>();
                            }
                            list.Add(navMeshHit.position);
                            if (list.Count == this.m_Count)
                            {
                                break;
                            }
                        }
                    }
                }
                if (list != null && list.Count == this.m_Count)
                {
                    break;
                }
            }
            if (list == null || list.Count != this.m_Count)
            {
                return;
            }
            Debug.Log("HumanAIWave - " + list.Count);
            for (int k = 0; k < list.Count; k++)
            {
                GameObject prefab     = GreenHellGame.Instance.GetPrefab((k != 0) ? "Hunter" : "Savage");
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(prefab, list[k], Quaternion.identity);
                gameObject.transform.parent = base.transform;
                HumanAI component = gameObject.GetComponent <HumanAI>();
                component.m_AnimationModule.m_StartFromRandomFrame = true;
                component.m_Hallucination = this.m_Hallucination;
                this.AddAI(component);
            }
            base.Activate();
            this.m_WaveSpawned = true;
        }
Ejemplo n.º 10
0
    private void SpawnStalker()
    {
        Vector3 forward = Camera.main.transform.forward;
        Vector3 vector  = Player.Get().GetHeadTransform().position - forward * this.m_MoveAwayRange;

        vector.y = MainLevel.GetTerrainY(vector);
        NavMeshHit navMeshHit;

        if (NavMesh.SamplePosition(vector, out navMeshHit, this.m_MoveAwayRange / 3f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(vector, Player.Get().transform.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
        {
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.m_StalkerPrefab, vector, Player.Get().transform.rotation);
            this.m_Stalker = gameObject.GetComponent <Stalker>();
        }
    }
Ejemplo n.º 11
0
 private void DebugRender()
 {
     if (!GreenHellGame.DEBUG)
     {
         return;
     }
     for (int i = 1; i < this.m_Agent.path.corners.Length; i++)
     {
         Vector3 vector = this.m_Agent.path.corners[i - 1];
         vector.y = MainLevel.GetTerrainY(vector);
         Vector3 vector2 = this.m_Agent.path.corners[i];
         vector2.y = MainLevel.GetTerrainY(vector2);
         Debug.DrawLine(vector, vector2, Color.blue);
     }
 }
Ejemplo n.º 12
0
        private void AllignToTerrain()
        {
            Vector3 position = this.m_AI.transform.position;

            this.GetRaycastHit(position + Vector3.up * this.m_AI.m_BoxCollider.size.y);
            position.y = Mathf.Max(TransformModule.s_RaycastHit.point.y, MainLevel.GetTerrainY(position));
            this.m_AI.transform.position = position;
            if (this.m_AI.m_Params.m_Human)
            {
                return;
            }
            if (this.m_AI.m_Visible)
            {
                Vector3 normalized2D = this.m_AI.transform.forward.GetNormalized2D();
                Vector3 vector       = this.m_AI.m_BoxCollider.bounds.center + normalized2D * this.m_AI.m_BoxCollider.size.z + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                this.GetRaycastHit(vector);
                vector = TransformModule.s_RaycastHit.point;
                Vector3 vector2 = this.m_AI.m_BoxCollider.bounds.center - normalized2D * this.m_AI.m_BoxCollider.size.z + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                this.GetRaycastHit(vector2);
                vector2 = TransformModule.s_RaycastHit.point;
                Vector3 lhs           = vector - vector2;
                Vector3 normalized2D2 = this.m_AI.transform.right.GetNormalized2D();
                Vector3 vector3       = Vector3.zero;
                if (this.m_AI.m_Params.m_AllignToTerrainFull)
                {
                    Vector3 vector4 = this.m_AI.m_BoxCollider.bounds.center + normalized2D2 * this.m_AI.m_BoxCollider.size.x + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                    this.GetRaycastHit(vector4);
                    vector4 = TransformModule.s_RaycastHit.point;
                    Vector3 vector5 = this.m_AI.m_BoxCollider.bounds.center - normalized2D2 * this.m_AI.m_BoxCollider.size.x + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                    this.GetRaycastHit(vector5);
                    vector5 = TransformModule.s_RaycastHit.point;
                    Vector3 vector6 = vector4 - vector5;
                    vector3 = Vector3.Cross(lhs.normalized, vector6.normalized);
                }
                else
                {
                    vector3 = Vector3.Cross(lhs, normalized2D2);
                }
                if (!vector3.IsZero())
                {
                    this.m_AI.transform.rotation = Quaternion.Slerp(this.m_AI.transform.rotation, Quaternion.LookRotation(lhs.normalized, vector3.normalized), 1f);
                }
            }
            this.m_AI.m_BoxCollider.enabled = true;
        }
Ejemplo n.º 13
0
        public Vector3 GetRandomPointInTankSpace()
        {
            Vector3 vector = Vector3.zero;
            int     num    = 99;

            for (int i = 0; i < num; i++)
            {
                vector.x = UnityEngine.Random.Range(-0.5f, 0.5f);
                vector.y = UnityEngine.Random.Range(-0.5f, 0.5f);
                vector.z = UnityEngine.Random.Range(-0.5f, 0.5f);
                vector   = base.gameObject.transform.TransformPoint(vector);
                if (vector.y >= MainLevel.GetTerrainY(vector))
                {
                    return(vector);
                }
            }
            return(base.transform.position);
        }
Ejemplo n.º 14
0
    private void AllignToTerrain()
    {
        if (!this.m_AllignToTerrain)
        {
            return;
        }
        bool enabled = this.m_BoxCollider.enabled;

        this.m_BoxCollider.enabled = false;
        RaycastHit raycastHit   = default(RaycastHit);
        Vector3    normalized2D = base.transform.forward.GetNormalized2D();
        Vector3    vector       = this.m_BoxCollider.bounds.center + normalized2D * this.m_BoxCollider.size.z + Vector3.up * this.m_BoxCollider.size.y;

        this.GetRaycastHit(vector, ref raycastHit);
        vector = raycastHit.point;
        Vector3 vector2 = this.m_BoxCollider.bounds.center - normalized2D * this.m_BoxCollider.size.z + Vector3.up * this.m_BoxCollider.size.y;

        this.GetRaycastHit(vector2, ref raycastHit);
        vector2 = raycastHit.point;
        Vector3 vector3       = vector - vector2;
        Vector3 normalized2D2 = base.transform.right.GetNormalized2D();
        Vector3 vector4       = Vector3.zero;
        Vector3 vector5       = this.m_BoxCollider.bounds.center + normalized2D2 * this.m_BoxCollider.size.x + Vector3.up * this.m_BoxCollider.size.y;

        this.GetRaycastHit(vector5, ref raycastHit);
        vector5 = raycastHit.point;
        Vector3 vector6 = this.m_BoxCollider.bounds.center - normalized2D2 * this.m_BoxCollider.size.x + Vector3.up * this.m_BoxCollider.size.y;

        this.GetRaycastHit(vector6, ref raycastHit);
        vector6 = raycastHit.point;
        Vector3 vector7 = vector5 - vector6;

        vector4 = Vector3.Cross(vector3.normalized, vector7.normalized);
        if (!vector4.IsZero())
        {
            base.transform.rotation = Quaternion.Slerp(base.transform.rotation, Quaternion.LookRotation(vector3.normalized, vector4.normalized), 1f);
        }
        Vector3 position = base.transform.position;

        this.GetRaycastHit(position + Vector3.up * this.m_BoxCollider.size.y, ref raycastHit);
        position.y = Mathf.Max(raycastHit.point.y, MainLevel.GetTerrainY(position)) + (this.m_BoxCollider.size.y * 0.5f - this.m_BoxCollider.center.y) + 0.1f;
        base.transform.position    = position;
        this.m_BoxCollider.enabled = enabled;
    }
Ejemplo n.º 15
0
        private void GetRaycastHit(Vector3 pos)
        {
            float terrainY = MainLevel.GetTerrainY(pos);

            pos.y = Mathf.Max(pos.y, terrainY + 0.1f);
            int num = Physics.RaycastNonAlloc(pos, -Vector3.up, TransformModule.s_RaycastHitCache, pos.y - terrainY + 0.1f);

            this.m_RaycastOrig = pos;
            Array.Sort <RaycastHit>(TransformModule.s_RaycastHitCache, 0, num, TransformModule.s_DistComparer);
            for (int i = 0; i < num; i++)
            {
                RaycastHit raycastHit = TransformModule.s_RaycastHitCache[i];
                if (!(raycastHit.collider.gameObject == base.gameObject) && !raycastHit.collider.isTrigger && !this.m_LayerMasksToIgnore.Contains(raycastHit.collider.gameObject.layer))
                {
                    TransformModule.s_RaycastHit = raycastHit;
                    return;
                }
            }
        }
Ejemplo n.º 16
0
        private Vector3 GetSpawnPosition()
        {
            int num = 50;

            for (int i = 0; i < num; i++)
            {
                Vector3 randomPositionInside = this.GetRandomPositionInside();
                randomPositionInside.y = MainLevel.GetTerrainY(randomPositionInside);
                if (this.m_Bounds.Contains(randomPositionInside))
                {
                    NavMeshHit navMeshHit;
                    if (NavMesh.SamplePosition(randomPositionInside, out navMeshHit, 2f, AIManager.s_WalkableAreaMask) && this.IsPoisitionAvailable(navMeshHit.position))
                    {
                        return(navMeshHit.position);
                    }
                }
            }
            return(Vector3.zero);
        }
Ejemplo n.º 17
0
 private void UpdateHook()
 {
     if (FishingController.Get().m_State == FishingController.State.Cast || FishingController.Get().m_State == FishingController.State.Aim)
     {
         if (this.m_Hook.gameObject.activeSelf)
         {
             this.m_Hook.gameObject.SetActive(false);
         }
     }
     else if (!this.m_Hook.gameObject.activeSelf)
     {
         this.m_Hook.gameObject.SetActive(true);
     }
     if (this.m_State == FishingRod.State.None && this.m_Hook.gameObject.activeSelf)
     {
         Vector3 vector = this.m_Top.transform.position + Vector3.down * 1f;
         vector.y = Mathf.Max(vector.y, MainLevel.GetTerrainY(vector) + 0.2f);
         this.m_Hook.transform.position = vector;
     }
 }
Ejemplo n.º 18
0
    public Item ReplaceItem()
    {
        if (this.m_Hallucination)
        {
            base.Disappear(true);
            return(null);
        }
        this.OnReplaceItem();
        Vector3 position = base.transform.position;

        position.y = Mathf.Max(MainLevel.GetTerrainY(position), position.y);
        Item result = ItemsManager.Get().CreateItem(this.m_ReplaceInfo.m_ID, true, position, Quaternion.identity);

        if (!this.m_IsThisUnlimited)
        {
            base.TryRemoveFromFallenObjectsMan();
            this.ReplRequestOwnership(false);
            UnityEngine.Object.Destroy(base.gameObject);
        }
        return(result);
    }
Ejemplo n.º 19
0
    private void GetRaycastHit(Vector3 pos, ref RaycastHit hit)
    {
        pos.y = Mathf.Max(pos.y, MainLevel.GetTerrainY(pos) + 0.1f);
        RaycastHit[] collection = Physics.RaycastAll(pos, -Vector3.up);
        this.m_RaycastOrig = pos;
        List <RaycastHit> list = new List <RaycastHit>(collection);

        list.Sort(new Comparison <RaycastHit>(this.CompareListByDist));
        foreach (RaycastHit raycastHit in list)
        {
            if (!(raycastHit.collider.gameObject == base.gameObject))
            {
                if (!raycastHit.collider.isTrigger)
                {
                    if (!this.m_LayerMasksToIgnore.Contains(raycastHit.collider.gameObject.layer))
                    {
                        hit = raycastHit;
                        break;
                    }
                }
            }
        }
    }
Ejemplo n.º 20
0
    private void SetupHookInWaterPos()
    {
        Ray ray = new Ray(this.m_FloatPos + Vector3.up * 0.1f, Vector3.down);

        RaycastHit[]      collection = Physics.RaycastAll(ray);
        List <RaycastHit> list       = new List <RaycastHit>(collection);
        FishTank          fishTank   = null;
        Vector3           vector     = Vector3.zero;

        foreach (RaycastHit raycastHit in list)
        {
            fishTank = raycastHit.collider.gameObject.GetComponent <FishTank>();
            if (fishTank)
            {
                vector = raycastHit.point;
                break;
            }
        }
        float terrainY = MainLevel.GetTerrainY(this.m_FloatPos);

        if (terrainY >= this.m_FloatPos.y)
        {
            DebugUtils.Assert("[FishingRod:OnEnterState] Float is under terrain!", true, DebugUtils.AssertType.Info);
        }
        Vector3 floatPos = this.m_FloatPos;

        if (fishTank)
        {
            floatPos.y = vector.y - fishTank.m_BoxCollider.size.y * 0.5f;
        }
        if (floatPos.y < terrainY + 0.2f)
        {
            floatPos.y = terrainY + 0.2f;
        }
        floatPos.y = Mathf.Min(floatPos.y, this.m_FloatPos.y);
        this.m_Hook.transform.position = floatPos;
    }
Ejemplo n.º 21
0
 private bool IsTankUnderTerrain()
 {
     return(MainLevel.GetTerrainY(base.transform.position) >= base.transform.position.y);
 }
Ejemplo n.º 22
0
        private bool IsTankUnderTerrain()
        {
            float terrainY = MainLevel.GetTerrainY(base.transform.position);

            return(terrainY >= base.transform.position.y);
        }
Ejemplo n.º 23
0
        private void AllignToTerrain(bool use_temp_transform)
        {
            Vector3 position           = this.m_AI.transform.position;
            bool    autoSyncTransforms = Physics.autoSyncTransforms;

            Physics.autoSyncTransforms = false;
            this.GetRaycastHit(position + Vector3.up * this.m_AI.m_BoxCollider.size.y);
            position.y            = Mathf.Max(TransformModule.s_RaycastHit.point.y, MainLevel.GetTerrainY(position));
            this.m_TempTerrainPos = position;
            if (Time.time - this.m_SwimmingLastTime < 1f)
            {
                float num = (Time.time - this.m_SwimmingLastTime) / 1f;
                this.m_AI.transform.position = this.m_LastPosition * (1f - num) + position * num;
            }
            else
            {
                this.m_AI.transform.position = position;
            }
            if (this.m_AI.m_Params.m_Human)
            {
                Physics.autoSyncTransforms = autoSyncTransforms;
                return;
            }
            if (this.m_AI.IsVisible())
            {
                Vector3 normalized2D = this.m_AI.transform.forward.GetNormalized2D();
                Vector3 vector       = this.m_AI.m_BoxCollider.bounds.center + normalized2D * this.m_AI.m_BoxCollider.size.z + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                this.GetRaycastHit(vector);
                vector = TransformModule.s_RaycastHit.point;
                if (use_temp_transform)
                {
                    this.m_TempTerrainPosFront = vector;
                }
                Vector3 vector2 = this.m_AI.m_BoxCollider.bounds.center - normalized2D * this.m_AI.m_BoxCollider.size.z + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                this.GetRaycastHit(vector2);
                vector2 = TransformModule.s_RaycastHit.point;
                Vector3 lhs           = vector - vector2;
                Vector3 normalized2D2 = this.m_AI.transform.right.GetNormalized2D();
                Vector3 vector3       = Vector3.zero;
                if (this.m_AI.m_Params.m_AllignToTerrainFull)
                {
                    Vector3 vector4 = this.m_AI.m_BoxCollider.bounds.center + normalized2D2 * this.m_AI.m_BoxCollider.size.x + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                    this.GetRaycastHit(vector4);
                    vector4 = TransformModule.s_RaycastHit.point;
                    Vector3 vector5 = this.m_AI.m_BoxCollider.bounds.center - normalized2D2 * this.m_AI.m_BoxCollider.size.x + Vector3.up * this.m_AI.m_BoxCollider.size.y;
                    this.GetRaycastHit(vector5);
                    vector5 = TransformModule.s_RaycastHit.point;
                    Vector3 vector6 = vector4 - vector5;
                    vector3 = Vector3.Cross(lhs.normalized, vector6.normalized);
                }
                else
                {
                    vector3 = Vector3.Cross(lhs, normalized2D2);
                }
                if (!vector3.IsZero())
                {
                    if (use_temp_transform)
                    {
                        this.m_TempTerrainRot = Quaternion.Slerp(this.m_AI.transform.rotation, Quaternion.LookRotation(lhs.normalized, vector3.normalized), 1f);
                    }
                    else
                    {
                        this.m_AI.transform.rotation = Quaternion.Slerp(this.m_AI.transform.rotation, Quaternion.LookRotation(lhs.normalized, vector3.normalized), 1f);
                    }
                }
            }
            Physics.autoSyncTransforms = autoSyncTransforms;
        }
Ejemplo n.º 24
0
 protected virtual bool IsPointInsideTank(Vector3 point)
 {
     return(this.m_Tank && point.y > MainLevel.GetTerrainY(point) && this.m_Tank.IsPointInside(point));
 }
Ejemplo n.º 25
0
        public bool CalcPath(PathModule.PathType path_type)
        {
            if (!this.m_Agent.isActiveAndEnabled || !this.m_Agent.isOnNavMesh)
            {
                return(false);
            }
            this.m_PathValid = false;
            Vector3 vector = Vector3.zero;

            switch (path_type)
            {
            case PathModule.PathType.Loiter:
            {
                Vector3 normalized2D = base.transform.forward.GetNormalized2D();
                for (int i = 0; i < this.m_SafeProbes; i++)
                {
                    if (this.m_AI.m_Spawner != null)
                    {
                        vector = this.m_AI.m_Spawner.GetRandomPositionInside();
                    }
                    else
                    {
                        vector = base.transform.position + Quaternion.AngleAxis(UnityEngine.Random.Range(0f, (i >= this.m_SafeProbes / 2) ? 360f : 120f), Vector3.up) * normalized2D * this.m_Range;
                    }
                    vector.y = MainLevel.GetTerrainY(vector);
                    if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask))
                    {
                        if (NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status != NavMeshPathStatus.PathInvalid)
                        {
                            this.m_Agent.ResetPath();
                            this.m_Agent.SetPath(this.m_TempPath);
                            this.m_PathValid    = true;
                            this.m_CurrPathType = path_type;
                        }
                        break;
                    }
                }
                break;
            }

            case PathModule.PathType.MoveAwayFromEnemy:
            case PathModule.PathType.StalkerRunAway:
            {
                Vector3 vector2 = (base.transform.position - Player.Get().transform.position).GetNormalized2D();
                float   num     = 0f;
                if (this.m_AI.m_ID == AI.AIID.Mouse)
                {
                    this.m_Range = UnityEngine.Random.Range(2f, 4f);
                    num          = UnityEngine.Random.Range(-90f, 90f);
                }
                for (int j = 0; j < this.m_DangerProbes; j++)
                {
                    if (j > 0)
                    {
                        if (j % 2 == 0)
                        {
                            num = -num;
                        }
                        else
                        {
                            num = Mathf.Abs(num) + 360f / (float)this.m_DangerProbes;
                        }
                    }
                    Vector3 b = Quaternion.AngleAxis(num, Vector3.up) * vector2 * this.m_Range;
                    vector   = base.transform.position + b;
                    vector.y = MainLevel.GetTerrainY(vector);
                    if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                    {
                        this.m_Agent.ResetPath();
                        this.m_Agent.SetPath(this.m_TempPath);
                        this.m_PathValid    = true;
                        this.m_CurrPathType = path_type;
                        break;
                    }
                }
                break;
            }

            case PathModule.PathType.MoveToEnemy:
                vector = Player.Get().transform.position;
                if (NavMesh.SamplePosition(vector, out this.m_TempHit, 4f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status != NavMeshPathStatus.PathInvalid)
                {
                    float num2            = 0f;
                    int   cornersNonAlloc = this.m_TempPath.GetCornersNonAlloc(this.m_TempCorners);
                    for (int k = 1; k < cornersNonAlloc; k++)
                    {
                        num2 += this.m_TempPath.corners[k].Distance(this.m_TempPath.corners[k - 1]);
                    }
                    if (num2 > this.m_AI.GetPathPassDistance())
                    {
                        this.m_Agent.ResetPath();
                        this.m_Agent.SetPath(this.m_TempPath);
                        this.m_PathValid    = true;
                        this.m_CurrPathType = path_type;
                    }
                }
                break;

            case PathModule.PathType.MoveAroundEnemy:
            case PathModule.PathType.StalkerMoveAround:
            {
                Vector3 vector3 = this.m_AI.transform.position - Player.Get().transform.position;
                Vector3 vector2 = Vector3.Cross(vector3.GetNormalized2D(), Vector3.up);
                vector   = Player.Get().transform.position + vector3.normalized * StalkerManager.Get().m_MoveAroundRange + vector2 * 3f;
                vector.y = MainLevel.GetTerrainY(vector);
                if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                {
                    this.m_Agent.ResetPath();
                    this.m_Agent.SetPath(this.m_TempPath);
                    this.m_PathValid    = true;
                    this.m_CurrPathType = path_type;
                }
                break;
            }

            case PathModule.PathType.ReturnToSpawner:
                vector   = this.m_AI.m_Spawner.GetRandomPositionInside();
                vector.y = MainLevel.GetTerrainY(vector);
                if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status != NavMeshPathStatus.PathInvalid)
                {
                    this.m_Agent.ResetPath();
                    this.m_Agent.SetPath(this.m_TempPath);
                    this.m_PathValid    = true;
                    this.m_CurrPathType = path_type;
                }
                break;

            case PathModule.PathType.Flank:
                for (int l = 0; l < this.m_StrafeProbes; l++)
                {
                    Vector3 vector2 = UnityEngine.Random.insideUnitCircle * Player.Get().transform.position.Distance2D(this.m_AI.transform.position);
                    vector   = Player.Get().transform.position + vector2;
                    vector.y = MainLevel.GetTerrainY(vector);
                    if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                    {
                        this.m_Agent.ResetPath();
                        this.m_Agent.SetPath(this.m_TempPath);
                        this.m_PathValid    = true;
                        this.m_CurrPathType = path_type;
                        break;
                    }
                }
                break;

            case PathModule.PathType.MoveToBowAttackPos:
            {
                HunterAI hunterAI = (HunterAI)this.m_AI;
                if (!hunterAI)
                {
                    return(this.m_PathValid);
                }
                float   d             = UnityEngine.Random.Range(hunterAI.m_MinBowDistance, hunterAI.m_MaxBowDistance);
                Vector3 normalized2D2 = (base.transform.position - Player.Get().transform.position).GetNormalized2D();
                float   num3          = UnityEngine.Random.Range(-45f, 45f);
                for (int m = 0; m < this.m_DangerProbes; m++)
                {
                    if (m > 0)
                    {
                        if (m % 2 == 0)
                        {
                            num3 = -num3;
                        }
                        else
                        {
                            num3 = Mathf.Abs(num3) + 180f / (float)this.m_DangerProbes;
                        }
                    }
                    Vector3 b2 = Quaternion.AngleAxis(num3, Vector3.up) * normalized2D2 * d;
                    vector   = Player.Get().transform.position + b2;
                    vector.y = MainLevel.GetTerrainY(vector);
                    if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                    {
                        this.m_Agent.ResetPath();
                        this.m_Agent.SetPath(this.m_TempPath);
                        this.m_PathValid    = true;
                        this.m_CurrPathType = path_type;
                        break;
                    }
                }
                break;
            }

            case PathModule.PathType.StrafeLeft:
            {
                Vector3 a = Vector3.Cross((Player.Get().transform.position - base.transform.position).GetNormalized2D(), Vector3.up);
                vector   = base.transform.position + a * UnityEngine.Random.Range(this.m_StrafeRangeMin, this.m_StrafeRangeMax);
                vector.y = MainLevel.GetTerrainY(vector);
                if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                {
                    this.m_Agent.ResetPath();
                    this.m_Agent.SetPath(this.m_TempPath);
                    this.m_PathValid    = true;
                    this.m_CurrPathType = path_type;
                }
                break;
            }

            case PathModule.PathType.StrafeRight:
            {
                Vector3 a2 = Vector3.Cross((Player.Get().transform.position - base.transform.position).GetNormalized2D(), Vector3.down);
                vector   = base.transform.position + a2 * UnityEngine.Random.Range(this.m_StrafeRangeMin, this.m_StrafeRangeMax);
                vector.y = MainLevel.GetTerrainY(vector);
                if (NavMesh.SamplePosition(vector, out this.m_TempHit, 1f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                {
                    this.m_Agent.ResetPath();
                    this.m_Agent.SetPath(this.m_TempPath);
                    this.m_PathValid    = true;
                    this.m_CurrPathType = path_type;
                }
                break;
            }

            case PathModule.PathType.AnimalMoveToEnemy:
                vector = Player.Get().transform.position;
                if (NavMesh.SamplePosition(vector, out this.m_TempHit, 4f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                {
                    float num4             = 0f;
                    int   cornersNonAlloc2 = this.m_TempPath.GetCornersNonAlloc(this.m_TempCorners);
                    for (int n = 1; n < cornersNonAlloc2; n++)
                    {
                        num4 += this.m_TempPath.corners[n].Distance(this.m_TempPath.corners[n - 1]);
                    }
                    if (num4 > this.m_AI.GetPathPassDistance())
                    {
                        this.m_Agent.ResetPath();
                        this.m_Agent.SetPath(this.m_TempPath);
                        this.m_PathValid    = true;
                        this.m_CurrPathType = path_type;
                    }
                }
                break;

            case PathModule.PathType.MoveToConstruction:
                vector = ((HumanAI)this.m_AI).m_SelectedConstruction.m_BoxCollider.ClosestPointOnBounds(((HumanAI)this.m_AI).m_SelectedConstruction.transform.position);
                if (NavMesh.SamplePosition(vector, out this.m_TempHit, 2f, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(base.transform.position, this.m_TempHit.position, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete)
                {
                    float num5             = 0f;
                    int   cornersNonAlloc3 = this.m_TempPath.GetCornersNonAlloc(this.m_TempCorners);
                    for (int num6 = 1; num6 < cornersNonAlloc3; num6++)
                    {
                        num5 += this.m_TempPath.corners[num6].Distance(this.m_TempPath.corners[num6 - 1]);
                    }
                    this.m_Agent.ResetPath();
                    this.m_Agent.SetPath(this.m_TempPath);
                    this.m_PathValid    = true;
                    this.m_CurrPathType = path_type;
                }
                break;
            }
            return(this.m_PathValid);
        }
Ejemplo n.º 26
0
        private void TrySpawnWave()
        {
            this.m_TempPositions.Clear();
            Vector3 position = Player.Get().transform.position;
            Vector3 vector   = Vector3.zero;

            if (position.Distance(base.transform.position) >= EnemyAISpawnManager.s_DeactivationDist)
            {
                vector   = base.transform.position;
                vector.y = MainLevel.GetTerrainY(vector);
            }
            else
            {
                for (int i = 0; i < 20; i++)
                {
                    Vector3 insideUnitSphere = UnityEngine.Random.insideUnitSphere;
                    Vector3 vector2          = base.transform.position + insideUnitSphere.GetNormalized2D() * UnityEngine.Random.Range(this.m_MinRange, this.m_MaxRange);
                    vector2.y = MainLevel.GetTerrainY(vector2);
                    if (position.Distance(vector2) > this.m_MinRange)
                    {
                        vector = vector2;
                        Debug.DrawLine(vector2, vector2 + Vector3.up, Color.blue, 60f);
                        break;
                    }
                }
            }
            if (vector == Vector3.zero)
            {
                return;
            }
            for (int j = 0; j < 20; j++)
            {
                Vector3 insideUnitSphere2 = UnityEngine.Random.insideUnitSphere;
                Vector3 vector3           = vector + insideUnitSphere2.GetNormalized2D() * UnityEngine.Random.Range(1f, 3f);
                vector3.y = MainLevel.GetTerrainY(vector3);
                for (int k = 0; k < this.m_Count; k++)
                {
                    NavMeshHit navMeshHit;
                    if (NavMesh.SamplePosition(vector3, out navMeshHit, this.m_MaxSampleRange, AIManager.s_WalkableAreaMask) && NavMesh.CalculatePath(navMeshHit.position, vector, AIManager.s_WalkableAreaMask, this.m_TempPath) && this.m_TempPath.status == NavMeshPathStatus.PathComplete && !this.IsPositionInWater(navMeshHit.position))
                    {
                        this.m_TempPositions.Add(navMeshHit.position);
                        if (this.m_TempPositions.Count == this.m_Count)
                        {
                            break;
                        }
                    }
                }
                if (this.m_TempPositions.Count == this.m_Count)
                {
                    break;
                }
            }
            if (this.m_TempPositions.Count != this.m_Count)
            {
                return;
            }
            Debug.Log("HumanAIWave - " + this.m_TempPositions.Count);
            for (int l = 0; l < this.m_TempPositions.Count; l++)
            {
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(GreenHellGame.Instance.GetPrefab(this.m_AINames[UnityEngine.Random.Range(0, this.m_AINames.Count)]), this.m_TempPositions[l], Quaternion.identity);
                gameObject.transform.parent = base.transform;
                HumanAI component = gameObject.GetComponent <HumanAI>();
                component.m_AnimationModule.m_StartFromRandomFrame = true;
                component.m_Hallucination = this.m_Hallucination;
                this.AddAI(component);
            }
            base.Activate();
            this.m_WaveSpawned = true;
        }
Ejemplo n.º 27
0
    private void UpdateTransform()
    {
        if (this.UpdateAttaching())
        {
            return;
        }
        this.m_ConstructionToAttachTo      = null;
        base.gameObject.transform.rotation = Player.Get().transform.rotation;
        base.gameObject.transform.Rotate(Vector3.up, this.m_Rotation);
        bool enabled = this.m_BoxCollider.enabled;

        this.m_BoxCollider.enabled = false;
        Vector3 vector = base.gameObject.transform.position;

        vector.y += 5f;
        float terrainY = MainLevel.GetTerrainY(vector);

        if (terrainY >= vector.y)
        {
            vector.y = terrainY;
        }
        else
        {
            float num = float.MinValue;
            foreach (RaycastHit raycastHit in Physics.RaycastAll(vector, -Vector3.up))
            {
                if (!(raycastHit.collider.gameObject.GetComponent <Water>() != null))
                {
                    if (raycastHit.collider.GetType() == typeof(TerrainCollider))
                    {
                        if (raycastHit.point.y > num)
                        {
                            vector = raycastHit.point;
                            num    = raycastHit.point.y;
                        }
                    }
                }
            }
        }
        float num2 = vector.y;

        this.m_BoxCollider.enabled = enabled;
        num2 -= this.m_BoxCollider.bounds.min.y - base.gameObject.transform.position.y;
        Vector3 position     = Player.Get().transform.position;
        Vector3 forward      = Player.Get().transform.forward;
        Vector3 normalized2D = forward.GetNormalized2D();
        Vector3 position2    = position + normalized2D * CJTools.Math.GetProportionalClamp(this.m_PositionOffsetMin, this.m_PositionOffsetMax, Camera.main.transform.forward.y, -0.5f, 0f);

        position2.y = num2;
        base.gameObject.transform.position = position2;
        if (this.UpdateSnapToFirecamp())
        {
            return;
        }
        if (this.UpdateSnapToRack())
        {
            return;
        }
        if (this.UpdateSnapToSmoker())
        {
            return;
        }
        this.AllignToTerrain();
    }