2025-05-18 01:04:31 +08:00

164 lines
3.6 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-01-26
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "RewardProxy" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using F;
using F.Network;
namespace G
{
/// <summary>
/// 奖励领取功能
/// </summary>
public class RewardProxy : F.GameProxy
{
#region Field
#endregion
#region Method
/// <summary>
/// 内部
/// </summary>
/// <param name="itemInfo"></param>
private void GetReward(int id, int count)
{
var propItem = ItemProxy.Instance.GetStaticItem<ItemProp>(id);
if (propItem != null)
{
switch (propItem.type)
{
case Item.Type.Money:
MoneyProxy.Instance.AddMoney(id, count);
break;
case Item.Type.Weapon:
case Item.Type.Equipment:
BagProxy.Instance.NewEquipment(id);
break;
case Item.Type.Prop:
case Item.Type.BeautyProp:
ItemProxy.Instance.AddProp(propItem.id, count);
break;
case Item.Type.Gem:
ItemProxy.Instance.AddGem(propItem.id, count);
break;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="itemInfo"></param>
/// <param name="callback"></param>
public void GetRewardWithUI(Item.ItemInfo itemInfo, Callback2 callback)
{
GetReward(itemInfo.id, itemInfo.count);
UI.RewardWindow.ShowReward(itemInfo, callback);
}
/// <summary>
///
/// </summary>
/// <param name="itemInfos"></param>
/// <param name="callback"></param>
public void GetRewardsWithUI(IList<Item.ItemInfo> itemInfos, Callback2 callback)
{
if (itemInfos.Count > 0)
{
foreach (var itemInfo in itemInfos)
{
GetReward(itemInfo.id, itemInfo.count);
}
#if UNITY_EDITOR && !UNITY_WEBGL
if (!KGMOptions.Instance.)
UI.RewardWindow.ShowRewards(itemInfos, callback);
#else
UI.RewardWindow.ShowRewards(itemInfos, callback);
#endif
}
else
{
callback?.Invoke(ErrorCode.REWARD_EMPTY, "");
}
}
/// <summary>
///
/// </summary>
/// <param name="itemInfo"></param>
public void GetReward(Item.ItemInfo itemInfo)
{
GetReward(itemInfo.id, itemInfo.count);
}
/// <summary>
///
/// </summary>
/// <param name="itemInfos"></param>
public void GetRewards(IList<Item.ItemInfo> itemInfos)
{
if (itemInfos.Count > 0)
{
foreach (var itemInfo in itemInfos)
{
GetReward(itemInfo.id, itemInfo.count);
}
}
}
#endregion
#region Proxy
public static RewardProxy Instance => GetInstance<RewardProxy>();
public override void InitCompleted()
{
KFramework.GameFacade.RegisterResp(90, this);
}
public override void Recv(IPacket packet)
{
if (packet.id == 90)
{
string json = (string)packet.data;
var table = F.Utils.ToJsonTable(json);
var tools = F.Utils.GetList(table, "tools");
if (tools != null)
{
var rewards = F.ListPool<Item.ItemInfo>.Get();
for (int i = 0; i < tools.Count; i++)
{
var tool = F.Utils.GetDictionary(tools, i);
int id = tool.GetInt("key");
int count = tool.GetInt("count");
if (id > 0 && count > 0)
{
rewards.Add(new Item.ItemInfo
{
id = id,
count = count,
});
}
}
GetRewardsWithUI(rewards, null);
F.ListPool<Item.ItemInfo>.Release(rewards);
}
}
}
#endregion
}
}