118 lines
3.2 KiB
Go
118 lines
3.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"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,
|
|
Id: 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) bool {
|
|
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 false
|
|
}
|
|
|
|
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 true
|
|
}
|
|
|
|
func (this *Player) AddEquip(equipId uint32, logType LogType) bool {
|
|
var equipTable = this.manager.tables.Equip.Find(int(equipId))
|
|
if equipTable == nil {
|
|
this.manager.logger.Errorf("Find equip table failed, equipId: %d, level: %d", equipId, 1)
|
|
return false
|
|
}
|
|
return this.addEquip(equipTable, logType)
|
|
}
|
|
|
|
func (this *Player) AddEquips(equipId, nums uint32, logType LogType) bool {
|
|
var equipTable = this.manager.tables.Equip.Find(int(equipId))
|
|
if equipTable == nil {
|
|
this.manager.logger.Errorf("Find equip table failed, equipId: %d, level: %d", equipId, 1)
|
|
return false
|
|
}
|
|
|
|
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 false
|
|
}
|
|
|
|
if nums < 1 {
|
|
nums = 1
|
|
}
|
|
|
|
var changeList []*pb.EquipChange
|
|
for range nums {
|
|
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)
|
|
|
|
changeList = append(changeList, &pb.EquipChange{Equip: equip.BuildMsgEquip(), ChangeType: pb.ChangeType_Add})
|
|
|
|
//this.CheckAchievement(proto.AchievementTypeEquipLevel, uint32(equipTable.Level), 1)
|
|
}
|
|
|
|
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipChange), &pb.EquipChangeListAck{
|
|
ChangeList: changeList,
|
|
})
|
|
return true
|
|
}
|
|
|
|
func (this *Player) BuildMsgEquipListAck() *pb.EquipListAck {
|
|
var list []*pb.Equip
|
|
for _, equip := range this.Equip {
|
|
list = append(list, equip.BuildMsgEquip())
|
|
}
|
|
return &pb.EquipListAck{EquipList: list}
|
|
}
|