| | |
| | | { |
| | | public const int TotleEquip = 12; //装备栏大小 |
| | | public bool waitEquipOPPack = false; // 穿戴装备的操作 不含分解 |
| | | public float waitEquipOPTime = 0; |
| | | public event Action<bool, int> OnEquipOPResultAction; //是否换上了新装备且分解了 装备索引 |
| | | public event Action<List<int>, RectTransform> OnItemDropEvent; |
| | | public event Action<BattleDrops> OnItemDropEvent; |
| | | |
| | | //用于飘动逻辑 |
| | | // public Dictionary<int, EquipOnFloorInfo> equipFloorInfo = new Dictionary<int, EquipOnFloorInfo>(); //真实背包的索引,对应地板装备的信息 |
| | |
| | | public int[] equipUIGirdEffects; //装备格子特效 |
| | | public ItemModel selectFloorEquip; //选中的地板装备 |
| | | public int lastShowEquipIndex = -1; //上一次界面显示装备的索引,拾取后物品消失需记录下做表现 |
| | | public Queue<int> waitEquipOP = new Queue<int>(); //等待操作的装备,需要和UI交互确认 不含分解 |
| | | public Queue<string> waitEquipOP = new Queue<string>(); //等待操作的装备,需要和UI交互确认 不含分解 |
| | | |
| | | public List<int> lastDropIndexs = new List<int>(); //上一次掉落物品索引 |
| | | |
| | | int lastAttackHeroID = 0; |
| | | |
| | | public override void Init() |
| | | { |
| | | DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnEquipResult; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += BeforePlayerDataInitialize; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerDataInitialize; |
| | | EventBroadcast.Instance.AddListener<string, BattleDrops, Action>(EventName.BATTLE_DROP_ITEMS, OnDropEvent); |
| | | EventBroadcast.Instance.AddListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnSkillCast); |
| | | EventBroadcast.Instance.AddListener<string>(EventName.RECORDPLAYER_END, RecordPlayerEnd); |
| | | GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; |
| | | ParseConfig(); |
| | | } |
| | | |
| | | public override void Release() |
| | | { |
| | | DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnEquipResult; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= BeforePlayerDataInitialize; |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= BeforePlayerDataInitialize; |
| | | EventBroadcast.Instance.RemoveListener<string, BattleDrops, Action>(EventName.BATTLE_DROP_ITEMS, OnDropEvent); |
| | | EventBroadcast.Instance.RemoveListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnSkillCast); |
| | | EventBroadcast.Instance.RemoveListener<string>(EventName.RECORDPLAYER_END, RecordPlayerEnd); |
| | | GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | void BeforePlayerDataInitialize() |
| | | { |
| | | if (UIManager.Instance.IsOpened<EquipExchangeWin>()) |
| | | { |
| | | //先关闭,后续再处理掉落 |
| | | UIManager.Instance.CloseWindow<EquipExchangeWin>(); |
| | | } |
| | | selectFloorEquip = null; |
| | | waitEquipOP.Clear(); |
| | | lastShowEquipIndex = -1; |
| | | lastDropIndexs.Clear(); |
| | | waitEquipOPPack = false; |
| | | } |
| | | |
| | | |
| | |
| | | return -1; |
| | | } |
| | | |
| | | //表现掉落和拾取分离开,先掉落等本武将回合完全结束再拾取 |
| | | void OnDropEvent(string guid, BattleDrops drops, Action action) |
| | | { |
| | | if (!string.IsNullOrEmpty(guid)) |
| | | return; |
| | | |
| | | lastDropIndexs = drops.dropItemPackIndex; |
| | | // lastDropIndexs = drops.dropItemPackIndex; |
| | | // Debug.Log("-掉落装备 " + lastDropIndexs.Count + " 个" + JsonMapper.ToJson(lastDropIndexs)); |
| | | NotifyItemDrop(drops.dropItemPackIndex, drops.rectTransform); |
| | | NotifyItemDrop(drops); |
| | | action?.Invoke(); |
| | | } |
| | | |
| | | //拾取时机为下一武将(含敌我)攻击 或者 本轮结算(MainFightRequest 前) |
| | | void OnSkillCast(string guid, SkillConfig skillConfig, TeamHero teamHero) |
| | | { |
| | | bool checkDrop = false; |
| | | if (!string.IsNullOrEmpty(guid)) |
| | | return; |
| | | |
| | | //防范回收报错 |
| | | if (teamHero == null) |
| | | checkDrop = true; |
| | | //只通知玩家武将的战斗 |
| | | else if (teamHero.NPCID != 0) |
| | | checkDrop = true; |
| | | else if (teamHero.heroId != lastAttackHeroID) |
| | | { |
| | | lastAttackHeroID = teamHero.heroId; |
| | | checkDrop = true; |
| | | } |
| | | |
| | | if (checkDrop) |
| | | { |
| | | // CalcAllFloorItems(); |
| | | } |
| | | } |
| | | |
| | | |
| | | void RecordPlayerEnd(string guid) |
| | | { |
| | | if (!string.IsNullOrEmpty(guid)) |
| | | return; |
| | | |
| | | CalcAllFloorItems(); |
| | | } |
| | | |
| | | |
| | | //掉落通知 |
| | | public void NotifyItemDrop(List<int> indexs, RectTransform rect) |
| | | public void NotifyItemDrop(BattleDrops drops)//(List<int> indexs, RectTransform rect) |
| | | { |
| | | // 界面不显示则立即处理 |
| | | if (!UIManager.Instance.IsOpened<HomeWin>()) |
| | | { |
| | | for (int i = 0; i < indexs.Count; i++) |
| | | { |
| | | CalcFloorEquip(indexs[i]); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | OnItemDropEvent?.Invoke(indexs, rect); |
| | | } |
| | | // if (!UIManager.Instance.IsOpened<HomeWin>()) |
| | | // { |
| | | // for (int i = 0; i < indexs.Count; i++) |
| | | // { |
| | | // CalcFloorEquip(indexs[i]); |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // OnItemDropEvent?.Invoke(indexs, rect); |
| | | // } |
| | | OnItemDropEvent?.Invoke(drops); |
| | | } |
| | | |
| | | public void CalcFloorEquip(int itemIndex) |
| | | { |
| | | if (itemIndex == -1) |
| | | { |
| | | Debug.Log("CalcFloorEquip 无效的物品索引"); |
| | | return; |
| | | } |
| | | |
| | | var item = PackManager.Instance.GetItemByIndex(PackType.DropItem, itemIndex); |
| | | if (item == null) |
| | | { |
| | | Debug.Log("CalcFloorEquip 无效的物品索引"); |
| | | return; |
| | | |
| | | } |
| | | |
| | | //非自动模式下,筛选装备打开装备操作界面 |
| | | if (IsEquip(item)) |
| | |
| | | } |
| | | } |
| | | |
| | | bool needMoreDrop = false; //由于掉落挤压导致,满掉落掉落背包的时候处理后再主动请求掉落 |
| | | //处理所有掉落的物品 |
| | | public void CalcAllFloorItems() |
| | | { |
| | | |
| | | var items = PackManager.Instance.GetItems(PackType.DropItem); |
| | | if (items.IsNullOrEmpty()) |
| | | return; |
| | | |
| | | int cnt = items.Count; |
| | | needMoreDrop = cnt == 20; |
| | | |
| | | //构建所有物品 |
| | | foreach (var item in items) |
| | | { |
| | | CalcFloorEquip(item.gridIndex); |
| | | } |
| | | if (needMoreDrop) |
| | | { |
| | | SendEquipOP(null, 3); |
| | | needMoreDrop = false; |
| | | } |
| | | } |
| | | |
| | | |
| | | void OnSecondEvent() |
| | | { |
| | | if (waitEquipOPPack && Time.time - waitEquipOPTime > 2) |
| | | { |
| | | //避免装备卡死无法继续主线 |
| | | waitEquipOPPack = false; |
| | | } |
| | | } |
| | | |
| | | private void OnEquipResult(HA814_tagMCMakeItemAnswer info) |
| | | { |
| | | if (info.MakeType != (int)MakeType.EquipOP) |
| | |
| | | return; |
| | | |
| | | if (info.MakeValue == 2) |
| | | { |
| | | waitEquipOPPack = false; |
| | | Debug.LogWarning("穿戴装备,服务器响应解除等待状态"); |
| | | } |
| | | bool isDone = false; // 换上新装备且分解了旧装备 |
| | | //选中的地板装备进行处理,替换还是找下一件,检查OnEquipOPResultAction |
| | | if (selectFloorEquip != null) |
| | |
| | | UIManager.Instance.CloseWindow<EquipExchangeWin>(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (!UIManager.Instance.IsOpened<EquipExchangeWin>()) |
| | | { |
| | | UIManager.Instance.OpenWindow<EquipExchangeWin>(); |
| | | } |
| | | } |
| | | // else |
| | | // { |
| | | // // if (!UIManager.Instance.IsOpened<EquipExchangeWin>()) |
| | | // // { |
| | | // // UIManager.Instance.OpenWindow<EquipExchangeWin>(); |
| | | // // } |
| | | |
| | | // //继续处理下一件装备 重新判断 |
| | | // CalcFloorEquip(selectFloorEquip.gridIndex); |
| | | // } |
| | | |
| | | OnEquipOPResultAction?.Invoke(isDone, lastShowEquipIndex); |
| | | } |
| | |
| | | /// <param name="autoDecompose"></param> |
| | | public void SendEquipOP(ushort[] itemIndexList, byte opType, bool autoDecompose = false) |
| | | { |
| | | if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin) |
| | | { |
| | | return; |
| | | } |
| | | if (opType == 2 && waitEquipOPPack) return; |
| | | |
| | | // NoteFloorEquip(itemIndexList, opType); |
| | | var pack = new CB415_tagCSMainDropItemOP(); |
| | | pack.Count = (byte)itemIndexList.Length; |
| | | pack.IndexList = itemIndexList; |
| | | if (itemIndexList != null) |
| | | { |
| | | pack.Count = (byte)itemIndexList.Length; |
| | | pack.IndexList = itemIndexList; |
| | | } |
| | | pack.OPType = opType; |
| | | pack.OPValue = (byte)(autoDecompose ? 1 : 0); // 替换后是否自动分解原装备:0否1是 |
| | | |
| | | if (opType == 2) |
| | | { |
| | | waitEquipOPPack = true; |
| | | waitEquipOPTime = Time.time; |
| | | Debug.LogWarning("穿戴装备,向服务器请求"); |
| | | } |
| | | |
| | | //记录销毁或替换前的装备 |
| | | if ((opType == 1 || opType == 2) && !itemIndexList.IsNullOrEmpty()) |
| | | { |
| | | foreach (var index in itemIndexList) |
| | | { |
| | | ItemModel newEquip = PackManager.Instance.GetItemByIndex(PackType.DropItem, index); |
| | | if (newEquip == null) |
| | | continue; |
| | | int equipPlace = newEquip.config.EquipPlace - 1; |
| | | ItemModel oldEquip = PackManager.Instance.GetItemByIndex(PackType.Equip, equipPlace); |
| | | EquipRecordManager.Instance.AddRecord(opType, newEquip, oldEquip); |
| | | } |
| | | } |
| | | GameNetSystem.Instance.SendInfo(pack); |
| | | } |
| | | |
| | |
| | | public bool OpenEquipExchangeWin(ItemModel equip) |
| | | { |
| | | if (equip == null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // if (!IsEquip(equip)) |
| | | // return false; |
| | |
| | | } |
| | | |
| | | // 好几件装备需要处理的情况存起来 |
| | | waitEquipOP.Enqueue(equip.gridIndex); |
| | | if (!waitEquipOP.Contains(equip.guid)) |
| | | { |
| | | //检测时机频繁,导致重复推送,需要检测过滤,对应Dequeue 也做一次检测 |
| | | waitEquipOP.Enqueue(equip.guid); |
| | | } |
| | | //未回复装备操作结果,否则会显示旧装备 |
| | | if (waitEquipOPPack) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // 后续补充引导或者其他情况下,不允许切换装备界面 |
| | | // if (NewBieCenter.Instance.inGuiding) |
| | | // return; |
| | | |
| | | if (UIManager.Instance.IsOpened<EquipExchangeWin>()) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | selectFloorEquip = GetSelectFloorEquip(); |
| | | if (selectFloorEquip == null) |
| | | { |
| | | return false; |
| | | |
| | | } |
| | | UIManager.Instance.OpenWindow<EquipExchangeWin>(); |
| | | return true; |
| | | |
| | |
| | | |
| | | // 新手引导中,不允许切换装备界面 |
| | | if (NewBieCenter.Instance.inGuiding) |
| | | { |
| | | Debug.LogWarning("GetSelectFloorEquip: 新手引导中,不允许切换装备界面"); |
| | | return null; |
| | | } |
| | | |
| | | return PackManager.Instance.GetItemByIndex(PackType.DropItem, waitEquipOP.Dequeue()); |
| | | string activeBattleName = BattleManager.Instance.GetActiveBattleName(); |
| | | if (activeBattleName != "" && activeBattleName != "StoryBattleField") |
| | | { |
| | | Debug.LogWarning("非主线战斗不弹窗"); |
| | | return null; |
| | | } |
| | | |
| | | var item = PackManager.Instance.GetItemByGuid(waitEquipOP.Dequeue()); |
| | | if (item != null && item.packType == PackType.DropItem) |
| | | { |
| | | return item; |
| | | } |
| | | // Debug.LogError("GetSelectFloorEquip: 没有找到可选装备, 该装备已经转移"); |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | return equip.GetUseData(23); |
| | | } |
| | | |
| | | //战斗属性ID列表 |
| | | //装备战斗属性ID列表, 如果是卦玉的话基础和战斗都放一起 |
| | | public List<int> GetEquipFightAttrs(ItemModel equip) |
| | | { |
| | | if (equip == null) |
| | |
| | | return equip.GetUseData(19); |
| | | } |
| | | |
| | | //技能ID列表 |
| | | public List<int> GetEquipSkillIDs(ItemModel equip) |
| | | { |
| | | if (equip == null) |
| | | { |
| | | return new List<int>(); |
| | | } |
| | | return equip.GetUseData(37); |
| | | } |
| | | |
| | | public int GetEquipSkillID(ItemModel equip) |
| | | { |
| | | if (equip == null) |
| | | { |
| | | return 0; |
| | | } |
| | | var _list = equip.GetUseData(37); |
| | | return _list.IsNullOrEmpty() ? 0 : _list[0]; |
| | | } |
| | | |
| | | |
| | | //得到装备位对应的部位名称 |
| | | public string GetEquipPlaceName(int place) |
| | | { |
| | | |
| | | return Language.Get("equipPlace" + place); |
| | | return Language.Get(string.Concat("equipPlace", place)); |
| | | } |
| | | |
| | | //是否装备 |
| | |
| | | } |
| | | |
| | | public ItemModel GetEquip(int index) |
| | | { |
| | | { |
| | | return PackManager.Instance.GetItemByIndex(PackType.Equip, index); |
| | | } |
| | | } |