/// <summary> /// マスターデータ取得通信 /// </summary> public static void CallGetMasterApi(Action onCompleted, params Master.IDataBase[] dbs) { #if SHARK_OFFLINE onCompleted?.Invoke(); return; #endif var request = new SharkWebRequest <Dictionary <string, object> >("master/getMaster"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "tableNameList", dbs.Select(x => x.tableName).ToArray() }, }); request.onSuccess = (response) => { foreach (var db in dbs) { db.SetList(response[db.tableName].ToString()); } onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// 購入履歴の取得 /// </summary> public static void CallBuyStatusApi(uint shopId, Action <List <UserShopData> > onCompleted) { //リクエスト作成 var request = new SharkWebRequest <BuyStatusResponseData>("shop/buyStatus"); request.SetRequestHeader("AccessToken", UserData.Get().hash); //リクエストパラメータセット if (shopId > 0) { //shopIdの指定がない場合は全件取得 request.SetRequestParameter(new Dictionary <string, object> { { "shopId", shopId } }); } //通信完了時コールバック登録 request.onSuccess = (response) => { //通信完了 onCompleted?.Invoke(response.tShop); }; //通信開始 request.Send(); }
/// <summary> /// パーツからギアの取り外し通信 /// </summary> public static void CallGearUnsetApi(uint gearServerId, Action onCompleted) { //対象ギアの取得 UserGearData userGear = UserData.Get().gearData.First(gear => gear.serverId == gearServerId); #if SHARK_OFFLINE userGear.SetPartsServerId(null, DateTime.Now); onCompleted?.Invoke(); return; #endif var request = new SharkWebRequest <CannonGearUnsetResponseData>("cannon/gearUnset"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "gearId", gearServerId }, }); request.onSuccess = (response) => { //コイン消費の反映 UserData.Get().Set(response.tUsers); SharedUI.Instance.header.SetInfo(UserData.Get()); //ギア取り外しの反映 userGear.SetPartsServerId(null, response.tGear.setDateTime); // 無理、ギア外すカウンター更新 CustomGearConfirmDialogContent.freeGearRemoveCount = response.freeRemoveCount; onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// ユーザー作成通信 /// </summary> public static void CallCreateApi(string userName, Action onCompleted) { //リクエスト作成 var request = new SharkWebRequest <CreateResponseData>("user/create"); //リクエストパラメータセット request.SetRequestParameter(new Dictionary <string, object> { { "userName", userName }, { "authType", 3 }, { "deviceType", SharkDefine.DEVICE_TYPE }, }); //通信完了時コールバック登録 request.onSuccess = (response) => { //id,hash,passwordが揃った段階で一旦端末に保存する response.userData.password = response.password; response.userData.Save(); //ユーザーデータセット response.userData.Set(response.tUsers); UserData.Set(response.userData); //通信完了 onCompleted?.Invoke(); }; //通信開始 request.Send(); }
/// <summary> /// パーツへのギア装着通信 /// </summary> public static void CallGearSetApi(uint gearServerId, uint partsServerId, Action onCompleted) { //対象ギアの取得 UserGearData userGear = UserData.Get().gearData.First(gear => gear.serverId == gearServerId); #if SHARK_OFFLINE userGear.SetPartsServerId(partsServerId, DateTime.Now); onCompleted?.Invoke(); return; #endif var request = new SharkWebRequest <CannonGearSetResponseData>("cannon/gearSet"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "gearId", gearServerId }, { "cannonId", partsServerId }, }); request.onSuccess = (response) => { //ギア装着の反映 userGear.SetPartsServerId(partsServerId, response.tGear.setDateTime); onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// 引継ぎコード入力後ユーザーID・PASS取得通信 /// </summary> public static void CallDeviceChangeCode( string takeOverId, string takeOverPass, Action <DeviceChangeCodeResponseData> onCompleted, Action <int> onError) { var request = new SharkWebRequest <DeviceChangeCodeResponseData>("user/takeOver"); request.SetRequestParameter(new Dictionary <string, object> { { "takeOverId", takeOverId }, { "takeOverPassword", takeOverPass }, { "authType", 3 }, { "deviceType", SharkDefine.DEVICE_TYPE } }); request.onSuccess = (response) => { onCompleted?.Invoke(response); }; request.onError = (errorCode) => { onError?.Invoke(errorCode); }; request.Send(); }
/// <summary> /// 受け取り通信 /// </summary> public static void CallReceiveApi(TPresentBox[] dataList, Action <ReceiveListResponseData> onCompleted, Action <int> onError) { var presentBoxType = (dataList[0] is TPresentBoxLimited) ? PresentBoxType.Limited : PresentBoxType.NonLimited; var presentBoxIdList = dataList.Select(x => x.id).ToArray(); //リクエスト作成 var request = new SharkWebRequest <ReceiveListResponseData>("present/receiveList"); request.SetRequestHeader("AccessToken", UserData.Get().hash); //リクエストパラメータセット request.SetRequestParameter(new Dictionary <string, object> { { "presentBoxType", presentBoxType }, { "presentBoxIdList", presentBoxIdList }, }); //通信完了時コールバック登録 request.onSuccess = (response) => { if (response.tPresentBoxReceived != null) { //アイテム付与 foreach (var item in response.tPresentBoxReceived) { UserData.Get().AddItem((ItemType)item.itemType, item.itemId, item.itemNum); } } //ユーザー情報同期 if (response.tUsers != null) { UserData.Get().Set(response.tUsers); } //ジェム同期 if (response.tGem != null) { UserData.Get().Set(response.tGem); } //ヘッダー更新 SharedUI.Instance.header.SetInfo(UserData.Get()); HomeScene.isMaxPossession = response.isMaxPossession; //通信完了 onCompleted?.Invoke(response); }; //エラー時の対応を追加 request.onError = onError; //通信開始 request.Send(); }
/// <summary> /// まとめてギア分解情報の通信 /// </summary> public static void CallSellGearList(List <uint> gearList, Action onCompleted) { var request = new SharkWebRequest <GearDecompositionListResponseData>("cannon/gearSellList"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "gearIdList", gearList } }); /// 成功時 request.onSuccess = (response) => { //コイン消費の反映 UserData.Get().Set(response.tUsers); SharedUI.Instance.header.SetInfo(UserData.Get()); // addItem responseデータ、itemIdとstockCountの順にソート var addItemSort = response.mItemSell .OrderBy(x => x.itemId) .ThenBy(c => c.itemNum) .ToArray(); // アイテム追加 foreach (var item in addItemSort) { // BattleItemの場合 if ((ItemType)item.itemType == ItemType.BattleItem) { // 現在所有するアイテム数 uint userStockCount = UserData.Get().itemData .Where(x => x.itemId == item.itemId) .Select(x => x.stockCount) .SingleOrDefault(); // 追加するアイテム数 uint addNum = item.itemNum - userStockCount; // アイテム追加 UserData.Get().AddItem((ItemType)item.itemType, item.itemId, addNum); } } // 分解した、ギア削除 foreach (var item in response.tGear) { var list = UserData.Get().gearData.ToList(); var index = list.FindIndex(x => x.serverId == item.serverId); list.RemoveAt(index); UserData.Get().gearData = list.ToArray(); } onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// レベルアップ通信 /// </summary> public static void CallLevelUpApi(LogData logData, Action <LevelUpResponseData> onCompleted) { var request = new SharkWebRequest <LevelUpResponseData>("multiPlaying/levelUp"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(logData.ToRequestParameter()); request.onSuccess = (response) => { onCompleted?.Invoke(response); }; request.Send(); }
/// <summary> /// マルチゲーム終了 /// </summary> public static void CallClearApi(LogData logData, Action onCompleted) { var request = new SharkWebRequest <ClearResponseData>("multi/multiClear"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(logData.ToRequestParameter()); request.onSuccess = (response) => { UserData.Get().Set(response.tUsers); onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// リソースバージョン取得通信 /// </summary> public static void CallTopApi(Action <string> onCompleted) { var request = new SharkWebRequest <object>("top"); request.SetRequestParameter(new Dictionary <string, object> { { "deviceType", SharkDefine.DEVICE_TYPE }, }); request.onSuccess = (response) => { onCompleted?.Invoke(request.resourceVersion); }; request.Send(); }
/// <summary> /// ミッションの報酬受け取り通信 /// </summary> public static void CallGetMissionRewardApi(MissionProgress progress, Action <MissionRewardResponseData> onCompleted) { //リクエスト作成 var request = new SharkWebRequest <MissionRewardResponseData>("mission/getMissionReward"); request.SetRequestHeader("AccessToken", UserData.Get().hash); //リクエストパラメータセット request.SetRequestParameter(new Dictionary <string, object> { { "tMissionId", progress.tMissionId }, { "missionGroupId", (uint)progress.category } }); //通信完了時コールバック登録 request.onSuccess = (response) => { response.Setup(); //アイテムの付与 UserData.Get().AddItem((ItemType)response.mMissionReward.itemType, response.mMissionReward.itemId, response.mMissionReward.itemNum); //ジェムの同期 if (response.tGem != null) { UserData.Get().Set(response.tGem); } //ユーザー情報の同期 if (response.tUsers != null) { UserData.Get().Set(response.tUsers); } //ヘッダ更新 SharedUI.Instance.header.SetInfo(UserData.Get()); //無期限のプレゼントBoxの上限を超えているかのフラグ HomeScene.isMaxPossession = response.isMaxPossession; //通信完了 onCompleted?.Invoke(response); }; //通信開始 request.Send(); }
/// <summary> /// 使用する砲台の変更通信 /// </summary> public static void CallUseApi(uint settingNumber, Action onCompleted) { #if SHARK_OFFLINE { var userData = UserData.Get(); var selectedTurretData = userData.GetSelectedTurretData(); if (selectedTurretData != null) { selectedTurretData.useFlg = 0; } userData.turretData.First(x => x.settingNumber == settingNumber).useFlg = 1; onCompleted?.Invoke(); return; } #endif var request = new SharkWebRequest <CannonUseResponseData>("cannon/use"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "settingNumber", settingNumber } }); request.onSuccess = (response) => { var userData = UserData.Get(); for (int i = 0; i < userData.turretData.Length; i++) { if (userData.turretData[i].settingNumber == settingNumber) { //現在の選択状態を解除 var selectedTurretData = userData.GetSelectedTurretData(); if (selectedTurretData != null) { selectedTurretData.useFlg = 0; } //レスポンスで更新 userData.turretData[i] = response.tCannonSetting; break; } } onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// ギアロック情報の通信 /// </summary> public static void CallGearLock(UserGearData geardata, Action onCompleted) { var request = new SharkWebRequest <GearLockResponseData>("cannon/gearLock"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "gearId", geardata.serverId } }); request.onSuccess = (response) => { geardata.lockFlg = response.tGear.lockFlg; onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// ユーザー名変更通信 /// </summary> public static void CallChangeUserNameApi(string changeuserName, Action onCompleted) { var request = new SharkWebRequest <ChangeUserNameResponseData>("user/edit"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "userName", changeuserName } }); request.onSuccess = (response) => { UserData.Get().Set(response.tUsers); onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// ログイン通信 /// </summary> public static void CallLoginApi(UserData userData, Action onCompleted) { //リクエスト作成 var request = new SharkWebRequest <LoginResponseData>("user/login"); //リクエストパラメータセット request.SetRequestParameter(new Dictionary <string, object> { { "userId", userData.userId }, { "password", userData.password }, { "authType", 3 }, { "deviceType", SharkDefine.DEVICE_TYPE }, }); //通信完了時コールバック登録 request.onSuccess = (response) => { //ログインの合否を判定 // ToDo 自身の端末内のパスワードが消失した場合にはアカウントの再発行となるので // アカウント作り直しのフローを作る必要がある /*if (!response.loginSuccess) * { * //リトライ用のダイアログを設定 * SimpleDialog dialog = SharedUI.Instance.ShowSimpleDialog(); * var content = dialog.SetAsMessageDialog("ログインに失敗しました" + "\n" + "login_success = " + response.loginSuccess); * content.buttonGroup.buttons[0].onClick = dialog.Close; * dialog.onClose = onRetry; * return; * }*/ //ログイン時に取得するuserIDとhashの設定 userData.Set(response.userData); userData.Save(); HomeScene.isMaxPossession = response.isMaxPossession; //通信完了 onCompleted?.Invoke(); }; //通信開始 request.Send(); }
/// <summary> /// 砲台のセット通信 /// </summary> public static void CallSetApi( uint settingNumber, uint batteryServerId, uint barrelServerId, uint bulletServerId, uint accessoryServerId, Action onCompleted) { #if SHARK_OFFLINE { onCompleted?.Invoke(); return; } #endif var request = new SharkWebRequest <CannonSetResponseData>("cannon/set"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "settingNumber", settingNumber }, { "batteryCannonId", batteryServerId }, { "barrelCannonId", barrelServerId }, { "bulletCannonId", bulletServerId }, { "accessoriesCannonId", accessoryServerId }, }); request.onSuccess = (response) => { var userData = UserData.Get(); for (int i = 0; i < userData.turretData.Length; i++) { if (userData.turretData[i].settingNumber == settingNumber) { userData.turretData[i] = response.tCannonSetting; break; } } onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// マルチゲーム開始 /// </summary> public static void CallStartApi(uint worldId, string roomId, Action onCompleted) { var request = new SharkWebRequest <object>("multi/multiStart"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "multiWorldId", worldId }, { "roomId", roomId }, }); request.onSuccess = (response) => { onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// パーツロック情報の通信 /// </summary> public static void CallCannonLock(UserPartsData partsData, Action onCompleted) { var request = new SharkWebRequest <CannonLockResponseData>("cannon/cannonLock"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "cannonId", partsData.serverId }, { "cannonType", partsData.itemType } }); request.onSuccess = (response) => { partsData.lockFlg = response.tCannon.lockFlg; onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// シングルバトル終了通信 /// </summary> public static void CallClearApi( ClearResult clearResult, Rank clearRank, Action <ClearResponseData> onCompleted) { var request = new SharkWebRequest <ClearResponseData>("single/clear"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "playingStatus", (int)PlayingStatus.Finish }, { "result", (int)clearResult }, { "clearRank", (int)clearRank }, }); request.onSuccess = (response) => { foreach (var reward in response.firstReward) { if (reward.directFlg > 0) { UserData.Get().AddItem((ItemType)reward.itemType, reward.itemId, reward.itemNum); } } foreach (var reward in response.normalReward) { reward.Set(); if (reward.directFlg > 0) { UserData.Get().AddItem((ItemType)reward.itemType, reward.itemId, reward.itemNum); } } HomeScene.isMaxPossession = response.isMaxPossession; onCompleted?.Invoke(response); }; request.Send(); }
/// <summary> /// 商品購入通信 /// </summary> public static void CallItemBuyApi(uint shopId, uint buyNum, LogData logData, Action <UserShopData> onCompleted) { var request = new SharkWebRequest <ShopApi.BuyResponseData>("multiPlaying/itemBuy"); request.SetRequestHeader("AccessToken", UserData.Get().hash); var requestParameter = logData.ToRequestParameter(); requestParameter.Add("shopId", shopId); requestParameter.Add("buyNum", buyNum); request.SetRequestParameter(requestParameter); request.onSuccess = (response) => { ShopApi.OnSuccessBuyApi(response, onCompleted); }; request.Send(); }
/// <summary> /// アイテム使用通信 /// </summary> public static void CallItemUseApi(UserItemData itemData, Action onCompleted) { var request = new SharkWebRequest <ItemUseResponseData>("multiPlaying/itemUse"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "itemId", itemData.itemId } }); request.onSuccess = (response) => { itemData.stockCount = response.tItem.stockCount; onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// 砲台追加 TODO. サーバ側で、APIを準備するまで /// </summary> public static void CallAddApi( uint settingNumber, uint batteryServerId, uint barrelServerId, uint bulletServerId, uint accessoryServerId, Action onCompleted) { #if SHARK_OFFLINE { onCompleted?.Invoke(); return; } #endif var request = new SharkWebRequest <CannonSetResponseData>("cannon/set"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "settingNumber", settingNumber }, { "batteryCannonId", batteryServerId }, { "barrelCannonId", barrelServerId }, { "bulletCannonId", bulletServerId }, { "accessoriesCannonId", accessoryServerId }, }); request.onSuccess = (response) => { var userData = UserData.Get(); List <UserTurretData> turretDataList = userData.turretData.ToList(); turretDataList.Add(response.tCannonSetting); userData.turretData = turretDataList.ToArray(); onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// ギアスロット解除 /// </summary> public static void CallGearAddSlotApi( uint partsServerId, uint partsType, Action onCompleted) { var request = new SharkWebRequest <GearAddSlotResponseData>("cannon/addSlot"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "cannonId", partsServerId }, { "cannonType", partsType }, }); request.onSuccess = (response) => { onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// ユーザー情報取得通信 /// </summary> public static void CallFindApi(UserData userData, Action onCompleted) { var request = new SharkWebRequest <FindResponseData>("user/find"); request.SetRequestHeader("AccessToken", userData.hash); request.SetRequestParameter(new Dictionary <string, object> { { "userId", userData.userId } }); request.onSuccess = (response) => { //ユーザーデータセット userData.Set(response.tUsers); UserData.Set(userData); //通信完了 onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// ギアまとめて、ロック情報の通信 /// </summary> public static void CallGearLockList(List <uint> gearId, Action onCompleted) { var request = new SharkWebRequest <GearCollectLockResponseData>("cannon/gearLockList"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "gearId", gearId } }); request.onSuccess = (response) => { var gearData = UserData.Get().gearData; for (int i = 0; i < gearData.Length; i++) { var id = response.tGear .Where(x => x.serverId == gearData[i].serverId) .Select(x => x.serverId) .SingleOrDefault(); if (id > 0) { var lockFlgResponse = response.tGear .Where(x => x.serverId == id) .Select(x => x.lockFlg) .SingleOrDefault(); gearData[i].lockFlg = lockFlgResponse; } } onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// シングルバトル開始通信 /// </summary> public static void CallStartApi(uint stageId, Action onCompleted) { #if SHARK_OFFLINE onCompleted?.Invoke(); return; #endif var request = new SharkWebRequest <object>("single/start"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "stageId", stageId } }); request.onSuccess = (response) => { UserData.Get().coin -= Masters.SingleStageDB.FindById(stageId).needCoin; onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// 補償取得通信 /// </summary> public static void CallVipRewardGetApi(uint vipLevel, Action onCompleted) { var request = new SharkWebRequest <VipRewardGetResponseData>("vip/rewardGet"); request.SetRequestHeader("AccessToken", UserData.Get().hash); request.SetRequestParameter(new Dictionary <string, object> { { "vipLevel", vipLevel } }); request.onSuccess = (response) => { UserData userData = UserData.Get(); // アイテム更新 foreach (var add in response.mVipReward) { userData.AddItem((ItemType)add.itemType, add.itemId, add.itemNum); } //ジェムとコインを反映 if (response.tGem != null) { userData.Set(response.tGem); } if (response.tUsers != null) { userData.Set(response.tUsers); SharedUI.Instance.header.SetInfo(userData); } onCompleted?.Invoke(); }; request.Send(); }
/// <summary> /// 有償石の購入 /// </summary> public static void CallBuyApi( string productId, string receipt, Action <UserBillingData> onCompleted, Action <BillingBuyErrorType, int> onError) { #if DEBUG if (receipt == "dummy") { CoroutineUpdator.Create(null, () => { var billingData = Masters.BillingDB.GetList().Find(x => x.productId == productId); var billingItems = Masters.BillingItemDB.GetList().FindAll(x => x.billingItemId == billingData.billingItemId); UserData.Get().chargeGem += (ulong)billingItems.Where(x => x.itemType == (uint)ItemType.ChargeGem).Sum(x => x.itemNum); UserData.Get().freeGem += (ulong)billingItems.Where(x => x.itemType == (uint)ItemType.FreeGem).Sum(x => x.itemNum); UserData.Get().coin += (ulong)billingItems.Where(x => x.itemType == (uint)ItemType.Coin).Sum(x => x.itemNum); onCompleted?.Invoke(new UserBillingData { billingId = billingData.id }); }); return; } #endif //リクエスト作成 var request = new SharkWebRequest <BuyResponseData>("billing/buy"); request.SetRequestHeader("AccessToken", UserData.Get().hash); //リクエストパラメータセット request.SetRequestParameter(new Dictionary <string, object> { { "productId", productId }, { "receipt", receipt }, { "platform", SharkDefine.DEVICE_TYPE }, }); //通信完了時コールバック登録 request.onSuccess = (response) => { //サーバーでアイテム付与成功 if (response.tBilling.status == (uint)UserBillingData.Status.AddItem) { //クライアントもアイテム付与 foreach (var item in response.mBillingItem) { UserData.Get().AddItem((ItemType)item.itemType, item.itemId, item.itemNum); } // tUsers更新 if (response.tUsers != null) { UserData.Get().Set(response.tUsers); } //通信完了 onCompleted?.Invoke(response.tBilling); } //何らかのエラー else { BillingBuyErrorType errorType = BillingBuyErrorType.None; int errorCode = 0; if (response.tBilling.status == (uint)UserBillingData.Status.ReceiptChkFailed) { //レシート検証に失敗:念のためペンディングは解除しない errorType = BillingBuyErrorType.BillingStatusType; errorCode = (int)UserBillingData.Status.ReceiptChkFailed; } #if UNITY_EDITOR || UNITY_ANDROID else if (response.result.purchaseState == (int)GoogleBuyResult.PurchaseState.Canceled) { //キャンセル済み:ペンディング解除OK errorType = BillingBuyErrorType.GooglePurchaseState; errorCode = (int)GoogleBuyResult.PurchaseState.Canceled; } else if (response.result.purchaseState == (int)GoogleBuyResult.PurchaseState.Pending) { //ペンディング中:ペンディング解除NG errorType = BillingBuyErrorType.GooglePurchaseState; errorCode = (int)GoogleBuyResult.PurchaseState.Pending; } #endif //エラー通知 onError?.Invoke(errorType, errorCode); } }; //エラーコールバック登録 request.onError = (errodCode) => { onError?.Invoke(BillingBuyErrorType.ErrorCodeType, errodCode); }; //通信開始 request.Send(); }
/// <summary> /// 商品購入通信 /// </summary> public static void CallBuyApi(uint shopId, uint buyNum, Action <UserShopData> onCompleted) { #if SHARK_OFFLINE //オフライン時の仮対応 UserData user = UserData.Get(); if (user != null) { //購入による消費関連の設定 ShopData shopData = Masters.ShopDB.FindById(shopId); ulong totalCost = 0; if (shopData.needChargeGem > 0) { totalCost = shopData.needChargeGem * buyNum; user.chargeGem -= totalCost; } else if (shopData.needFreeGem > 0) { totalCost = shopData.needFreeGem * buyNum; if (user.freeGem < totalCost) { user.chargeGem -= totalCost - user.freeGem; user.freeGem = 0; } else { user.freeGem -= totalCost; } } else if (shopData.needCoin > 0) { totalCost = shopData.needCoin * buyNum; user.coin -= totalCost; } //購入によるアイテム付与 List <ShopItemData> shopItemDatas = Masters.ShopItemDB.GetList().FindAll(x => x.shopItemId == shopData.shopItemId); foreach (ShopItemData shopItem in shopItemDatas) { //ひとまずはコインとジェムのみ switch ((ItemType)shopItem.itemType) { case ItemType.ChargeGem: user.chargeGem += shopItem.itemNum * buyNum; break; case ItemType.FreeGem: user.freeGem += shopItem.itemNum * buyNum; break; case ItemType.Coin: user.coin += shopItem.itemNum * buyNum; break; } } //購入による履歴の設定 UserShopData userShopData = new UserShopData(); userShopData.shopId = shopData.id; userShopData.buyNum = buyNum; onCompleted?.Invoke(userShopData); return; } #endif //リクエスト作成 var request = new SharkWebRequest <BuyResponseData>("shop/buy"); request.SetRequestHeader("AccessToken", UserData.Get().hash); //リクエストパラメータセット request.SetRequestParameter(new Dictionary <string, object> { { "shopId", shopId }, { "buyNum", buyNum }, }); //通信完了時コールバック登録 request.onSuccess = (response) => { OnSuccessBuyApi(response, onCompleted); }; //通信開始 request.Send(); }