diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index 299392cc1..75c45e9a8 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -1,6 +1,6 @@ import {Application, BackendSession, createTcpMailBox, ChannelService} from 'pinus'; import { handleCost, addItems } from '../../../services/rewardService'; -import { calPlayerCeAndSave, getAllAttrStage } from '../../../services/playerCeService'; +import { calPlayerCeAndSave } from '../../../services/playerCeService'; import { resResult } from '../../../pubUtils/util'; import { STATUS } from '../../../consts/statusCode'; import {HeroModel} from '../../../db/Hero'; @@ -9,6 +9,7 @@ import { RoleModel } from '../../../db/Role'; import { ItemModel } from '../../../db/Item'; import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById } from '../../../pubUtils/data'; import { RewardInter } from '../../../pubUtils/interface'; +import { getAllAttrStage } from '../../../pubUtils/playerCe'; export default function(app: Application) { return new HeroHandler(app); diff --git a/game-server/app/services/rewardService.ts b/game-server/app/services/rewardService.ts index f2a334f96..d1ad96b58 100644 --- a/game-server/app/services/rewardService.ts +++ b/game-server/app/services/rewardService.ts @@ -2,14 +2,13 @@ import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE, COUNTER, CONSUME_TYPE, getCur import { EquipModel } from './../db/Equip'; import { CounterModel } from './../db/Counter'; import { decodeStr, resResult } from '../pubUtils/util'; -import { getGoodById, getFashionsById } from '../pubUtils/gamedata'; +import { getGoodById } from '../pubUtils/gamedata'; import { RoleModel } from '../db/Role'; import { setAp } from './actionPointService'; import { ItemModel } from '../db/Item'; import { STATUS } from '../consts/statusCode'; import { pinus } from 'pinus'; -import { HeroModel } from '../db/Hero'; -import { treatTask } from './battleService'; +import { addEquips, addBags, addSkins } from '../pubUtils/itemUtils'; const _ = require('underscore'); export async function handleFixedReward(roleId: string, roleName: string, rewardStr: string, multi: number) { @@ -298,31 +297,4 @@ function sortItems (goods: Array, bags: Array, skins: Array, } } } -} - -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); -} - +} \ No newline at end of file diff --git a/gm-server/app/controller/users.ts b/gm-server/app/controller/users.ts index c406e0b27..ca49c28f6 100644 --- a/gm-server/app/controller/users.ts +++ b/gm-server/app/controller/users.ts @@ -30,7 +30,7 @@ export default class UserController extends Controller { public async createRoleData() { 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') { ctx.body = await ctx.service.users.createHero(uids, hid, hlv); } else if(optType == 'equip') { @@ -41,6 +41,8 @@ export default class UserController extends Controller { ctx.body = await ctx.service.users.addGold(uids, count); } else if (optType == 'lv') { ctx.body = await ctx.service.users.levelUp(uids, lv); + } else if (optType == 'skin') { + ctx.body = await ctx.service.users.addSkins(uids, skinid); } else { ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS); } diff --git a/gm-server/app/service/Utils.ts b/gm-server/app/service/Utils.ts index 245c14134..8853ae813 100644 --- a/gm-server/app/service/Utils.ts +++ b/gm-server/app/service/Utils.ts @@ -3,6 +3,8 @@ import * as pubUtils from '../pubUtils/util'; import * as pubGamedata from '../pubUtils/gamedata' import { HeroType } from '@db/Hero'; import { calPlayerCeAndSave } from '@pubUtils/playerCe'; +import { addSkins, addBags, addEquips } from '@pubUtils/itemUtils'; +import { BagInter, EquipInter } from '@pubUtils/interface'; const csprng = require('csprng'); /** @@ -52,4 +54,16 @@ export default class Utils extends Service { public calPlayerCeAndSave(roleId: string, heros: HeroType[], type: number, args: number[]) { 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); + } } diff --git a/gm-server/app/service/users.ts b/gm-server/app/service/users.ts index 4de506a8d..5c678f701 100644 --- a/gm-server/app/service/users.ts +++ b/gm-server/app/service/users.ts @@ -25,6 +25,7 @@ import { STATUS } from '@consts'; import { ITID, COUNTER } from '@consts'; import Actor from '@pubUtils/actor'; import { ItemModel } from '@db/Item'; +import { gameData } from '@pubUtils/data'; /** * Test Service @@ -271,7 +272,7 @@ 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); - let dicGoods = ctx.service.utils.getGoodById(itemid); + let dicGoods = gameData.goods.get(itemid); let itidObj = ITID.get(dicGoods.itid); let flag = 0, msg = '创建失败'; @@ -283,8 +284,7 @@ export default class GMUsers extends Service { for(let roleId of uids) { let role = await RoleModel.findByRoleId(roleId); if(role) { - let dicItem = ctx.service.utils.getGoodById(itemid); - await ItemModel.increaseItem(roleId, itemid, itemcount, {roleId, roleName:role.roleName, id: itemid, itemName: dicItem.name, type: itidObj.type||0}); + await ctx.service.utils.addBags(roleId, role.roleName, {id: itemid, itemName: dicGoods.name, count: itemcount, type: itidObj.type, hid: 0}); } else { flag = 1, msg = '未找到角色' + roleId; } @@ -310,6 +310,18 @@ export default class GMUsers extends Service { return ctx.service.utils.resResult(STATUS.SUCCESS, { uids }); } + public async addSkins(uids: Array, _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, _lv: string) { const {ctx} = this; console.log('gm levelUp', uids, _lv); diff --git a/gm-server/tsconfig.json b/gm-server/tsconfig.json index 4e0feaed2..26b4629a9 100644 --- a/gm-server/tsconfig.json +++ b/gm-server/tsconfig.json @@ -19,6 +19,7 @@ "noFallthroughCasesInSwitch": true, "skipLibCheck": true, "skipDefaultLibCheck": true, + "strictNullChecks": false, "inlineSourceMap": true, "importHelpers": true, "baseUrl": ".", diff --git a/shared/consts/constModules/itemConst.ts b/shared/consts/constModules/itemConst.ts index 31615d0a6..22dc12a4a 100644 --- a/shared/consts/constModules/itemConst.ts +++ b/shared/consts/constModules/itemConst.ts @@ -22,29 +22,38 @@ export const CONSUME_TYPE = { SKIN: 7, // 时装 }; +export enum EQUIP_TYPE { + WEAPON = 1, // 神兵(武器) + CLOTHES = 2, // 宝甲(上装) + SHOES = 3, // 行具(下装) + CAP = 4, // 冠冕(头部) + BOOK = 5, // 典籍(饰品) + ACCESSORY = 6, // 礼器(饰品) +} + 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.EQUIP }, + { id: 1, name: '短兵(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 2, name: '枪矛(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 3, name: '重兵(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 4, name: '弓弩(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 5, name: '奇门(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 6, name: '羽扇(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 7, name: '法器(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 8, name: '杖(神兵)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, + { id: 9, name: '头盔(冠冕)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CAP }, + { id: 10, name: '头巾(冠冕)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CAP }, + { id: 11, name: '重铠(宝甲)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES }, + { id: 12, name: '皮甲(宝甲)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES }, + { id: 13, name: '布衣(宝甲)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES }, + { id: 14, name: '兵书(典籍)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK }, + { id: 15, name: '杂记(典籍)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK }, + { id: 16, name: '经典(典籍)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK }, + { id: 17, name: '马(行具)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES }, + { id: 18, name: '鞋(行具)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES }, + { id: 19, name: '车(行具)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES }, + { id: 20, name: '佩饰(礼器)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY }, + { id: 21, name: '钟鼎(礼器)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY }, + { id: 22, name: '印章(礼器)', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY }, { 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: 28, name: '藏宝图', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.BLUEPRT }, - { id: 29, name: '礼器', goodType: GOOD_TYPE.EQUIP }, - { id: 30, name: '宝甲', goodType: GOOD_TYPE.EQUIP }, - { id: 31, name: '名驹', goodType: GOOD_TYPE.EQUIP }, - { id: 32, name: '典籍', goodType: GOOD_TYPE.EQUIP }, - { id: 33, name: '神兵', goodType: GOOD_TYPE.EQUIP }, + { id: 29, name: '礼器', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.ACCESSORY }, + { id: 30, name: '宝甲', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.CLOTHES }, + { id: 31, name: '名驹', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.SHOES }, + { id: 32, name: '典籍', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.BOOK }, + { id: 33, name: '神兵', goodType: GOOD_TYPE.EQUIP, type: EQUIP_TYPE.WEAPON }, { id: 34, name: '代币', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.POINT }, { id: 39, name: '时装', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.SKIN } ]; diff --git a/shared/pubUtils/interface.ts b/shared/pubUtils/interface.ts index b6bd3cecf..3378ef258 100644 --- a/shared/pubUtils/interface.ts +++ b/shared/pubUtils/interface.ts @@ -24,4 +24,7 @@ export interface Attributes { defIngnore?: number; bloodSuck?: number; ap?: number; -} \ No newline at end of file +} + +export interface EquipInter {id: number, name: string, quality: number, type: number}; +export interface BagInter {id: number, itemName: string, count: number, type: number, hid:number}; \ No newline at end of file diff --git a/shared/pubUtils/itemUtils.ts b/shared/pubUtils/itemUtils.ts new file mode 100644 index 000000000..9eb03e4e3 --- /dev/null +++ b/shared/pubUtils/itemUtils.ts @@ -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); +}