DressUpObjDataCache.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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 bool picStatus
  36. {
  37. get
  38. {
  39. return _isPic;
  40. }
  41. }
  42. private List<int> _equipDatas = new List<int>();
  43. public List<int> equipDatas
  44. {
  45. get
  46. {
  47. return _equipDatas.ToList();
  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. if (!_autoPlay) fightSpeed = 1;
  101. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY, _autoPlay == true ? 1 : 0).Coroutine();
  102. }
  103. }
  104. public int maxFightSpeed = 8;
  105. private int _fightSpeed = 1;
  106. public int fightSpeed
  107. {
  108. get
  109. {
  110. return _fightSpeed;
  111. }
  112. set
  113. {
  114. _fightSpeed = value;
  115. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED, _fightSpeed).Coroutine();
  116. }
  117. }
  118. public void Dispose()
  119. {
  120. _sceneObj = null;
  121. }
  122. private void Add(int value)
  123. {
  124. if (!_equipDatas.Contains(value))
  125. {
  126. _equipDatas.Add(value);
  127. DressUpUtil.AddItem(value, _sceneObj, _needSetMask);
  128. score += DressUpMenuItemDataManager.GetItemScore(value);
  129. }
  130. int dressSuitId = DressUpMenuSuitDataManager.CheckCurDressIsSuit();
  131. if (dressSuitId > 0) _suitId = dressSuitId;
  132. }
  133. private void Remove(int value)
  134. {
  135. if (_equipDatas == null)
  136. {
  137. return;
  138. }
  139. if (_equipDatas.Contains(value))
  140. {
  141. _equipDatas.Remove(value);
  142. DressUpUtil.RemoveItem(value, _sceneObj);
  143. score -= DressUpMenuItemDataManager.GetItemScore(value);
  144. }
  145. }
  146. /// <summary>
  147. /// 仅判断换装部件是否已穿着
  148. /// </summary>
  149. /// <param name="id"></param>
  150. /// <returns></returns>
  151. public bool CheckDressUpItemIsOn(int id)
  152. {
  153. if (id == _bgId)
  154. {
  155. return true;
  156. }
  157. return _equipDatas.Contains(id);
  158. }
  159. /// <summary>
  160. /// 仅判断套装是否穿上
  161. /// </summary>
  162. /// <param name="id"></param>
  163. /// <returns></returns>
  164. public bool CheckSuitIsOn(int id)
  165. {
  166. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
  167. if (suitCfg == null)
  168. {
  169. return false;
  170. }
  171. int[] items = suitCfg.partsArr;
  172. foreach (int itemId in items)
  173. {
  174. bool isOn = CheckDressUpItemIsOn(itemId);
  175. if (!isOn)
  176. {
  177. return false;
  178. }
  179. }
  180. return true;
  181. }
  182. public void AddOrRemove(int value, bool checkDefault, bool isAdd = false, bool isRemove = false)
  183. {
  184. int subType = ItemUtilCS.GetItemSubType(value);
  185. if (subType == ConstDressUpItemType.BEI_JING)
  186. {
  187. _bgId = value;
  188. DressUpUtil.AddItem(_bgId, _sceneObj, _needSetMask);
  189. }
  190. else
  191. {
  192. if (!CheckDressUpItemIsOn(value))
  193. {
  194. if (!isRemove)
  195. {
  196. checkRemoveSameType(subType);
  197. Add(value);
  198. }
  199. }
  200. else
  201. {
  202. if (!isAdd)
  203. {
  204. Remove(value);
  205. }
  206. }
  207. if (checkDefault)
  208. {
  209. checkDefaultItem();
  210. }
  211. }
  212. }
  213. public void checkRemoveSameType(int type)
  214. {
  215. int count = 0;
  216. int firstTeshuId = 0;
  217. for (int i = 0; i < _equipDatas.Count; i++)
  218. {
  219. int itemID = (int)_equipDatas[i];
  220. int subType = ItemUtilCS.GetItemSubType(itemID);
  221. if (subType == type
  222. || (type == ConstDressUpItemType.LIAN_YI_QUN && (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA))
  223. || (type == ConstDressUpItemType.SHANG_YI && subType == ConstDressUpItemType.LIAN_YI_QUN)
  224. || (type == ConstDressUpItemType.XIA_ZHUANG && subType == ConstDressUpItemType.LIAN_YI_QUN)
  225. || (type == ConstDressUpItemType.NEI_DA && subType == ConstDressUpItemType.LIAN_YI_QUN))
  226. {
  227. Remove(itemID);
  228. i--;
  229. }
  230. if (subType > ConstDressUpItemType.TE_SHU)
  231. {
  232. if (count == 0)
  233. {
  234. firstTeshuId = itemID;
  235. }
  236. count++;
  237. }
  238. }
  239. if (type > ConstDressUpItemType.TE_SHU && count >= 3)
  240. {
  241. //特殊饰品最多穿三件,第四件会自动顶掉第一件
  242. Remove(firstTeshuId);
  243. }
  244. }
  245. private void checkDefaultItem()
  246. {
  247. if (!IsSuitPic)
  248. {
  249. //检查默认资源
  250. //是否有头发
  251. bool has1 = false;
  252. //是否有连衣裙
  253. bool has2 = false;
  254. //是否有内搭
  255. bool has3 = false;
  256. //是否有上衣
  257. // bool has4 = false;
  258. //是否有下装
  259. bool has5 = false;
  260. //是否有默认内搭
  261. // bool has30000 = false;
  262. //是否有默认下装
  263. // bool has50000 = false;
  264. for (int i = 0; i < _equipDatas.Count; i++)
  265. {
  266. int itemID = (int)_equipDatas[i];
  267. int subType = ItemUtilCS.GetItemSubType(itemID);
  268. if (subType == (int)ConstDressUpItemType.FA_XING)
  269. {
  270. has1 = true;
  271. }
  272. else if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  273. {
  274. has2 = true;
  275. }
  276. else if (subType == ConstDressUpItemType.NEI_DA)
  277. {
  278. has3 = true;
  279. }
  280. else if (subType == ConstDressUpItemType.XIA_ZHUANG)
  281. {
  282. has5 = true;
  283. }
  284. }
  285. if (!has1)
  286. {
  287. Add(10000);
  288. }
  289. if (!has2)
  290. {
  291. if (!has5)
  292. {
  293. Add(50000);
  294. }
  295. if (!has3)
  296. {
  297. Add(30000);
  298. }
  299. }
  300. }
  301. }
  302. /// <summary>
  303. /// 检测是否穿戴完整(穿着连衣裙或同时穿着上装下装)
  304. /// </summary>
  305. /// <returns></returns>
  306. public bool CheckPutOnFinish()
  307. {
  308. List<int> equipDatas = EquipDataCache.cacher.equipDatas;
  309. bool isLianYiQun = false;
  310. bool isShangYi = false;
  311. bool isXiaZhuang = false;
  312. for (int i = 0; i < equipDatas.Count; i++)
  313. {
  314. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(equipDatas[i]);
  315. if (itemCfg.subType == ConstDressUpItemType.LIAN_YI_QUN && itemCfg.id != ConstItemID.DEFULT_LIAN_YI_QUN)
  316. {
  317. isLianYiQun = true; break;
  318. }
  319. if (itemCfg.subType == ConstDressUpItemType.SHANG_YI && itemCfg.id != ConstItemID.DEFULT_NEI_DA)
  320. {
  321. isShangYi = true;
  322. }
  323. if (itemCfg.subType == ConstDressUpItemType.XIA_ZHUANG && itemCfg.id != ConstItemID.DEFULT_XIA_ZHUANG)
  324. {
  325. isXiaZhuang = true;
  326. }
  327. }
  328. return isLianYiQun || isXiaZhuang && isShangYi;
  329. }
  330. private void UpdatePicAction()
  331. {
  332. if (IsSuitPic)
  333. {
  334. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  335. DressUpUtil.UpdateBody(suitCfg.picRes, _sceneObj, !string.IsNullOrEmpty(suitCfg.aniRes), suitCfg.effRes);
  336. }
  337. else
  338. {
  339. DressUpUtil.UpdateBody(null, _sceneObj, false, null, _needSetMask);
  340. }
  341. }
  342. public void TakeOffAll(bool checkDefault = true)
  343. {
  344. _suitId = 0;
  345. _isPic = false;
  346. // AddOrRemove(propID, false, true);
  347. var tempList = equipDatas;
  348. foreach (int itemID in tempList)
  349. {
  350. AddOrRemove(itemID, false, false, true);
  351. }
  352. if (checkDefault)
  353. {
  354. checkDefaultItem();
  355. UpdatePicAction();
  356. }
  357. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  358. score = roleLevelCfg.baseScore;
  359. foreach (int itemId in _equipDatas)
  360. {
  361. score += DressUpMenuItemDataManager.GetItemScore(itemId);
  362. }
  363. }
  364. public void ChangeAction()
  365. {
  366. if (!HasSuitPicRes)
  367. {
  368. return;
  369. }
  370. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  371. _isPic = !_isPic;
  372. if (_isPic)
  373. {
  374. var tempList = equipDatas;
  375. foreach (int itemID in tempList)
  376. {
  377. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  378. {
  379. AddOrRemove(itemID, false, false, true);
  380. }
  381. }
  382. }
  383. else
  384. {
  385. int[] items = suitCfg.partsArr;
  386. foreach (int itemId in items)
  387. {
  388. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemId))
  389. {
  390. AddOrRemove(itemId, false, true);
  391. }
  392. }
  393. }
  394. checkDefaultItem();
  395. UpdatePicAction();
  396. }
  397. public void TryCancelSuit(int itemID)
  398. {
  399. if (_suitId > 0)
  400. {
  401. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  402. {
  403. if (_isPic)
  404. {
  405. ChangeAction();
  406. }
  407. _suitId = 0;
  408. }
  409. }
  410. }
  411. public bool IsSuitPic
  412. {
  413. get
  414. {
  415. return _suitId > 0 && _isPic;
  416. }
  417. }
  418. public bool HasSuitPicRes
  419. {
  420. get
  421. {
  422. if (_suitId > 0)
  423. {
  424. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  425. if (suitCfg.picRes != null && suitCfg.picRes.Length > 0)
  426. {
  427. return true;
  428. }
  429. }
  430. return false;
  431. }
  432. }
  433. public void PutOnSuitCfg(int id, bool checkPic, bool noSceneType, int[] excludeType = null)
  434. {
  435. if (_suitId == id)
  436. {
  437. return;
  438. }
  439. TakeOffAll(false);
  440. _suitId = id;
  441. _isPic = HasSuitPicRes && checkPic;
  442. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  443. List<int> items = new List<int>(suitCfg.partsArr);
  444. if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
  445. {
  446. items.AddRange(suitCfg.partsOptionalArr);
  447. }
  448. int subType = 0;
  449. foreach (int itemID in items)
  450. {
  451. if (DressUpMenuItemDataManager.CheckHasItem(itemID))
  452. {
  453. bool isSceneType = DressUpMenuItemDataManager.CheckIsSceneType(itemID);
  454. subType = ItemUtilCS.GetItemSubType(itemID);
  455. if (!_isPic || isSceneType)
  456. {
  457. if (!noSceneType || !isSceneType)
  458. {
  459. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  460. {
  461. AddOrRemove(itemID, false, true);
  462. }
  463. }
  464. }
  465. }
  466. }
  467. checkDefaultItem();
  468. UpdatePicAction();
  469. }
  470. public void PutOnSuitSaved(int index)
  471. {
  472. TakeOffAll(false);
  473. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  474. if (suitSavedData.bg > 0)
  475. {
  476. AddOrRemove(suitSavedData.bg, false);
  477. }
  478. foreach (int itemID in suitSavedData.equipDatas)
  479. {
  480. AddOrRemove(itemID, false, true);
  481. }
  482. _suitId = suitSavedData.suitId;
  483. _isPic = suitSavedData.pic;
  484. checkDefaultItem();
  485. UpdatePicAction();
  486. }
  487. public void PutOnSuitSavedInFight(int index)
  488. {
  489. TakeOffAll(false);
  490. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  491. if (suitSavedData.suitId > 0)
  492. {
  493. PutOnSuitCfg(suitSavedData.suitId, false, true);
  494. }
  495. else
  496. {
  497. foreach (int itemID in suitSavedData.equipDatas)
  498. {
  499. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  500. {
  501. AddOrRemove(itemID, false, true);
  502. }
  503. }
  504. checkDefaultItem();
  505. }
  506. }
  507. public void PutOnCurrentSuitSaved()
  508. {
  509. PutOnSuitSaved(CustomSuitDataManager.currentIndex);
  510. }
  511. public void PutOnDefaultSuitSaved(bool withBg = true)
  512. {
  513. TakeOffAll(false);
  514. CustomSuitData suitSavedData = CustomSuitDataManager.CreateDefaultSuitData(0);
  515. foreach (int itemID in suitSavedData.equipDatas)
  516. {
  517. AddOrRemove(itemID, false, true);
  518. }
  519. if (withBg)
  520. {
  521. if (suitSavedData.bg > 0)
  522. {
  523. AddOrRemove(suitSavedData.bg, false);
  524. }
  525. }
  526. checkDefaultItem();
  527. UpdatePicAction();
  528. }
  529. public void PutOnRecommendItems()
  530. {
  531. TakeOffAll(false);
  532. List<int> recommendList = DressUpMenuItemDataManager.GetRecommendItemList();
  533. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  534. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  535. //推荐搭配自动穿必穿品
  536. if (fightCfg.needItemId > 0 && DressUpMenuItemDataManager.CheckHasItem(fightCfg.needItemId) && recommendList.IndexOf(fightCfg.needItemId) < 0)
  537. {
  538. recommendList.Add(fightCfg.needItemId);
  539. }
  540. else if (fightCfg.needSuitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(fightCfg.needSuitId))
  541. {
  542. recommendList.Clear();
  543. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  544. recommendList.AddRange(cfg.partsArr);
  545. }
  546. foreach (int itemID in recommendList)
  547. {
  548. AddOrRemove(itemID, false, true);
  549. }
  550. checkDefaultItem();
  551. UpdatePicAction();
  552. }
  553. public bool CheckEquipedFightNeeded()
  554. {
  555. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  556. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  557. if (fightCfg.needItemId > 0)
  558. {
  559. return CheckDressUpItemIsOn(fightCfg.needItemId);
  560. }
  561. else if (fightCfg.needSuitId > 0)
  562. {
  563. return CheckSuitIsOn(fightCfg.needSuitId);
  564. }
  565. return true;
  566. }
  567. //根据位置原点和随机范围获取评分位置
  568. public void GetCirclePos(Vector2 pos, int range, out float x, out float y)
  569. {
  570. int numX = UnityEngine.Random.Range(0, 2);
  571. int signX = numX % 2 == 0 ? 1 : -1;
  572. float rangeX = UnityEngine.Random.Range(0, range);
  573. x = pos.x + signX * (rangeX);
  574. int numY = UnityEngine.Random.Range(0, 2);
  575. int signY = numY % 2 == 0 ? 1 : -1;
  576. float rangeY = UnityEngine.Random.Range(0, range);
  577. y = pos.y + signY * (rangeY);
  578. }
  579. public int GetItemIdBuyType(int subType)
  580. {
  581. for (int i = 0; i < equipDatas.Count; i++)
  582. {
  583. if (equipDatas[i] != ConstItemID.DEFULT_LIAN_YI_QUN && equipDatas[i] != ConstItemID.DEFULT_NEI_DA && equipDatas[i] != ConstItemID.DEFULT_XIA_ZHUANG && equipDatas[i] != ConstItemID.DEFULT_FA_XING)
  584. {
  585. if (subType == ItemUtilCS.GetItemSubType(equipDatas[i]))
  586. {
  587. return equipDatas[i];
  588. }
  589. }
  590. }
  591. if (suitId > 0)
  592. {
  593. return suitId;
  594. }
  595. return 0;
  596. }
  597. }
  598. }