0a3cee0e-d616-496c-ac8f-17c583b5ee07.js 6.32 KB
"use strict";
cc._RF.push(module, '0a3ce4O1hZJbKyPF8WDte4H', 'GameRoleDataModel');
// script/game/model/GameRoleDataModel.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const GameRecord_1 = require("../../avg/game-data/GameRecord");
const GameModelManager_1 = require("./GameModelManager");
const ConfigManager_1 = require("../../common/gameplay/managers/ConfigManager");
const RelationLevelConfig_1 = require("../../config/RelationLevelConfig");
const EditorEnums_1 = require("../../avg/EditorEnums");
class GameRoleDataModel {
    constructor() {
        this._cfg = undefined;
        this._goldcoin = 0; //金币
        this._clothcoin = 0; //服装币
        this._skins = [];
        this._curSkin = -1;
        this._skinMaps = new Set();
        this._roleName = "";
        this._energyValue = 0; //灵力值
        this._itemMaps = new Map();
    }
    setConfig(cfg) {
        this._cfg = cfg;
        this.initDate();
    }
    getConfig() {
        return this._cfg;
    }
    initDate() {
        this.initSkin();
        this.initCoin();
        this.initData();
    }
    hasSkin(id) {
        return this._skinMaps.has(id);
    }
    getRoleLike() {
        return GameRecord_1.GameRecord.globalVariables["like" + this._cfg.id] + GameRecord_1.GameRecord.recordVariables["like" + this._cfg.id];
    }
    getPortrait(face = EditorEnums_1.FaceType.Normal, skin) {
        if (skin === undefined && this._curSkin > 0)
            skin = this._curSkin;
        return "textures/portrait/" + this._cfg.id + "/" + (skin !== undefined ? skin + "/" : "") + face;
    }
    getBust(skin) {
        if (skin === undefined && this._curSkin > 0)
            skin = this._curSkin;
        let ret = "textures/bust/" + this._cfg.id;
        if (skin) {
            ret += skin;
        }
        return ret;
    }
    getHeadIcon(small = false) {
        let ret = "textures/head_icon/" + (small ? "small/" : "large/") + this._cfg.id;
        if (this._curSkin > 0) {
            ret += "_" + this._curSkin;
        }
        return ret;
    }
    getRoleLikeLevel() {
        let configs = ConfigManager_1.ConfigManager.getAllConfig(RelationLevelConfig_1.relationLevelConfig);
        let level = 0;
        let like = this.getRoleLike();
        const maxLevel = Object.keys(configs).length;
        let levelValue = 0;
        for (let id = 1; id <= maxLevel; id++) {
            levelValue = configs[id].relation_value;
            if (like >= levelValue) {
                like -= levelValue;
                level = id;
            }
            else {
                break;
            }
        }
        return { level, currLike: like, nextLevelLike: levelValue, maxLevel };
    }
    addSkin(id) {
        this._skinMaps.add(id);
        let skinsstr = "";
        let index = 0;
        for (let value of this._skinMaps) {
            skinsstr += value;
            if (index != this._skinMaps.size - 1) {
                skinsstr += ",";
            }
            ++index;
        }
        GameRecord_1.GameRecord.globalVariables["skins_" + this._cfg.id + "_skins"] = skinsstr;
        GameRecord_1.GameRecord.autoSave();
    }
    initSkin() {
        let curSkin = GameRecord_1.GameRecord.globalVariables["curskin_" + this._cfg.id + "_skin"];
        this._curSkin = curSkin === undefined ? this._cfg['drawing'] : curSkin;
        let skins = GameRecord_1.GameRecord.globalVariables["skins_" + this._cfg.id + "_skins"];
        skins = skins === undefined ? "" : skins;
        let skinSpilt = skins.split(",");
        for (let index = 0; index < skinSpilt.length; ++index) {
            this._skinMaps.add(parseInt(skinSpilt[index]));
        }
    }
    initCoin() {
        let goldcoin = GameRecord_1.GameRecord.globalVariables["goldcoin_" + this._cfg.id + "_num"];
        this._goldcoin = goldcoin === undefined ? 0 : goldcoin;
        let clothcoin = GameRecord_1.GameRecord.globalVariables["clothcoin_" + this._cfg.id + "_num"];
        this._clothcoin = clothcoin === undefined ? 0 : clothcoin;
    }
    initData() {
        this._itemMaps.clear();
        let props = GameModelManager_1.GameModelManager.getItemConfigs();
        for (let key in props) {
            let value = props[key];
            let recordNum = GameRecord_1.GameRecord.globalVariables["prop_" + this._cfg.id + value.id + "_num"];
            recordNum = recordNum === undefined ? 0 : recordNum;
            this._itemMaps.set(value.id, recordNum);
        }
        this._energyValue = GameRecord_1.GameRecord.globalVariables["energy_" + this._cfg.id];
        this._energyValue = this._energyValue === undefined ? 0 : this._energyValue;
    }
    getProps(id) {
        return this._itemMaps.get(id);
    }
    addProps(id, num) {
        let value = this._itemMaps.get(id);
        value += num;
        value = Math.max(0, value);
        this._itemMaps.set(id, value);
        GameRecord_1.GameRecord.globalVariables["prop_" + this._cfg.id + "" + id + "_num"] = value;
        GameRecord_1.GameRecord.autoSave();
    }
    getEnergy(isceil = true) {
        if (isceil) {
            return Math.ceil(this._energyValue);
        }
        return this._energyValue;
    }
    addEnergy(value) {
        let max = 100;
        let min = 0;
        this._energyValue += value;
        this._energyValue = Math.max(min, this._energyValue);
        this._energyValue = Math.min(max, this._energyValue);
        GameRecord_1.GameRecord.globalVariables["energy_" + this._cfg.id] = this._energyValue;
        GameRecord_1.GameRecord.autoSave();
    }
    getGoldCoin() {
        return this._goldcoin;
    }
    addGoldCoin(addvalue) {
        this._goldcoin += addvalue;
        GameRecord_1.GameRecord.globalVariables["goldcoin_" + this._cfg.id + "_num"] = this._goldcoin;
        GameRecord_1.GameRecord.autoSave();
    }
    getClothCoin() {
        return this._clothcoin;
        //return 10000;
    }
    addClothCoin(addvalue) {
        this._clothcoin += addvalue;
        GameRecord_1.GameRecord.globalVariables["clothcoin_" + this._cfg.id + "_num"] = this._clothcoin;
        GameRecord_1.GameRecord.autoSave();
    }
    getRoleName() {
        if (!this._roleName || this._roleName === "") {
            return this._cfg.name;
        }
        else {
            return this._roleName;
        }
    }
    setRoleName(name) {
        this._roleName = name;
    }
}
exports.default = GameRoleDataModel;

cc._RF.pop();