英雄和英雄名将册

This commit is contained in:
sk 2025-06-05 17:48:23 +08:00
parent 10a2bd4d15
commit 4ebf0badf5
13 changed files with 367 additions and 276 deletions

View File

@ -4,36 +4,36 @@ option go_package = "pb/";
import "mod_item.proto"; import "mod_item.proto";
message BattleEnterReq { //
uint32 SceneId = 1; //ID message BattleEntity {
}
message EntityProperty {
}
message ActionTarget {
uint32 Type = 1; //, 1.2.() uint32 Type = 1; //, 1.2.()
uint32 TargetId = 2; //ID uint32 Id = 2; //ID
uint32 Status = 3; // uint64 Hp = 3; //
uint64 Value = 4; // uint32 Rage = 4; //
uint32 Status = 5; //
uint64 Value = 6; //
} }
//
message BattleAction { message BattleAction {
uint32 BattleRound = 5; // BattleEntity Caster = 1; //
uint32 Caster = 1; //
uint32 Type = 2; // uint32 Type = 2; //
uint32 SkillId = 3; //ID uint32 SkillId = 3; //ID
repeated ActionTarget TargetList = 4; // repeated BattleEntity TargetList = 4; //
}
message BattleRound {
uint32 BattleRound = 1; //
repeated BattleAction ActionList = 2; //
} }
message BattleEnterAck { message BattleEnterAck {
uint32 SceneId = 1; //ID uint32 SceneId = 1; //ID
uint32 Result = 2; //, 1., 0. bool Result = 2; //, 1., 0.
uint32 Starts = 3; // int32 Score = 3; //
repeated int32 Heroes = 4; // repeated int32 Heroes = 4; //
repeated int32 Enemies = 5; // repeated int32 Enemies = 5; //
uint32 BattleRounds = 6; // uint32 BattleRounds = 6; //
repeated BattleAction ActionList = 7; // repeated BattleRound RoundList = 7;
repeated Item RewardList = 8; // repeated Item RewardList = 8; //
} }

View File

@ -9,19 +9,19 @@ import "enums.proto";
// , // ,
message Hero { message Hero {
uint32 HeroId = 1; uint64 Uid = 1;
uint64 Exp = 2; uint32 Id = 2;
uint32 Level = 3; uint64 Exp = 3;
uint32 BreakLevel = 4; uint32 Level = 4;
uint32 SoulLevel = 5; uint32 BreakLevel = 5;
repeated uint32 SoulList = 6; uint32 SoulLevel = 6;
uint32 Awaken = 7; repeated uint32 SoulList = 7;
repeated uint32 General = 8; uint32 Awaken = 8;
repeated uint64 Equips = 9; repeated uint64 Equips = 10;
repeated uint64 Treasures = 10; repeated uint64 Treasures = 11;
repeated uint64 Mounts = 11; repeated uint64 Mounts = 12;
repeated uint64 Artifact = 12; repeated uint64 Artifact = 13;
repeated uint64 Attrs = 13; repeated uint64 Attrs = 14;
} }
// ModItemChange: 6002 // ModItemChange: 6002
@ -44,21 +44,48 @@ message HeroChangeListAck {
// ModHeroUpgrade: 5003 // ModHeroUpgrade: 5003
// //
message HeroUpgradeReq { message HeroUpgradeReq {
uint32 HeroId = 1; uint64 HeroUid = 1;
uint32 Levels = 2; // 1/5 uint32 Levels = 2; // 1/5
} }
message HeroBreakReq { message HeroBreakReq {
uint32 HeroId = 1; uint64 HeroUid = 1;
uint32 OptItemId = 2; //ID uint32 OptItemId = 2; //ID
} }
message HeroGeneralActivateReq { message HeroEquipReq {
uint64 HeroUid = 1;
uint64 EquipUid = 2;
}
//
message HeroBookItem {
uint32 BookId = 1;
bool Active = 2;
}
//
message HeroBook {
uint32 HeroId = 1;
repeated HeroBookItem ItemList = 8;
}
// ModHeroBookList: 5013
//
message HeroBookListAck {
repeated HeroBook BookList = 1;
}
// ModHeroBookActivate: 5014
//
message HeroBookActivateReq {
uint32 HeroId = 1; uint32 HeroId = 1;
uint32 Index = 2; uint32 Index = 2;
} }
message HeroEquipReq { // ModHeroBookChange: 5015
uint32 HeroId = 1; //
uint64 EquipUid = 2; message HeroBookChangeAck {
ChangeType ChangeType = 1;
HeroBook HeroBook = 2;
} }

View File

@ -44,7 +44,7 @@ message Equip {
uint32 Level = 4; uint32 Level = 4;
uint32 Refine = 5; uint32 Refine = 5;
repeated uint32 Holes = 6; repeated uint32 Holes = 6;
uint32 HeroId = 7; uint64 HeroUid = 7;
} }
// ModEquipList: 6011 // ModEquipList: 6011

