112 lines
3.2 KiB
Go
112 lines
3.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"ecs/proto/pb"
|
|
"github.com/oylshe1314/framework/util"
|
|
)
|
|
|
|
type PlayerEquip struct {
|
|
Uid uint64 `bson:"uid" key:"1"`
|
|
Id uint32 `bson:"id"`
|
|
Level uint32 `bson:"level"`
|
|
RefineExp uint32 `bson:"refine_exp"`
|
|
RefineLevel uint32 `bson:"refine_level"`
|
|
Holes1 []uint64 `bson:"holes"`
|
|
Holes2 []uint64 `bson:"holes"`
|
|
HeroUid uint64 `bson:"hero_id"`
|
|
}
|
|
|
|
func (this *PlayerEquip) BuildMsgEquip() *pb.Equip {
|
|
return &pb.Equip{
|
|
Uid: this.Uid,
|
|
Id: this.Id,
|
|
Level: this.Level,
|
|
RefineExp: this.RefineExp,
|
|
RefineLevel: this.RefineLevel,
|
|
Holes1: this.Holes1,
|
|
Holes2: this.Holes2,
|
|
HeroUid: this.HeroUid,
|
|
}
|
|
}
|
|
|
|
func (this *Player) AddEquip(equipId uint32, logType LogType) bool {
|
|
var equipTable = this.manager.tables.Equip.Find1(int(equipId))
|
|
if equipTable == nil {
|
|
this.manager.Logger().Errorf("Find equip table failed, equipId: %d, level: %d", equipId, 1)
|
|
return false
|
|
}
|
|
|
|
var levelTable = this.manager.tables.EquipLevel.Find3(equipTable.Id, 1)
|
|
if levelTable == nil {
|
|
this.manager.Logger().Errorf("Table 'EquipLevel' was not fount, equipId %d, level: %d", equipTable.Id, 1)
|
|
return false
|
|
}
|
|
|
|
var equip = &PlayerEquip{
|
|
Uid: util.RandomUid(),
|
|
Id: uint32(equipTable.Id),
|
|
Level: uint32(levelTable.Level),
|
|
Holes1: make([]uint64, equipTable.Holes1),
|
|
Holes2: make([]uint64, equipTable.Holes2),
|
|
}
|
|
|
|
this.Equip[equip.Uid] = equip
|
|
this.SaveModel(equip)
|
|
|
|
_ = this.Send(pb.ModId_ModuleItem, 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) AddEquips(equipId, nums uint32, logType LogType) bool {
|
|
if nums <= 1 {
|
|
return this.AddEquip(equipId, logType)
|
|
}
|
|
|
|
var equipTable = this.manager.tables.Equip.Find1(int(equipId))
|
|
if equipTable == nil {
|
|
this.manager.Logger().Errorf("Find equip table failed, equipId: %d, level: %d", equipId, 1)
|
|
return false
|
|
}
|
|
|
|
var levelTable = this.manager.tables.EquipLevel.Find3(equipTable.Id, 1)
|
|
if levelTable == nil {
|
|
this.manager.Logger().Errorf("Find equip level table failed, equipId %d, level: %d", equipTable.Id, 1)
|
|
return false
|
|
}
|
|
|
|
var changeList []*pb.EquipChange
|
|
for range nums {
|
|
var equip = &PlayerEquip{
|
|
Uid: util.RandomUid(),
|
|
Id: uint32(equipTable.Id),
|
|
Level: uint32(levelTable.Level),
|
|
Holes1: make([]uint64, equipTable.Holes1),
|
|
Holes2: make([]uint64, equipTable.Holes2),
|
|
}
|
|
|
|
this.Equip[equip.Uid] = equip
|
|
this.SaveModel(equip)
|
|
|
|
changeList = append(changeList, &pb.EquipChange{ChangeType: pb.ChangeType_Add, Equip: equip.BuildMsgEquip()})
|
|
|
|
//this.CheckAchievement(proto.AchievementTypeEquipLevel, uint32(equipTable.Level), 1)
|
|
}
|
|
|
|
_ = this.Send(pb.ModId_ModuleItem, 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}
|
|
}
|