备份CatanBuilding瘦身独立工程
This commit is contained in:
164
Assets/Scripts/EventCan/EventCanSystem.cs
Normal file
164
Assets/Scripts/EventCan/EventCanSystem.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
|
||||
public class EventCanSystem
|
||||
{
|
||||
private readonly EventCanModel _model;
|
||||
public EventCanSystem()
|
||||
{
|
||||
_model = GContext.container.Resolve<EventCanModel>();
|
||||
}
|
||||
|
||||
public EEventCanOpenResponse OpenCan(int canIdx)
|
||||
{
|
||||
if (_model.TicketCount <= 0)
|
||||
{
|
||||
Debug.Log($"[EventCan] No ticket to open can.");
|
||||
return EEventCanOpenResponse.InsufficientToken;
|
||||
}
|
||||
if (!_model.CanList[canIdx].DoesExist)
|
||||
{
|
||||
Debug.Log($"[EventCan] Can {canIdx} has been opened.");
|
||||
return EEventCanOpenResponse.Other;
|
||||
}
|
||||
_model.AddTicket(-1);
|
||||
_model.CanList[canIdx].DoesExist = false;
|
||||
_model.ToPlayfabData().Save();
|
||||
return EEventCanOpenResponse.Success;
|
||||
}
|
||||
|
||||
public void GrantCanReward(EventCanRewardInfo rewardInfo)
|
||||
{
|
||||
int _evItemId = 0, _evItemNum = 0, _evRewardId = 0, _evRewardNum = 0, _evTaskId = 0, _evItemDrop = 0, _evItemDropNum = 0;
|
||||
_model.WeightModifier.UpdateDrawsSinceLastRewards(rewardInfo.RewardId);
|
||||
ItemData progressReward;
|
||||
_evItemId = rewardInfo.ItemId;
|
||||
_evItemNum = rewardInfo.ItemCount;
|
||||
switch (rewardInfo.RewardType)
|
||||
{
|
||||
case EEventCanRewardType.Green:
|
||||
case EEventCanRewardType.Blue:
|
||||
case EEventCanRewardType.Purple:
|
||||
case EEventCanRewardType.Red:
|
||||
// _model.GemTasks[rewardInfo.RewardType].CurrentGemProgress += rewardInfo.ItemCount;
|
||||
_model.GemTasks[rewardInfo.RewardType].UpdateGemTasks(rewardInfo, out progressReward, out var oldTaskId);
|
||||
if (progressReward != null)
|
||||
{
|
||||
_evTaskId = oldTaskId;
|
||||
_evItemDrop = progressReward.id;
|
||||
_evItemDropNum = progressReward.count;
|
||||
// GContext.container.Resolve<PlayerItemData>().AddItem(progressReward);
|
||||
GContext.Publish(new DeferredRewardStashService.EventStashItem { Item = progressReward });
|
||||
}
|
||||
break;
|
||||
case EEventCanRewardType.Supply:
|
||||
RefillCanList();
|
||||
break;
|
||||
case EEventCanRewardType.Item:
|
||||
var r = rewardInfo.ToItemData();
|
||||
//in case the item needs transformation somehow
|
||||
_evItemId = r.id;
|
||||
_evItemNum = r.count;
|
||||
// GContext.container.Resolve<PlayerItemData>().AddItem(r);
|
||||
GContext.Publish(new DeferredRewardStashService.EventStashItem { Item = r });
|
||||
break;
|
||||
default:
|
||||
Debug.Log($"[EventCan] Unknown reward type: {rewardInfo.RewardType}");
|
||||
break;
|
||||
}
|
||||
// _model.ProgressTaskInfo.CurrentProgress++;
|
||||
_model.ProgressTaskInfo.UpdateProgressTask(out progressReward);
|
||||
if (progressReward != null)
|
||||
{
|
||||
_evRewardId = progressReward.id;
|
||||
_evRewardNum = progressReward.count;
|
||||
// GContext.container.Resolve<PlayerItemData>().AddItem(progressReward);
|
||||
GContext.Publish(new DeferredRewardStashService.EventStashItem { Item = progressReward });
|
||||
}
|
||||
_model.ToPlayfabData().Save();
|
||||
|
||||
|
||||
// Debug.Log($"<color=red>[EventCan] -------------------Event Tracking---------------------</color>");
|
||||
// Debug.Log($"[EventCan] item_id: {_evItemId}");
|
||||
// Debug.Log($"[EventCan] item_num: {_evItemNum}");
|
||||
// Debug.Log($"[EventCan] reward_id: {_evRewardId}");
|
||||
// Debug.Log($"[EventCan] reward_num: {_evRewardNum}");
|
||||
// Debug.Log($"[EventCan] task_id: {_evTaskId}");
|
||||
// Debug.Log($"[EventCan] item_drop: {_evItemDrop}");
|
||||
// Debug.Log($"[EventCan] item_dropnum: {_evItemDropNum}");
|
||||
// Debug.Log($"[EventCan] -------------------End of Event Tracking---------------------");
|
||||
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("event_can"))
|
||||
{
|
||||
e.AddContent("item_id", _evItemId)
|
||||
.AddContent("item_num", _evItemNum)
|
||||
.AddContent("reward_id", _evRewardId)
|
||||
.AddContent("reward_num", _evRewardNum)
|
||||
.AddContent("task_id", _evTaskId)
|
||||
.AddContent("item_drop", _evItemDrop)
|
||||
.AddContent("item_dropnum", _evItemDropNum);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public EventCanRewardInfo GenerateReward()
|
||||
{
|
||||
var weightList = new List<int>();
|
||||
EventCanRewardInfo rewardInfo, res = null;
|
||||
for (int i = 0; i < _model.RewardPool.Length; i++)
|
||||
{
|
||||
rewardInfo = _model.RewardPool[i];
|
||||
_model.WeightModifier.GetWeightDelta(rewardInfo.RewardId, out var weightDelta, out var mustGet);
|
||||
// if (mustGet)
|
||||
// {
|
||||
// Debug.Log($"[EventCan] Must get! {rewardInfo.RewardType}.");
|
||||
// Debug.Log($"[EventCan] Must get! {res is not {RewardType: EEventCanRewardType.Supply}}.");
|
||||
// }
|
||||
if (mustGet && res is not { RewardType: EEventCanRewardType.Supply })
|
||||
res = rewardInfo;
|
||||
else
|
||||
weightList.Add(rewardInfo.BaseWeight + weightDelta);
|
||||
}
|
||||
if (res != null)
|
||||
{
|
||||
// Debug.Log($"[EventCan] Must get! {res.RewardType}.");
|
||||
return res;
|
||||
}
|
||||
var idx = FtMathUtils.GetRandomIdxFromWeightList(weightList);
|
||||
return _model.RewardPool[idx];
|
||||
}
|
||||
|
||||
public void RefillCanList()
|
||||
{
|
||||
// Debug.Log("<color=red>[EventCan] Refill!</color>");
|
||||
foreach (var canInfo in _model.CanList)
|
||||
{
|
||||
canInfo.DoesExist = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EventCanOpenEvent
|
||||
{
|
||||
public EventCanRewardInfo RewardInfo;
|
||||
public Vector2 CanPosition;
|
||||
public EventCanGemTaskInfo GemTaskInfoSnapShot = null;
|
||||
public RectTransform CanRt;
|
||||
public EventCanOpenEvent(EventCanRewardInfo rewardInfo, RectTransform can, EventCanGemTaskInfo infoSnapShot = null)
|
||||
{
|
||||
RewardInfo = rewardInfo;
|
||||
CanPosition = can.position;
|
||||
GemTaskInfoSnapShot = infoSnapShot;
|
||||
CanRt = can;
|
||||
}
|
||||
}
|
||||
|
||||
public enum EEventCanOpenResponse
|
||||
{
|
||||
Success, InsufficientToken, Other
|
||||
}
|
||||
Reference in New Issue
Block a user