大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

137 lines
4.2 KiB

import { EGlobalEvent } from "../MesEvent/EGlobalEvent";
import CsvMgr from "../Mgr_CSV/CsvMgr";
import { BuildsDataProxy } from "../Mgr_LocalData/DataTypeProxy/BuildsDataProxy";
import { TaskDataProxy } from "../Mgr_LocalData/DataTypeProxy/TaskDataProxy";
import { TokenDataProxy } from "../Mgr_LocalData/DataTypeProxy/TokenDataProxy";
import { TreasureDataProxy } from "../Mgr_LocalData/DataTypeProxy/TreasureDataProxy";
import SceneDataMgr from "../Mgr_LocalData/SceneDataMgr";
import { BUILDING_TYPE, PropType, TASK_TYPE } from "./GameEnum";
import { BuildData } from "./GameInterface";
import { TREASURE_TYPE } from "./GGameData";
import IUpgrade from "./IUpgrade";
export default class BuildDataPoxy extends IUpgrade{
archive:BuildData;
cd:number;
income:number;
add:number;
upgradeCost:number;
constructor(buildingArchive:BuildData) {
// 调用父类构造函数,传入等级和材料参数
const config = CsvMgr.Builds_csv[buildingArchive.type];
super(buildingArchive.level, config.material_base, config.material_senior);
this.income = 0;
this.add = 0;
this.upgradeCost = 0;
this.cd = 0;
this.archive = buildingArchive;
// 如果建筑正在运行,初始化冷却时间
if (buildingArchive.running) {
this.cd = this.config.interval;
this.refreshIncome();
}else{
this.upgradeCost = config.cost;
}
}
/**
* 刷新建筑等级
*/
refreshLevel() {
this.archive.level = this.level;
BuildsDataProxy.Ins.Save();
this.refreshIncome();
}
/**
* 刷新建筑收益计算
*/
refreshIncome() {
const config = this.config;
const level = this.level;
// 计算基础收益
let baseValue = 0;
let cumulative = 5;
for (let i = 1; i < level; i++) {
baseValue += cumulative;
cumulative += 5;
}
this.income = cumulative * (config.costquality - 1);
// 这里修改add计算方式,表示下一级的收益
this.add = (cumulative + 5) * (config.costquality - 1);
// this.add = (baseValue + 5) * (config.costquality - 1);
this.upgradeCost = Math.floor(2500 * (level * level + 2) * (config.costquality - 1) + 2 * this.income * level * level);
// 应用投资属性加成
const investBonus = TreasureDataProxy.Ins.getProp1(TREASURE_TYPE.INVEST);
if (investBonus) {
this.income += Math.floor(this.income * investBonus * 0.01);
this.add += Math.floor(this.add * investBonus * 0.01);
}
// 检查建筑相关的任务进度
if(!TaskDataProxy.Ins.isCompleteAllTask()) {
const taskConfig = TaskDataProxy.Ins.task.config;
if(taskConfig.condition === TASK_TYPE.UPGRADE_BUILDING &&
taskConfig.conditionId >= BUILDING_TYPE.TEAHOUSE && taskConfig.conditionId <= BUILDING_TYPE.BANK){
SceneDataMgr.Ins.refreshTaskProgress();
}
}
}
/**
* 执行一次收益获取
*/
earnOnce() {
this.cd = this.config.interval;
TokenDataProxy.Ins.addToken(PropType.eGold, this.income)
//app.service.item.addCurrency(CurrencyType.Coin, this.income, false);
}
// Getter 属性
/**
* 获取建筑因子(用于升级计算)
*/
get factor() {
const level = this.level;
const quality = this.config.costquality;
if (level < 3) {
return quality + level - 2;
} else {
return Math.floor(1.5 * (level + 1) * (quality - 1)) + level - 3;
}
}
/**
* 获取或设置建筑运行状态
*/
get running() {
return this.archive.running;
}
set running(value) {
this.archive.running = value;
this.cd = this.config.interval; // 重置冷却时间
this.refreshIncome();
BuildsDataProxy.Ins.Save();
}
/**
* 获取建筑类型
*/
get type() {
return this.archive.type;
}
/**
* 获取建筑配置数据
*/
get config() {
return CsvMgr.Builds_csv[this.type];
}
}