From d6d589a95185fb17efb7b8cac09bc2f9d227c078 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Thu, 5 May 2022 18:55:00 +0800 Subject: [PATCH] feat: 增加装备接口 --- cmd/gameserver/action/GmAction.go | 27 +++++++++++++++++++++++++++ models/role.go | 11 +++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-) diff --git a/cmd/gameserver/action/GmAction.go b/cmd/gameserver/action/GmAction.go index c7e514d..7394ee5 100644 --- a/cmd/gameserver/action/GmAction.go +++ b/cmd/gameserver/action/GmAction.go @@ -3,6 +3,7 @@ package action import ( "pro2d/common/logger" "pro2d/models" + "pro2d/pb" "strconv" ) @@ -15,3 +16,29 @@ func (gm *GmAction) AddExp(role *models.RoleModel, properties map[string]interfa role.IncrPropertyChan("exp", int64(exp)) return 0 } + +func (gm *GmAction) AddEquip(role *models.RoleModel, properties map[string]interface{}) int { + logger.Debug(properties) + equip := &pb.Equipment{ + Id: role.IncreEquipByKey(1), + RoleId: role.Role.Id, + Type: properties["id"].(string), + } + //TODO 验证装备是否存在 + + role.AddEquip(equip) + return 0 +} + +func (gm *GmAction) DelEquip(role *models.RoleModel, properties map[string]interface{}) int { + logger.Debug(properties) + equip := &pb.Equipment{ + Id: role.IncreEquipByKey(1), + RoleId: role.Role.Id, + Type: properties["id"].(string), + } + //TODO 验证装备是否存在 + + role.AddEquip(equip) + return 0 +} diff --git a/models/role.go b/models/role.go index 8daf746..8575251 100644 --- a/models/role.go +++ b/models/role.go @@ -72,10 +72,15 @@ func (m *RoleModel) IncreByKey(key string, detal uint32) uint32 { func (m *RoleModel) IncreHearByKey(detal uint32) string { return fmt.Sprintf("%s%04d", m.Role.Id, m.IncreByKey("hero", detal)) } + func (m *RoleModel) IncreTeamByKey(detal uint32) string { return fmt.Sprintf("%s%02d", m.Role.Id, m.IncreByKey("team", detal)) } +func (m *RoleModel) IncreEquipByKey(detal uint32) string { + return fmt.Sprintf("%s%04d", m.Role.Id, m.IncreByKey("equipment", detal)) +} + func (m *RoleModel) InitRole() { //init hero h1 := pb.Hero{ @@ -252,6 +257,12 @@ func (m *RoleModel) UpdateTeam(teams []*pb.Team) { } } +func (m *RoleModel) AddEquip(equip *pb.Equipment) { + e := NewEquip(equip) + e.Create() + m.Equipments[equip.Id] = e +} + func (m *RoleModel) OnRecoverTimer(now int64) { m.SaveRoleData(now) } -- libgit2 0.21.2