备份CatanBuilding瘦身独立工程
This commit is contained in:
233
Assets/Scripts/UI/RewardPopup/RewardFishBoxOpen.cs
Normal file
233
Assets/Scripts/UI/RewardPopup/RewardFishBoxOpen.cs
Normal file
@@ -0,0 +1,233 @@
|
||||
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<ItemData> itemDatas;
|
||||
}
|
||||
|
||||
public class RewardFishBoxOpen : MonoBehaviour
|
||||
{
|
||||
public RewardFishBox rewardFishBox;
|
||||
private SkeletonGraphic curAnimation;
|
||||
Tables tables;
|
||||
[SerializeField]
|
||||
private List<SkeletonGraphic> boxAnimations = new();
|
||||
[SerializeField] float _fxDelay, _fxDisappearDelay;
|
||||
|
||||
List<FishingBoxOpenData> fishingBoxOpenDatas = new List<FishingBoxOpenData>();
|
||||
FishingBoxDataProvier _dataProvider;
|
||||
PlayerItemData playerItemData;
|
||||
ItemData openData;
|
||||
public void Init(List<ItemData> openDatas)
|
||||
{
|
||||
if (openDatas == null || openDatas.Count == 0)
|
||||
{
|
||||
openData = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.openData = openDatas[0];
|
||||
}
|
||||
//开箱获得新鱼杆
|
||||
//GContext.container.Resolve<PlayerData>().StartAddNewRod();
|
||||
for (int i = 0; i < boxAnimations.Count; i++)
|
||||
{
|
||||
boxAnimations[i].gameObject.SetActive(false);
|
||||
}
|
||||
tables = GContext.container.Resolve<Tables>();
|
||||
playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||||
_dataProvider = GContext.container.Resolve<FishingBoxDataProvier>();
|
||||
|
||||
AddItem();
|
||||
OnClickClose(false);
|
||||
}
|
||||
|
||||
void AddItem()
|
||||
{
|
||||
Dictionary<int, int> FishingBoxs = new Dictionary<int, int>();
|
||||
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<int, int>();
|
||||
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<ItemData>();
|
||||
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<int> dropIds = new List<int>();
|
||||
List<ItemData> localDropItems = new List<ItemData>();
|
||||
for (int i = 0; i < boxCount; i++)
|
||||
{
|
||||
List<int> dropId = _dataProvider.GetFishingBoxDropID(boxID);
|
||||
//dropIds.AddRange(dropId);
|
||||
//List<ItemData> localDropItems = playerItemData.GetItemDataByDropList(dropIds);
|
||||
localDropItems.AddRange(playerItemData.GetItemDataByDropList(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 || item.SubType == 7))
|
||||
{
|
||||
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);
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("item_change", gaSend: false))
|
||||
{
|
||||
e.AddContent("item_id", boxID)
|
||||
.AddContent("state_info", "cost")
|
||||
.AddContent("change_num", boxCount);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ShowAll()
|
||||
{
|
||||
var dropItems = new List<ItemData>();
|
||||
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<PlayerData>().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<TMP_Text>().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<ItemData> dropItems)
|
||||
{
|
||||
rewardFishBox.isFly = true;
|
||||
rewardFishBox.gameObject.SetActive(true);
|
||||
rewardFishBox.OnClickClose = NextShow;
|
||||
rewardFishBox.InitAsync(dropItems);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user