123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityGameFramework.Runtime;
- using GameFramework.Event;
- using BattleDefine;
- /// <summary>
- /// 描述:
- /// 作者:WJ
- /// </summary>
- public class AIManager : MonoBehaviour
- {
- /// <summary>
- /// 单键
- /// </summary>
- private static AIManager m_Instance;
- /// <summary>
- /// 刷怪点MO
- /// </summary>
- private Dictionary<int, WJBirthPointMo> mPointMos = new Dictionary<int, WJBirthPointMo>();
- /// <summary>
- /// 近战攻击角色
- /// </summary>
- private List<Role> mNearAttackRoles = new List<Role>();
- /// <summary>
- /// 远程攻击角色
- /// </summary>
- private List<Role> mFarAttackRoles = new List<Role>();
- private List<SceneEventAreaLockLogic> mAreaLocks = new List<SceneEventAreaLockLogic>();
- /// <summary>
- /// 当前所在刷怪点索引
- /// </summary>
- public int mCurPoint = 0;
- public Transform playerPoint;
- /// <summary>
- /// 检测朝玩家移动
- /// </summary>
- private bool mCheckMoveToPlayer = true;
- /// <summary>
- /// 单键
- /// </summary>
- public static AIManager Instance
- {
- get
- {
- if (m_Instance == null)
- {
- m_Instance = GameObject.Find("AIManager").AddComponent<AIManager>();
- }
- return m_Instance;
- }
- }
- /// <summary>
- /// 初始化
- /// </summary>
- public void Init()
- {
- mPointMos.Clear();
- // 关卡数据
- sm_gate gateMo = sm_gate.GetMoById(GameDateManager.Instance.GateID);
- // 出生点
- playerPoint = this.transform.Find("Area1/0");
- // 刷怪点数据
- List<sm_gatelevel> levels = gateMo.GetMonsterLevels();
- for (int i = 0; i < levels.Count; i++)
- {
- Transform tran = transform.Find("Area1/" + (i + 1).ToString());
- if (tran)
- {
- WJBirthPointMo pointMO = new WJBirthPointMo();
- pointMO.point = i + 1;
- pointMO.pointTran = tran;
- pointMO.monsters = levels[i].GetMonsterList();
- pointMO.bossID = levels[i].boss1;
- if(tran.CompareTag("NoRandom"))
- {
- pointMO.randomPos = false;
- }
- mPointMos.Add(i + 1, pointMO);
- }
- }
- // 创建怪物
-
- switch((EBattleSceneType)int.Parse(gateMo.battleType))
- {
- case EBattleSceneType.EBattleType_Default:
- while (CreateNextPointMonster(Vector3.zero))
- {
- }
- break;
- case EBattleSceneType.EBattleType_Boss:
- CreatPointMonster(1, Vector3.zero);
- break;
- case EBattleSceneType.EBattleType_Guide:
- CreatPointMonster(1, Vector3.zero);
- break;
- case EBattleSceneType.EBattleType_Arena:
- break;
- case EBattleSceneType.EBattleType_Safe:
- break;
- }
- }
- public Transform GetPlayerCreatePoint()
- {
- return GameObject.Find("AIManager/Area1/0").transform;
- }
- public Transform GetPointMOByIndex(int index)
- {
- return playerPoint;
- }
- /// <summary>
- /// 创建怪物点
- /// </summary>
- public bool CreatPointMonster(int point, Vector3 livePos)
- {
- if (mPointMos.ContainsKey(point))
- {
- mCurPoint = point;
- // 怪物
- for (int i = 0; i < mPointMos[point].monsters.Count; i++)
- {
- if (livePos == Vector3.zero)
- {
- livePos = mPointMos[point].pointTran.position;
- }
- float radius = mPointMos[point].randomDis;
- // 在出生位置小范围随机
- if (mPointMos[point].randomPos)
- {
- livePos += new Vector3(Random.Range(-radius, radius), 0, Random.Range(-radius, radius));
- }
- //if (mPointMos[point].monsters[i].heroId == mPointMos[point].bossID)
- //{
- // RoleManager.Instance.CreateMonster(point, mPointMos[point].monsters[i], null, livePos, livePos, radius, true);
- //}
- //else
- //{
- // RoleManager.Instance.CreateMonster(point, mPointMos[point].monsters[i], null, livePos, livePos, radius, false);
- //}
- }
- EventComponent nowEvent = GameEntry.GetComponent<EventComponent>();
- nowEvent.FireNow(this, new NoviceEventSpawnerIndex(point));
- mCheckMoveToPlayer = true;
- return true;
- }
- return false;
- }
- /// <summary>
- /// 获取场景所有怪物数量
- /// </summary>
- /// <returns></returns>
- public int GetMonsterMaxNumber()
- {
- int nodeIndex = 1;
- int maxNumber = 0;
- foreach (var item in mPointMos)
- {
- maxNumber += GetPointMonsterNumber(nodeIndex);
- }
- return maxNumber;
- }
- /// <summary>
- /// 获取单一出生点 怪物数量
- /// </summary>
- /// <param name="point"></param>
- /// <returns></returns>
- public int GetPointMonsterNumber(int point)
- {
- int number = 0;
- if (mPointMos.ContainsKey(point))
- {
- number += mPointMos[point].monsters.Count;
- }
- return number;
- }
- /// <summary>
- /// 创建下一个怪物点
- /// </summary>
- /// <returns>是否创建成功</returns>
- public bool CreateNextPointMonster(Vector3 livePos)
- {
- mCurPoint++;
- if (mPointMos.ContainsKey(mCurPoint))
- {
- // 解除区域限制
- RemoveAreaLockCmpt(mCurPoint);
- return CreatPointMonster(mCurPoint, livePos);
- }
- return false;
- }
- /// <summary>
- /// 添加禁止区域
- /// </summary>
- /// <param name="al"></param>
- public void AddAreaLockCmpt(SceneEventAreaLockLogic al)
- {
- mAreaLocks.Add(al);
- }
- public SceneEventAreaLockLogic GetAreaLockCmpt(int id)
- {
- foreach(var item in mAreaLocks)
- {
- if(item.areaIndex == id)
- {
- return item;
- }
- }
- return null;
- }
- /// <summary>
- /// 移除禁止区域
- /// </summary>
- /// <param name="index"></param>
- public void RemoveAreaLockCmpt(int index)
- {
- foreach(var item in mAreaLocks)
- {
- if(item.areaIndex == index)
- {
- item.AreaUnlock();
- mAreaLocks.Remove(item);
- UI_TipsWindow.InitFloatWaringDialog("前方结界屏障已消失,可以通行!");
- break;
- }
- }
- }
- }
- /// <summary>
- /// 怪物出生点MO
- /// </summary>
- public class WJBirthPointMo
- {
- /// <summary>
- /// 怪物
- /// </summary>
- public List<sm_hero> monsters;
- /// <summary>
- /// BOSS ID
- /// </summary>
- public int bossID = 0;
- /// <summary>
- /// 出生点
- /// </summary>
- public int point = 0;
- /// <summary>
- /// 是否小范围随机
- /// </summary>
- public bool randomPos = true;
- /// <summary>
- /// 随机的距离
- /// </summary>
- public float randomDis = 5.0f;
- /// <summary>
- /// 点坐标
- /// </summary>
- public Transform pointTran = null;
- }
|