//购买配饰 public void BuyPetAccessories(PetAccessoryOrder petAccessoryOrder, Action <Result> callBack = null, Action <Result> errCallBack = null) { Header header = new Header(); header.headers = new List <HeaderData>(); header.headers.Add(new HeaderData() { key = "Gululu-Agent", value = GululuNetworkHelper.GetAgent() }); header.headers.Add(new HeaderData() { key = "udid", value = GululuNetworkHelper.GetUdid() }); header.headers.Add(new HeaderData() { key = "Accept-Language", value = GululuNetworkHelper.GetAcceptLang() }); header.headers.Add(new HeaderData() { key = "Content-Type", value = "application/json" }); string strHeader = this.JsonUtils.Json2String(header); if (petAccessoryOrder == null || petAccessoryOrder.items == null || petAccessoryOrder.items.Count == 0) {//如果本地找不到已经解锁的宠物,那默认宠物就作为第一个已解锁宠物 if (errCallBack != null) { errCallBack(new Result() { boolValue = false, info = "<><PetAccessoryUtils.BuyPetAccessories>Error: shopping cart is empty" }); } return; } string strBody = this.JsonUtils.Json2String(petAccessoryOrder); Debug.Log("<><PetAccessoryUtils.BuyPetAccessories>Prepare data"); ActionData newActionData = new ActionData() { Header = strHeader, Body = strBody, SendTimes = 3, OnSuccess = callBack, OnFailed = errCallBack }; //检查队列里是否已经有数据 if (this.lastActionData != null && this.lastActionData.Body == strBody) { //队列里有数据,只需要处理数据是否压栈 Debug.LogFormat("<><PetAccessoryUtils.BuyPetAccessories>Ignore same data, Header: {0}, Body: {1}", strHeader, strBody); return; //如果新数据与最后一条数据的Body相同,直接忽略 } else {//队列里没有数据,才需要数据压栈,且主动调用数据同步方法 Debug.LogFormat("<><PetAccessoryUtils.BuyPetAccessories>Append new data and execute, Header: {0}, Body: {1}", strHeader, strBody); this.lastActionData = newActionData; this.actionDatas.Add(newActionData); this.SendPetAccessoryOrder(); } }
//点击确认 public void Confirm() { if (this.accessoryTypes.BackButtonSelected) {//退出换装页 this.CloseViewSignal.Dispatch(true); } else if (!this.accessories.HasItems) {//如果当前商店中无配饰 return; } else if (!this.accessories.CurrentButton.Accessory.Suitable(this.PlayerDataManager.CurrentPet) && !this.suitLockView.IsOpen) {//显示配饰不适用提示页面 this.audioPlayer.Stop(); this.suitLockView.Open(this.accessories.CurrentButton.Accessory); FlurryUtil.LogEventWithParam("mall_scene_lock_suitable", "accessory_name", this.accessories.CurrentButton.Accessory.Name); } else if (this.suitLockView.IsOpen) {//关闭配饰不适用提示页面 this.suitLockView.Close(); } else if (this.accessories.CurrentButton.Paid && !this.accessories.CurrentButton.Worn) {//已拥有:穿上当前配饰 this.PutOn(this.accessories.CurrentButton.Accessory); this.PlaySound("mall_put_on_accessory"); FlurryUtil.LogEventWithParam("mall_scene_change", "accessory_name", this.accessories.CurrentButton.Accessory.Name); } else if (this.accessories.CurrentButton.Paid && this.accessories.CurrentButton.Worn) {//已拥有:脱掉当前配饰 this.TakeOff(this.accessories.CurrentButton.Accessory); this.PlaySound(this.accessories.CurrentButton.Accessory.CanWear ? "mall_take_off_accessory" : "mall_spirit_out"); } else if (this.accessories.CurrentButton.Accessory.Level > this.PlayerDataManager.playerLevel && !this.levelLockView.IsOpen) {//显示等级不够提示页面 this.audioPlayer.Stop(); this.levelLockView.Open(this.accessories.CurrentButton.Accessory); FlurryUtil.LogEventWithParam("mall_scene_lock_level", "accessory_name", this.accessories.CurrentButton.Accessory.Name); } else if (this.levelLockView.IsOpen) {//关闭等级不够提示页面 this.levelLockView.Close(); } else if (!this.accessories.CurrentButton.Accessory.Opened && !this.openLockView.IsOpen) {//显示未开放提示页面 this.audioPlayer.Stop(); this.openLockView.Open(this.accessories.CurrentButton.Accessory); } else if (this.openLockView.IsOpen) {//关闭未开放提示页面 this.openLockView.Close(); } else if (this.goalLockView.IsOpen) {//关闭饮水目标未达标提示页面 this.goalLockView.Close(); } else if (this.coinLockView.IsOpen) {//关闭金币不足提示页面 this.coinLockView.Close(); } else if (this.wifiLockView.IsOpen) {//关闭无网络连接提示页面 this.wifiLockView.Close(); } else if (this.qrCodeView.IsOpen) {//关闭二维码页面 this.qrCodeView.Close(); } else if (!this.accessories.CurrentButton.Paid && this.accessories.CurrentButton.Accessory.Coin) {//金币购买的配饰:钱够→扣钱→配饰进包裹→记录穿戴数据→配饰图标状态更新 if (this.FundDataManager.GetItemCount(this.FundDataManager.GetCoinId()) >= this.accessories.CurrentButton.Accessory.Price) { this.accessories.CurrentButton.Paid = true; this.AccessoryDataManager.AddItem(this.accessories.CurrentButton.Accessory.ID); //配饰添加到包裹 this.FundDataManager.ExpendCoin(this.FundDataManager.GetCoinId(), (int)this.accessories.CurrentButton.Accessory.Price); //扣钱 SoundPlayer.GetInstance().StopAllSoundExceptMusic(); SoundPlayer.GetInstance().PlaySoundInChannal("mall_purchase_qr_complete", this.audioPlayer, 0.2f); this.PutOn(this.accessories.CurrentButton.Accessory); ExpUI.Instance.Show(this.accessories.CurrentButton.Accessory.Exp, 0, -25, 25, GameObject.FindGameObjectWithTag("ExpUILayer").transform); this.PlayerDataManager.exp += this.accessories.CurrentButton.Accessory.Exp; this.UIState.PushNewState(UIStateEnum.eExpIncrease, this.PlayerDataManager.GetExpPercent()); this.UpdateExpAndCoinSignal.Dispatch(); FlurryUtil.LogEventWithParam("mall_scene_purchase", "accessory_name", this.accessories.CurrentButton.Accessory.Name); } else if (!this.coinLockView.IsOpen) {//显示金币不足提示页面 this.audioPlayer.Stop(); this.coinLockView.Open(); } } else if (!this.accessories.CurrentButton.Paid && this.accessories.CurrentButton.Accessory.Cash && !this.qrCodeView.IsOpen) { //货币购买的配饰:向服务器发送请求,获取二维码并打开页面显示 if (this.PlayerDataManager.currIntake < this.PlayerDataManager.GetDailyGoal() && !this.goalLockView.IsOpen) { //显示饮水目标未达标提示页面 this.audioPlayer.Stop(); this.goalLockView.Open(this.accessories.CurrentButton.Accessory); FlurryUtil.LogEventWithParam("mall_scene_lock_goal", "accessory_name", this.accessories.CurrentButton.Accessory.Name); } #if !UNITY_EDITOR && UNITY_ANDROID else if (!NativeWifiManager.Instance.IsConnected() && !this.wifiLockView.IsOpen) {//显示无网络连接提示页面 this.audioPlayer.Stop(); this.wifiLockView.Open(); } #else else if (!this.wifiLockView.IsOpen) {//显示无网络连接提示页面 this.audioPlayer.Stop(); this.wifiLockView.Open(); } #endif else { #if !UNITY_EDITOR && UNITY_ANDROID this.IsBuying = true; PetAccessoryOrder order = new PetAccessoryOrder() { items = new List <PetAccessory>() { new PetAccessory() { sn = this.accessories.CurrentButton.Accessory.ID.ToString(), count = 1 } }, remark = string.Format("CupSn:{0}, ChildSn:{1}", CupBuild.getCupSn(), this.LocalChildInfoAgent.getChildSN()) }; this.PetAccessoryUtils.BuyPetAccessories(order, (result) => { this.IsBuying = false; OrderReceipt orderReceipt = this.JsonUtils.String2Json <OrderReceipt>(result.info); if (orderReceipt != null && !string.IsNullOrEmpty(orderReceipt.status) && orderReceipt.status.ToUpper() == "OK") { this.audioPlayer.Stop(); this.qrCodeView.Open(orderReceipt); FlurryUtil.LogEventWithParam("mall_scene_qr", "accessory_name", this.accessories.CurrentButton.Accessory.Name); } else { Debug.LogError("<><PetPageView.Confirm>orderReceipt is null"); } }, (error) => { this.IsBuying = false; Debug.LogErrorFormat("<><PetPageView.Confirm>BuyPetAccessories, error: {0}", error.info); }); #else this.audioPlayer.Stop(); this.qrCodeView.Open(null); #endif } } }