添加GM函数执行的返回数据
This commit is contained in:
1 parent
0cbaa27b74
commit
3076e78b9f
13 files changed
+284
-153
No files matched your search
+45
-45
@@ -81,16 +81,16 @@ type GameDataConfig struct {
|
||||
func InitGameDataConfig() {
|
||||
CONF = new(GameDataConfig)
|
||||
startTime := time.Now().Unix()
|
||||
CONF.loadAll()
|
||||
CONF.loadAll(config.GetConfig().Hk4e.LoadSceneLuaConfig)
|
||||
endTime := time.Now().Unix()
|
||||
runtime.GC()
|
||||
logger.Info("load all game data config finish, cost: %v(s)", endTime-startTime)
|
||||
}
|
||||
|
||||
func ReloadGameDataConfig() {
|
||||
func ReloadGameDataConfig(reloadSceneLua bool) {
|
||||
CONF_RELOAD = new(GameDataConfig)
|
||||
startTime := time.Now().Unix()
|
||||
CONF_RELOAD.loadAll()
|
||||
CONF_RELOAD.loadAll(reloadSceneLua)
|
||||
endTime := time.Now().Unix()
|
||||
runtime.GC()
|
||||
logger.Info("reload all game data config finish, cost: %v(s)", endTime-startTime)
|
||||
@@ -100,7 +100,7 @@ func ReplaceGameDataConfig() {
|
||||
CONF = CONF_RELOAD
|
||||
}
|
||||
|
||||
func (g *GameDataConfig) loadAll() {
|
||||
func (g *GameDataConfig) loadAll(loadSceneLua bool) {
|
||||
pathPrefix := config.GetConfig().Hk4e.GameDataConfigPath
|
||||
|
||||
dirInfo, err := os.Stat(pathPrefix)
|
||||
@@ -141,49 +141,49 @@ func (g *GameDataConfig) loadAll() {
|
||||
}
|
||||
g.extPrefix += "/"
|
||||
|
||||
g.load()
|
||||
g.load(loadSceneLua)
|
||||
}
|
||||
|
||||
func (g *GameDataConfig) load() {
|
||||
g.loadSceneData() // 场景
|
||||
g.loadSceneLuaConfig() // 场景LUA配置
|
||||
g.loadTriggerData() // 场景LUA触发器
|
||||
g.loadScenePoint() // 场景传送点
|
||||
g.loadSceneTagData() // 场景标签
|
||||
g.loadGatherData() // 采集物
|
||||
g.loadWorldAreaData() // 世界区域
|
||||
g.loadAvatarData() // 角色
|
||||
g.loadAvatarSkillData() // 角色技能
|
||||
g.loadAvatarSkillDepotData() // 角色技能库
|
||||
g.loadFetterData() // 角色资料解锁
|
||||
g.loadItemData() // 统一道具
|
||||
g.loadAvatarLevelData() // 角色等级
|
||||
g.loadAvatarPromoteData() // 角色突破
|
||||
g.loadPlayerLevelData() // 玩家等级
|
||||
g.loadWeaponLevelData() // 武器等级
|
||||
g.loadWeaponPromoteData() // 武器突破
|
||||
g.loadRewardData() // 奖励
|
||||
g.loadAvatarCostumeData() // 角色时装
|
||||
g.loadAvatarFlycloakData() // 角色风之翼
|
||||
g.loadReliquaryMainData() // 圣遗物主属性
|
||||
g.loadReliquaryAffixData() // 圣遗物追加属性
|
||||
g.loadQuestData() // 任务
|
||||
g.loadDropData() // 掉落
|
||||
g.loadMonsterDropData() // 怪物掉落
|
||||
g.loadChestDropData() // 宝箱掉落
|
||||
g.loadDungeonData() // 地牢
|
||||
g.loadGadgetData() // 物件
|
||||
g.loadRefreshPolicyData() // 刷新策略
|
||||
g.loadGCGCharData() // 七圣召唤角色卡牌
|
||||
g.loadGCGSkillData() // 七圣召唤卡牌技能
|
||||
g.loadGachaDropGroupData() // 卡池掉落组 临时的
|
||||
g.loadSkillStaminaData() // 角色技能消耗体力 临时的
|
||||
g.loadVehicleData() // 载具
|
||||
g.loadOpenStateData() // 开放状态
|
||||
g.loadWeatherData() // 天气
|
||||
g.loadWeatherTemplateData() // 天气模版
|
||||
g.loadSceneWeatherArea() // 天气区域
|
||||
g.loadPubgWorldGadgetData() // pubg世界物件
|
||||
func (g *GameDataConfig) load(loadSceneLua bool) {
|
||||
g.loadSceneData() // 场景
|
||||
g.loadSceneLuaConfig(loadSceneLua) // 场景LUA配置
|
||||
g.loadTriggerData() // 场景LUA触发器
|
||||
g.loadScenePoint() // 场景传送点
|
||||
g.loadSceneTagData() // 场景标签
|
||||
g.loadGatherData() // 采集物
|
||||
g.loadWorldAreaData() // 世界区域
|
||||
g.loadAvatarData() // 角色
|
||||
g.loadAvatarSkillData() // 角色技能
|
||||
g.loadAvatarSkillDepotData() // 角色技能库
|
||||
g.loadFetterData() // 角色资料解锁
|
||||
g.loadItemData() // 统一道具
|
||||
g.loadAvatarLevelData() // 角色等级
|
||||
g.loadAvatarPromoteData() // 角色突破
|
||||
g.loadPlayerLevelData() // 玩家等级
|
||||
g.loadWeaponLevelData() // 武器等级
|
||||
g.loadWeaponPromoteData() // 武器突破
|
||||
g.loadRewardData() // 奖励
|
||||
g.loadAvatarCostumeData() // 角色时装
|
||||
g.loadAvatarFlycloakData() // 角色风之翼
|
||||
g.loadReliquaryMainData() // 圣遗物主属性
|
||||
g.loadReliquaryAffixData() // 圣遗物追加属性
|
||||
g.loadQuestData() // 任务
|
||||
g.loadDropData() // 掉落
|
||||
g.loadMonsterDropData() // 怪物掉落
|
||||
g.loadChestDropData() // 宝箱掉落
|
||||
g.loadDungeonData() // 地牢
|
||||
g.loadGadgetData() // 物件
|
||||
g.loadRefreshPolicyData() // 刷新策略
|
||||
g.loadGCGCharData() // 七圣召唤角色卡牌
|
||||
g.loadGCGSkillData() // 七圣召唤卡牌技能
|
||||
g.loadGachaDropGroupData() // 卡池掉落组 临时的
|
||||
g.loadSkillStaminaData() // 角色技能消耗体力 临时的
|
||||
g.loadVehicleData() // 载具
|
||||
g.loadOpenStateData() // 开放状态
|
||||
g.loadWeatherData() // 天气
|
||||
g.loadWeatherTemplateData() // 天气模版
|
||||
g.loadSceneWeatherArea() // 天气区域
|
||||
g.loadPubgWorldGadgetData() // pubg世界物件
|
||||
}
|
||||
|
||||
// CSV相关
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/pkg/logger"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
@@ -306,11 +305,11 @@ func (g *GameDataConfig) loadGroup(group *Group, block *Block, sceneId int32, bl
|
||||
block.groupMapLoadLock.Unlock()
|
||||
}
|
||||
|
||||
func (g *GameDataConfig) loadSceneLuaConfig() {
|
||||
func (g *GameDataConfig) loadSceneLuaConfig(loadSceneLua bool) {
|
||||
g.SceneLuaConfigMap = make(map[int32]*SceneLuaConfig)
|
||||
g.GroupMap = make(map[int32]*Group)
|
||||
g.LuaStateLruMap = make(map[int32]*LuaStateLru)
|
||||
if !config.GetConfig().Hk4e.LoadSceneLuaConfig {
|
||||
if !loadSceneLua {
|
||||
return
|
||||
}
|
||||
sceneLuaPrefix := g.luaPrefix + "scene/"
|
||||
|
||||
@@ -18,17 +18,23 @@ type GmCmdReq struct {
|
||||
GsAppid string `json:"gs_appid"`
|
||||
}
|
||||
|
||||
type GmCmdRsp struct {
|
||||
ResultCode int32 `json:"result_code"`
|
||||
ResultMsg string `json:"result_msg"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
func (c *Controller) gmCmd(ctx *gin.Context) {
|
||||
gmCmdReq := new(GmCmdReq)
|
||||
err := ctx.ShouldBindJSON(gmCmdReq)
|
||||
if err != nil {
|
||||
logger.Error("parse json error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "参数解析错误", Data: err})
|
||||
return
|
||||
}
|
||||
logger.Info("GmCmdReq: %v", gmCmdReq)
|
||||
if gmCmdReq.GsId != 0 {
|
||||
// 指定gsid
|
||||
// 指定GSID执行
|
||||
c.gmClientMapLock.RLock()
|
||||
gmClient, exist := c.gmClientMap[gmCmdReq.GsId]
|
||||
c.gmClientMapLock.RUnlock()
|
||||
@@ -37,7 +43,7 @@ func (c *Controller) gmCmd(ctx *gin.Context) {
|
||||
gmClient, err = rpc.NewGMClient(gmCmdReq.GsId)
|
||||
if err != nil {
|
||||
logger.Error("new gm client error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
c.gmClientMapLock.Lock()
|
||||
@@ -49,12 +55,12 @@ func (c *Controller) gmCmd(ctx *gin.Context) {
|
||||
ParamList: gmCmdReq.ParamList,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, rsp)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: &GmCmdRsp{ResultCode: rsp.Code, ResultMsg: rsp.Message, Desc: "指定GSID执行"}})
|
||||
} else if gmCmdReq.GsAppid != "" {
|
||||
// 指定gsappid
|
||||
// 指定GSAPPID执行
|
||||
c.messageQueue.SendToGs(gmCmdReq.GsAppid, &mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerGmCmdNotify,
|
||||
@@ -63,9 +69,9 @@ func (c *Controller) gmCmd(ctx *gin.Context) {
|
||||
GmCmdParamList: gmCmdReq.ParamList,
|
||||
},
|
||||
})
|
||||
ctx.JSON(http.StatusOK, nil)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: &GmCmdRsp{ResultCode: 0, ResultMsg: "", Desc: "指定GSAPPID执行"}})
|
||||
} else {
|
||||
// 全服
|
||||
// 全服GS执行
|
||||
c.messageQueue.SendToAll(&mq.NetMsg{
|
||||
MsgType: mq.MsgTypeServer,
|
||||
EventId: mq.ServerGmCmdNotify,
|
||||
@@ -74,6 +80,6 @@ func (c *Controller) gmCmd(ctx *gin.Context) {
|
||||
GmCmdParamList: gmCmdReq.ParamList,
|
||||
},
|
||||
})
|
||||
ctx.JSON(http.StatusOK, nil)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: &GmCmdRsp{ResultCode: 0, ResultMsg: "", Desc: "全服GS执行"}})
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ func (c *Controller) serverStopState(ctx *gin.Context) {
|
||||
stopServerInfo, err := c.discoveryClient.GetStopServerInfo(ctx.Request.Context(), &api.NullMsg{})
|
||||
if err != nil {
|
||||
logger.Error("get stop server info error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: stopServerInfo})
|
||||
@@ -29,7 +29,7 @@ func (c *Controller) serverStopChange(ctx *gin.Context) {
|
||||
req := new(ServerStopChangeReq)
|
||||
err := ctx.ShouldBindJSON(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "参数解析错误", Data: err})
|
||||
return
|
||||
}
|
||||
_, err = c.discoveryClient.SetStopServerInfo(ctx.Request.Context(), &api.StopServerInfo{
|
||||
@@ -39,7 +39,7 @@ func (c *Controller) serverStopChange(ctx *gin.Context) {
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("set stop server info error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: nil})
|
||||
@@ -49,7 +49,7 @@ func (c *Controller) serverWhiteList(ctx *gin.Context) {
|
||||
whiteList, err := c.discoveryClient.GetWhiteList(ctx.Request.Context(), &api.NullMsg{})
|
||||
if err != nil {
|
||||
logger.Error("get white list error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: whiteList.IpAddrList})
|
||||
@@ -63,7 +63,7 @@ func (c *Controller) serverWhiteAdd(ctx *gin.Context) {
|
||||
req := new(ServerWhiteAdd)
|
||||
err := ctx.ShouldBindJSON(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "参数解析错误", Data: err})
|
||||
return
|
||||
}
|
||||
_, err = c.discoveryClient.SetWhiteList(ctx.Request.Context(), &api.SetWhiteListReq{
|
||||
@@ -72,7 +72,7 @@ func (c *Controller) serverWhiteAdd(ctx *gin.Context) {
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("set white list error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: nil})
|
||||
@@ -86,7 +86,7 @@ func (c *Controller) serverWhiteDel(ctx *gin.Context) {
|
||||
req := new(ServerWhiteDel)
|
||||
err := ctx.ShouldBindJSON(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "参数解析错误", Data: err})
|
||||
return
|
||||
}
|
||||
_, err = c.discoveryClient.SetWhiteList(ctx.Request.Context(), &api.SetWhiteListReq{
|
||||
@@ -95,7 +95,7 @@ func (c *Controller) serverWhiteDel(ctx *gin.Context) {
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("set white list error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: nil})
|
||||
@@ -109,7 +109,7 @@ func (c *Controller) serverDispatchCancel(ctx *gin.Context) {
|
||||
req := new(ServerDispatchCancel)
|
||||
err := ctx.ShouldBindJSON(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "参数解析错误", Data: err})
|
||||
return
|
||||
}
|
||||
_, err = c.discoveryClient.ServerDispatchCancel(ctx.Request.Context(), &api.ServerDispatchCancelReq{
|
||||
@@ -117,7 +117,7 @@ func (c *Controller) serverDispatchCancel(ctx *gin.Context) {
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("server dispatch cancel error: %v", err)
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "", Data: err})
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: -1, Msg: "服务器内部错误", Data: err})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &CommonRsp{Code: 0, Msg: "", Data: nil})
|
||||
|
||||
+14
-20
@@ -1,7 +1,7 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/jpeg"
|
||||
@@ -29,8 +29,9 @@ func init() {
|
||||
AUDIO_CHAN = make(chan uint32, 1000)
|
||||
}
|
||||
|
||||
func PlayAudio() {
|
||||
audio, err := smf.ReadFile("./audio.mid")
|
||||
func PlayAudio(fileData []byte) {
|
||||
reader := bytes.NewReader(fileData)
|
||||
audio, err := smf.ReadFrom(reader)
|
||||
if err != nil {
|
||||
logger.Error("read midi file error: %v", err)
|
||||
return
|
||||
@@ -104,11 +105,6 @@ const (
|
||||
)
|
||||
const GADGET_ID = 70590015
|
||||
|
||||
var BASE_POS = &model.Vector{
|
||||
X: 2700,
|
||||
Y: 200,
|
||||
Z: -1800,
|
||||
}
|
||||
var SCREEN_ENTITY_ID_LIST []uint32
|
||||
var FRAME_COLOR [][]int
|
||||
var FRAME [][]bool
|
||||
@@ -239,10 +235,11 @@ func WriteJpgFile(fileName string, jpg image.Image) {
|
||||
}
|
||||
}
|
||||
|
||||
func LoadFrameFile() error {
|
||||
frameImg := ReadJpgFile("./frame.jpg")
|
||||
if frameImg == nil {
|
||||
return errors.New("file not exist")
|
||||
func LoadFrameFile(fileData []byte) error {
|
||||
reader := bytes.NewReader(fileData)
|
||||
frameImg, err := jpeg.Decode(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
FRAME = make([][]bool, SCREEN_WIDTH)
|
||||
for w := 0; w < SCREEN_WIDTH; w++ {
|
||||
@@ -263,7 +260,6 @@ func LoadFrameFile() error {
|
||||
grayAvg += uint64(gray)
|
||||
}
|
||||
}
|
||||
WriteJpgFile("./frame_gray.jpg", grayImg)
|
||||
grayAvg /= SCREEN_WIDTH * SCREEN_HEIGHT
|
||||
rgbImg := image.NewRGBA(image.Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
binImg := image.NewRGBA(image.Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
@@ -291,13 +287,11 @@ func LoadFrameFile() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
WriteJpgFile("./frame_rgb.jpg", rgbImg)
|
||||
WriteJpgFile("./frame_bin.jpg", binImg)
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateFrame(rgb bool) {
|
||||
err := LoadFrameFile()
|
||||
func UpdateFrame(fileData []byte, basePos *model.Vector, rgb bool) {
|
||||
err := LoadFrameFile(fileData)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -309,9 +303,9 @@ func UpdateFrame(rgb bool) {
|
||||
GAME.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_REMOVE, SCREEN_ENTITY_ID_LIST)
|
||||
SCREEN_ENTITY_ID_LIST = make([]uint32, 0)
|
||||
leftTopPos := &model.Vector{
|
||||
X: BASE_POS.X + float64(SCREEN_WIDTH)*SCREEN_DPI/2,
|
||||
Y: BASE_POS.Y + float64(SCREEN_HEIGHT)*SCREEN_DPI,
|
||||
Z: BASE_POS.Z,
|
||||
X: basePos.X + float64(SCREEN_WIDTH)*SCREEN_DPI/2,
|
||||
Y: basePos.Y + float64(SCREEN_HEIGHT)*SCREEN_DPI,
|
||||
Z: basePos.Z,
|
||||
}
|
||||
for w := 0; w < SCREEN_WIDTH; w++ {
|
||||
for h := 0; h < SCREEN_HEIGHT; h++ {
|
||||
|
||||
+104
-23
@@ -432,8 +432,54 @@ func (g *GMCmd) GMCreateGadget(userId uint32, gadgetId uint32, count uint32) {
|
||||
}
|
||||
}
|
||||
|
||||
// GMClearPlayer 清除账号数据
|
||||
func (g *GMCmd) GMClearPlayer(userId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.OfflineClear = true
|
||||
GAME.LogoutPlayer(userId)
|
||||
}
|
||||
|
||||
// GMClearItem 清除道具
|
||||
func (g *GMCmd) GMClearItem(userId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.DbItem = nil
|
||||
GAME.LogoutPlayer(userId)
|
||||
}
|
||||
|
||||
// GMClearQuest 清除任务
|
||||
func (g *GMCmd) GMClearQuest(userId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.DbQuest = nil
|
||||
GAME.LogoutPlayer(userId)
|
||||
}
|
||||
|
||||
// GMClearWorld 清除大世界数据
|
||||
func (g *GMCmd) GMClearWorld(userId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.DbWorld = nil
|
||||
GAME.LogoutPlayer(userId)
|
||||
}
|
||||
|
||||
// 系统级GM指令
|
||||
|
||||
// TODO 不知道为什么0个参数的函数会反射调用失败
|
||||
|
||||
func (g *GMCmd) ChangePlayerCmdPerm(userId uint32, cmdPerm uint8) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
@@ -443,10 +489,10 @@ func (g *GMCmd) ChangePlayerCmdPerm(userId uint32, cmdPerm uint8) {
|
||||
player.CmdPerm = cmdPerm
|
||||
}
|
||||
|
||||
func (g *GMCmd) ReloadGameDataConfig(v bool) {
|
||||
// TODO 不知道为什么0个参数的函数会反射调用失败
|
||||
func (g *GMCmd) ReloadGameDataConfig(reloadSceneLua bool) {
|
||||
LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{
|
||||
EventId: ReloadGameDataConfig,
|
||||
Msg: reloadSceneLua,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,20 +521,31 @@ func (g *GMCmd) XLuaDebug(userId uint32, luacBase64 string) {
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GMCmd) PlayAudio(v bool) {
|
||||
go PlayAudio()
|
||||
func (g *GMCmd) AvPlayAudio(fileDataBase64 string) {
|
||||
fileData, err := base64.StdEncoding.DecodeString(fileDataBase64)
|
||||
if err != nil {
|
||||
logger.Error("file data base64 format error: %v", err)
|
||||
return
|
||||
}
|
||||
go PlayAudio(fileData)
|
||||
}
|
||||
|
||||
func (g *GMCmd) UpdateFrame(rgb bool) {
|
||||
UpdateFrame(rgb)
|
||||
func (g *GMCmd) AvUpdateFrame(fileDataBase64 string, rgb bool, posX, posY, posZ float64) {
|
||||
fileData, err := base64.StdEncoding.DecodeString(fileDataBase64)
|
||||
if err != nil {
|
||||
logger.Error("file data base64 format error: %v", err)
|
||||
return
|
||||
}
|
||||
basePos := &model.Vector{X: posX, Y: posY, Z: posZ}
|
||||
if basePos.X == 0.0 && basePos.Y == 0.0 && basePos.Z == 0.0 {
|
||||
basePos = &model.Vector{X: 2700, Y: 200, Z: -1800}
|
||||
}
|
||||
UpdateFrame(fileData, basePos, rgb)
|
||||
}
|
||||
|
||||
var RobotUidCounter uint32 = 0
|
||||
|
||||
func (g *GMCmd) CreateRobotInAiWorld(uid uint32, name string, avatarId uint32) {
|
||||
func (g *GMCmd) CreateRobotInAiWorld(uid uint32, name string, avatarId uint32, posX, posY, posZ float64) {
|
||||
if uid == 0 {
|
||||
RobotUidCounter++
|
||||
uid = 1000000 + RobotUidCounter
|
||||
return
|
||||
}
|
||||
if name == "" {
|
||||
name = random.GetRandomStr(8)
|
||||
@@ -527,20 +584,11 @@ func (g *GMCmd) CreateRobotInAiWorld(uid uint32, name string, avatarId uint32) {
|
||||
EnterSceneToken: aiWorld.GetEnterSceneToken(),
|
||||
})
|
||||
activeAvatarId := aiWorld.GetPlayerActiveAvatarId(robot)
|
||||
pos := new(model.Vector)
|
||||
rot := new(model.Vector)
|
||||
for _, targetPlayer := range aiWorld.GetAllPlayer() {
|
||||
if targetPlayer.PlayerId < PlayerBaseUid {
|
||||
continue
|
||||
}
|
||||
pos = &model.Vector{X: targetPlayer.Pos.X, Y: targetPlayer.Pos.Y, Z: targetPlayer.Pos.Z}
|
||||
rot = &model.Vector{X: targetPlayer.Rot.X, Y: targetPlayer.Rot.Y, Z: targetPlayer.Rot.Z}
|
||||
}
|
||||
entityMoveInfo := &proto.EntityMoveInfo{
|
||||
EntityId: aiWorld.GetPlayerWorldAvatarEntityId(robot, activeAvatarId),
|
||||
MotionInfo: &proto.MotionInfo{
|
||||
Pos: &proto.Vector{X: float32(pos.X), Y: float32(pos.Y), Z: float32(pos.Z)},
|
||||
Rot: &proto.Vector{X: float32(rot.X), Y: float32(rot.Y), Z: float32(rot.Z)},
|
||||
Pos: &proto.Vector{X: float32(posX), Y: float32(posY), Z: float32(posZ)},
|
||||
Rot: &proto.Vector{X: float32(0.0), Y: float32(0.0), Z: float32(0.0)},
|
||||
State: proto.MotionState_MOTION_STANDBY,
|
||||
},
|
||||
SceneTime: 0,
|
||||
@@ -627,6 +675,7 @@ func (g *GMCmd) AiWorldAoiDebug(v bool) {
|
||||
if aiWorld == nil {
|
||||
return
|
||||
}
|
||||
scene := aiWorld.GetSceneById(aiWorld.GetOwner().SceneId)
|
||||
aiWorldAoi := aiWorld.GetAiWorldAoi()
|
||||
gridMap := aiWorldAoi.Debug()
|
||||
logger.Debug("total grid num: %v", len(gridMap))
|
||||
@@ -638,7 +687,39 @@ func (g *GMCmd) AiWorldAoiDebug(v bool) {
|
||||
logger.Debug("================================================== GRID gid:%v ==================================================", grid.GetGid())
|
||||
for objectId, object := range objectMap {
|
||||
wa := object.(*WorldAvatar)
|
||||
logger.Debug("uid: %v, wa.uid: %v, wa.avatarId: %v, wa.entityId: %v", objectId, wa.uid, wa.avatarId, wa.avatarEntityId)
|
||||
var pos *model.Vector = nil
|
||||
entity := scene.GetEntity(wa.avatarEntityId)
|
||||
if entity != nil {
|
||||
pos = entity.GetPos()
|
||||
}
|
||||
logger.Debug("uid: %v, wa.uid: %v, wa.avatarId: %v, wa.entityId: %v, pos: %+v", objectId, wa.uid, wa.avatarId, wa.avatarEntityId, pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GMCmd) GetPlayerData(userId uint32) *model.Player {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return nil
|
||||
}
|
||||
return player
|
||||
}
|
||||
|
||||
func (g *GMCmd) GetPlayerPos(userId uint32) *model.Vector {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return nil
|
||||
}
|
||||
return player.Pos
|
||||
}
|
||||
|
||||
func (g *GMCmd) NotSavePlayer(userId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.OfflineNotSave = true
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -38,8 +39,14 @@ type CommandMessage struct {
|
||||
Executor *model.Player // 执行者
|
||||
Text string // 命令文本
|
||||
// 系统函数GM
|
||||
FuncName string // 函数名
|
||||
ParamList []string // 函数参数列表
|
||||
FuncName string // 函数名
|
||||
ParamList []string // 函数参数列表
|
||||
ResultChan chan *GMCmdResult // 执行结果返回管道
|
||||
}
|
||||
|
||||
type GMCmdResult struct {
|
||||
Code int32
|
||||
Msg string
|
||||
}
|
||||
|
||||
// CommandContentStepFunc 命令步骤处理函数
|
||||
@@ -365,15 +372,15 @@ func (c *CommandManager) PlayerInputCommand(player *model.Player, targetUid uint
|
||||
}
|
||||
|
||||
// CallGMCmd 调用GM命令
|
||||
func (c *CommandManager) CallGMCmd(funcName string, paramList []string) bool {
|
||||
func (c *CommandManager) CallGMCmd(funcName string, paramList []string) (bool, string) {
|
||||
fn := c.gmCmdRefValue.MethodByName(funcName)
|
||||
if !fn.IsValid() {
|
||||
logger.Error("gm func not valid, func: %v", funcName)
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
if fn.Type().NumIn() != len(paramList) {
|
||||
logger.Error("gm func param num not match, func: %v, need: %v, give: %v", funcName, fn.Type().NumIn(), len(paramList))
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
in := make([]reflect.Value, fn.Type().NumIn())
|
||||
for i := 0; i < fn.Type().NumIn(); i++ {
|
||||
@@ -384,103 +391,118 @@ func (c *CommandManager) CallGMCmd(funcName string, paramList []string) bool {
|
||||
case reflect.Int:
|
||||
val, err := strconv.ParseInt(param, 10, 64)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(int(val))
|
||||
case reflect.Uint:
|
||||
val, err := strconv.ParseUint(param, 10, 64)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(uint(val))
|
||||
case reflect.Int8:
|
||||
val, err := strconv.ParseInt(param, 10, 8)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(int8(val))
|
||||
case reflect.Uint8:
|
||||
val, err := strconv.ParseUint(param, 10, 8)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(uint8(val))
|
||||
case reflect.Int16:
|
||||
val, err := strconv.ParseInt(param, 10, 16)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(int16(val))
|
||||
case reflect.Uint16:
|
||||
val, err := strconv.ParseUint(param, 10, 16)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(uint16(val))
|
||||
case reflect.Int32:
|
||||
val, err := strconv.ParseInt(param, 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(int32(val))
|
||||
case reflect.Uint32:
|
||||
val, err := strconv.ParseUint(param, 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(uint32(val))
|
||||
case reflect.Int64:
|
||||
val, err := strconv.ParseInt(param, 10, 64)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(val)
|
||||
case reflect.Uint64:
|
||||
val, err := strconv.ParseUint(param, 10, 64)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(val)
|
||||
case reflect.Float32:
|
||||
val, err := strconv.ParseFloat(param, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(float32(val))
|
||||
case reflect.Float64:
|
||||
val, err := strconv.ParseFloat(param, 64)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(val)
|
||||
case reflect.Bool:
|
||||
val, err := strconv.ParseBool(param)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
value = reflect.ValueOf(val)
|
||||
case reflect.String:
|
||||
value = reflect.ValueOf(param)
|
||||
default:
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
in[i] = value
|
||||
}
|
||||
fn.Call(in)
|
||||
return true
|
||||
out := fn.Call(in)
|
||||
ret := make([]any, 0)
|
||||
for _, v := range out {
|
||||
ret = append(ret, v.Interface())
|
||||
}
|
||||
data, _ := json.Marshal(ret)
|
||||
return true, string(data)
|
||||
}
|
||||
|
||||
// HandleCommand 处理命令
|
||||
// 主协程接收到命令消息后执行
|
||||
func (c *CommandManager) HandleCommand(cmd *CommandMessage) {
|
||||
switch cmd.GMType {
|
||||
func (c *CommandManager) HandleCommand(command *CommandMessage) {
|
||||
switch command.GMType {
|
||||
case PlayerChatGM, DevClientGM:
|
||||
// 执行命令
|
||||
c.ExecCommand(cmd)
|
||||
c.ExecCommand(command)
|
||||
case SystemFuncGM:
|
||||
logger.Info("run gm cmd, FuncName: %v, ParamList: %v", cmd.FuncName, cmd.ParamList)
|
||||
// 反射调用command_gm.go中的函数并反射解析传入参数类型
|
||||
c.CallGMCmd(cmd.FuncName, cmd.ParamList)
|
||||
logger.Info("run gm cmd, FuncName: %v, ParamList: %v", command.FuncName, command.ParamList)
|
||||
// 反射调用game_command_gm.go中的函数并反射解析传入参数类型
|
||||
ok, ret := c.CallGMCmd(command.FuncName, command.ParamList)
|
||||
if command.ResultChan != nil {
|
||||
var gmCmdResult *GMCmdResult = nil
|
||||
if ok {
|
||||
gmCmdResult = &GMCmdResult{Code: 0, Msg: ret}
|
||||
} else {
|
||||
gmCmdResult = &GMCmdResult{Code: -1, Msg: ""}
|
||||
}
|
||||
command.ResultChan <- gmCmdResult
|
||||
close(command.ResultChan)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,13 +186,14 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
|
||||
playerOfflineInfo.Player.PlayerId, playerOfflineInfo.Player.GateAppId, gsAppId, playerOfflineInfo.ChangeGsInfo.JoinHostUserId)
|
||||
}
|
||||
case ReloadGameDataConfig:
|
||||
reloadSceneLua := localEvent.Msg.(bool)
|
||||
go func() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logger.Error("reload game data config error: %v", err)
|
||||
}
|
||||
}()
|
||||
gdconf.ReloadGameDataConfig()
|
||||
gdconf.ReloadGameDataConfig(reloadSceneLua)
|
||||
LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{
|
||||
EventId: ReloadGameDataConfigFinish,
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ func (p *PluginPubg) UserTimerPubgEnd(player *model.Player, data []any) {
|
||||
roomNumber := GAME.GetGsId() - 1
|
||||
startMinute := roomNumber % 6 * 10
|
||||
info := fmt.Sprintf("下一次游戏开启时间:%02d:%02d。", time.Now().Add(time.Hour).Hour(), startMinute)
|
||||
GAME.PlayerChatReq(p.world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
GAME.PlayerChatReq(player, &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
}
|
||||
|
||||
// UserTimerPubgUpdateArea 更新游戏区域
|
||||
@@ -347,6 +347,8 @@ func (p *PluginPubg) StartPubg() {
|
||||
logger.Debug("StartPubg, seq: %v", p.seq)
|
||||
world := WORLD_MANAGER.GetAiWorld()
|
||||
p.world = world
|
||||
info := "游戏开始。"
|
||||
GAME.PlayerChatReq(p.world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
for _, pubgWorldGadgetDataConfig := range gdconf.GetPubgWorldGadgetDataMap() {
|
||||
rn := random.GetRandomInt32(1, 100)
|
||||
if rn > pubgWorldGadgetDataConfig.Probability {
|
||||
@@ -380,8 +382,6 @@ func (p *PluginPubg) StartPubg() {
|
||||
})
|
||||
p.playerHitTimeMap[player.PlayerId] = 0
|
||||
}
|
||||
info := "游戏开始。"
|
||||
GAME.PlayerChatReq(p.world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
}
|
||||
|
||||
// StopPubg 结束pubg游戏
|
||||
@@ -390,7 +390,7 @@ func (p *PluginPubg) StopPubg() {
|
||||
return
|
||||
}
|
||||
logger.Debug("StopPubg, seq: %v", p.seq)
|
||||
world := p.world
|
||||
owner := p.world.GetOwner()
|
||||
p.world = nil
|
||||
p.blueAreaCenterPos = &model.Vector{X: 0.0, Y: 0.0, Z: 0.0}
|
||||
p.blueAreaRadius = 0.0
|
||||
@@ -403,9 +403,9 @@ func (p *PluginPubg) StopPubg() {
|
||||
p.areaPointList = make([]*proto.MapMarkPoint, 0)
|
||||
p.entityIdWorldGadgetIdMap = make(map[uint32]int32)
|
||||
p.playerHitTimeMap = make(map[uint32]int64)
|
||||
p.CreateUserTimer(world.GetOwner().PlayerId, 60, p.UserTimerPubgEnd)
|
||||
p.CreateUserTimer(owner.PlayerId, 60, p.UserTimerPubgEnd)
|
||||
info := "游戏结束。"
|
||||
GAME.PlayerChatReq(p.world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
GAME.PlayerChatReq(owner, &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
}
|
||||
|
||||
// IsStartPubg pubg游戏是否开启
|
||||
|
||||
@@ -215,9 +215,10 @@ func (r *RouteManager) RouteHandle(netMsg *mq.NetMsg) {
|
||||
case mq.ServerGmCmdNotify:
|
||||
commandTextInput := COMMAND_MANAGER.GetCommandMessageInput()
|
||||
commandTextInput <- &CommandMessage{
|
||||
GMType: SystemFuncGM,
|
||||
FuncName: serverMsg.GmCmdFuncName,
|
||||
ParamList: serverMsg.GmCmdParamList,
|
||||
GMType: SystemFuncGM,
|
||||
FuncName: serverMsg.GmCmdFuncName,
|
||||
ParamList: serverMsg.GmCmdParamList,
|
||||
ResultChan: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +174,21 @@ type PlayerOfflineInfo struct {
|
||||
|
||||
// OfflineUser 玩家离线
|
||||
func (u *UserManager) OfflineUser(player *model.Player, changeGsInfo *ChangeGsInfo) {
|
||||
if player.OfflineNotSave {
|
||||
LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{
|
||||
EventId: UserOfflineSaveToDbFinish,
|
||||
Msg: &PlayerOfflineInfo{
|
||||
Player: player,
|
||||
ChangeGsInfo: changeGsInfo,
|
||||
},
|
||||
}
|
||||
return
|
||||
}
|
||||
if player.OfflineClear {
|
||||
newPlayer := GAME.CreatePlayer(player.PlayerId)
|
||||
newPlayer.DbState = player.DbState
|
||||
player = newPlayer
|
||||
}
|
||||
startTime := time.Now().UnixNano()
|
||||
playerData, err := msgpack.Marshal(player)
|
||||
if err != nil {
|
||||
|
||||
@@ -85,6 +85,8 @@ type Player struct {
|
||||
CommandAssignUid uint32 `bson:"-" msgpack:"-"` // 命令指定uid
|
||||
WeatherInfo *WeatherInfo `bson:"-" msgpack:"-"` // 天气信息
|
||||
ClientVersion int `bson:"-" msgpack:"-"` // 玩家在线的客户端版本
|
||||
OfflineClear bool `bson:"-" msgpack:"-"` // 是否离线时清除账号数据
|
||||
OfflineNotSave bool `bson:"-" msgpack:"-"` // 是否离线时不保存账号数据
|
||||
// 特殊数据
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||
}
|
||||
|
||||
+16
-6
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"hk4e/gs/api"
|
||||
"hk4e/gs/game"
|
||||
@@ -15,12 +16,21 @@ type GMService struct {
|
||||
|
||||
func (s *GMService) Cmd(ctx context.Context, req *api.CmdRequest) (*api.CmdReply, error) {
|
||||
commandTextInput := game.COMMAND_MANAGER.GetCommandMessageInput()
|
||||
resultChan := make(chan *game.GMCmdResult)
|
||||
commandTextInput <- &game.CommandMessage{
|
||||
GMType: game.SystemFuncGM,
|
||||
FuncName: req.FuncName,
|
||||
ParamList: req.ParamList,
|
||||
GMType: game.SystemFuncGM,
|
||||
FuncName: req.FuncName,
|
||||
ParamList: req.ParamList,
|
||||
ResultChan: resultChan,
|
||||
}
|
||||
return &api.CmdReply{
|
||||
Message: "OK",
|
||||
}, nil
|
||||
timer := time.NewTimer(time.Second * 10)
|
||||
var cmdReply *api.CmdReply = nil
|
||||
select {
|
||||
case <-timer.C:
|
||||
cmdReply = &api.CmdReply{Code: -1, Message: "执行结果等待超时"}
|
||||
case result := <-resultChan:
|
||||
cmdReply = &api.CmdReply{Code: result.Code, Message: result.Msg}
|
||||
}
|
||||
timer.Stop()
|
||||
return cmdReply, nil
|
||||
}
|
||||
Reference in new issue
Block a user