镇念塔:铜钱
This commit is contained in:
@@ -73,13 +73,14 @@ export class CheckMeterial {
|
|||||||
let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0);
|
let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0);
|
||||||
if(this.itemsIndb.get(this.goldId) < goldCost) isEnough = false;
|
if(this.itemsIndb.get(this.goldId) < goldCost) isEnough = false;
|
||||||
}
|
}
|
||||||
if(isEnough && coin > 0) {
|
if(isEnough && coin.length > 0) {
|
||||||
if(!this.itemsIndb.has(this.coinId)) {
|
if(!this.itemsIndb.has(this.coinId)) {
|
||||||
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
|
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
|
||||||
this.itemsIndb.set(this.goldId, role.gold);
|
this.itemsIndb.set(this.goldId, role.gold);
|
||||||
this.itemsIndb.set(this.coinId, role.coin);
|
this.itemsIndb.set(this.coinId, role.coin);
|
||||||
}
|
}
|
||||||
if(this.itemsIndb.get(this.coinId) < coin) isEnough = false;
|
let coinCost = coin.reduce((pre, cur) => pre + cur, 0);
|
||||||
|
if(this.itemsIndb.get(this.coinId) < coinCost) isEnough = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isEnough) this.consumes.push(...goods);
|
if(isEnough) this.consumes.push(...goods);
|
||||||
@@ -101,10 +102,11 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
|||||||
|
|
||||||
// 检查货币是否充足
|
// 检查货币是否充足
|
||||||
let role = await RoleModel.findByRoleId(roleId);
|
let role = await RoleModel.findByRoleId(roleId);
|
||||||
if (gold.length > 0 || coin > 0) {
|
if (gold.length > 0 || coin.length > 0) {
|
||||||
let { gold: originGold, coin: originCoin } = role;
|
let { gold: originGold, coin: originCoin } = role;
|
||||||
for(let {count} of gold) { originGold -= count };
|
for(let {count} of gold) { originGold -= count };
|
||||||
if(originGold < 0 || originCoin < coin) return false;
|
for(let count of coin) { originCoin -= count };
|
||||||
|
if(originGold < 0 || originCoin < 0) return false;
|
||||||
}
|
}
|
||||||
//检查装备是否存在
|
//检查装备是否存在
|
||||||
if (equips.length > 0) {
|
if (equips.length > 0) {
|
||||||
@@ -147,8 +149,9 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
|||||||
}
|
}
|
||||||
|
|
||||||
//消耗玩家货币
|
//消耗玩家货币
|
||||||
if (gold.length > 0 || coin > 0) {
|
if (gold.length > 0 || coin.length > 0) {
|
||||||
role = await RoleModel.decreaseGoldAndCoin(roleId, gold, coin);
|
let costCoin = coin.reduce((pre, cur) => pre + cur, 0);
|
||||||
|
role = await RoleModel.decreaseGoldAndCoin(roleId, gold, costCoin);
|
||||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, {
|
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, {
|
||||||
gold: role.gold, coin: role.coin
|
gold: role.gold, coin: role.coin
|
||||||
}), uids);
|
}), uids);
|
||||||
@@ -210,10 +213,10 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. 货币推送
|
// 3. 货币推送
|
||||||
if(gold.length > 0 || coin > 0 || ap > 0) {
|
if(gold.length > 0 || coin.length > 0 || ap > 0) {
|
||||||
let { ap: addAp } = await setAp(roleId, role.lv, ap, sid);
|
let { ap: addAp } = await setAp(roleId, role.lv, ap, sid);
|
||||||
|
let incCoin = coin.reduce((pre, cur) => pre + cur, 0);
|
||||||
role = await RoleModel.increaseGoldAndCoin(roleId, gold, coin);
|
role = await RoleModel.increaseGoldAndCoin(roleId, gold, incCoin);
|
||||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, {
|
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, {
|
||||||
gold: role.gold, coin: role.coin, ap: addAp
|
gold: role.gold, coin: role.coin, ap: addAp
|
||||||
}), uids);
|
}), uids);
|
||||||
@@ -222,8 +225,10 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
|||||||
showItems.push(getGoldObject(count));
|
showItems.push(getGoldObject(count));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(coin > 0) {
|
if(coin.length > 0) {
|
||||||
showItems.push(getCoinObject(coin));
|
coin.forEach(count => {
|
||||||
|
showItems.push(getCoinObject(count));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if(ap > 0) {
|
if(ap > 0) {
|
||||||
showItems.push(getApObject(ap));
|
showItems.push(getApObject(ap));
|
||||||
@@ -292,7 +297,7 @@ function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
|||||||
let items: { id: number, count: number }[] = []; // 可叠加道具
|
let items: { id: number, count: number }[] = []; // 可叠加道具
|
||||||
let equips: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
|
let equips: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
|
||||||
let gold: { count: number, isPay: boolean }[] = []; // 金币
|
let gold: { count: number, isPay: boolean }[] = []; // 金币
|
||||||
let coin: number = 0;
|
let coin: number[] = [];
|
||||||
let ap: number = 0;
|
let ap: number = 0;
|
||||||
let skins: number[] = [];
|
let skins: number[] = [];
|
||||||
let figures: number[] = [];
|
let figures: number[] = [];
|
||||||
@@ -346,7 +351,7 @@ function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
|||||||
gold.push({ count: good.count, isPay: !!good.isPay });
|
gold.push({ count: good.count, isPay: !!good.isPay });
|
||||||
}
|
}
|
||||||
} else if (dicCurrency.type == CURRENCY_TYPE.COIN) { // 铜钱
|
} else if (dicCurrency.type == CURRENCY_TYPE.COIN) { // 铜钱
|
||||||
coin += good.count;
|
coin.push(good.count);
|
||||||
} else if (dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 体力
|
} else if (dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 体力
|
||||||
ap += good.count;
|
ap += good.count;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user