Ejemplo n.º 1
0
        public void Load(int index)
        {
            for (int i = 0; i < this.m_Members.Count; i++)
            {
                if (this.m_Members[i] != null)
                {
                    this.m_AllObjects.Remove(this.m_Members[i].gameObject);
                    UnityEngine.Object.Destroy(this.m_Members[i].gameObject);
                }
            }
            this.m_Members.Clear();
            int num = SaveGame.LoadIVal("HAGroupCount" + index);

            for (int j = 0; j < num; j++)
            {
                AI.AIID    aiid       = (AI.AIID)Enum.Parse(typeof(AI.AIID), SaveGame.LoadSVal("HAGroupID" + j.ToString() + "_" + index.ToString()));
                Vector3    position   = SaveGame.LoadV3Val("HAGroupPos" + j.ToString() + "_" + index.ToString());
                Quaternion rotation   = SaveGame.LoadQVal("HAGroupRot" + j.ToString() + "_" + index.ToString());
                GameObject prefab     = GreenHellGame.Instance.GetPrefab(aiid.ToString());
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(prefab, position, rotation, base.transform);
                HumanAI    component  = gameObject.GetComponent <HumanAI>();
                this.AddAI(component);
            }
            this.Deactivate();
        }
Ejemplo n.º 2
0
        public override void Start()
        {
            base.Start();
            HumanAI humanAI = (HumanAI)this.m_AI;

            this.m_Animation = "Switch";
            if (humanAI.m_CurrentWeapon.m_Info.IsBow())
            {
                this.m_Animation += "Bow";
            }
            else if (humanAI.m_CurrentWeapon.m_Info.IsKnife())
            {
                this.m_Animation += "Knife";
            }
            else
            {
                DebugUtils.Assert(DebugUtils.AssertType.Info);
            }
            this.m_Animation += "To";
            Item item = (!(humanAI.m_CurrentWeapon == humanAI.m_PrimaryWeapon)) ? humanAI.m_PrimaryWeapon : humanAI.m_SecondaryWeapon;

            if (item.m_Info.IsBow())
            {
                this.m_Animation += "Bow";
            }
            else if (item.m_Info.IsKnife())
            {
                this.m_Animation += "Knife";
            }
            else
            {
                DebugUtils.Assert(DebugUtils.AssertType.Info);
            }
        }
Ejemplo n.º 3
0
 protected virtual void InitObjects()
 {
     for (int i = 0; i < base.transform.childCount; i++)
     {
         GameObject gameObject = base.transform.GetChild(i).gameObject;
         HumanAI    component  = gameObject.GetComponent <HumanAI>();
         if (component)
         {
             this.AddAI(component);
         }
         else
         {
             Item component2 = gameObject.GetComponent <Item>();
             if (component2)
             {
                 component2.m_Group = this;
                 component2.ItemsManagerUnregister();
             }
             this.m_AllObjects.Add(gameObject);
         }
         gameObject.SetActive(this.m_Active);
     }
     if (this.m_Members.Count == 0)
     {
         UnityEngine.Object.Destroy(base.gameObject);
         DebugUtils.Assert("HumanAIGroup does not contains any AI!", true, DebugUtils.AssertType.Info);
     }
 }
Ejemplo n.º 4
0
        private void OnEnterUpsetState()
        {
            int     index   = UnityEngine.Random.Range(0, this.m_Members.Count);
            HumanAI humanAI = this.m_Members[index];

            humanAI.SetState(HumanAI.State.Upset);
        }
Ejemplo n.º 5
0
 public virtual void AddAI(HumanAI ai)
 {
     ai.gameObject.SetActive(true);
     ai.m_Group = this;
     this.m_Members.Add(ai);
     this.m_AllObjects.Add(ai.gameObject);
 }
