123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645 |
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using System.Linq;
- using FairyGUI;
- using ET;
- namespace GFGGame
- {
- public class DressUpObjDataCache
- {
- private GameObject _sceneObj;
- private bool _needSetMask;
- public void setSceneObj(GameObject sceneObj, bool needSetMask = false)
- {
- _sceneObj = sceneObj;
- _needSetMask = needSetMask;
- }
- private int _bgId;
- public int bgId
- {
- get
- {
- return _bgId;
- }
- }
- private int _suitId;
- public int suitId
- {
- get
- {
- return _suitId;
- }
- }
- private bool _isPic;
- public bool picStatus
- {
- get
- {
- return _isPic;
- }
- }
- private List<int> _equipDatas = new List<int>();
- public List<int> equipDatas
- {
- get
- {
- return _equipDatas.ToList();
- }
- }
- //角色基础分+部件基础分
- private int _score;
- public int score
- {
- get
- {
- return _score;
- }
- private set
- {
- _score = value;
- EventAgent.DispatchEvent(ConstMessage.DRESS_UP_SCORE_CHANGED, _score);
- }
- }
- //最终得分
- private int _totalScore;
- public int totalScore
- {
- get
- {
- return _totalScore;
- }
- set
- {
- _totalScore = value;
- }
- }
- //战斗对象最终得分
- private int _targetTotalScore;
- public int npcTotalScore
- {
- get
- {
- return _targetTotalScore;
- }
- set
- {
- _targetTotalScore = value;
- }
- }
- private bool _autoPlay = false;
- public bool autoPlay
- {
- get
- {
- return _autoPlay;
- }
- set
- {
- _autoPlay = value;
- if (!_autoPlay) fightSpeed = 1;
- StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY, _autoPlay == true ? 1 : 0).Coroutine();
- }
- }
- public int maxFightSpeed = 8;
- private int _fightSpeed = 1;
- public int fightSpeed
- {
- get
- {
- return _fightSpeed;
- }
- set
- {
- _fightSpeed = value;
- StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED, _fightSpeed).Coroutine();
- }
- }
- private int _fieldFightSpeed = 1;
- public int fieldFightSpeed
- {
- get
- {
- return _fieldFightSpeed;
- }
- set
- {
- _fieldFightSpeed = value;
- StorageSProxy.ReqSetClientValue(ConstStorageId.FIELD_AUTO_PLAY_SPEED, _fieldFightSpeed).Coroutine();
- }
- }
- public void Dispose()
- {
- _sceneObj = null;
- }
- private void Add(int value)
- {
- if (!_equipDatas.Contains(value))
- {
- _equipDatas.Add(value);
- DressUpUtil.AddItem(value, _sceneObj, _needSetMask);
- score += DressUpMenuItemDataManager.GetItemScore(value);
- }
- // int dressSuitId = DressUpMenuSuitDataManager.CheckCurDressIsSuit();
- // if (dressSuitId > 0) _suitId = dressSuitId;
- }
- private void Remove(int value)
- {
- if (_equipDatas == null)
- {
- return;
- }
- if (_equipDatas.Contains(value))
- {
- _equipDatas.Remove(value);
- DressUpUtil.RemoveItem(value, _sceneObj);
- score -= DressUpMenuItemDataManager.GetItemScore(value);
- }
- }
- /// <summary>
- /// 仅判断换装部件是否已穿着
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool CheckDressUpItemIsOn(int id)
- {
- if (id == _bgId)
- {
- return true;
- }
- return _equipDatas.Contains(id);
- }
- /// <summary>
- /// 仅判断套装是否穿上
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool CheckSuitIsOn(int id)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
- if (suitCfg == null)
- {
- return false;
- }
- int[] items = suitCfg.partsArr;
- foreach (int itemId in items)
- {
- bool isOn = CheckDressUpItemIsOn(itemId);
- if (!isOn)
- {
- return false;
- }
- }
- return true;
- }
- public void AddOrRemove(int value, bool checkDefault, bool isAdd = false, bool isRemove = false)
- {
- int subType = ItemUtilCS.GetItemSubType(value);
- if (subType == ConstDressUpItemType.BEI_JING)
- {
- _bgId = value;
- DressUpUtil.AddItem(_bgId, _sceneObj, _needSetMask);
- }
- else
- {
- if (!CheckDressUpItemIsOn(value))
- {
- if (!isRemove)
- {
- checkRemoveSameType(subType);
- Add(value);
- }
- }
- else
- {
- if (!isAdd)
- {
- Remove(value);
- }
- }
- if (checkDefault)
- {
- checkDefaultItem();
- }
- }
- }
- public void checkRemoveSameType(int type)
- {
- int count = 0;
- int firstTeshuId = 0;
- for (int i = 0; i < _equipDatas.Count; i++)
- {
- int itemID = (int)_equipDatas[i];
- int subType = ItemUtilCS.GetItemSubType(itemID);
- if (subType == type
- || (type == ConstDressUpItemType.LIAN_YI_QUN && (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA))
- || (type == ConstDressUpItemType.SHANG_YI && subType == ConstDressUpItemType.LIAN_YI_QUN)
- || (type == ConstDressUpItemType.XIA_ZHUANG && subType == ConstDressUpItemType.LIAN_YI_QUN)
- || (type == ConstDressUpItemType.NEI_DA && subType == ConstDressUpItemType.LIAN_YI_QUN))
- {
- Remove(itemID);
- i--;
- }
- if (subType > ConstDressUpItemType.TE_SHU)
- {
- if (count == 0)
- {
- firstTeshuId = itemID;
- }
- count++;
- }
- }
- if (type > ConstDressUpItemType.TE_SHU && count >= 3)
- {
- //特殊饰品最多穿三件,第四件会自动顶掉第一件
- Remove(firstTeshuId);
- }
- }
- private void checkDefaultItem()
- {
- if (!IsSuitPic)
- {
- //检查默认资源
- //是否有头发
- bool has1 = false;
- //是否有连衣裙
- bool has2 = false;
- //是否有内搭
- bool has3 = false;
- //是否有上衣
- // bool has4 = false;
- //是否有下装
- bool has5 = false;
- //是否有默认内搭
- // bool has30000 = false;
- //是否有默认下装
- // bool has50000 = false;
- for (int i = 0; i < _equipDatas.Count; i++)
- {
- int itemID = (int)_equipDatas[i];
- int subType = ItemUtilCS.GetItemSubType(itemID);
- if (subType == (int)ConstDressUpItemType.FA_XING)
- {
- has1 = true;
- }
- else if (subType == ConstDressUpItemType.LIAN_YI_QUN)
- {
- has2 = true;
- }
- else if (subType == ConstDressUpItemType.NEI_DA)
- {
- has3 = true;
- }
- else if (subType == ConstDressUpItemType.XIA_ZHUANG)
- {
- has5 = true;
- }
- }
- if (!has1)
- {
- Add(10000);
- }
- if (!has2)
- {
- if (!has5)
- {
- Add(50000);
- }
- if (!has3)
- {
- Add(30000);
- }
- }
- }
- }
- /// <summary>
- /// 检测是否穿戴完整(穿着连衣裙或同时穿着上装下装)
- /// </summary>
- /// <returns></returns>
- public bool CheckPutOnFinish()
- {
- List<int> equipDatas = EquipDataCache.cacher.equipDatas;
- bool isLianYiQun = false;
- bool isShangYi = false;
- bool isXiaZhuang = false;
- for (int i = 0; i < equipDatas.Count; i++)
- {
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(equipDatas[i]);
- if (itemCfg.subType == ConstDressUpItemType.LIAN_YI_QUN && itemCfg.id != ConstItemID.DEFULT_LIAN_YI_QUN)
- {
- isLianYiQun = true; break;
- }
- if (itemCfg.subType == ConstDressUpItemType.SHANG_YI && itemCfg.id != ConstItemID.DEFULT_NEI_DA)
- {
- isShangYi = true;
- }
- if (itemCfg.subType == ConstDressUpItemType.XIA_ZHUANG && itemCfg.id != ConstItemID.DEFULT_XIA_ZHUANG)
- {
- isXiaZhuang = true;
- }
- }
- return isLianYiQun || isXiaZhuang && isShangYi;
- }
- private void UpdatePicAction()
- {
- if (IsSuitPic)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
- DressUpUtil.UpdateBody(suitCfg.picRes, _sceneObj, !string.IsNullOrEmpty(suitCfg.aniRes), suitCfg.effRes);
- }
- else
- {
- DressUpUtil.UpdateBody(null, _sceneObj, false, null, _needSetMask);
- }
- }
- public void TakeOffAll(bool checkDefault = true)
- {
- _suitId = 0;
- _isPic = false;
- // AddOrRemove(propID, false, true);
- var tempList = equipDatas;
- foreach (int itemID in tempList)
- {
- AddOrRemove(itemID, false, false, true);
- }
- if (checkDefault)
- {
- checkDefaultItem();
- UpdatePicAction();
- }
- RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
- score = roleLevelCfg.baseScore;
- foreach (int itemId in _equipDatas)
- {
- score += DressUpMenuItemDataManager.GetItemScore(itemId);
- }
- }
- public void ChangeAction()
- {
- if (!HasSuitPicRes)
- {
- return;
- }
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
- _isPic = !_isPic;
- if (_isPic)
- {
- var tempList = equipDatas;
- foreach (int itemID in tempList)
- {
- if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
- {
- AddOrRemove(itemID, false, false, true);
- }
- }
- }
- else
- {
- int[] items = suitCfg.partsArr;
- foreach (int itemId in items)
- {
- if (!DressUpMenuItemDataManager.CheckIsSceneType(itemId))
- {
- AddOrRemove(itemId, false, true);
- }
- }
- }
- checkDefaultItem();
- UpdatePicAction();
- }
- public void TryCancelSuit(int itemID)
- {
- if (_suitId > 0)
- {
- if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
- {
- if (_isPic)
- {
- ChangeAction();
- }
- _suitId = 0;
- }
- }
- }
- public bool IsSuitPic
- {
- get
- {
- return _suitId > 0 && _isPic;
- }
- }
- public bool HasSuitPicRes
- {
- get
- {
- if (_suitId > 0)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
- if (suitCfg.picRes != null && suitCfg.picRes.Length > 0)
- {
- return true;
- }
- }
- return false;
- }
- }
- public void PutOnSuitCfg(int id, bool checkPic, bool noSceneType, int[] excludeType = null)
- {
- if (_suitId == id)
- {
- return;
- }
- TakeOffAll(false);
- _suitId = id;
- _isPic = HasSuitPicRes && checkPic;
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
- List<int> items = new List<int>(suitCfg.partsArr);
- if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
- {
- items.AddRange(suitCfg.partsOptionalArr);
- }
- int subType = 0;
- foreach (int itemID in items)
- {
- if (DressUpMenuItemDataManager.CheckHasItem(itemID))
- {
- bool isSceneType = DressUpMenuItemDataManager.CheckIsSceneType(itemID);
- subType = ItemUtilCS.GetItemSubType(itemID);
- if (!_isPic || isSceneType)
- {
- if (!noSceneType || !isSceneType)
- {
- if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
- {
- AddOrRemove(itemID, false, true);
- }
- }
- }
- }
- }
- checkDefaultItem();
- UpdatePicAction();
- }
- public void PutOnSuitSaved(int index)
- {
- TakeOffAll(false);
- CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
- if (suitSavedData.bg > 0)
- {
- AddOrRemove(suitSavedData.bg, false);
- }
- foreach (int itemID in suitSavedData.equipDatas)
- {
- AddOrRemove(itemID, false, true);
- }
- _suitId = suitSavedData.suitId;
- _isPic = suitSavedData.pic;
- checkDefaultItem();
- UpdatePicAction();
- }
- public void PutOnSuitSavedInFight(int index)
- {
- TakeOffAll(false);
- CustomSuitData suitSavedData = CustomSuitDataManager.GetSuitList(index);
- if (suitSavedData.suitId > 0)
- {
- PutOnSuitCfg(suitSavedData.suitId, false, true);
- }
- else
- {
- foreach (int itemID in suitSavedData.equipDatas)
- {
- if (!DressUpMenuItemDataManager.CheckIsSceneType(itemID))
- {
- AddOrRemove(itemID, false, true);
- }
- }
- checkDefaultItem();
- }
- }
- public void PutOnCurrentSuitSaved()
- {
- PutOnSuitSaved(CustomSuitDataManager.currentIndex);
- }
- public void PutOnDefaultSuitSaved(bool withBg = true)
- {
- TakeOffAll(false);
- CustomSuitData suitSavedData = CustomSuitDataManager.CreateDefaultSuitData(0);
- foreach (int itemID in suitSavedData.equipDatas)
- {
- AddOrRemove(itemID, false, true);
- }
- if (withBg)
- {
- if (suitSavedData.bg > 0)
- {
- AddOrRemove(suitSavedData.bg, false);
- }
- }
- checkDefaultItem();
- UpdatePicAction();
- }
- public void PutOnRecommendItems()
- {
- TakeOffAll(false);
- List<int> recommendList = DressUpMenuItemDataManager.GetRecommendItemList();
- StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
- StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
- //推荐搭配自动穿必穿品
- if (fightCfg.needItemId > 0 && DressUpMenuItemDataManager.CheckHasItem(fightCfg.needItemId) && recommendList.IndexOf(fightCfg.needItemId) < 0)
- {
- recommendList.Add(fightCfg.needItemId);
- }
- else if (fightCfg.needSuitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(fightCfg.needSuitId))
- {
- recommendList.Clear();
- SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
- recommendList.AddRange(cfg.partsArr);
- }
- foreach (int itemID in recommendList)
- {
- AddOrRemove(itemID, false, true);
- }
- checkDefaultItem();
- UpdatePicAction();
- }
- public bool CheckEquipedFightNeeded()
- {
- StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
- StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
- if (fightCfg.needItemId > 0)
- {
- return CheckDressUpItemIsOn(fightCfg.needItemId);
- }
- else if (fightCfg.needSuitId > 0)
- {
- return CheckSuitIsOn(fightCfg.needSuitId);
- }
- return true;
- }
- //根据位置原点和随机范围获取评分位置
- public void GetCirclePos(Vector2 pos, int range, out float x, out float y)
- {
- int numX = UnityEngine.Random.Range(0, 2);
- int signX = numX % 2 == 0 ? 1 : -1;
- float rangeX = UnityEngine.Random.Range(0, range);
- x = pos.x + signX * (rangeX);
- int numY = UnityEngine.Random.Range(0, 2);
- int signY = numY % 2 == 0 ? 1 : -1;
- float rangeY = UnityEngine.Random.Range(0, range);
- y = pos.y + signY * (rangeY);
- }
- public int GetItemIdBuyType(int subType)
- {
- for (int i = 0; i < equipDatas.Count; i++)
- {
- 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)
- {
- if (subType == ItemUtilCS.GetItemSubType(equipDatas[i]))
- {
- return equipDatas[i];
- }
- }
- }
- if (suitId > 0)
- {
- return suitId;
- }
- return 0;
- }
- }
- }
|