Commit d6d589a95185fb17efb7b8cac09bc2f9d227c078
1 parent
71920def
feat: 增加装备接口
Showing
2 changed files
with
38 additions
and
0 deletions
Show diff stats
cmd/gameserver/action/GmAction.go
| @@ -3,6 +3,7 @@ package action | @@ -3,6 +3,7 @@ package action | ||
| 3 | import ( | 3 | import ( |
| 4 | "pro2d/common/logger" | 4 | "pro2d/common/logger" |
| 5 | "pro2d/models" | 5 | "pro2d/models" |
| 6 | + "pro2d/pb" | ||
| 6 | "strconv" | 7 | "strconv" |
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| @@ -15,3 +16,29 @@ func (gm *GmAction) AddExp(role *models.RoleModel, properties map[string]interfa | @@ -15,3 +16,29 @@ func (gm *GmAction) AddExp(role *models.RoleModel, properties map[string]interfa | ||
| 15 | role.IncrPropertyChan("exp", int64(exp)) | 16 | role.IncrPropertyChan("exp", int64(exp)) |
| 16 | return 0 | 17 | return 0 |
| 17 | } | 18 | } |
| 19 | + | ||
| 20 | +func (gm *GmAction) AddEquip(role *models.RoleModel, properties map[string]interface{}) int { | ||
| 21 | + logger.Debug(properties) | ||
| 22 | + equip := &pb.Equipment{ | ||
| 23 | + Id: role.IncreEquipByKey(1), | ||
| 24 | + RoleId: role.Role.Id, | ||
| 25 | + Type: properties["id"].(string), | ||
| 26 | + } | ||
| 27 | + //TODO 验证装备是否存在 | ||
| 28 | + | ||
| 29 | + role.AddEquip(equip) | ||
| 30 | + return 0 | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +func (gm *GmAction) DelEquip(role *models.RoleModel, properties map[string]interface{}) int { | ||
| 34 | + logger.Debug(properties) | ||
| 35 | + equip := &pb.Equipment{ | ||
| 36 | + Id: role.IncreEquipByKey(1), | ||
| 37 | + RoleId: role.Role.Id, | ||
| 38 | + Type: properties["id"].(string), | ||
| 39 | + } | ||
| 40 | + //TODO 验证装备是否存在 | ||
| 41 | + | ||
| 42 | + role.AddEquip(equip) | ||
| 43 | + return 0 | ||
| 44 | +} |
models/role.go
| @@ -72,10 +72,15 @@ func (m *RoleModel) IncreByKey(key string, detal uint32) uint32 { | @@ -72,10 +72,15 @@ func (m *RoleModel) IncreByKey(key string, detal uint32) uint32 { | ||
| 72 | func (m *RoleModel) IncreHearByKey(detal uint32) string { | 72 | func (m *RoleModel) IncreHearByKey(detal uint32) string { |
| 73 | return fmt.Sprintf("%s%04d", m.Role.Id, m.IncreByKey("hero", detal)) | 73 | return fmt.Sprintf("%s%04d", m.Role.Id, m.IncreByKey("hero", detal)) |
| 74 | } | 74 | } |
| 75 | + | ||
| 75 | func (m *RoleModel) IncreTeamByKey(detal uint32) string { | 76 | func (m *RoleModel) IncreTeamByKey(detal uint32) string { |
| 76 | return fmt.Sprintf("%s%02d", m.Role.Id, m.IncreByKey("team", detal)) | 77 | return fmt.Sprintf("%s%02d", m.Role.Id, m.IncreByKey("team", detal)) |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 80 | +func (m *RoleModel) IncreEquipByKey(detal uint32) string { | ||
| 81 | + return fmt.Sprintf("%s%04d", m.Role.Id, m.IncreByKey("equipment", detal)) | ||
| 82 | +} | ||
| 83 | + | ||
| 79 | func (m *RoleModel) InitRole() { | 84 | func (m *RoleModel) InitRole() { |
| 80 | //init hero | 85 | //init hero |
| 81 | h1 := pb.Hero{ | 86 | h1 := pb.Hero{ |
| @@ -252,6 +257,12 @@ func (m *RoleModel) UpdateTeam(teams []*pb.Team) { | @@ -252,6 +257,12 @@ func (m *RoleModel) UpdateTeam(teams []*pb.Team) { | ||
| 252 | } | 257 | } |
| 253 | } | 258 | } |
| 254 | 259 | ||
| 260 | +func (m *RoleModel) AddEquip(equip *pb.Equipment) { | ||
| 261 | + e := NewEquip(equip) | ||
| 262 | + e.Create() | ||
| 263 | + m.Equipments[equip.Id] = e | ||
| 264 | +} | ||
| 265 | + | ||
| 255 | func (m *RoleModel) OnRecoverTimer(now int64) { | 266 | func (m *RoleModel) OnRecoverTimer(now int64) { |
| 256 | m.SaveRoleData(now) | 267 | m.SaveRoleData(now) |
| 257 | } | 268 | } |