Ejemplo n.º 6
0
        public bool GivePlayerDamage()
        {
            bool  result = false;
            float num    = (!Player.Get()) ? float.MaxValue : Player.Get().transform.position.Distance(this.m_AI.transform.position);
            float num2   = this.m_AI.m_Params.m_AttackRange;

            if (AI.IsSnake(this.m_AI.m_ID))
            {
                num2 *= 1.5f;
            }
            if (num <= num2)
            {
                Vector3    hit_dir    = Player.Get().transform.position + Vector3.up * Player.Get().GetComponent <CharacterController>().height * 0.5f - this.m_AI.transform.position;
                float      damage     = this.m_AI.m_Params.m_Damage;
                DamageType damageType = this.m_AI.m_Params.m_DamageType;
                HumanAI    humanAI    = (!this.m_AI.IsHuman()) ? null : ((HumanAI)this.m_AI);
                if (humanAI)
                {
                    Weapon weapon = (Weapon)humanAI.m_CurrentWeapon;
                    if (weapon)
                    {
                        damage     = ((WeaponInfo)weapon.m_Info).m_PlayerDamage;
                        damageType = weapon.GetDamageType();
                    }
                }
                float num3         = UnityEngine.Random.Range(0f, 1f);
                bool  critical_hit = num3 < 0.05f * (PlayerConditionModule.Get().GetHP() / PlayerConditionModule.Get().GetMaxHP());
                Player.Get().GiveDamage(base.gameObject, null, damage, hit_dir, damageType, this.m_AI.m_Params.m_PoisonLevel, critical_hit);
                result = true;
            }
            this.m_AI.m_GoalsModule.m_ActiveGoal.m_WasDamage = true;
            return(result);
        }
Ejemplo n.º 7
0
        private void GiveConstructionDamage()
        {
            if (!this.m_AI.IsHuman())
            {
                return;
            }
            HumanAI humanAI = (HumanAI)this.m_AI;

            if (!humanAI.m_SelectedConstruction)
            {
                return;
            }
            Vector3    forward    = humanAI.transform.forward;
            float      damage     = this.m_AI.m_Params.m_Damage;
            DamageType damageType = this.m_AI.m_Params.m_DamageType;
            Weapon     weapon     = (Weapon)humanAI.m_CurrentWeapon;

            if (weapon)
            {
                float playerDamage = ((WeaponInfo)weapon.m_Info).m_PlayerDamage;
                weapon.GetDamageType();
            }
            DamageInfo damageInfo = new DamageInfo();

            damageInfo.m_Damage = 10f;
            humanAI.m_SelectedConstruction.TakeDamage(damageInfo);
        }
Ejemplo n.º 8
0
        private void GiveConstructionDamage()
        {
            if (!this.m_AI.IsHuman())
            {
                return;
            }
            HumanAI humanAI = (HumanAI)this.m_AI;

            if (!humanAI.m_SelectedConstruction)
            {
                return;
            }
            float num = humanAI.m_SelectedConstruction.m_BoxCollider.ClosestPointOnBounds(this.m_AI.transform.position).Distance(this.m_AI.transform.position);

            if (num <= this.m_AI.m_Params.m_AttackRange)
            {
                Vector3    forward    = humanAI.transform.forward;
                float      num2       = this.m_AI.m_Params.m_Damage;
                DamageType damageType = this.m_AI.m_Params.m_DamageType;
                Weapon     weapon     = (Weapon)humanAI.m_CurrentWeapon;
                if (weapon)
                {
                    num2       = ((WeaponInfo)weapon.m_Info).m_PlayerDamage;
                    damageType = weapon.GetDamageType();
                }
                humanAI.m_SelectedConstruction.TakeDamage(10f);
            }
        }
Ejemplo n.º 9
0
 public void OnAIDie(HumanAI ai)
 {
     this.RemovedAI(ai, false);
     foreach (HumanAI humanAI in this.m_Members)
     {
         humanAI.m_EnemyModule.SetEnemy(Player.Get());
     }
 }
Ejemplo n.º 10
0
 public void RemovedAI(HumanAI ai)
 {
     this.m_Members.Remove(ai);
     this.m_AllObjects.Remove(ai.gameObject);
     ai.m_Group          = null;
     ai.transform.parent = null;
     if (this.m_Members.Count == 0)
     {
         this.Deactivate();
     }
 }
Ejemplo n.º 11
0
 public override void AddAI(HumanAI ai)
 {
     base.AddAI(ai);
     ai.m_Patrol = this;
     if (!ai.gameObject.GetComponent <PatrolModule>())
     {
         ai.m_PatrolModule = ai.gameObject.AddComponent <PatrolModule>();
     }
     ai.m_PatrolModule.m_Patrol = this;
     ai.m_PatrolModule.Initialize(ai);
 }
