结算获取消耗品和金币
This commit is contained in:
@@ -107,7 +107,7 @@ export class EventBattleHandler {
|
||||
eventCode: result.eventCode,
|
||||
eventId: result.eventId,
|
||||
status: result.status,
|
||||
goods
|
||||
...goods
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ export class ExpeditionBattleHandler {
|
||||
expeditionCode, expeditionId,
|
||||
battleCode, battleId,
|
||||
battleStatus: expeditionWarRecord.battleStatus,
|
||||
goods: reward,
|
||||
...reward,
|
||||
apJson,
|
||||
expeditionPoint
|
||||
});
|
||||
@@ -273,7 +273,7 @@ export class ExpeditionBattleHandler {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId,
|
||||
battleId, battleCode, battleStatus, received,
|
||||
goods
|
||||
...goods
|
||||
});
|
||||
|
||||
}
|
||||
@@ -315,7 +315,7 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
pointRewards,
|
||||
goods
|
||||
...goods
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ export class NormalBattleHandler {
|
||||
// towerBonus: 天梯每隔几层的额外宝箱
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleCode, battleId, status, towerStatus,
|
||||
goods: reward, towerBonus, towerReward,
|
||||
...reward, towerBonus, towerReward,
|
||||
apJson,
|
||||
dailyNum,
|
||||
heroes: curHeroes,
|
||||
@@ -262,7 +262,7 @@ export class NormalBattleHandler {
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleId, count,
|
||||
goods: result,
|
||||
...result,
|
||||
apJson,
|
||||
dailyNum,
|
||||
...actordata
|
||||
|
||||
@@ -85,7 +85,7 @@ export class TowerBattleHandler {
|
||||
}
|
||||
const goods = await handleFixedReward(roleId, roleName, timeReward, multi);
|
||||
const newRec = await HangUpRecordModel.updateRec(roleId, roleName, endLv, endTime);
|
||||
return resResult(STATUS.SUCCESS, { endTime, goods, hangUpRec: newRec });
|
||||
return resResult(STATUS.SUCCESS, { endTime, ...goods, hangUpRec: newRec });
|
||||
}
|
||||
|
||||
async hangUpSpeedUp(msg: {speedUpCnt: number}, session: BackendSession) {
|
||||
@@ -106,7 +106,7 @@ export class TowerBattleHandler {
|
||||
}
|
||||
const spdUpRec = await HangUpSpdUpRecModel.updateRec(roleId, roleName, multi, endLv);
|
||||
const goods = await handleFixedReward(roleId, roleName, timeReward, multi);
|
||||
return resResult(STATUS.SUCCESS, { goods, rewardLv: endLv, spdUpRec });
|
||||
return resResult(STATUS.SUCCESS, { ...goods, rewardLv: endLv, spdUpRec });
|
||||
}
|
||||
|
||||
async getTasks(msg: {}, session: BackendSession) {
|
||||
@@ -186,11 +186,11 @@ export class TowerBattleHandler {
|
||||
if (task.sendTime && task.sendTime.getTime() + completeTime * 1000 < curTime.getTime()) {
|
||||
compTasks.push(task.taskCode);
|
||||
const rewardGoods = await handleFixedReward(roleId, roleName, reward, 1);
|
||||
goods = goods.concat(rewardGoods);
|
||||
goods = goods.concat(rewardGoods.goods);
|
||||
if(bonusCondition) {
|
||||
const res = checkTaskConditions(roleId, task.heroes, bonusCondition);
|
||||
const bonusGoods = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
goods = goods.concat(bonusGoods);
|
||||
goods = goods.concat(bonusGoods.goods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,8 @@ import { BattleRecordModel } from './../db/BattleRecord';
|
||||
import { TowerRecordModel } from './../db/TowerRecord';
|
||||
import { RoleModel } from './../db/Role';
|
||||
import { getHeroInfoById, getJobInfoById, getTowerDataByLv, getLvByExp, getExpByLv } from "../pubUtils/gamedata"
|
||||
import { decodeArrayStr, shouldRefresh } from '../pubUtils/util';
|
||||
import { decodeArrayStr, shouldRefresh, resResult } from '../pubUtils/util';
|
||||
import { handleFixedReward } from './rewardService';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
|
||||
@@ -75,10 +74,12 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
|
||||
}
|
||||
const { bonus, fixReward } = getTowerDataByLv(towerLv);
|
||||
if (bonus) {
|
||||
bonusReward = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
let result = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
bonusReward = result.goods;
|
||||
}
|
||||
if (fixReward) {
|
||||
towerReward = await handleFixedReward(roleId, roleName, fixReward, 1);
|
||||
let result = await handleFixedReward(roleId, roleName, fixReward, 1);
|
||||
towerReward = result.goods;
|
||||
}
|
||||
if (towerLv + 1 >= HANG_UP_CONSTS.ENABLE_LV) {
|
||||
await startHangUp(roleId, roleName);
|
||||
@@ -200,5 +201,5 @@ export async function roleLevelup(roleId: string, kingExp: number) {
|
||||
mostExp : cur
|
||||
})
|
||||
}
|
||||
return {actordata, lv, exp};
|
||||
return {actordata, lv, exp, kingExp};
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import { GOOD_TYPE } from './../consts/consts';
|
||||
import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE } from './../consts/consts';
|
||||
import { EquipModel } from './../db/Equip';
|
||||
import { ItemModel } from './../db/Item';
|
||||
import { ScriptItemModel } from './../db/ScriptItem';
|
||||
import { HeroSoulModel } from './../db/HeroSoul';
|
||||
import { CounterModel } from './../db/Counter';
|
||||
import { decodeStr } from '../pubUtils/util';
|
||||
import { getGoodById, getHeroInfoById } from '../pubUtils/gamedata';
|
||||
import { getGoodById } from '../pubUtils/gamedata';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { setAp } from './actionPointService';
|
||||
|
||||
export async function handleFixedReward(roleId: string, roleName: string, rewardStr: string, multi: number) {
|
||||
let reward = decodeStr('fixReward', rewardStr);
|
||||
@@ -18,26 +17,40 @@ export async function handleFixedReward(roleId: string, roleName: string, reward
|
||||
|
||||
export async function handleReward(roleId: string, roleName: string, rewards: Array<{type: number, gid: number, count: number, times: number}>) {
|
||||
|
||||
let returnGoods = new Array();
|
||||
let returnGoods = new Array(), getGold = 0, getCoin = 0, getAp = 0;
|
||||
for(let goods of rewards) {
|
||||
let goodInfo = getGoodById(goods.gid);
|
||||
let result = new Array<any>()
|
||||
if(goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
|
||||
result = await rewardWeapons(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else if(goodInfo.goodType == GOOD_TYPE.ITEM) { // 消耗品
|
||||
result = await rewardItems(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else if(goodInfo.goodType == GOOD_TYPE.SCRIPT_ITEM) { // 剧情物品
|
||||
result = await rewardScriptItems(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else if (goodInfo.goodType == GOOD_TYPE.HERO_SOUL) { // 武将碎片
|
||||
result = await rewardHeroSouls(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else { // 货币
|
||||
|
||||
} else if(goodInfo.goodType == GOOD_TYPE.CONSUMES|| goodInfo.goodType == GOOD_TYPE.SCRIPT) { // 消耗品
|
||||
let {field, isCurrency} = ITID.get(goodInfo.itid);
|
||||
if(isCurrency) { // 货币
|
||||
result = await rewardCurrency(roleId, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else {
|
||||
result = await rewardItems(roleId, goodInfo, field, {id: goods.gid, cnt: goods.count });
|
||||
}
|
||||
}
|
||||
|
||||
for(let obj of result) {
|
||||
returnGoods.push({dropType: goods.type, times: goods.times, ...obj})
|
||||
returnGoods.push({dropType: goods.type, times: goods.times, ...obj});
|
||||
if(obj.isCurrency) {
|
||||
if(obj.currencyType == CURRENCY_TYPE.GOLD) {
|
||||
getGold += obj.count;
|
||||
} else if (obj.currencyType == CURRENCY_TYPE.COIN) {
|
||||
getCoin += obj.count;
|
||||
} else if (obj.currencyType == CURRENCY_TYPE.ACTION_POINT) {
|
||||
getAp += obj.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnGoods;
|
||||
return {
|
||||
goods: returnGoods,
|
||||
getGold,
|
||||
getCoin,
|
||||
getAp
|
||||
};
|
||||
}
|
||||
|
||||
async function rewardWeapons (roleId: string, roleName: string, dicGood: any, weapon: {id:number,cnt:number }) {
|
||||
@@ -63,91 +76,45 @@ async function rewardWeapons (roleId: string, roleName: string, dicGood: any, w
|
||||
}
|
||||
|
||||
// 消耗品
|
||||
async function rewardItems (roleId: string, roleName: string, dicGood: any, data: {id:number,cnt:number }) {
|
||||
async function rewardItems (roleId: string, dicGood: any, field: string, data: {id:number,cnt:number }) {
|
||||
|
||||
let goods = new Array();
|
||||
let itemcount = data.cnt;
|
||||
let itemid = data.id;
|
||||
|
||||
let item = await ItemModel.findbyItemid(itemid, roleId);
|
||||
if(item) {
|
||||
let result = await ItemModel.changeItemCount(item.seqId, itemcount);
|
||||
goods.push(result);
|
||||
} else {
|
||||
const seqId = await CounterModel.getNewCounter('itemid')||-1;
|
||||
const itemInfo = {
|
||||
roleId,
|
||||
roleName: roleName,
|
||||
itemid,
|
||||
itemName: dicGood.name,
|
||||
seqId,
|
||||
count: itemcount,
|
||||
type: dicGood.goodType
|
||||
}
|
||||
let result = await ItemModel.createItem(itemInfo);
|
||||
goods.push(result);
|
||||
}
|
||||
let {id, cnt} = data;
|
||||
|
||||
let result = await RoleModel.addItems(roleId, field, id, cnt);
|
||||
console.log(result)
|
||||
|
||||
goods.push({
|
||||
id: id,
|
||||
name: dicGood.name,
|
||||
count: cnt,
|
||||
type: dicGood.goodType,
|
||||
isCurrency: false
|
||||
});
|
||||
return goods;
|
||||
}
|
||||
|
||||
// 剧情道具
|
||||
async function rewardScriptItems (roleId: string, roleName: string, dicGood: any, data: {id:number,cnt:number }) {
|
||||
// 消耗品
|
||||
async function rewardCurrency (roleId: string, dicGood: any, data: {id:number,cnt:number }) {
|
||||
|
||||
let goods = [];
|
||||
let itemcount = data.cnt;
|
||||
let itemid = data.id;
|
||||
|
||||
let item = await ScriptItemModel.findbyItemid(itemid, roleId);
|
||||
if(item) {
|
||||
let result = await ScriptItemModel.changeItemCount(item.seqId, itemcount);
|
||||
goods.push(result);
|
||||
} else {
|
||||
const seqId = await CounterModel.getNewCounter('scriptitemid')||-1;
|
||||
const itemInfo = {
|
||||
roleId,
|
||||
roleName: roleName,
|
||||
itemid,
|
||||
itemName: dicGood.name,
|
||||
seqId,
|
||||
count: itemcount,
|
||||
type: dicGood.goodType
|
||||
}
|
||||
let result = await ScriptItemModel.createItem(itemInfo);
|
||||
goods.push(result);
|
||||
let goods = new Array();
|
||||
let {id, cnt} = data;
|
||||
let dicCurrency = CURRENCY.get(id);
|
||||
if(dicCurrency.type == CURRENCY_TYPE.GOLD) { // 处理元宝
|
||||
await RoleModel.addGoldFree(roleId, cnt);
|
||||
} else if(dicCurrency.type == CURRENCY_TYPE.COIN) { // 处理铜币
|
||||
await RoleModel.addCoin(roleId, cnt);
|
||||
} else if(dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 处理体力
|
||||
await setAp(Date.now(), roleId, cnt);
|
||||
}
|
||||
|
||||
goods.push({
|
||||
id: id,
|
||||
name: dicGood.name,
|
||||
count: cnt,
|
||||
type: dicGood.goodType,
|
||||
isCurrency: true,
|
||||
currencyType: dicCurrency.type
|
||||
});
|
||||
return goods;
|
||||
}
|
||||
|
||||
// 剧情道具
|
||||
async function rewardHeroSouls (roleId: string, roleName: string, dicGood: any, data: {id:number,cnt:number }) {
|
||||
|
||||
let goods = [];
|
||||
let soulcount = data.cnt;
|
||||
let soulid = data.id;
|
||||
|
||||
let item = await HeroSoulModel.findbyItemid(soulid, roleId);
|
||||
if(item) {
|
||||
let result = await HeroSoulModel.changeItemCount(item.seqId, soulcount);
|
||||
goods.push(result);
|
||||
} else {
|
||||
const dicHero = getHeroInfoById(dicGood.hid);
|
||||
const seqId = await CounterModel.getNewCounter('scriptitemid')||-1;
|
||||
const itemInfo = {
|
||||
roleId,
|
||||
roleName: roleName,
|
||||
soulid,
|
||||
soulName: dicGood.name,
|
||||
hid: dicGood.hid,
|
||||
hName: dicHero.name,
|
||||
seqId,
|
||||
count: soulcount,
|
||||
type: dicGood.goodType
|
||||
}
|
||||
let result = await HeroSoulModel.createItem(itemInfo);
|
||||
goods.push(result);
|
||||
}
|
||||
|
||||
return goods;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user