Commit 92256e324771fac8fc6a43b486706237e425a755

Authored by zhangqijia
1 parent 8db23cb6

fix: 结束战斗的协议加上队伍id

cmd/gameserver/action/RoleAction.go
... ... @@ -221,6 +221,13 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i
221 221 return 2, nil
222 222 }
223 223  
  224 + //team
  225 + team, ok := role.Teams[req.TeamId]
  226 + if !ok {
  227 + logger.Error("team not exists")
  228 + return 3, nil
  229 + }
  230 +
224 231 reward := make(common.IMapStringNum)
225 232 if !first {
226 233 role.Role.PassChapters[req.ChapterId] = 1
... ... @@ -252,12 +259,40 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i
252 259 level, exp := role.UpLevel(amount)
253 260 role.UpdateProperties(map[string]interface{}{"level": level, "exp": exp}, true)
254 261  
  262 + //team exp
  263 + heros := make([]*pb.Hero, 4)
  264 + t := team.(*models.TeamModel).Team
  265 + h1, ok := role.Heros[t.HeroId1]
  266 + if ok {
  267 + level, exp := h1.(*models.HeroModel).UpLevel(amount)
  268 + h1.SetProperty("level", level)
  269 + h1.SetProperty("exp", exp)
  270 + heros = append(heros, h1.(*models.HeroModel).Hero)
  271 + }
  272 +
  273 + h2, ok := role.Heros[t.HeroId2]
  274 + if ok {
  275 + level, exp := h2.(*models.HeroModel).UpLevel(amount)
  276 + h2.SetProperty("level", level)
  277 + h2.SetProperty("exp", exp)
  278 + heros = append(heros, h2.(*models.HeroModel).Hero)
  279 + }
  280 +
  281 + h3, ok := role.Heros[t.HeroId3]
  282 + if ok {
  283 + level, exp := h3.(*models.HeroModel).UpLevel(amount)
  284 + h3.SetProperty("level", level)
  285 + h3.SetProperty("exp", exp)
  286 + heros = append(heros, h3.(*models.HeroModel).Hero)
  287 + }
  288 +
255 289 rsp := &pb.RoleEndBattleRsp{
256 290 RoleLevel: level,
257 291 RoleExp: exp,
258 292 RoleExpamount: amount,
259 293 Pass: req.Pass,
260 294 Reward: common.MapNumToString(reward),
  295 + Hero: heros,
261 296 }
262 297 return 0, rsp
263 298 }
... ...
cmd/gameserver/action/protocode.go
... ... @@ -18,4 +18,4 @@ func GetActionMap() map[interface{}]interface{} {
18 18 am[uint32(pb.ProtoCode_EquipmentDelReq)] = EquipmentDelRpc
19 19  
20 20 return am
21 21 -}
  22 +}
22 23 \ No newline at end of file
... ...
models/hero.go
... ... @@ -3,6 +3,7 @@ package models
3 3 import (
4 4 "pro2d/common"
5 5 "pro2d/common/components"
  6 + "pro2d/csvdata"
6 7 "pro2d/pb"
7 8 )
8 9  
... ... @@ -30,3 +31,33 @@ func (m *HeroModel) UpdateEquipment(key string, typ string) {
30 31  
31 32 m.SetProperty("equipments", common.MapToString(m.Equipments))
32 33 }
  34 +func (m *HeroModel) UpLevel(exp int32) (int32, int32) {
  35 + level := m.Hero.Level
  36 + oldLevelExp := csvdata.Get().TbHeroLevelExp.Get(level)
  37 + if oldLevelExp == nil {
  38 + return level, m.Hero.Exp
  39 + }
  40 + if exp >= oldLevelExp.NeedExp-m.Hero.Exp {
  41 + exp = exp - (oldLevelExp.NeedExp - m.Hero.Exp)
  42 + level++
  43 +
  44 + for exp > 0 {
  45 + oldLevelExp = csvdata.Get().TbHeroLevelExp.Get(level)
  46 + if oldLevelExp == nil {
  47 + return level, exp
  48 + }
  49 +
  50 + if exp >= oldLevelExp.NeedExp {
  51 + exp = exp - oldLevelExp.NeedExp
  52 + level++
  53 + } else {
  54 + exp = exp + m.Hero.Exp
  55 + break
  56 + }
  57 + }
  58 +
  59 + } else {
  60 + exp = exp + m.Hero.Exp
  61 + }
  62 + return level, exp
  63 +}
