DressUpObjDataCache.cs 17 KB

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