331 lines
12 KiB
C#
331 lines
12 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BombBuildingDataEvent
|
|
{
|
|
public BombBuildingDataEvent(int index = -1)
|
|
{
|
|
this.index = index;
|
|
}
|
|
public int index;
|
|
|
|
public BombBuilding bombBuilding;
|
|
public Transform[] bombPos;
|
|
}
|
|
public class EventIslandBombHeistPanel : BasePanel
|
|
{
|
|
Tables _tables;
|
|
Head head;
|
|
Button switchbtn;
|
|
GameObject exchange;
|
|
TMP_Text text_name;
|
|
TMP_Text text_beilv;
|
|
Transform frame_bomb;
|
|
List<BombHeistTargetItem> targetItems = new List<BombHeistTargetItem>();
|
|
bool isClick = false;
|
|
int multiple;
|
|
bool is_double_cash = false;
|
|
float allExtraPoint;
|
|
//目标位置
|
|
Vector3 targetPos;
|
|
int selectIndex = 0;
|
|
BombBuildingDataEvent bombBuilding;
|
|
List<ItemData> itemDatas;
|
|
//int curRankCount;
|
|
int addRankCount;
|
|
FishingEventData _fishingEventData;
|
|
BombGamePlay bombGamePlay;
|
|
SmallGameData smallGameData;
|
|
string playFabId;
|
|
bool isGuided = false;
|
|
float superBombCashBonus = 0;
|
|
private void Awake()
|
|
{
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
_fishingEventData = GContext.container.Resolve<FishingEventData>();
|
|
smallGameData = GContext.container.Resolve<SmallGameData>();
|
|
frame_bomb = transform.Find("root/frame_bomb");
|
|
text_name = transform.Find("root/title/bg/text_name").GetComponent<TMP_Text>();
|
|
head = transform.Find("root/title/btn_head").GetComponent<Head>();
|
|
switchbtn = transform.Find("root/switch/btn_switch/btn_green").GetComponent<Button>();
|
|
exchange = transform.Find("root/switch").gameObject;
|
|
text_beilv = transform.Find("root/text_beilv").GetComponent<TMP_Text>();
|
|
text_beilv.gameObject.SetActive(false);
|
|
BombHeistTargetItem item;
|
|
for (int i = 1; i < 6; i++)
|
|
{
|
|
item = transform.Find($"root/target{i}").GetComponent<BombHeistTargetItem>();
|
|
targetItems.Add(item);
|
|
}
|
|
frame_bomb.gameObject.SetActive(false);
|
|
isGuided = GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("EventIslandBombHeistPanel");
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
//bool isRankInit = _fishingEventData.rankInit != null;
|
|
//if (isRankInit)
|
|
//{
|
|
// curRankCount = (int)GContext.container.Resolve<PlayerItemData>().GetItemCount(_fishingEventData.rankInit.TokenID);
|
|
//}
|
|
|
|
multiple = GContext.container.Resolve<PlayerData>().GetMagnification();
|
|
if (multiple > 1)
|
|
{
|
|
text_beilv.text = $"x{multiple}";
|
|
}
|
|
}
|
|
protected override void Start()
|
|
{
|
|
SuperBomb superBomb = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<SuperBomb>(true);
|
|
if (superBomb != null)
|
|
{
|
|
superBombCashBonus = superBomb.CashBonus;
|
|
}
|
|
base.Start();
|
|
for (int i = 0; i < targetItems.Count; i++)
|
|
{
|
|
targetItems[i].Init(i, OnClickItem);
|
|
targetItems[i].gameObject.SetActive(false);
|
|
}
|
|
GContext.OnEvent<ChangeSmallGameTargetEvent>().Subscribe(ChangeSmallGameTarget).AddTo(disposables);
|
|
playFabId = smallGameData.opponentData.playFabID;
|
|
GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar).AddTo(disposables);
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
|
|
SetAvatar(clubPlayInfo);
|
|
//text_name.text = LocalizationMgr.GetFormatTextValue("UI_EventIslandBombHeistPanel_1", smallGameData.opponentData.playName);
|
|
//head.SetData(smallGameData.opponentData.url);
|
|
switchbtn.onClick.AddListener(OnClickHead);
|
|
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("specialevent_bomb"))
|
|
{
|
|
}
|
|
#endif
|
|
StartCoroutine(Show());
|
|
}
|
|
|
|
IEnumerator Show()
|
|
{
|
|
float time = 0.5f;
|
|
if (isGuided)
|
|
{
|
|
time = 2f;
|
|
}
|
|
yield return new WaitForSeconds(time);
|
|
SetBombBuilding();
|
|
}
|
|
void SetBombBuilding()
|
|
{
|
|
bombBuilding = new BombBuildingDataEvent();
|
|
GContext.Publish(bombBuilding);
|
|
for (int i = 0; i < bombBuilding.bombPos.Length; i++)
|
|
{
|
|
targetItems[i].gameObject.SetActive(true);
|
|
targetItems[i].transform.localPosition = ConvertTools.WorldToScreenPoint(bombBuilding.bombPos[i].position);
|
|
}
|
|
}
|
|
private void Update()
|
|
{
|
|
if (bombBuilding != null)
|
|
{
|
|
for (int i = 0; i < bombBuilding.bombPos.Length; i++)
|
|
{
|
|
targetItems[i].gameObject.SetActive(true);
|
|
targetItems[i].transform.localPosition = ConvertTools.WorldToScreenPoint(bombBuilding.bombPos[i].position);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool isShowing = false;
|
|
async void OnClickHead()
|
|
{
|
|
if (isClick)
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_20"));
|
|
}
|
|
else if (!isShowing)
|
|
{
|
|
isShowing = true;
|
|
//选择对象
|
|
await UIManager.Instance.ShowUI(UITypes.EventBankHeistOpponentPopupPanel);
|
|
isShowing = false;
|
|
}
|
|
|
|
}
|
|
void OnClickItem(int index)
|
|
{
|
|
//GContext.Publish(new VibrationData(HapticTypes.Selection));
|
|
|
|
selectIndex = index;
|
|
isClick = true;
|
|
exchange.SetActive(false);
|
|
GContext.Publish(new BombBuildingDataEvent(index));
|
|
//炮弹路径
|
|
for (int i = 0; i < targetItems.Count; i++)
|
|
{
|
|
targetItems[i].OnSelect(i == index);
|
|
}
|
|
SetData();
|
|
PlayAni();
|
|
}
|
|
void SetData()
|
|
{
|
|
List<BombInit> bombInits = _tables.TbBombInit.DataList;
|
|
List<BombGamePlay> bombGamePlays = _tables.TbBombGamePlay.DataList;
|
|
bombGamePlay = bombGamePlays[0];
|
|
if (GContext.container.Resolve<IStageData>().IsRewardSettlement && GContext.container.Resolve<SmallGameData>().BombGameCount < bombInits.Count)
|
|
{
|
|
int gameType = bombInits[GContext.container.Resolve<SmallGameData>().BombGameCount].Type;
|
|
bombGamePlay = _tables.TbBombGamePlay.GetOrDefault(gameType);
|
|
}
|
|
else
|
|
{
|
|
int allWeight = 0;
|
|
for (int i = 0; i < bombGamePlays.Count; i++)
|
|
{
|
|
allWeight += bombGamePlays[i].Weight;
|
|
}
|
|
int random = Random.Range(0, allWeight);
|
|
int weight = 0;
|
|
for (int i = 0; i < bombGamePlays.Count; i++)
|
|
{
|
|
weight += bombGamePlays[i].Weight;
|
|
if (random <= weight)
|
|
{
|
|
bombGamePlay = bombGamePlays[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
itemDatas = new List<ItemData>();
|
|
ItemData itemData;
|
|
int dataIndex = 0;
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataOne(bombGamePlays[i].Reward);
|
|
itemData.count = (int)(itemData.count * smallGameData.opponentData.power);
|
|
if (bombGamePlay.ID == bombGamePlays[i].ID)
|
|
{
|
|
dataIndex = i;
|
|
}
|
|
itemData.count = (int)(itemData.count * (1 + superBombCashBonus));
|
|
itemDatas.Add(itemData);
|
|
}
|
|
itemData = itemDatas[selectIndex];
|
|
itemDatas[selectIndex] = itemDatas[dataIndex];
|
|
itemDatas[dataIndex] = itemData;
|
|
}
|
|
async void PlayAni()
|
|
{
|
|
await Awaiters.Seconds(5f);
|
|
frame_bomb.gameObject.SetActive(false);
|
|
|
|
targetItems[selectIndex].MainShowData(itemDatas[selectIndex]);
|
|
await Awaiters.Seconds(0.5f);
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
if (i != selectIndex)
|
|
{
|
|
targetItems[i].ShowData(itemDatas[i]);
|
|
await Awaiters.Seconds(0.2f);
|
|
}
|
|
}
|
|
GContext.Publish(new VibrationData(HapticTypes.HeavyImpact));
|
|
await Awaiters.Seconds(0.5f);
|
|
if (multiple > 1)
|
|
{
|
|
bombBuilding.bombBuilding.cannonRoot.text_beilv.gameObject.SetActive(false);
|
|
text_beilv.gameObject.SetActive(true);
|
|
targetPos = targetItems[selectIndex].transform.position;
|
|
text_beilv.transform.DOMove(targetPos, 0.5f);
|
|
await Awaiters.Seconds(0.5f);
|
|
text_beilv.gameObject.SetActive(false);
|
|
//翻倍
|
|
targetItems[selectIndex].Multiply(itemDatas[selectIndex], multiple);
|
|
await Awaiters.Seconds(1.3f);
|
|
}
|
|
|
|
//结算
|
|
UIManager.Instance.DestroyUI(UITypes.EventBankHeistOpponentPopupPanel);
|
|
|
|
if (_fishingEventData.rankInit != null)
|
|
{
|
|
int point = _fishingEventData.rankInit.PointDestruction[^bombGamePlay.Type] * multiple;
|
|
addRankCount += point;
|
|
|
|
_fishingEventData.AddRankTarget(point);
|
|
}
|
|
int getGlodCount = (int)itemDatas[selectIndex].count;// * multiple;
|
|
GContext.Publish(new ConditionTypeEvent(ConditionType.MaxCashFromBomb, getGlodCount));
|
|
int glodCount = getGlodCount * multiple;
|
|
GContext.container.Resolve<PlayerItemData>().AddItemCount(1002, glodCount);
|
|
smallGameData.SetEnemy(EnemyType.Bomb, glodCount);
|
|
GContext.Publish(new ConditionTypeEvent(ConditionType.CashFromBomb, glodCount));
|
|
GContext.Publish(new BombBuildingDataEvent(-2));
|
|
GContext.container.Resolve<SmallGameData>().SaveBombGameCount();
|
|
GContext.Publish(new ConditionTypeEvent(ConditionType.DoBomb, 1));
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("special_event"))
|
|
{
|
|
e.AddContent("special_event_multiple", multiple)
|
|
.AddContent("finish_times", GContext.container.Resolve<SmallGameData>().BombGameCount)
|
|
.AddContent("item_id", 1002)
|
|
.AddContent("reward_cash", glodCount)
|
|
.AddContent("event_type", 2);
|
|
}
|
|
using (var e = GEvent.GameEvent("bomb_camp"))
|
|
{
|
|
e.AddContent("fish_multiple", multiple)
|
|
.AddContent("map_id", GContext.container.Resolve<PlayerData>().currentMapId)
|
|
.AddContent("bomb_user_id", smallGameData.opponentData.playFabID)
|
|
.AddContent("bomb_map_id", smallGameData.opponentData.BombID)
|
|
.AddContent("reward_cash", glodCount);
|
|
}
|
|
#endif
|
|
|
|
var go = await UIManager.Instance.GetUIAsync(UITypes.EventBankHeistRewardPanel);
|
|
EventBankHeistRewardPanel eventBankHeistRewardPanel = go.GetComponent<EventBankHeistRewardPanel>();
|
|
eventBankHeistRewardPanel.SetData(glodCount, superBombCashBonus, addRankCount);
|
|
}
|
|
|
|
async void ChangeSmallGameTarget(ChangeSmallGameTargetEvent data)
|
|
{
|
|
bombBuilding = null;
|
|
playFabId = data.opponentItemData.playFabID;
|
|
await data.ts.Task;
|
|
//text_name.text = LocalizationMgr.GetFormatTextValue("UI_EventIslandBombHeistPanel_1", data.opponentItemData.playName);
|
|
//head.SetData(data.opponentItemData.url);
|
|
SetBombBuilding();
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
|
|
SetAvatar(clubPlayInfo);
|
|
}
|
|
|
|
public void SetAvatar(PlayInfo clubPlayInfo)
|
|
{
|
|
if (clubPlayInfo != null)
|
|
{
|
|
text_name.text = LocalizationMgr.GetFormatTextValue("UI_EventIslandBombHeistPanel_1", clubPlayInfo.name);
|
|
head.SetData(clubPlayInfo.avatarUrl);
|
|
}
|
|
}
|
|
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
|
|
{
|
|
if (getClubPlayInfoEvent.id == playFabId)
|
|
{
|
|
text_name.text = LocalizationMgr.GetFormatTextValue("UI_EventIslandBombHeistPanel_1", getClubPlayInfoEvent.name);
|
|
head.SetData(getClubPlayInfoEvent.avatarUrl);
|
|
}
|
|
}
|
|
}
|