... ...
models/rolePlugin.go
... ... @@ -161,7 +161,6 @@ func (m *RoleModel) UpLevel(exp int32) (int32, int32) {
161 161 exp = exp + m.Role.Exp
162 162 }
163 163 return level, exp
164   -
165 164 }
166 165  
167 166 func (m *RoleModel) Award(award common.IMapStringNum) common.IMapStringNum {
... ...
models/team.go
... ... @@ -2,6 +2,8 @@ package models
2 2  
3 3 import (
4 4 "pro2d/common/components"
  5 + "pro2d/common/db/mongoproxy"
  6 + "pro2d/common/logger"
5 7 "pro2d/pb"
6 8 )
7 9  
... ... @@ -19,3 +21,16 @@ func NewTeam(data *pb.Team) *TeamModel {
19 21  
20 22 return m
21 23 }
  24 +
  25 +func TeamExistsByID(id string) *TeamModel {
  26 + data := &pb.Team{Id: id}
  27 + if err := mongoproxy.FindOne(mongoproxy.GetCollName(data), mongoproxy.GetBsonM("id", id), data); err != nil {
  28 + logger.Error("Role not exist err: %v", err)
  29 + return nil
  30 + }
  31 + r := &TeamModel{
  32 + ISchema: NewSchema(data.Id, data),
  33 + Team: data,
  34 + }
  35 + return r
  36 +}
... ...
pb/game.pb.go
... ... @@ -661,9 +661,10 @@ type RoleEndBattleReq struct {
661 661 sizeCache protoimpl.SizeCache
662 662 unknownFields protoimpl.UnknownFields
663 663  
664   - ChapterId int32 `protobuf:"varint,1,opt,name=chapter_id,json=chapterId,proto3" json:"chapter_id,omitempty"`
665   - CarbonId int32 `protobuf:"varint,2,opt,name=carbon_id,json=carbonId,proto3" json:"carbon_id,omitempty"`
666   - Pass bool `protobuf:"varint,3,opt,name=pass,proto3" json:"pass,omitempty"`
  664 + ChapterId int32 `protobuf:"varint,1,opt,name=chapter_id,json=chapterId,proto3" json:"chapter_id,omitempty"`
  665 + CarbonId int32 `protobuf:"varint,2,opt,name=carbon_id,json=carbonId,proto3" json:"carbon_id,omitempty"`
  666 + Pass bool `protobuf:"varint,3,opt,name=pass,proto3" json:"pass,omitempty"`
  667 + TeamId string `protobuf:"bytes,4,opt,name=team_id,json=teamId,proto3" json:"team_id,omitempty"`
667 668 }
668 669  
669 670 func (x *RoleEndBattleReq) Reset() {
... ... @@ -719,6 +720,14 @@ func (x *RoleEndBattleReq) GetPass() bool {
719 720 return false
720 721 }
721 722  
  723 +func (x *RoleEndBattleReq) GetTeamId() string {
  724 + if x != nil {
  725 + return x.TeamId
  726 + }
  727 + return ""
  728 +}
  729 +
  730 +//ResponseCmd RoleEndBattleRsp
722 731 type RoleEndBattleRsp struct {
723 732 state protoimpl.MessageState
724 733 sizeCache protoimpl.SizeCache
... ... @@ -954,32 +963,34 @@ var file_game_proto_rawDesc = []byte{
954 963 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65,
955 964 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x5f, 0x69, 0x64,
956 965 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x49, 0x64,
957   - 0x22, 0x62, 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x42, 0x61, 0x74, 0x74, 0x6c,
  966 + 0x22, 0x7b, 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x42, 0x61, 0x74, 0x74, 0x6c,
958 967 0x65, 0x52, 0x65, 0x71, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x5f,
959 968 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65,
960 969 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x5f, 0x69, 0x64,
961 970 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x63, 0x61, 0x72, 0x62, 0x6f, 0x6e, 0x49, 0x64,
962 971 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04,
963   - 0x70, 0x61, 0x73, 0x73, 0x22, 0xc1, 0x01, 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64,
964   - 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x6f, 0x6c,
965   - 0x65, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x72,
966   - 0x6f, 0x6c, 0x65, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x6f, 0x6c, 0x65,
967   - 0x5f, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x72, 0x6f, 0x6c, 0x65,
968   - 0x45, 0x78, 0x70, 0x12, 0x25, 0x0a, 0x0e, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x65, 0x78, 0x70, 0x61,
969   - 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x72, 0x6f, 0x6c,
970   - 0x65, 0x45, 0x78, 0x70, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65,
971   - 0x77, 0x61, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x77, 0x61,
972   - 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08,
973   - 0x52, 0x04, 0x70, 0x61, 0x73, 0x73, 0x12, 0x20, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x06,
974   - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x48, 0x65,
975   - 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x22, 0x21, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69,
976   - 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69,
977   - 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x3a, 0x0a, 0x0f, 0x45,
978   - 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x12, 0x27,
979   - 0x0a, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e,
980   - 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74,
981   - 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62,
982   - 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
  972 + 0x70, 0x61, 0x73, 0x73, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x69, 0x64, 0x18,
  973 + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x65, 0x61, 0x6d, 0x49, 0x64, 0x22, 0xc1, 0x01,
  974 + 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52,
  975 + 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c,
  976 + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x4c, 0x65, 0x76, 0x65,
  977 + 0x6c, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20,
  978 + 0x01, 0x28, 0x05, 0x52, 0x07, 0x72, 0x6f, 0x6c, 0x65, 0x45, 0x78, 0x70, 0x12, 0x25, 0x0a, 0x0e,
  979 + 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x65, 0x78, 0x70, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03,
  980 + 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x72, 0x6f, 0x6c, 0x65, 0x45, 0x78, 0x70, 0x61, 0x6d, 0x6f,
  981 + 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x18, 0x04, 0x20,
  982 + 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70,
  983 + 0x61, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x70, 0x61, 0x73, 0x73, 0x12,
  984 + 0x20, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e,
  985 + 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72,
  986 + 0x6f, 0x22, 0x21, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x44, 0x65,
  987 + 0x6c, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09,
  988 + 0x52, 0x02, 0x69, 0x64, 0x22, 0x3a, 0x0a, 0x0f, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e,
  989 + 0x74, 0x41, 0x64, 0x64, 0x52, 0x73, 0x70, 0x12, 0x27, 0x0a, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70,
  990 + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e,
  991 + 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x71, 0x75, 0x69, 0x70,
  992 + 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
  993 + 0x6f, 0x74, 0x6f, 0x33,
983 994 }
984 995  
985 996 var (
... ...