GM后台添加皮肤

This commit is contained in:
luying
2020-12-17 13:17:19 +08:00
parent b79157b5c9
commit 04063fe2d4
9 changed files with 115 additions and 64 deletions
@@ -1,6 +1,6 @@
import {Application, BackendSession, createTcpMailBox, ChannelService} from 'pinus'; import {Application, BackendSession, createTcpMailBox, ChannelService} from 'pinus';
import { handleCost, addItems } from '../../../services/rewardService'; import { handleCost, addItems } from '../../../services/rewardService';
import { calPlayerCeAndSave, getAllAttrStage } from '../../../services/playerCeService'; import { calPlayerCeAndSave } from '../../../services/playerCeService';
import { resResult } from '../../../pubUtils/util'; import { resResult } from '../../../pubUtils/util';
import { STATUS } from '../../../consts/statusCode'; import { STATUS } from '../../../consts/statusCode';
import {HeroModel} from '../../../db/Hero'; import {HeroModel} from '../../../db/Hero';
@@ -9,6 +9,7 @@ import { RoleModel } from '../../../db/Role';
import { ItemModel } from '../../../db/Item'; import { ItemModel } from '../../../db/Item';
import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById } from '../../../pubUtils/data'; import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById } from '../../../pubUtils/data';
import { RewardInter } from '../../../pubUtils/interface'; import { RewardInter } from '../../../pubUtils/interface';
import { getAllAttrStage } from '../../../pubUtils/playerCe';
export default function(app: Application) { export default function(app: Application) {
return new HeroHandler(app); return new HeroHandler(app);
+2 -30
View File
@@ -2,14 +2,13 @@ import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE, COUNTER, CONSUME_TYPE, getCur
import { EquipModel } from './../db/Equip'; import { EquipModel } from './../db/Equip';
import { CounterModel } from './../db/Counter'; import { CounterModel } from './../db/Counter';
import { decodeStr, resResult } from '../pubUtils/util'; import { decodeStr, resResult } from '../pubUtils/util';
import { getGoodById, getFashionsById } from '../pubUtils/gamedata'; import { getGoodById } from '../pubUtils/gamedata';
import { RoleModel } from '../db/Role'; import { RoleModel } from '../db/Role';
import { setAp } from './actionPointService'; import { setAp } from './actionPointService';
import { ItemModel } from '../db/Item'; import { ItemModel } from '../db/Item';
import { STATUS } from '../consts/statusCode'; import { STATUS } from '../consts/statusCode';
import { pinus } from 'pinus'; import { pinus } from 'pinus';
import { HeroModel } from '../db/Hero'; import { addEquips, addBags, addSkins } from '../pubUtils/itemUtils';
import { treatTask } from './battleService';
const _ = require('underscore'); const _ = require('underscore');
export async function handleFixedReward(roleId: string, roleName: string, rewardStr: string, multi: number) { export async function handleFixedReward(roleId: string, roleName: string, rewardStr: string, multi: number) {
@@ -299,30 +298,3 @@ function sortItems (goods: Array<Item>, bags: Array<Bag>, skins: Array<number>,
} }
} }
} }
async function addSkins(roleId: string, id: number) {
let skinInfo = getFashionsById(id);
if (!skinInfo)
return false;
let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId, false);
if (!hero)
return false;
if (!!_.findWhere(hero.skins, {id}))
return false;
hero.skins.push({id, enable: false});
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
return {skins: hero.skins, hid: hero.hid};
}
async function addBags(roleId: string, roleName: string, data:Bag) {
let {id, count, itemName, type, hid} = data;
let item = await ItemModel.increaseItem(roleId, id, count, {roleId, roleName, itemName, id, type, hid});
return {id:item.id, count: item.count};
}
async function addEquips (roleId: string, roleName: string, weapon: Equip) {
const seqId = await CounterModel.getNewCounter(COUNTER.EID);
let equip = Object.assign({seqId, roleId, roleName}, weapon);
return await EquipModel.createEquip(equip);
}
+3 -1
View File
@@ -30,7 +30,7 @@ export default class UserController extends Controller {
public async createRoleData() { public async createRoleData() {
const { ctx } = this; const { ctx } = this;
const { hid, hlv, eid, elv, ecount, ehid, itemid, itemcount, count, lv, selectedRowKeys: uids, optType } = ctx.request.body; const { hid, hlv, eid, elv, ecount, ehid, itemid, itemcount, count, lv, skinid, selectedRowKeys: uids, optType } = ctx.request.body;
if(optType == 'hero') { if(optType == 'hero') {
ctx.body = await ctx.service.users.createHero(uids, hid, hlv); ctx.body = await ctx.service.users.createHero(uids, hid, hlv);
} else if(optType == 'equip') { } else if(optType == 'equip') {
@@ -41,6 +41,8 @@ export default class UserController extends Controller {
ctx.body = await ctx.service.users.addGold(uids, count); ctx.body = await ctx.service.users.addGold(uids, count);
} else if (optType == 'lv') { } else if (optType == 'lv') {
ctx.body = await ctx.service.users.levelUp(uids, lv); ctx.body = await ctx.service.users.levelUp(uids, lv);
} else if (optType == 'skin') {
ctx.body = await ctx.service.users.addSkins(uids, skinid);
} else { } else {
ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS); ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
} }
+14
View File
@@ -3,6 +3,8 @@ import * as pubUtils from '../pubUtils/util';
import * as pubGamedata from '../pubUtils/gamedata' import * as pubGamedata from '../pubUtils/gamedata'
import { HeroType } from '@db/Hero'; import { HeroType } from '@db/Hero';
import { calPlayerCeAndSave } from '@pubUtils/playerCe'; import { calPlayerCeAndSave } from '@pubUtils/playerCe';
import { addSkins, addBags, addEquips } from '@pubUtils/itemUtils';
import { BagInter, EquipInter } from '@pubUtils/interface';
const csprng = require('csprng'); const csprng = require('csprng');
/** /**
@@ -52,4 +54,16 @@ export default class Utils extends Service {
public calPlayerCeAndSave(roleId: string, heros: HeroType[], type: number, args: number[]) { public calPlayerCeAndSave(roleId: string, heros: HeroType[], type: number, args: number[]) {
return calPlayerCeAndSave(roleId, heros, type, args) return calPlayerCeAndSave(roleId, heros, type, args)
} }
public addSkins(roleId: string, id: number) {
return addSkins(roleId, id);
}
public addBags(roleId: string, roleName: string, data: BagInter) {
return addBags(roleId, roleName, data);
}
public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
return addEquips(roleId, roleName, weapon);
}
} }
+15 -3
View File
@@ -25,6 +25,7 @@ import { STATUS } from '@consts';
import { ITID, COUNTER } from '@consts'; import { ITID, COUNTER } from '@consts';
import Actor from '@pubUtils/actor'; import Actor from '@pubUtils/actor';
import { ItemModel } from '@db/Item'; import { ItemModel } from '@db/Item';
import { gameData } from '@pubUtils/data';
/** /**
* Test Service * Test Service
@@ -271,7 +272,7 @@ export default class GMUsers extends Service {
let itemid = parseInt(_itemid); let itemid = parseInt(_itemid);
let itemcount = parseInt(_itemcount); let itemcount = parseInt(_itemcount);
if(isNaN(itemid) || isNaN(itemcount)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS); if(isNaN(itemid) || isNaN(itemcount)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
let dicGoods = ctx.service.utils.getGoodById(itemid); let dicGoods = gameData.goods.get(itemid);
let itidObj = ITID.get(dicGoods.itid); let itidObj = ITID.get(dicGoods.itid);
let flag = 0, msg = '创建失败'; let flag = 0, msg = '创建失败';
@@ -283,8 +284,7 @@ export default class GMUsers extends Service {
for(let roleId of uids) { for(let roleId of uids) {
let role = await RoleModel.findByRoleId(roleId); let role = await RoleModel.findByRoleId(roleId);
if(role) { if(role) {
let dicItem = ctx.service.utils.getGoodById(itemid); await ctx.service.utils.addBags(roleId, role.roleName, {id: itemid, itemName: dicGoods.name, count: itemcount, type: itidObj.type, hid: 0});
await ItemModel.increaseItem(roleId, itemid, itemcount, {roleId, roleName:role.roleName, id: itemid, itemName: dicItem.name, type: itidObj.type||0});
} else { } else {
flag = 1, msg = '未找到角色' + roleId; flag = 1, msg = '未找到角色' + roleId;
} }
@@ -310,6 +310,18 @@ export default class GMUsers extends Service {
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids }); return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
} }
public async addSkins(uids: Array<string>, _id: string) {
const {ctx} = this;
console.log('gm addSkin', uids, _id);
let id = parseInt(_id);
if(isNaN(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
for(let roleId of uids) {
await ctx.service.utils.addSkins(roleId, id);
}
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
}
public async levelUp(uids: Array<string>, _lv: string) { public async levelUp(uids: Array<string>, _lv: string) {
const {ctx} = this; const {ctx} = this;
console.log('gm levelUp', uids, _lv); console.log('gm levelUp', uids, _lv);
+1
View File
@@ -19,6 +19,7 @@
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"skipLibCheck": true, "skipLibCheck": true,
"skipDefaultLibCheck": true, "skipDefaultLibCheck": true,
"strictNullChecks": false,
"inlineSourceMap": true, "inlineSourceMap": true,
"importHelpers": true, "importHelpers": true,
"baseUrl": ".", "baseUrl": ".",
+36 -27
View File
@@ -22,29 +22,38 @@ export const CONSUME_TYPE = {
SKIN: 7, // 时装 SKIN: 7, // 时装
}; };
export enum EQUIP_TYPE {
WEAPON = 1, // 神兵(武器)
CLOTHES = 2, // 宝甲(上装)
SHOES = 3, // 行具(下装)
CAP = 4, // 冠冕(头部)
BOOK = 5, // 典籍(饰品)
ACCESSORY = 6, // 礼器(饰品)
}
const itid_array = [ const itid_array = [
{ id: 1, name: '短兵(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 1, name: '短兵(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 2, name: '枪矛(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 2, name: '枪矛(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 3, name: '重兵(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 3, name: '重兵(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 4, name: '弓弩(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 4, name: '弓弩(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 5, name: '奇门(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 5, name: '奇门(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 6, name: '羽扇(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 6, name: '羽扇(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 7, name: '法器(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 7, name: '法器(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 8, name: '杖(神兵)', goodType: GOOD_TYPE.EQUIP }, { id: 8, name: '杖(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 9, name: '头盔(冠冕)', goodType: GOOD_TYPE.EQUIP }, { id: 9, name: '头盔(冠冕)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CAP },
{ id: 10, name: '头巾(冠冕)', goodType: GOOD_TYPE.EQUIP }, { id: 10, name: '头巾(冠冕)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CAP },
{ id: 11, name: '重铠(宝甲)', goodType: GOOD_TYPE.EQUIP }, { id: 11, name: '重铠(宝甲)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES },
{ id: 12, name: '皮甲(宝甲)', goodType: GOOD_TYPE.EQUIP }, { id: 12, name: '皮甲(宝甲)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES },
{ id: 13, name: '布衣(宝甲)', goodType: GOOD_TYPE.EQUIP }, { id: 13, name: '布衣(宝甲)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES },
{ id: 14, name: '兵书(典籍)', goodType: GOOD_TYPE.EQUIP }, { id: 14, name: '兵书(典籍)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK },
{ id: 15, name: '杂记(典籍)', goodType: GOOD_TYPE.EQUIP }, { id: 15, name: '杂记(典籍)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK },
{ id: 16, name: '经典(典籍)', goodType: GOOD_TYPE.EQUIP }, { id: 16, name: '经典(典籍)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK },
{ id: 17, name: '马(行具)', goodType: GOOD_TYPE.EQUIP }, { id: 17, name: '马(行具)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES },
{ id: 18, name: '鞋(行具)', goodType: GOOD_TYPE.EQUIP }, { id: 18, name: '鞋(行具)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES },
{ id: 19, name: '车(行具)', goodType: GOOD_TYPE.EQUIP }, { id: 19, name: '车(行具)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES },
{ id: 20, name: '佩饰(礼器)', goodType: GOOD_TYPE.EQUIP }, { id: 20, name: '佩饰(礼器)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY },
{ id: 21, name: '钟鼎(礼器)', goodType: GOOD_TYPE.EQUIP }, { id: 21, name: '钟鼎(礼器)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY },
{ id: 22, name: '印章(礼器)', goodType: GOOD_TYPE.EQUIP }, { id: 22, name: '印章(礼器)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY },
{ id: 23, name: '消耗品', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.CONSUME }, { id: 23, name: '消耗品', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.CONSUME },
@@ -60,11 +69,11 @@ const itid_array = [
{ id: 27, name: '货币', goodType: GOOD_TYPE.CONSUMES, isCurrency: true }, { id: 27, name: '货币', goodType: GOOD_TYPE.CONSUMES, isCurrency: true },
{ id: 28, name: '藏宝图', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.BLUEPRT }, { id: 28, name: '藏宝图', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.BLUEPRT },
{ id: 29, name: '礼器', goodType: GOOD_TYPE.EQUIP }, { id: 29, name: '礼器', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY },
{ id: 30, name: '宝甲', goodType: GOOD_TYPE.EQUIP }, { id: 30, name: '宝甲', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES },
{ id: 31, name: '名驹', goodType: GOOD_TYPE.EQUIP }, { id: 31, name: '名驹', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES },
{ id: 32, name: '典籍', goodType: GOOD_TYPE.EQUIP }, { id: 32, name: '典籍', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK },
{ id: 33, name: '神兵', goodType: GOOD_TYPE.EQUIP }, { id: 33, name: '神兵', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON },
{ id: 34, name: '代币', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.POINT }, { id: 34, name: '代币', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.POINT },
{ id: 39, name: '时装', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.SKIN } { id: 39, name: '时装', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.SKIN }
]; ];
+3
View File
@@ -25,3 +25,6 @@ export interface Attributes {
bloodSuck?: number; bloodSuck?: number;
ap?: number; ap?: number;
} }
export interface EquipInter {id: number, name: string, quality: number, type: number};
export interface BagInter {id: number, itemName: string, count: number, type: number, hid:number};
+37
View File
@@ -0,0 +1,37 @@
import { HeroModel } from '../db/Hero';
import { ItemModel } from '../db/Item';
import { EquipModel } from './../db/Equip';
import { CounterModel } from './../db/Counter';
import { COUNTER } from './../consts/consts';
import { BagInter, EquipInter } from './interface';
import { gameData } from './data';
const _ = require('underscore');
export async function addSkins(roleId: string, id: number) {
let skinInfo = gameData.fashion.get(id);
if (!skinInfo)
return false;
let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId, false);
if (!hero)
return false;
if (!!_.findWhere(hero.skins, { id }))
return false;
hero.skins.push({ id, enable: false });
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
return { skins: hero.skins, hid: hero.hid };
}
export async function addBags(roleId: string, roleName: string, data: BagInter) {
let { id, count, itemName, type, hid } = data;
let item = await ItemModel.increaseItem(roleId, id, count, { roleId, roleName, itemName, id, type, hid });
return { id: item.id, count: item.count };
}
export async function addEquips(roleId: string, roleName: string, weapon: EquipInter) {
const seqId = await CounterModel.getNewCounter(COUNTER.EID);
let equip = Object.assign({ seqId, roleId, roleName }, weapon);
return await EquipModel.createEquip(equip);
}