// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-01-26 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using System.Collections; using System.Collections.Generic; using F; using F.Network; namespace G { /// /// 奖励领取功能 /// public class RewardProxy : F.GameProxy { #region Field #endregion #region Method /// /// 内部 /// /// private void GetReward(int id, int count) { var propItem = ItemProxy.Instance.GetStaticItem(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; } } } /// /// /// /// /// public void GetRewardWithUI(Item.ItemInfo itemInfo, Callback2 callback) { GetReward(itemInfo.id, itemInfo.count); UI.RewardWindow.ShowReward(itemInfo, callback); } /// /// /// /// /// public void GetRewardsWithUI(IList 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, ""); } } /// /// /// /// public void GetReward(Item.ItemInfo itemInfo) { GetReward(itemInfo.id, itemInfo.count); } /// /// /// /// public void GetRewards(IList itemInfos) { if (itemInfos.Count > 0) { foreach (var itemInfo in itemInfos) { GetReward(itemInfo.id, itemInfo.count); } } } #endregion #region Proxy public static RewardProxy Instance => GetInstance(); 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.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.Release(rewards); } } } #endregion } }