215 lines
8.4 KiB
C#
215 lines
8.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using GameCore;
|
|
using cfg;
|
|
using asap.core;
|
|
using Castle.Core.Internal;
|
|
using game;
|
|
using UnityEngine.Assertions;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class EventPartnerMainPanel : MonoBehaviour
|
|
{
|
|
#region UI
|
|
|
|
[SerializeField] private TMP_Text _textTimer, _textAreaInfo, _textProgress, _textTicketCount;
|
|
[SerializeField] private Image[] _targetBars;
|
|
[SerializeField] private RewardItemNew[] _rewardItems;
|
|
[SerializeField] private Image _iconTicket;
|
|
[SerializeField] private EventPartnerCharaSlot[] _characters;
|
|
[SerializeField] private GameObject finishedGo, ticketGo;
|
|
[SerializeField] private Button btnInfo, btnTicket, btnApplication;
|
|
[SerializeField] private EventPartnerMainPanelMatchTip matchTip;
|
|
[SerializeField] private EventPartnerTips tips;
|
|
private Image _activeBar;
|
|
private PlayerItemData _playerItemData;
|
|
|
|
#endregion
|
|
|
|
#region Config
|
|
|
|
private EventPartnerData _data;
|
|
private Tables _tables;
|
|
private TbEventPartnerMain _tableMain;
|
|
|
|
#endregion
|
|
|
|
private void Start()
|
|
{
|
|
btnInfo.onClick.AddListener(() => _ = UIManager.Instance.ShowUI(UITypes.EventPartnerInfoPopupPanel));
|
|
btnTicket.onClick.AddListener(tips.ShowMainTip);
|
|
btnApplication.onClick.AddListener(() => _ = UIManager.Instance.ShowUI(UITypes.EventPartnerInvitedPanel));
|
|
EventPartnerAct.Ctx.EventAggregator.GetEvent<EventPartnerMatchSuccess>().Subscribe(OnNewMatch).AddTo(this);
|
|
EventPartnerAct.Ctx.EventAggregator.GetEvent<EventPartnerPartnerAddScore>().Subscribe(OnScoreAdd).AddTo(this);
|
|
EventPartnerAct.Ctx.EventAggregator.GetEvent<EventPartnerOnInvited>().Subscribe(_ => OnInvited()).AddTo(this);
|
|
Observable.Interval(TimeSpan.FromSeconds(1.0f)).Subscribe(_ => _textTimer.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_end", ConvertTools.ConvertTime2(_data.RemainingTime))).AddTo(this);
|
|
EventPartnerAct.Ctx.EventAggregator.GetEvent<EventPartnerHideApplicationBtn>().Subscribe(e => btnApplication.transform.parent.gameObject.SetActive(false)).AddTo(this);
|
|
}
|
|
#if UNITY_EDITOR
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.B))
|
|
{
|
|
Debug.Log("Bot recommend.");
|
|
_data.ActivateRobotRecommend();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
public void Init()
|
|
{
|
|
var ctx = EventPartnerAct.Ctx;
|
|
_tables = ctx.Tables;
|
|
_tableMain = _tables.TbEventPartnerMain;
|
|
_playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
_data = ctx.Data;
|
|
// Debug.Log($"[EventPartner] Data in main panel: {_data.GetHashCode()}");
|
|
for (int i = 0; i < _characters.Length; i++)
|
|
_characters[i].Init(_data.Components[i]);
|
|
|
|
_textTimer.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_end", ConvertTools.ConvertTime2(_data.RemainingTime));
|
|
InitializeTarget();
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(_iconTicket, _tables.TbItem[_tableMain[_data.RedirectId].WheelTicket].Icon);
|
|
_textTicketCount.text = _data.TicketCount.ToString();
|
|
finishedGo.SetActive(_data.IsBuildingCompleted);
|
|
ticketGo.SetActive(!_data.IsBuildingCompleted);
|
|
if (_data.IsBuildingCompleted && !_data.IsBuildingRewardCollected)
|
|
{
|
|
int dropId = _tableMain[_data.RedirectId].Reward;
|
|
// SendCheck();
|
|
_playerItemData.AddItemByDrop(dropId, false);
|
|
GContext.Publish(new ShowData(_playerItemData.GetItemDataByDropId(dropId)));
|
|
GContext.Publish(new ShowData());
|
|
int _EvStageId = 99, _EvRewardList = dropId, _EvRewardHook = 0, _EvRewardCash = 0;
|
|
var rewardIdList = _tables.TbDrop[dropId].DropList.DropIDList;
|
|
for (int i = 0; i < rewardIdList.Count; i++)
|
|
{
|
|
if (rewardIdList[i] == 1001)
|
|
_EvRewardHook = _tables.TbDrop[dropId].DropList.DropCountList[i];
|
|
if (rewardIdList[i] == 1002)
|
|
_EvRewardCash = _tables.TbDrop[dropId].DropList.DropCountList[i];
|
|
}
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("event_partners_reward"))
|
|
{
|
|
e.AddContent("stage_id", _EvStageId)
|
|
.AddContent("reward_list", _EvRewardList)
|
|
.AddContent("reward_hook", _EvRewardHook)
|
|
.AddContent("reward_cash", _EvRewardCash);
|
|
}
|
|
#endif
|
|
_data.IsBuildingRewardCollected = true;
|
|
_data.SavePlayerPreferenceData();
|
|
_data.ToPlayfabData().Save();
|
|
}
|
|
btnApplication.transform.parent.gameObject.SetActive(!ctx.Data.RequestPartners.IsNullOrEmpty() && !ctx.Data.IsFullyMatched);
|
|
GContext.OnEvent<EventPartnerTicketChangedEvent>().Subscribe(_ => UpdateTicketCount()).AddTo(this);
|
|
}
|
|
|
|
private void UpdateTicketCount()
|
|
{
|
|
_textTicketCount.text = _data.TicketCount.ToString();
|
|
_textTicketCount.color = _data.TicketCount < 1 ? Color.red : Color.white;
|
|
}
|
|
|
|
// private async void SendCheck()
|
|
// {
|
|
// var res = await GContext.container.Resolve<ICustomServerMgr>().EventPartnerRequest<EventPartnerData.EventBuildRewardStatusResp>(EventPartnerData.SetRewardCollectedUrl, null);
|
|
// Debug.Log($"<color=#c191ff>full reward res: {res.State}, {res.Message}, {res.IsRewardCollected}</color>");
|
|
// }
|
|
|
|
private void InitializeTarget()
|
|
{
|
|
var d = _tables.TbDrop[_tableMain[_data.RedirectId].Reward];
|
|
int dropTypeCount = d.DropList.DropIDList.Count;
|
|
Assert.IsTrue(dropTypeCount is > 0 and <= 3,
|
|
$"Drop count {dropTypeCount} is not within [0, 3].");
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
_targetBars[i].gameObject.SetActive(3 - dropTypeCount == i);
|
|
if (3 - dropTypeCount == i)
|
|
_activeBar = _targetBars[i];
|
|
_rewardItems[i].gameObject.SetActive(i < dropTypeCount);
|
|
}
|
|
|
|
var itemList = _playerItemData.GetItemDataByDropId(d.ID);
|
|
for (int i = 0; i < dropTypeCount; i++)
|
|
_rewardItems[i].SetData(itemList[i]);
|
|
int amount = _data.Components.Count(t => t.IsFinished);
|
|
_activeBar.fillAmount = (float)amount / _data.Components.Count;
|
|
_textProgress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9",
|
|
$"{amount}/{_data.Components.Count}");
|
|
}
|
|
|
|
public void SetMatchTip(string namePartner, string iconPartner, string nameComponent,
|
|
bool doShowPanelTips)
|
|
{
|
|
if (!doShowPanelTips)
|
|
{
|
|
matchTip.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
|
|
matchTip.Show(namePartner, iconPartner, nameComponent);
|
|
matchTip.gameObject.SetActive(false);
|
|
matchTip.gameObject.SetActive(true);
|
|
}
|
|
|
|
private async void OnNewMatch(EventPartnerMatchSuccess e)
|
|
{
|
|
if (e.PartnerId.EndsWith(EventPartnerBot.RobotIdentifier))
|
|
{
|
|
int delay = Random.Range( _tables.TbEventPartnerConfig.RobotAgreeTime[0],
|
|
_tables.TbEventPartnerConfig.RobotAgreeTime[1]);
|
|
Debug.Log($"<color=#c191ff>[EventPartner]Delay: {delay} seconds.</color>");
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
|
}
|
|
// Init();
|
|
SetMatchTip(e.NamePartner, e.IconPartner, e.NameComponent, true);
|
|
_characters[e.SlotId].Init(_data.Components[e.SlotId]);
|
|
}
|
|
|
|
private async void OnInvited()
|
|
{
|
|
await Awaiters.NextFrame;
|
|
btnApplication.transform.parent.gameObject.SetActive(true);
|
|
}
|
|
// private async void OnAccepted(EventPartnerOnAccepted e)
|
|
// {
|
|
// await Awaiters.NextFrame;
|
|
// _characters[e.SlotId].Init(_data.Components[e.SlotId]);
|
|
// }
|
|
|
|
private async void OnScoreAdd(EventPartnerPartnerAddScore _)
|
|
{
|
|
await Awaiters.NextFrame;
|
|
for (int i = 0; i < _data.Components.Count; i++)
|
|
_characters[i].Init(_data.Components[i]);
|
|
}
|
|
}
|
|
|
|
public class EventPartnerMatchSuccess
|
|
{
|
|
public string NamePartner;
|
|
public string IconPartner;
|
|
public string NameComponent;
|
|
public int SlotId;
|
|
public string PartnerId;
|
|
}
|
|
|
|
public class EventPartnerOnInvited { }
|
|
public class EventPartnerHideApplicationBtn { }
|
|
// public class EventPartnerOnAccepted
|
|
// {
|
|
// public int SlotId;
|
|
// public string PartnerId;
|
|
// public EventPartnerOnAccepted(EventPartnerData.EventBuildPartnerEvt e)
|
|
// {
|
|
// SlotId = e.slotId;
|
|
// PartnerId = e.partnerId;
|
|
// }
|
|
// } |