结算获取消耗品和金币
This commit is contained in:
@@ -107,7 +107,7 @@ export class EventBattleHandler {
|
||||
eventCode: result.eventCode,
|
||||
eventId: result.eventId,
|
||||
status: result.status,
|
||||
goods
|
||||
...goods
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ export class ExpeditionBattleHandler {
|
||||
expeditionCode, expeditionId,
|
||||
battleCode, battleId,
|
||||
battleStatus: expeditionWarRecord.battleStatus,
|
||||
goods: reward,
|
||||
...reward,
|
||||
apJson,
|
||||
expeditionPoint
|
||||
});
|
||||
@@ -273,7 +273,7 @@ export class ExpeditionBattleHandler {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId,
|
||||
battleId, battleCode, battleStatus, received,
|
||||
goods
|
||||
...goods
|
||||
});
|
||||
|
||||
}
|
||||
@@ -315,7 +315,7 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
pointRewards,
|
||||
goods
|
||||
...goods
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ export class NormalBattleHandler {
|
||||
// towerBonus: 天梯每隔几层的额外宝箱
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleCode, battleId, status, towerStatus,
|
||||
goods: reward, towerBonus, towerReward,
|
||||
...reward, towerBonus, towerReward,
|
||||
apJson,
|
||||
dailyNum,
|
||||
heroes: curHeroes,
|
||||
@@ -262,7 +262,7 @@ export class NormalBattleHandler {
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleId, count,
|
||||
goods: result,
|
||||
...result,
|
||||
apJson,
|
||||
dailyNum,
|
||||
...actordata
|
||||
|
||||
@@ -85,7 +85,7 @@ export class TowerBattleHandler {
|
||||
}
|
||||
const goods = await handleFixedReward(roleId, roleName, timeReward, multi);
|
||||
const newRec = await HangUpRecordModel.updateRec(roleId, roleName, endLv, endTime);
|
||||
return resResult(STATUS.SUCCESS, { endTime, goods, hangUpRec: newRec });
|
||||
return resResult(STATUS.SUCCESS, { endTime, ...goods, hangUpRec: newRec });
|
||||
}
|
||||
|
||||
async hangUpSpeedUp(msg: {speedUpCnt: number}, session: BackendSession) {
|
||||
@@ -106,7 +106,7 @@ export class TowerBattleHandler {
|
||||
}
|
||||
const spdUpRec = await HangUpSpdUpRecModel.updateRec(roleId, roleName, multi, endLv);
|
||||
const goods = await handleFixedReward(roleId, roleName, timeReward, multi);
|
||||
return resResult(STATUS.SUCCESS, { goods, rewardLv: endLv, spdUpRec });
|
||||
return resResult(STATUS.SUCCESS, { ...goods, rewardLv: endLv, spdUpRec });
|
||||
}
|
||||
|
||||
async getTasks(msg: {}, session: BackendSession) {
|
||||
@@ -186,11 +186,11 @@ export class TowerBattleHandler {
|
||||
if (task.sendTime && task.sendTime.getTime() + completeTime * 1000 < curTime.getTime()) {
|
||||
compTasks.push(task.taskCode);
|
||||
const rewardGoods = await handleFixedReward(roleId, roleName, reward, 1);
|
||||
goods = goods.concat(rewardGoods);
|
||||
goods = goods.concat(rewardGoods.goods);
|
||||
if(bonusCondition) {
|
||||
const res = checkTaskConditions(roleId, task.heroes, bonusCondition);
|
||||
const bonusGoods = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
goods = goods.concat(bonusGoods);
|
||||
goods = goods.concat(bonusGoods.goods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,8 @@ import { BattleRecordModel } from './../db/BattleRecord';
|
||||
import { TowerRecordModel } from './../db/TowerRecord';
|
||||
import { RoleModel } from './../db/Role';
|
||||
import { getHeroInfoById, getJobInfoById, getTowerDataByLv, getLvByExp, getExpByLv } from "../pubUtils/gamedata"
|
||||
import { decodeArrayStr, shouldRefresh } from '../pubUtils/util';
|
||||
import { decodeArrayStr, shouldRefresh, resResult } from '../pubUtils/util';
|
||||
import { handleFixedReward } from './rewardService';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
|
||||
@@ -75,10 +74,12 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
|
||||
}
|
||||
const { bonus, fixReward } = getTowerDataByLv(towerLv);
|
||||
if (bonus) {
|
||||
bonusReward = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
let result = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
bonusReward = result.goods;
|
||||
}
|
||||
if (fixReward) {
|
||||
towerReward = await handleFixedReward(roleId, roleName, fixReward, 1);
|
||||
let result = await handleFixedReward(roleId, roleName, fixReward, 1);
|
||||
towerReward = result.goods;
|
||||
}
|
||||
if (towerLv + 1 >= HANG_UP_CONSTS.ENABLE_LV) {
|
||||
await startHangUp(roleId, roleName);
|
||||
@@ -200,5 +201,5 @@ export async function roleLevelup(roleId: string, kingExp: number) {
|
||||
mostExp : cur
|
||||
})
|
||||
}
|
||||
return {actordata, lv, exp};
|
||||
return {actordata, lv, exp, kingExp};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import { UserModel } from '@db/User';
|
||||
import { RoleModel } from '@db/Role';
|
||||
import { HeroModel } from '@db/Hero';
|
||||
import { EquipModel } from '@db/Equip';
|
||||
import { ItemModel } from '@db/Item';
|
||||
import { CounterModel } from '@db/Counter';
|
||||
import { ActionPointModel } from '@db/ActionPoint';
|
||||
import { BattleDropModel } from '@db/BattleDrop';
|
||||
@@ -15,8 +14,6 @@ import { ExpeditionRecordModel } from '@db/ExpeditionRecord';
|
||||
import { ExpeditionWarRecordModel } from '@db/ExpeditionWarRecord';
|
||||
import { HangUpRecordModel } from '@db/HangUpRecord';
|
||||
import { HangUpSpdUpRecModel } from '@db/HangUpSpdUpRec';
|
||||
import { HeroSoulModel } from '@db/HeroSoul';
|
||||
import { ScriptItemModel } from '@db/ScriptItem';
|
||||
import { SearchRecordModel } from '@db/SearchRecord';
|
||||
import { TowerRecordModel } from '@db/TowerRecord';
|
||||
import { TowerTaskRecModel } from '@db/TowerTaskRec';
|
||||
@@ -24,6 +21,8 @@ import { TowerTaskRecModel } from '@db/TowerTaskRec';
|
||||
import { Service } from 'egg';
|
||||
import Counter from '@db/Counter';
|
||||
import { STATUS } from '@consts/statusCode';
|
||||
import { getGoodById } from '@pubUtils/gamedata';
|
||||
import { ITID } from '@consts/consts';
|
||||
|
||||
/**
|
||||
* Test Service
|
||||
@@ -107,10 +106,7 @@ export default class GMUsers extends Service {
|
||||
await HangUpSpdUpRecModel.deleteAccount(roleId);
|
||||
await HangUpRecordModel.deleteAccount(roleId);
|
||||
await HeroModel.deleteAccount(roleId);
|
||||
await HeroSoulModel.deleteAccount(roleId);
|
||||
await ItemModel.deleteAccount(roleId);
|
||||
await RoleModel.deleteAccount(roleId);
|
||||
await ScriptItemModel.deleteAccount(roleId);
|
||||
await SearchRecordModel.deleteAccount(roleId);
|
||||
await TowerTaskRecModel.deleteAccount(roleId);
|
||||
await TowerRecordModel.deleteAccount(roleId);
|
||||
@@ -161,11 +157,11 @@ export default class GMUsers extends Service {
|
||||
for(let role of roles) {
|
||||
let heroCount = await HeroModel.count({roleId: role.roleId}).lean();
|
||||
let equipCount = await EquipModel.count({roleId: role.roleId}).lean();
|
||||
let itemCount = await ItemModel.count({roleId: role.roleId}).lean();
|
||||
let {roleId, roleName, serverId, lv, vLv} = role;
|
||||
let itemCount = (role.consumeGoods?role.consumeGoods.length: 0) + (role.souls?role.souls.length:0);
|
||||
let {roleId, roleName, serverId, lv, vLv, gold, coin} = role;
|
||||
let {uid, tel} = role.userInfo;
|
||||
result.push({
|
||||
key: roleId, roleId, roleName, serverId, lv, vLv, uid, tel, heroCount, equipCount, itemCount
|
||||
key: roleId, roleId, roleName, serverId, lv, vLv, uid, tel, heroCount, equipCount, itemCount, gold, coin
|
||||
});
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list: result });
|
||||
@@ -274,32 +270,12 @@ export default class GMUsers extends Service {
|
||||
let itemid = parseInt(_itemid);
|
||||
let itemcount = parseInt(_itemcount);
|
||||
if(isNaN(itemid) || isNaN(itemcount)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
console.log('gm createEquip');
|
||||
let dicGoods = getGoodById(itemid);
|
||||
let itidObj = ITID.get(dicGoods.itid);
|
||||
|
||||
let flag = 0;
|
||||
for(let roleId of uids) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(role) {
|
||||
let item = await ItemModel.findbyItemid(itemid, roleId);
|
||||
if(item) {
|
||||
await ItemModel.changeItemCount(item.seqId, itemcount);
|
||||
} else {
|
||||
const seqId = await CounterModel.getNewCounter('itemid')||-1;
|
||||
const itemInfo = {
|
||||
roleId,
|
||||
roleName: role.roleName,
|
||||
itemid,
|
||||
itemName: '包子',
|
||||
seqId,
|
||||
type: 1,
|
||||
count: itemcount
|
||||
}
|
||||
await ItemModel.createItem(itemInfo);
|
||||
}
|
||||
} else {
|
||||
flag = 1;
|
||||
}
|
||||
await RoleModel.addItems(roleId, itidObj?itidObj.field||'':'', itemid, itemcount);
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@db/*": ["app/db/*"],
|
||||
"@consts/*": ["app/consts/*"]
|
||||
"@consts/*": ["app/consts/*"],
|
||||
"@pubUtils/*": ["app/pubUtils/*"]
|
||||
},
|
||||
},
|
||||
"exclude": [
|
||||
|
||||
@@ -27,11 +27,60 @@ export const BATTLE_REWARD_TYPE = {
|
||||
|
||||
export const GOOD_TYPE = {
|
||||
EQUIP: 1,
|
||||
ITEM: 2,
|
||||
SCRIPT_ITEM: 3,
|
||||
HERO_SOUL: 4
|
||||
CONSUMES: 2,
|
||||
SCRIPT: 3
|
||||
};
|
||||
|
||||
const itid_array = [
|
||||
{ id: 1, name: '剑', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 2, name: '枪', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 3, name: '刀', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 4, name: '弓', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 5, name: '拳', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 6, name: '扇', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 7, name: '宝剑', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 8, name: '权杖', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 9, name: '头盔', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 10, name: '帽子', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 11, name: '头巾', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 12, name: '铠甲(衣)', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 13, name: '战袍(衣)', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 14, name: '法衣(衣)', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 15, name: '铠甲(裤)', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 16, name: '战袍(裤)', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 17, name: '法衣(裤)', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 18, name: '重靴', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 19, name: '战靴', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 20, name: '布鞋', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 21, name: '饰品', goodType: GOOD_TYPE.EQUIP },
|
||||
{ id: 22, name: '消耗类物品(图纸类)', goodType: GOOD_TYPE.CONSUMES, field: "consumeGoods" },
|
||||
{ id: 23, name: '消耗类物品(材料类)', goodType: GOOD_TYPE.CONSUMES, field: "consumeGoods" },
|
||||
{ id: 24, name: '消耗类物品(宝箱类)', goodType: GOOD_TYPE.CONSUMES, field: "consumeGoods" },
|
||||
{ id: 26, name: '武将碎片', goodType: GOOD_TYPE.CONSUMES, field: "souls" },
|
||||
{ id: 27, name: '货币', goodType: GOOD_TYPE.CONSUMES, field: "currency", isCurrency: true }
|
||||
];
|
||||
|
||||
export const ITID = new Map<number, {id: number, name: string, goodType: number, field?: string, isCurrency?: boolean}>();
|
||||
for(let obj of itid_array) {
|
||||
ITID.set(obj.id, obj);
|
||||
}
|
||||
|
||||
export const CURRENCY_TYPE = {
|
||||
GOLD: "gold",
|
||||
COIN: "coin",
|
||||
ACTION_POINT: "ap"
|
||||
}
|
||||
|
||||
const currencyArr = [
|
||||
{ "gid": 31001, "name": "铜钱", "type": CURRENCY_TYPE.COIN },
|
||||
{ "gid": 31002, "name": "元宝", "type": CURRENCY_TYPE.GOLD },
|
||||
{ "gid": 31003, "name": "体力", "type": CURRENCY_TYPE.ACTION_POINT },
|
||||
];
|
||||
export const CURRENCY = new Map<number, {gid: number, name: string, type: string}>();
|
||||
for(let obj of currencyArr) {
|
||||
CURRENCY.set(obj.gid, obj);
|
||||
}
|
||||
|
||||
export const WAR_TYPE = {
|
||||
NORMAL: 1,
|
||||
DAILY: 2,
|
||||
|
||||
@@ -59,6 +59,9 @@ export default class Role extends BaseModel {
|
||||
cnt: number; // 购买次数
|
||||
}];
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
coin: number; // 总铜钱
|
||||
|
||||
@prop({ required: true, default: [] })
|
||||
consumeGoods: [{ // 消耗品
|
||||
id: number; // id
|
||||
@@ -181,6 +184,33 @@ export default class Role extends BaseModel {
|
||||
let result = await RoleModel.deleteMany({roleId}).lean(lean);
|
||||
return result||{};
|
||||
}
|
||||
|
||||
|
||||
public static async addItems(roleId: string, field: string, id: number, cnt: number, lean = true) {
|
||||
|
||||
let addToSet = {};
|
||||
addToSet[field] = {id, cnt: 0};
|
||||
await RoleModel.findOneAndUpdate({roleId}, { $addToSet: addToSet }, { "new": true, "upsert": true});
|
||||
|
||||
let condition = { roleId };
|
||||
condition[`${field}.id`] = id;
|
||||
let update = {};
|
||||
update[`${field}.$.cnt`] = cnt;
|
||||
|
||||
console.log(JSON.stringify(condition), update)
|
||||
let result = await RoleModel.findOneAndUpdate(condition, { $inc: update }, { "new": true, "upsert": true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async addCoin(roleId: string, cnt: number, lean = true) {
|
||||
let result = await RoleModel.findOneAndUpdate({roleId}, { $inc: {coin: cnt} }, { "new": true, "upsert": true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async addGoldFree(roleId: string, cnt: number, lean = true) {
|
||||
let result = await RoleModel.findOneAndUpdate({roleId}, { $inc: { gold: cnt, giftGold: cnt } }, { "new": true, "upsert": true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const RoleModel = getModelForClass(Role);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user