DressUpObjDataCache.cs 18 KB

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