添加获得武将碎片
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ export default class HeroSoul extends BaseModel {
|
||||
roleName: string; // 角色名称
|
||||
|
||||
@prop({ required: true })
|
||||
itemid: number; // 道具 id
|
||||
soulid: number; // 道具 id
|
||||
@prop({ required: true })
|
||||
itemName: string; // 道具名称
|
||||
soulName: string; // 道具名称
|
||||
@prop({ required: true })
|
||||
hid: number; // 武将 id
|
||||
@prop({ required: true })
|
||||
@@ -39,7 +39,7 @@ export default class HeroSoul extends BaseModel {
|
||||
return equips;
|
||||
}
|
||||
|
||||
public static async createItem(itemInfo: {roleId: string, roleName: string, itemid: number, seqId: number, itemName: string, count: number}, lean = true) {
|
||||
public static async createItem(itemInfo: {roleId: string, roleName: string, soulid: number, seqId: number, soulName: string, count: number, hid: number, hName: string}, lean = true) {
|
||||
const doc = new HeroSoulModel();
|
||||
const update = Object.assign(doc.toJSON(), itemInfo);
|
||||
const item = await HeroSoulModel.findOneAndUpdate({ seqId: itemInfo.seqId }, update, {upsert: true, new: true}).lean(lean);
|
||||
|
||||
Reference in New Issue
Block a user