DressUpObjDataCache.cs 29 KB

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