关卡添加消耗品结算,奇遇的坐标改为点id

This commit is contained in:
luying
2020-10-20 11:38:13 +08:00
parent a96c4c4182
commit 16085ca55d
13 changed files with 8230 additions and 929 deletions
@@ -11,6 +11,7 @@ import { getAp, setAp } from '../../../services/actionPointService';
import { setBattleStatus, startEvent } from '../../../services/eventSercive';
import { STATUS } from '../../../consts/statusCode';
import { resResult } from '../../../pubUtils/util';
import { HeroModel } from '../../../db/Hero';
export default function(app: Application) {
return new NormalBattleHandler(app);
@@ -101,7 +102,6 @@ export class NormalBattleHandler {
// 关卡结算,记录使用的武将,获得奖励
async battleEnd(msg: {battleCode: string, battleId: number, isSuccess: boolean, star: number, heroes: Array<any>, }, session: BackendSession) {
const { battleCode, battleId, isSuccess, heroes, star } = msg;
let roleId = session.get('roleId');
let roleName = session.get('roleName');
@@ -181,6 +181,12 @@ export class NormalBattleHandler {
}, true);
let { status } = updateResult;
let curHeroes = [];
for(let hid of heroes) {
let hero = await HeroModel.findByHidAndRole(hid, roleId);
curHeroes.push(hero);
}
// 主线关卡某个关卡触发事件开启
let eventStatus = session.get('eventStatus')||0;
if(battleId == EVENT_START_BATTLE && eventStatus == 0) {
@@ -194,7 +200,29 @@ export class NormalBattleHandler {
battleCode, battleId, status, towerStatus,
goods: reward, towerBonus, towerReward,
apJson,
dailyNum
dailyNum,
kingExp: warInfo.kingExp,
heroes: curHeroes,
actordata: [
{
lv : 20,
exp : 700,
getExp : 1300,
mostExp : 2000
},
{
lv : 21,
exp : 0,
getExp : 3000,
mostExp : 3000
},
{
lv : 22,
exp : 0,
getExp : 700,
mostExp : 4000,
}
]
});
}
+5 -5
View File
@@ -129,14 +129,14 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
let index = Math.floor(Math.random() * randomList.length);
let dic = randomList[index];
let position = randomPosition(dic.position);
let point = randomPosition(dic.movePointArray);
let question = dic.eventType == EVENT_TYPE.QUIZ?randomQuestion(EVENT_QUIZ_NUM): undefined;
let eventCode = genCode(8);
let data = await EventRecordModel.saveEventRecord(eventCode, {
roleId, refTime: t, eventId: dic.eventID,
roleName, turn, type: dic.eventType, battleId: dic.warId||0, quality: dic.quality,
status: EVENT_RECORD_STATUS.WAITING,
position, question
point, question
});
event.push(data);
randomList.splice(index, 1);
@@ -148,14 +148,14 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
let {dic} = getRandomWithWeight(randomList);
console.log(JSON.stringify(dic))
// if(!dic) break;
let position = randomPosition(dic.position);
let point = randomPosition(dic.movePointArray);
let eventCode = genCode(8);
let question = dic.eventType == EVENT_TYPE.QUIZ?randomQuestion(EVENT_QUIZ_NUM): [];
let data = await EventRecordModel.saveEventRecord(eventCode, {
roleId, refTime: t, eventId: dic.eventID,
roleName, type: dic.eventType, battleId: dic.warId||0, quality: dic.quality,
status: EVENT_RECORD_STATUS.WAITING,
position, question
point, question
});
event.push(data)
}
@@ -165,7 +165,7 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
}
function randomPosition(positionStr: string) {
let positionArr = decodeStr('position', positionStr);
let positionArr = decodeStr('point', positionStr, '&');
let index = Math.floor(Math.random() * positionArr.length);
return positionArr[index]
}
+73 -4
View File
@@ -1,5 +1,7 @@
import { GOOD_TYPE } from './../consts/consts';
import { EquipModel } from './../db/Equip';
import { ItemModel } from './../db/Item';
import { ScriptItemModel } from './../db/ScriptItem';
import { CounterModel } from './../db/Counter';
import { decodeStr } from '../pubUtils/util';
import { getGoodById } from '../pubUtils/gamedata';
@@ -18,11 +20,20 @@ export async function handleReward(roleId: string, roleName: string, rewards: Ar
let returnGoods = new Array();
for(let goods of rewards) {
let goodInfo = getGoodById(goods.gid);
let result = new Array<any>()
if(goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
let result = await rewardWeapons(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count });
for(let obj of result) {
returnGoods.push({dropType: goods.type, times: goods.times, ...obj})
}
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) { // 武将碎片
} else { // 货币
}
for(let obj of result) {
returnGoods.push({dropType: goods.type, times: goods.times, ...obj})
}
}
return returnGoods;
@@ -48,4 +59,62 @@ async function rewardWeapons (roleId: string, roleName: string, dicGood: any, w
weaponsData.push(equip);
}
return weaponsData;
}
// 消耗品
async function rewardItems (roleId: string, roleName: string, dicGood: any, 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);
}
return goods;
}
// 剧情道具
async function rewardScriptItems (roleId: string, roleName: 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);
}
return goods;
}
@@ -97,7 +97,6 @@ export class WarReward {
this.handleConditionReward(num);
await this.handleRandomReward(num);
console.log(this.rewards)
let returnGoods = await handleReward(this.roleId, this.roleName, this.rewards);
return returnGoods;
}