🎈 perf(clear): 格式化

This commit is contained in:
luying
2023-07-14 13:38:07 +08:00
parent 1d02e0f62e
commit 9c10f33401
6 changed files with 1086 additions and 1086 deletions
File diff suppressed because it is too large Load Diff
+35 -35
View File
@@ -18,19 +18,19 @@ export class CheckMeterial {
constructor(roleId: string, role?: RoleType, items?: ItemType[]) {
this.roleId = roleId;
if(role) {
if (role) {
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
if(items && items.length) {
for(let {id, count} of items) {
if (items && items.length) {
for (let { id, count } of items) {
this.itemsIndb.set(id, count);
}
}
}
private pushToNotEnoughItems(id: number, count: number) {
if(!this.notEnoughItems.has(id)) {
if (!this.notEnoughItems.has(id)) {
this.notEnoughItems.set(id, 0);
}
this.notEnoughItems.set(id, this.notEnoughItems.get(id) + count);
@@ -38,21 +38,21 @@ export class CheckMeterial {
public getNotEnoughItems() {
let map = new Map<number, number>();
for(let [ id, count ] of this.notEnoughItems) {
for (let [id, count] of this.notEnoughItems) {
map.set(id, count);
}
return map;
}
public async decrease(goods: {id: number, count: number}[]) {
public async decrease(goods: { id: number, count: number }[]) {
this.tempConsumes.splice(0, this.tempConsumes.length);
this.notEnoughItems.clear();
let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
for(let { id, count} of items) {
for (let { id, count } of items) {
let notEnoughCount = await this.decreaseItem(id, count);
if(notEnoughCount > 0) {
if (notEnoughCount > 0) {
let isEnough = await this.checkReplaceItem(id, notEnoughCount);
if(isEnough) {
if (isEnough) {
this.tempConsumes.push({ id, count: count - notEnoughCount });
} else {
return false;
@@ -60,29 +60,29 @@ export class CheckMeterial {
}
}
if(gold.length > 0) {
if (gold.length > 0) {
let isEnough = await this.decreaseGold(gold);
if(!isEnough) return false;
if (!isEnough) return false;
}
if(coin.length > 0) {
if (coin.length > 0) {
let isEnough = await this.decreaseCoin(coin);
if(!isEnough) return false;
if (!isEnough) return false;
}
this.consumes.push(...this.tempConsumes);
return true;
}
// 当消耗不足的时候,不提前返回,也不去算元宝和铜币
public async decreaseItemsContinue(goods: {id: number, count: number}[]) {
public async decreaseItemsContinue(goods: { id: number, count: number }[]) {
this.tempConsumes.splice(0, this.tempConsumes.length);
this.notEnoughItems.clear();
let { items } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
let itemIsEnough = true;
for(let { id, count} of items) {
for (let { id, count } of items) {
let notEnoughCount = await this.decreaseItem(id, count);
if(notEnoughCount > 0) {
if (notEnoughCount > 0) {
let isEnough = await this.checkReplaceItem(id, notEnoughCount);
if(isEnough) {
if (isEnough) {
this.tempConsumes.push({ id, count: count - notEnoughCount });
} else {
itemIsEnough = false;
@@ -98,15 +98,15 @@ export class CheckMeterial {
}
private async decreaseItem(id: number, count: number) {
if(!this.itemsIndb.has(id)) {
if (!this.itemsIndb.has(id)) {
let item = await ItemModel.findbyRoleAndGid(this.roleId, id);
if(!item) {
if (!item) {
this.pushToNotEnoughItems(id, count);
return count;
}
this.itemsIndb.set(id, item.count);
}
if(this.itemsIndb.get(id) < count) {
if (this.itemsIndb.get(id) < count) {
let notEnoughCount = count - this.itemsIndb.get(id);
this.pushToNotEnoughItems(id, notEnoughCount);
this.itemsIndb.set(id, 0);
@@ -119,12 +119,12 @@ export class CheckMeterial {
}
private async checkReplaceItem(id: number, count: number) {
if(!this.canReplace) return false;
if (!this.canReplace) return false;
let relationGoodId = gameData.relationGoods.get(id);
if(!relationGoodId) return false;
if (!relationGoodId) return false;
if(relationGoodId == this.goldId) {
if (relationGoodId == this.goldId) {
return await this.decreaseGold([{ count }]);
} else if (relationGoodId == this.coinId) {
return await this.decreaseCoin([count]);
@@ -136,13 +136,13 @@ export class CheckMeterial {
private async decreaseGold(gold: { count: number }[]) {
if(!this.itemsIndb.has(this.goldId)) {
if (!this.itemsIndb.has(this.goldId)) {
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0);
if(this.itemsIndb.get(this.goldId) < goldCost) {
if (this.itemsIndb.get(this.goldId) < goldCost) {
this.pushToNotEnoughItems(this.goldId, goldCost - this.itemsIndb.get(this.goldId));
this.itemsIndb.set(this.goldId, 0);
return false;
@@ -154,13 +154,13 @@ export class CheckMeterial {
private async decreaseCoin(coin: number[]) {
if(!this.itemsIndb.has(this.coinId)) {
if (!this.itemsIndb.has(this.coinId)) {
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
let coinCost = coin.reduce((pre, cur) => pre + cur, 0);
if(this.itemsIndb.get(this.coinId) < coinCost) {
if (this.itemsIndb.get(this.coinId) < coinCost) {
this.pushToNotEnoughItems(this.coinId, coinCost - this.itemsIndb.get(this.coinId));
this.itemsIndb.set(this.coinId, 0);
return false;
@@ -172,8 +172,8 @@ export class CheckMeterial {
private getMaterialEnough(materials: RewardInter[], notEnoughItems: Map<number, number>) {
let newMaterials: RewardInter[] = [];
for(let {id, count} of materials) {
if(notEnoughItems.has(id)) {
for (let { id, count } of materials) {
if (notEnoughItems.has(id)) {
newMaterials.push({ id, count: count - notEnoughItems.get(id) });
} else {
newMaterials.push({ id, count });
@@ -185,19 +185,19 @@ export class CheckMeterial {
// 检查地玉石是否可以合成
public async composeStone(id: number, count: number) {
let dicStone = gameData.stone.get(id);
if(!dicStone || dicStone.composeMaterial.length <= 0) return false; // 1阶石头不能再从下合成返回不行
let materials = dicStone.composeMaterial.map(cur => ({...cur, count: cur.count * count }));
if (!dicStone || dicStone.composeMaterial.length <= 0) return false; // 1阶石头不能再从下合成返回不行
let materials = dicStone.composeMaterial.map(cur => ({ ...cur, count: cur.count * count }));
let isEnough = await this.decrease(materials);
if(!isEnough) {
if (!isEnough) {
let notEnoughItems = this.getNotEnoughItems();
let newMaterials = this.getMaterialEnough(materials, notEnoughItems);
let isEnough = await this.decrease(newMaterials); // 消耗掉除了不足的部分以外的其他部分
if(!isEnough) return false;
if (!isEnough) return false;
let isAllOK = true; // 如果有石头不足,向下补充,isAllOK标识不足的都能补充上
for(let [id, count] of notEnoughItems) {
for (let [id, count] of notEnoughItems) {
let isEnough = await this.composeStone(id, count);
if(!isEnough) {
if (!isEnough) {
isAllOK = false; break;
}
}