using asap.core; using cfg; using game; using Game; using GameCore; using Spine.Unity; using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; public class FishingBoxOpenData { public int id; public int count; public List itemDatas; } public class RewardFishBoxOpen : MonoBehaviour { public RewardFishBox rewardFishBox; private SkeletonGraphic curAnimation; Tables tables; [SerializeField] private List boxAnimations = new(); [SerializeField] float _fxDelay, _fxDisappearDelay; List fishingBoxOpenDatas = new List(); FishingBoxDataProvier _dataProvider; PlayerItemData playerItemData; ItemData openData; public void Init(List openDatas) { if (openDatas == null || openDatas.Count == 0) { openData = null; } else { this.openData = openDatas[0]; } //开箱获得新鱼杆 //GContext.container.Resolve().StartAddNewRod(); for (int i = 0; i < boxAnimations.Count; i++) { boxAnimations[i].gameObject.SetActive(false); } tables = GContext.container.Resolve(); playerItemData = GContext.container.Resolve(); _dataProvider = GContext.container.Resolve(); AddItem(); OnClickClose(false); } void AddItem() { Dictionary FishingBoxs = new Dictionary(); if (openData != null) { int count = _dataProvider.Data.GetFishingBoxCount(openData.id); if (count < openData.count) { openData.count = count; } FishingBoxs[openData.id] = (int)openData.count; } else { FishingBoxs = _dataProvider.Data.FishingNewBoxs; } int allCount = 0; var localFishingBoxCount = new Dictionary(); foreach (var box in FishingBoxs) { var boxCount = box.Value; if (boxCount > 0) { var boxID = box.Key; localFishingBoxCount[boxID] = boxCount; allCount += boxCount; } } if (allCount == 0) { GContext.Publish(new ShowData(RewardType.Destroy)); return; } var dropItems = new List(); var items = tables.TbItem.DataMap; foreach (var box in localFishingBoxCount) { var boxCount = box.Value; var boxID = box.Key; _dataProvider.Data.SetFishingBoxCount(boxID, -boxCount); //_dataProvider.SetBoxRewardScore(boxID, openCount); //List dropIds = new List(); List localDropItems = new List(); for (int i = 0; i < boxCount; i++) { List dropId = _dataProvider.GetFishingBoxDropID(boxID); //dropIds.AddRange(dropId); //List localDropItems = playerItemData.GetItemDataByDropList(dropIds); localDropItems.AddRange(playerItemData.GetMergedItemDataByDropList(dropId)); } int count = localDropItems.Count; //Convert Random Rod To A Rod for (int i = 0; i < count; i++) { var item = items[localDropItems[i].id]; if (item.Type == 9 && (item.SubType == 4 || item.SubType == 1 || item.SubType == 3)) { var newItem = playerItemData.GetItemDropPackageItemList(item.RedirectID, localDropItems[i].count)[0]; localDropItems[i] = newItem; } } dropItems.AddRange(localDropItems); FishingBoxOpenData data = new FishingBoxOpenData(); fishingBoxOpenDatas.Add(data); data.id = boxID; data.count = boxCount; data.itemDatas = localDropItems; //Add To ItemData playerItemData.AddItem(localDropItems, null); #if AGG using (var e = GEvent.GameEvent("item_change", gaSend: true)) { e.AddContent("item_id", boxID) .AddContent("state_info", "cost") .AddContent("change_num", boxCount); } #endif } } void ShowAll() { var dropItems = new List(); for (int i = 0; i < fishingBoxOpenDatas.Count; i++) { dropItems.AddRange(fishingBoxOpenDatas[i].itemDatas); } fishingBoxOpenDatas.Clear(); rewardFishBox.btn_close.gameObject.SetActive(true); rewardFishBox.btn_next.gameObject.SetActive(false); rewardFishBox.btn_all.gameObject.SetActive(false); InitAsync(dropItems); } void NextShow(bool isAllOpen) { OnClickClose(isAllOpen); } void OnClickClose(bool isAllOpen) { if (fishingBoxOpenDatas.Count == 0) { //获得新鱼杆展示 //GContext.container.Resolve().ShowNewRod(); GContext.Publish(new ShowData(RewardType.Destroy)); GContext.Publish(new ResAddEvent(1002)); return; } if (isAllOpen) { ShowAll(); return; } rewardFishBox.btn_close.gameObject.SetActive(fishingBoxOpenDatas.Count == 1); rewardFishBox.btn_next.gameObject.SetActive(fishingBoxOpenDatas.Count > 1); rewardFishBox.btn_all.gameObject.SetActive(fishingBoxOpenDatas.Count > 2); StartCoroutine(PlayOpenOn()); } IEnumerator PlayOpenOn() { //打开全部开启按钮 //隐藏下一个按钮 if (curAnimation != null) { curAnimation.gameObject.SetActive(false); } FishingBoxOpenData data = fishingBoxOpenDatas[0]; Item boxItem = tables.TbItem.GetOrDefault(data.id); curAnimation = boxAnimations[boxItem.Quality]; Transform bg_num = curAnimation.transform.Find("bg_num"); bg_num.gameObject.SetActive(data.count > 1); if (data.count > 1) { bg_num.Find("text_num").GetComponent().text = $"x{data.count}"; } curAnimation.gameObject.SetActive(true); curAnimation.AnimationState.SetAnimation(0, "Show01", false); yield return new WaitForSeconds(0.333f); fishingBoxOpenDatas.RemoveAt(0); curAnimation.AnimationState.SetAnimation(0, boxItem.Quality > 2 ? "Open01" : "Open02", false); GContext.Publish(new EventUISound("audio_ui_box_open")); //Debug.Log($"Animation Open Played! Idx: {curAnimationIdx}"); yield return new WaitForSeconds(_fxDelay); GameObject fx = curAnimation.transform.GetChild(0).gameObject; fx.SetActive(false); fx.SetActive(true); yield return new WaitForSeconds(_fxDisappearDelay - _fxDelay); fx.SetActive(false); if (curAnimation != null) { curAnimation.gameObject.SetActive(false); } //下一个按钮打开 InitAsync(data.itemDatas); } void InitAsync(List dropItems) { rewardFishBox.gameObject.SetActive(true); rewardFishBox.OnClickClose = NextShow; rewardFishBox.InitAsync(dropItems); } }