修改问题和战斗相关

This commit is contained in:
sk 2025-06-14 18:49:31 +08:00
parent 09538cc2ba
commit 2990de6624
19 changed files with 363 additions and 51 deletions

2
go.mod
View File

@ -1,6 +1,6 @@
module ecs
go 1.24.3
go 1.24
require (
github.com/json-iterator/go v1.1.12

8
go.sum
View File

@ -86,15 +86,11 @@ github.com/xuri/nfp v0.0.1/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.17.3 h1:TQyXhnsWfWtgAhMtOgtYHMTkZIfBTpMTsMnd9ZBeHxQ=
go.mongodb.org/mongo-driver v1.17.3/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
@ -111,8 +107,6 @@ golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -140,8 +134,6 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View File

@ -135,6 +135,9 @@ const (
// TipLineupsAlreadyMax 需要上级天赋满级
TipLineupsAlreadyMax StringTipError = "LineupsAlreadyMax"
// TipLineupCanNotDelete 阵容无法删除
TipLineupCanNotDelete StringTipError = "LineupCanNotDelete"
// ----------------------- 关卡模块 -----------------------
// TipCopyNotFound 找不到副本

View File

@ -30,7 +30,7 @@ message HeroListAck {
//
message HeroChange {
ChangeType ChangeType = 1;
Hero Hero = 2;
Hero Hero = 2; //ChangeType=ChangeType.Delete时, Hero中只有Uid有值
}
// MsgId.ModHeroChang: 5002

View File

@ -30,7 +30,7 @@ message ItemListAck {
// Change的消息基本都是这样的操作
message ItemChange {
ChangeType ChangeType = 1;
Item Item = 2;
Item Item = 2; //ChangeType=ChangeType.Delete时, Item中只有Uid有值
}
// MsgId.ModItemChange: 6002
@ -84,7 +84,7 @@ message EquipListAck {
message EquipChange {
ChangeType ChangeType = 1;
Equip Equip = 2;
Equip Equip = 2; //ChangeType=ChangeType.Delete时, Equip中只有Uid有值
}
// MsgId.ModEquipChange: 6012
@ -126,7 +126,7 @@ message TreasureListAck {
message TreasureChange {
ChangeType ChangeType = 1;
Treasure Treasure = 2;
Treasure Treasure = 2; //ChangeType=ChangeType.Delete时, Treasure中只有Uid有值
}
// MsgId.ModItemTreasureChange = 6022;

View File

@ -113,14 +113,14 @@ message LineupHeroChangeReq {
uint64 HeroUid = 3;
}
// MsgId.ModRoleBattleHeroPosition = 2008;
// MsgId.ModRoleLineupHeroPosition = 2008;
//
message LineupHeroPositionReq {
uint64 LineupUid = 1;
repeated uint32 PositionList = 3; // 6
}
// MsgId.ModRoleBattleHeroEquip = 2009;
// MsgId.ModRoleLineupHeroEquip = 2009;
//
message LineupHeroEquipReq {
uint64 LineupUid = 1;
@ -129,7 +129,7 @@ message LineupHeroEquipReq {
uint64 EquipUid = 4; // 0
}
// MsgId.ModRoleBattleHeroTreasure = 2010;
// MsgId.ModRoleLineupHeroTreasure = 2010;
//
message LineupHeroTreasureReq {
uint64 LineupUid = 1;
@ -138,7 +138,7 @@ message LineupHeroTreasureReq {
uint64 TreasureUid = 4; // 0
}
// MsgId.ModRoleBattleHeroArtifact = 2011;
// MsgId.ModRoleLineupHeroArtifact = 2011;
//
message LineupHeroArtifactReq {
uint64 LineupUid = 1;
@ -146,7 +146,7 @@ message LineupHeroArtifactReq {
uint64 ArtifactUid = 3;
}
// MsgId.ModRoleBattleHeroMounts = 2012;
// MsgId.ModRoleLineupHeroMounts = 2012;
//
message LineupHeroMountsReq {
uint64 LineupUid = 1;
@ -154,7 +154,7 @@ message LineupHeroMountsReq {
uint64 MountsUid = 3;
}
// MsgId.ModRoleBattleHeroGeneral = 2013;
// MsgId.ModRoleLineupHeroGeneral = 2013;
//
message LineupHeroGeneralReq {
uint64 LineupUid = 1;
@ -162,7 +162,7 @@ message LineupHeroGeneralReq {
uint64 GeneralUid = 3;
}
// MsgId.ModRoleBattleHeroOrnament = 2014;
// MsgId.ModRoleLineupHeroOrnament = 2014;
//
message LineupHeroOrnamentReq {
uint64 LineupUid = 1;
@ -178,6 +178,14 @@ message LineupHelperChangeReq{
uint64 HeroUid = 3; //0
}
// MsgId.ModRoleLineupEquipInlay = 2016;
//
message LineupEquipInlayReq {
uint64 LineupUid = 1;
uint32 Index = 2;
}
message Lineup {
uint64 Uid = 1; // ID(UID会越大)
string Name = 2; //
@ -194,7 +202,7 @@ message LineupListAck {
message LineupChange {
ChangeType ChangeType = 1;
Lineup Lineup = 2;
Lineup Lineup = 2; //ChangeType=ChangeType.Delete时, Lineup中只有Uid有值
}
// MsgId.ModRoleLineupChange = 2022;

View File

@ -125,6 +125,12 @@ enum MsgId {
//
ModRoleLineupHelperChange = 2015;
//
ModRoleLineupEquipInlay = 2016;
//
ModRoleLineupTreasureInlay = 2017;
//
ModRoleLineupList = 2021;

View File

@ -0,0 +1,40 @@
package data
import json "github.com/json-iterator/go"
type Skill struct {
Id int `json:"id"`
SkillType int `json:"skill_type"`
SkillBuff []int `json:"skill_buff"`
}
type SkillTable struct {
l []*Skill
m map[int]*Skill
}
func (this *SkillTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m = make(map[int]*Skill)
for i := range this.l {
this.m[this.l[i].Id] = this.l[i]
}
return nil
}
func (this *SkillTable) List() []*Skill {
return this.l
}
func (this *SkillTable) Get(i int) *Skill {
return this.l[i]
}
func (this *SkillTable) Find(id int) *Skill {
return this.m[id]
}

View File

@ -0,0 +1,40 @@
package data
import json "github.com/json-iterator/go"
type SkillBuff struct {
Id int `json:"id"`
SkillBuffType int `json:"SkillBuff_type"`
SkillBuffBuff []int `json:"SkillBuff_buff"`
}
type SkillBuffTable struct {
l []*SkillBuff
m map[int]*SkillBuff
}
func (this *SkillBuffTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m = make(map[int]*SkillBuff)
for i := range this.l {
this.m[this.l[i].Id] = this.l[i]
}
return nil
}
func (this *SkillBuffTable) List() []*SkillBuff {
return this.l
}
func (this *SkillBuffTable) Get(i int) *SkillBuff {
return this.l[i]
}
func (this *SkillBuffTable) Find(id int) *SkillBuff {
return this.m[id]
}

View File

@ -34,6 +34,8 @@ type Tables struct {
Monster MonsterTable
Scene SceneTable
ServerConfig ServerConfigTable
Skill SkillTable
SkillBuff SkillBuffTable
Treasure TreasureTable
TreasureLevel TreasureLevelTable
TreasureRefine TreasureRefineTable

View File

@ -61,3 +61,15 @@ func (this *UpgradeMasterTable) Find1(tipe int) []*UpgradeMaster {
func (this *UpgradeMasterTable) Find2(tipe, level int) *UpgradeMaster {
return this.m2[util.Compose2uint32(uint32(tipe), uint32(level))]
}
func (this *UpgradeMasterTable) FindMax(tipe, minLevel int) *UpgradeMaster {
var l = this.Find1(tipe)
var t *UpgradeMaster
for i := range l {
if l[i].NeedLevel >= minLevel {
break
}
t = l[i]
}
return t
}

View File

@ -124,7 +124,7 @@ func (this *PlayerHandler) GmCommand(player *logic.Player, msg *net.Message) {
player.WipeModel(item)
_ = player.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemChange), &pb.ItemChangeListAck{
ChangeList: []*pb.ItemChange{{Item: item.BuildMsgItem(), ChangeType: pb.ChangeType_Delete}},
ChangeList: []*pb.ItemChange{{ChangeType: pb.ChangeType_Delete, Item: item.BuildMsgItem(true)}},
})
return
}

View File

@ -6,6 +6,7 @@ import (
"ecs/servers/game/logic"
"github.com/oylshe1314/framework/net"
"github.com/oylshe1314/framework/util"
"sort"
"strings"
)
@ -320,6 +321,7 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
}
var lineupHeroList []*pb.LineupHero
var heroChangeList []*pb.HeroChange
var equipChangeList []*pb.EquipChange
if lineupHero.Equip[req.EquipType] != 0 {
@ -338,6 +340,12 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
player.SaveArray("lineup.heroes", int(req.Index), lineupHero)
lineupHeroList = append(lineupHeroList, lineupHero.BuildMsgLineupHero(req.Index))
if hero, ok := player.Hero[lineupHero.HeroUid]; ok {
if player.UpdateHeroAttrs(hero) {
heroChangeList = append(heroChangeList, &pb.HeroChange{ChangeType: pb.ChangeType_Changed, Hero: hero.BuildMsgHero()})
}
}
if equip != nil {
if equip.HeroUid != 0 {
util.SliceFindValue(lineup.Heroes[:], func(i int) bool {
@ -351,6 +359,11 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
preLineupHero.Equip[req.EquipType] = 0
player.SaveArray("lineup.heroes", i, preLineupHero)
lineupHeroList = append(lineupHeroList, preLineupHero.BuildMsgLineupHero(uint32(i)))
if preHero, ok := player.Hero[preLineupHero.HeroUid]; ok {
if player.UpdateHeroAttrs(preHero) {
heroChangeList = append(heroChangeList, &pb.HeroChange{ChangeType: pb.ChangeType_Changed, Hero: preHero.BuildMsgHero()})
}
}
}
return true
}
@ -370,6 +383,7 @@ func (this *PlayerHandler) LineupHeroEquip(player *logic.Player, msg *net.Messag
ChangeList: []*pb.LineupChange{{ChangeType: pb.ChangeType_Changed, Lineup: lineup.BuildMsgLineup()}},
})
_ = player.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipChange), &pb.EquipChangeListAck{ChangeList: equipChangeList})
_ = player.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroChange), &pb.HeroChangeListAck{ChangeList: heroChangeList})
return
}
@ -439,6 +453,7 @@ func (this *PlayerHandler) LineupHeroTreasure(player *logic.Player, msg *net.Mes
}
var lineupHeroList []*pb.LineupHero
var heroChangeList []*pb.HeroChange
var equipChangeList []*pb.TreasureChange
if lineupHero.Treasure[req.TreasureType] != 0 {
@ -457,6 +472,12 @@ func (this *PlayerHandler) LineupHeroTreasure(player *logic.Player, msg *net.Mes
player.SaveArray("lineup.heroes", int(req.Index), lineupHero)
lineupHeroList = append(lineupHeroList, lineupHero.BuildMsgLineupHero(req.Index))
if hero, ok := player.Hero[lineupHero.HeroUid]; ok {
if player.UpdateHeroAttrs(hero) {
heroChangeList = append(heroChangeList, &pb.HeroChange{ChangeType: pb.ChangeType_Changed, Hero: hero.BuildMsgHero()})
}
}
if treasure != nil {
if treasure.HeroUid != 0 {
util.SliceFindValue(lineup.Heroes[:], func(i int) bool {
@ -470,6 +491,12 @@ func (this *PlayerHandler) LineupHeroTreasure(player *logic.Player, msg *net.Mes
preLineupHero.Treasure[req.TreasureType] = 0
player.SaveArray("lineup.heroes", i, preLineupHero)
lineupHeroList = append(lineupHeroList, preLineupHero.BuildMsgLineupHero(uint32(i)))
if preHero, ok := player.Hero[preLineupHero.HeroUid]; ok {
if player.UpdateHeroAttrs(preHero) {
heroChangeList = append(heroChangeList, &pb.HeroChange{ChangeType: pb.ChangeType_Changed, Hero: preHero.BuildMsgHero()})
}
}
}
return true
}
@ -489,6 +516,7 @@ func (this *PlayerHandler) LineupHeroTreasure(player *logic.Player, msg *net.Mes
ChangeList: []*pb.LineupChange{{ChangeType: pb.ChangeType_Changed, Lineup: lineup.BuildMsgLineup()}},
})
_ = player.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemTreasureChange), &pb.TreasureChangeListAck{ChangeList: equipChangeList})
_ = player.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroChange), &pb.HeroChangeListAck{ChangeList: heroChangeList})
return
}
@ -540,6 +568,17 @@ func (this *PlayerHandler) LineupHelperChange(player *logic.Player, msg *net.Mes
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupChange), &pb.LineupChangeListAck{
ChangeList: []*pb.LineupChange{{ChangeType: pb.ChangeType_Changed, Lineup: lineup.BuildMsgLineup()}},
})
player.SendLineupHeroChange(lineup)
return
}
func (this *PlayerHandler) LineupEquipInlay(player *logic.Player, msg *net.Message) {
}
func (this *PlayerHandler) LineupTreasureInlay(player *logic.Player, msg *net.Message) {
}
func (this *PlayerHandler) LineupCreate(player *logic.Player, msg *net.Message) {
@ -631,7 +670,7 @@ func (this *PlayerHandler) LineupChangeName(player *logic.Player, msg *net.Messa
player.SaveModel(lineup)
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupChange), &pb.LineupChangeListAck{
ChangeList: []*pb.LineupChange{{ChangeType: pb.ChangeType_Changed, Lineup: lineup.BuildMsgLineup()}},
ChangeList: []*pb.LineupChange{{ChangeType: pb.ChangeType_Add, Lineup: lineup.BuildMsgLineup()}},
})
}
@ -657,13 +696,35 @@ func (this *PlayerHandler) LineupActivate(player *logic.Player, msg *net.Message
return
}
lineup.Active = true
if lineup.Active {
return
}
var lineupChangeList []*pb.LineupChange
var preLineup *logic.PlayerLineup
for _, v := range player.Lineup {
if v.Active {
preLineup = v
}
}
if preLineup != nil {
preLineup.Active = false
player.SaveModel(lineup)
lineupChangeList = append(lineupChangeList, &pb.LineupChange{ChangeType: pb.ChangeType_Changed, Lineup: preLineup.BuildMsgLineup()})
}
lineup.Active = true
player.SaveModel(lineup)
lineupChangeList = append(lineupChangeList, &pb.LineupChange{ChangeType: pb.ChangeType_Changed, Lineup: lineup.BuildMsgLineup()})
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupChange), &pb.LineupChangeListAck{
ChangeList: []*pb.LineupChange{{ChangeType: pb.ChangeType_Changed, Lineup: lineup.BuildMsgLineup()}},
})
player.SendLineupHeroChange(preLineup, lineup)
return
}
func (this *PlayerHandler) LineupDelete(player *logic.Player, msg *net.Message) {
@ -681,20 +742,45 @@ func (this *PlayerHandler) LineupDelete(player *logic.Player, msg *net.Message)
return
}
var lineup = player.Lineup[req.Uid]
if lineup == nil {
var delLineup = player.Lineup[req.Uid]
if delLineup == nil {
this.logger.Error("Player lineup not found, req.Uid: ", req.Uid)
_ = player.TipNotice(proto.TipLineupNotFound)
return
}
delete(player.Lineup, req.Uid)
if len(player.Lineup) == 1 {
this.logger.Error("Player lineup can not delete, len(player.Lineup) == 1")
_ = player.TipNotice(proto.TipLineupCanNotDelete)
return
}
var lineupChangeList []*pb.LineupChange
delLineup.Active = false
delete(player.Lineup, delLineup.Uid)
player.WipeModel(delLineup)
lineupChangeList = append(lineupChangeList, &pb.LineupChange{ChangeType: pb.ChangeType_Delete, Lineup: delLineup.BuildMsgLineup()})
var lineupList = make([]*logic.PlayerLineup, 0, len(player.Lineup))
for _, v := range player.Lineup {
lineupList = append(lineupList, v)
}
sort.Slice(lineupList, func(i, j int) bool {
return lineupList[i].Uid < lineupList[j].Uid
})
var lineup = lineupList[0]
lineup.Active = true
player.WipeModel(lineup)
lineupChangeList = append(lineupChangeList, &pb.LineupChange{ChangeType: pb.ChangeType_Changed, Lineup: lineup.BuildMsgLineup()})
_ = player.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupChange), &pb.LineupChangeListAck{
ChangeList: []*pb.LineupChange{{ChangeType: pb.ChangeType_Delete, Lineup: lineup.BuildMsgLineup()}},
ChangeList: lineupChangeList,
})
player.SendLineupHeroChange(delLineup, lineup)
}
//

View File

@ -175,7 +175,7 @@ func (this *PlayerManager) storeChanges(player *Player) {
}
func (this *PlayerManager) tick(player *Player, now, elapsed int64) int64 {
player.lock() // lock
player.lock()
defer player.unlock()
this.clearChanges(player)
@ -185,7 +185,6 @@ func (this *PlayerManager) tick(player *Player, now, elapsed int64) int64 {
var e = util.UnixMilli()
this.storeChanges(player)
return e - b
}
@ -236,7 +235,7 @@ func (this *PlayerManager) NewPlayer() *Player {
Artifact: map[uint64]*PlayerArtifact{},
//Achievement: map[uint64]*PlayerAchievement{},
//BattlePass: map[uint32]*PlayerBattlePass{},
//Cdkey: map[string]*PlayerCdkey{},
//CdKey: map[string]*PlayerCdKey{},
//CopyPassed: map[uint32]*PlayerCopyPassed{},
//CopySpeed: map[uint32]*PlayerCopySpeed{},
//CopyStatus: map[uint64]*PlayerCopyStatus{},

View File

@ -4,6 +4,7 @@ import (
"ecs/proto/pb"
"ecs/servers/game/data"
"github.com/oylshe1314/framework/util"
"math"
"slices"
)
@ -23,7 +24,10 @@ type PlayerHero struct {
attrs Attrs
}
func (this *PlayerHero) BuildMsgHero() *pb.Hero {
func (this *PlayerHero) BuildMsgHero(deleted ...bool) *pb.Hero {
if len(deleted) > 0 && deleted[0] {
return &pb.Hero{Uid: this.Uid}
}
return &pb.Hero{
Uid: this.Uid,
Id: this.Id,
@ -234,17 +238,51 @@ func (this *Player) calcHeroEquipsAttrs(hero *PlayerHero, lineup *PlayerLineup,
if lineup == nil || lineupHero == nil {
return
}
var minLevel uint32
var minRefineLevel uint32
var masterTable *data.UpgradeMaster
minLevel = math.MaxUint32
for _, equipUid := range lineupHero.Equip {
if equipUid == 0 {
continue
}
var equip = this.Equip[equipUid]
var equipLevelTable = this.manager.tables.EquipLevel.Find3(int(equip.Id), int(equip.Level))
if equipLevelTable != nil {
attrs[equipLevelTable.AttrType] += uint64(equipLevelTable.AttrValue)
if equip := this.Equip[equipUid]; equip != nil {
var equipLevelTable = this.manager.tables.EquipLevel.Find3(int(equip.Id), int(equip.Level))
if equipLevelTable != nil {
attrs[equipLevelTable.AttrType] += uint64(equipLevelTable.AttrValue)
}
if equip.Level < minLevel {
minLevel = equip.Level
}
if equip.RefineLevel < minRefineLevel {
minRefineLevel = equip.RefineLevel
}
}
}
masterTable = this.manager.tables.UpgradeMaster.FindMax(int(pb.UpgradeMasterType_MasterEquipUpgrade), int(minLevel))
if masterTable != nil {
attrs[masterTable.AttrType1] = uint64(masterTable.AttrValue1)
attrs[masterTable.AttrType2] = uint64(masterTable.AttrValue2)
attrs[masterTable.AttrType3] = uint64(masterTable.AttrValue3)
attrs[masterTable.AttrType4] = uint64(masterTable.AttrValue4)
attrs[masterTable.AttrType5] = uint64(masterTable.AttrValue5)
attrs[masterTable.AttrType6] = uint64(masterTable.AttrValue6)
}
masterTable = this.manager.tables.UpgradeMaster.FindMax(int(pb.UpgradeMasterType_MasterEquipUpgrade), int(minRefineLevel))
if masterTable != nil {
attrs[masterTable.AttrType1] = uint64(masterTable.AttrValue1)
attrs[masterTable.AttrType2] = uint64(masterTable.AttrValue2)
attrs[masterTable.AttrType3] = uint64(masterTable.AttrValue3)
attrs[masterTable.AttrType4] = uint64(masterTable.AttrValue4)
attrs[masterTable.AttrType5] = uint64(masterTable.AttrValue5)
attrs[masterTable.AttrType6] = uint64(masterTable.AttrValue6)
}
return
}
@ -252,17 +290,51 @@ func (this *Player) calcHeroTreasuresAttrs(hero *PlayerHero, lineup *PlayerLineu
if lineup == nil || lineupHero == nil {
return
}
var minLevel uint32
var minRefineLevel uint32
var masterTable *data.UpgradeMaster
minLevel = math.MaxUint32
for _, treasureUid := range lineupHero.Treasure {
if treasureUid == 0 {
continue
}
var treasure = this.Treasure[treasureUid]
var treasureLevelTable = this.manager.tables.TreasureLevel.Find3(int(treasure.Id), int(treasure.Level))
if treasureLevelTable != nil {
attrs[treasureLevelTable.AttrType] += uint64(treasureLevelTable.AttrValue)
if treasure := this.Treasure[treasureUid]; treasure != nil {
var treasureLevelTable = this.manager.tables.TreasureLevel.Find3(int(treasure.Id), int(treasure.Level))
if treasureLevelTable != nil {
attrs[treasureLevelTable.AttrType] += uint64(treasureLevelTable.AttrValue)
}
if treasure.Level < minLevel {
minLevel = treasure.Level
}
if treasure.RefineLevel < minRefineLevel {
minRefineLevel = treasure.RefineLevel
}
}
}
masterTable = this.manager.tables.UpgradeMaster.FindMax(int(pb.UpgradeMasterType_MasterTreasureUpgrade), int(minLevel))
if masterTable != nil {
attrs[masterTable.AttrType1] = uint64(masterTable.AttrValue1)
attrs[masterTable.AttrType2] = uint64(masterTable.AttrValue2)
attrs[masterTable.AttrType3] = uint64(masterTable.AttrValue3)
attrs[masterTable.AttrType4] = uint64(masterTable.AttrValue4)
attrs[masterTable.AttrType5] = uint64(masterTable.AttrValue5)
attrs[masterTable.AttrType6] = uint64(masterTable.AttrValue6)
}
masterTable = this.manager.tables.UpgradeMaster.FindMax(int(pb.UpgradeMasterType_MasterTreasureRefine), int(minRefineLevel))
if masterTable != nil {
attrs[masterTable.AttrType1] = uint64(masterTable.AttrValue1)
attrs[masterTable.AttrType2] = uint64(masterTable.AttrValue2)
attrs[masterTable.AttrType3] = uint64(masterTable.AttrValue3)
attrs[masterTable.AttrType4] = uint64(masterTable.AttrValue4)
attrs[masterTable.AttrType5] = uint64(masterTable.AttrValue5)
attrs[masterTable.AttrType6] = uint64(masterTable.AttrValue6)
}
return
}
@ -288,14 +360,12 @@ func (this *Player) calcHeroAttrs(hero *PlayerHero, attrsList ...Attrs) bool {
}
}
for i := range newAttrs {
if hero.attrs[i] != newAttrs[i] {
hero.attrs = newAttrs
return true
}
if newAttrs == hero.attrs {
return false
}
return false
hero.attrs = newAttrs
return true
}
func (this *Player) updateHeroAttrs(hero *PlayerHero, lineup *PlayerLineup, lineupHero *PlayerLineupHero) bool {

View File

@ -12,7 +12,10 @@ type PlayerItem struct {
Expired int64 `bson:"expired"`
}
func (this *PlayerItem) BuildMsgItem() *pb.Item {
func (this *PlayerItem) BuildMsgItem(deleted ...bool) *pb.Item {
if len(deleted) > 0 && deleted[0] {
return &pb.Item{ItemId: this.Id}
}
return &pb.Item{ItemId: this.Id, ItemNum: this.Num, Expired: this.Expired}
}
@ -194,17 +197,19 @@ func (this *Player) reduceItem(itemId, itemNum uint32, logType LogType) {
item.Num -= itemNum
var deleted = false
var changeType pb.ChangeType
if item.Num == 0 {
delete(this.Item, item.Id)
this.WipeModel(item)
deleted = true
changeType = pb.ChangeType_Delete
} else {
this.SaveModel(item)
changeType = pb.ChangeType_Changed
}
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemChange), &pb.ItemChangeListAck{ChangeList: []*pb.ItemChange{{Item: item.BuildMsgItem(), ChangeType: changeType}}})
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemChange), &pb.ItemChangeListAck{ChangeList: []*pb.ItemChange{{Item: item.BuildMsgItem(deleted), ChangeType: changeType}}})
//if logType > LogTypeNone {
// this.manager.eventManager.PlayerItemConsume(this, logType, itemId, itemNum)

View File

@ -15,7 +15,10 @@ type PlayerLineup struct {
Helper [8]uint64 `bson:"helper"`
}
func (this *PlayerLineup) BuildMsgLineup() *pb.Lineup {
func (this *PlayerLineup) BuildMsgLineup(deleted ...bool) *pb.Lineup {
if len(deleted) > 0 && deleted[0] {
return &pb.Lineup{Uid: this.Uid}
}
var msg = &pb.Lineup{Uid: this.Uid, Name: this.Name, Active: this.Active}
if this.Active {
msg.HeroList = make([]*pb.LineupHero, 8)
@ -31,11 +34,46 @@ func (this *PlayerLineup) BuildMsgLineup() *pb.Lineup {
return msg
}
func (this *Player) SendLineupHeroChange(lineups ...*PlayerLineup) {
var heroChangeList []*pb.HeroChange
for _, lineup := range lineups {
if lineup == nil {
continue
}
for _, lineupHero := range lineup.Heroes {
if lineupHero == nil {
continue
}
if hero, ok := this.Hero[lineupHero.HeroUid]; ok {
if lineup.Active {
if this.updateHeroAttrs(hero, lineup, lineupHero) {
heroChangeList = append(heroChangeList, &pb.HeroChange{ChangeType: pb.ChangeType_Changed, Hero: hero.BuildMsgHero()})
}
} else {
if this.updateHeroAttrs(hero, nil, nil) {
heroChangeList = append(heroChangeList, &pb.HeroChange{ChangeType: pb.ChangeType_Changed, Hero: hero.BuildMsgHero()})
}
}
}
}
}
_ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroChange), pb.HeroChangeListAck{
ChangeList: heroChangeList,
})
}
func (this *Player) SendUpgradeMaster(masterType pb.UpgradeMasterType, preLevel, curLevel uint32, heroUid uint64) {
if heroUid == 0 {
return
}
var hero = this.Hero[heroUid]
if hero == nil {
return
}
var masterTables = this.manager.tables.UpgradeMaster.Find1(int(masterType))
if len(masterTables) == 0 {
return
@ -68,7 +106,7 @@ func (this *Player) SendUpgradeMaster(masterType pb.UpgradeMasterType, preLevel,
}
var lineupHero = util.SliceFindValue(lineup.Heroes[:], func(i int) bool {
return lineup.Heroes[i] != nil && lineup.Heroes[i].HeroUid == heroUid
return lineup.Heroes[i] != nil && lineup.Heroes[i].HeroUid == hero.Uid
})
if lineupHero == nil {
return
@ -125,6 +163,12 @@ func (this *Player) SendUpgradeMaster(masterType pb.UpgradeMasterType, preLevel,
}
_ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleUpgradeMaster), ack)
if this.updateHeroAttrs(hero, lineup, lineupHero) {
_ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroChange), pb.HeroChangeListAck{
ChangeList: []*pb.HeroChange{{ChangeType: pb.ChangeType_Changed, Hero: hero.BuildMsgHero()}},
})
}
}
func (this *Player) BuildMsgLineupListAck() *pb.LineupListAck {

View File

@ -16,7 +16,10 @@ type PlayerTreasure struct {
HeroUid uint64 `bson:"hero_id"`
}
func (this *PlayerTreasure) BuildMsgTreasure() *pb.Treasure {
func (this *PlayerTreasure) BuildMsgTreasure(deleted ...bool) *pb.Treasure {
if len(deleted) > 0 && deleted[0] {
return &pb.Treasure{Uid: this.Uid}
}
return &pb.Treasure{
Uid: this.Uid,
Id: this.Id,

View File

@ -163,6 +163,8 @@ func (this *gameServer) Init() (err error) {
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroGeneral), this.playerHandler.LineupHeroGeneral)
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHeroOrnament), this.playerHandler.LineupHeroOrnament)
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupHelperChange), this.playerHandler.LineupHelperChange)
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupEquipInlay), this.playerHandler.LineupEquipInlay)
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupTreasureInlay), this.playerHandler.LineupTreasureInlay)
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupCreate), this.playerHandler.LineupCreate)
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupChangeName), this.playerHandler.LineupChangeName)
this.playerManager.Handler(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupActivate), this.playerHandler.LineupActivate)