GameDotMgr.js 12.3 KB
"use strict";
cc._RF.push(module, '42c85SZlkZBiK4oiwPhmvGG', 'GameDotMgr');
// script/game/GameDotMgr.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const simba_sdk_1 = require("simba-sdk");
const EditorEnums_1 = require("../avg/EditorEnums");
const AVG_1 = require("../avg/AVG");
const simba_config_manager_1 = require("simba-config-manager");
const Role_1 = require("../config/Role");
const GameConfig_1 = require("../GameConfig");
const Enums_1 = require("./Enums");
const GameModelManager_1 = require("./model/GameModelManager");
let GameDotMgr = /** @class */ (() => {
    class GameDotMgr {
        constructor() {
            this._majorIds = [];
        }
        static getInstance() {
            return GameDotMgr._instance;
        }
        async dot(eventKey, data, category) {
            // if (channel === "dummy") return;
            // category = category ? category : "yybs_event";
            // let baseElements = this.getBaseElements();
            // let biRet = await SDK.bi(category, eventKey, baseElements, data);
        }
        getBaseElements() {
            let regV = AVG_1.GameRecord.globalVariables["register_version"];
            if (!regV) {
                regV = GameConfig_1.GameConfig.gameVersion;
                AVG_1.GameRecord.globalVariables["register_version"] = regV;
                AVG_1.GameRecord.saveRecord();
            }
            let player = GameModelManager_1.GameModelManager.getPlayerData();
            let base = {
                energy: player.getEnergy(),
                gold: player.getGoldCoin(),
                silver: player.getClothCoin(),
                grace: [],
                user_register_version: regV,
                login_duration: simba_sdk_1.TimeManager.getGameTime(),
                total_duration: simba_sdk_1.TimeManager.getTotalGameTime(),
                daily_duration: simba_sdk_1.TimeManager.getTodayGameTime(),
            };
            let gArr = [];
            if (!this._majorIds || 0 === this._majorIds.length) {
                let r = simba_config_manager_1.ConfigManager.getAllConfig(Role_1.role);
                for (let id in r) {
                    let c = r[id];
                    if (c && c.RoleType === EditorEnums_1.RoleType.Role_Major) {
                        this._majorIds.push(c.id);
                    }
                }
            }
            for (let i = 0; i < this._majorIds.length; i++) {
                let rid = this._majorIds[i];
                let role = GameModelManager_1.GameModelManager.getRoleData(rid);
                let gv = role === null || role === void 0 ? void 0 : role.getRoleLike();
                gv = gv ? gv : 0;
                let item = {
                    roleId: rid,
                    grace: gv
                };
                gArr.push(item);
            }
            base.grace = gArr;
            return base;
        }
        async dotClickUI(uiName) {
            let eventKey = "click_ui";
            let recordKey = "click_ui_count_" + uiName + "_t_" + GameModelManager_1.GameModelManager.getCurDayStr();
            let clickCount = AVG_1.GameRecord.globalVariables[recordKey];
            if (undefined === clickCount) {
                clickCount = 0;
            }
            clickCount += 1;
            AVG_1.GameRecord.globalVariables[recordKey] = clickCount;
            AVG_1.GameRecord.saveRecord();
            // console.log("dotClickUI = ", { click_ui: clickCount, ui_location: uiName });
            await this.dot(eventKey, { click_ui: clickCount, ui_location: uiName }, "click_ui");
        }
        async dotLoading(state) {
            let eventKey = "loading";
            await this.dot(eventKey, { loading: state }, "loading");
        }
        /**
         *
         * @param playerId 玩家的PlayerId
         * @param gameConstData 兑换码兑换的道具ID
         */
        async dotExchangeCodeSuccess(playerId, gameConstData) {
            let eventKey = "exchange_code_success";
            await this.dot(eventKey, { exchange_code_success: playerId, gameConstData: gameConstData }, "exchange_code_success");
        }
        async dotCost(cType, cNum) {
            // let eventKey = "cost";
            // let recordKey = cType + GameModelManager.getCurDayStr();
            // let count = GameRecord.globalVariables[recordKey] as number;
            // if (undefined === count) {
            //     count = 0;
            // }
            // count = count + cNum;
            // GameRecord.globalVariables[recordKey] = count;
            // GameRecord.saveRecord();
            // let data = {};
            // data[cType] = count;
            // // console.log("dotCost = ", data);
            // await this.dot(eventKey, data, "cost");
        }
        async dotPlot(session, state) {
            let eventKey = "plot";
            let v = session + "_" + state;
            // console.log("dotPlot = ", { plot_state: v });
            await this.dot(eventKey, { plot_state: v }, "plot");
        }
        async dotExposure(eType) {
            // let eventKey = "show";
            // // console.log("dotExposure = ", { show: eType });
            // await this.dot(eventKey, { show: eType }, "show");
        }
        async dotShop(sType, param) {
            // let eventKey = "shop";
            // let data = {};
            // switch (sType) {
            //     case DotShopType.LuckyDraw:
            //         {
            //             data[sType] = param.location;
            //         }
            //         break;
            //     case DotShopType.Clothes:
            //         {
            //             if (param.isWear) {
            //                 data[sType] = "wear_" + param.sid + "_" + param.rid;
            //             } else {
            //                 data[sType] = "have_" + param.sid + "_" + param.rid;
            //             }
            //         }
            //         break;
            // }
            // // console.log("dotShop = ", data);
            // await this.dot(eventKey, data, "shop");
        }
        async dotShopTotal(sType, param) {
            // let eventKey = "shop_total";
            // let data = {};
            // switch (sType) {
            //     case DotShopTotalType.ShowGift:
            //         {
            //             let rKey = "g_i_t_show_c" + GameModelManager.getCurDayStr();;
            //             let total = GameRecord.globalVariables[rKey] as number;
            //             total = total ? total : 0;
            //             total++;
            //             data[sType] = {
            //                 show_id: "show_item_" + param.id,
            //                 total_show: total
            //             }
            //             GameRecord.globalVariables[rKey] = total;
            //         }
            //         break;
            //     case DotShopTotalType.BuyItem:
            //         {
            //             let rKey = "g_i_t_buy_c" + GameModelManager.getCurDayStr();;
            //             let total = GameRecord.globalVariables[rKey] as number;
            //             total = total ? total : 0;
            //             total++;
            //             data[sType] = {
            //                 buy_id: "buy_" + param.id,
            //                 total_buy: total
            //             }
            //             GameRecord.globalVariables[rKey] = total;
            //         }
            //         break;
            //     case DotShopTotalType.SendGift:
            //         {
            //             let rKey = "g_i_t_send_c" + GameModelManager.getCurDayStr();;
            //             let total = GameRecord.globalVariables[rKey] as number;
            //             total = total ? total : 0;
            //             total++;
            //             data[sType] =
            //             {
            //                 send_id: param.gid,
            //                 role_id: param.rid,
            //                 total_send: total
            //             };
            //             GameRecord.globalVariables[rKey] = total;
            //         }
            //         break;
            //     case DotShopTotalType.Popup:
            //         {
            //             data[sType] = param.popType;
            //         }
            //         break;
            // }
            // GameRecord.autoSave();
            // // console.log("dotShopTotal = ", data);
            // await this.dot(eventKey, data, "shop_total");
        }
        async dotTask(taskDotType, tId) {
            // let eventKey = "task";
            // let data = {};
            // data["daily_task"] = {};
            // switch (taskDotType) {
            //     case TaskDotType.CompleteTask:
            //         {
            //             data["daily_task"] = "completed_" + tId;
            //         }
            //         break;
            //     case TaskDotType.GetTaskRewards:
            //         {
            //             data["daily_task"] = "get_rewards_" + tId;
            //         }
            //         break;
            // }
            // await this.dot(eventKey, data, "task");
        }
        async dotMoment(id, optionType) {
            // let eventKey = "circle_of_friends";
            // let v = "circle_" + optionType;
            // await this.dot(eventKey, { circle: v }, "circle_of_friends");
        }
        async dotTutorial(tType, state, param) {
            let eventKey = "tutorial";
            let k = "" + tType;
            let v = "" + param.session;
            switch (state) {
                case Enums_1.TutorialState.SelectSentence:
                    {
                        v += state + param.plotId;
                    }
                    break;
                case Enums_1.TutorialState.SelectSentenceRet:
                    {
                        k += "_plot_select";
                        v += Enums_1.TutorialState.SelectSentence + param.plotId + state + param.select;
                    }
                    break;
                case Enums_1.TutorialState.Progress:
                    {
                        k += "_plot_progress";
                        v += state + param.progress;
                    }
                    break;
            }
            let data = {};
            data[k] = v;
            // console.log("dotTutorial = ", data);
            await this.dot(eventKey, data, "tutorial");
        }
        async dotShare(shareType, shareLocation) {
            let eventKey = "share";
            // console.log("dotShare = ", { share_type: shareType, share_location: shareLocation });
            await this.dot(eventKey, { share_type: shareType, share_location: shareLocation }, "share");
        }
        async dotVideo(videoType, videoLocation) {
            let eventKey = "video";
            // console.log("dotVideo = ", { video_type: videoType, video_location: videoLocation });
            await this.dot(eventKey, { video_type: videoType, video_location: videoLocation }, "video");
        }
        //todo
        async dotShareRes(location, titleId, imgId) {
            let eventKey = "share_source";
            let v = location + "_" + titleId + "_" + imgId;
            await this.dot(eventKey, { share_source: v }, "share_source");
        }
        async dotGuide(oprType, location) {
            let eventKey = "guide";
            let v = location + oprType;
            // console.log("dotGuide = ",{ guide: v });
            await this.dot(eventKey, { guide: v }, "guide");
        }
        async dotEvent(oprType, location) {
            let eventKey = 'event';
            let v = location;
            let data = {};
            data[oprType] = v;
            // console.log("dotEvent = ",data);
            await this.dot(eventKey, data, 'event');
        }
        async dotSpecialPlot(sceneId, plotId, selectIndex, contenType, contentStatus) {
            let eventKey = 'special_plot';
            let data = {
                scene: sceneId,
                plot: plotId,
                select: selectIndex,
                contentype: contenType,
                status: contentStatus
            };
            // console.log("dotSpecialPlot = ", data);
            await this.dot(eventKey, data, 'special_plot');
        }
    }
    GameDotMgr._instance = new GameDotMgr();
    return GameDotMgr;
})();
exports.default = GameDotMgr;

cc._RF.pop();