diff --git a/cmd/gameserver/action/RoleAction.go b/cmd/gameserver/action/RoleAction.go index 4627db5..387d26c 100644 --- a/cmd/gameserver/action/RoleAction.go +++ b/cmd/gameserver/action/RoleAction.go @@ -221,6 +221,13 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i return 2, nil } + //team + team, ok := role.Teams[req.TeamId] + if !ok { + logger.Error("team not exists") + return 3, nil + } + reward := make(common.IMapStringNum) if !first { role.Role.PassChapters[req.ChapterId] = 1 @@ -252,12 +259,40 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i level, exp := role.UpLevel(amount) role.UpdateProperties(map[string]interface{}{"level": level, "exp": exp}, true) + //team exp + heros := make([]*pb.Hero, 4) + t := team.(*models.TeamModel).Team + h1, ok := role.Heros[t.HeroId1] + if ok { + level, exp := h1.(*models.HeroModel).UpLevel(amount) + h1.SetProperty("level", level) + h1.SetProperty("exp", exp) + heros = append(heros, h1.(*models.HeroModel).Hero) + } + + h2, ok := role.Heros[t.HeroId2] + if ok { + level, exp := h2.(*models.HeroModel).UpLevel(amount) + h2.SetProperty("level", level) + h2.SetProperty("exp", exp) + heros = append(heros, h2.(*models.HeroModel).Hero) + } + + h3, ok := role.Heros[t.HeroId3] + if ok { + level, exp := h3.(*models.HeroModel).UpLevel(amount) + h3.SetProperty("level", level) + h3.SetProperty("exp", exp) + heros = append(heros, h3.(*models.HeroModel).Hero) + } + rsp := &pb.RoleEndBattleRsp{ RoleLevel: level, RoleExp: exp, RoleExpamount: amount, Pass: req.Pass, Reward: common.MapNumToString(reward), + Hero: heros, } return 0, rsp } diff --git a/cmd/gameserver/action/protocode.go b/cmd/gameserver/action/protocode.go index a908688..c687269 100644 --- a/cmd/gameserver/action/protocode.go +++ b/cmd/gameserver/action/protocode.go @@ -18,4 +18,4 @@ func GetActionMap() map[interface{}]interface{} { am[uint32(pb.ProtoCode_EquipmentDelReq)] = EquipmentDelRpc return am -} +} \ No newline at end of file diff --git a/models/hero.go b/models/hero.go index 9c2d313..dcc7342 100644 --- a/models/hero.go +++ b/models/hero.go @@ -3,6 +3,7 @@ package models import ( "pro2d/common" "pro2d/common/components" + "pro2d/csvdata" "pro2d/pb" ) @@ -30,3 +31,33 @@ func (m *HeroModel) UpdateEquipment(key string, typ string) { m.SetProperty("equipments", common.MapToString(m.Equipments)) } +func (m *HeroModel) UpLevel(exp int32) (int32, int32) { + level := m.Hero.Level + oldLevelExp := csvdata.Get().TbHeroLevelExp.Get(level) + if oldLevelExp == nil { + return level, m.Hero.Exp + } + if exp >= oldLevelExp.NeedExp-m.Hero.Exp { + exp = exp - (oldLevelExp.NeedExp - m.Hero.Exp) + level++ + + for exp > 0 { + oldLevelExp = csvdata.Get().TbHeroLevelExp.Get(level) + if oldLevelExp == nil { + return level, exp + } + + if exp >= oldLevelExp.NeedExp { + exp = exp - oldLevelExp.NeedExp + level++ + } else { + exp = exp + m.Hero.Exp + break + } + } + + } else { + exp = exp + m.Hero.Exp + } + return level, exp +} diff --git a/models/rolePlugin.go b/models/rolePlugin.go index 02f35d2..f05fbad 100644 --- a/models/rolePlugin.go +++ b/models/rolePlugin.go @@ -161,7 +161,6 @@ func (m *RoleModel) UpLevel(exp int32) (int32, int32) { exp = exp + m.Role.Exp } return level, exp - } func (m *RoleModel) Award(award common.IMapStringNum) common.IMapStringNum { diff --git a/models/team.go b/models/team.go index cb0f00f..595f37d 100644 --- a/models/team.go +++ b/models/team.go @@ -2,6 +2,8 @@ package models import ( "pro2d/common/components" + "pro2d/common/db/mongoproxy" + "pro2d/common/logger" "pro2d/pb" ) @@ -19,3 +21,16 @@ func NewTeam(data *pb.Team) *TeamModel { return m } + +func TeamExistsByID(id string) *TeamModel { + data := &pb.Team{Id: id} + if err := mongoproxy.FindOne(mongoproxy.GetCollName(data), mongoproxy.GetBsonM("id", id), data); err != nil { + logger.Error("Role not exist err: %v", err) + return nil + } + r := &TeamModel{ + ISchema: NewSchema(data.Id, data), + Team: data, + } + return r +} diff --git a/pb/game.pb.go b/pb/game.pb.go index 0aeb56c..d6a556b 100644 --- a/pb/game.pb.go +++ b/pb/game.pb.go @@ -661,9 +661,10 @@ type RoleEndBattleReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ChapterId int32 `protobuf:"varint,1,opt,name=chapter_id,json=chapterId,proto3" json:"chapter_id,omitempty"` - CarbonId int32 `protobuf:"varint,2,opt,name=carbon_id,json=carbonId,proto3" json:"carbon_id,omitempty"` - Pass bool `protobuf:"varint,3,opt,name=pass,proto3" json:"pass,omitempty"` + ChapterId int32 `protobuf:"varint,1,opt,name=chapter_id,json=chapterId,proto3" json:"chapter_id,omitempty"` + CarbonId int32 `protobuf:"varint,2,opt,name=carbon_id,json=carbonId,proto3" json:"carbon_id,omitempty"` + Pass bool `protobuf:"varint,3,opt,name=pass,proto3" json:"pass,omitempty"` + TeamId string `protobuf:"bytes,4,opt,name=team_id,json=teamId,proto3" json:"team_id,omitempty"` } func (x *RoleEndBattleReq) Reset() { @@ -719,6 +720,14 @@ func (x *RoleEndBattleReq) GetPass() bool { return false } +func (x *RoleEndBattleReq) GetTeamId() string { + if x != nil { + return x.TeamId + } + return "" +} + +//ResponseCmd RoleEndBattleRsp type RoleEndBattleRsp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -954,32 +963,34 @@ var file_game_proto_rawDesc = []byte{ 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x49, 0x64, - 0x22, 0x62, 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x42, 0x61, 0x74, 0x74, 0x6c, + 0x22, 0x7b, 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, - 0x70, 0x61, 0x73, 0x73, 0x22, 0xc1, 0x01, 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, - 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x6f, 0x6c, - 0x65, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x72, - 0x6f, 0x6c, 0x65, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x6f, 0x6c, 0x65, - 0x5f, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x72, 0x6f, 0x6c, 0x65, - 0x45, 0x78, 0x70, 0x12, 0x25, 0x0a, 0x0e, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x65, 0x78, 0x70, 0x61, - 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x72, 0x6f, 0x6c, - 0x65, 0x45, 0x78, 0x70, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, - 0x77, 0x61, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x77, 0x61, - 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x04, 0x70, 0x61, 0x73, 0x73, 0x12, 0x20, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x06, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x48, 0x65, - 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x22, 0x21, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, - 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x3a, 0x0a, 0x0f, 0x45, - 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x12, 0x27, - 0x0a, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, - 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, - 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, - 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x61, 0x73, 0x73, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x69, 0x64, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x65, 0x61, 0x6d, 0x49, 0x64, 0x22, 0xc1, 0x01, + 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, + 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x4c, 0x65, 0x76, 0x65, + 0x6c, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x07, 0x72, 0x6f, 0x6c, 0x65, 0x45, 0x78, 0x70, 0x12, 0x25, 0x0a, 0x0e, + 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x65, 0x78, 0x70, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x72, 0x6f, 0x6c, 0x65, 0x45, 0x78, 0x70, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, + 0x61, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x70, 0x61, 0x73, 0x73, 0x12, + 0x20, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, + 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, + 0x6f, 0x22, 0x21, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65, + 0x6c, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x02, 0x69, 0x64, 0x22, 0x3a, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x12, 0x27, 0x0a, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, + 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, + 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( -- libgit2 0.21.2