DressUpObjDataCache.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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 NTexture _nTexture;
  43. public NTexture nTexture
  44. {
  45. get
  46. {
  47. return _nTexture;
  48. }
  49. set
  50. {
  51. _nTexture = value;
  52. }
  53. }
  54. private List<int> _equipDatas = new List<int>();
  55. public List<int> equipDatas
  56. {
  57. get
  58. {
  59. return _equipDatas.ToList();
  60. }
  61. set
  62. {
  63. _equipDatas = value;
  64. }
  65. }
  66. //角色基础分+部件基础分
  67. private int _score;
  68. public int score
  69. {
  70. get
  71. {
  72. return _score;
  73. }
  74. private set
  75. {
  76. _score = value;
  77. EventAgent.DispatchEvent(ConstMessage.DRESS_UP_SCORE_CHANGED, _score);
  78. }
  79. }
  80. //最终得分
  81. private int _totalScore;
  82. public int totalScore
  83. {
  84. get
  85. {
  86. return _totalScore;
  87. }
  88. set
  89. {
  90. _totalScore = value;
  91. }
  92. }
  93. //战斗对象最终得分
  94. private int _targetTotalScore;
  95. public int npcTotalScore
  96. {
  97. get
  98. {
  99. return _targetTotalScore;
  100. }
  101. set
  102. {
  103. _targetTotalScore = value;
  104. }
  105. }
  106. private bool _autoPlay = false;
  107. public bool autoPlay
  108. {
  109. get
  110. {
  111. return _autoPlay;
  112. }
  113. set
  114. {
  115. _autoPlay = value;
  116. if (!_autoPlay) fightSpeed = 1;
  117. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY, _autoPlay == true ? 1 : 0).Coroutine();
  118. }
  119. }
  120. public int maxFightSpeed = 2;
  121. private int _fightSpeed = 1;
  122. public int fightSpeed
  123. {
  124. get
  125. {
  126. return _fightSpeed;
  127. }
  128. set
  129. {
  130. _fightSpeed = value;
  131. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_FIGHT_AUTO_PLAY_SPEED, _fightSpeed).Coroutine();
  132. }
  133. }
  134. private int _storyDialogSpeed = 1;
  135. public int dialogSpeed
  136. {
  137. get
  138. {
  139. return _storyDialogSpeed;
  140. }
  141. set
  142. {
  143. _storyDialogSpeed = value;
  144. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_DIALOG_AUTO_PLAY_SPEED, _storyDialogSpeed).Coroutine();
  145. }
  146. }
  147. public void Dispose()
  148. {
  149. _sceneObj = null;
  150. }
  151. private void Add(int value)
  152. {
  153. if (!_equipDatas.Contains(value))
  154. {
  155. _equipDatas.Add(value);
  156. DressUpUtil.AddItem(value, _sceneObj, _needSetMask);
  157. score += DressUpMenuItemDataManager.GetItemScore(value);
  158. }
  159. int dressSuitId = CheckCurDressIsSuit();
  160. if (dressSuitId > 0) _suitId = dressSuitId;
  161. }
  162. private void Remove(int value)
  163. {
  164. if (_equipDatas == null)
  165. {
  166. return;
  167. }
  168. if (_equipDatas.Contains(value))
  169. {
  170. _equipDatas.Remove(value);
  171. DressUpUtil.RemoveItem(value, _sceneObj);
  172. score -= DressUpMenuItemDataManager.GetItemScore(value);
  173. }
  174. }
  175. //检测当前穿戴是否是一件完整套装,且只穿了一件套装,返回套装id
  176. public int CheckCurDressIsSuit()
  177. {
  178. if (_suitId > 0) return _suitId;
  179. // var equipDatas = _equipDatas;
  180. int dressSuitId = 0;
  181. List<int> equipDatas = new List<int>();
  182. for (int i = 0; i < _equipDatas.Count; i++)
  183. {
  184. if (DressUpMenuItemDataManager.CheckIsSceneType(_equipDatas[i])) continue;
  185. if (_equipDatas[i] != ConstItemID.DEFULT_FA_XING && _equipDatas[i] != ConstItemID.DEFULT_LIAN_YI_QUN && _equipDatas[i] != ConstItemID.DEFULT_NEI_DA && _equipDatas[i] != ConstItemID.DEFULT_XIA_ZHUANG)
  186. {
  187. int suitId = SuitCfgManager.Instance.GetItemSuitId(_equipDatas[i]);
  188. if (suitId <= 0) return 0;//有任何不属于套装的部件且不是原始服装,则当前穿戴不属于套装
  189. if (dressSuitId != 0 && dressSuitId != suitId) return 0;//当前穿戴不同套装的部件,则当前穿戴不属于套装
  190. dressSuitId = suitId;
  191. equipDatas.Add(_equipDatas[i]);
  192. }
  193. }
  194. if (dressSuitId == 0) return dressSuitId;
  195. int[] itemIds = SuitCfgManager.Instance.GetSuitItems(dressSuitId);
  196. for (int i = 0; i < itemIds.Length; i++)
  197. {
  198. if (DressUpMenuItemDataManager.CheckIsSceneType(itemIds[i])) continue;
  199. if (equipDatas.IndexOf(itemIds[i]) < 0) return 0;//套装部件穿戴不完整
  200. }
  201. return dressSuitId;
  202. }
  203. /// <summary>
  204. /// 仅判断换装部件是否已穿着
  205. /// </summary>
  206. /// <param name="id"></param>
  207. /// <returns></returns>
  208. public bool CheckDressUpItemIsOn(int id)
  209. {
  210. if (id == _bgId)
  211. {
  212. return true;
  213. }
  214. // if (suitId > 0)
  215. // {
  216. // int[] suitparts = SuitCfgArray.Instance.GetCfg(suitId).partsArr;
  217. // if (Array.IndexOf(suitparts, id) >= 0)
  218. // {
  219. // return true;
  220. // }
  221. // }
  222. return _equipDatas.Contains(id);
  223. }
  224. /// <summary>
  225. /// 仅判断套装是否穿上
  226. /// </summary>
  227. /// <param name="id"></param>
  228. /// <returns></returns>
  229. public bool CheckSuitIsOn(int id)
  230. {
  231. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
  232. if (suitCfg == null)
  233. {
  234. return false;
  235. }
  236. int[] items = suitCfg.partsArr;
  237. foreach (int itemId in items)
  238. {
  239. bool isOn = CheckDressUpItemIsOn(itemId);
  240. if (!isOn)
  241. {
  242. return false;
  243. }
  244. }
  245. return true;
  246. }
  247. public void AddOrRemove(int value, bool checkDefault, bool isAdd = false, bool isRemove = false)
  248. {
  249. int subType = ItemUtilCS.GetItemSubType(value);
  250. if (subType == ConstDressUpItemType.BEI_JING)
  251. {
  252. _bgId = value;
  253. DressUpUtil.AddItem(_bgId, _sceneObj, _needSetMask);
  254. }
  255. else
  256. {
  257. if (!CheckDressUpItemIsOn(value))
  258. {
  259. if (!isRemove)
  260. {
  261. checkRemoveSameType(subType);
  262. Add(value);
  263. }
  264. }
  265. else
  266. {
  267. if (!isAdd)
  268. {
  269. Remove(value);
  270. }
  271. }
  272. if (checkDefault)
  273. {
  274. checkDefaultItem();
  275. }
  276. }
  277. }
  278. public void checkRemoveSameType(int type)
  279. {
  280. int count = 0;
  281. int firstTeshuId = 0;
  282. for (int i = 0; i < _equipDatas.Count; i++)
  283. {
  284. int itemID = (int)_equipDatas[i];
  285. int subType = ItemUtilCS.GetItemSubType(itemID);
  286. if (subType == type
  287. || (type == ConstDressUpItemType.LIAN_YI_QUN && (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA))
  288. || (type == ConstDressUpItemType.SHANG_YI && subType == ConstDressUpItemType.LIAN_YI_QUN)
  289. || (type == ConstDressUpItemType.XIA_ZHUANG && subType == ConstDressUpItemType.LIAN_YI_QUN)
  290. || (type == ConstDressUpItemType.NEI_DA && subType == ConstDressUpItemType.LIAN_YI_QUN))
  291. {
  292. Remove(itemID);
  293. i--;
  294. }
  295. if (subType > ConstDressUpItemType.TE_SHU)
  296. {
  297. if (count == 0)
  298. {
  299. firstTeshuId = itemID;
  300. }
  301. count++;
  302. }
  303. }
  304. if (type > ConstDressUpItemType.TE_SHU && count >= 3)
  305. {
  306. //特殊饰品最多穿三件,第四件会自动顶掉第一件
  307. Remove(firstTeshuId);
  308. }
  309. }
  310. private void checkDefaultItem()
  311. {
  312. if (!IsSuitPic)
  313. {
  314. //检查默认资源
  315. //是否有头发
  316. bool hasFaXing = false;
  317. //是否有连衣裙
  318. bool hasLianYiQun = false;
  319. //是否有内搭
  320. bool hasNeiDa = false;
  321. //是否有上衣
  322. bool hasShangYi = false;
  323. //是否有下装
  324. bool hasXiaZhuang = false;
  325. //是否有默认内搭
  326. bool hasNeiDaDefault = false;
  327. //是否有默认下装
  328. bool hasXiaZhuangDefault = false;
  329. for (int i = 0; i < _equipDatas.Count; i++)
  330. {
  331. int itemID = (int)_equipDatas[i];
  332. int subType = ItemUtilCS.GetItemSubType(itemID);
  333. if (subType == (int)ConstDressUpItemType.FA_XING)
  334. {
  335. hasFaXing = true;
  336. }
  337. else if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  338. {
  339. hasLianYiQun = true;
  340. }
  341. else if (subType == ConstDressUpItemType.NEI_DA)
  342. {
  343. hasNeiDa = true;
  344. }
  345. else if (subType == ConstDressUpItemType.XIA_ZHUANG)
  346. {
  347. hasXiaZhuang = true;
  348. }
  349. else if (subType == ConstDressUpItemType.SHANG_YI)
  350. {
  351. hasShangYi = true;
  352. }
  353. if (itemID == ConstItemID.DEFULT_NEI_DA)
  354. {
  355. hasNeiDaDefault = true;
  356. }
  357. else if (itemID == ConstItemID.DEFULT_XIA_ZHUANG)
  358. {
  359. hasXiaZhuangDefault = true;
  360. }
  361. }
  362. if (!hasFaXing)
  363. {
  364. Add(10000);
  365. }
  366. if (!hasLianYiQun)
  367. {
  368. if (!hasShangYi && (!hasNeiDa || hasNeiDaDefault) && (!hasXiaZhuang || hasXiaZhuangDefault))
  369. {
  370. Remove(ConstItemID.DEFULT_XIA_ZHUANG);
  371. Remove(ConstItemID.DEFULT_NEI_DA);
  372. Add(ConstItemID.DEFULT_LIAN_YI_QUN);
  373. }
  374. else
  375. {
  376. if (!hasXiaZhuang)
  377. {
  378. Add(ConstItemID.DEFULT_XIA_ZHUANG);
  379. }
  380. if (!hasNeiDa)
  381. {
  382. Add(ConstItemID.DEFULT_NEI_DA);
  383. }
  384. }
  385. }
  386. }
  387. }
  388. /// <summary>
  389. /// 检测是否穿戴完整(穿着连衣裙或同时穿着上装下装)
  390. /// </summary>
  391. /// <returns></returns>
  392. public bool CheckPutOnFinish()
  393. {
  394. List<int> equipDatas = EquipDataCache.cacher.equipDatas;
  395. bool isLianYiQun = false;
  396. bool isShangYi = false;
  397. bool isXiaZhuang = false;
  398. for (int i = 0; i < equipDatas.Count; i++)
  399. {
  400. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(equipDatas[i]);
  401. if (itemCfg.subType == ConstDressUpItemType.LIAN_YI_QUN && itemCfg.id != ConstItemID.DEFULT_LIAN_YI_QUN)
  402. {
  403. isLianYiQun = true; break;
  404. }
  405. if (itemCfg.subType == ConstDressUpItemType.SHANG_YI && itemCfg.id != ConstItemID.DEFULT_NEI_DA)
  406. {
  407. isShangYi = true;
  408. }
  409. if (itemCfg.subType == ConstDressUpItemType.XIA_ZHUANG && itemCfg.id != ConstItemID.DEFULT_XIA_ZHUANG)
  410. {
  411. isXiaZhuang = true;
  412. }
  413. }
  414. return isLianYiQun || isXiaZhuang && isShangYi;
  415. }
  416. private void UpdatePicAction()
  417. {
  418. if (IsSuitPic)
  419. {
  420. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  421. DressUpUtil.UpdateBody(suitCfg.picRes, _sceneObj, !string.IsNullOrEmpty(suitCfg.aniRes), suitCfg.effRes);
  422. }
  423. else
  424. {
  425. DressUpUtil.UpdateBody(null, _sceneObj, false, null, _needSetMask);
  426. }
  427. }
  428. public void TakeOffAll(bool checkDefault = true)
  429. {
  430. _suitId = 0;
  431. _isPic = false;
  432. // AddOrRemove(propID, false, true);
  433. var tempList = equipDatas;
  434. foreach (int itemID in tempList)
  435. {
  436. AddOrRemove(itemID, false, false, true);
  437. }
  438. if (checkDefault)
  439. {
  440. checkDefaultItem();
  441. UpdatePicAction();
  442. }
  443. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  444. score = roleLevelCfg.baseScore;
  445. foreach (int itemId in _equipDatas)
  446. {
  447. score += DressUpMenuItemDataManager.GetItemScore(itemId);
  448. }
  449. }
  450. public void ChangeAction()
  451. {
  452. if (!HasSuitPicRes)
  453. {
  454. return;
  455. }
  456. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  457. _isPic = !_isPic;
  458. if (_isPic)
  459. {
  460. var tempList = equipDatas;
  461. foreach (int itemID in tempList)
  462. {
  463. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  464. {
  465. AddOrRemove(itemID, false, false, true);
  466. }
  467. }
  468. }
  469. else
  470. {
  471. int[] items = suitCfg.partsArr;
  472. foreach (int itemId in items)
  473. {
  474. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemId))
  475. {
  476. AddOrRemove(itemId, false, true);
  477. }
  478. }
  479. }
  480. checkDefaultItem();
  481. UpdatePicAction();
  482. }
  483. public void TryCancelSuit(int itemID)
  484. {
  485. if (_suitId > 0)
  486. {
  487. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  488. {
  489. if (_isPic)
  490. {
  491. ChangeAction();
  492. }
  493. _suitId = 0;
  494. }
  495. }
  496. }
  497. public bool IsSuitPic
  498. {
  499. get
  500. {
  501. return _suitId > 0 && _isPic;
  502. }
  503. }
  504. public bool HasSuitPicRes
  505. {
  506. get
  507. {
  508. if (_suitId > 0)
  509. {
  510. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  511. if (suitCfg.picRes != null && suitCfg.picRes.Length > 0)
  512. {
  513. return true;
  514. }
  515. }
  516. return false;
  517. }
  518. }
  519. public void PutOnSuitCfg(int id, bool checkPic, bool noSceneType, int[] excludeType = null)
  520. {
  521. if (_suitId == id)
  522. {
  523. return;
  524. }
  525. TakeOffAll(false);
  526. _suitId = id;
  527. _isPic = HasSuitPicRes && checkPic;
  528. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  529. List<int> items = new List<int>(suitCfg.partsArr);
  530. if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
  531. {
  532. items.AddRange(suitCfg.partsOptionalArr);
  533. }
  534. int subType = 0;
  535. foreach (int itemID in items)
  536. {
  537. if (DressUpMenuItemDataManager.CheckHasItem(itemID))
  538. {
  539. bool isSceneType = DressUpMenuItemDataManager.CheckIsSceneType(itemID);
  540. subType = ItemUtilCS.GetItemSubType(itemID);
  541. if (!_isPic || isSceneType)
  542. {
  543. if (!noSceneType || !isSceneType)
  544. {
  545. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  546. {
  547. AddOrRemove(itemID, false, true);
  548. }
  549. }
  550. }
  551. }
  552. }
  553. checkDefaultItem();
  554. UpdatePicAction();
  555. }
  556. public CustomSuitData GetCurSuitData(int index)
  557. {
  558. CustomSuitData suitSavedData = new CustomSuitData(index);
  559. suitSavedData.equipDatas = EquipDataCache.cacher.equipDatas;
  560. suitSavedData.bg = EquipDataCache.cacher.bgId;
  561. suitSavedData.pic = EquipDataCache.cacher.picStatus;
  562. suitSavedData.suitId = EquipDataCache.cacher.suitId;
  563. return suitSavedData;
  564. }
  565. public void PutOnSuitSaved(int index)
  566. {
  567. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  568. PutOnSuitMemory(suitSavedData);
  569. }
  570. public void PutOnSuitMemory(CustomSuitData suitSavedData)
  571. {
  572. TakeOffAll(false);
  573. if (suitSavedData.bg > 0)
  574. {
  575. AddOrRemove(suitSavedData.bg, false);
  576. }
  577. foreach (int itemID in suitSavedData.equipDatas)
  578. {
  579. AddOrRemove(itemID, false, true);
  580. }
  581. _suitId = suitSavedData.suitId;
  582. _isPic = suitSavedData.pic;
  583. checkDefaultItem();
  584. UpdatePicAction();
  585. }
  586. public void PutOnSuitSavedInFight(int index)
  587. {
  588. TakeOffAll(false);
  589. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  590. if (suitSavedData.suitId > 0)
  591. {
  592. PutOnSuitCfg(suitSavedData.suitId, false, true);
  593. }
  594. else
  595. {
  596. foreach (int itemID in suitSavedData.equipDatas)
  597. {
  598. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  599. {
  600. AddOrRemove(itemID, false, true);
  601. }
  602. }
  603. checkDefaultItem();
  604. }
  605. }
  606. // public void PutOnCurrentSuitSaved()
  607. // {
  608. // PutOnSuitSaved(CustomSuitDataManager.currentIndex);
  609. // }
  610. public void PutOnDefaultSuitSaved(bool withBg = true)
  611. {
  612. TakeOffAll(false);
  613. CustomSuitData suitSavedData = CustomSuitDataManager.CreateDefaultSuitData(0);
  614. foreach (int itemID in suitSavedData.equipDatas)
  615. {
  616. AddOrRemove(itemID, false, true);
  617. }
  618. if (withBg)
  619. {
  620. if (suitSavedData.bg > 0)
  621. {
  622. AddOrRemove(suitSavedData.bg, false);
  623. }
  624. }
  625. checkDefaultItem();
  626. UpdatePicAction();
  627. }
  628. public void PutOnRecommendItems()
  629. {
  630. TakeOffAll(false);
  631. List<int> recommendList = DressUpMenuItemDataManager.GetRecommendItemList();
  632. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  633. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  634. int liangyiqunIndex = -1;
  635. int shangyiIndex = -1;
  636. int xiazhuangIndex = -1;
  637. int neidaIndex = -1;
  638. for (int i = 0; i < recommendList.Count; i++)
  639. {
  640. int subType = ItemUtilCS.GetItemSubType(recommendList[i]);
  641. if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  642. {
  643. liangyiqunIndex = i;
  644. continue;
  645. }
  646. if (subType == ConstDressUpItemType.SHANG_YI)
  647. {
  648. shangyiIndex = i;
  649. continue;
  650. }
  651. if (subType == ConstDressUpItemType.XIA_ZHUANG)
  652. {
  653. xiazhuangIndex = i;
  654. continue;
  655. }
  656. if (subType == ConstDressUpItemType.NEI_DA)
  657. {
  658. neidaIndex = i;
  659. continue;
  660. }
  661. }
  662. if (liangyiqunIndex >= 0 && (shangyiIndex >= 0 || xiazhuangIndex >= 0))
  663. {
  664. if (shangyiIndex < 0 && xiazhuangIndex >= 0) recommendList.RemoveAt(xiazhuangIndex);//上衣下装只有一件,则保留连衣裙
  665. if (xiazhuangIndex < 0 && shangyiIndex >= 0) recommendList.RemoveAt(shangyiIndex);
  666. if (shangyiIndex >= 0 && xiazhuangIndex >= 0)//同时拥有上衣、下装、连衣裙
  667. {
  668. int lianyiqunScore = DressUpMenuItemDataManager.GetItemScore(recommendList[liangyiqunIndex]);
  669. int shangyiScore = DressUpMenuItemDataManager.GetItemScore(recommendList[shangyiIndex]);
  670. int xiazhuangScore = DressUpMenuItemDataManager.GetItemScore(recommendList[xiazhuangIndex]);
  671. int neidaScore = neidaIndex >= 0 ? DressUpMenuItemDataManager.GetItemScore(recommendList[neidaIndex]) : 0;
  672. int subType = ItemUtilCS.GetItemSubType(fightCfg.needItemId);
  673. if (fightCfg.needItemId > 0 && recommendList.IndexOf(fightCfg.needItemId) >= 0 && (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA || subType == ConstDressUpItemType.LIAN_YI_QUN))//推荐列表里有必需品且,必需品类型为上衣或下装或连衣裙,有先穿戴必须品,其次穿戴高分服装
  674. {
  675. if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  676. {
  677. shangyiIndex = CheckIndex(ConstDressUpItemType.SHANG_YI, recommendList);
  678. if (shangyiIndex >= 0) recommendList.RemoveAt(shangyiIndex);
  679. xiazhuangIndex = CheckIndex(ConstDressUpItemType.XIA_ZHUANG, recommendList);
  680. if (xiazhuangIndex >= 0) recommendList.RemoveAt(xiazhuangIndex);
  681. neidaIndex = CheckIndex(ConstDressUpItemType.NEI_DA, recommendList);
  682. if (neidaIndex >= 0) recommendList.RemoveAt(neidaIndex);
  683. }
  684. else if (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA)
  685. {
  686. liangyiqunIndex = CheckIndex(ConstDressUpItemType.LIAN_YI_QUN, recommendList);
  687. if (liangyiqunIndex >= 0) recommendList.RemoveAt(liangyiqunIndex);
  688. }
  689. }
  690. else
  691. {
  692. if (lianyiqunScore > shangyiScore + xiazhuangScore + neidaScore)
  693. {
  694. shangyiIndex = CheckIndex(ConstDressUpItemType.SHANG_YI, recommendList);
  695. if (shangyiIndex >= 0) recommendList.RemoveAt(shangyiIndex);
  696. xiazhuangIndex = CheckIndex(ConstDressUpItemType.XIA_ZHUANG, recommendList);
  697. if (xiazhuangIndex >= 0) recommendList.RemoveAt(xiazhuangIndex);
  698. neidaIndex = CheckIndex(ConstDressUpItemType.NEI_DA, recommendList);
  699. if (neidaIndex >= 0) recommendList.RemoveAt(neidaIndex);
  700. }
  701. else
  702. {
  703. liangyiqunIndex = CheckIndex(ConstDressUpItemType.LIAN_YI_QUN, recommendList);
  704. if (liangyiqunIndex >= 0) recommendList.RemoveAt(liangyiqunIndex);
  705. }
  706. }
  707. }
  708. }
  709. //推荐搭配自动穿必穿品
  710. if (fightCfg.needItemId > 0 && DressUpMenuItemDataManager.CheckHasItem(fightCfg.needItemId) && recommendList.IndexOf(fightCfg.needItemId) < 0)
  711. {
  712. int subType = ItemUtilCS.GetItemSubType(fightCfg.needItemId);
  713. for (int i = 0; i < recommendList.Count; i++)
  714. {
  715. int recommendSubType = ItemUtilCS.GetItemSubType(recommendList[i]);
  716. if (recommendSubType == subType)
  717. {
  718. recommendList.RemoveAt(i);
  719. break;
  720. }
  721. }
  722. recommendList.Add(fightCfg.needItemId);
  723. }
  724. else if (fightCfg.needSuitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(fightCfg.needSuitId))
  725. {
  726. recommendList.Clear();
  727. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  728. recommendList.AddRange(cfg.partsArr);
  729. }
  730. foreach (int itemID in recommendList)
  731. {
  732. AddOrRemove(itemID, false, true);
  733. }
  734. checkDefaultItem();
  735. UpdatePicAction();
  736. }
  737. private int CheckIndex(int _subType, List<int> recommendList)
  738. {
  739. for (int i = 0; i < recommendList.Count; i++)
  740. {
  741. int itemSubType = ItemUtilCS.GetItemSubType(recommendList[i]);
  742. if (itemSubType == _subType)
  743. {
  744. return i;
  745. }
  746. }
  747. return -1;
  748. }
  749. public bool CheckEquipedFightNeeded()
  750. {
  751. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  752. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  753. if (fightCfg.needItemId > 0)
  754. {
  755. return CheckDressUpItemIsOn(fightCfg.needItemId);
  756. }
  757. else if (fightCfg.needSuitId > 0)
  758. {
  759. return CheckSuitIsOn(fightCfg.needSuitId);
  760. }
  761. return true;
  762. }
  763. //根据位置原点和随机范围获取评分位置
  764. public void GetCirclePos(Vector2 pos, int range, out float x, out float y)
  765. {
  766. int numX = UnityEngine.Random.Range(0, 2);
  767. int signX = numX % 2 == 0 ? 1 : -1;
  768. float rangeX = UnityEngine.Random.Range(0, range);
  769. x = pos.x + signX * (rangeX);
  770. int numY = UnityEngine.Random.Range(0, 2);
  771. int signY = numY % 2 == 0 ? 1 : -1;
  772. float rangeY = UnityEngine.Random.Range(0, range);
  773. y = pos.y + signY * (rangeY);
  774. }
  775. public int GetItemIdBuyType(int subType)
  776. {
  777. for (int i = 0; i < equipDatas.Count; i++)
  778. {
  779. 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)
  780. {
  781. if (subType == ItemUtilCS.GetItemSubType(equipDatas[i]))
  782. {
  783. return equipDatas[i];
  784. }
  785. }
  786. }
  787. if (suitId > 0)
  788. {
  789. return suitId;
  790. }
  791. return 0;
  792. }
  793. }
  794. }