DressUpObjDataCache.cs 20 KB

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