DressUpObjDataCache.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. using System.Linq;
  5. using FairyGUI;
  6. using ET;
  7. namespace GFGGame
  8. {
  9. public class DressUpObjDataCache
  10. {
  11. private GameObject _sceneObj;
  12. private bool _needSetMask;
  13. public void setSceneObj(GameObject sceneObj, bool needSetMask = false)
  14. {
  15. _sceneObj = sceneObj;
  16. _needSetMask = needSetMask;
  17. }
  18. private int _bgId;
  19. public int bgId
  20. {
  21. get
  22. {
  23. return _bgId;
  24. }
  25. }
  26. private int _suitId;
  27. public int suitId
  28. {
  29. get
  30. {
  31. return _suitId;
  32. }
  33. }
  34. private bool _isPic;
  35. public int picStatus
  36. {
  37. get
  38. {
  39. return _isPic ? 1 : 0;
  40. }
  41. }
  42. private List<int> _equipDatas = new List<int>();
  43. public int[] equipDatas
  44. {
  45. get
  46. {
  47. return _equipDatas.ToArray();
  48. }
  49. }
  50. //角色基础分+部件基础分
  51. private int _score;
  52. public int score
  53. {
  54. get
  55. {
  56. return _score;
  57. }
  58. private set
  59. {
  60. _score = value;
  61. EventAgent.DispatchEvent(ConstMessage.DRESS_UP_SCORE_CHANGED, _score);
  62. }
  63. }
  64. //最终得分
  65. private int _totalScore;
  66. public int totalScore
  67. {
  68. get
  69. {
  70. return _totalScore;
  71. }
  72. set
  73. {
  74. _totalScore = value;
  75. }
  76. }
  77. //战斗对象最终得分
  78. private int _targetTotalScore;
  79. public int npcTotalScore
  80. {
  81. get
  82. {
  83. return _targetTotalScore;
  84. }
  85. set
  86. {
  87. _targetTotalScore = value;
  88. }
  89. }
  90. private bool _autoPlay = false;
  91. public bool autoPlay
  92. {
  93. get
  94. {
  95. return _autoPlay;
  96. }
  97. set
  98. {
  99. _autoPlay = value;
  100. }
  101. }
  102. public int maxFightSpeed = 8;
  103. private int _fightSpeed = 1;
  104. public int fightSpeed
  105. {
  106. get
  107. {
  108. return _fightSpeed;
  109. }
  110. set
  111. {
  112. _fightSpeed = value;
  113. }
  114. }
  115. public void Dispose()
  116. {
  117. _sceneObj = null;
  118. }
  119. private void Add(int value)
  120. {
  121. if (!_equipDatas.Contains(value))
  122. {
  123. _equipDatas.Add(value);
  124. DressUpUtil.AddItem(value, _sceneObj, _needSetMask);
  125. score += DressUpMenuItemDataManager.GetItemScore(value);
  126. }
  127. int dressSuitId = DressUpMenuSuitDataManager.CheckCurDressIsSuit();
  128. if (dressSuitId > 0) _suitId = dressSuitId;
  129. }
  130. private void Remove(int value)
  131. {
  132. if (_equipDatas == null)
  133. {
  134. return;
  135. }
  136. if (_equipDatas.Contains(value))
  137. {
  138. _equipDatas.Remove(value);
  139. DressUpUtil.RemoveItem(value, _sceneObj);
  140. score -= DressUpMenuItemDataManager.GetItemScore(value);
  141. }
  142. }
  143. /// <summary>
  144. /// 仅判断换装部件是否已穿着
  145. /// </summary>
  146. /// <param name="id"></param>
  147. /// <returns></returns>
  148. public bool CheckDressUpItemIsOn(int id)
  149. {
  150. if (id == _bgId)
  151. {
  152. return true;
  153. }
  154. return _equipDatas.Contains(id);
  155. }
  156. /// <summary>
  157. /// 仅判断套装是否穿上
  158. /// </summary>
  159. /// <param name="id"></param>
  160. /// <returns></returns>
  161. public bool CheckSuitIsOn(int id)
  162. {
  163. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
  164. if (suitCfg == null)
  165. {
  166. return false;
  167. }
  168. int[] items = suitCfg.partsArr;
  169. foreach (int itemId in items)
  170. {
  171. bool isOn = CheckDressUpItemIsOn(itemId);
  172. if (!isOn)
  173. {
  174. return false;
  175. }
  176. }
  177. return true;
  178. }
  179. public void AddOrRemove(int value, bool checkDefault, bool isAdd = false, bool isRemove = false)
  180. {
  181. int subType = ItemUtilCS.GetItemSubType(value);
  182. if (subType == ConstDressUpItemType.BEI_JING)
  183. {
  184. _bgId = value;
  185. DressUpUtil.AddItem(_bgId, _sceneObj, _needSetMask);
  186. }
  187. else
  188. {
  189. if (!CheckDressUpItemIsOn(value))
  190. {
  191. if (!isRemove)
  192. {
  193. checkRemoveSameType(subType);
  194. Add(value);
  195. }
  196. }
  197. else
  198. {
  199. if (!isAdd)
  200. {
  201. Remove(value);
  202. }
  203. }
  204. if (checkDefault)
  205. {
  206. checkDefaultItem();
  207. }
  208. }
  209. }
  210. public void checkRemoveSameType(int type)
  211. {
  212. int count = 0;
  213. int firstTeshuId = 0;
  214. for (int i = 0; i < _equipDatas.Count; i++)
  215. {
  216. int itemID = (int)_equipDatas[i];
  217. int subType = ItemUtilCS.GetItemSubType(itemID);
  218. if (subType == type
  219. || (type == ConstDressUpItemType.LIAN_YI_QUN && (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA))
  220. || (type == ConstDressUpItemType.SHANG_YI && subType == ConstDressUpItemType.LIAN_YI_QUN)
  221. || (type == ConstDressUpItemType.XIA_ZHUANG && subType == ConstDressUpItemType.LIAN_YI_QUN)
  222. || (type == ConstDressUpItemType.NEI_DA && subType == ConstDressUpItemType.LIAN_YI_QUN))
  223. {
  224. Remove(itemID);
  225. i--;
  226. }
  227. if (subType > ConstDressUpItemType.TE_SHU)
  228. {
  229. if (count == 0)
  230. {
  231. firstTeshuId = itemID;
  232. }
  233. count++;
  234. }
  235. }
  236. if (type > ConstDressUpItemType.TE_SHU && count >= 3)
  237. {
  238. //特殊饰品最多穿三件,第四件会自动顶掉第一件
  239. Remove(firstTeshuId);
  240. }
  241. }
  242. private void checkDefaultItem()
  243. {
  244. if (!IsSuitPic)
  245. {
  246. //检查默认资源
  247. //是否有头发
  248. bool has1 = false;
  249. //是否有连衣裙
  250. bool has2 = false;
  251. //是否有内搭
  252. bool has3 = false;
  253. //是否有上衣
  254. // bool has4 = false;
  255. //是否有下装
  256. bool has5 = false;
  257. //是否有默认内搭
  258. // bool has30000 = false;
  259. //是否有默认下装
  260. // bool has50000 = false;
  261. for (int i = 0; i < _equipDatas.Count; i++)
  262. {
  263. int itemID = (int)_equipDatas[i];
  264. int subType = ItemUtilCS.GetItemSubType(itemID);
  265. if (subType == (int)ConstDressUpItemType.FA_XING)
  266. {
  267. has1 = true;
  268. }
  269. else if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  270. {
  271. has2 = true;
  272. }
  273. else if (subType == ConstDressUpItemType.NEI_DA)
  274. {
  275. has3 = true;
  276. }
  277. else if (subType == ConstDressUpItemType.XIA_ZHUANG)
  278. {
  279. has5 = true;
  280. }
  281. }
  282. if (!has1)
  283. {
  284. Add(10000);
  285. }
  286. if (!has2)
  287. {
  288. if (!has5)
  289. {
  290. Add(50000);
  291. }
  292. if (!has3)
  293. {
  294. Add(30000);
  295. }
  296. }
  297. }
  298. }
  299. private void UpdatePicAction()
  300. {
  301. if (IsSuitPic)
  302. {
  303. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  304. DressUpUtil.UpdateBody(suitCfg.picRes, _sceneObj, !string.IsNullOrEmpty(suitCfg.aniRes), suitCfg.effRes);
  305. }
  306. else
  307. {
  308. DressUpUtil.UpdateBody(null, _sceneObj, false, null, _needSetMask);
  309. }
  310. }
  311. public void TakeOffAll(bool checkDefault = true)
  312. {
  313. _suitId = 0;
  314. _isPic = false;
  315. // AddOrRemove(propID, false, true);
  316. int[] tempList = equipDatas;
  317. foreach (int itemID in tempList)
  318. {
  319. AddOrRemove(itemID, false, false, true);
  320. }
  321. if (checkDefault)
  322. {
  323. checkDefaultItem();
  324. UpdatePicAction();
  325. }
  326. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  327. score = roleLevelCfg.baseScore;
  328. foreach (int itemId in _equipDatas)
  329. {
  330. score += DressUpMenuItemDataManager.GetItemScore(itemId);
  331. }
  332. }
  333. public void ChangeAction()
  334. {
  335. if (!HasSuitPicRes)
  336. {
  337. return;
  338. }
  339. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  340. _isPic = !_isPic;
  341. if (_isPic)
  342. {
  343. int[] tempList = equipDatas;
  344. foreach (int itemID in tempList)
  345. {
  346. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  347. {
  348. AddOrRemove(itemID, false, false, true);
  349. }
  350. }
  351. }
  352. else
  353. {
  354. int[] items = suitCfg.partsArr;
  355. foreach (int itemId in items)
  356. {
  357. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemId))
  358. {
  359. AddOrRemove(itemId, false, true);
  360. }
  361. }
  362. }
  363. checkDefaultItem();
  364. UpdatePicAction();
  365. }
  366. public void TryCancelSuit(int itemID)
  367. {
  368. if (_suitId > 0)
  369. {
  370. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  371. {
  372. if (_isPic)
  373. {
  374. ChangeAction();
  375. }
  376. _suitId = 0;
  377. }
  378. }
  379. }
  380. public bool IsSuitPic
  381. {
  382. get
  383. {
  384. return _suitId > 0 && _isPic;
  385. }
  386. }
  387. public bool HasSuitPicRes
  388. {
  389. get
  390. {
  391. if (_suitId > 0)
  392. {
  393. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  394. if (suitCfg.picRes != null && suitCfg.picRes.Length > 0)
  395. {
  396. return true;
  397. }
  398. }
  399. return false;
  400. }
  401. }
  402. public void PutOnSuitCfg(int id, bool checkPic, bool noSceneType, int[] excludeType = null)
  403. {
  404. if (_suitId == id)
  405. {
  406. return;
  407. }
  408. TakeOffAll(false);
  409. _suitId = id;
  410. _isPic = HasSuitPicRes && checkPic;
  411. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  412. List<int> items = new List<int>(suitCfg.partsArr);
  413. if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
  414. {
  415. items.AddRange(suitCfg.partsOptionalArr);
  416. }
  417. int subType = 0;
  418. foreach (int itemID in items)
  419. {
  420. if (DressUpMenuItemDataManager.CheckHasItem(itemID))
  421. {
  422. bool isSceneType = DressUpMenuItemDataManager.CheckIsSceneType(itemID);
  423. subType = ItemUtilCS.GetItemSubType(itemID);
  424. if (!_isPic || isSceneType)
  425. {
  426. if (!noSceneType || !isSceneType)
  427. {
  428. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  429. {
  430. AddOrRemove(itemID, false, true);
  431. }
  432. }
  433. }
  434. }
  435. }
  436. checkDefaultItem();
  437. UpdatePicAction();
  438. }
  439. public void PutOnSuitSaved(int index)
  440. {
  441. TakeOffAll(false);
  442. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  443. if (suitSavedData.bg > 0)
  444. {
  445. AddOrRemove(suitSavedData.bg, false);
  446. }
  447. foreach (int itemID in suitSavedData.equipDatas)
  448. {
  449. AddOrRemove(itemID, false, true);
  450. }
  451. _suitId = suitSavedData.suitId;
  452. _isPic = suitSavedData.pic > 0;
  453. checkDefaultItem();
  454. UpdatePicAction();
  455. }
  456. public void PutOnSuitSavedInFight(int index)
  457. {
  458. TakeOffAll(false);
  459. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  460. if (suitSavedData.suitId > 0)
  461. {
  462. PutOnSuitCfg(suitSavedData.suitId, false, true);
  463. }
  464. else
  465. {
  466. foreach (int itemID in suitSavedData.equipDatas)
  467. {
  468. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  469. {
  470. AddOrRemove(itemID, false, true);
  471. }
  472. }
  473. checkDefaultItem();
  474. }
  475. }
  476. public void PutOnCurrentSuitSaved()
  477. {
  478. PutOnSuitSaved(CustomSuitDataManager.currentIndex);
  479. }
  480. public void PutOnDefaultSuitSaved(bool withBg = true)
  481. {
  482. TakeOffAll(false);
  483. CustomSuitData suitSavedData = CustomSuitDataManager.CreateDefaultSuitData(0);
  484. foreach (int itemID in suitSavedData.equipDatas)
  485. {
  486. AddOrRemove(itemID, false, true);
  487. }
  488. if (withBg)
  489. {
  490. if (suitSavedData.bg > 0)
  491. {
  492. AddOrRemove(suitSavedData.bg, false);
  493. }
  494. }
  495. checkDefaultItem();
  496. UpdatePicAction();
  497. }
  498. public void PutOnRecommendItems()
  499. {
  500. TakeOffAll(false);
  501. List<int> recommendList = DressUpMenuItemDataManager.GetRecommendItemList();
  502. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  503. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  504. //推荐搭配自动穿必穿品
  505. if (fightCfg.needItemId > 0 && DressUpMenuItemDataManager.CheckHasItem(fightCfg.needItemId) && recommendList.IndexOf(fightCfg.needItemId) < 0)
  506. {
  507. recommendList.Add(fightCfg.needItemId);
  508. }
  509. else if (fightCfg.needSuitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(fightCfg.needSuitId))
  510. {
  511. recommendList.Clear();
  512. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  513. recommendList.AddRange(cfg.partsArr);
  514. }
  515. foreach (int itemID in recommendList)
  516. {
  517. AddOrRemove(itemID, false, true);
  518. }
  519. checkDefaultItem();
  520. UpdatePicAction();
  521. }
  522. public bool CheckEquipedFightNeeded()
  523. {
  524. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  525. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  526. if (fightCfg.needItemId > 0)
  527. {
  528. return CheckDressUpItemIsOn(fightCfg.needItemId);
  529. }
  530. else if (fightCfg.needSuitId > 0)
  531. {
  532. return CheckSuitIsOn(fightCfg.needSuitId);
  533. }
  534. return true;
  535. }
  536. //根据位置原点和随机范围获取评分位置
  537. public void GetCirclePos(Vector2 pos, int range, out float x, out float y)
  538. {
  539. int numX = UnityEngine.Random.Range(0, 2);
  540. int signX = numX % 2 == 0 ? 1 : -1;
  541. float rangeX = UnityEngine.Random.Range(0, range);
  542. x = pos.x + signX * (rangeX);
  543. int numY = UnityEngine.Random.Range(0, 2);
  544. int signY = numY % 2 == 0 ? 1 : -1;
  545. float rangeY = UnityEngine.Random.Range(0, range);
  546. y = pos.y + signY * (rangeY);
  547. }
  548. }
  549. }