382 lines
15 KiB
C#
382 lines
15 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
using System.Linq;
|
|
using DG.Tweening;
|
|
using System.Collections;
|
|
|
|
public class EventFishingDuelRewardPanel : BasePanel
|
|
{
|
|
Tables tables;
|
|
FishingDuelManager FDM;
|
|
Image img_map;
|
|
TMP_Text text_map;
|
|
Button btn_claim;
|
|
Button btn_confirm;
|
|
GameObject winner_tag_my;
|
|
GameObject winner_tag;
|
|
Transform root;
|
|
|
|
DuelMatchPlayer myself;
|
|
DuelMatchPlayer enemy;
|
|
|
|
TMP_Text text_change_my;
|
|
TMP_Text text_change;
|
|
|
|
Button btn_chat;
|
|
GameObject chat;
|
|
GameObject title_reward;
|
|
Transform layout_reward;
|
|
List<RewardItemNew> rewardItemNews;
|
|
|
|
bool isWin;
|
|
IUIService uiService;
|
|
int trophy_before;
|
|
|
|
DuelChatView selfView;
|
|
DuelChatView enemyView;
|
|
|
|
/*
|
|
* RewardFly起始时间 RewardFlyStartTime = 2s
|
|
数字滚动起始时间 NumberStartTime= 2.1s
|
|
RewardFly和数字滚动的持续时间 RewardPlayDuration= 0.7s
|
|
*/
|
|
public float NumberStartTime = 2.1f;
|
|
public float RewardPlayDuration = 0.7f;
|
|
private void Awake()
|
|
{
|
|
FDM = GContext.container.Resolve<FishingDuelManager>();
|
|
FDM.duelData.progress = FDM.curProgress;
|
|
trophy_before = FDM.duelData.progress;
|
|
uiService = GContext.container.Resolve<IUIService>();
|
|
tables = GContext.container.Resolve<Tables>();
|
|
isWin = FDM.SetProgress();
|
|
root = transform.Find("root");
|
|
img_map = root.Find("map/Item/img_map").GetComponent<Image>();
|
|
text_map = root.Find("map/text_map").GetComponent<TMP_Text>();
|
|
selfView = root.Find("bubble_chat_myself").GetComponent<DuelChatView>();
|
|
enemyView = root.Find("bubble_chat_enermy").GetComponent<DuelChatView>();
|
|
btn_claim = root.Find("btn_claim/btn_green").GetComponent<Button>();
|
|
btn_confirm = root.Find("btn_confirm/btn_green").GetComponent<Button>();
|
|
myself = root.Find("myself").GetComponent<DuelMatchPlayer>();
|
|
enemy = root.Find("enermy").GetComponent<DuelMatchPlayer>();
|
|
winner_tag_my = root.Find("myself/winner_tag").gameObject;
|
|
winner_tag = root.Find("enermy/winner_tag").gameObject;
|
|
text_change_my = root.Find("myself/point_change/text_num").GetComponent<TMP_Text>();
|
|
text_change = root.Find("enermy/point_change/text_num").GetComponent<TMP_Text>();
|
|
title_reward = root.Find("title_reward").gameObject;
|
|
layout_reward = root.Find("layout_reward");
|
|
rewardItemNews = new List<RewardItemNew>();
|
|
int layout_reward_count = layout_reward.childCount;
|
|
for (int i = 0; i < layout_reward_count; i++)
|
|
{
|
|
rewardItemNews.Add(layout_reward.GetChild(i).GetComponent<RewardItemNew>());
|
|
}
|
|
|
|
btn_chat = root.Find("btn_chat").GetComponent<Button>();
|
|
chat = transform.Find("event_fishingduel_chat").gameObject;
|
|
|
|
selfView.SetDuelFishingEvent(0);
|
|
enemyView.SetDuelFishingEvent(1);
|
|
FDM.SelfChatModel.RoleID = 0;
|
|
FDM.EnemyChatModel.RoleID = 1;
|
|
}
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(OnRewardPanelClose).AddTo(this);
|
|
GContext.Publish(new ConditionTypeEvent(ConditionType.Complete1v1Count, 1));
|
|
btn_chat.onClick.AddListener(() =>
|
|
{
|
|
chat.SetActive(!chat.activeSelf);
|
|
});
|
|
winner_tag_my.SetActive(isWin);
|
|
winner_tag.SetActive(!isWin);
|
|
title_reward.SetActive(isWin);
|
|
layout_reward.gameObject.SetActive(isWin);
|
|
btn_claim.gameObject.SetActive(isWin);
|
|
btn_confirm.gameObject.SetActive(!isWin);
|
|
btn_claim.onClick.AddListener(Claim);
|
|
btn_confirm.onClick.AddListener(Claim);
|
|
Init();
|
|
FDM.EnemyChatModel.SendMessage(isWin ? (int)RobotDuelChatType.EndDefeat : (int)RobotDuelChatType.EndVictory);
|
|
MapData mapData = tables.TbMapData.GetOrDefault(FDM.duelData.mapId);
|
|
if (mapData != null)
|
|
{
|
|
uiService.SetImageSprite(img_map, mapData.Bg);
|
|
text_map.text = LocalizationMgr.GetText(mapData.Name_l10n_key);
|
|
}
|
|
}
|
|
void PlayNumWin()
|
|
{
|
|
myself.fx_ui_matchingPanel_rank.SetActive(true);
|
|
int add = FDM.eventSolomain.WinTrophy * FDM.magnification;
|
|
int add1 = FDM.enemySolomain.LoseTrophy * FDM.EnemyModel.Mag;
|
|
text_change_my.text = $"+{add}";
|
|
text_change.text = $"-{add1}";
|
|
StartCoroutine(Play(add, add1, true));
|
|
}
|
|
void PlayNumLose()
|
|
{
|
|
int add = FDM.eventSolomain.LoseTrophy * FDM.magnification;
|
|
int add1 = FDM.enemySolomain.WinTrophy * FDM.EnemyModel.Mag;
|
|
text_change_my.text = $"-{add}";
|
|
text_change.text = $"+{add1}";
|
|
|
|
StartCoroutine(Play(add, add1, false));
|
|
}
|
|
IEnumerator Play(int add, int add1, bool isWin)
|
|
{
|
|
int trophy_before = this.trophy_before;
|
|
int enemy_before = FDM.EnemyModel.RankScore;
|
|
yield return new WaitForSeconds(NumberStartTime);
|
|
float pre = 0;
|
|
if (isWin)
|
|
{
|
|
DOTween.To(() => pre, x => pre = x, 1, RewardPlayDuration).OnUpdate(
|
|
() =>
|
|
{
|
|
text_change_my.text = $"+{(int)(add * (1 - pre))}";
|
|
text_change.text = $"-{(int)(add1 * (1 - pre))}";
|
|
myself.text_score.text = ConvertTools.GetNumberString2(trophy_before + (int)(add * pre));
|
|
enemy.text_score.text = ConvertTools.GetNumberString2(enemy_before - (int)(add1 * pre));
|
|
});
|
|
}
|
|
else
|
|
{
|
|
DOTween.To(() => pre, x => pre = x, 1, RewardPlayDuration).OnUpdate(
|
|
() =>
|
|
{
|
|
text_change_my.text = $"-{(int)(add * (1 - pre))}";
|
|
text_change.text = $"+{(int)(add1 * (1 - pre))}";
|
|
myself.text_score.text = ConvertTools.GetNumberString2(trophy_before - (int)(add * pre));
|
|
enemy.text_score.text = ConvertTools.GetNumberString2(enemy_before + (int)(add1 * pre));
|
|
});
|
|
}
|
|
}
|
|
void Init()
|
|
{
|
|
//双方基础信息
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
|
|
var url = userService.AvatarUrl;
|
|
|
|
uiService.SetHeadImage(myself.icon_head, url);
|
|
myself.text_name.text = userService.DisplayName;
|
|
//uiService.SetImageSprite(myself.icon_rank, FDM.eventSolomain.RankIcon);
|
|
uiService.SetHeadImage(enemy.icon_head, FDM.EnemyModel.PlayerAvatar);
|
|
enemy.text_name.text = FDM.EnemyModel.PlayerName;
|
|
//uiService.SetImageSprite(enemy.icon_rank, FDM.robotSolomain.RankIcon);
|
|
myself.text_score.text = ConvertTools.GetNumberString2(trophy_before);
|
|
enemy.text_score.text = ConvertTools.GetNumberString2(FDM.EnemyModel.RankScore);
|
|
PlayerFishData playerFishData = GContext.container.Resolve<PlayerFishData>();
|
|
PlayerData playerData = GContext.container.Resolve<PlayerData>();
|
|
//胜负显示
|
|
int trophy_change = FDM.eventSolomain.WinTrophy * FDM.magnification;
|
|
|
|
if (isWin)
|
|
{
|
|
PlayNumWin();
|
|
GetReward();
|
|
}
|
|
else
|
|
{
|
|
PlayNumLose();
|
|
trophy_change = -FDM.eventSolomain.LoseTrophy * FDM.magnification;
|
|
}
|
|
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("single_battle"))
|
|
{
|
|
int currentRodLevel = playerFishData.GetRodLevel(playerData.equipRodID);
|
|
int fishCardLevel = playerFishData.GetFishLevelByMap(FDM.MapId);
|
|
int myStar = GContext.container.Resolve<PlayerFishData>().GetRodPiece(playerData.equipRodID);
|
|
Dictionary<RodPerkType, string> RodPerkDic = playerFishData.GetRodPerk(playerData.equipRodID, myStar);
|
|
float rod_points_bonus = FDM.GetCurRodBuff(RodPerkDic, 5);
|
|
e.AddContent("map_id", FDM.duelData.mapId)
|
|
.AddContent("tire", FDM.eventSolomain.RankTier)
|
|
.AddContent("charge_count", GContext.container.Resolve<PlayerShopData>().GetBuyPaymentAmount())
|
|
.AddContent("multiple", FDM.magnification)
|
|
.AddContent("result", isWin)
|
|
.AddContent("rod_id", playerData.equipRodID)
|
|
.AddContent("rod_level", currentRodLevel)
|
|
.AddContent("rod_star", myStar)
|
|
.AddContent("rod_points_bonus", rod_points_bonus)
|
|
.AddContent("card_level", fishCardLevel)
|
|
.AddContent("points", FDM.SelfModel.CurrentPTS)
|
|
.AddContent("trophy_before", trophy_before)
|
|
.AddContent("trophy_change", trophy_change)
|
|
.AddContent("trophy_after", FDM.duelData.progress)
|
|
.AddContent("reward_list", FDM.eventSolomain.WinReward)
|
|
.AddContent("first_complete", FDM.selfIsLastFish ? 1 : 2)
|
|
;
|
|
int allCount = FDM.FishItemIDs.Count;
|
|
var fishInfos = FDM.SelfModel.DuelFishingDatas;
|
|
int myDataCount = fishInfos.Count - 1;
|
|
Dictionary<int, List<int>> items = new Dictionary<int, List<int>>();
|
|
int fish_count = 0;
|
|
int slienceTime = 0;
|
|
List<int> fish_points_list = new List<int>();
|
|
for (int i = 0; i < allCount; i++)
|
|
{
|
|
fish_points_list.Add(0);
|
|
}
|
|
for (int i = 0; i < myDataCount && i < allCount; i++)
|
|
{
|
|
if (fishInfos[i].fishItemId > 0)
|
|
{
|
|
slienceTime += fishInfos[i].slienceTime;
|
|
if (fishInfos[i].isWin)
|
|
{
|
|
Item item = tables.TbItem.GetOrDefault(fishInfos[i].fishItemId);
|
|
if (!items.TryGetValue(item.Quality, out List<int> fish_time))
|
|
{
|
|
fish_time = new List<int>();
|
|
items[item.Quality] = fish_time;
|
|
}
|
|
fish_time.Add(fishInfos[i].fishingTime /*+ fishInfos[i].castingTime*/);
|
|
fish_count++;
|
|
fish_points_list[i] = fishInfos[i].point;
|
|
}
|
|
}
|
|
}
|
|
string fish_id = string.Join(",", FDM.FishItemIDs);
|
|
|
|
e.AddContent("cast_time", (float)slienceTime / myDataCount);
|
|
e.AddContent("fish_count", fish_count)
|
|
.AddContent("fish_id_sequence", fish_id)
|
|
.AddContent("fish_points_list", string.Join(",", fish_points_list));
|
|
|
|
|
|
foreach (var item in items)
|
|
{
|
|
if (item.Value.Count > 0)
|
|
{
|
|
e.AddContent("fish_time_" + item.Key, (float)item.Value.Sum() / item.Value.Count);
|
|
}
|
|
}
|
|
|
|
if (FDM.IsRobot)
|
|
{
|
|
int star = FDM.EnemyModel.RodStar;
|
|
RodPerkDic = playerFishData.GetRodPerk(playerData.equipRodID, star);
|
|
rod_points_bonus = FDM.GetCurRodBuff(RodPerkDic, 5);
|
|
fishCardLevel = 0;
|
|
int mapIndex = (FDM.MapId - 1) % 100;
|
|
var CardLevelList = FDM.eventSoloRobot.CardLevel;
|
|
for (int i = 0; i < CardLevelList.Count; i++)
|
|
{
|
|
var CardLevel = CardLevelList[i];
|
|
mapIndex = mapIndex % CardLevel.Count;
|
|
int cardLevel = CardLevel[mapIndex];
|
|
fishCardLevel += cardLevel;
|
|
}
|
|
|
|
|
|
List<int> fish_points_list_robot = new List<int>();
|
|
for (int i = 0; i < allCount; i++)
|
|
{
|
|
fish_points_list_robot.Add(0);
|
|
}
|
|
var robotInfos = FDM.EnemyModel.DuelFishingDatas;
|
|
int dataCount = robotInfos.Count - 1;
|
|
items = new Dictionary<int, List<int>>();
|
|
for (int i = 0; i < dataCount && i < allCount; i++)
|
|
{
|
|
if (robotInfos[i].fishItemId > 0)
|
|
{
|
|
if (robotInfos[i].isWin)
|
|
{
|
|
Item item = tables.TbItem.GetOrDefault(robotInfos[i].fishItemId);
|
|
if (!items.TryGetValue(item.Quality, out List<int> fish_time))
|
|
{
|
|
fish_time = new List<int>();
|
|
items[item.Quality] = fish_time;
|
|
}
|
|
fish_time.Add(robotInfos[i].fishingTime /*+ robotInfos[i].castingTime*/);
|
|
fish_points_list_robot[i] = robotInfos[i].point;
|
|
}
|
|
}
|
|
}
|
|
e.AddContent("points_robot", FDM.EnemyModel.CurrentPTS)
|
|
.AddContent("rod_id_robot", FDM.EnemyModel.RodId)
|
|
.AddContent("rod_level_robot", FDM.EnemyModel.RodLevel)
|
|
.AddContent("rod_star_robot", star)
|
|
.AddContent("rod_points_bonus_robot", rod_points_bonus)
|
|
.AddContent("fish_points_list_robot", string.Join(",", fish_points_list_robot))
|
|
.AddContent("card_level_robot", fishCardLevel);
|
|
foreach (var item in items)
|
|
{
|
|
if (item.Value.Count > 0)
|
|
{
|
|
e.AddContent("robot_fish_time_" + item.Key, (float)item.Value.Sum() / item.Value.Count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void GetReward()
|
|
{
|
|
var rewardItemData = FDM.GetReward();
|
|
if (rewardItemData != null)
|
|
{
|
|
int dataCount = rewardItemData.Count;
|
|
int rewardCount = rewardItemNews.Count;
|
|
for (int i = 0; i < rewardCount; i++)
|
|
{
|
|
if (i < dataCount)
|
|
{
|
|
rewardItemData[i].count *= FDM.magnification;
|
|
rewardItemNews[i].SetData(rewardItemData[i]);
|
|
}
|
|
else
|
|
{
|
|
rewardItemNews[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
GContext.container.Resolve<PlayerItemData>().AddItem(rewardItemData);
|
|
}
|
|
}
|
|
|
|
void Claim()
|
|
{
|
|
CurRewardQCount curRewardQCount = new CurRewardQCount();
|
|
GContext.Publish(curRewardQCount);
|
|
if (curRewardQCount.count <= 0)
|
|
{
|
|
QuitDuel();
|
|
}
|
|
else
|
|
{
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
}
|
|
void OnRewardPanelClose(RewardPanelClose e)
|
|
{
|
|
QuitDuel();
|
|
}
|
|
void QuitDuelToRod()
|
|
{
|
|
FDM.OnStopShowUIType = UITypes.FishingRodBagPanel;
|
|
QuitDuel();
|
|
}
|
|
void QuitDuelToFishCard()
|
|
{
|
|
FDM.OnStopShowUIType = UITypes.FishingMapPanel;
|
|
QuitDuel();
|
|
}
|
|
void QuitDuel()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.EventFishingDuelRewardPanel);
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
}
|
|
}
|