diff --git a/game-server/app/servers/connector/handler/entryHandler.ts b/game-server/app/servers/connector/handler/entryHandler.ts index 2be08705f..31862a690 100644 --- a/game-server/app/servers/connector/handler/entryHandler.ts +++ b/game-server/app/servers/connector/handler/entryHandler.ts @@ -83,10 +83,10 @@ export class EntryHandler { let equips = await EquipModel.findbyRole(role.roleId); let items = await ItemModel.findbyRole(role.roleId); - for(let hero of heros) { - let actor = new Actor(); - actor.initHero(hero); - actor.calculateCE(); + for(let i of heros) { + for(let j of i.ePlace) { + console.log(j.equip) + } } role['heros'] = heros; diff --git a/game-server/app/servers/role/handler/roleHandler.ts b/game-server/app/servers/role/handler/roleHandler.ts index 48ab60350..5dfc803dd 100644 --- a/game-server/app/servers/role/handler/roleHandler.ts +++ b/game-server/app/servers/role/handler/roleHandler.ts @@ -26,7 +26,7 @@ export class RoleHandler { type: 1 } const equip = await EquipModel.createEquip(equipInfo); - await HeroModel.addEquip(roleId, 1, equip._id); + await HeroModel.addEquip(roleId, 12, equip._id); } async initHeros(roleId: string, roleName: string) { @@ -54,10 +54,10 @@ export class RoleHandler { await this.initHeros(roleId, roleName); } - let equips = await EquipModel.findbyRole(roleId); - if (!equips || equips.length === 0) { + // let equips = await EquipModel.findbyRole(roleId); + // if (!equips || equips.length === 0) { await this.initEquips(roleId, roleName); - } + // } console.log('initRole finish'); } diff --git a/shared/db/Hero.ts b/shared/db/Hero.ts index d73c0ee7d..5377772da 100644 --- a/shared/db/Hero.ts +++ b/shared/db/Hero.ts @@ -3,7 +3,8 @@ import { CeAttr } from './generalField'; import { index, getModelForClass, prop, Ref, mongoose, DocumentType } from '@typegoose/typegoose'; import Equip from './Equip'; import { CounterModel } from './Counter'; -import { COUNTER } from '../consts'; +import { COUNTER, EQUIP_TYPE } from '../consts'; + /** * 英雄表 @@ -22,7 +23,7 @@ class Skin { enable: boolean; } -class EPlace { +export class EPlace { @prop({ required: true }) id: number; @prop({ ref: Equip, type: mongoose.Schema.Types.ObjectId }) @@ -35,6 +36,22 @@ class EPlace { refineCount: number; } +// 初始化 +function getInitialEplace() { + let ePlace = new Array(); + for(let i = EQUIP_TYPE.START; i <= EQUIP_TYPE.END; i++) { + let p = new EPlace(); + p.id = i; + p.equip = null; + p.lv = 1; + p.refineLv = 1; + p.refineCount = 0; + + ePlace.push(p); + } + return ePlace; +} + interface heroUpdate { exp?: number; lv?: number; @@ -108,11 +125,11 @@ export default class Hero extends BaseModel { @prop({ required: true, type: Skin, default: [] }) skins: Skin[]; // 皮肤 - @prop({ required: true, type: EPlace, default:[] }) - ePlact: EPlace[]; // 武将装备引用数组 + @prop({ required: true, type: EPlace, default: getInitialEplace() }) + ePlace: EPlace[]; // 武将装备引用数组 public static async findByRole(roleId: string, lean = true) { - const heros: HeroType[] = await HeroModel.find({ roleId }).populate('equips').lean(lean); + const heros: HeroType[] = await HeroModel.find({ roleId }).lean(lean); return heros; } @@ -130,7 +147,10 @@ export default class Hero extends BaseModel { } public static async addEquip(roleId: string, hid: number, equipId: string, lean = true) { - const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, {$push: {equips: equipId}}, {new: true}).lean(lean); + const hero: HeroType = await HeroModel.findOneAndUpdate( + { roleId, hid, 'ePlace.id': 1 }, + {$set: {'ePlace.$.equip': equipId}}, + {new: true}).lean(lean); if (hero) { await Equip.putOn(hero.hid, equipId); } diff --git a/shared/pubUtils/itemUtils.ts b/shared/pubUtils/itemUtils.ts index 9eb03e4e3..fa6cef4fd 100644 --- a/shared/pubUtils/itemUtils.ts +++ b/shared/pubUtils/itemUtils.ts @@ -1,12 +1,13 @@ -import { HeroModel } from '../db/Hero'; +import { HeroModel, EPlace } 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'; +import { EQUIP_TYPE } from '../consts'; const _ = require('underscore'); diff --git a/shared/pubUtils/playerCe.ts b/shared/pubUtils/playerCe.ts index 881e9e865..53f496846 100644 --- a/shared/pubUtils/playerCe.ts +++ b/shared/pubUtils/playerCe.ts @@ -4,14 +4,14 @@ import { HERO_SYSTEM_TYPE } from '../consts'; -import { deepCopy } from '../pubUtils/util'; +import { deepCopy } from './util'; import { HeroModel, HeroType } from '../db/Hero'; import { RoleModel } from '../db/Role'; import { CeAttrData, CeAttr } from '../db/generalField'; import { getAttrNameByJobStage, getAttrCeRatio, getAtrrNameById, ABI_TYPE_TO_STAGE, ABI_STAGE, SEID_TYPE, HERO_ATTR} from '../consts'; -import { gameData, getJobByGradeAndClass, getHeroWakeByQuality, getHeroStarByQuality, getFriendShipById } from '../pubUtils/data'; -import { Attributes } from '../pubUtils/interface'; -import { DicSe } from '../pubUtils/dictionary/DicSe'; +import { gameData, getJobByGradeAndClass, getHeroWakeByQuality, getHeroStarByQuality, getFriendShipById } from './data'; +import { Attributes } from './interface'; +import { DicSe } from './dictionary/DicSe'; const HERO_CE_RATIO = 100; const _ = require('underscore'); //战力计算TODO