111 lines
3.9 KiB
C#
111 lines
3.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
using asap.core;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
|
|
public class DrillSystem
|
|
{
|
|
private readonly EventBreakTableContext _drillDataHub;
|
|
private readonly PlayerItemData _playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
private int _evTunnel, _evTicketConsume, _evGemGet, _evTaskId;
|
|
private string _evReward;
|
|
private Dictionary<int, int> _evNormalRewardDic;
|
|
|
|
public DrillSystem(EventBreakTableContext drillDataHub)
|
|
{
|
|
_drillDataHub = drillDataHub;
|
|
}
|
|
|
|
public bool DoDrillJob(int jobIdx)
|
|
{
|
|
var _drillModel = GContext.container.Resolve<DrillModel>();
|
|
var jobData = _drillModel.DrillJobList[jobIdx];
|
|
if (!_drillModel.AddTicket(-jobData.Cost))
|
|
{
|
|
Debug.Log("[EventBreak] Insufficient ticket.");
|
|
return false;
|
|
}
|
|
|
|
_evTunnel = jobIdx + 1;
|
|
_evTicketConsume = jobData.Cost;
|
|
_evGemGet = 0;
|
|
_evNormalRewardDic = new Dictionary<int, int>();
|
|
_evReward = "";
|
|
_evTaskId = 0;
|
|
|
|
ProcessBlocks(ref _drillModel.TaskInfoList[jobIdx], jobData.Blocks);
|
|
|
|
/*
|
|
Debug.Log($"[EventBreak]<color=#fe231b>Event tracking:</color>");
|
|
Debug.Log($"[EventBreak]<color=#fe231b> tunnel: {_evTunnel}</color>");
|
|
Debug.Log($"[EventBreak]<color=#fe231b> item_consume: {_evTicketConsume}</color>");
|
|
Debug.Log($"[EventBreak]<color=#fe231b> gem_count: {_evGemGet}</color>");
|
|
Debug.Log($"[EventBreak]<color=#fe231b> reward_normal: {_evReward}</color>");
|
|
Debug.Log($"[EventBreak]<color=#fe231b> milestone_task: {_evTaskId}</color>");
|
|
*/
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("event_drill"))
|
|
{
|
|
e.AddContent("tunnel", _evTunnel)
|
|
.AddContent("item_consume", _evTicketConsume)
|
|
.AddContent("gem_count", _evGemGet)
|
|
.AddContent("reward_normal", _evReward)
|
|
.AddContent("milestone_task", _evTaskId);
|
|
}
|
|
#endif
|
|
_drillModel.UpdateSeed(jobIdx);
|
|
_drillModel.DrillJobList[jobIdx] = _drillDataHub.GetDrillJob(jobIdx, _drillModel.DrillJobSeeds[jobIdx]);
|
|
return true;
|
|
}
|
|
|
|
private void ProcessBlocks(ref EventBreakTaskInfo taskInfo, IEnumerable<DrillBlockData> blocks)
|
|
{
|
|
var _drillModel = GContext.container.Resolve<DrillModel>();
|
|
foreach (var block in blocks)
|
|
{
|
|
if (block.IsEmpty)
|
|
continue;
|
|
if (block.Item.id != taskInfo.TargetItemId)
|
|
{
|
|
GrantPlayerReward(block.Item);
|
|
if (!_evNormalRewardDic.TryAdd(block.Item.id, (int) block.Item.count))
|
|
_evNormalRewardDic[block.Item.id] += (int) block.Item.count;
|
|
continue;
|
|
}
|
|
taskInfo.CurrentGemProgress += (int)block.Item.count;
|
|
_evGemGet++;
|
|
if (taskInfo.CurrentGemProgress < taskInfo.TotalGemRequired)
|
|
continue;
|
|
GrantPlayerReward(taskInfo.Reward);
|
|
_evTaskId = taskInfo.TaskId;
|
|
taskInfo = _drillDataHub.GetNextTaskInfo(taskInfo);
|
|
}
|
|
_evReward = SerializeRewardDic(_evNormalRewardDic);
|
|
_drillModel.ToPlayfabData().Save();
|
|
}
|
|
|
|
private string SerializeRewardDic(Dictionary<int, int> d)
|
|
{
|
|
var res = new StringBuilder();
|
|
if (d == null || d.Count <= 0)
|
|
return "";
|
|
foreach (var kv in d)
|
|
{
|
|
res.Append("(");
|
|
res.Append(kv.Key);
|
|
res.Append(",");
|
|
res.Append(kv.Value);
|
|
res.Append("),");
|
|
}
|
|
return res.ToString();
|
|
}
|
|
|
|
public void GrantPlayerReward(ItemData item)
|
|
{
|
|
// Debug.Log($"[Drill] Add rewards: id {item.id} count {item.count}");
|
|
// _playerItemData.AddItem(item);
|
|
GContext.Publish(new DeferredRewardStashService.EventStashItem {Item = item});
|
|
}
|
|
}
|