DressUpObjDataCache.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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 += ItemDataManager.GetItemAdditionScore(value, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
  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 -= ItemDataManager.GetItemAdditionScore(value, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
  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. if (EquipDataCache.cacher.suitId > 0) return true;
  385. List<int> equipDatas = EquipDataCache.cacher.equipDatas;
  386. bool isLianYiQun = false;
  387. bool isShangYi = false;
  388. bool isXiaZhuang = false;
  389. for (int i = 0; i < equipDatas.Count; i++)
  390. {
  391. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(equipDatas[i]);
  392. if (itemCfg.subType == ConstDressUpItemType.LIAN_YI_QUN && itemCfg.id != ConstItemID.DEFULT_LIAN_YI_QUN)
  393. {
  394. isLianYiQun = true; break;
  395. }
  396. if (itemCfg.subType == ConstDressUpItemType.SHANG_YI && itemCfg.id != ConstItemID.DEFULT_NEI_DA)
  397. {
  398. isShangYi = true;
  399. }
  400. if (itemCfg.subType == ConstDressUpItemType.XIA_ZHUANG && itemCfg.id != ConstItemID.DEFULT_XIA_ZHUANG)
  401. {
  402. isXiaZhuang = true;
  403. }
  404. }
  405. return isLianYiQun || isXiaZhuang && isShangYi;
  406. }
  407. private void UpdatePicAction()
  408. {
  409. if (IsSuitPic)
  410. {
  411. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  412. DressUpUtil.UpdateBody(suitCfg.picRes, _sceneObj, !string.IsNullOrEmpty(suitCfg.aniRes), suitCfg.effRes);
  413. }
  414. else
  415. {
  416. DressUpUtil.UpdateBody(null, _sceneObj, false, null, _needSetMask);
  417. }
  418. }
  419. public void TakeOffAll(bool checkDefault = true)
  420. {
  421. _suitId = 0;
  422. _isPic = false;
  423. // AddOrRemove(propID, false, true);
  424. var tempList = equipDatas;
  425. foreach (int itemID in tempList)
  426. {
  427. AddOrRemove(itemID, false, false, true);
  428. }
  429. if (checkDefault)
  430. {
  431. checkDefaultItem();
  432. UpdatePicAction();
  433. }
  434. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  435. score = roleLevelCfg.baseScore;
  436. foreach (int itemId in _equipDatas)
  437. {
  438. score += ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
  439. }
  440. }
  441. public void ChangeAction()
  442. {
  443. if (!HasSuitPicRes)
  444. {
  445. return;
  446. }
  447. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  448. _isPic = !_isPic;
  449. if (_isPic)
  450. {
  451. var tempList = equipDatas;
  452. foreach (int itemID in tempList)
  453. {
  454. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  455. {
  456. AddOrRemove(itemID, false, false, true);
  457. }
  458. }
  459. }
  460. else
  461. {
  462. int[] items = suitCfg.partsArr;
  463. foreach (int itemId in items)
  464. {
  465. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemId))
  466. {
  467. AddOrRemove(itemId, false, true);
  468. }
  469. }
  470. }
  471. checkDefaultItem();
  472. UpdatePicAction();
  473. }
  474. public void TryCancelSuit(int itemID)
  475. {
  476. if (_suitId > 0)
  477. {
  478. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  479. {
  480. if (_isPic)
  481. {
  482. ChangeAction();
  483. }
  484. _suitId = 0;
  485. }
  486. }
  487. }
  488. public bool IsSuitPic
  489. {
  490. get
  491. {
  492. return _suitId > 0 && _isPic;
  493. }
  494. }
  495. public bool HasSuitPicRes
  496. {
  497. get
  498. {
  499. if (_suitId > 0)
  500. {
  501. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  502. if (suitCfg.picRes != null && suitCfg.picRes.Length > 0)
  503. {
  504. return true;
  505. }
  506. }
  507. return false;
  508. }
  509. }
  510. /// <summary>
  511. /// 尝试穿戴配置套装
  512. /// </summary>
  513. /// <param name="id">套装id</param>
  514. /// <param name="checkPic">检查是否是立绘</param>
  515. /// <param name="noSceneType">是否排除场景类型</param>
  516. /// <param name="excludeType">排除类型列表</param>
  517. /// <param name="showOptional">是否显示可选部件</param>
  518. /// <param name="CheckOwn">是否只显示主角拥有的部件</param>
  519. public void PutOnSuitCfg(int id, bool checkPic, bool noSceneType, int[] excludeType = null, bool showOptional = true, bool CheckOwn = true)
  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 (showOptional)
  531. {
  532. if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
  533. {
  534. items.AddRange(suitCfg.partsOptionalArr);
  535. }
  536. }
  537. int subType = 0;
  538. foreach (int itemID in items)
  539. {
  540. if (!CheckOwn || DressUpMenuItemDataManager.CheckHasItem(itemID))
  541. {
  542. bool isSceneType = DressUpMenuItemDataManager.CheckIsSceneType(itemID);
  543. subType = ItemUtilCS.GetItemSubType(itemID);
  544. if (!_isPic || isSceneType)
  545. {
  546. if (!noSceneType || !isSceneType)
  547. {
  548. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  549. {
  550. AddOrRemove(itemID, false, true);
  551. }
  552. }
  553. }
  554. }
  555. }
  556. checkDefaultItem();
  557. UpdatePicAction();
  558. }
  559. public CustomSuitData GetCurSuitData(int index)
  560. {
  561. CustomSuitData suitSavedData = new CustomSuitData(index);
  562. suitSavedData.equipDatas = EquipDataCache.cacher.equipDatas;
  563. suitSavedData.bg = EquipDataCache.cacher.bgId;
  564. suitSavedData.pic = EquipDataCache.cacher.picStatus;
  565. suitSavedData.suitId = EquipDataCache.cacher.suitId;
  566. return suitSavedData;
  567. }
  568. public void PutOnSuitSaved(int index)
  569. {
  570. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  571. PutOnSuitMemory(suitSavedData);
  572. }
  573. public void PutOnSuitMemory(CustomSuitData suitSavedData)
  574. {
  575. TakeOffAll(false);
  576. if (suitSavedData.bg > 0)
  577. {
  578. AddOrRemove(suitSavedData.bg, false);
  579. }
  580. foreach (int itemID in suitSavedData.equipDatas)
  581. {
  582. AddOrRemove(itemID, false, true);
  583. }
  584. _suitId = suitSavedData.suitId;
  585. _isPic = suitSavedData.pic;
  586. checkDefaultItem();
  587. UpdatePicAction();
  588. }
  589. public void PutOnSuitSavedInFight(int index)
  590. {
  591. TakeOffAll(false);
  592. CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
  593. if (suitSavedData.suitId > 0)
  594. {
  595. PutOnSuitCfg(suitSavedData.suitId, false, true);
  596. }
  597. else
  598. {
  599. foreach (int itemID in suitSavedData.equipDatas)
  600. {
  601. if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
  602. {
  603. AddOrRemove(itemID, false, true);
  604. }
  605. }
  606. checkDefaultItem();
  607. }
  608. }
  609. // public void PutOnCurrentSuitSaved()
  610. // {
  611. // PutOnSuitSaved(CustomSuitDataManager.currentIndex);
  612. // }
  613. public void PutOnDefaultSuitSaved(bool withBg = true)
  614. {
  615. TakeOffAll(false);
  616. CustomSuitData suitSavedData = CustomSuitDataManager.CreateDefaultSuitData(0);
  617. foreach (int itemID in suitSavedData.equipDatas)
  618. {
  619. AddOrRemove(itemID, false, true);
  620. }
  621. if (withBg)
  622. {
  623. if (suitSavedData.bg > 0)
  624. {
  625. AddOrRemove(suitSavedData.bg, false);
  626. }
  627. }
  628. checkDefaultItem();
  629. UpdatePicAction();
  630. }
  631. public void PutOnRecommendItems()
  632. {
  633. TakeOffAll(false);
  634. List<int> recommendList = DressUpMenuItemDataManager.GetRecommendItemList();
  635. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  636. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  637. int liangyiqunIndex = -1;
  638. int shangyiIndex = -1;
  639. int xiazhuangIndex = -1;
  640. int neidaIndex = -1;
  641. for (int i = 0; i < recommendList.Count; i++)
  642. {
  643. int subType = ItemUtilCS.GetItemSubType(recommendList[i]);
  644. if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  645. {
  646. liangyiqunIndex = i;
  647. continue;
  648. }
  649. if (subType == ConstDressUpItemType.SHANG_YI)
  650. {
  651. shangyiIndex = i;
  652. continue;
  653. }
  654. if (subType == ConstDressUpItemType.XIA_ZHUANG)
  655. {
  656. xiazhuangIndex = i;
  657. continue;
  658. }
  659. if (subType == ConstDressUpItemType.NEI_DA)
  660. {
  661. neidaIndex = i;
  662. continue;
  663. }
  664. }
  665. if (liangyiqunIndex >= 0 && (shangyiIndex >= 0 || xiazhuangIndex >= 0))
  666. {
  667. if (shangyiIndex < 0 && xiazhuangIndex >= 0) recommendList.RemoveAt(xiazhuangIndex);//上衣下装只有一件,则保留连衣裙
  668. if (xiazhuangIndex < 0 && shangyiIndex >= 0) recommendList.RemoveAt(shangyiIndex);
  669. if (shangyiIndex >= 0 && xiazhuangIndex >= 0)//同时拥有上衣、下装、连衣裙
  670. {
  671. int lianyiqunScore = ItemDataManager.GetItemAdditionScore(recommendList[liangyiqunIndex], InstanceZonesDataManager.currentScoreType);
  672. int shangyiScore = ItemDataManager.GetItemAdditionScore(recommendList[shangyiIndex], InstanceZonesDataManager.currentScoreType);
  673. int xiazhuangScore = ItemDataManager.GetItemAdditionScore(recommendList[xiazhuangIndex], InstanceZonesDataManager.currentScoreType);
  674. int neidaScore = neidaIndex >= 0 ? ItemDataManager.GetItemAdditionScore(recommendList[neidaIndex], InstanceZonesDataManager.currentScoreType) : 0;
  675. int subType = ItemUtilCS.GetItemSubType(fightCfg.needItemId);
  676. 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))//推荐列表里有必需品且,必需品类型为上衣或下装或连衣裙,有先穿戴必须品,其次穿戴高分服装
  677. {
  678. if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  679. {
  680. shangyiIndex = CheckIndex(ConstDressUpItemType.SHANG_YI, recommendList);
  681. if (shangyiIndex >= 0) recommendList.RemoveAt(shangyiIndex);
  682. xiazhuangIndex = CheckIndex(ConstDressUpItemType.XIA_ZHUANG, recommendList);
  683. if (xiazhuangIndex >= 0) recommendList.RemoveAt(xiazhuangIndex);
  684. neidaIndex = CheckIndex(ConstDressUpItemType.NEI_DA, recommendList);
  685. if (neidaIndex >= 0) recommendList.RemoveAt(neidaIndex);
  686. }
  687. else if (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA)
  688. {
  689. liangyiqunIndex = CheckIndex(ConstDressUpItemType.LIAN_YI_QUN, recommendList);
  690. if (liangyiqunIndex >= 0) recommendList.RemoveAt(liangyiqunIndex);
  691. }
  692. }
  693. else
  694. {
  695. if (lianyiqunScore > shangyiScore + xiazhuangScore + neidaScore)
  696. {
  697. shangyiIndex = CheckIndex(ConstDressUpItemType.SHANG_YI, recommendList);
  698. if (shangyiIndex >= 0) recommendList.RemoveAt(shangyiIndex);
  699. xiazhuangIndex = CheckIndex(ConstDressUpItemType.XIA_ZHUANG, recommendList);
  700. if (xiazhuangIndex >= 0) recommendList.RemoveAt(xiazhuangIndex);
  701. neidaIndex = CheckIndex(ConstDressUpItemType.NEI_DA, recommendList);
  702. if (neidaIndex >= 0) recommendList.RemoveAt(neidaIndex);
  703. }
  704. else
  705. {
  706. liangyiqunIndex = CheckIndex(ConstDressUpItemType.LIAN_YI_QUN, recommendList);
  707. if (liangyiqunIndex >= 0) recommendList.RemoveAt(liangyiqunIndex);
  708. }
  709. }
  710. }
  711. }
  712. //推荐搭配自动穿必穿品
  713. if (fightCfg.needItemId > 0 && DressUpMenuItemDataManager.CheckHasItem(fightCfg.needItemId) && recommendList.IndexOf(fightCfg.needItemId) < 0)
  714. {
  715. int subType = ItemUtilCS.GetItemSubType(fightCfg.needItemId);
  716. for (int i = 0; i < recommendList.Count; i++)
  717. {
  718. int recommendSubType = ItemUtilCS.GetItemSubType(recommendList[i]);
  719. if (recommendSubType == subType)
  720. {
  721. recommendList.RemoveAt(i);
  722. break;
  723. }
  724. }
  725. recommendList.Add(fightCfg.needItemId);
  726. }
  727. else if (fightCfg.needSuitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(fightCfg.needSuitId))
  728. {
  729. recommendList.Clear();
  730. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  731. recommendList.AddRange(cfg.partsArr);
  732. }
  733. foreach (int itemID in recommendList)
  734. {
  735. AddOrRemove(itemID, false, true);
  736. }
  737. checkDefaultItem();
  738. UpdatePicAction();
  739. }
  740. private int CheckIndex(int _subType, List<int> recommendList)
  741. {
  742. for (int i = 0; i < recommendList.Count; i++)
  743. {
  744. int itemSubType = ItemUtilCS.GetItemSubType(recommendList[i]);
  745. if (itemSubType == _subType)
  746. {
  747. return i;
  748. }
  749. }
  750. return -1;
  751. }
  752. public bool CheckEquipedFightNeeded()
  753. {
  754. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  755. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  756. if (fightCfg.needItemId > 0)
  757. {
  758. return CheckDressUpItemIsOn(fightCfg.needItemId);
  759. }
  760. else if (fightCfg.needSuitId > 0)
  761. {
  762. return CheckSuitIsOn(fightCfg.needSuitId);
  763. }
  764. return true;
  765. }
  766. //根据位置原点和随机范围获取评分位置
  767. public void GetCirclePos(Vector2 pos, int range, out float x, out float y)
  768. {
  769. int numX = UnityEngine.Random.Range(0, 2);
  770. int signX = numX % 2 == 0 ? 1 : -1;
  771. float rangeX = UnityEngine.Random.Range(0, range);
  772. x = pos.x + signX * (rangeX);
  773. int numY = UnityEngine.Random.Range(0, 2);
  774. int signY = numY % 2 == 0 ? 1 : -1;
  775. float rangeY = UnityEngine.Random.Range(0, range);
  776. y = pos.y + signY * (rangeY);
  777. }
  778. public int GetItemIdBuyType(int subType)
  779. {
  780. for (int i = 0; i < equipDatas.Count; i++)
  781. {
  782. 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)
  783. {
  784. if (subType == ItemUtilCS.GetItemSubType(equipDatas[i]))
  785. {
  786. return equipDatas[i];
  787. }
  788. }
  789. }
  790. if (suitId > 0)
  791. {
  792. return suitId;
  793. }
  794. return 0;
  795. }
  796. }
  797. }