Ejemplo n.º 12
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.º 13
0
        private void TrySpawnDestroyers()
        {
            List <Vector3> list = null;

            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < this.m_Count; j++)
                {
                    Vector3    normalized2D   = UnityEngine.Random.insideUnitSphere.GetNormalized2D();
                    Vector3    sourcePosition = this.m_Construction.transform.position + normalized2D * 10f;
                    NavMeshHit navMeshHit;
                    if (NavMesh.SamplePosition(sourcePosition, out navMeshHit, 2f, AIManager.s_WalkableAreaMask))
                    {
                        sourcePosition = navMeshHit.position;
                        Vector3 sourcePosition2 = this.m_Construction.m_BoxCollider.ClosestPointOnBounds(navMeshHit.position);
                        if (NavMesh.SamplePosition(sourcePosition2, out navMeshHit, 1f, AIManager.s_WalkableAreaMask))
                        {
                            if (NavMesh.CalculatePath(sourcePosition, navMeshHit.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;
            }
            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;
                this.AddAI(component);
            }
            base.Activate();
            this.m_GroupSpawned = true;
        }
Ejemplo n.º 14
0
        protected virtual void UpdateActivity()
        {
            if (this.m_ChallengeGroup)
            {
                return;
            }
            float   maxValue      = float.MaxValue;
            HumanAI closestMember = this.GetClosestMember(out maxValue);

            if (closestMember && maxValue >= HumanAIGroupManager.Get().m_DeactivationDistance)
            {
                this.Deactivate();
            }
        }
Ejemplo n.º 15
0
 public void RemovedAI(HumanAI ai, bool from_destroy)
 {
     this.m_Members.Remove(ai);
     this.m_AllObjects.Remove(ai.gameObject);
     ai.m_Group = null;
     if (!ai.m_IsBeingDestroyed)
     {
         ai.transform.parent = null;
     }
     if (this.m_Members.Count == 0)
     {
         this.Deactivate(from_destroy);
     }
 }
Ejemplo n.º 16
0
 protected override void UpdateCalmSound()
 {
     if (this.m_Members.Count == 0)
     {
         return;
     }
     if (Time.time >= this.m_NextCalmSoundTime)
     {
         HumanAI humanAI = this.m_Members[UnityEngine.Random.Range(0, this.m_Members.Count)];
         this.m_LastCalmClip = humanAI.m_HumanAISoundModule.PlaySound(HumanAISoundModule.SoundType.Scream);
         if (this.m_LastCalmClip)
         {
             this.m_NextCalmSoundTime = Time.time + this.m_LastCalmClip.length + UnityEngine.Random.Range(this.m_MinCalmSoundInterval, this.m_MaxCalmSoundInterval);
         }
     }
 }
Ejemplo n.º 17
0
        private bool CheckGroup(HumanAIGroup group)
        {
            if (group.m_Active)
            {
                return(false);
            }
            float   num           = 0f;
            HumanAI closestMember = group.GetClosestMember(out num);
            bool    flag          = closestMember && num <this.m_MaxActivationDistance && num> this.m_MinActivationDistance;

            if (flag)
            {
                group.Activate();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 18
0
        public HumanAI GetClosestMember(out float distance)
        {
            Vector3 position = Player.Get().transform.position;
            HumanAI result   = null;

            distance = float.MaxValue;
            foreach (HumanAI humanAI in this.m_Members)
            {
                float num = humanAI.transform.position.Distance(position);
                if (num < distance)
                {
                    result   = humanAI;
                    distance = num;
                }
            }
            return(result);
        }
Ejemplo n.º 19
0
        public bool GivePlayerDamage(Vector3 world_hit_dir)
        {
            bool  result = false;
            float num    = Player.Get() ? Player.Get().transform.position.Distance(this.m_AI.transform.position) : float.MaxValue;
            float num2   = this.m_AI.m_Params.m_AttackRange;

            if (AI.IsSnake(this.m_AI.m_ID))
            {
                num2 *= 1.5f;
            }
            if (this.m_AI.m_ID == AI.AIID.BlackCaiman)
            {
                num = Player.Get().transform.position.Distance(this.m_AI.GetHeadTransform().position);
                if (!this.m_AI.IsSwimming() && (this.m_AI.GetHeadTransform().position.y < Player.Get().transform.position.y - 1f || this.m_AI.GetHeadTransform().position.y > Player.Get().GetHeadTransform().position.y + 0.75f))
                {
                    if (this.m_AI.m_GoalsModule.m_ActiveGoal != null)
                    {
                        this.m_AI.m_GoalsModule.m_ActiveGoal.m_WasDamage = true;
                    }
                    return(result);
                }
            }
            if (num <= num2 || this.m_AI.m_ID == AI.AIID.BrasilianWanderingSpider)
            {
                float      damage     = this.m_AI.m_Params.m_Damage;
                DamageType damageType = this.m_AI.m_Params.m_DamageType;
                HumanAI    humanAI    = this.m_AI.IsHuman() ? ((HumanAI)this.m_AI) : null;
                if (humanAI)
                {
                    Weapon weapon = (Weapon)humanAI.m_CurrentWeapon;
                    if (weapon)
                    {
                        damage     = ((WeaponInfo)weapon.m_Info).m_PlayerDamage;
                        damageType = weapon.GetDamageType();
                    }
                }
                bool critical_hit = UnityEngine.Random.Range(0f, 1f) < 0.05f * (PlayerConditionModule.Get().GetHP() / PlayerConditionModule.Get().GetMaxHP());
                Player.Get().GiveDamage(base.gameObject, null, damage, this.m_AI.IsHumanAI() ? UnityEngine.Random.insideUnitSphere : world_hit_dir, damageType, this.m_AI.m_Params.m_PoisonLevel, critical_hit);
                result = true;
            }
            if (this.m_AI.m_GoalsModule.m_ActiveGoal != null)
            {
                this.m_AI.m_GoalsModule.m_ActiveGoal.m_WasDamage = true;
            }
            return(result);
        }
Ejemplo n.º 20
0
 private bool CanSetEnemy(Being being)
 {
     if (being.GetPlayerComponent <ReplicatedPlayerParams>().m_IsInSafeZone)
     {
         return(false);
     }
     if (being.GetPlayerComponent <ReplicatedPlayerParams>().m_IsDead)
     {
         return(false);
     }
     if (this.m_AI.IsHuman())
     {
         HumanAI humanAI = (HumanAI)this.m_AI;
         if ((humanAI.GetState() == HumanAI.State.Attack || humanAI.GetState() == HumanAI.State.StartWave) && this.m_AI.m_EnemyModule.m_Enemy == being)
         {
             return(true);
         }
     }
     if (this.m_AI.m_BleedingDamage > 0f)
     {
         return(true);
     }
     if (this.m_AI.m_SightModule && this.m_AI.m_SightModule.m_VisiblePlayers.Contains(being))
     {
         return(true);
     }
     if (this.m_AI.m_HearingModule && this.m_AI.m_HearingModule.m_Noise != null)
     {
         return(true);
     }
     if (this.m_AI.m_EnemySenseModule && this.m_AI.m_EnemySenseModule.m_Enemies.Contains(being))
     {
         return(true);
     }
     if (this.m_Enemy)
     {
         this.m_SafeDuration += Time.deltaTime;
         float safeDuration     = this.m_SafeDuration;
         float timeToLooseEnemy = this.m_TimeToLooseEnemy;
         return(false);
     }
     return(false);
 }
Ejemplo n.º 21
0
 public void Activate()
 {
     base.gameObject.SetActive(true);
     foreach (GameObject gameObject in this.m_AllObjects)
     {
         gameObject.SetActive(true);
     }
     if (!this.m_ChallengeGroup && this.m_FromBalance)
     {
         int currentGroupMembersCount = EnemyAISpawnManager.Get().GetCurrentGroupMembersCount();
         while (this.m_Members.Count > currentGroupMembersCount)
         {
             HumanAI humanAI = this.m_Members[UnityEngine.Random.Range(0, this.m_Members.Count)];
             this.RemovedAI(humanAI, false);
             UnityEngine.Object.Destroy(humanAI.gameObject);
         }
     }
     this.m_Active = true;
     this.OnActivate();
 }
Ejemplo n.º 22
0
        private void UpdateEnemy()
        {
            if (this.m_AI.IsHuman())
            {
                HumanAI humanAI = (HumanAI)this.m_AI;
                if (humanAI.GetState() == HumanAI.State.Attack || humanAI.GetState() == HumanAI.State.StartWave)
                {
                    this.SetEnemy(true);
                    return;
                }
            }
            if (this.m_AI.m_SightModule && this.m_AI.m_SightModule.m_PlayerVisible)
            {
                this.SetEnemy(true);
                return;
            }
            bool flag = this.m_AI.m_HearingModule && this.m_AI.m_HearingModule.m_Noise != null;

            if (flag)
            {
                this.SetEnemy(true);
                return;
            }
            if (this.m_AI.m_EnemySenseModule && this.m_AI.m_EnemySenseModule.m_Enemy)
            {
                this.SetEnemy(true);
                return;
            }
            if (this.m_Enemy)
            {
                this.m_SafeDuration += Time.deltaTime;
                if (this.m_SafeDuration >= this.m_TimeToLooseEnemy)
                {
                    this.SetEnemy(false);
                }
            }
        }
Ejemplo n.º 23
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;
        }