添加获得武将碎片

This commit is contained in:
luying
2020-10-20 17:53:58 +08:00
parent 2711fafd9f
commit 3332d16cc6
2 changed files with 39 additions and 6 deletions
+36 -3
View File
@@ -2,9 +2,10 @@ import { GOOD_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 } from '../pubUtils/gamedata';
import { getGoodById, getHeroInfoById } from '../pubUtils/gamedata';
export async function handleFixedReward(roleId: string, roleName: string, rewardStr: string, multi: number) {
let reward = decodeStr('fixReward', rewardStr);
@@ -28,7 +29,7 @@ export async function handleReward(roleId: string, roleName: string, rewards: Ar
} 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 { // 货币
}
@@ -117,4 +118,36 @@ async function rewardScriptItems (roleId: string, roleName: string, dicGood: any
}
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;
}