✨ feat(gvg): 农庄
This commit is contained in:
@@ -121,6 +121,8 @@ import { dicGiftPackagePlan, loadGiftPackagePlan } from "./dictionary/DicGiftPac
|
||||
import { dicGVGPeriod, loadGVGPeriod } from './dictionary/DicGVGPeriod';
|
||||
import { dicGVGTech, loadGVGTech } from "./dictionary/DicGVGTech";
|
||||
import { dicGVGItem, loadGVGItem } from "./dictionary/DicGVGItems";
|
||||
import { dicGVGLeagueLv, loadGVGLeagueLv } from "./dictionary/DicGVGLeagueLv";
|
||||
import { dicGVGResourceBase, dicGVGResourceBaseByType, dicGVGResourceBaseByLv, loadGVGResourceBase, DicGVGResourceBase } from './dictionary/DicGVGResourceBase';
|
||||
|
||||
export const gameData = {
|
||||
daily: dicDaily,
|
||||
@@ -302,6 +304,12 @@ export const gameData = {
|
||||
gvgTech: dicGVGTech,
|
||||
gvgItem: dicGVGItem,
|
||||
gvgActive: new Map<number, number>(),
|
||||
gvgLeagueLv: dicGVGLeagueLv,
|
||||
gvgResource: dicGVGResourceBase,
|
||||
gvgResourceBaseByType: dicGVGResourceBaseByType,
|
||||
gvgResourceBaseByLv: dicGVGResourceBaseByLv,
|
||||
gvgFieldAddType: new Map<number, number>(),
|
||||
gvgSpFieldRatio: { min: 0, max: 0},
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
@@ -1081,6 +1089,57 @@ function parseGVGActive() {
|
||||
}
|
||||
}
|
||||
|
||||
export function calLeagueLv(resources: { food: number, mineral: number, wood: number }) {
|
||||
let lv = 1;
|
||||
for(let [curLv, dic] of gameData.gvgLeagueLv) {
|
||||
lv = curLv;
|
||||
if(resources.food < dic.food || resources.mineral < dic.mineral || resources.wood < dic.wood) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return lv
|
||||
}
|
||||
|
||||
export function getGVGResourceBasesByType(type: number) {
|
||||
const ids = gameData.gvgResourceBaseByType.get(type)||[];
|
||||
const result: DicGVGResourceBase[] = [];
|
||||
for(let id of ids) {
|
||||
let dicResource = gameData.gvgResource.get(id);
|
||||
if(dicResource) result.push(dicResource);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function getGVGResourceBaseByTypeAndLv(type: number, lv: number) {
|
||||
let id = gameData.gvgResourceBaseByLv.get(`${type}_${lv}`);
|
||||
return gameData.gvgResource.get(id);
|
||||
}
|
||||
|
||||
|
||||
// 获取农庄小游戏最多能有多少特殊加成田
|
||||
export function getFieldMaxAddType(farmId: number) {
|
||||
let add = new Map<number, number>();
|
||||
let dicResource = gameData.gvgResource.get(farmId);
|
||||
if(!dicResource) return add;
|
||||
for(let [type, ratio] of gameData.gvgFieldAddType) {
|
||||
add.set(type, Math.floor(dicResource.sum * ratio / 100))
|
||||
}
|
||||
return add;
|
||||
}
|
||||
|
||||
function parseGVGFieldAdd() {
|
||||
let arr = decodeArrayListStr(param.GVG.GVG_FIELD_TYPE_RATIO);
|
||||
for(let [type, ratio] of arr) {
|
||||
gameData.gvgFieldAddType.set(parseInt(type), parseFloat(ratio));
|
||||
}
|
||||
}
|
||||
|
||||
function parseGVGSpFieldRatio() {
|
||||
let arr = param.GVG.GVG_SP_FIELD_RATIO.split('&');
|
||||
gameData.gvgSpFieldRatio.min = parseFloat(arr[0]);
|
||||
gameData.gvgSpFieldRatio.max = parseFloat(arr[0]);
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
function initDatas() {
|
||||
parseDicParam();
|
||||
@@ -1102,6 +1161,8 @@ function parseDicParam() {
|
||||
decodeLadderBuyCost();
|
||||
parseComBattleRewardTime();
|
||||
parseGVGActive();
|
||||
parseGVGFieldAdd();
|
||||
parseGVGSpFieldRatio();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1280,6 +1341,8 @@ function loadDatas() {
|
||||
loadGVGPeriod();
|
||||
loadGVGTech();
|
||||
loadGVGItem();
|
||||
loadGVGLeagueLv();
|
||||
loadGVGResourceBase();
|
||||
}
|
||||
|
||||
// 重载dicParam
|
||||
|
||||
@@ -384,4 +384,8 @@ export const GVG = {
|
||||
GVG_SERVICETYPE_VESTIGE: '1&1|2&3', // 单服和跨服随机出几个遗迹点
|
||||
GVG_ARMY_LEAGUE_TIME: 3, // GVG开启军团等级开启限制
|
||||
GVG_ROLE_TYPE: '1&贤臣|2&猛将', // GVG中职能选择
|
||||
GVG_SP_FIELD_ADD: 0.2,
|
||||
GVG_FARM_LOCK_TIME: 180,
|
||||
GVG_FIELD_TYPE_RATIO: '1&10|2&20|3&10',
|
||||
GVG_SP_FIELD_RATIO: '30&60',
|
||||
};
|
||||
|
||||
@@ -22,6 +22,8 @@ export interface DicGVGItem {
|
||||
reward: RewardInter[];
|
||||
// 消耗后可获得的这张表里的奖励
|
||||
leagueReward: RewardInter[];
|
||||
// 成熟时间
|
||||
ripeTime: number;
|
||||
}
|
||||
|
||||
export const dicGVGItem = new Map<number, DicGVGItem>();
|
||||
|
||||
34
shared/pubUtils/dictionary/DicGVGLeagueLv.ts
Normal file
34
shared/pubUtils/dictionary/DicGVGLeagueLv.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// GVG道具
|
||||
import { FILENAME } from '../../consts'
|
||||
import { RewardInter } from '../interface';
|
||||
import { parseGoodStr, readFileAndParse } from '../util'
|
||||
|
||||
export interface DicGVGLeagueLv {
|
||||
// 等级
|
||||
lv: number;
|
||||
// 粮食
|
||||
food: number;
|
||||
// 矿产
|
||||
mineral: number;
|
||||
// 木材
|
||||
wood: number;
|
||||
// 消耗后可获得的奖励
|
||||
reward: RewardInter[];
|
||||
}
|
||||
|
||||
export const dicGVGLeagueLv = new Map<number, DicGVGLeagueLv>();
|
||||
export function loadGVGLeagueLv() {
|
||||
dicGVGLeagueLv.clear();
|
||||
|
||||
let arr = readFileAndParse(FILENAME.DIC_GVG_LEAGUE_LV);
|
||||
let food = 0, mineral = 0, wood = 0;
|
||||
arr.forEach(o => {
|
||||
food += o.food;
|
||||
mineral += o.mineral;
|
||||
wood += o.wood;
|
||||
dicGVGLeagueLv.set(o.lv, {
|
||||
lv: o.lv, reward: parseGoodStr(o.reward), food, mineral, wood,
|
||||
});
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
74
shared/pubUtils/dictionary/DicGVGResourceBase.ts
Normal file
74
shared/pubUtils/dictionary/DicGVGResourceBase.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
// GVG千机阁
|
||||
import { FILENAME } from '../../consts';
|
||||
import { decodeArrayListStr, parseNumberList, readFileAndParse } from '../util';
|
||||
const _ = require('lodash');
|
||||
|
||||
export interface DicGVGResourceBase {
|
||||
// 唯一id
|
||||
id: number;
|
||||
// 名称
|
||||
name: string
|
||||
// 农庄等级
|
||||
lv: number;
|
||||
// 类型 1-农田 2-矿场 3-木堆
|
||||
type: number;
|
||||
// 限制类型
|
||||
limitType: number;
|
||||
// 限制参数
|
||||
limitParams: number[];
|
||||
// 农田产量加成
|
||||
fieldAdd: number;
|
||||
// 矿山铁矿的含铁量
|
||||
mineralValue: { type: number, output: number, count: number }[];
|
||||
// 单木框产量
|
||||
woodOutput: number;
|
||||
// 总数
|
||||
sum: number;
|
||||
}
|
||||
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
const DicGVGResourceBaseKeys: KeysEnum<DicGVGResourceBase> = {
|
||||
id: true, name: true, lv: true, type: true, limitType: true, limitParams: true, fieldAdd: true, mineralValue: true, woodOutput: true, sum: true
|
||||
}
|
||||
export const dicGVGResourceBase = new Map<number, DicGVGResourceBase>(); // id => DicGVGResourceBase
|
||||
export const dicGVGResourceBaseByType = new Map<number, number[]>(); // type => [id]
|
||||
export const dicGVGResourceBaseByLv = new Map<string, number>(); // type + lv => [id]
|
||||
export function loadGVGResourceBase() {
|
||||
dicGVGResourceBase.clear();
|
||||
dicGVGResourceBaseByType.clear();
|
||||
dicGVGResourceBaseByLv.clear();
|
||||
|
||||
let arr = readFileAndParse(FILENAME.DIC_GVG_RESOURCE_BASE);
|
||||
arr.forEach(o => {
|
||||
o.limitParams = parseNumberList(o.limitParams);
|
||||
if(o.type == 1) { // 农田
|
||||
o.fieldAdd = parseFloat(o.value.split('&')[1]);
|
||||
if(isNaN(o.fieldAdd)) throw new Error('data table format wrong');
|
||||
} else if (o.type == 2) { // 矿山
|
||||
o.mineralValue = parseMineralValue(o.value);
|
||||
} else if (o.type == 3) {
|
||||
o.woodOutput = parseFloat(o.value.split('&')[1]);
|
||||
if(isNaN(o.woodOutput)) throw new Error('data table format wrong');
|
||||
}
|
||||
dicGVGResourceBase.set(o.id, _.pick(o, Object.keys(DicGVGResourceBaseKeys)));
|
||||
dicGVGResourceBaseByLv.set(`${o.type}_${o.lv}`, o.id);
|
||||
if(!dicGVGResourceBaseByType.has(o.type)) {
|
||||
dicGVGResourceBaseByType.set(o.type, []);
|
||||
}
|
||||
dicGVGResourceBaseByType.get(o.type)?.push(o.id);
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
|
||||
function parseMineralValue(str: string) {
|
||||
let result = new Array<{ type: number, output: number, count: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [type, output, count] of decodeArr) {
|
||||
if (isNaN(parseInt(type)) || isNaN(parseInt(output)) || isNaN(parseInt(count))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ type: parseInt(type), output: parseInt(output), count: parseInt(count) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// GVG千机阁
|
||||
import { FILENAME } from '../../consts'
|
||||
import { decodeArrayListStr, readFileAndParse } from '../util'
|
||||
import { decodeArrayListStr, parseNumberList, readFileAndParse } from '../util'
|
||||
|
||||
export interface DicGVGTech {
|
||||
// 唯一id
|
||||
@@ -12,7 +12,7 @@ export interface DicGVGTech {
|
||||
// 效果类型 1-资源产量上传 2-征战中原提升 3-激战期提升 4-复活cd减少 5-箭塔 6-攻城车
|
||||
type: number;
|
||||
// 资源提升量啊,复活cd减少量啊之类的值
|
||||
param: number;
|
||||
param: number[];
|
||||
// 点排序
|
||||
nodeSort: number;
|
||||
// 联军等级限制
|
||||
@@ -30,6 +30,7 @@ export function loadGVGTech() {
|
||||
let arr = readFileAndParse(FILENAME.DIC_GVG_TECH);
|
||||
arr.forEach(o => {
|
||||
o.prepositionId = parsePrePositionId(o.prepositionId);
|
||||
o.param = parseNumberList(o.param)
|
||||
dicGVGTech.set(o.id, o);
|
||||
});
|
||||
arr = undefined;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import moment = require('moment');
|
||||
import { REFRESH_TIME, TIME_OUTPUT_TYPE, SHOP_REFRESH_TYPE } from '../consts';
|
||||
import { isDebugTime } from './sdkUtil';
|
||||
|
||||
@@ -559,3 +560,12 @@ export function setWeek(d?: number) {
|
||||
week = d;
|
||||
if(d == 7) week = 0;
|
||||
}
|
||||
|
||||
|
||||
export function getPastTime() {
|
||||
return moment('2022-01-01').unix();
|
||||
}
|
||||
|
||||
export function getFutureTime() {
|
||||
return moment('2100-01-01').unix();
|
||||
}
|
||||
@@ -821,4 +821,10 @@ export function getGachaRemainFloor(gachaId: number, userFloor: Floor[]) {
|
||||
export function isDevelopEnv(env: string) {
|
||||
const envs = ['development', 'monitor', 'alpha', 'dev'];
|
||||
return envs.indexOf(env) != -1;
|
||||
}
|
||||
|
||||
export function getArrayOfNumber(len: number) {
|
||||
let arr: number[] = [];
|
||||
for(let i = 1; i <= len; i++) arr.push(i);
|
||||
return arr;
|
||||
}
|
||||
Reference in New Issue
Block a user