public float GoldNextFreeSyncTime; // 同步时间 // 请求商店信息 public void RequestShopInfo(ShopType shopType) { PCMInt data = new PCMInt(); data.arg = (int)shopType; NetworkManager.Instance.Send(eCommand.GET_PLAYER_SHOP_LIST, data, (buffer) => { PGeneralGoodList ret = Net.Deserialize <PGeneralGoodList>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.GET_PLAYER_SHOP_LIST)) { return; } OnRefreshShopInfo(ret, shopType); }); }
// 请求手动刷新商店 public void RequestRefreshShop(ShopType shopType) { ShopInfo info = GetShopInfo(shopType); if (info == null) { return; } int costGold = info.GetRefreshCost(); if (UserManager.Instance.Gold < costGold) { UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_GOLD_LIMIT"); return; } PCMInt data = new PCMInt(); data.arg = (int)shopType; NetworkManager.Instance.Send(eCommand.MANAUL_REFRESH_SHOP, data, (buffer) => { PGeneralGoodList ret = Net.Deserialize <PGeneralGoodList>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.MANAUL_REFRESH_SHOP)) { return; } // 减少金钱 UserManager.Instance.CostMoney(costGold, PriceType.GOLD); // 增加刷新次数 ++info.refreshCount; OnRefreshShopInfo(ret, shopType); }); }
private void OnRefreshShopInfo(PGeneralGoodList ret, ShopType shopType) { ShopInfo shopInfo = null; if (!ShopInfoData.TryGetValue(shopType, out shopInfo)) { shopInfo = new ShopInfo(); ShopInfoData[shopType] = shopInfo; } shopInfo.refreshCD.SetTimeMilliseconds(ret.nextAutoRefreshTime); shopInfo.refreshCount = ret.refreshTime; shopInfo.itemList.Clear(); foreach (var item in ret.GeneralGoodList) { ShopItemInfo info = new ShopItemInfo(); info.Deserialize(item); info.PriceType = shopType; shopInfo.itemList.Add(info); } EventDispatcher.TriggerEvent(EventID.EVENT_SHOP_REFRESH_SHOP, shopType); }