View File

@ -88,3 +88,7 @@ message Money {
message MoneyListAck { message MoneyListAck {
repeated Money MoneyList = 1; repeated Money MoneyList = 1;
} }
message TeamAck {
}

View File

@ -2,7 +2,7 @@ package data
import json "github.com/json-iterator/go" import json "github.com/json-iterator/go"
type HeroGeneral struct { type HeroBook struct {
Id int `json:"id"` Id int `json:"id"`
HeroId int `json:"hero_id"` HeroId int `json:"hero_id"`
NeedHeroes []int `json:"need_heroes"` NeedHeroes []int `json:"need_heroes"`
@ -14,20 +14,20 @@ type HeroGeneral struct {
AttrValue3 int `json:"attr_value3"` AttrValue3 int `json:"attr_value3"`
} }
type HeroGeneralTable struct { type HeroBookTable struct {
l []*HeroGeneral l []*HeroBook
m1 map[int]*HeroGeneral m1 map[int]*HeroBook
m2 map[int][]*HeroGeneral m2 map[int][]*HeroBook
} }
func (this *HeroGeneralTable) load(buf []byte) error { func (this *HeroBookTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l) var err = json.Unmarshal(buf, &this.l)
if err != nil { if err != nil {
return err return err
} }
this.m1 = make(map[int]*HeroGeneral) this.m1 = make(map[int]*HeroBook)
this.m2 = make(map[int][]*HeroGeneral) this.m2 = make(map[int][]*HeroBook)
for i := range this.l { for i := range this.l {
this.m1[this.l[i].Id] = this.l[i] this.m1[this.l[i].Id] = this.l[i]
this.m2[this.l[i].HeroId] = append(this.m2[this.l[i].HeroId], this.l[i]) this.m2[this.l[i].HeroId] = append(this.m2[this.l[i].HeroId], this.l[i])
@ -36,10 +36,10 @@ func (this *HeroGeneralTable) load(buf []byte) error {
return nil return nil
} }
func (this *HeroGeneralTable) Find1(heroId int) *HeroGeneral { func (this *HeroBookTable) Find1(id int) *HeroBook {
return this.m1[heroId] return this.m1[id]
} }
func (this *HeroGeneralTable) Find2(heroId int) []*HeroGeneral { func (this *HeroBookTable) Find2(heroId int) []*HeroBook {
return this.m2[heroId] return this.m2[heroId]
} }

View File

@ -16,7 +16,7 @@ func (this *PlayerHandler) HeroUpgrade(player *logic.Player, msg *net.Message) {
return return
} }
if req.HeroId == 0 { if req.HeroUid == 0 {
_ = player.TipNotice(proto.ErrParameterError) _ = player.TipNotice(proto.ErrParameterError)
return return
} }
@ -26,7 +26,7 @@ func (this *PlayerHandler) HeroUpgrade(player *logic.Player, msg *net.Message) {
return return
} }
var hero = player.Hero[req.HeroId] var hero = player.Hero[req.HeroUid]
if hero == nil { if hero == nil {
_ = player.TipNotice(proto.ErrHeroNotFound) _ = player.TipNotice(proto.ErrHeroNotFound)
return return
@ -144,12 +144,12 @@ func (this *PlayerHandler) HeroBreak(player *logic.Player, msg *net.Message) {
return return
} }
if req.HeroId == 0 || req.OptItemId == 0 { if req.HeroUid == 0 || req.OptItemId == 0 {
_ = player.TipNotice(proto.ErrParameterError) _ = player.TipNotice(proto.ErrParameterError)
return return
} }
var hero = player.Hero[req.HeroId] var hero = player.Hero[req.HeroUid]
if hero == nil { if hero == nil {
_ = player.TipNotice(proto.ErrHeroNotFound) _ = player.TipNotice(proto.ErrHeroNotFound)
return return
@ -208,70 +208,6 @@ func (this *PlayerHandler) HeroBreak(player *logic.Player, msg *net.Message) {
player.ReduceItem(optItemId, optItemNum, logic.LogTypeItemConsumeByHeroBreak) player.ReduceItem(optItemId, optItemNum, logic.LogTypeItemConsumeByHeroBreak)
} }
func (this *PlayerHandler) HeroGeneralActivate(player *logic.Player, msg *net.Message) {
var req = new(pb.HeroGeneralActivateReq)
var err = msg.Read(req)
if err != nil {
this.logger.Error("Read message failed, ", err)
_ = player.TipNotice(proto.ErrMessageError)
return
}
if req.HeroId == 0 {
_ = player.TipNotice(proto.ErrParameterError)
return
}
var hero = player.Hero[req.HeroId]
if hero == nil {
_ = player.TipNotice(proto.ErrHeroNotFound)
return
}
var heroGeneralTables = this.tables.HeroGeneral.Find2(int(hero.Id))
if len(heroGeneralTables) == 0 {
_ = player.TipNotice(proto.ErrDataTablesError)
return
}
if req.Index >= uint32(len(heroGeneralTables)) {
_ = player.TipNotice(proto.ErrParameterError)
return
}
if req.Index >= uint32(len(hero.General)) {
_ = player.TipNotice(proto.ErrParameterError)
return
}
if len(hero.General) != len(heroGeneralTables) {
var general = make([]uint32, len(heroGeneralTables))
copy(general, hero.General)
hero.General = general
}
if hero.General[req.Index] != 0 {
_ = player.TipNotice(proto.ErrHeroGeneralActivated)
return
}
for _, needId := range heroGeneralTables[req.Index].NeedHeroes {
if _, ok := player.Hero[uint32(needId)]; !ok {
_ = player.TipNotice(proto.ErrHeroGeneralCanNotActivate)
return
}
}
hero.General[req.Index] = uint32(heroGeneralTables[req.Index].HeroId)
player.SaveModel(hero)
player.UpdateHeroAttrs(hero)
_ = player.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroChange), &pb.HeroChangeListAck{
ChangeList: []*pb.HeroChange{{ChangeType: pb.ChangeType_Changed, Hero: hero.BuildMsgHero()}},
})
}
func (this *PlayerHandler) HeroAwaken(player *logic.Player, msg *net.Message) { func (this *PlayerHandler) HeroAwaken(player *logic.Player, msg *net.Message) {
} }
@ -297,7 +233,7 @@ func (this *PlayerHandler) HeroEquip(player *logic.Player, msg *net.Message) {
return return
} }
var hero = player.Hero[req.HeroId] var hero = player.Hero[req.HeroUid]
if hero == nil { if hero == nil {
_ = player.TipNotice(proto.ErrHeroNotFound) _ = player.TipNotice(proto.ErrHeroNotFound)
return return
@ -335,7 +271,7 @@ func (this *PlayerHandler) HeroEquip(player *logic.Player, msg *net.Message) {
if hero.Equips[equipIndex] != 0 { if hero.Equips[equipIndex] != 0 {
var setup = player.Equip[hero.Equips[equipIndex]] var setup = player.Equip[hero.Equips[equipIndex]]
if setup != nil && setup.HeroId != 0 { if setup != nil && setup.HeroUid != 0 {
setup.Id = 0 setup.Id = 0
player.SaveModel(setup) player.SaveModel(setup)
equipChangeList = append(equipChangeList, &pb.EquipChange{ equipChangeList = append(equipChangeList, &pb.EquipChange{
@ -352,8 +288,8 @@ func (this *PlayerHandler) HeroEquip(player *logic.Player, msg *net.Message) {
Hero: hero.BuildMsgHero(), Hero: hero.BuildMsgHero(),
}) })
if equip.HeroId != 0 { if equip.HeroUid != 0 {
var setup = player.Hero[equip.HeroId] var setup = player.Hero[equip.HeroUid]
if setup != nil && setup.Equips[equipIndex] != 0 { if setup != nil && setup.Equips[equipIndex] != 0 {
setup.Equips[equipIndex] = 0 setup.Equips[equipIndex] = 0
player.SaveModel(setup) player.SaveModel(setup)
@ -364,7 +300,7 @@ func (this *PlayerHandler) HeroEquip(player *logic.Player, msg *net.Message) {
} }
} }
equip.HeroId = hero.Id equip.HeroUid = hero.Uid
player.SaveModel(equip) player.SaveModel(equip)
equipChangeList = append(equipChangeList, &pb.EquipChange{ equipChangeList = append(equipChangeList, &pb.EquipChange{
ChangeType: pb.ChangeType_Changed, ChangeType: pb.ChangeType_Changed,
@ -387,3 +323,61 @@ func (this *PlayerHandler) HeroArtifacts(player *logic.Player, msg *net.Message)
func (this *PlayerHandler) HeroTips(player *logic.Player, msg *net.Message) { func (this *PlayerHandler) HeroTips(player *logic.Player, msg *net.Message) {
} }
func (this *PlayerHandler) HeroBookActivate(player *logic.Player, msg *net.Message) {
var req = new(pb.HeroBookActivateReq)
var err = msg.Read(req)
if err != nil {
this.logger.Error("Read message failed, ", err)
_ = player.TipNotice(proto.ErrMessageError)
return
}
if req.HeroId == 0 {
_ = player.TipNotice(proto.ErrParameterError)
return
}
var heroBook = player.HeroBook[req.HeroId]
if heroBook == nil {
_ = player.TipNotice(proto.ErrHeroNotFound)
return
}
if req.Index >= uint32(len(heroBook.Items)) {
_ = player.TipNotice(proto.ErrParameterError)
return
}
var heroBookTables = this.tables.HeroBook.Find2(int(heroBook.HeroId))
if len(heroBookTables) != len(heroBook.Items) {
_ = player.TipNotice(proto.ErrDataTablesError)
return
}
if heroBook.Items[req.Index].Value {
_ = player.TipNotice(proto.ErrHeroBookActivated)
return
}
for _, needId := range heroBookTables[req.Index].NeedHeroes {
if _, ok := player.HeroBook[uint32(needId)]; !ok {
_ = player.TipNotice(proto.ErrHeroBookCanNotActivate)
return
}
}
heroBook.Items[req.Index].Value = true
player.SaveModel(heroBook)
for _, hero := range player.Hero {
if hero.Id == heroBook.HeroId {
player.UpdateHeroAttrs(hero)
}
}
_ = player.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroBookChange), &pb.HeroBookChangeAck{
ChangeType: pb.ChangeType_Changed,
HeroBook: heroBook.BuildMsgHeroBook(),
})
}

View File

@ -119,8 +119,8 @@ func (this *PlayerManager) SetTables(tables *data.Tables) {
func (this *PlayerManager) PutPlayer(player *Player) { func (this *PlayerManager) PutPlayer(player *Player) {
this.locker.Lock() this.locker.Lock()
defer this.locker.Unlock()
this.players[player.UserId] = player this.players[player.UserId] = player
this.locker.Unlock()
} }
func (this *PlayerManager) GetPlayer(userId uint64) *Player { func (this *PlayerManager) GetPlayer(userId uint64) *Player {
@ -164,8 +164,8 @@ func (this *PlayerManager) storeChanges(player *Player) {
} }
if this.logger.IsDebugEnabled() { if this.logger.IsDebugEnabled() {
this.logger.Debug("Save: ", util.ToJsonString(player.save)) this.logger.Debugf("[%s:%d] Save: %s", player.Temp.Address, player.RoleId, util.ToJsonString(player.save))
this.logger.Debug("Wipe: ", util.ToJsonString(player.wipe)) this.logger.Debugf("[%s:%d] Wipe: %s", player.Temp.Address, player.RoleId, util.ToJsonString(player.wipe))
} }
_, err := this.mongoClient.Collection(TablePlayer).UpdateByID(this.mongoClient.Context(), player.RoleId, m) _, err := this.mongoClient.Collection(TablePlayer).UpdateByID(this.mongoClient.Context(), player.RoleId, m)
@ -205,7 +205,12 @@ func (this *PlayerManager) run(player *Player) {
player.unlock() // unlock player.unlock() // unlock
if e-b >= 1000 { if e-b >= 1000 {
this.logger.Warnf("The executing time of the player loop function is too long, Time: %dms, userId: %d, roleId: %d", e-b, player.UserId, player.RoleId) this.logger.Warnf("[%s:%d] The executing time of the player loop function is too long, Time: %dms, userId: %d, roleId: %d",
player.Temp.Address,
player.RoleId,
e-b,
player.UserId,
player.RoleId)
} }
} }
}(player) }(player)
@ -231,7 +236,8 @@ func (this *PlayerManager) NewPlayer() *Player {
//CopySpeed: map[uint32]*PlayerCopySpeed{}, //CopySpeed: map[uint32]*PlayerCopySpeed{},
//CopyStatus: map[uint64]*PlayerCopyStatus{}, //CopyStatus: map[uint64]*PlayerCopyStatus{},
Counter: map[uint32]map[uint64]*PlayerCounter{}, Counter: map[uint32]map[uint64]*PlayerCounter{},
Hero: map[uint32]*PlayerHero{}, Hero: map[uint64]*PlayerHero{},
HeroBook: map[uint32]*PlayerHeroBook{},
Item: map[uint32]*PlayerItem{}, Item: map[uint32]*PlayerItem{},
Equip: map[uint64]*PlayerEquip{}, Equip: map[uint64]*PlayerEquip{},
//GiftPack: map[uint32]*PlayerGiftPack{}, //GiftPack: map[uint32]*PlayerGiftPack{},
@ -404,7 +410,7 @@ func (this *PlayerManager) ExistsRoleName(name string) (bool, error) {
//} //}
func (this *PlayerManager) Enter(player *Player, conn *net.Conn) { func (this *PlayerManager) Enter(player *Player, conn *net.Conn) {
this.logger.Infof("The player enter game_1, userId: %d, roleId: %d", player.UserId, player.RoleId) this.logger.Infof("[%s] The player enter game_1, userId: %d, roleId: %d", player.Temp.Address, player.UserId, player.RoleId)
this.PutPlayer(player) this.PutPlayer(player)
@ -420,7 +426,7 @@ func (this *PlayerManager) Enter(player *Player, conn *net.Conn) {
} }
func (this *PlayerManager) Reenter(player *Player, conn *net.Conn) { func (this *PlayerManager) Reenter(player *Player, conn *net.Conn) {
this.logger.Infof("The player reenter game, userId: %d, roleId: %d", player.UserId, player.RoleId) this.logger.Infof("[%s] The player reenter game, userId: %d, roleId: %d", player.Temp.Address, player.UserId, player.RoleId)
player.lock() player.lock()
player.reenter(conn) player.reenter(conn)
@ -430,7 +436,7 @@ func (this *PlayerManager) Reenter(player *Player, conn *net.Conn) {
} }
func (this *PlayerManager) Exit(player *Player) { func (this *PlayerManager) Exit(player *Player) {
this.logger.Infof("The player exit game, userId: %d, roleId: %d", player.UserId, player.RoleId) this.logger.Infof("[%s] The player exit game, userId: %d, roleId: %d", player.Temp.Address, player.UserId, player.RoleId)
this.RemovePlayer(player.UserId) this.RemovePlayer(player.UserId)
@ -442,7 +448,7 @@ func (this *PlayerManager) Exit(player *Player) {
} }
func (this *PlayerManager) Lost(player *Player) { func (this *PlayerManager) Lost(player *Player) {
this.logger.Infof("The player lost, userId: %d, roleId: %d", player.UserId, player.RoleId) this.logger.Infof("[%s] The player lost, userId: %d, roleId: %d", player.Temp.Address, player.UserId, player.RoleId)
player.lock() player.lock()
player.lost(func() { player.lost(func() {
@ -454,7 +460,7 @@ func (this *PlayerManager) Lost(player *Player) {
} }
func (this *PlayerManager) Kick(player *Player, message string) { func (this *PlayerManager) Kick(player *Player, message string) {
this.logger.Infof("The player kicked, userId: %d, roleId: %d", player.UserId, player.RoleId) this.logger.Infof("[%s] The player kicked, userId: %d, roleId: %d", player.Temp.Address, player.UserId, player.RoleId)
this.RemovePlayer(player.UserId) this.RemovePlayer(player.UserId)
@ -514,7 +520,7 @@ func (this *PlayerManager) Handler(modId, msgId uint16, handler MessageHandler)
func (this *PlayerManager) Handle(player *Player, msg *net.Message) { func (this *PlayerManager) Handle(player *Player, msg *net.Message) {
handler, ok := this.messageHandlers[util.Compose2uint16(msg.ModId, msg.MsgId)] handler, ok := this.messageHandlers[util.Compose2uint16(msg.ModId, msg.MsgId)]
if !ok { if !ok {
this.logger.Warnf("Could not find the message handler, modId: %d, msgId: %d ", msg.ModId, msg.MsgId) this.logger.Warnf("[%s] Could not find the message handler, modId: %d, msgId: %d ", player.Temp.Address, msg.ModId, msg.MsgId)
return return
} }

View File

@ -14,7 +14,7 @@ type PlayerEquip struct {
Level uint32 `bson:"level"` Level uint32 `bson:"level"`
Refine uint32 `bson:"refine"` Refine uint32 `bson:"refine"`
Holes []uint32 `bson:"holes"` Holes []uint32 `bson:"holes"`
HeroId uint32 `bson:"hero_id"` HeroUid uint64 `bson:"hero_id"`
} }
func (this *PlayerEquip) BuildMsgEquip() *pb.Equip { func (this *PlayerEquip) BuildMsgEquip() *pb.Equip {
@ -25,7 +25,7 @@ func (this *PlayerEquip) BuildMsgEquip() *pb.Equip {
Level: this.Level, Level: this.Level,
Refine: this.Refine, Refine: this.Refine,
Holes: this.Holes, Holes: this.Holes,
HeroId: this.HeroId, HeroUid: this.HeroUid,
} }
} }
@ -45,7 +45,7 @@ func (this *Player) addEquip(equipTable *data.Equip, logType LogType) error {
Level: uint32(equipLevelTable.Level), Level: uint32(equipLevelTable.Level),
Refine: 0, Refine: 0,
Holes: make([]uint32, equipTable.Holes), Holes: make([]uint32, equipTable.Holes),
HeroId: 0, HeroUid: 0,
} }
this.Equip[equip.Uid] = equip this.Equip[equip.Uid] = equip

View File

@ -4,20 +4,21 @@ import (
"ecs/proto" "ecs/proto"
"ecs/proto/pb" "ecs/proto/pb"
"ecs/servers/game/data" "ecs/servers/game/data"
"github.com/oylshe1314/framework/util"
"slices" "slices"
) )
type Attrs [pb.AttrType_Nums]uint64 type Attrs [pb.AttrType_Nums]uint64
type PlayerHero struct { type PlayerHero struct {
Id uint32 `bson:"id" key:"1"` Uid uint64 `json:"uid" key:"1"`
Id uint32 `bson:"id"`
Exp uint64 `bson:"exp"` Exp uint64 `bson:"exp"`
Level uint32 `bson:"level"` Level uint32 `bson:"level"`
BreakLevel uint32 `bson:"break_level"` BreakLevel uint32 `bson:"break_level"`
SoulLevel uint32 `bson:"soul_level"` SoulLevel uint32 `bson:"soul_level"`
SoulList []uint32 `bson:"soul_list"` SoulList []uint32 `bson:"soul_list"`
Awaken uint32 `bson:"awaken"` Awaken uint32 `bson:"awaken"`
General []uint32 `bson:"general"`
Equips [4]uint64 `bson:"equips"` Equips [4]uint64 `bson:"equips"`
Treasures [2]uint64 `bson:"treasures"` Treasures [2]uint64 `bson:"treasures"`
Mounts [1]uint64 `bson:"mounts"` Mounts [1]uint64 `bson:"mounts"`
@ -28,14 +29,14 @@ type PlayerHero struct {
func (this *PlayerHero) BuildMsgHero() *pb.Hero { func (this *PlayerHero) BuildMsgHero() *pb.Hero {
return &pb.Hero{ return &pb.Hero{
HeroId: this.Id, Uid: this.Uid,
Id: this.Id,
Exp: this.Exp, Exp: this.Exp,
Level: this.Level, Level: this.Level,
BreakLevel: this.BreakLevel, BreakLevel: this.BreakLevel,
SoulLevel: this.SoulLevel, SoulLevel: this.SoulLevel,
SoulList: this.SoulList, SoulList: this.SoulList,
Awaken: this.Awaken, Awaken: this.Awaken,
General: this.General,
Equips: this.Equips[:], Equips: this.Equips[:],
Treasures: this.Treasures[:], Treasures: this.Treasures[:],
Mounts: this.Mounts[:], Mounts: this.Mounts[:],
@ -49,7 +50,10 @@ func (this *PlayerHero) Attrs() Attrs {
} }
func (this *Player) addHero(heroTable *data.Hero) error { func (this *Player) addHero(heroTable *data.Hero) error {
var hero = &PlayerHero{Id: uint32(heroTable.Id)} var hero = &PlayerHero{
Uid: util.RandomUid(),
Id: uint32(heroTable.Id),
}
var heroLevelTable *data.HeroLevel var heroLevelTable *data.HeroLevel
if heroTable.Level > 0 { if heroTable.Level > 0 {
@ -75,20 +79,14 @@ func (this *Player) addHero(heroTable *data.Hero) error {
//Awaken //Awaken
var heroGeneralBookTables = this.manager.tables.HeroGeneral.Find2(heroTable.Id) this.Hero[hero.Uid] = hero
hero.General = make([]uint32, len(heroGeneralBookTables))
this.Hero[hero.Id] = hero
this.SaveModel(hero) this.SaveModel(hero)
this.addHeroBook(hero.Id)
return nil return nil
} }
func (this *Player) AddHero(heroId uint32) error { func (this *Player) AddHero(heroId uint32) error {
var hero = this.Hero[heroId]
if hero != nil {
return nil
}
var heroTable = this.manager.tables.Hero.Find(int(heroId)) var heroTable = this.manager.tables.Hero.Find(int(heroId))
if heroTable == nil { if heroTable == nil {
this.manager.logger.Error("find hero table failed, heroId: ", heroId) this.manager.logger.Error("find hero table failed, heroId: ", heroId)
@ -132,23 +130,6 @@ func (this *Player) calcHeroBreakAttrs(hero *PlayerHero) (attrs Attrs) {
return return
} }
func (this *Player) calcHeroGeneralAttrs(hero *PlayerHero) (attrs Attrs) {
for i := range hero.General {
if hero.General[i] == 0 {
continue
}
var heroGeneralTable = this.manager.tables.HeroGeneral.Find1(int(hero.General[i]))
if heroGeneralTable == nil {
continue
}
attrs[heroGeneralTable.AttrType1] += uint64(heroGeneralTable.AttrValue1)
attrs[heroGeneralTable.AttrType2] += uint64(heroGeneralTable.AttrValue2)
attrs[heroGeneralTable.AttrType3] += uint64(heroGeneralTable.AttrValue3)
}
return
}
func (this *Player) calcHeroBondAttrs(hero *PlayerHero) (attrs Attrs) { func (this *Player) calcHeroBondAttrs(hero *PlayerHero) (attrs Attrs) {
var heroBondTables = this.manager.tables.HeroBond.Find(int(hero.Id)) var heroBondTables = this.manager.tables.HeroBond.Find(int(hero.Id))
for i := range heroBondTables { for i := range heroBondTables {
@ -184,6 +165,8 @@ func (this *Player) calcHeroBondAttrs(hero *PlayerHero) (attrs Attrs) {
break break
} }
} }
case 4: //英雄
} }
if yes { if yes {
attrs[heroBondTables[i].AttrType1] += uint64(heroBondTables[i].AttrValue1) attrs[heroBondTables[i].AttrType1] += uint64(heroBondTables[i].AttrValue1)
@ -225,6 +208,29 @@ func (this *Player) calcHeroArtifactAttrs(hero *PlayerHero) (attrs Attrs) {
return return
} }
func (this *Player) calcHeroBookAttrs(hero *PlayerHero) (attrs Attrs) {
var heroBook = this.HeroBook[hero.Id]
if heroBook == nil {
return
}
for _, item := range heroBook.Items {
if !item.Value {
continue
}
var heroGeneralTable = this.manager.tables.HeroBook.Find1(int(item.Key))
if heroGeneralTable == nil {
continue
}
attrs[heroGeneralTable.AttrType1] += uint64(heroGeneralTable.AttrValue1)
attrs[heroGeneralTable.AttrType2] += uint64(heroGeneralTable.AttrValue2)
attrs[heroGeneralTable.AttrType3] += uint64(heroGeneralTable.AttrValue3)
}
return
}
func (this *Player) calcHeroAttrs(hero *PlayerHero, attrsList ...Attrs) bool { func (this *Player) calcHeroAttrs(hero *PlayerHero, attrsList ...Attrs) bool {
var newAttrs Attrs var newAttrs Attrs
for _, attrs := range attrsList { for _, attrs := range attrsList {
@ -247,11 +253,13 @@ func (this *Player) updateHeroAttrs(hero *PlayerHero) bool {
return this.calcHeroAttrs(hero, return this.calcHeroAttrs(hero,
this.calcHeroLevelAttrs(hero), this.calcHeroLevelAttrs(hero),
this.calcHeroBreakAttrs(hero), this.calcHeroBreakAttrs(hero),
this.calcHeroBondAttrs(hero),
this.calcHeroAwakenAttrs(hero), this.calcHeroAwakenAttrs(hero),
this.calcHeroEquipsAttrs(hero), this.calcHeroEquipsAttrs(hero),
this.calcHeroTreasuresAttrs(hero), this.calcHeroTreasuresAttrs(hero),
this.calcHeroMountsAttrs(hero), this.calcHeroMountsAttrs(hero),
this.calcHeroArtifactAttrs(hero), this.calcHeroArtifactAttrs(hero),
this.calcHeroBookAttrs(hero),
) )
} }

View File

@ -0,0 +1,52 @@
package logic
import (
"ecs/proto/pb"
"github.com/oylshe1314/framework/util"
)
type PlayerHeroBook struct {
HeroId uint32 `json:"hero_id" key:"1"`
Items []*util.Pair[uint32, bool] `bson:"items"`
}
func (this *PlayerHeroBook) BuildMsgHeroBook() *pb.HeroBook {
var list []*pb.HeroBookItem
for _, item := range this.Items {
list = append(list, &pb.HeroBookItem{BookId: item.Key, Active: item.Value})
}
return &pb.HeroBook{HeroId: this.HeroId, ItemList: list}
}
func (this *Player) addHeroBook(heroId uint32) {
if _, ok := this.HeroBook[heroId]; ok {
return
}
var items []*util.Pair[uint32, bool]
var heroBookTables = this.manager.tables.HeroBook.Find2(int(heroId))
for _, heroBookTable := range heroBookTables {
items = append(items, util.NewPair(uint32(heroBookTable.Id), false))
}
var heroBook = &PlayerHeroBook{
HeroId: heroId,
Items: items,
}
this.HeroBook[heroBook.HeroId] = heroBook
this.SaveModel(heroBook)
_ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroBookChange), &pb.HeroBookChangeAck{
ChangeType: pb.ChangeType_Changed,
HeroBook: heroBook.BuildMsgHeroBook(),
})
}
func (this *Player) BuildMsgHeroBookListAck() *pb.HeroBookListAck {
var list []*pb.HeroBook
for _, heroBook := range this.HeroBook {
list = append(list, heroBook.BuildMsgHeroBook())
}
return &pb.HeroBookListAck{BookList: list}
}