结算获取消耗品和金币
This commit is contained in:
@@ -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