113 lines
3.0 KiB
Go
113 lines
3.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"ecs/proto"
|
|
"ecs/proto/pb"
|
|
"ecs/servers/game/data"
|
|
"github.com/oylshe1314/framework/util"
|
|
)
|
|
|
|
type PlayerEquip struct {
|
|
Uid uint64 `bson:"uid" key:"1"`
|
|
Id uint32 `bson:"id"`
|
|
Exp uint64 `bson:"exp"`
|
|
Level uint32 `bson:"level"`
|
|
Refine uint32 `bson:"refine"`
|
|
Holes []uint32 `bson:"holes"`
|
|
HeroUid uint64 `bson:"hero_id"`
|
|
}
|
|
|
|
func (this *PlayerEquip) BuildMsgEquip() *pb.Equip {
|
|
return &pb.Equip{
|
|
Uid: this.Uid,
|
|
EquipId: this.Id,
|
|
Exp: this.Exp,
|
|
Level: this.Level,
|
|
Refine: this.Refine,
|
|
Holes: this.Holes,
|
|
HeroUid: this.HeroUid,
|
|
}
|
|
}
|
|
|
|
func (this *Player) addEquip(equipTable *data.Equip, logType LogType) error {
|
|
var equipLevelTable = this.manager.tables.EquipLevel.Find3(equipTable.Id, 1)
|
|
if equipLevelTable == nil {
|
|
this.manager.logger.Errorf("find equip level table failed, equipId %d, level: %d", equipTable.Id, 1)
|
|
return proto.ErrDataTablesError
|
|
}
|
|
|
|
this.manager.mongoClient.Counter("equip_id", 1)
|
|
|
|
var equip = &PlayerEquip{
|
|
Uid: util.RandomUid(),
|
|
Id: uint32(equipTable.Id),
|
|
Exp: 0,
|
|
Level: uint32(equipLevelTable.Level),
|
|
Refine: 0,
|
|
Holes: make([]uint32, equipTable.Holes),
|
|
HeroUid: 0,
|
|
}
|
|
|
|
this.Equip[equip.Uid] = equip
|
|
this.SaveModel(equip)
|
|
|
|
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipChange), &pb.EquipChangeListAck{
|
|
ChangeList: []*pb.EquipChange{{Equip: equip.BuildMsgEquip(), ChangeType: pb.ChangeType_Add}},
|
|
})
|
|
|
|
//this.CheckAchievement(proto.AchievementTypeEquipLevel, uint32(equipTable.Level), 1)
|
|
return nil
|
|
}
|
|
|
|
func (this *Player) AddEquip(itemTable *data.Item, logType LogType) error {
|
|
var equipTable = this.manager.tables.Equip.Find(itemTable.Id)
|
|
if equipTable == nil {
|
|
this.manager.logger.Errorf("find equip table failed, itemId %d, level: %d", itemTable.Id, 1)
|
|
return proto.ErrDataTablesError
|
|
}
|
|
return this.addEquip(equipTable, logType)
|
|
}
|
|
|
|
//func (this *Player) SetupRigEquip(index uint32, equip *PlayerRigEquip) {
|
|
// var list []*proto.RigEquipChange
|
|
// var setupId = this.Rig.Equips[index]
|
|
// if equip == nil {
|
|
// if setupId == 0 {
|
|
// return
|
|
// }
|
|
// this.Rig.Equips[index] = 0
|
|
// } else {
|
|
// this.Rig.Equips[index] = equip.ItemId
|
|
//
|
|
// equip.Setup = true
|
|
// this.SaveModel(equip)
|
|
//
|
|
// list = append(list, &proto.RigEquipChange{RigEquip: equip.BuildMsgRigEquip(), ChangeType: uint32(proto.ChangeTypeChange)})
|
|
// }
|
|
//
|
|
// this.SaveField("rig.equips", this.Rig.Equips)
|
|
//
|
|
// if setupId > 0 {
|
|
// if setupEquip := this.RigEquip[setupId]; setupEquip != nil {
|
|
// setupEquip.Setup = false
|
|
// this.SaveModel(setupEquip)
|
|
//
|
|
// list = append(list, &proto.RigEquipChange{RigEquip: setupEquip.BuildMsgRigEquip(), ChangeType: uint32(proto.ChangeTypeChange)})
|
|
// }
|
|
// }
|
|
//
|
|
// _ = this.Send(proto.ModIdRig, proto.MsgIdRigEquipChange, &proto.MsgRigEquipChangeListAck{
|
|
// List: list,
|
|
// })
|
|
//
|
|
// this.UpdateRigAttrs()
|
|
//}
|
|
|
|
func (this *Player) BuildMsgRigEquipListAck() *pb.EquipListAck {
|
|
var list []*pb.Equip
|
|
for _, equip := range this.Equip {
|
|
list = append(list, equip.BuildMsgEquip())
|
|
}
|
|
return &pb.EquipListAck{EquipList: list}
|
|
}
|