优化代码

This commit is contained in:
flswld
2023-02-18 22:09:59 +08:00
parent 21fb9d400f
commit e580baeb46
37 changed files with 198 additions and 118 deletions

View File

@@ -1,10 +1,11 @@
package game
import (
"hk4e/gdconf"
"strconv"
"strings"
"hk4e/gdconf"
"hk4e/gs/model"
)

View File

@@ -31,6 +31,8 @@ type CommandMessage struct {
Text string // 命令原始文本
Name string // 命令前缀
Args map[string]string // 命令参数
FuncName string // 函数名
Param []string // 函数参数列表
}
// CommandManager 命令管理器
@@ -129,6 +131,12 @@ func (c *CommandManager) InputCommand(executor any, text string) {
// HandleCommand 处理命令
// 主协程接收到命令消息后执行
func (c *CommandManager) HandleCommand(cmd *CommandMessage) {
if cmd.FuncName != "" {
logger.Info("run gm cmd, FuncName: %v, Param: %v", cmd.FuncName, cmd.Param)
// TODO 反射调用command_gm.go中的函数并反射解析传入参数类型
return
}
executor := cmd.Executor
// 分割出命令的每个参数

View File

@@ -63,7 +63,7 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs
r.dao = dao
MESSAGE_QUEUE = messageQueue
r.snowflake = alg.NewSnowflakeWorker(int64(gsId))
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
r.clientCmdProtoMap = client_proto.NewClientCmdProtoMap()
// 反射调用的方法在启动时测试是否正常防止中途panic
r.GetClientProtoObjByName("PingReq")
@@ -276,7 +276,6 @@ func (g *GameManager) Close() {
},
})
}
time.Sleep(time.Second)
}
// SendMsgToGate 发送消息给客户端 指定网关

View File

@@ -112,7 +112,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
switch entry.ArgumentType {
case proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT:
hitInfo := new(proto.EvtBeingHitInfo)
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
clientProtoObj := g.GetClientProtoObjByName("EvtBeingHitInfo")
if clientProtoObj == nil {
logger.Error("get client proto obj is nil")
@@ -170,7 +170,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
case proto.CombatTypeArgument_ENTITY_MOVE:
entityMoveInfo := new(proto.EntityMoveInfo)
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
clientProtoObj := g.GetClientProtoObjByName("EntityMoveInfo")
if clientProtoObj == nil {
logger.Error("get client proto obj is nil")
@@ -239,7 +239,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
case proto.CombatTypeArgument_COMBAT_ANIMATOR_STATE_CHANGED:
evtAnimatorStateChangedInfo := new(proto.EvtAnimatorStateChangedInfo)
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
clientProtoObj := g.GetClientProtoObjByName("EvtAnimatorStateChangedInfo")
if clientProtoObj == nil {
logger.Error("get client proto obj is nil")
@@ -403,7 +403,7 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
switch abilityInvokeEntry.ArgumentType {
case proto.AbilityInvokeArgument_ABILITY_META_ADD_NEW_ABILITY:
abilityMetaAddAbility := new(proto.AbilityMetaAddAbility)
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
clientProtoObj := g.GetClientProtoObjByName("AbilityMetaAddAbility")
if clientProtoObj == nil {
logger.Error("get client proto obj is nil")
@@ -433,7 +433,7 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
worldAvatar.SetAbilityList(abilityList)
case proto.AbilityInvokeArgument_ABILITY_META_MODIFIER_CHANGE:
abilityMetaModifierChange := new(proto.AbilityMetaModifierChange)
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
clientProtoObj := g.GetClientProtoObjByName("AbilityMetaModifierChange")
if clientProtoObj == nil {
logger.Error("get client proto obj is nil")

View File

@@ -23,7 +23,7 @@ type UserInfo struct {
// 获取卡池信息
func (g *GameManager) GetGachaInfoReq(player *model.Player, payloadMsg pb.Message) {
logger.Debug("user get gacha info, uid: %v", player.PlayerID)
serverAddr := config.CONF.Hk4e.GachaHistoryServer
serverAddr := config.GetConfig().Hk4e.GachaHistoryServer
userInfo := &UserInfo{
UserId: player.PlayerID,
RegisteredClaims: jwt.RegisteredClaims{

View File

@@ -23,7 +23,7 @@ func (g *GameManager) HandleAbilityStamina(player *model.Player, entry *proto.Ab
case proto.AbilityInvokeArgument_ABILITY_MIXIN_COST_STAMINA:
// 大剑重击 或 持续技能 耐力消耗
costStamina := new(proto.AbilityMixinCostStamina)
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
clientProtoObj := g.GetClientProtoObjByName("AbilityMixinCostStamina")
if clientProtoObj == nil {
logger.Error("get client proto obj is nil")