DressUpObjDataCache.cs 20 KB

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