Files
ft/Client/Assets/Scripts/UI/PartnerStatue/EventPartnerCore.cs
2026-06-29 21:18:33 +08:00

120 lines
4.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using asap.core;
using GameCore;
namespace EventPartner
{
public class Model
{
public List<BuildComponent> ComponentList;
public int TicketCount;
public float LureInflationRate;
private readonly IEventPartnerArchitecture _arc;
public bool IsFinalRewardClaimed = false;
public Model(IEventPartnerArchitecture arc)
{
_arc = arc;
}
//初始化需要执行SaveTransitionData
public void SetTicketCount(int n)
{
TicketCount=n;
GContext.container.Resolve<FishingEventData>().SaveTransitionData(_arc.Ctx.EventId, TicketCount);
}
public bool AddTicket(int n)
{
TicketCount += n;
if (TicketCount < 0)
{
TicketCount -= n;
return false;
}
_arc.EventAggregator.Publish(new EventPartnerTicketChangedEvent());
// remove red point for now
// RedPointManager.Instance.SetRedPointState(_arc.GetRedPointKey(), TicketCount > 0, TicketCount);
GContext.container.Resolve<FishingEventData>().SaveTransitionData(_arc.Ctx.EventId, TicketCount);
_arc.SavePlayfab();
return true;
}
public HashSet<string> PartnerIdSet => ComponentList.Select(x => x.PartnerId).ToHashSet();
public List<bool> BuildStatus => ComponentList.Select(x => x.IsRewardClaimed).ToList();
}
public class BuildComponent
{
public int Index;
public string PartnerId = "";
public int ScoreSelfActual, ScorePartnerActual;
public int ScoreSelfDisplay, ScorePartnerDisplay;
private readonly int MaxScore;
public bool IsEmpty => PartnerId == "";
public int ScoreTotal => ScoreSelfActual + ScorePartnerActual;
public int ScoreDisplayTotal => ScoreSelfDisplay + ScorePartnerDisplay;
public bool IsDone => ScoreTotal >= MaxScore;
// public bool IsRewardClaimed => ScoreDisplayTotal >= ScoreTotal && ScoreDisplayTotal >= MaxScore;
public bool IsRewardClaimed => ScoreDisplayTotal >= MaxScore;
private IEventPartnerArchitecture _arc;
public BuildComponent(int idx, int maxScore, IEventPartnerArchitecture arc, string partnerId = "", int scoreSelf = 0,
int scorePartner = 0, int scoreSelfDisplay = 0, int scorePartnerDisplay = 0)
{
Index = idx;
PartnerId = partnerId;
ScoreSelfActual = scoreSelf;
ScorePartnerActual = scorePartner;
ScoreSelfDisplay = scoreSelfDisplay;
ScorePartnerDisplay = scorePartnerDisplay;
MaxScore = maxScore;
_arc = arc;
}
private void UpdateSelfScore(int newScore)
{
if (newScore < ScoreSelfActual)
{
Debug.Log($"[EventPartner] New self score is smaller than current score, ignore. New: {newScore}, Current actual: {ScoreSelfActual}");
return;
}
ScoreSelfActual = newScore < MaxScore ? newScore : MaxScore;
}
public void UpdatePartnerScore(int newScore)
{
if (newScore < ScorePartnerActual)
{
Debug.Log($"[EventPartner] New partner score is smaller than current score, ignore. New: {newScore}, Current actual: {ScorePartnerActual}");
return;
}
ScorePartnerActual = newScore < MaxScore ? newScore : MaxScore;
}
public void AddSelfScore(int n)
{
UpdateSelfScore(n + ScoreSelfActual);
}
public void AddPartnerScore(int n)
{
UpdatePartnerScore(n + ScorePartnerActual);
}
/// <summary>
/// Sync display score with actual score. Should be called during display sequence and progress reward given.
/// </summary>
public void SyncDisplayScore()
{
ScoreSelfDisplay = ScoreSelfActual;
ScorePartnerDisplay = ScorePartnerActual;
_arc.SavePlayfab();
}
}
}