DressUpObjDataCache.cs 20 KB

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