499 lines
19 KiB
C#
499 lines
19 KiB
C#
using asap.core;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using UniRx;
|
|
using game;
|
|
using EventPartnerGatherRequests;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using EventPartner;
|
|
using System.Threading.Tasks;
|
|
|
|
public class EventPartnerStatueBuildPanel : MonoBehaviour
|
|
{
|
|
// [SerializeField] private EventPartnerStatueBuildMultiplierBtn multiplierView;
|
|
[SerializeField] private Button btnClose, btnAdd, btnSwitchLeft, btnSwitchRight;
|
|
[SerializeField] private TMP_Text textCost, textTicketCount, textAddScore;
|
|
[SerializeField] private EventPartnerStatueBuildScoreView scoreViewSelf, scoreViewPartner;
|
|
[SerializeField] private EventPartnerStatueBuildProgressView progressView;
|
|
[SerializeField] private EventPartnerStatueBuildFxCtrl fxCtrl;
|
|
[SerializeField]
|
|
private float
|
|
DiceAnimationDelay = 1.0f,
|
|
BuffMoreFxDuration = 1.0f,
|
|
BuffFreeFxDuration = 1.0f,
|
|
BuffSuperFxDuration = 1.0f,
|
|
ScoreAddDelay = 1.0f,
|
|
// ProgressBarAnimationDelay = 1.0f,
|
|
MaskShiftFxDelay = 1.0f,
|
|
ScoreAddFxDuration = 0.5f,
|
|
CheckProgressDelay = 0.0f;
|
|
[SerializeField] private EventPartnerStatueBuildBtn btnBuild;
|
|
[SerializeField] private GameObject goFinished, fxFinished, goClickMask, goAddScore;
|
|
[SerializeField] private Animation ani;
|
|
private int _idx;
|
|
private EventPartnerStatueBuild _buildScene;
|
|
private bool _expectingRewardPanelClose = false;
|
|
private (int c1, int c2, int c3) _currentCombination;
|
|
|
|
public void Start()
|
|
{
|
|
btnClose.onClick.AddListener(OnClickClose);
|
|
btnAdd.onClick.AddListener(OnClickAdd);
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.EventAggregator.GetEvent<EventPartnerTicketChangedEvent>().Subscribe(OnTicketChange).AddTo(this);
|
|
(bool isMax, int idx, int multiplier) = arc.GetInitMultiplier();
|
|
btnSwitchLeft.onClick.AddListener(OnSwitchSlot);
|
|
btnSwitchRight.onClick.AddListener(OnSwitchSlot);
|
|
GContext.OnEvent<FishingTurnTableContinueMultiDraw>().Subscribe(_ => OnRewardPanelClose()).AddTo(this);
|
|
// StartCoroutine(InitialUnblockCoroutine());
|
|
}
|
|
|
|
public void Init(EventPartnerStatueBuildPanelData data, EventPartnerStatueBuild buildScene)
|
|
{
|
|
_buildScene = buildScene;
|
|
scoreViewSelf.Init(data.InfoSelf.AvatarUrl, data.InfoSelf.DisplayName, data.ScoreSelf);
|
|
scoreViewPartner.Init(data.InfoPartner.AvatarUrl, data.InfoPartner.DisplayName, data.ScorePartner);
|
|
progressView.Init(data.ProgressData);
|
|
textTicketCount.text = data.TicketCount.ToString();
|
|
fxCtrl.Init();
|
|
goAddScore.SetActive(false);
|
|
_idx = data.SlotIdx;
|
|
btnBuild.Init(OnClickBuild);
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.RtSystem.Subscribe(OnScore, OnPartnerChange);
|
|
var c = arc.Model.ComponentList[_idx];
|
|
if (c.IsRewardClaimed)
|
|
{
|
|
SetFinished();
|
|
UnBlockInput();
|
|
}
|
|
else
|
|
{
|
|
goFinished.SetActive(false);
|
|
fxFinished.SetActive(false);
|
|
CheckScoreForPotentialProgress();
|
|
}
|
|
}
|
|
|
|
private async void OnClickClose()
|
|
{
|
|
try
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
|
|
arc.EventAggregator.Publish(new EventPartnerStatueEnterMain());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
private void OnClickAdd()
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.TableContext.ShowFestPack();
|
|
}
|
|
private async void ShowAddScore(int score)
|
|
{
|
|
try
|
|
{
|
|
textAddScore.text = "+" + score;
|
|
goAddScore.SetActive(false);
|
|
goAddScore.SetActive(true);
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(2f));
|
|
goAddScore.SetActive(false);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
[Header(">>>>>>Test Params<<<<<<")]
|
|
[Range(1, 6)]
|
|
[SerializeField] private List<int> testCombination;
|
|
[SerializeField] private int testScore = -1;
|
|
#endif
|
|
private async void OnClickBuild()
|
|
{
|
|
// Debug.Log("[EventPartnerStatue] Click build!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
try
|
|
{
|
|
BlockInput();
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var c = arc.Model.ComponentList[_idx];
|
|
var (point, combination) = (0, (0, 0, 0));
|
|
var cost = btnBuild.Cost;
|
|
#if UNITY_EDITOR
|
|
if (testScore > 0)
|
|
(point, combination) = arc.RollTest(testScore, (testCombination[0], testCombination[1], testCombination[2]), cost);
|
|
else
|
|
#endif
|
|
(point, combination) = arc.Roll(cost);
|
|
// #if UNITY_EDITOR
|
|
// if (point > 0)
|
|
// point = 1;
|
|
// #endif
|
|
arc.EventTrackingSystem.RollPartnerId = RobotDataManager.IsRobot(c.PartnerId) ? "Robot" : c.PartnerId;
|
|
arc.EventTrackingSystem.RollSlotId = _idx;
|
|
if (point < 0)
|
|
{
|
|
arc.TableContext.ShowFestPack();
|
|
btnBuild.RefreshToCurrentMax();
|
|
UnBlockInput();
|
|
return;
|
|
}
|
|
if (point + c.ScoreTotal > arc.TableContext.GetMaxScore())
|
|
{
|
|
point = arc.TableContext.GetMaxScore() - c.ScoreTotal;
|
|
}
|
|
arc.EventTrackingSystem.RollPoint = point;
|
|
var resp = await arc.Requests.Build(c.PartnerId, c.ScoreSelfActual + point);
|
|
if (resp.State != EEventBuildBuildState.Success)
|
|
{
|
|
arc.Model.AddTicket(cost);
|
|
Debug.Log($"[EventPartnerStatue] build failed: {resp.State}, {resp.Message}, refund.");
|
|
UnBlockInput();
|
|
return;
|
|
}
|
|
|
|
var oldStage = arc.TableContext.GetStageFromTotalScore(arc.Model.ComponentList[_idx].ScoreTotal);
|
|
arc.Model.ComponentList[_idx].AddSelfScore(point);
|
|
arc.EventTrackingSystem.ReportRoll();
|
|
var stageRewards = arc.TryGetStageReward(_idx);
|
|
// Debug.Log($"[EventPartnerStatue] add self items: {stageRewards.Count}");
|
|
arc.SavePlayfab();
|
|
await DisplaySelfBuild(point, oldStage, stageRewards, combination);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
UnBlockInput();
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private async System.Threading.Tasks.Task DisplaySelfBuild(int scoreToAdd, int oldStage, List<ItemData> stageRewards, (int c1, int c2, int c3) combination)
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var c = arc.Model.ComponentList[_idx];
|
|
_buildScene.PlayDice(combination);
|
|
BlockInput();
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(DiceAnimationDelay));
|
|
if (combination == arc.TableContext.GetMoreDisplayCombination())
|
|
{
|
|
fxCtrl.ShowMore();
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(BuffMoreFxDuration));
|
|
// btnBuild.RefreshToCurrentMax();
|
|
btnBuild.RefreshAndHold();
|
|
}
|
|
else if (combination.c1 == combination.c2 && combination.c2 == combination.c3 && combination.c1 == 6)
|
|
{
|
|
fxCtrl.ShowThree();
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(BuffSuperFxDuration));
|
|
// btnBuild.RefreshToCurrentMax();
|
|
btnBuild.RefreshAndHold();
|
|
}
|
|
else if (combination != arc.TableContext.GetFreeDisplayCombination())
|
|
{
|
|
// btnBuild.RefreshToCurrentMax();
|
|
btnBuild.RefreshAndHold();
|
|
}
|
|
|
|
ShowAddScore(scoreToAdd);
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(ScoreAddDelay));
|
|
|
|
var newStage = arc.TableContext.GetStageFromTotalScore(c.ScoreTotal);
|
|
_buildScene.PlayToolAnimation(combination, oldStage, arc.TableContext.GetScoreStageList().Count);
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(arc.TableContext.GetSumToolAnimationDuration(combination)));
|
|
|
|
await progressView.OnBuildAsync(c.ScoreTotal);
|
|
// await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(ProgressBarAnimationDelay));
|
|
|
|
if (stageRewards != null && stageRewards.Count > 0)
|
|
{
|
|
_buildScene.SetStatue(newStage);
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(MaskShiftFxDelay));
|
|
}
|
|
|
|
await scoreViewSelf.AddScores(scoreToAdd, c.ScoreSelfActual, ScoreAddFxDuration);
|
|
|
|
UnBlockInput();
|
|
if (stageRewards != null && stageRewards.Count > 0)
|
|
{
|
|
GContext.Publish(new ShowData(stageRewards));
|
|
GContext.Publish(new ShowData());
|
|
BlockInput();
|
|
// Will be set false after reward panel is closed
|
|
_expectingRewardPanelClose = true;
|
|
_currentCombination = combination;
|
|
ChangeSource changeSource = new ChangeSource(arc.TableContext.EventId, "Event_Minigame4", "Event_Minigame4_Partner", "StageReward");
|
|
|
|
GContext.container.Resolve<PlayerItemData>().AddItem(stageRewards, changeSource);
|
|
|
|
arc.EventTrackingSystem.RewardPartnerId = RobotDataManager.IsRobot(c.PartnerId) ? "Robot" : c.PartnerId;
|
|
arc.EventTrackingSystem.RewardSlotId = _idx;
|
|
arc.EventTrackingSystem.RewardStageId = arc.TableContext.GetStageFromTotalScore(c.ScoreTotal);
|
|
arc.EventTrackingSystem.RewardHook = stageRewards.Where(r => r.id == 1001).Sum(r => r.count);
|
|
arc.EventTrackingSystem.ReportReward();
|
|
}
|
|
else if (combination == arc.TableContext.GetFreeDisplayCombination())
|
|
{
|
|
BlockInput();
|
|
fxCtrl.ShowFree();
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(BuffFreeFxDuration));
|
|
// btnBuild.RefreshToCurrentMax();
|
|
btnBuild.RefreshAndHold();
|
|
UnBlockInput();
|
|
}
|
|
c.SyncDisplayScore();
|
|
}
|
|
|
|
private async void DisplayPartnerBuild(int scoreToAdd, int oldStage, List<ItemData> stageRewards)
|
|
{
|
|
// await Awaiters.NextFrame;
|
|
try
|
|
{
|
|
BlockInput();
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var c = arc.Model.ComponentList[_idx];
|
|
ShowAddScore(scoreToAdd);
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(ScoreAddDelay));
|
|
|
|
var newStage = arc.TableContext.GetStageFromTotalScore(c.ScoreTotal);
|
|
_buildScene.PlayToolAnimation((1, 2, 3), oldStage, arc.TableContext.GetScoreStageList().Count);
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(arc.TableContext.GetSumToolAnimationDuration((1, 2, 3))));
|
|
|
|
// arc.EventAggregator.Publish(new EventPartnerStatueSelfBuild(combination, oldStage, arc.TableContext.GetScoreStageList().Count, newStage));
|
|
await progressView.OnBuildAsync(c.ScoreTotal);
|
|
// await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(ProgressBarAnimationDelay));
|
|
|
|
if (stageRewards != null && stageRewards.Count > 0)
|
|
{
|
|
_buildScene.SetStatue(newStage);
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(MaskShiftFxDelay));
|
|
}
|
|
|
|
if (c.ScorePartnerActual > c.ScorePartnerDisplay)
|
|
await scoreViewPartner.AddScores(c.ScorePartnerActual - c.ScorePartnerDisplay, c.ScorePartnerActual, ScoreAddFxDuration);
|
|
if (c.ScoreSelfActual > c.ScoreSelfDisplay)
|
|
await scoreViewSelf.AddScores(c.ScoreSelfActual - c.ScoreSelfDisplay, c.ScoreSelfActual, ScoreAddFxDuration);
|
|
|
|
UnBlockInput();
|
|
if (stageRewards != null && stageRewards.Count > 0)
|
|
{
|
|
_currentCombination = (7, 7, 7);//No dot need free judgement
|
|
_expectingRewardPanelClose = true;
|
|
BlockInput();
|
|
GContext.Publish(new ShowData(stageRewards));
|
|
ChangeSource changeSource = new ChangeSource(arc.TableContext.EventId, "Event_Minigame4", "Event_Minigame4_Partner", "StageReward");
|
|
GContext.container.Resolve<PlayerItemData>().AddItem(stageRewards, changeSource);
|
|
GContext.Publish(new ShowData());
|
|
|
|
arc.EventTrackingSystem.RewardPartnerId = RobotDataManager.IsRobot(c.PartnerId) ? "Robot" : c.PartnerId;
|
|
arc.EventTrackingSystem.RewardSlotId = _idx;
|
|
arc.EventTrackingSystem.RewardStageId = arc.TableContext.GetStageFromTotalScore(c.ScoreTotal);
|
|
arc.EventTrackingSystem.RewardHook = stageRewards.Where(r => r.id == 1001).Sum(r => r.count);
|
|
arc.EventTrackingSystem.ReportReward();
|
|
}
|
|
c.SyncDisplayScore();
|
|
// else if (c.IsDone)
|
|
// {
|
|
// SetFinished();
|
|
// _buildScene.SetFinished();
|
|
// }
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void OnTicketChange(EventPartnerTicketChangedEvent e)
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var ticketCount = arc.Model.TicketCount;
|
|
textTicketCount.text = ticketCount.ToString();
|
|
if (ticketCount <= 0)
|
|
textTicketCount.color = Color.red;
|
|
else
|
|
textTicketCount.color = Color.white;
|
|
}
|
|
|
|
private async void OnScore(EventPartnerGatherScoreEvt e)
|
|
{
|
|
await Awaiters.NextFrame;
|
|
// var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
// var c = arc.Model.ComponentList.FirstOrDefault(x => x.PartnerId == e.PartnerId);
|
|
// if (c == null)
|
|
// return;
|
|
// var oldStage = arc.TableContext.GetStageFromTotalScore(c.ScoreDisplayTotal);
|
|
// arc.OnScore(e);
|
|
// var scoreToAdd = c.ScorePartnerActual - c.ScorePartnerDisplay;
|
|
// var stageRewards = arc.TryGetStageReward(e.PartnerId);
|
|
// DisplayPartnerBuild(scoreToAdd, oldStage, stageRewards);
|
|
}
|
|
|
|
private async void OnPartnerChange(EventPartnerGatherPartnerEvt e)
|
|
{
|
|
await Awaiters.NextFrame;
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.OnPartnerChange(e);
|
|
}
|
|
|
|
private async void CheckScoreForPotentialProgress()
|
|
{
|
|
try
|
|
{
|
|
BlockInput();
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(CheckProgressDelay));
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var c = arc.Model.ComponentList[_idx];
|
|
// Debug.Log($"c.ScoreDisplayTotal: {c.ScoreDisplayTotal}, c.ScoreTotal: {c.ScoreTotal}");
|
|
if (c.ScoreDisplayTotal >= c.ScoreTotal)
|
|
{
|
|
UnBlockInput();
|
|
return;
|
|
}
|
|
var oldStage = arc.TableContext.GetStageFromTotalScore(c.ScoreDisplayTotal);
|
|
int scoreToAdd;
|
|
scoreToAdd = c.ScoreTotal - c.ScoreDisplayTotal;
|
|
var stageRewards = arc.TryGetStageReward(_idx);
|
|
DisplayPartnerBuild(scoreToAdd, oldStage, stageRewards);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
UnBlockInput();
|
|
}
|
|
}
|
|
|
|
private void SetFinished()
|
|
{
|
|
btnBuild.Hide();
|
|
goFinished.SetActive(true);
|
|
fxFinished.SetActive(true);
|
|
}
|
|
|
|
private void OnSwitchSlot()
|
|
{
|
|
// Debug.Log("[EventPartnerStatue] On switch");
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
if (arc.Model.ComponentList.Count <= 1)
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_EventPartnerStatueNewyearPanel_7"));
|
|
return;
|
|
}
|
|
PlaySwitchAniamtion();
|
|
_idx = (_idx + 1) % arc.Model.ComponentList.Count;
|
|
|
|
var data = arc.GetEventPartnerStatueBuildPanelData(_idx);
|
|
scoreViewSelf.Init(data.InfoSelf.AvatarUrl, data.InfoSelf.DisplayName, data.ScoreSelf);
|
|
scoreViewPartner.Init(data.InfoPartner.AvatarUrl, data.InfoPartner.DisplayName, data.ScorePartner);
|
|
progressView.Init(data.ProgressData);
|
|
textTicketCount.text = data.TicketCount.ToString();
|
|
fxCtrl.Init();
|
|
goAddScore.SetActive(false);
|
|
_idx = data.SlotIdx;
|
|
arc.RtSystem.Subscribe(OnScore, OnPartnerChange);
|
|
var c = arc.Model.ComponentList[_idx];
|
|
if (c.IsRewardClaimed)
|
|
{
|
|
SetFinished();
|
|
}
|
|
else
|
|
{
|
|
goFinished.SetActive(false);
|
|
fxFinished.SetActive(false);
|
|
btnBuild.RefreshToCurrentMax();
|
|
CheckScoreForPotentialProgress();
|
|
}
|
|
arc.EventAggregator.Publish(new EventPartnerStatueSwitchBuild
|
|
{
|
|
SlotIdx = _idx,
|
|
});
|
|
}
|
|
|
|
private async void OnRewardPanelClose()
|
|
{
|
|
if (!_expectingRewardPanelClose)
|
|
return;
|
|
_expectingRewardPanelClose = false;
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var c = arc.Model.ComponentList[_idx];
|
|
if (_currentCombination == arc.TableContext.GetFreeDisplayCombination())
|
|
{
|
|
fxCtrl.ShowFree();
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(BuffFreeFxDuration));
|
|
btnBuild.RefreshAndHold();
|
|
}
|
|
if (c.IsDone)
|
|
{
|
|
SetFinished();
|
|
_buildScene.SetFinished();
|
|
arc.EventAggregator.Publish(new EventPartnerStatueEnterMain() { SlotIdx = _idx });
|
|
}
|
|
UnBlockInput();
|
|
}
|
|
|
|
private void PlaySwitchAniamtion()
|
|
{
|
|
ani.Play("EventPartnerStatueNewyearPanel_switch");
|
|
}
|
|
|
|
private void BlockInput()
|
|
{
|
|
goClickMask.SetActive(true);
|
|
}
|
|
|
|
private void UnBlockInput()
|
|
{
|
|
goClickMask.SetActive(false);
|
|
}
|
|
|
|
private System.Collections.IEnumerator InitialUnblockCoroutine()
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
UnBlockInput();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
StopAllCoroutines();
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Space) && testScore > 0)
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var e = new EventPartnerGatherScoreEvt
|
|
{
|
|
PartnerId = arc.Model.ComponentList[_idx].PartnerId,
|
|
Score = testScore,
|
|
};
|
|
OnScore(e);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
public class EventPartnerStatueBuildPanelData
|
|
{
|
|
public PlayerInfo InfoSelf { get; set; }
|
|
public PlayerInfo InfoPartner { get; set; }
|
|
public int ScoreSelf { get; set; }
|
|
public int ScorePartner { get; set; }
|
|
public EventPartnerStatueBuildProgressData ProgressData { get; set; }
|
|
public int TicketCount { get; set; }
|
|
public int SlotIdx { get; set; }
|
|
public EventPartnerStatueBuild BuildScene { get; set; }
|
|
}
|
|
|