c1dcd2f0-53b5-45aa-8b5c-8f322a23573d.js 10.1 KB
"use strict";
cc._RF.push(module, 'c1dcdLwU7VFqotcjzIqI1c9', 'ExchangeCodeViewPresenter');
// script/game/ui/presenter/ExchangeCodeViewPresenter.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const ExChangeCodeView_1 = require("../view/type/ExChangeCodeView");
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const HttpRequests_1 = require("../../network/HttpRequests");
const GameModelManager_1 = require("../../model/GameModelManager");
const GameConstData_1 = require("../../../common/gameplay/gamedata/GameConstData");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const GameTextData_1 = require("../../../common/gameplay/gamedata/GameTextData");
const GameDotMgr_1 = require("../../GameDotMgr");
const UnlockSpecialPlotEventManager_1 = require("../../model/UnlockSpecialPlotEventManager");
const CDKeyEventManager_1 = require("../../model/CDKeyEventManager");
const simba_sdk_exchangecode_1 = require("simba-sdk-exchangecode");
const ExchangeCodeClassBase_1 = require("simba-sdk-exchangecode/dist/ExchangeCodeClassBase");
const GameConfig_1 = require("../../../GameConfig");
let ExchangeCodeViewPresenter = /** @class */ (() => {
    let ExchangeCodeViewPresenter = class ExchangeCodeViewPresenter extends PresenterBase_1.Presenter {
        constructor() {
            super();
            this.onActionClickCallback = async (ret, cdkey) => {
                if (!cdkey || "" === cdkey.trim()) {
                    return;
                }
                GameDotMgr_1.default.getInstance().dotClickUI("exchange_code");
                let sdkExchangeCode = true;
                let toastStr = "";
                if (sdkExchangeCode) {
                    let ret = await simba_sdk_exchangecode_1.exchangeCode(cdkey);
                    if (GameConfig_1.GameConfig.debug)
                        console.log("SDKExchangeCode ret: ", ret);
                    switch (ret.errorCode) {
                        case ExchangeCodeClassBase_1.ExchangeErrorCode.Invalid:
                            {
                                toastStr = "兑换码无效";
                                if (GameConfig_1.GameConfig.debug)
                                    console.log("SDKExchangeCode Invalid, toastStr: ", toastStr);
                                UIManager_1.UIManager.showToast(toastStr);
                            }
                            break;
                        case ExchangeCodeClassBase_1.ExchangeErrorCode.OK:
                            {
                                if (ret.props && 0 !== ret.props.length) {
                                    let player = GameModelManager_1.GameModelManager.getPlayerData();
                                    for (let i = 0; i < ret.props.length; i++) {
                                        let p = ret.props[i];
                                        // player.addProps(parseInt(p.id + ''), parseInt(p.num + ''));
                                        let id = Number.parseInt(p.id + '');
                                        let count = Number.parseInt(p.num + '');
                                        if (id >= GameConstData_1.GameConstData.GAME_ITEM_AND_SPECIAL_PLOT_ID && id < 1000) {
                                            let itemId = Math.floor(id / GameConstData_1.GameConstData.GAME_ITEM_AND_SPECIAL_PLOT_ID);
                                            let specialPlotId = id - GameConstData_1.GameConstData.GAME_ITEM_AND_SPECIAL_PLOT_ID * itemId;
                                            UnlockSpecialPlotEventManager_1.default.getInstance().cdKeyUnlockSpecialPlot(specialPlotId, itemId);
                                        }
                                        else if (id === GameConstData_1.GameConstData.UNLOCK_PLOT_WITHOUT_AD) {
                                            CDKeyEventManager_1.default.getInstance().cdKeyRemovePlotAD();
                                        }
                                        else if (id >= GameConstData_1.GameConstData.CHANGE_ROLE_LIKE && id < 3000) {
                                            let roleId = id - GameConstData_1.GameConstData.CHANGE_ROLE_LIKE;
                                            CDKeyEventManager_1.default.getInstance().changeRoleLike(roleId, count);
                                        }
                                    }
                                    GameModelManager_1.GameModelManager.UpdatePlayerData.emit();
                                }
                            }
                            break;
                        case ExchangeCodeClassBase_1.ExchangeErrorCode.TimeOut:
                            {
                                toastStr = "兑换码已过期!";
                                if (GameConfig_1.GameConfig.debug)
                                    console.log("SDKExchangeCode TimeOut, toastStr: ", toastStr);
                                UIManager_1.UIManager.showToast(toastStr);
                            }
                            break;
                        case ExchangeCodeClassBase_1.ExchangeErrorCode.Used:
                            {
                                toastStr = "兑换码已经兑换过了";
                                if (GameConfig_1.GameConfig.debug)
                                    console.log("SDKExchangeCode Used, toastStr: ", toastStr);
                                UIManager_1.UIManager.showToast(toastStr);
                            }
                            break;
                        case ExchangeCodeClassBase_1.ExchangeErrorCode.ScoreWeak:
                            {
                                toastStr = "积分不足";
                                if (GameConfig_1.GameConfig.debug)
                                    console.log("SDKExchangeCode Used, toastStr: ", toastStr);
                                UIManager_1.UIManager.showToast(toastStr);
                            }
                            break;
                    }
                }
                else {
                    if (ret) {
                        let ret = await HttpRequests_1.HttpRequests.exchangeCDKEY(cdkey);
                        console.log("current ret is" + JSON.stringify(ret));
                        if (ret.code === "0") {
                            for (let i = 0; i < ret.obj.props.length; i++) {
                                let data = ret.obj.props[i];
                                let id = Number.parseInt(data.prop_id);
                                let count = Number.parseInt(data.count);
                                if (id >= GameConstData_1.GameConstData.GAME_ITEM_AND_SPECIAL_PLOT_ID && id < 1000) {
                                    let itemId = Math.floor(id / GameConstData_1.GameConstData.GAME_ITEM_AND_SPECIAL_PLOT_ID);
                                    let specialPlotId = id - GameConstData_1.GameConstData.GAME_ITEM_AND_SPECIAL_PLOT_ID * itemId;
                                    UnlockSpecialPlotEventManager_1.default.getInstance().cdKeyUnlockSpecialPlot(specialPlotId, itemId);
                                }
                                else if (id === GameConstData_1.GameConstData.UNLOCK_PLOT_WITHOUT_AD) {
                                    CDKeyEventManager_1.default.getInstance().cdKeyRemovePlotAD();
                                }
                                else if (id >= GameConstData_1.GameConstData.CHANGE_ROLE_LIKE && id < 3000) {
                                    let roleId = id - GameConstData_1.GameConstData.CHANGE_ROLE_LIKE;
                                    CDKeyEventManager_1.default.getInstance().changeRoleLike(roleId, count);
                                }
                            }
                            GameModelManager_1.GameModelManager.UpdatePlayerData.emit();
                        }
                        else if (ret.code === "104001") { //错误的验证码
                            let content = GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.TEXT_CDKEYINVALID_VALUE);
                            UIManager_1.UIManager.showToast(content);
                        }
                        else if (ret.code === "104002") { //已经领过了
                            let content = GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.TEXT_CDKEYHADEXCHANGED_VALUE);
                            UIManager_1.UIManager.showToast(content);
                        }
                        else { //其他
                            let content = GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.TEXT_CDKEYINVALID_VALUE);
                            UIManager_1.UIManager.showToast(content);
                        }
                    }
                }
            };
            this._viewProps = {
                onActionClick: this.onActionClickCallback
            };
        }
        onOpen(param) {
            super.onOpen(param);
            this._view.setProps(this._viewProps);
            this.view.setContentTxt(param.titletxt, param.contenttxt);
            this.view.showBanner(false);
        }
        onClose() {
            super.onClose();
            this.view.setContentTxt("", "");
        }
    };
    ExchangeCodeViewPresenter.uuid = "ExchangeCodeViewPresenter";
    ExchangeCodeViewPresenter = __decorate([
        PresenterCCViewFactory_1.RegPresenter(ExChangeCodeView_1.ExchangeCodeViewType)
    ], ExchangeCodeViewPresenter);
    return ExchangeCodeViewPresenter;
})();
exports.default = ExchangeCodeViewPresenter;

cc._RF.pop();