DressUpObjDataCache.cs 17 KB

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