SceneEventNpcLogic.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. using System;
  7. using YLTask;
  8. using TMPro;
  9. public enum NpcInteractiveType
  10. {
  11. Function = 0, // 功能
  12. Main, // 主线
  13. Daily, // 日常
  14. College, // 学院
  15. Wanted, // 悬赏
  16. About, // 关于
  17. Leave // 离开
  18. }
  19. public class NpcInfoVo
  20. {
  21. public NpcInfoVo(int id, Role r)
  22. {
  23. npcId = id;
  24. role = r;
  25. }
  26. public int npcId;
  27. public Role role;
  28. public SceneEventNpcLogic npcLogic;
  29. }
  30. public class SceneEventNpcLogic : MonoBehaviour
  31. {
  32. public GameObject mapIconObj = null;
  33. public SceneEventNpc info = null;
  34. private bool isEntry = false;
  35. Button btnInteractive;
  36. NpcInfoVo npcVo = null;
  37. GameObject signObj = null;
  38. static bool isOpen = false;
  39. Collider nowCollider = null;
  40. private void Awake()
  41. {
  42. isEntry = false;
  43. info = this.gameObject.GetComponent<SceneEventNpc>();
  44. }
  45. // Start is called before the first frame update
  46. void Start()
  47. {
  48. NpcManager.Instance.AddNpcItem(this);
  49. AddNameBillboard();
  50. AddNpcSignToMiniMap(mapIconObj);
  51. RefreshCollider();
  52. }
  53. private void OnEnable()
  54. {
  55. // 解锁状态
  56. int curMapId = UserProxy.Instance.player.newMap.curMapId;
  57. List<string> unlockInfo = MapProxy.Instance.getMapUnlockInfoList(curMapId);
  58. foreach (var item in unlockInfo)
  59. {
  60. string[] unlock = item.Split('_');
  61. if (curMapId != int.Parse(unlock[0]))
  62. {
  63. continue;
  64. }
  65. if (int.Parse(unlock[1]) != (int)(SceneEventExplore.ExploreType.Npc))
  66. {
  67. continue;
  68. }
  69. if (info.npcId == int.Parse(unlock[2]))
  70. {
  71. AnimUnlock();
  72. }
  73. }
  74. }
  75. public void AnimLock()
  76. {
  77. Animator anim = GetComponent<Animator>();
  78. anim.Play("lock", 0);
  79. }
  80. public void AnimUnlock()
  81. {
  82. Animator anim = GetComponent<Animator>();
  83. anim.Play("unlock", 0);
  84. }
  85. public void AddNameBillboard()
  86. {
  87. ResourceHelper.Instance.LoadAssetBundle("NameBillboard", ab =>
  88. {
  89. if (ab != null)
  90. {
  91. GameObject billboard = (GameObject)Instantiate(ab.LoadAsset("NameBillboard"));
  92. billboard.SetActive(true);
  93. billboard.transform.SetParent(this.transform);
  94. billboard.transform.localRotation = Quaternion.identity;
  95. TextMesh tm = billboard.transform.Find("NameBillboard").GetComponent<TextMesh>();
  96. sm_npc npcInfo = sm_npc.GetMoById(info.npcId);
  97. tm.text = npcInfo.name;
  98. }
  99. });
  100. }
  101. public void OnTriggerEnter(Collider collider)
  102. {
  103. nowCollider = null;
  104. if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
  105. {
  106. return;
  107. }
  108. if (isOpen)
  109. {
  110. OnTriggerExit(collider);
  111. }
  112. ////// 移动中不弹窗
  113. ////if (HeroPlayerController.Instance != null && HeroPlayerController.Instance.GetMoveMagnitude() > 0)
  114. ////{
  115. //// return;
  116. ////}
  117. nowCollider = collider;
  118. SetInteractiveBtn();
  119. }
  120. public void RefreshInteractiveIcon(ref UI_BaseMainWindow.InteractiveType ittType)
  121. {
  122. // 添加任务
  123. List<TaskCardVo> taskVos = UserProxy.Instance.player.collectTaskCard.GetActivingCards();
  124. foreach (var item in taskVos)
  125. {
  126. // 当前步骤
  127. List<Ins_TaskStepVo> stepVos = item.curSteps;
  128. foreach (var step in stepVos)
  129. {
  130. if (step.isFinish())
  131. {
  132. continue;
  133. }
  134. if (step.mo().cmd != (int)Enum_TaskCmdType.PlotOver)
  135. {
  136. continue;
  137. }
  138. string[] paramList = step.mo().paras.Split(',');
  139. int stepNpcID = int.Parse(paramList[0]);
  140. int stepStageID = int.Parse(paramList[1]);
  141. int showLevel = 0;
  142. if (stepNpcID != info.npcId)
  143. {
  144. continue;
  145. }
  146. if (item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief)
  147. {
  148. ittType = UI_BaseMainWindow.InteractiveType.NpcTask_Chief;
  149. showLevel = 4;
  150. return;
  151. }
  152. else if(showLevel < 3 && item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Daily)
  153. {
  154. ittType = UI_BaseMainWindow.InteractiveType.NpcTask_Daily;
  155. showLevel = 3;
  156. }
  157. else if (showLevel < 2 && item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_College)
  158. {
  159. ittType = UI_BaseMainWindow.InteractiveType.NpcTask_College;
  160. showLevel = 2;
  161. }
  162. else if (showLevel < 1 && item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Wanted)
  163. {
  164. ittType = UI_BaseMainWindow.InteractiveType.NpcTask_Wanted;
  165. showLevel = 1;
  166. }
  167. }
  168. }
  169. }
  170. public void SetInteractiveBtn()
  171. {
  172. UI_BaseMainWindow.InteractiveType ittType = UI_BaseMainWindow.InteractiveType.NpcDialog;
  173. switch (info.iconType)
  174. {
  175. case SceneEventNpc.NpcIconType.Default:
  176. ittType = UI_BaseMainWindow.InteractiveType.NpcDialog;
  177. break;
  178. case SceneEventNpc.NpcIconType.Store:
  179. ittType = UI_BaseMainWindow.InteractiveType.Grocery;
  180. break;
  181. case SceneEventNpc.NpcIconType.Smithy:
  182. ittType = UI_BaseMainWindow.InteractiveType.Weapon;
  183. break;
  184. case SceneEventNpc.NpcIconType.Storehouse:
  185. ittType = UI_BaseMainWindow.InteractiveType.Storage;
  186. break;
  187. case SceneEventNpc.NpcIconType.Teleporter:
  188. ittType = UI_BaseMainWindow.InteractiveType.Teleport;
  189. break;
  190. case SceneEventNpc.NpcIconType.Reword:
  191. ittType = UI_BaseMainWindow.InteractiveType.Wanted;
  192. break;
  193. case SceneEventNpc.NpcIconType.Email:
  194. ittType = UI_BaseMainWindow.InteractiveType.Email;
  195. break;
  196. case SceneEventNpc.NpcIconType.Ranking:
  197. ittType = UI_BaseMainWindow.InteractiveType.Ranking;
  198. break;
  199. case SceneEventNpc.NpcIconType.Entry:
  200. ittType = UI_BaseMainWindow.InteractiveType.Teleport;
  201. break;
  202. case SceneEventNpc.NpcIconType.Export:
  203. ittType = UI_BaseMainWindow.InteractiveType.Teleport;
  204. break;
  205. }
  206. RefreshInteractiveIcon(ref ittType);
  207. UI_BaseMainWindow.Instance().ShowInteractiveIcon(ittType, (_btn) =>
  208. {
  209. UI_BaseMainWindow.Instance().HideInteractive();
  210. OpenNpcWindow();
  211. });
  212. }
  213. public void OpenNpcWindow()
  214. {
  215. // 唤灵师界面启动时,不开启。
  216. if (UI_NewHeroTeamNewWindow.Instance() != null && UI_NewHeroTeamNewWindow.Instance().gameObject.activeInHierarchy)
  217. {
  218. return;
  219. }
  220. // 唤灵师界面启动时,不开启。
  221. if (UI_YanLingZhaoHuanWindow.Instance() != null && UI_YanLingZhaoHuanWindow.Instance().gameObject.activeInHierarchy)
  222. {
  223. return;
  224. }
  225. // UI_YanLingZhaoHuanWindow
  226. isOpen = true;
  227. HideBattleBtn();
  228. npcVo = new NpcInfoVo(info.npcId, nowCollider.gameObject.GetComponent<Role>());
  229. npcVo.npcLogic = this;
  230. PanelHelper.Instance.ShowPanel("UI_NpcWindow", (GameObject panel) =>
  231. {
  232. }, npcVo);
  233. }
  234. public void OnTriggerExit(Collider collider)
  235. {
  236. if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
  237. {
  238. return;
  239. }
  240. UI_BaseMainWindow.Instance().HideInteractive();
  241. PanelHelper.Instance.ClosePanel("UI_NpcWindow");
  242. ShowBattleBtn();
  243. isOpen = false;
  244. }
  245. public void HideBattleBtn()
  246. {
  247. if (BattleCanvas.Instance)
  248. {
  249. BattleCanvas.Instance.SetSkillButtonSatus(false);
  250. }
  251. }
  252. public void ShowBattleBtn()
  253. {
  254. if (BattleCanvas.Instance)
  255. {
  256. BattleCanvas.Instance.SetSkillButtonSatus(true);
  257. }
  258. }
  259. public void EnableCollider()
  260. {
  261. }
  262. public void OnClickInteractive()
  263. {
  264. isEntry = true;
  265. EventComponent e = GameEntry.GetComponent<EventComponent>();
  266. e.FireNow(this, new BattleEventOpenDialog(info.npcId, info.stageIndex));
  267. UI_BaseMainWindow.Instance().HideInteractive();
  268. }
  269. public void RefreshTaskSign()
  270. {
  271. if (signObj)
  272. {
  273. GameObject.Destroy(signObj);
  274. }
  275. if (mapIconObj)
  276. {
  277. AddNpcSignToMiniMap(mapIconObj);
  278. }
  279. if (BattleCanvas.Instance && BattleCanvas.Instance.mapCmpt)
  280. {
  281. BattleCanvas.Instance.mapCmpt.RemoveNpcArrowTarget(this.gameObject);
  282. }
  283. // 添加任务
  284. List<TaskCardVo> taskVos = TaskProxy.Instance.GetTaskTrackInfo();
  285. foreach (var item in taskVos)
  286. {
  287. DoTrackTaskCard(item);
  288. }
  289. }
  290. /// <summary>
  291. /// 进行一项追踪的任务
  292. /// </summary>
  293. public void DoTrackTaskCard(TaskCardVo vo)
  294. {
  295. // 当前步骤
  296. List<Ins_TaskStepVo> stepVos = vo.curSteps;
  297. for (int i = 0; i < stepVos.Count; ++i)
  298. {
  299. if (stepVos[i].mo().cmd != (int)Enum_TaskCmdType.PlotOver)
  300. {
  301. continue;
  302. }
  303. string[] paramList = stepVos[i].mo().paras.Split(',');
  304. int stepNpcID = int.Parse(paramList[0]);
  305. int stepStageID = int.Parse(paramList[1]);
  306. if (stepNpcID != info.npcId)
  307. {
  308. continue;
  309. }
  310. if (stepVos[i].isFinish())
  311. {
  312. if (BattleCanvas.Instance && BattleCanvas.Instance.mapCmpt)
  313. {
  314. BattleCanvas.Instance.mapCmpt.RemoveNpcArrowTarget(this.gameObject);
  315. }
  316. continue;
  317. }
  318. // 添加领取标志
  319. if (vo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief)
  320. {
  321. // 添加完成标志
  322. if (i >= stepVos.Count - 1)
  323. {
  324. AddTaskCompleteSign();
  325. }
  326. // 添加接取标志
  327. else
  328. {
  329. AddTaskAcceptSign();
  330. }
  331. }
  332. // 添加支线
  333. else
  334. {
  335. // 添加完成标志
  336. if (i >= stepVos.Count - 1)
  337. {
  338. AddTaskCompleteSignBranch();
  339. }
  340. // 添加接取标志
  341. else
  342. {
  343. AddTaskAcceptSignBranch();
  344. }
  345. }
  346. }
  347. }
  348. /// <summary>
  349. /// 添加任务领取标志 主线任务
  350. /// </summary>
  351. public void AddTaskAcceptSign()
  352. {
  353. // 3D场景
  354. ResourceHelper.Instance.LoadAssetBundle("taskSignExclamation", ab =>
  355. {
  356. if (signObj)
  357. {
  358. GameObject.Destroy(signObj);
  359. }
  360. signObj = (GameObject)Instantiate(ab.LoadAsset("taskSignExclamation"));
  361. signObj.transform.parent = this.transform;
  362. signObj.transform.localPosition = new Vector3(0, 2.5f, 0);
  363. });
  364. // 小地图
  365. if (mapIconObj)
  366. {
  367. AddTaskAcceptSignToMiniMap(mapIconObj);
  368. BattleCanvas.Instance.mapCmpt.AddNpcArrowTarget(this.gameObject, () =>
  369. {
  370. AddTaskAcceptSignToMiniMap(mapIconObj);
  371. this.gameObject.SetActive(false);
  372. // Invoke("RefreshCollider", 0.0f);和孟沟通以后,暂时去掉这个任务状态改变后,触发npc窗体的,测试。想法是让玩家手动再触发。
  373. });
  374. }
  375. }
  376. /// <summary>
  377. /// 添加任务完成标志 主线任务
  378. /// </summary>
  379. public void AddTaskCompleteSign()
  380. {
  381. ResourceHelper.Instance.LoadAssetBundle("taskSignQuestion", ab =>
  382. {
  383. if (signObj)
  384. {
  385. GameObject.Destroy(signObj);
  386. }
  387. signObj = Instantiate(ab.LoadAsset("taskSignQuestion")) as GameObject;
  388. if (signObj)
  389. {
  390. signObj.transform.parent = this.transform;
  391. signObj.transform.localPosition = new Vector3(0, 3.2f, 0);
  392. }
  393. });
  394. // 小地图
  395. if (mapIconObj)
  396. {
  397. AddTaskCompleteSignToMiniMap(mapIconObj);
  398. }
  399. }
  400. /// <summary>
  401. /// 添加任务领取标志 分支任务
  402. /// </summary>
  403. public void AddTaskAcceptSignBranch()
  404. {
  405. // 3D场景
  406. ResourceHelper.Instance.LoadAssetBundle("taskSignExclamation", ab =>
  407. {
  408. if (signObj)
  409. {
  410. GameObject.Destroy(signObj);
  411. }
  412. signObj = (GameObject)Instantiate(ab.LoadAsset("taskSignExclamation"));
  413. signObj.transform.parent = this.transform;
  414. signObj.transform.localPosition = new Vector3(0, 2.5f, 0);
  415. });
  416. // 小地图
  417. if (mapIconObj)
  418. {
  419. AddTaskAcceptSignToMiniMapBranch(mapIconObj);
  420. }
  421. }
  422. /// <summary>
  423. /// 添加任务完成标志 分支任务
  424. /// </summary>
  425. public void AddTaskCompleteSignBranch()
  426. {
  427. ResourceHelper.Instance.LoadAssetBundle("taskSignQuestion", ab =>
  428. {
  429. if (signObj)
  430. {
  431. GameObject.Destroy(signObj);
  432. }
  433. signObj = (GameObject)Instantiate(ab.LoadAsset("taskSignQuestion"));
  434. signObj.transform.parent = this.transform;
  435. signObj.transform.localPosition = new Vector3(0, 3.2f, 0);
  436. });
  437. // 小地图
  438. if (mapIconObj)
  439. {
  440. AddTaskCompleteSignToMiniMapBranch(mapIconObj);
  441. }
  442. }
  443. public void RefreshCollider()
  444. {
  445. this.gameObject.SetActive(true);
  446. }
  447. /// <summary>
  448. /// 任务标识
  449. /// </summary>
  450. /// <param name="mapIconObj"></param>
  451. public void AddNpcSignToMiniMap(GameObject mapIconObj)
  452. {
  453. if (mapIconObj == null)
  454. {
  455. return;
  456. }
  457. if (info.iconType == SceneEventNpc.NpcIconType.Default)
  458. {
  459. mapIconObj.transform.Find("npc").gameObject.SetActive(true);
  460. }
  461. else
  462. {
  463. mapIconObj.transform.Find("npc").gameObject.SetActive(false);
  464. }
  465. mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
  466. mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
  467. mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
  468. mapIconObj.transform.Find("taskBE").gameObject.SetActive(false);
  469. }
  470. /// <summary>
  471. /// 任务领取 主线
  472. /// </summary>
  473. /// <param name="mapIconObj"></param>
  474. public void AddTaskAcceptSignToMiniMap(GameObject mapIconObj)
  475. {
  476. mapIconObj.transform.Find("npc").gameObject.SetActive(false);
  477. mapIconObj.transform.Find("taskMS").gameObject.SetActive(true);
  478. mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
  479. mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
  480. mapIconObj.transform.Find("taskBE").gameObject.SetActive(false);
  481. }
  482. /// <summary>
  483. /// 任务完成 主线
  484. /// </summary>
  485. /// <param name="mapIconObj"></param>
  486. public void AddTaskCompleteSignToMiniMap(GameObject mapIconObj)
  487. {
  488. mapIconObj.transform.Find("npc").gameObject.SetActive(false);
  489. mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
  490. mapIconObj.transform.Find("taskME").gameObject.SetActive(true);
  491. mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
  492. mapIconObj.transform.Find("taskBE").gameObject.SetActive(false);
  493. }
  494. /// <summary>
  495. /// 任务领取 支线
  496. /// </summary>
  497. /// <param name="mapIconObj"></param>
  498. public void AddTaskAcceptSignToMiniMapBranch(GameObject mapIconObj)
  499. {
  500. mapIconObj.transform.Find("npc").gameObject.SetActive(false);
  501. mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
  502. mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
  503. mapIconObj.transform.Find("taskBS").gameObject.SetActive(true);
  504. mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
  505. }
  506. /// <summary>
  507. /// 任务完成 支线
  508. /// </summary>
  509. /// <param name="mapIconObj"></param>
  510. public void AddTaskCompleteSignToMiniMapBranch(GameObject mapIconObj)
  511. {
  512. mapIconObj.transform.Find("npc").gameObject.SetActive(false);
  513. mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
  514. mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
  515. mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
  516. mapIconObj.transform.Find("taskBE").gameObject.SetActive(true);
  517. }
  518. }