addItem goodType修改
This commit is contained in:
@@ -7,7 +7,6 @@ import { TowerRecordModel } from './../db/TowerRecord';
|
||||
import { RoleModel } from './../db/Role';
|
||||
import { getHeroInfoById, getJobInfoById, getTowerDataByLv, getTaskById, getGamedata, getRandExpedition, getWarById, getWarJsons } from "../pubUtils/gamedata"
|
||||
import { decodeArrayStr, shouldRefresh, resResult, decodeStr, cal, getRandomWithWeight, getRefTime, decodeStrSingle, genCode } from '../pubUtils/util';
|
||||
import { handleFixedReward } from './rewardService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
|
||||
import { TowerTaskRecModel } from '../db/TowerTaskRec';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE, CONSUME_TYPE, getCurNameById } from './../consts';
|
||||
import { ITID, CONSUME_TYPE, getCurNameById, ITEM_TABLE } from './../consts';
|
||||
import { EquipModel } from './../db/Equip';
|
||||
import { decodeStr, resResult } from '../pubUtils/util';
|
||||
import { resResult, parseReward } from '../pubUtils/util';
|
||||
import { getGoodById } from '../pubUtils/gamedata';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { setAp } from './actionPointService';
|
||||
@@ -12,120 +12,15 @@ import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
const _ = require('underscore');
|
||||
|
||||
export async function handleFixedReward(roleId: string, roleName: string, rewardStr: string, multi: number) {
|
||||
let reward = decodeStr('fixReward', rewardStr);
|
||||
export async function handleFixedReward(roleId: string, roleName: string, sid: string, rewardStr: string, multi: number) {
|
||||
let reward = parseReward(rewardStr);
|
||||
let rewards = [];
|
||||
for(let obj of reward)
|
||||
rewards.push({ ...obj, count: Math.ceil(obj.count * multi)});
|
||||
const result = await handleReward(roleId, roleName, reward);
|
||||
const result = await addItems(roleId, roleName, sid, reward);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function handleReward(roleId: string, roleName: string, rewards: Array<{type?: number, gid: number, count: number, times?: number}>) {
|
||||
|
||||
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.CONSUMES|| goodInfo.goodType == GOOD_TYPE.SCRIPT) { // 消耗品
|
||||
let {type, isCurrency} = ITID.get(goodInfo.itid);
|
||||
if(isCurrency) { // 货币
|
||||
result = await rewardCurrency(roleId, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else {
|
||||
result = await rewardItems(roleId, roleName, goodInfo, type, {id: goods.gid, cnt: goods.count });
|
||||
}
|
||||
}
|
||||
|
||||
for(let obj of result) {
|
||||
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 {
|
||||
goods: returnGoods,
|
||||
getGold,
|
||||
getCoin,
|
||||
getAp
|
||||
};
|
||||
}
|
||||
|
||||
async function rewardWeapons (roleId: string, roleName: string, dicGood: any, weapon: {id:number,cnt:number }) {
|
||||
|
||||
let weaponsData = [];
|
||||
let cnt = weapon.cnt;
|
||||
// while (cnt > 0) {
|
||||
// const seqId = await CounterModel.getNewCounter(COUNTER.EID);
|
||||
// const equipInfo = {
|
||||
// roleId,
|
||||
// roleName,
|
||||
// id: weapon.id,
|
||||
// name: dicGood.name,
|
||||
// seqId,
|
||||
// quality: dicGood.lv,
|
||||
// type: dicGood.goodType
|
||||
// }
|
||||
// const equip = await EquipModel.createEquip(equipInfo);
|
||||
// cnt -= 1;
|
||||
// weaponsData.push(equip);
|
||||
// }
|
||||
return weaponsData;
|
||||
}
|
||||
|
||||
// 消耗品
|
||||
async function rewardItems (roleId: string, roleName: string, dicGood: any, type: number, data: {id:number,cnt:number }) {
|
||||
|
||||
let goods = new Array();
|
||||
let {id, cnt} = data;
|
||||
|
||||
let result = await ItemModel.increaseItem(roleId, id, cnt, {roleId, roleName, itemName: dicGood.name, id, type, hid: dicGood.hid||0});
|
||||
|
||||
if(result) {
|
||||
goods.push({
|
||||
id: id,
|
||||
name: dicGood.name,
|
||||
count: cnt,
|
||||
type: dicGood.goodType,
|
||||
isCurrency: false
|
||||
});
|
||||
}
|
||||
return goods;
|
||||
}
|
||||
|
||||
// 消耗品
|
||||
async function rewardCurrency (roleId: string, dicGood: any, data: {id:number,cnt:number }) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
let currencysMap: any = {};
|
||||
let equips: Array<number> = [];
|
||||
@@ -173,15 +68,25 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
|
||||
function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencysMap: any, equips: Array<number>) {
|
||||
for (let good of goods) {
|
||||
if (good.type == GOOD_TYPE.EQUIP) { // 装备
|
||||
let goodInfo = getGoodById(good.id);
|
||||
let {type, table } = ITID.get(goodInfo.itid);
|
||||
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
if (!!good.seqId) {
|
||||
equips.push(good.seqId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
let goodInfo = getGoodById(good.id);
|
||||
let {type} = ITID.get(goodInfo.itid);
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
let index = _.indexOf(bags, {id: good.id});
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
bags.push(good);
|
||||
}
|
||||
} else if (table == ITEM_TABLE.HERO) {
|
||||
return false
|
||||
} else if (table == ITEM_TABLE.ROLE) {
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
if (curname != 'ap') {
|
||||
@@ -189,15 +94,6 @@ function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencys
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (type != CONSUME_TYPE.SKIN){
|
||||
let index = _.indexOf(bags, {id: good.id});
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
bags.push(good);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,14 +160,31 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<ItemInter>) {
|
||||
for (let good of goods) {
|
||||
let goodInfo = gameData.goods.get(good.id);
|
||||
console.log('*****', good.id, goodInfo.goodType)
|
||||
if (goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
|
||||
console.log()
|
||||
console.error('无道具', good.id);
|
||||
|
||||
let {type, table, isCurrency} = ITID.get(goodInfo.itid);
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
for (let i = 0; i < good.count; i++) {
|
||||
equips.push({id: good.id, ...goodInfo});
|
||||
}
|
||||
} else {
|
||||
let {type, isCurrency} = ITID.get(goodInfo.itid);
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
|
||||
let index = _.indexOf(bags, {id: good.id});
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
bags.push({id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid||0, type});
|
||||
}
|
||||
|
||||
} else if (table == ITEM_TABLE.HERO) {
|
||||
if (type == CONSUME_TYPE.SKIN) {
|
||||
let index = _.indexOf(skins, good.id);
|
||||
if (index == -1) {
|
||||
skins.push(good.id);
|
||||
}
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ROLE) {
|
||||
|
||||
if (!!isCurrency) {
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
@@ -283,18 +196,6 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
|
||||
}
|
||||
currencysMap[curname] = (currencysMap[curname]||0 )+ good.count;
|
||||
}
|
||||
} else if (type == CONSUME_TYPE.SKIN) {
|
||||
let index = _.indexOf(skins, good.id);
|
||||
if (index == -1) {
|
||||
skins.push(good.id);
|
||||
}
|
||||
} else {
|
||||
let index = _.indexOf(bags, {id: good.id});
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
bags.push({id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid||0, type});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,14 @@ import { BattleDropModel } from '../db/BattleDrop';
|
||||
import { getWarById, getBluePrtByQuality, getGamedata } from '../pubUtils/gamedata';
|
||||
import { decodeStr, getRefTime, getRandomWithWeight, getRandomByLen } from '../pubUtils/util';
|
||||
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST } from '../consts';
|
||||
import { handleReward } from './rewardService';
|
||||
import { addItems } from './rewardService';
|
||||
import { BattleBlueprtDropModel } from '../db/BattleBlueprtDrop'
|
||||
import { RoleModel } from '../db/Role';
|
||||
|
||||
export class WarReward {
|
||||
private roleId: string;
|
||||
private roleName: string;
|
||||
private sid: string;
|
||||
private battleId: number;
|
||||
private condition: Map<number, boolean>;
|
||||
private warInfo: any;
|
||||
@@ -24,9 +25,10 @@ export class WarReward {
|
||||
private randomReward: string;
|
||||
private costAp: number;
|
||||
|
||||
constructor(roleId: string, roleName: string, battleId: number, isSuccess: boolean) {
|
||||
constructor(roleId: string, roleName: string, sid: string, battleId: number, isSuccess: boolean) {
|
||||
this.roleId = roleId;
|
||||
this.roleName = roleName;
|
||||
this.sid = sid;
|
||||
this.battleId = battleId;
|
||||
this.condition = new Map();
|
||||
this.warInfo = getWarById(battleId);
|
||||
@@ -196,8 +198,9 @@ export class WarReward {
|
||||
if(this.costAp > 0) await this.handlerBlueprtReward(num);
|
||||
}
|
||||
|
||||
let returnGoods = await handleReward(this.roleId, this.roleName, this.rewards);
|
||||
return returnGoods;
|
||||
let rewards = this.rewards.sort((a, b) => a.times - b.times)
|
||||
await addItems(this.roleId, this.roleName, this.sid, rewards);
|
||||
return rewards;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user