格式化代码

This commit is contained in:
huangxiaolei
2022-12-19 13:40:04 +08:00
parent f773ba8df7
commit 58b2df2bc6
92 changed files with 682 additions and 626 deletions

View File

@@ -2,7 +2,6 @@ package app
import (
"context"
"hk4e/gdconf"
_ "net/http/pprof"
"os"
"os/signal"
@@ -10,6 +9,7 @@ import (
"time"
"hk4e/common/config"
"hk4e/gdconf"
gdc "hk4e/gs/config"
"hk4e/gs/constant"
"hk4e/gs/dao"
@@ -26,7 +26,7 @@ func Run(ctx context.Context, configFile string) error {
config.InitConfig(configFile)
logger.InitLogger("gs")
logger.LOG.Info("gs start")
logger.Warn("gs start")
constant.InitConstant()
@@ -35,7 +35,7 @@ func Run(ctx context.Context, configFile string) error {
conn, err := nats.Connect(config.CONF.MQ.NatsUrl)
if err != nil {
logger.LOG.Error("connect nats error: %v", err)
logger.Error("connect nats error: %v", err)
return err
}
defer conn.Close()
@@ -71,10 +71,10 @@ func Run(ctx context.Context, configFile string) error {
case <-ctx.Done():
return nil
case s := <-c:
logger.LOG.Info("get a signal %s", s.String())
logger.Warn("get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
logger.LOG.Info("gs exit")
logger.Warn("gs exit")
time.Sleep(time.Second)
return nil
case syscall.SIGHUP:

View File

@@ -26,7 +26,7 @@ func (g *GameDataConfig) loadAbilityEmbryos() {
dirPath := g.binPrefix + "Avatar"
fileList, err := os.ReadDir(dirPath)
if err != nil {
logger.LOG.Error("open dir error: %v", err)
logger.Error("open dir error: %v", err)
return
}
embryoList := make([]*AbilityEmbryoEntry, 0)
@@ -38,19 +38,19 @@ func (g *GameDataConfig) loadAbilityEmbryos() {
startIndex := strings.Index(fileName, "ConfigAvatar_")
endIndex := strings.Index(fileName, ".json")
if startIndex == -1 || endIndex == -1 || startIndex+13 > endIndex {
logger.LOG.Error("file name format error: %v", fileName)
logger.Error("file name format error: %v", fileName)
continue
}
avatarName := fileName[startIndex+13 : endIndex]
fileData, err := os.ReadFile(dirPath + "/" + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
avatarConfig := new(AvatarConfig)
err = json.Unmarshal(fileData, avatarConfig)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
if len(avatarConfig.Abilities) == 0 {
@@ -64,11 +64,11 @@ func (g *GameDataConfig) loadAbilityEmbryos() {
embryoList = append(embryoList, abilityEmbryoEntry)
}
if len(embryoList) == 0 {
logger.LOG.Error("no embryo load")
logger.Error("no embryo load")
}
g.AbilityEmbryos = make(map[string]*AbilityEmbryoEntry)
for _, v := range embryoList {
g.AbilityEmbryos[v.Name] = v
}
logger.LOG.Info("load %v AbilityEmbryos", len(g.AbilityEmbryos))
logger.Info("load %v AbilityEmbryos", len(g.AbilityEmbryos))
}

View File

@@ -48,31 +48,31 @@ func (g *GameDataConfig) loadAvatarData() {
for _, fileName := range fileNameList {
fileData, err := os.ReadFile(g.excelBinPrefix + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
list := make([]map[string]any, 0)
err = json.Unmarshal(fileData, &list)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for _, v := range list {
i, err := json.Marshal(v)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
avatarData := new(AvatarData)
err = json.Unmarshal(i, avatarData)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
g.AvatarDataMap[avatarData.Id] = avatarData
}
}
logger.LOG.Info("load %v AvatarData", len(g.AvatarDataMap))
logger.Info("load %v AvatarData", len(g.AvatarDataMap))
for _, v := range g.AvatarDataMap {
split := strings.Split(v.IconName, "_")
if len(split) > 0 {

View File

@@ -35,31 +35,31 @@ func (g *GameDataConfig) loadAvatarSkillData() {
for _, fileName := range fileNameList {
fileData, err := os.ReadFile(g.excelBinPrefix + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
list := make([]map[string]any, 0)
err = json.Unmarshal(fileData, &list)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for _, v := range list {
i, err := json.Marshal(v)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
avatarSkillData := new(AvatarSkillData)
err = json.Unmarshal(i, avatarSkillData)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
g.AvatarSkillDataMap[avatarSkillData.Id] = avatarSkillData
}
}
logger.LOG.Info("load %v AvatarSkillData", len(g.AvatarSkillDataMap))
logger.Info("load %v AvatarSkillData", len(g.AvatarSkillDataMap))
for _, v := range g.AvatarSkillDataMap {
v.CostElemTypeX = constant.ElementTypeConst.STRING_MAP[v.CostElemType]
}

View File

@@ -39,31 +39,31 @@ func (g *GameDataConfig) loadAvatarSkillDepotData() {
for _, fileName := range fileNameList {
fileData, err := os.ReadFile(g.excelBinPrefix + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
list := make([]map[string]any, 0)
err = json.Unmarshal(fileData, &list)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for _, v := range list {
i, err := json.Marshal(v)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
avatarSkillDepotData := new(AvatarSkillDepotData)
err = json.Unmarshal(i, avatarSkillDepotData)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
g.AvatarSkillDepotDataMap[avatarSkillDepotData.Id] = avatarSkillDepotData
}
}
logger.LOG.Info("load %v AvatarSkillDepotData", len(g.AvatarSkillDepotDataMap))
logger.Info("load %v AvatarSkillDepotData", len(g.AvatarSkillDepotDataMap))
for _, v := range g.AvatarSkillDepotDataMap {
// set energy skill data
v.EnergySkillData = g.AvatarSkillDataMap[v.EnergySkill]

View File

@@ -18,31 +18,31 @@ func (g *GameDataConfig) loadFetterData() {
for _, fileName := range fileNameList {
fileData, err := os.ReadFile(g.excelBinPrefix + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
list := make([]map[string]any, 0)
err = json.Unmarshal(fileData, &list)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for _, v := range list {
i, err := json.Marshal(v)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
fetterData := new(FetterData)
err = json.Unmarshal(i, fetterData)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
g.FetterDataMap[fetterData.FetterId] = fetterData
}
}
logger.LOG.Info("load %v FetterData", len(g.FetterDataMap))
logger.Info("load %v FetterData", len(g.FetterDataMap))
g.AvatarFetterDataMap = make(map[int32][]int32)
for _, v := range g.FetterDataMap {
avatarFetterIdList, exist := g.AvatarFetterDataMap[v.AvatarId]

View File

@@ -30,31 +30,31 @@ func (g *GameDataConfig) loadGadgetData() {
for _, fileName := range fileNameList {
fileData, err := os.ReadFile(g.excelBinPrefix + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
list := make([]map[string]any, 0)
err = json.Unmarshal(fileData, &list)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for _, v := range list {
i, err := json.Marshal(v)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
gadgetData := new(GadgetData)
err = json.Unmarshal(i, gadgetData)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
g.GadgetDataMap[gadgetData.Id] = gadgetData
}
}
logger.LOG.Info("load %v GadgetData", len(g.GadgetDataMap))
logger.Info("load %v GadgetData", len(g.GadgetDataMap))
for _, v := range g.GadgetDataMap {
v.TypeX = constant.EntityTypeConst.STRING_MAP[v.Type]
}

View File

@@ -76,19 +76,19 @@ func (g *GameDataConfig) loadAll() {
resourcePath := g.getResourcePathPrefix()
dirInfo, err := os.Stat(resourcePath)
if err != nil || !dirInfo.IsDir() {
logger.LOG.Error("open game data config dir error: %v", err)
logger.Error("open game data config dir error: %v", err)
return
}
g.binPrefix = resourcePath + "/BinOutput"
g.excelBinPrefix = resourcePath + "/ExcelBinOutput"
dirInfo, err = os.Stat(g.binPrefix)
if err != nil || !dirInfo.IsDir() {
logger.LOG.Error("open game data bin output config dir error: %v", err)
logger.Error("open game data bin output config dir error: %v", err)
return
}
dirInfo, err = os.Stat(g.excelBinPrefix)
if err != nil || !dirInfo.IsDir() {
logger.LOG.Error("open game data excel bin output config dir error: %v", err)
logger.Error("open game data excel bin output config dir error: %v", err)
return
}
g.binPrefix += "/"
@@ -100,17 +100,17 @@ func (g *GameDataConfig) ReadWorldTerrain() []byte {
resourcePath := g.getResourcePathPrefix()
dirInfo, err := os.Stat(resourcePath)
if err != nil || !dirInfo.IsDir() {
logger.LOG.Error("open game data config dir error: %v", err)
logger.Error("open game data config dir error: %v", err)
return nil
}
dirInfo, err = os.Stat(resourcePath + "/WorldStatic")
if err != nil || !dirInfo.IsDir() {
logger.LOG.Error("open game data world static dir error: %v", err)
logger.Error("open game data world static dir error: %v", err)
return nil
}
data, err := os.ReadFile(resourcePath + "/WorldStatic/world_terrain.bin")
if err != nil {
logger.LOG.Error("read world terrain file error: %v", err)
logger.Error("read world terrain file error: %v", err)
return nil
}
return data
@@ -120,17 +120,17 @@ func (g *GameDataConfig) WriteWorldTerrain(data []byte) {
resourcePath := g.getResourcePathPrefix()
dirInfo, err := os.Stat(resourcePath)
if err != nil || !dirInfo.IsDir() {
logger.LOG.Error("open game data config dir error: %v", err)
logger.Error("open game data config dir error: %v", err)
return
}
dirInfo, err = os.Stat(resourcePath + "/WorldStatic")
if err != nil || !dirInfo.IsDir() {
logger.LOG.Error("open game data world static dir error: %v", err)
logger.Error("open game data world static dir error: %v", err)
return
}
err = os.WriteFile(resourcePath+"/WorldStatic/world_terrain.bin", data, 0644)
if err != nil {
logger.LOG.Error("write world terrain file error: %v", err)
logger.Error("write world terrain file error: %v", err)
return
}
}

View File

@@ -16,15 +16,15 @@ func (g *GameDataConfig) loadGameDepot() {
playerElementsFilePath := g.binPrefix + "AbilityGroup/AbilityGroup_Other_PlayerElementAbility.json"
playerElementsFile, err := os.ReadFile(playerElementsFilePath)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
return
}
playerAbilities := make(map[string]*AvatarConfig)
err = json.Unmarshal(playerElementsFile, &playerAbilities)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
return
}
g.GameDepot.PlayerAbilities = playerAbilities
logger.LOG.Info("load %v PlayerAbilities", len(g.GameDepot.PlayerAbilities))
logger.Info("load %v PlayerAbilities", len(g.GameDepot.PlayerAbilities))
}

View File

@@ -23,29 +23,29 @@ func (g *GameDataConfig) loadGatherData() {
for _, fileName := range fileNameList {
fileData, err := os.ReadFile(g.excelBinPrefix + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
list := make([]map[string]any, 0)
err = json.Unmarshal(fileData, &list)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for _, v := range list {
i, err := json.Marshal(v)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
gatherData := new(GatherData)
err = json.Unmarshal(i, gatherData)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
g.GatherDataMap[gatherData.Id] = gatherData
}
}
logger.LOG.Info("load %v GatherData", len(g.GatherDataMap))
logger.Info("load %v GatherData", len(g.GatherDataMap))
}

View File

@@ -89,31 +89,31 @@ func (g *GameDataConfig) loadItemData() {
for _, fileName := range fileNameList {
fileData, err := os.ReadFile(g.excelBinPrefix + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
list := make([]map[string]any, 0)
err = json.Unmarshal(fileData, &list)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for _, v := range list {
i, err := json.Marshal(v)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
itemData := new(ItemData)
err = json.Unmarshal(i, itemData)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
g.ItemDataMap[itemData.Id] = itemData
}
}
logger.LOG.Info("load %v ItemData", len(g.ItemDataMap))
logger.Info("load %v ItemData", len(g.ItemDataMap))
for _, itemData := range g.ItemDataMap {
itemData.ItemEnumType = constant.ItemTypeConst.STRING_MAP[itemData.ItemType]

View File

@@ -57,7 +57,7 @@ func (g *GameDataConfig) loadOpenConfig() {
dirPath := g.binPrefix + v
fileList, err := os.ReadDir(dirPath)
if err != nil {
logger.LOG.Error("open dir error: %v", err)
logger.Error("open dir error: %v", err)
return
}
for _, file := range fileList {
@@ -68,12 +68,12 @@ func (g *GameDataConfig) loadOpenConfig() {
config := make(map[string][]*OpenConfigData)
fileData, err := os.ReadFile(dirPath + "/" + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
err = json.Unmarshal(fileData, &config)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
for kk, vv := range config {
@@ -83,11 +83,11 @@ func (g *GameDataConfig) loadOpenConfig() {
}
}
if len(list) == 0 {
logger.LOG.Error("no open config entries load")
logger.Error("no open config entries load")
}
g.OpenConfigEntries = make(map[string]*OpenConfigEntry)
for _, v := range list {
g.OpenConfigEntries[v.Name] = v
}
logger.LOG.Info("load %v OpenConfig", len(g.OpenConfigEntries))
logger.Info("load %v OpenConfig", len(g.OpenConfigEntries))
}

View File

@@ -39,7 +39,7 @@ func (g *GameDataConfig) loadScenePoints() {
dirPath := g.binPrefix + "Scene/Point"
fileList, err := os.ReadDir(dirPath)
if err != nil {
logger.LOG.Error("open dir error: %v", err)
logger.Error("open dir error: %v", err)
return
}
for _, file := range fileList {
@@ -50,19 +50,19 @@ func (g *GameDataConfig) loadScenePoints() {
startIndex := strings.Index(fileName, "scene")
endIndex := strings.Index(fileName, "_point.json")
if startIndex == -1 || endIndex == -1 || startIndex+5 > endIndex {
logger.LOG.Error("file name format error: %v", fileName)
logger.Error("file name format error: %v", fileName)
continue
}
sceneId := fileName[startIndex+5 : endIndex]
fileData, err := os.ReadFile(dirPath + "/" + fileName)
if err != nil {
logger.LOG.Error("open file error: %v", err)
logger.Error("open file error: %v", err)
continue
}
scenePointConfig := new(ScenePointConfig)
err = json.Unmarshal(fileData, scenePointConfig)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
if len(scenePointConfig.Points) == 0 {
@@ -71,7 +71,7 @@ func (g *GameDataConfig) loadScenePoints() {
for k, v := range scenePointConfig.Points {
sceneIdInt32, err := strconv.ParseInt(k, 10, 32)
if err != nil {
logger.LOG.Error("parse file error: %v", err)
logger.Error("parse file error: %v", err)
continue
}
v.Id = int32(sceneIdInt32)
@@ -82,5 +82,5 @@ func (g *GameDataConfig) loadScenePoints() {
g.ScenePointEntries[scenePointEntry.Name] = scenePointEntry
}
}
logger.LOG.Info("load %v ScenePointEntries", len(g.ScenePointEntries))
logger.Info("load %v ScenePointEntries", len(g.ScenePointEntries))
}

View File

@@ -20,7 +20,7 @@ func NewDao() (r *Dao, err error) {
clientOptions := options.Client().ApplyURI(config.CONF.Database.Url)
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
logger.LOG.Error("mongo connect error: %v", err)
logger.Error("mongo connect error: %v", err)
return nil, err
}
r.client = client
@@ -31,6 +31,6 @@ func NewDao() (r *Dao, err error) {
func (d *Dao) CloseDao() {
err := d.client.Disconnect(context.TODO())
if err != nil {
logger.LOG.Error("mongo close error: %v", err)
logger.Error("mongo close error: %v", err)
}
}

View File

@@ -2,9 +2,11 @@ package dao
import (
"context"
"hk4e/gs/model"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"hk4e/gs/model"
)
func (d *Dao) InsertPlayer(player *model.Player) error {

View File

@@ -34,7 +34,7 @@ func NewAoiManager(minX, maxX, numX, minY, maxY, numY, minZ, maxZ, numZ int16) (
r.maxZ = maxZ
r.numZ = numZ
r.gridMap = make(map[uint32]*Grid)
logger.LOG.Info("start init aoi area grid, num: %v", uint32(numX)*uint32(numY)*uint32(numZ))
logger.Info("start init aoi area grid, num: %v", uint32(numX)*uint32(numY)*uint32(numZ))
// 初始化aoi区域中所有的格子
for x := int16(0); x < numX; x++ {
for y := int16(0); y < numY; y++ {
@@ -55,7 +55,7 @@ func NewAoiManager(minX, maxX, numX, minY, maxY, numY, minZ, maxZ, numZ int16) (
}
}
}
logger.LOG.Info("init aoi area grid finish")
logger.Info("init aoi area grid finish")
return r
}
@@ -175,7 +175,7 @@ func (a *AoiManager) GetEntityIdListByPos(x, y, z float32) (entityIdList []uint3
for _, v := range gridList {
tmp := v.GetEntityIdList()
entityIdList = append(entityIdList, tmp...)
//logger.LOG.Debug("Grid: gid: %d, tmp len: %v", v.gid, len(tmp))
// logger.Debug("Grid: gid: %d, tmp len: %v", v.gid, len(tmp))
}
return entityIdList
}

View File

@@ -16,16 +16,16 @@ func TestAoiManagerGetSurrGridListByGid(t *testing.T) {
-150, 150, 3,
-150, 150, 3,
)
logger.LOG.Debug("aoiManager: %s", aoiManager.DebugString())
logger.Debug("aoiManager: %s", aoiManager.DebugString())
for k := range aoiManager.gridMap {
// 得到当前格子周边的九宫格
gridList := aoiManager.GetSurrGridListByGid(k)
// 得到九宫格所有的id
logger.LOG.Debug("gid: %d gridList len: %d", k, len(gridList))
logger.Debug("gid: %d gridList len: %d", k, len(gridList))
gidList := make([]uint32, 0, len(gridList))
for _, grid := range gridList {
gidList = append(gidList, grid.gid)
}
logger.LOG.Debug("Grid: gid: %d, surr grid gid list: %v", k, gidList)
logger.Debug("Grid: gid: %d, surr grid gid list: %v", k, gidList)
}
}

View File

@@ -44,7 +44,7 @@ func (g *Grid) RemoveEntityId(entityId uint32) {
if exist {
delete(g.entityIdMap, entityId)
} else {
logger.LOG.Error("remove entity id but it not exist, entityId: %v", entityId)
logger.Error("remove entity id but it not exist, entityId: %v", entityId)
}
}

View File

@@ -1,9 +1,10 @@
package game
import (
"hk4e/gs/model"
"strconv"
"strings"
"hk4e/gs/model"
)
// HelpCommand 帮助命令

View File

@@ -9,7 +9,7 @@ import (
func (c *CommandManager) GMTeleportPlayer(userId, sceneId uint32, posX, posY, posZ float64) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
GAME_MANAGER.TeleportPlayer(player, sceneId, &model.Vector{
@@ -42,13 +42,13 @@ func (c *CommandManager) GMAddUserWeapon(userId, itemId, itemCount uint32) {
func (c *CommandManager) GMAddUserAvatar(userId, avatarId uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
// 添加角色
GAME_MANAGER.AddUserAvatar(userId, avatarId)
// TODO 设置角色 等以后做到角色升级之类的再说
//avatar := player.AvatarMap[avatarId]
// avatar := player.AvatarMap[avatarId]
}
// GMAddUserAllItem 给予玩家所有物品

View File

@@ -86,7 +86,7 @@ func (c *CommandManager) RegisterRouter(cmdPerm CommandPerm, cmdFunc CommandFunc
s = strings.ToLower(s)
// 如果命令已注册则报错 后者覆盖前者
if c.HasCommand(s) {
logger.LOG.Error("register command repeat, name: %v", s)
logger.Error("register command repeat, name: %v", s)
}
// 记录命令
c.commandFuncRouter[s] = cmdFunc
@@ -112,7 +112,7 @@ func (c *CommandManager) InputCommand(executor any, text string) {
// 确保消息文本为 / 开头
// 如果不为这个开头那接下来就毫无意义
if strings.HasPrefix(text, "/") {
logger.LOG.Debug("command input, uid: %v, text: %v", c.GetExecutorId(executor), text)
logger.Debug("command input, uid: %v, text: %v", c.GetExecutorId(executor), text)
// 输入的命令将在其他协程中处理
c.commandTextInput <- &CommandMessage{Executor: executor, Text: text}
@@ -123,7 +123,7 @@ func (c *CommandManager) InputCommand(executor any, text string) {
// 主协程接收到命令消息后执行
func (c *CommandManager) HandleCommand(cmd *CommandMessage) {
executor := cmd.Executor
logger.LOG.Debug("command handle, uid: %v, text: %v", c.GetExecutorId(executor), cmd.Text)
logger.Debug("command handle, uid: %v, text: %v", c.GetExecutorId(executor), cmd.Text)
// 将开头的 / 去掉 并 分割出命令的每个参数
// 不区分命令的大小写 统一转为小写
@@ -150,7 +150,7 @@ func (c *CommandManager) HandleCommand(cmd *CommandMessage) {
// 分割出来的参数只有一个那肯定不是键值对
if len(cmdArg) < 2 {
logger.LOG.Debug("command arg error, uid: %v, name: %v, arg: %v, text: %v", c.GetExecutorId(executor), cmd.Name, cmdSplit, cmd.Text)
logger.Debug("command arg error, uid: %v, name: %v, arg: %v, text: %v", c.GetExecutorId(executor), cmd.Name, cmdSplit, cmd.Text)
c.SendMessage(executor, "格式错误,用法: /[命令名] -[参数名] [参数]。")
return
}
@@ -186,13 +186,13 @@ func (c *CommandManager) GetFriendList(friendList map[uint32]bool) map[uint32]bo
// ExecCommand 执行命令
func (c *CommandManager) ExecCommand(cmd *CommandMessage) {
executor := cmd.Executor
logger.LOG.Debug("command exec, uid: %v, name: %v, args: %v", c.GetExecutorId(executor), cmd.Name, cmd.Args)
logger.Debug("command exec, uid: %v, name: %v, args: %v", c.GetExecutorId(executor), cmd.Name, cmd.Args)
// 判断命令是否注册
cmdFunc, ok := c.commandFuncRouter[cmd.Name]
if !ok {
// 玩家可能会执行一些没有的命令仅做调试输出
logger.LOG.Debug("exec command not exist, uid: %v, name: %v", c.GetExecutorId(executor), cmd.Name)
logger.Debug("exec command not exist, uid: %v, name: %v", c.GetExecutorId(executor), cmd.Name)
c.SendMessage(executor, "命令不存在,输入 /help 查看帮助。")
return
}
@@ -200,21 +200,21 @@ func (c *CommandManager) ExecCommand(cmd *CommandMessage) {
cmdPerm, ok := c.commandPermMap[cmd.Name]
if !ok {
// 一般命令权限都会注册 没注册则报error错误
logger.LOG.Error("command exec permission not exist, name: %v", cmd.Name)
logger.Error("command exec permission not exist, name: %v", cmd.Name)
return
}
// 判断玩家的权限是否符合要求
player, ok := executor.(*model.Player)
if ok && player.IsGM < uint8(cmdPerm) {
logger.LOG.Debug("exec command permission denied, uid: %v, isGM: %v", player.PlayerID, player.IsGM)
logger.Debug("exec command permission denied, uid: %v, isGM: %v", player.PlayerID, player.IsGM)
c.SendMessage(player, "权限不足,该命令需要%v级权限。\n你目前的权限等级%v", cmdPerm, player.IsGM)
return
}
logger.LOG.Debug("command start, uid: %v, name: %v, args: %v", c.GetExecutorId(executor), cmd.Name, cmd.Args)
logger.Debug("command start, uid: %v, name: %v, args: %v", c.GetExecutorId(executor), cmd.Name, cmd.Args)
cmdFunc(cmd) // 执行命令
logger.LOG.Debug("command done, uid: %v, name: %v, args: %v", c.GetExecutorId(executor), cmd.Name, cmd.Args)
logger.Debug("command done, uid: %v, name: %v, args: %v", c.GetExecutorId(executor), cmd.Name, cmd.Args)
}
// SendMessage 发送消息
@@ -227,10 +227,10 @@ func (c *CommandManager) SendMessage(executor any, msg string, param ...any) {
GAME_MANAGER.SendPrivateChat(c.system, player, fmt.Sprintf(msg, param...))
case string:
// GM接口等
//str := executor.(string)
// str := executor.(string)
default:
// 无效的类型报错
logger.LOG.Error("command executor type error, type: %T", executor)
logger.Error("command executor type error, type: %T", executor)
}
}

View File

@@ -1,7 +1,8 @@
package game
import (
pb "google.golang.org/protobuf/proto"
"time"
"hk4e/gs/dao"
"hk4e/gs/model"
"hk4e/pkg/alg"
@@ -9,7 +10,8 @@ import (
"hk4e/pkg/reflection"
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
"time"
pb "google.golang.org/protobuf/proto"
)
var GAME_MANAGER *GameManager = nil
@@ -72,7 +74,7 @@ func (g *GameManager) Stop() {
EventId: RunUserCopyAndSave,
}
time.Sleep(time.Second * 3)
//g.worldManager.worldStatic.SaveTerrain()
// g.worldManager.worldStatic.SaveTerrain()
}
// SendMsg 发送消息给客户端
@@ -88,7 +90,7 @@ func (g *GameManager) SendMsg(cmdId uint16, userId uint32, clientSeq uint32, pay
// 在这里直接序列化成二进制数据 防止发送的消息内包含各种游戏数据指针 而造成并发读写的问题
payloadMessageData, err := pb.Marshal(payloadMsg)
if err != nil {
logger.LOG.Error("parse payload msg to bin error: %v", err)
logger.Error("parse payload msg to bin error: %v", err)
return
}
netMsg.PayloadMessageData = payloadMessageData
@@ -112,7 +114,7 @@ func (g *GameManager) CommonRetError(cmdId uint16, player *model.Player, rsp pb.
if !ok {
return
}
logger.LOG.Debug("send common error: %v", rsp)
logger.Debug("send common error: %v", rsp)
g.SendMsg(cmdId, player.PlayerID, player.ClientSeq, rsp)
}

View File

@@ -1,10 +1,11 @@
package game
import (
"time"
"hk4e/gs/model"
"hk4e/pkg/logger"
"hk4e/pkg/object"
"time"
)
// 本地事件队列管理器
@@ -57,7 +58,7 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
playerCopy := new(model.Player)
err := object.FastDeepCopy(playerCopy, player)
if err != nil {
logger.LOG.Error("deep copy player error: %v", err)
logger.Error("deep copy player error: %v", err)
continue
}
insertPlayerList = append(insertPlayerList, playerCopy)
@@ -66,7 +67,7 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
playerCopy := new(model.Player)
err := object.FastDeepCopy(playerCopy, player)
if err != nil {
logger.LOG.Error("deep copy player error: %v", err)
logger.Error("deep copy player error: %v", err)
continue
}
updatePlayerList = append(updatePlayerList, playerCopy)
@@ -75,7 +76,7 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
playerCopy := new(model.Player)
err := object.FastDeepCopy(playerCopy, player)
if err != nil {
logger.LOG.Error("deep copy player error: %v", err)
logger.Error("deep copy player error: %v", err)
continue
}
updatePlayerList = append(updatePlayerList, playerCopy)
@@ -87,6 +88,6 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
}
endTime := time.Now().UnixNano()
costTime := endTime - startTime
logger.LOG.Info("run save user copy cost time: %v ns", costTime)
logger.Info("run save user copy cost time: %v ns", costTime)
}
}

View File

@@ -30,12 +30,12 @@ func (r *RouteManager) registerRouter(cmdId uint16, handlerFunc HandlerFunc) {
func (r *RouteManager) doRoute(cmdId uint16, userId uint32, clientSeq uint32, payloadMsg pb.Message) {
handlerFunc, ok := r.handlerFuncRouteMap[cmdId]
if !ok {
logger.LOG.Error("no route for msg, cmdId: %v", cmdId)
logger.Error("no route for msg, cmdId: %v", cmdId)
return
}
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
// 临时为了调试便捷搞的重连 生产环境请务必去除 不然新用户会一直重连不能进入
// GAME_MANAGER.ReconnectPlayer(userId)
return

View File

@@ -21,7 +21,7 @@ type TickManager struct {
func NewTickManager() (r *TickManager) {
r = new(TickManager)
r.ticker = time.NewTicker(time.Millisecond * 100)
logger.LOG.Info("game server tick start at: %v", time.Now().UnixMilli())
logger.Info("game server tick start at: %v", time.Now().UnixMilli())
return r
}
@@ -59,15 +59,15 @@ func (t *TickManager) OnGameServerTick() {
}
func (t *TickManager) onTickWeek(now int64) {
logger.LOG.Info("on tick week, time: %v", now)
logger.Info("on tick week, time: %v", now)
}
func (t *TickManager) onTickDay(now int64) {
logger.LOG.Info("on tick day, time: %v", now)
logger.Info("on tick day, time: %v", now)
}
func (t *TickManager) onTickHour(now int64) {
logger.LOG.Info("on tick hour, time: %v", now)
logger.Info("on tick hour, time: %v", now)
}
func (t *TickManager) onTick10Minute(now int64) {
@@ -81,7 +81,7 @@ func (t *TickManager) onTick10Minute(now int64) {
}
func (t *TickManager) onTickMinute(now int64) {
//GAME_MANAGER.ServerAnnounceNotify(100, "test123")
// GAME_MANAGER.ServerAnnounceNotify(100, "test123")
for _, world := range WORLD_MANAGER.worldMap {
for _, player := range world.playerMap {
// 随机物品
@@ -91,7 +91,7 @@ func (t *TickManager) onTickMinute(now int64) {
for itemId := range allItemDataConfig {
itemDataConfig, ok := allItemDataConfig[itemId]
if !ok {
logger.LOG.Error("config is nil, itemId: %v", itemId)
logger.Error("config is nil, itemId: %v", itemId)
return
}
// TODO 3.0.0REL版本中 发送某些无效家具 可能会导致客户端背包家具界面卡死

View File

@@ -31,20 +31,20 @@ func (g *GameManager) GetAllAvatarDataConfig() map[int32]*gdc.AvatarData {
func (g *GameManager) AddUserAvatar(userId uint32, avatarId uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
player.AddAvatar(avatarId)
avatar := player.AvatarMap[avatarId]
if avatar == nil {
logger.LOG.Error("avatar is nil, avatarId", avatarId)
logger.Error("avatar is nil, avatarId", avatarId)
return
}
// 添加初始武器
avatarDataConfig, ok := gdc.CONF.AvatarDataMap[int32(avatarId)]
if !ok {
logger.LOG.Error("config is nil, itemId: %v", avatarId)
logger.Error("config is nil, itemId: %v", avatarId)
return
}
weaponId := g.AddUserWeapon(player.PlayerID, uint32(avatarDataConfig.InitialWeapon))
@@ -62,7 +62,7 @@ func (g *GameManager) AddUserAvatar(userId uint32, avatarId uint32) {
}
func (g *GameManager) WearEquipReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user wear equip, uid: %v", player.PlayerID)
logger.Debug("user wear equip, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.WearEquipReq)
avatarGuid := req.AvatarGuid
equipGuid := req.EquipGuid
@@ -80,7 +80,7 @@ func (g *GameManager) WearEquipReq(player *model.Player, payloadMsg pb.Message)
func (g *GameManager) WearUserAvatarEquip(userId uint32, avatarId uint32, weaponId uint64) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
avatar := player.AvatarMap[avatarId]
@@ -127,7 +127,7 @@ func (g *GameManager) WearUserAvatarEquip(userId uint32, avatarId uint32, weapon
}
func (g *GameManager) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change avatar costume, uid: %v", player.PlayerID)
logger.Debug("user change avatar costume, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarChangeCostumeReq)
avatarGuid := req.AvatarGuid
costumeId := req.CostumeId
@@ -165,7 +165,7 @@ func (g *GameManager) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb
}
func (g *GameManager) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change avatar fly cloak, uid: %v", player.PlayerID)
logger.Debug("user change avatar fly cloak, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarWearFlycloakReq)
avatarGuid := req.AvatarGuid
flycloakId := req.FlycloakId
@@ -236,7 +236,7 @@ func (g *GameManager) PacketAvatarEquipTakeOffNotify(avatar *model.Avatar, weapo
func (g *GameManager) UpdateUserAvatarFightProp(userId uint32, avatarId uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
avatar := player.AvatarMap[avatarId]
@@ -249,9 +249,9 @@ func (g *GameManager) UpdateUserAvatarFightProp(userId uint32, avatarId uint32)
func (g *GameManager) PacketAvatarInfo(avatar *model.Avatar) *proto.AvatarInfo {
isFocus := false
//if avatar.AvatarId == 10000005 || avatar.AvatarId == 10000007 {
// if avatar.AvatarId == 10000005 || avatar.AvatarId == 10000007 {
// isFocus = true
//}
// }
pbAvatar := &proto.AvatarInfo{
IsFocus: isFocus,
AvatarId: avatar.AvatarId,

View File

@@ -12,7 +12,7 @@ import (
)
func (g *GameManager) PullRecentChatReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user pull recent chat, uid: %v", player.PlayerID)
logger.Debug("user pull recent chat, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.PullRecentChatReq)
// 经研究发现 原神现网环境 客户端仅拉取最新的5条未读聊天消息 所以人太多的话小姐姐不回你消息是有原因的
// 因此 阿米你这样做真的合适吗 不过现在代码到了我手上我想怎么写就怎么写 我才不会重蹈覆辙
@@ -52,7 +52,7 @@ func (g *GameManager) PullRecentChatReq(player *model.Player, payloadMsg pb.Mess
}
func (g *GameManager) PullPrivateChatReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user pull private chat, uid: %v", player.PlayerID)
logger.Debug("user pull private chat, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.PullPrivateChatReq)
targetUid := req.TargetUid
pullNum := req.PullNum
@@ -132,7 +132,7 @@ func (g *GameManager) SendPrivateChat(player, targetPlayer *model.Player, conten
}
func (g *GameManager) PrivateChatReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user send private chat, uid: %v", player.PlayerID)
logger.Debug("user send private chat, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.PrivateChatReq)
targetUid := req.TargetUid
content := req.Content
@@ -171,7 +171,7 @@ func (g *GameManager) PrivateChatReq(player *model.Player, payloadMsg pb.Message
}
func (g *GameManager) ReadPrivateChatReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user read private chat, uid: %v", player.PlayerID)
logger.Debug("user read private chat, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ReadPrivateChatReq)
targetUid := req.TargetUid
@@ -189,7 +189,7 @@ func (g *GameManager) ReadPrivateChatReq(player *model.Player, payloadMsg pb.Mes
}
func (g *GameManager) PlayerChatReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user multiplayer chat, uid: %v", player.PlayerID)
logger.Debug("user multiplayer chat, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.PlayerChatReq)
channelId := req.ChannelId
chatInfo := req.ChatInfo

View File

@@ -12,7 +12,7 @@ import (
)
func (g *GameManager) PlayerSetPauseReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user pause, uid: %v", player.PlayerID)
logger.Debug("user pause, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.PlayerSetPauseReq)
isPaused := req.IsPaused
player.Pause = isPaused
@@ -21,7 +21,7 @@ func (g *GameManager) PlayerSetPauseReq(player *model.Player, payloadMsg pb.Mess
}
func (g *GameManager) TowerAllDataReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get tower all data, uid: %v", player.PlayerID)
logger.Debug("user get tower all data, uid: %v", player.PlayerID)
towerAllDataRsp := &proto.TowerAllDataRsp{
TowerScheduleId: 29,
@@ -40,7 +40,7 @@ func (g *GameManager) TowerAllDataReq(player *model.Player, payloadMsg pb.Messag
}
func (g *GameManager) EntityAiSyncNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user entity ai sync, uid: %v", player.PlayerID)
logger.Debug("user entity ai sync, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EntityAiSyncNotify)
entityAiSyncNotify := &proto.EntityAiSyncNotify{
@@ -59,20 +59,20 @@ func (g *GameManager) EntityAiSyncNotify(player *model.Player, payloadMsg pb.Mes
func (g *GameManager) ClientTimeNotify(userId uint32, clientTime uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
logger.LOG.Debug("client time notify, uid: %v, time: %v", userId, clientTime)
logger.Debug("client time notify, uid: %v, time: %v", userId, clientTime)
player.ClientTime = clientTime
}
func (g *GameManager) ClientRttNotify(userId uint32, clientRtt uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
logger.LOG.Debug("client rtt notify, uid: %v, rtt: %v", userId, clientRtt)
logger.Debug("client rtt notify, uid: %v, rtt: %v", userId, clientRtt)
player.ClientRTT = clientRtt
}
@@ -102,14 +102,14 @@ func (g *GameManager) ServerAnnounceRevokeNotify(announceId uint32) {
}
func (g *GameManager) ToTheMoonEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user ttm enter scene, uid: %v", player.PlayerID)
logger.Debug("user ttm enter scene, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ToTheMoonEnterSceneReq)
_ = req
g.SendMsg(cmd.ToTheMoonEnterSceneRsp, player.PlayerID, player.ClientSeq, new(proto.ToTheMoonEnterSceneRsp))
}
func (g *GameManager) SetEntityClientDataNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user set entity client data, uid: %v", player.PlayerID)
logger.Debug("user set entity client data, uid: %v", player.PlayerID)
ntf := payloadMsg.(*proto.SetEntityClientDataNotify)
g.SendMsg(cmd.SetEntityClientDataNotify, player.PlayerID, player.ClientSeq, ntf)
}

View File

@@ -54,7 +54,7 @@ func DoForward[IET model.InvokeEntryType](player *model.Player, req pb.Message,
}
func (g *GameManager) UnionCmdNotify(player *model.Player, payloadMsg pb.Message) {
//logger.LOG.Debug("user send union cmd, uid: %v", player.PlayerID)
// logger.Debug("user send union cmd, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.UnionCmdNotify)
_ = req
if player.SceneLoadState != model.SceneEnterDone {
@@ -67,7 +67,7 @@ func (g *GameManager) UnionCmdNotify(player *model.Player, payloadMsg pb.Message
}
func (g *GameManager) MassiveEntityElementOpBatchNotify(player *model.Player, payloadMsg pb.Message) {
//logger.LOG.Debug("user meeo sync, uid: %v", player.PlayerID)
// logger.Debug("user meeo sync, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.MassiveEntityElementOpBatchNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
@@ -84,7 +84,7 @@ func (g *GameManager) MassiveEntityElementOpBatchNotify(player *model.Player, pa
}
func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Message) {
//logger.LOG.Debug("user combat invocations, uid: %v", player.PlayerID)
// logger.Debug("user combat invocations, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.CombatInvocationsNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
@@ -99,7 +99,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
entityMoveInfo := new(proto.EntityMoveInfo)
err := pb.Unmarshal(entry.CombatData, entityMoveInfo)
if err != nil {
logger.LOG.Error("parse EntityMoveInfo error: %v", err)
logger.Error("parse EntityMoveInfo error: %v", err)
continue
}
motionInfo := entityMoveInfo.MotionInfo
@@ -144,9 +144,9 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
evtAnimatorStateChangedInfo := new(proto.EvtAnimatorStateChangedInfo)
err := pb.Unmarshal(entry.CombatData, evtAnimatorStateChangedInfo)
if err != nil {
logger.LOG.Error("parse EvtAnimatorStateChangedInfo error: %v", err)
logger.Error("parse EvtAnimatorStateChangedInfo error: %v", err)
}
logger.LOG.Debug("EvtAnimatorStateChangedInfo: %v", entry, player.PlayerID)
logger.Debug("EvtAnimatorStateChangedInfo: %v", entry, player.PlayerID)
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
default:
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
@@ -155,38 +155,38 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
}
func (g *GameManager) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Message) {
//logger.LOG.Debug("user ability invocations, uid: %v", player.PlayerID)
// logger.Debug("user ability invocations, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AbilityInvocationsNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
for _, entry := range req.Invokes {
//logger.LOG.Debug("AbilityInvocationsNotify: %v", entry, player.PlayerID)
// logger.Debug("AbilityInvocationsNotify: %v", entry, player.PlayerID)
//switch entry.ArgumentType {
//case proto.AbilityInvokeArgument_ABILITY_INVOKE_ARGUMENT_META_MODIFIER_CHANGE:
// switch entry.ArgumentType {
// case proto.AbilityInvokeArgument_ABILITY_INVOKE_ARGUMENT_META_MODIFIER_CHANGE:
// world := WORLD_MANAGER.GetWorldByID(player.WorldId)
// worldAvatar := world.GetWorldAvatarByEntityId(entry.EntityId)
// if worldAvatar != nil {
// for _, ability := range worldAvatar.abilityList {
// if ability.InstancedAbilityId == entry.Head.InstancedAbilityId {
// logger.LOG.Error("A: %v", ability)
// logger.Error("A: %v", ability)
// }
// }
// for _, modifier := range worldAvatar.modifierList {
// if modifier.InstancedAbilityId == entry.Head.InstancedAbilityId {
// logger.LOG.Error("B: %v", modifier)
// logger.Error("B: %v", modifier)
// }
// }
// for _, modifier := range worldAvatar.modifierList {
// if modifier.InstancedModifierId == entry.Head.InstancedModifierId {
// logger.LOG.Error("C: %v", modifier)
// logger.Error("C: %v", modifier)
// }
// }
// }
//case proto.AbilityInvokeArgument_ABILITY_INVOKE_ARGUMENT_NONE:
//}
// case proto.AbilityInvokeArgument_ABILITY_INVOKE_ARGUMENT_NONE:
// }
// 处理耐力消耗
g.HandleAbilityStamina(player, entry)
@@ -195,28 +195,28 @@ func (g *GameManager) AbilityInvocationsNotify(player *model.Player, payloadMsg
}
func (g *GameManager) ClientAbilityInitFinishNotify(player *model.Player, payloadMsg pb.Message) {
//logger.LOG.Debug("user client ability init finish, uid: %v", player.PlayerID)
// logger.Debug("user client ability init finish, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ClientAbilityInitFinishNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
invokeHandler := model.NewInvokeHandler[proto.AbilityInvokeEntry]()
for _, entry := range req.Invokes {
logger.LOG.Debug("ClientAbilityInitFinishNotify: %v", entry, player.PlayerID)
logger.Debug("ClientAbilityInitFinishNotify: %v", entry, player.PlayerID)
invokeHandler.AddEntry(entry.ForwardType, entry)
}
DoForward[proto.AbilityInvokeEntry](player, &proto.ClientAbilityInitFinishNotify{}, []string{"EntityId"}, "Invokes", invokeHandler)
}
func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Message) {
//logger.LOG.Debug("user client ability change, uid: %v", player.PlayerID)
// logger.Debug("user client ability change, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ClientAbilityChangeNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
invokeHandler := model.NewInvokeHandler[proto.AbilityInvokeEntry]()
for _, entry := range req.Invokes {
logger.LOG.Debug("ClientAbilityChangeNotify: %v", entry, player.PlayerID)
logger.Debug("ClientAbilityChangeNotify: %v", entry, player.PlayerID)
invokeHandler.AddEntry(entry.ForwardType, entry)
}
@@ -232,7 +232,7 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
abilityMetaAddAbility := new(proto.AbilityMetaAddAbility)
err := pb.Unmarshal(abilityInvokeEntry.AbilityData, abilityMetaAddAbility)
if err != nil {
logger.LOG.Error("%v", err)
logger.Error("%v", err)
continue
}
worldAvatar := world.GetWorldAvatarByEntityId(abilityInvokeEntry.EntityId)
@@ -244,7 +244,7 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
abilityMetaModifierChange := new(proto.AbilityMetaModifierChange)
err := pb.Unmarshal(abilityInvokeEntry.AbilityData, abilityMetaModifierChange)
if err != nil {
logger.LOG.Error("%v", err)
logger.Error("%v", err)
continue
}
abilityAppliedModifier := &proto.AbilityAppliedModifier{
@@ -273,68 +273,68 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
}
func (g *GameManager) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user event do skill success, uid: %v", player.PlayerID)
logger.Debug("user event do skill success, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtDoSkillSuccNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
logger.LOG.Debug("EvtDoSkillSuccNotify: %v", req)
logger.Debug("EvtDoSkillSuccNotify: %v", req)
// 处理技能开始的耐力消耗
g.SkillStartStamina(player, req.CasterId, req.SkillId)
}
func (g *GameManager) EvtAvatarEnterFocusNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user avatar enter focus, uid: %v", player.PlayerID)
logger.Debug("user avatar enter focus, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtAvatarEnterFocusNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
logger.LOG.Debug("EvtAvatarEnterFocusNotify: %v", req)
logger.Debug("EvtAvatarEnterFocusNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
g.SendToWorldA(world, cmd.EvtAvatarEnterFocusNotify, player.ClientSeq, req)
}
func (g *GameManager) EvtAvatarUpdateFocusNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user avatar update focus, uid: %v", player.PlayerID)
logger.Debug("user avatar update focus, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtAvatarUpdateFocusNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
logger.LOG.Debug("EvtAvatarUpdateFocusNotify: %v", req)
logger.Debug("EvtAvatarUpdateFocusNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
g.SendToWorldA(world, cmd.EvtAvatarUpdateFocusNotify, player.ClientSeq, req)
}
func (g *GameManager) EvtAvatarExitFocusNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user avatar exit focus, uid: %v", player.PlayerID)
logger.Debug("user avatar exit focus, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtAvatarExitFocusNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
logger.LOG.Debug("EvtAvatarExitFocusNotify: %v", req)
logger.Debug("EvtAvatarExitFocusNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
g.SendToWorldA(world, cmd.EvtAvatarExitFocusNotify, player.ClientSeq, req)
}
func (g *GameManager) EvtEntityRenderersChangedNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user entity render change, uid: %v", player.PlayerID)
logger.Debug("user entity render change, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtEntityRenderersChangedNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
logger.LOG.Debug("EvtEntityRenderersChangedNotify: %v", req)
logger.Debug("EvtEntityRenderersChangedNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
g.SendToWorldA(world, cmd.EvtEntityRenderersChangedNotify, player.ClientSeq, req)
}
func (g *GameManager) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user create gadget, uid: %v", player.PlayerID)
logger.Debug("user create gadget, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtCreateGadgetNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
logger.LOG.Debug("EvtCreateGadgetNotify: %v", req)
logger.Debug("EvtCreateGadgetNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
scene.ClientCreateEntityGadget(&model.Vector{
@@ -350,12 +350,12 @@ func (g *GameManager) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.
}
func (g *GameManager) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user destroy gadget, uid: %v", player.PlayerID)
logger.Debug("user destroy gadget, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtDestroyGadgetNotify)
if player.SceneLoadState != model.SceneEnterDone {
return
}
logger.LOG.Debug("EvtDestroyGadgetNotify: %v", req)
logger.Debug("EvtDestroyGadgetNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
scene.DestroyEntity(req.EntityId)

View File

@@ -1,10 +1,10 @@
package game
import (
"hk4e/gdconf"
"time"
"hk4e/common/config"
"hk4e/gdconf"
"hk4e/gs/model"
"hk4e/pkg/logger"
"hk4e/pkg/random"
@@ -22,7 +22,7 @@ type UserInfo struct {
// 获取卡池信息
func (g *GameManager) GetGachaInfoReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get gacha info, uid: %v", player.PlayerID)
logger.Debug("user get gacha info, uid: %v", player.PlayerID)
serverAddr := config.CONF.Hk4e.GachaHistoryServer
userInfo := &UserInfo{
UserId: player.PlayerID,
@@ -35,7 +35,7 @@ func (g *GameManager) GetGachaInfoReq(player *model.Player, payloadMsg pb.Messag
token := jwt.NewWithClaims(jwt.SigningMethodHS512, userInfo)
jwtStr, err := token.SignedString([]byte("flswld"))
if err != nil {
logger.LOG.Error("generate jwt error: %v", err)
logger.Error("generate jwt error: %v", err)
jwtStr = "default.jwt.token"
}
@@ -195,7 +195,7 @@ func (g *GameManager) GetGachaInfoReq(player *model.Player, payloadMsg pb.Messag
}
func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user do gacha, uid: %v", player.PlayerID)
logger.Debug("user do gacha, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.DoGachaReq)
gachaScheduleId := req.GachaScheduleId
gachaTimes := req.GachaTimes
@@ -319,7 +319,7 @@ func (g *GameManager) DoGachaReq(player *model.Player, payloadMsg pb.Message) {
doGachaRsp.GachaItemList = append(doGachaRsp.GachaItemList, gachaItem)
}
logger.LOG.Debug("doGachaRsp: %v", doGachaRsp.String())
logger.Debug("doGachaRsp: %v", doGachaRsp.String())
g.SendMsg(cmd.DoGachaRsp, player.PlayerID, player.ClientSeq, doGachaRsp)
}
@@ -380,21 +380,21 @@ const (
func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnable bool, weaponFix bool) (bool, uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return false, 0
}
// 找到卡池对应的掉落组
dropGroupDataConfig := gdconf.CONF.DropGroupDataMap[int32(gachaType)]
if dropGroupDataConfig == nil {
logger.LOG.Error("drop group not found, drop id: %v", gachaType)
logger.Error("drop group not found, drop id: %v", gachaType)
return false, 0
}
// 获取用户的卡池保底信息
gachaPoolInfo := player.DropInfo.GachaPoolInfo[gachaType]
if gachaPoolInfo == nil {
logger.LOG.Error("user gacha pool info not found, gacha type: %v", gachaType)
logger.Error("user gacha pool info not found, gacha type: %v", gachaType)
return false, 0
}
@@ -448,7 +448,7 @@ func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnab
} else if drop.Result == blueDropId {
fixDrop.Weight = drop.Weight - addOrangeWeight - addPurpleWeight
} else {
logger.LOG.Error("invalid drop group id, does not match any case of orange/purple/blue, result group id: %v", drop.Result)
logger.Error("invalid drop group id, does not match any case of orange/purple/blue, result group id: %v", drop.Result)
fixDrop.Weight = drop.Weight
}
fixDropGroupDataConfig.DropConfig = append(fixDropGroupDataConfig.DropConfig, fixDrop)
@@ -473,20 +473,20 @@ func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnab
allAvatarDataConfig := g.GetAllAvatarDataConfig()
avatarDataConfig := allAvatarDataConfig[int32(avatarId)]
if avatarDataConfig == nil {
logger.LOG.Error("avatar data config not found, avatar id: %v", avatarId)
logger.Error("avatar data config not found, avatar id: %v", avatarId)
return false, 0
}
if avatarDataConfig.QualityType == "QUALITY_ORANGE" {
itemColor = Orange
logger.LOG.Debug("[orange avatar], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
logger.Debug("[orange avatar], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
if gachaPoolInfo.OrangeTimes > 90 {
logger.LOG.Error("[abnormal orange avatar], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
logger.Error("[abnormal orange avatar], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
}
} else if avatarDataConfig.QualityType == "QUALITY_PURPLE" {
itemColor = Purple
logger.LOG.Debug("[purple avatar], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
logger.Debug("[purple avatar], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
if gachaPoolInfo.PurpleTimes > 10 {
logger.LOG.Error("[abnormal purple avatar], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
logger.Error("[abnormal purple avatar], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
}
} else {
itemColor = Blue
@@ -497,20 +497,20 @@ func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnab
allWeaponDataConfig := g.GetAllWeaponDataConfig()
weaponDataConfig := allWeaponDataConfig[int32(gachaItemId)]
if weaponDataConfig == nil {
logger.LOG.Error("weapon item data config not found, item id: %v", gachaItemId)
logger.Error("weapon item data config not found, item id: %v", gachaItemId)
return false, 0
}
if weaponDataConfig.RankLevel == 5 {
itemColor = Orange
logger.LOG.Debug("[orange weapon], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
logger.Debug("[orange weapon], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
if gachaPoolInfo.OrangeTimes > 90 {
logger.LOG.Error("[abnormal orange weapon], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
logger.Error("[abnormal orange weapon], times: %v, gachaItemId: %v", gachaPoolInfo.OrangeTimes, gachaItemId)
}
} else if weaponDataConfig.RankLevel == 4 {
itemColor = Purple
logger.LOG.Debug("[purple weapon], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
logger.Debug("[purple weapon], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
if gachaPoolInfo.PurpleTimes > 10 {
logger.LOG.Error("[abnormal purple weapon], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
logger.Error("[abnormal purple weapon], times: %v, gachaItemId: %v", gachaPoolInfo.PurpleTimes, gachaItemId)
}
} else {
itemColor = Blue
@@ -526,10 +526,10 @@ func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnab
upOrangeDropId := int32(gachaType*100 + 12)
// 替换本次结果为5星大保底
if gachaPoolInfo.MustGetUpOrange {
logger.LOG.Debug("trigger must get up orange, uid: %v", userId)
logger.Debug("trigger must get up orange, uid: %v", userId)
upOrangeDropGroupDataConfig := gdconf.CONF.DropGroupDataMap[upOrangeDropId]
if upOrangeDropGroupDataConfig == nil {
logger.LOG.Error("drop group not found, drop id: %v", upOrangeDropId)
logger.Error("drop group not found, drop id: %v", upOrangeDropId)
return false, 0
}
upOrangeOk, upOrangeDrop := g.doFullRandDrop(upOrangeDropGroupDataConfig)
@@ -553,10 +553,10 @@ func (g *GameManager) doGachaOnce(userId uint32, gachaType uint32, mustGetUpEnab
upPurpleDropId := int32(gachaType*100 + 22)
// 替换本次结果为4星大保底
if gachaPoolInfo.MustGetUpPurple {
logger.LOG.Debug("trigger must get up purple, uid: %v", userId)
logger.Debug("trigger must get up purple, uid: %v", userId)
upPurpleDropGroupDataConfig := gdconf.CONF.DropGroupDataMap[upPurpleDropId]
if upPurpleDropGroupDataConfig == nil {
logger.LOG.Error("drop group not found, drop id: %v", upPurpleDropId)
logger.Error("drop group not found, drop id: %v", upPurpleDropId)
return false, 0
}
upPurpleOk, upPurpleDrop := g.doFullRandDrop(upPurpleDropGroupDataConfig)
@@ -582,7 +582,7 @@ func (g *GameManager) doFullRandDrop(dropGroupDataConfig *gdconf.DropGroupData)
for {
drop := g.doRandDropOnce(dropGroupDataConfig)
if drop == nil {
logger.LOG.Error("weight error, drop group config: %v", dropGroupDataConfig)
logger.Error("weight error, drop group config: %v", dropGroupDataConfig)
return false, nil
}
if drop.IsEnd {
@@ -592,7 +592,7 @@ func (g *GameManager) doFullRandDrop(dropGroupDataConfig *gdconf.DropGroupData)
// 进行下一步掉落流程
dropGroupDataConfig = gdconf.CONF.DropGroupDataMap[drop.Result]
if dropGroupDataConfig == nil {
logger.LOG.Error("drop config tab exist error, invalid drop id: %v", drop.Result)
logger.Error("drop config tab exist error, invalid drop id: %v", drop.Result)
return false, nil
}
}

View File

@@ -51,7 +51,7 @@ func (g *GameManager) GetAllItemDataConfig() map[int32]*gdc.ItemData {
func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bool, hintReason uint16) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
for _, userItem := range itemList {
@@ -118,7 +118,7 @@ func (g *GameManager) AddUserItem(userId uint32, itemList []*UserItem, isHint bo
func (g *GameManager) CostUserItem(userId uint32, itemList []*UserItem) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
for _, userItem := range itemList {

View File

@@ -1,7 +1,6 @@
package game
import (
pb "google.golang.org/protobuf/proto"
"time"
gdc "hk4e/gs/config"
@@ -11,10 +10,12 @@ import (
"hk4e/pkg/reflection"
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
pb "google.golang.org/protobuf/proto"
)
func (g *GameManager) OnLogin(userId uint32, clientSeq uint32) {
logger.LOG.Info("user login, uid: %v", userId)
logger.Info("user login, uid: %v", userId)
player, asyncWait := USER_MANAGER.OnlineUser(userId, clientSeq)
if !asyncWait {
g.OnLoginOk(userId, player, clientSeq)
@@ -31,7 +32,7 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
// 初始化
player.InitAll()
//player.TeamConfig.UpdateTeam()
// player.TeamConfig.UpdateTeam()
// 创建世界
world := WORLD_MANAGER.CreateWorld(player)
world.AddPlayer(player, player.SceneId)
@@ -40,8 +41,8 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
player.CombatInvokeHandler = model.NewInvokeHandler[proto.CombatInvokeEntry]()
player.AbilityInvokeHandler = model.NewInvokeHandler[proto.AbilityInvokeEntry]()
//// TODO 薄荷标记
//if world.IsBigWorld() {
// // TODO 薄荷标记
// if world.IsBigWorld() {
// bigWorld := world.GetSceneById(3)
// for pos := range g.worldManager.worldStatic.terrain {
// bigWorld.CreateEntityGadget(&model.Vector{
@@ -50,7 +51,7 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
// Z: float64(pos.Z),
// }, 3003009)
// }
//}
// }
g.LoginNotify(userId, player, clientSeq)
@@ -59,9 +60,9 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u
}
func (g *GameManager) OnReg(userId uint32, clientSeq uint32, payloadMsg pb.Message) {
logger.LOG.Debug("user reg, uid: %v", userId)
logger.Debug("user reg, uid: %v", userId)
req := payloadMsg.(*proto.SetPlayerBornDataReq)
logger.LOG.Debug("avatar id: %v, nickname: %v", req.AvatarId, req.NickName)
logger.Debug("avatar id: %v, nickname: %v", req.AvatarId, req.NickName)
exist, asyncWait := USER_MANAGER.CheckUserExistOnReg(userId, req, clientSeq)
if !asyncWait {
@@ -71,20 +72,20 @@ func (g *GameManager) OnReg(userId uint32, clientSeq uint32, payloadMsg pb.Messa
func (g *GameManager) OnRegOk(exist bool, req *proto.SetPlayerBornDataReq, userId uint32, clientSeq uint32) {
if exist {
logger.LOG.Error("recv reg req, but user is already exist, userId: %v", userId)
logger.Error("recv reg req, but user is already exist, userId: %v", userId)
return
}
nickName := req.NickName
mainCharAvatarId := req.GetAvatarId()
if mainCharAvatarId != 10000005 && mainCharAvatarId != 10000007 {
logger.LOG.Error("invalid main char avatar id: %v", mainCharAvatarId)
logger.Error("invalid main char avatar id: %v", mainCharAvatarId)
return
}
player := g.CreatePlayer(userId, nickName, mainCharAvatarId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return
}
USER_MANAGER.AddUser(player)
@@ -94,10 +95,10 @@ func (g *GameManager) OnRegOk(exist bool, req *proto.SetPlayerBornDataReq, userI
}
func (g *GameManager) OnUserOffline(userId uint32) {
logger.LOG.Info("user offline, uid: %v", userId)
logger.Info("user offline, uid: %v", userId)
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, userId: %v", userId)
logger.Error("player is nil, userId: %v", userId)
return
}
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
@@ -164,7 +165,7 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
}
itemData, ok := itemDataMapConfig[int32(weapon.ItemId)]
if !ok {
logger.LOG.Error("config is nil, itemId: %v", weapon.ItemId)
logger.Error("config is nil, itemId: %v", weapon.ItemId)
return nil
}
if itemData.ItemEnumType != constant.ItemTypeConst.ITEM_WEAPON {
@@ -364,7 +365,7 @@ func (g *GameManager) CreatePlayer(userId uint32, nickName string, mainCharAvata
// 添加初始武器
avatarDataConfig, ok := gdc.CONF.AvatarDataMap[int32(mainCharAvatarId)]
if !ok {
logger.LOG.Error("config is nil, mainCharAvatarId: %v", mainCharAvatarId)
logger.Error("config is nil, mainCharAvatarId: %v", mainCharAvatarId)
return nil
}
weaponId := uint64(g.snowflake.GenId())

View File

@@ -111,7 +111,7 @@ func (u *UserManager) LoadTempOfflineUserSync(userId uint32) *model.Player {
func (u *UserManager) loadUserFromDb(userId uint32) *model.Player {
player, err := u.dao.QueryPlayerByID(userId)
if err != nil {
logger.LOG.Error("query player error: %v", err)
logger.Error("query player error: %v", err)
return nil
}
return player
@@ -150,7 +150,7 @@ func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32) (*model.Player
if player != nil {
u.ChangeUserDbState(player, model.DbNormal)
} else {
logger.LOG.Error("can not find user from db, uid: %v", userId)
logger.Error("can not find user from db, uid: %v", userId)
}
LOCAL_EVENT_MANAGER.localEventChan <- &LocalEvent{
EventId: LoadLoginUserFromDbFinish,
@@ -178,22 +178,22 @@ func (u *UserManager) ChangeUserDbState(player *model.Player, state int) {
} else if state == model.DbNormal {
player.DbState = model.DbNormal
} else {
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
logger.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
}
case model.DbInsert:
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
logger.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
break
case model.DbDelete:
if state == model.DbNormal {
player.DbState = model.DbNormal
} else {
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
logger.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
}
case model.DbNormal:
if state == model.DbDelete {
player.DbState = model.DbDelete
} else {
logger.LOG.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
logger.Error("player db state change not allow, before: %v, after: %v", player.DbState, state)
}
}
}
@@ -221,13 +221,13 @@ func (u *UserManager) StartAutoSaveUser() {
func (u *UserManager) SaveUser(saveUserData *SaveUserData) {
err := u.dao.InsertPlayerList(saveUserData.insertPlayerList)
if err != nil {
logger.LOG.Error("insert player list error: %v", err)
logger.Error("insert player list error: %v", err)
return
}
err = u.dao.UpdatePlayerList(saveUserData.updatePlayerList)
if err != nil {
logger.LOG.Error("update player list error: %v", err)
logger.Error("update player list error: %v", err)
return
}
logger.LOG.Info("save user finish, insert user count: %v, update user count: %v", len(saveUserData.insertPlayerList), len(saveUserData.updatePlayerList))
logger.Info("save user finish, insert user count: %v, update user count: %v", len(saveUserData.insertPlayerList), len(saveUserData.updatePlayerList))
}

View File

@@ -14,7 +14,7 @@ import (
)
func (g *GameManager) SceneTransToPointReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get scene trans to point, uid: %v", player.PlayerID)
logger.Debug("user get scene trans to point, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SceneTransToPointReq)
transPointId := strconv.Itoa(int(req.SceneId)) + "_" + strconv.Itoa(int(req.PointId))
@@ -43,15 +43,15 @@ func (g *GameManager) SceneTransToPointReq(player *model.Player, payloadMsg pb.M
}
func (g *GameManager) MarkMapReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user mark map, uid: %v", player.PlayerID)
logger.Debug("user mark map, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.MarkMapReq)
operation := req.Op
if operation == proto.MarkMapReq_OPERATION_ADD {
logger.LOG.Debug("user mark type: %v", req.Mark.PointType)
logger.Debug("user mark type: %v", req.Mark.PointType)
if req.Mark.PointType == proto.MapMarkPointType_MAP_MARK_POINT_TYPE_NPC {
posYInt, err := strconv.ParseInt(req.Mark.Name, 10, 64)
if err != nil {
logger.LOG.Error("parse pos y error: %v", err)
logger.Error("parse pos y error: %v", err)
posYInt = 300
}
// 传送玩家
@@ -99,10 +99,10 @@ func (g *GameManager) TeleportPlayer(player *model.Player, sceneId uint32, pos *
var enterType proto.EnterType
if jumpScene {
logger.LOG.Debug("player jump scene, scene: %v, pos: %v", player.SceneId, player.Pos)
logger.Debug("player jump scene, scene: %v, pos: %v", player.SceneId, player.Pos)
enterType = proto.EnterType_ENTER_TYPE_JUMP
} else {
logger.LOG.Debug("player goto scene, scene: %v, pos: %v", player.SceneId, player.Pos)
logger.Debug("player goto scene, scene: %v, pos: %v", player.SceneId, player.Pos)
enterType = proto.EnterType_ENTER_TYPE_GOTO
}
playerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyTp(player, enterType, uint32(constant.EnterReasonConst.TransPoint), oldSceneId, oldPos)
@@ -110,12 +110,12 @@ func (g *GameManager) TeleportPlayer(player *model.Player, sceneId uint32, pos *
}
func (g *GameManager) PathfindingEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user pathfinding enter scene, uid: %v", player.PlayerID)
logger.Debug("user pathfinding enter scene, uid: %v", player.PlayerID)
g.SendMsg(cmd.PathfindingEnterSceneRsp, player.PlayerID, player.ClientSeq, new(proto.PathfindingEnterSceneRsp))
}
func (g *GameManager) QueryPathReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user query path, uid: %v", player.PlayerID)
logger.Debug("user query path, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.QueryPathReq)
queryPathRsp := &proto.QueryPathRsp{
@@ -127,7 +127,7 @@ func (g *GameManager) QueryPathReq(player *model.Player, payloadMsg pb.Message)
}
func (g *GameManager) GetScenePointReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get scene point, uid: %v", player.PlayerID)
logger.Debug("user get scene point, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.GetScenePointReq)
if req.SceneId != 3 {
@@ -150,7 +150,7 @@ func (g *GameManager) GetScenePointReq(player *model.Player, payloadMsg pb.Messa
}
func (g *GameManager) GetSceneAreaReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get scene area, uid: %v", player.PlayerID)
logger.Debug("user get scene area, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.GetSceneAreaReq)
if req.SceneId != 3 {

View File

@@ -1,12 +1,12 @@
package game
import (
"hk4e/pkg/object"
"time"
"hk4e/gs/constant"
"hk4e/gs/model"
"hk4e/pkg/logger"
"hk4e/pkg/object"
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
@@ -14,7 +14,7 @@ import (
)
func (g *GameManager) PlayerApplyEnterMpReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user apply enter world, uid: %v", player.PlayerID)
logger.Debug("user apply enter world, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.PlayerApplyEnterMpReq)
targetUid := req.TargetUid
@@ -36,7 +36,7 @@ func (g *GameManager) PlayerApplyEnterMpReq(player *model.Player, payloadMsg pb.
}
func (g *GameManager) PlayerApplyEnterMpResultReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user deal world enter apply, uid: %v", player.PlayerID)
logger.Debug("user deal world enter apply, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.PlayerApplyEnterMpResultReq)
applyUid := req.ApplyUid
isAgreed := req.IsAgreed
@@ -51,7 +51,7 @@ func (g *GameManager) PlayerApplyEnterMpResultReq(player *model.Player, payloadM
}
func (g *GameManager) PlayerGetForceQuitBanInfoReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get world exit ban info, uid: %v", player.PlayerID)
logger.Debug("user get world exit ban info, uid: %v", player.PlayerID)
ok := true
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
for _, worldPlayer := range world.playerMap {
@@ -68,7 +68,7 @@ func (g *GameManager) PlayerGetForceQuitBanInfoReq(player *model.Player, payload
}
func (g *GameManager) BackMyWorldReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user back world, uid: %v", player.PlayerID)
logger.Debug("user back world, uid: %v", player.PlayerID)
// 其他玩家
ok := g.UserLeaveWorld(player)
@@ -80,7 +80,7 @@ func (g *GameManager) BackMyWorldReq(player *model.Player, payloadMsg pb.Message
}
func (g *GameManager) ChangeWorldToSingleModeReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change world to single, uid: %v", player.PlayerID)
logger.Debug("user change world to single, uid: %v", player.PlayerID)
// 房主
ok := g.UserLeaveWorld(player)
@@ -92,7 +92,7 @@ func (g *GameManager) ChangeWorldToSingleModeReq(player *model.Player, payloadMs
}
func (g *GameManager) SceneKickPlayerReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user kick player, uid: %v", player.PlayerID)
logger.Debug("user kick player, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SceneKickPlayerReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if player.PlayerID != world.owner.PlayerID {
@@ -122,7 +122,7 @@ func (g *GameManager) SceneKickPlayerReq(player *model.Player, payloadMsg pb.Mes
}
func (g *GameManager) JoinPlayerSceneReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user join player scene, uid: %v", player.PlayerID)
logger.Debug("user join player scene, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.JoinPlayerSceneReq)
hostPlayer := USER_MANAGER.GetOnlineUser(req.TargetUid)
hostWorld := WORLD_MANAGER.GetWorldByID(hostPlayer.WorldId)
@@ -140,7 +140,7 @@ func (g *GameManager) JoinPlayerSceneReq(player *model.Player, payloadMsg pb.Mes
g.SendMsg(cmd.LeaveWorldNotify, player.PlayerID, player.ClientSeq, new(proto.LeaveWorldNotify))
//g.LoginNotify(player.PlayerID, player, 0)
// g.LoginNotify(player.PlayerID, player, 0)
if hostPlayer.SceneLoadState == model.SceneEnterDone {
delete(hostWorld.waitEnterPlayerMap, player.PlayerID)

View File

@@ -17,7 +17,7 @@ import (
)
func (g *GameManager) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user enter scene ready, uid: %v", player.PlayerID)
logger.Debug("user enter scene ready, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
enterScenePeerNotify := &proto.EnterScenePeerNotify{
@@ -35,7 +35,7 @@ func (g *GameManager) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Mes
}
func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user scene init finish, uid: %v", player.PlayerID)
logger.Debug("user scene init finish, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
@@ -220,7 +220,7 @@ func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Mes
}
func (g *GameManager) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user enter scene done, uid: %v", player.PlayerID)
logger.Debug("user enter scene done, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world.multiplayer && world.IsPlayerFirstEnter(player) {
@@ -240,7 +240,7 @@ func (g *GameManager) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Mess
g.AddSceneEntityNotify(player, visionType, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}, true, false)
// 通过aoi获取场景中在自己周围格子里的全部实体id
//entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
// entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
entityIdList := world.GetSceneById(player.SceneId).GetEntityIdList()
if world.IsPlayerFirstEnter(player) {
visionType = proto.VisionType_VISION_TYPE_MEET
@@ -281,7 +281,7 @@ func (g *GameManager) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Mess
}
func (g *GameManager) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user post enter scene, uid: %v", player.PlayerID)
logger.Debug("user post enter scene, uid: %v", player.PlayerID)
postEnterSceneRsp := &proto.PostEnterSceneRsp{
EnterSceneToken: player.EnterSceneToken,
@@ -290,7 +290,7 @@ func (g *GameManager) PostEnterSceneReq(player *model.Player, payloadMsg pb.Mess
}
func (g *GameManager) EnterWorldAreaReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user enter world area, uid: %v", player.PlayerID)
logger.Debug("user enter world area, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EnterWorldAreaReq)
enterWorldAreaRsp := &proto.EnterWorldAreaRsp{
@@ -301,7 +301,7 @@ func (g *GameManager) EnterWorldAreaReq(player *model.Player, payloadMsg pb.Mess
}
func (g *GameManager) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change game time, uid: %v", player.PlayerID)
logger.Debug("user change game time, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ChangeGameTimeReq)
gameTime := req.GameTime
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
@@ -394,7 +394,7 @@ func (g *GameManager) AddSceneEntityNotifyToPlayer(player *model.Player, visionT
EntityList: entityList,
}
g.SendMsg(cmd.SceneEntityAppearNotify, player.PlayerID, player.ClientSeq, sceneEntityAppearNotify)
logger.LOG.Debug("SceneEntityAppearNotify, uid: %v, type: %v, len: %v",
logger.Debug("SceneEntityAppearNotify, uid: %v, type: %v, len: %v",
player.PlayerID, sceneEntityAppearNotify.AppearType, len(sceneEntityAppearNotify.EntityList))
}
@@ -408,7 +408,7 @@ func (g *GameManager) AddSceneEntityNotifyBroadcast(player *model.Player, scene
continue
}
g.SendMsg(cmd.SceneEntityAppearNotify, scenePlayer.PlayerID, scenePlayer.ClientSeq, sceneEntityAppearNotify)
logger.LOG.Debug("SceneEntityAppearNotify, uid: %v, type: %v, len: %v",
logger.Debug("SceneEntityAppearNotify, uid: %v, type: %v, len: %v",
scenePlayer.PlayerID, sceneEntityAppearNotify.AppearType, len(sceneEntityAppearNotify.EntityList))
}
}
@@ -419,7 +419,7 @@ func (g *GameManager) RemoveSceneEntityNotifyToPlayer(player *model.Player, visi
DisappearType: visionType,
}
g.SendMsg(cmd.SceneEntityDisappearNotify, player.PlayerID, player.ClientSeq, sceneEntityDisappearNotify)
logger.LOG.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
logger.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
player.PlayerID, sceneEntityDisappearNotify.DisappearType, len(sceneEntityDisappearNotify.EntityList))
}
@@ -430,7 +430,7 @@ func (g *GameManager) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType
}
for _, scenePlayer := range scene.playerMap {
g.SendMsg(cmd.SceneEntityDisappearNotify, scenePlayer.PlayerID, scenePlayer.ClientSeq, sceneEntityDisappearNotify)
logger.LOG.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
logger.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
scenePlayer.PlayerID, sceneEntityDisappearNotify.DisappearType, len(sceneEntityDisappearNotify.EntityList))
}
}
@@ -442,7 +442,7 @@ func (g *GameManager) AddSceneEntityNotify(player *model.Player, visionType prot
for _, entityId := range entityIdList {
entity, ok := scene.entityMap[entityId]
if !ok {
// logger.LOG.Error("get entity is nil, entityId: %v", entityId)
// logger.Error("get entity is nil, entityId: %v", entityId)
continue
}
switch entity.entityType {
@@ -452,7 +452,7 @@ func (g *GameManager) AddSceneEntityNotify(player *model.Player, visionType prot
}
scenePlayer := USER_MANAGER.GetOnlineUser(entity.avatarEntity.uid)
if scenePlayer == nil {
logger.LOG.Error("get scene player is nil, world id: %v, scene id: %v", world.id, scene.id)
logger.Error("get scene player is nil, world id: %v, scene id: %v", world.id, scene.id)
continue
}
if entity.avatarEntity.avatarId != world.GetPlayerActiveAvatarId(scenePlayer) {
@@ -719,9 +719,9 @@ func (g *GameManager) PacketSceneAvatarInfo(scene *Scene, player *model.Player,
BornTime: uint32(player.AvatarMap[avatarId].BornTime),
TeamResonanceList: make([]uint32, 0),
}
//for id := range player.TeamConfig.TeamResonances {
// for id := range player.TeamConfig.TeamResonances {
// sceneAvatarInfo.TeamResonanceList = append(sceneAvatarInfo.TeamResonanceList, uint32(id))
//}
// }
return sceneAvatarInfo
}
@@ -756,13 +756,13 @@ func (g *GameManager) PacketSceneGadgetInfoVehicle(gadgetVehicleEntity *GadgetVe
func (g *GameManager) PacketSceneGadgetInfoGather(gadgetGatherEntity *GadgetGatherEntity) *proto.SceneGadgetInfo {
gather, ok := gdc.CONF.GatherDataMap[int32(gadgetGatherEntity.gatherId)]
if !ok {
logger.LOG.Error("gather data error, gatherId: %v", gadgetGatherEntity.gatherId)
logger.Error("gather data error, gatherId: %v", gadgetGatherEntity.gatherId)
return new(proto.SceneGadgetInfo)
}
sceneGadgetInfo := &proto.SceneGadgetInfo{
GadgetId: uint32(gather.GadgetId),
//GroupId: 133003011,
//ConfigId: 11001,
// GroupId: 133003011,
// ConfigId: 11001,
GadgetState: 0,
IsEnableInteract: false,
AuthorityPeerId: 1,

View File

@@ -13,7 +13,7 @@ import (
)
func (g *GameManager) GetShopmallDataReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get shop mall, uid: %v", player.PlayerID)
logger.Debug("user get shop mall, uid: %v", player.PlayerID)
getShopmallDataRsp := &proto.GetShopmallDataRsp{
ShopTypeList: []uint32{900, 1052, 902, 1001, 903},
@@ -22,7 +22,7 @@ func (g *GameManager) GetShopmallDataReq(player *model.Player, payloadMsg pb.Mes
}
func (g *GameManager) GetShopReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get shop, uid: %v", player.PlayerID)
logger.Debug("user get shop, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.GetShopReq)
shopType := req.ShopType
@@ -70,7 +70,7 @@ func (g *GameManager) GetShopReq(player *model.Player, payloadMsg pb.Message) {
}
func (g *GameManager) BuyGoodsReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user buy goods, uid: %v", player.PlayerID)
logger.Debug("user buy goods, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.BuyGoodsReq)
buyItemId := req.Goods.GoodsItem.ItemId
buyItemCount := req.BuyCount
@@ -103,7 +103,7 @@ func (g *GameManager) BuyGoodsReq(player *model.Player, payloadMsg pb.Message) {
}
func (g *GameManager) McoinExchangeHcoinReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user mcoin exchange hcoin, uid: %v", player.PlayerID)
logger.Debug("user mcoin exchange hcoin, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.McoinExchangeHcoinReq)
if req.Hcoin != req.McoinCost {
return

View File

@@ -16,7 +16,7 @@ import (
)
func (g *GameManager) GetPlayerSocialDetailReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get player social detail, uid: %v", player.PlayerID)
logger.Debug("user get player social detail, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.GetPlayerSocialDetailReq)
targetUid := req.Uid
@@ -47,7 +47,7 @@ func (g *GameManager) GetPlayerSocialDetailReq(player *model.Player, payloadMsg
}
func (g *GameManager) SetPlayerBirthdayReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user set birthday, uid: %v", player.PlayerID)
logger.Debug("user set birthday, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SetPlayerBirthdayReq)
if player.Birthday[0] != 0 || player.Birthday[1] != 0 {
g.CommonRetError(cmd.SetPlayerBirthdayRsp, player, &proto.SetPlayerBirthdayRsp{})
@@ -64,7 +64,7 @@ func (g *GameManager) SetPlayerBirthdayReq(player *model.Player, payloadMsg pb.M
}
func (g *GameManager) SetNameCardReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change name card, uid: %v", player.PlayerID)
logger.Debug("user change name card, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SetNameCardReq)
nameCardId := req.NameCardId
exist := false
@@ -74,7 +74,7 @@ func (g *GameManager) SetNameCardReq(player *model.Player, payloadMsg pb.Message
}
}
if !exist {
logger.LOG.Error("name card not exist, uid: %v", player.PlayerID)
logger.Error("name card not exist, uid: %v", player.PlayerID)
return
}
player.NameCard = nameCardId
@@ -86,7 +86,7 @@ func (g *GameManager) SetNameCardReq(player *model.Player, payloadMsg pb.Message
}
func (g *GameManager) SetPlayerSignatureReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change signature, uid: %v", player.PlayerID)
logger.Debug("user change signature, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SetPlayerSignatureReq)
signature := req.Signature
@@ -103,7 +103,7 @@ func (g *GameManager) SetPlayerSignatureReq(player *model.Player, payloadMsg pb.
}
func (g *GameManager) SetPlayerNameReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change nickname, uid: %v", player.PlayerID)
logger.Debug("user change nickname, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SetPlayerNameReq)
nickName := req.NickName
@@ -124,12 +124,12 @@ func (g *GameManager) SetPlayerNameReq(player *model.Player, payloadMsg pb.Messa
}
func (g *GameManager) SetPlayerHeadImageReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change head image, uid: %v", player.PlayerID)
logger.Debug("user change head image, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SetPlayerHeadImageReq)
avatarId := req.AvatarId
_, exist := player.AvatarMap[avatarId]
if !exist {
logger.LOG.Error("the head img of the avatar not exist, uid: %v", player.PlayerID)
logger.Error("the head img of the avatar not exist, uid: %v", player.PlayerID)
return
}
player.HeadImage = avatarId
@@ -141,7 +141,7 @@ func (g *GameManager) SetPlayerHeadImageReq(player *model.Player, payloadMsg pb.
}
func (g *GameManager) GetAllUnlockNameCardReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get all unlock name card, uid: %v", player.PlayerID)
logger.Debug("user get all unlock name card, uid: %v", player.PlayerID)
getAllUnlockNameCardRsp := &proto.GetAllUnlockNameCardRsp{
NameCardList: player.NameCardList,
@@ -150,7 +150,7 @@ func (g *GameManager) GetAllUnlockNameCardReq(player *model.Player, payloadMsg p
}
func (g *GameManager) GetPlayerFriendListReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get friend list, uid: %v", player.PlayerID)
logger.Debug("user get friend list, uid: %v", player.PlayerID)
getPlayerFriendListRsp := &proto.GetPlayerFriendListRsp{
FriendList: make([]*proto.FriendBrief, 0),
}
@@ -169,7 +169,7 @@ func (g *GameManager) GetPlayerFriendListReq(player *model.Player, payloadMsg pb
}
friendPlayer := USER_MANAGER.LoadTempOfflineUserSync(uid)
if friendPlayer == nil {
logger.LOG.Error("target player is nil, uid: %v", player.PlayerID)
logger.Error("target player is nil, uid: %v", player.PlayerID)
continue
}
friendBrief := &proto.FriendBrief{
@@ -193,7 +193,7 @@ func (g *GameManager) GetPlayerFriendListReq(player *model.Player, payloadMsg pb
}
func (g *GameManager) GetPlayerAskFriendListReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get friend apply list, uid: %v", player.PlayerID)
logger.Debug("user get friend apply list, uid: %v", player.PlayerID)
getPlayerAskFriendListRsp := &proto.GetPlayerAskFriendListRsp{
AskFriendList: make([]*proto.FriendBrief, 0),
@@ -209,7 +209,7 @@ func (g *GameManager) GetPlayerAskFriendListReq(player *model.Player, payloadMsg
}
friendPlayer := USER_MANAGER.LoadTempOfflineUserSync(uid)
if friendPlayer == nil {
logger.LOG.Error("target player is nil, uid: %v", player.PlayerID)
logger.Error("target player is nil, uid: %v", player.PlayerID)
continue
}
friendBrief := &proto.FriendBrief{
@@ -233,7 +233,7 @@ func (g *GameManager) GetPlayerAskFriendListReq(player *model.Player, payloadMsg
}
func (g *GameManager) AskAddFriendReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user apply add friend, uid: %v", player.PlayerID)
logger.Debug("user apply add friend, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AskAddFriendReq)
targetUid := req.TargetUid
@@ -241,13 +241,13 @@ func (g *GameManager) AskAddFriendReq(player *model.Player, payloadMsg pb.Messag
targetPlayerOnline := USER_MANAGER.GetUserOnlineState(targetUid)
targetPlayer := USER_MANAGER.LoadTempOfflineUserSync(targetUid)
if targetPlayer == nil {
logger.LOG.Error("apply add friend target player is nil, uid: %v", player.PlayerID)
logger.Error("apply add friend target player is nil, uid: %v", player.PlayerID)
return
}
_, applyExist := targetPlayer.FriendApplyList[player.PlayerID]
_, friendExist := targetPlayer.FriendList[player.PlayerID]
if applyExist || friendExist {
logger.LOG.Error("friend or apply already exist, uid: %v", player.PlayerID)
logger.Error("friend or apply already exist, uid: %v", player.PlayerID)
return
}
targetPlayer.FriendApplyList[player.PlayerID] = true
@@ -285,14 +285,14 @@ func (g *GameManager) AddFriend(player *model.Player, targetUid uint32) {
// TODO 同步阻塞待优化
targetPlayer := USER_MANAGER.LoadTempOfflineUserSync(targetUid)
if targetPlayer == nil {
logger.LOG.Error("agree friend apply target player is nil, uid: %v", player.PlayerID)
logger.Error("agree friend apply target player is nil, uid: %v", player.PlayerID)
return
}
targetPlayer.FriendList[player.PlayerID] = true
}
func (g *GameManager) DealAddFriendReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user deal friend apply, uid: %v", player.PlayerID)
logger.Debug("user deal friend apply, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.DealAddFriendReq)
targetUid := req.TargetUid
result := req.DealAddFriendResult
@@ -310,7 +310,7 @@ func (g *GameManager) DealAddFriendReq(player *model.Player, payloadMsg pb.Messa
}
func (g *GameManager) GetOnlinePlayerListReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user get online player list, uid: %v", player.PlayerID)
logger.Debug("user get online player list, uid: %v", player.PlayerID)
count := 0
onlinePlayerList := make([]*model.Player, 0)

View File

@@ -1,7 +1,8 @@
package game
import (
pb "google.golang.org/protobuf/proto"
"time"
"hk4e/gdconf"
"hk4e/gs/constant"
"hk4e/gs/model"
@@ -9,7 +10,8 @@ import (
"hk4e/pkg/logger"
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
"time"
pb "google.golang.org/protobuf/proto"
)
// HandleAbilityStamina 处理来自ability的耐力消耗
@@ -20,7 +22,7 @@ func (g *GameManager) HandleAbilityStamina(player *model.Player, entry *proto.Ab
costStamina := new(proto.AbilityMixinCostStamina)
err := pb.Unmarshal(entry.AbilityData, costStamina)
if err != nil {
logger.LOG.Error("unmarshal ability data err: %v", err)
logger.Error("unmarshal ability data err: %v", err)
return
}
// 处理持续耐力消耗
@@ -37,7 +39,7 @@ func (g *GameManager) HandleAbilityStamina(player *model.Player, entry *proto.Ab
abilityNameHashCode := uint32(0)
for _, ability := range worldAvatar.abilityList {
if ability.InstancedAbilityId == entry.Head.InstancedAbilityId {
//logger.LOG.Error("%v", ability)
// logger.Error("%v", ability)
abilityNameHashCode = ability.AbilityName.GetHash()
}
}
@@ -84,7 +86,7 @@ func (g *GameManager) SceneAvatarStaminaStepReq(player *model.Player, payloadMsg
} else if req.Rot.X > 270 && req.Rot.X < 360 {
angleRevise = int32(req.Rot.X - 360.0)
} else {
logger.LOG.Error("invalid rot x angle: %v, uid: %v", req.Rot.X, player.PlayerID)
logger.Error("invalid rot x angle: %v, uid: %v", req.Rot.X, player.PlayerID)
g.CommonRetError(cmd.SceneAvatarStaminaStepRsp, player, &proto.SceneAvatarStaminaStepRsp{})
return
}
@@ -99,7 +101,7 @@ func (g *GameManager) SceneAvatarStaminaStepReq(player *model.Player, payloadMsg
// 倒三角 非常消耗体力
costRevise = -(angleRevise * 2) + 10
}
logger.LOG.Debug("stamina climbing, rotX: %v, costRevise: %v, cost: %v", req.Rot.X, costRevise, constant.StaminaCostConst.CLIMBING_BASE-costRevise)
logger.Debug("stamina climbing, rotX: %v, costRevise: %v, cost: %v", req.Rot.X, costRevise, constant.StaminaCostConst.CLIMBING_BASE-costRevise)
g.UpdatePlayerStamina(player, constant.StaminaCostConst.CLIMBING_BASE-costRevise)
case proto.MotionState_MOTION_STATE_SWIM_MOVE:
// 缓慢游泳
@@ -120,7 +122,7 @@ func (g *GameManager) ImmediateStamina(player *model.Player, motionState proto.M
return
}
staminaInfo := player.StaminaInfo
//logger.LOG.Debug("stamina handle, uid: %v, motionState: %v", player.PlayerID, motionState)
// logger.Debug("stamina handle, uid: %v, motionState: %v", player.PlayerID, motionState)
// 设置用于持续消耗或恢复耐力的值
staminaInfo.SetStaminaCost(motionState)
@@ -158,7 +160,7 @@ func (g *GameManager) SkillSustainStamina(player *model.Player, isSwim bool) {
// 读取技能配置表
avatarSkillConfig, ok := gdconf.CONF.AvatarSkillDataMap[int32(skillId)]
if !ok {
logger.LOG.Error("avatarSkillConfig error, skillId: %v", skillId)
logger.Error("avatarSkillConfig error, skillId: %v", skillId)
return
}
// 获取释放技能者的角色Id
@@ -171,7 +173,7 @@ func (g *GameManager) SkillSustainStamina(player *model.Player, isSwim bool) {
// 获取现行角色的配置表
avatarDataConfig, ok := gdconf.CONF.AvatarDataMap[int32(worldAvatar.avatarId)]
if !ok {
logger.LOG.Error("avatarDataConfig error, avatarId: %v", worldAvatar.avatarId)
logger.Error("avatarDataConfig error, avatarId: %v", worldAvatar.avatarId)
return
}
@@ -192,7 +194,7 @@ func (g *GameManager) SkillSustainStamina(player *model.Player, isSwim bool) {
pastTime := time.Now().UnixMilli() - staminaInfo.LastSkillTime
// 根据配置以及距离上次的时间计算消耗的耐力
costStamina = int32(float64(pastTime) / 1000 * float64(costStamina))
logger.LOG.Debug("stamina skill sustain, skillId: %v, cost: %v, isSwim: %v", skillId, costStamina, isSwim)
logger.Debug("stamina skill sustain, skillId: %v, cost: %v, isSwim: %v", skillId, costStamina, isSwim)
// 根据配置以及距离上次的时间计算消耗的耐力
g.UpdatePlayerStamina(player, costStamina)
@@ -206,7 +208,7 @@ func (g *GameManager) ChargedAttackStamina(player *model.Player, worldAvatar *Wo
// 获取现行角色的配置表
avatarDataConfig, ok := gdconf.CONF.AvatarDataMap[int32(worldAvatar.avatarId)]
if !ok {
logger.LOG.Error("avatarDataConfig error, avatarId: %v", worldAvatar.avatarId)
logger.Error("avatarDataConfig error, avatarId: %v", worldAvatar.avatarId)
return
}
@@ -231,7 +233,7 @@ func (g *GameManager) ChargedAttackStamina(player *model.Player, worldAvatar *Wo
} else {
costStamina = -(skillData.CostStamina * 100)
}
logger.LOG.Debug("charged attack stamina, skillId: %v, cost: %v", skillData.AvatarSkillId, costStamina)
logger.Debug("charged attack stamina, skillId: %v, cost: %v", skillData.AvatarSkillId, costStamina)
// 根据配置消耗耐力
g.UpdatePlayerStamina(player, costStamina)
@@ -250,13 +252,13 @@ func (g *GameManager) SkillStartStamina(player *model.Player, casterId uint32, s
pastTime := time.Now().UnixMilli() - staminaInfo.LastSkillStartTime
// 上次触发的技能相同则每400ms触发一次消耗
if staminaInfo.LastSkillId != skillId || pastTime > 400 {
logger.LOG.Debug("skill start stamina, skillId: %v, cost: %v", skillId, costStamina)
logger.Debug("skill start stamina, skillId: %v, cost: %v", skillId, costStamina)
// 根据配置消耗耐力
g.UpdatePlayerStamina(player, costStamina)
staminaInfo.LastSkillStartTime = time.Now().UnixMilli()
}
} else {
//logger.LOG.Debug("skill start cost error, cost: %v", costStamina)
// logger.Debug("skill start cost error, cost: %v", costStamina)
}
// 记录最后释放的技能
@@ -338,13 +340,13 @@ func (g *GameManager) UpdateVehicleStamina(player *model.Player, vehicleEntity *
if staminaCost > 0 {
// 耐力延迟2s(10 ticks)恢复 动作状态为加速将立刻恢复耐力
if staminaInfo.VehicleRestoreDelay < 10 && staminaInfo.State != proto.MotionState_MOTION_STATE_SKIFF_POWERED_DASH {
//logger.LOG.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay)
// logger.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay)
staminaInfo.VehicleRestoreDelay++
return // 不恢复耐力
}
} else {
// 消耗耐力重新计算恢复需要延迟的tick
//logger.LOG.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.VehicleRestoreDelay)
// logger.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.VehicleRestoreDelay)
staminaInfo.VehicleRestoreDelay = 0
}
@@ -384,13 +386,13 @@ func (g *GameManager) UpdatePlayerStamina(player *model.Player, staminaCost int3
if staminaCost > 0 {
// 耐力延迟2s(10 ticks)恢复 动作状态为加速将立刻恢复耐力
if staminaInfo.PlayerRestoreDelay < 10 && staminaInfo.State != proto.MotionState_MOTION_STATE_POWERED_FLY {
//logger.LOG.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay)
// logger.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay)
staminaInfo.PlayerRestoreDelay++
return // 不恢复耐力
}
} else {
// 消耗耐力重新计算恢复需要延迟的tick
//logger.LOG.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.RestoreDelay)
// logger.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.RestoreDelay)
staminaInfo.PlayerRestoreDelay = 0
}
@@ -415,7 +417,7 @@ func (g *GameManager) UpdatePlayerStamina(player *model.Player, staminaCost int3
func (g *GameManager) SetVehicleStamina(player *model.Player, vehicleEntity *Entity, stamina float32) {
// 设置载具的耐力
vehicleEntity.gadgetEntity.gadgetVehicleEntity.curStamina = stamina
//logger.LOG.Debug("vehicle stamina set, stamina: %v", stamina)
// logger.Debug("vehicle stamina set, stamina: %v", stamina)
// PacketVehicleStaminaNotify
vehicleStaminaNotify := new(proto.VehicleStaminaNotify)
@@ -429,7 +431,7 @@ func (g *GameManager) SetPlayerStamina(player *model.Player, stamina uint32) {
// 设置玩家的耐力
prop := constant.PlayerPropertyConst.PROP_CUR_PERSIST_STAMINA
player.PropertiesMap[prop] = stamina
//logger.LOG.Debug("player stamina set, stamina: %v", stamina)
// logger.Debug("player stamina set, stamina: %v", stamina)
// PacketPlayerPropNotify
playerPropNotify := new(proto.PlayerPropNotify)

View File

@@ -13,7 +13,7 @@ import (
)
func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change avatar, uid: %v", player.PlayerID)
logger.Debug("user change avatar, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ChangeAvatarReq)
targetAvatarGuid := req.Guid
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
@@ -21,12 +21,12 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
targetAvatarId := player.GetAvatarIdByGuid(targetAvatarGuid)
oldAvatarId := world.GetPlayerActiveAvatarId(player)
if targetAvatarId == oldAvatarId {
logger.LOG.Error("can not change to the same avatar, uid: %v, oldAvatarId: %v, targetAvatarId: %v", player.PlayerID, oldAvatarId, targetAvatarId)
logger.Error("can not change to the same avatar, uid: %v, oldAvatarId: %v, targetAvatarId: %v", player.PlayerID, oldAvatarId, targetAvatarId)
return
}
newAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, targetAvatarId)
if newAvatarIndex == -1 {
logger.LOG.Error("can not find the target avatar in team, uid: %v, targetAvatarId: %v", player.PlayerID, targetAvatarId)
logger.Error("can not find the target avatar in team, uid: %v, targetAvatarId: %v", player.PlayerID, targetAvatarId)
return
}
if !world.multiplayer {
@@ -36,7 +36,7 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
oldAvatarEntityId := world.GetPlayerWorldAvatarEntityId(player, oldAvatarId)
oldAvatarEntity := scene.GetEntity(oldAvatarEntityId)
if oldAvatarEntity == nil {
logger.LOG.Error("can not find old avatar entity, entity id: %v", oldAvatarEntityId)
logger.Error("can not find old avatar entity, entity id: %v", oldAvatarEntityId)
return
}
oldAvatarEntity.moveState = uint16(proto.MotionState_MOTION_STATE_STANDBY)
@@ -67,7 +67,7 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
}
func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change team avatar, uid: %v", player.PlayerID)
logger.Debug("user change team avatar, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.SetUpAvatarTeamReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world.multiplayer {
@@ -111,7 +111,7 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
g.SendMsg(cmd.AvatarTeamUpdateNotify, player.PlayerID, player.ClientSeq, avatarTeamUpdateNotify)
if selfTeam {
//player.TeamConfig.UpdateTeam()
// player.TeamConfig.UpdateTeam()
world.SetPlayerLocalTeam(player, avatarIdList)
world.UpdateMultiplayerTeam()
world.InitPlayerWorldAvatar(player)
@@ -135,7 +135,7 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
}
func (g *GameManager) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user switch team, uid: %v", player.PlayerID)
logger.Debug("user switch team, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ChooseCurAvatarTeamReq)
teamId := req.TeamId
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
@@ -149,7 +149,7 @@ func (g *GameManager) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb
}
player.TeamConfig.CurrTeamIndex = uint8(teamId) - 1
player.TeamConfig.CurrAvatarIndex = 0
//player.TeamConfig.UpdateTeam()
// player.TeamConfig.UpdateTeam()
world.SetPlayerAvatarIndex(player, 0)
world.SetPlayerLocalTeam(player, team.GetAvatarIdList())
world.UpdateMultiplayerTeam()
@@ -165,7 +165,7 @@ func (g *GameManager) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb
}
func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user change mp team avatar, uid: %v", player.PlayerID)
logger.Debug("user change mp team avatar, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
avatarGuidList := req.AvatarGuidList
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
@@ -265,8 +265,8 @@ func (g *GameManager) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeam
}
acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, emb)
}
//// add team resonances
//for id := range worldPlayer.TeamConfig.TeamResonancesConfig {
// // add team resonances
// for id := range worldPlayer.TeamConfig.TeamResonancesConfig {
// embryoId++
// emb := &proto.AbilityEmbryo{
// AbilityId: uint32(embryoId),
@@ -274,7 +274,7 @@ func (g *GameManager) PacketSceneTeamUpdateNotify(world *World) *proto.SceneTeam
// AbilityOverrideNameHash: uint32(constant.GameConstantConst.DEFAULT_ABILITY_NAME),
// }
// acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, emb)
//}
// }
// add skill depot abilities
skillDepot := gdc.CONF.AvatarSkillDepotDataMap[int32(worldPlayerAvatar.SkillDepotId)]
if skillDepot != nil && len(skillDepot.Abilities) != 0 {

View File

@@ -1,12 +1,14 @@
package game
import (
pb "google.golang.org/protobuf/proto"
"time"
"hk4e/gs/model"
"hk4e/pkg/logger"
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
"time"
pb "google.golang.org/protobuf/proto"
)
// CreateVehicleReq 创建载具
@@ -37,7 +39,7 @@ func (g *GameManager) CreateVehicleReq(player *model.Player, payloadMsg pb.Messa
rot := &model.Vector{X: float64(req.Rot.X), Y: float64(req.Rot.Y), Z: float64(req.Rot.Z)}
entityId := scene.CreateEntityGadgetVehicle(player.PlayerID, pos, rot, req.VehicleId)
if entityId == 0 {
logger.LOG.Error("vehicle entityId is 0, uid: %v", player.PlayerID)
logger.Error("vehicle entityId is 0, uid: %v", player.PlayerID)
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
return
}
@@ -89,9 +91,9 @@ func (g *GameManager) DestroyVehicleEntity(player *model.Player, scene *Scene, v
}
// 目前原神仅有一种载具 多载具时可能跟载具耐力回复冲突 到时候再改
// 确保载具Id为将要创建的 (每种载具允许存在1个)
//if entity.gadgetEntity.gadgetVehicleEntity.vehicleId != vehicleId {
// if entity.gadgetEntity.gadgetVehicleEntity.vehicleId != vehicleId {
// return
//}
// }
// 该载具是否为此玩家的
if entity.gadgetEntity.gadgetVehicleEntity.owner != player {
return
@@ -147,7 +149,7 @@ func (g *GameManager) EnterVehicle(player *model.Player, entity *Entity, avatarG
func (g *GameManager) ExitVehicle(player *model.Player, entity *Entity, avatarGuid uint64) {
// 玩家是否进入载具
if !g.IsPlayerInVehicle(player, entity.gadgetEntity.gadgetVehicleEntity) {
logger.LOG.Error("vehicle not has player, uid: %v", player.PlayerID)
logger.Error("vehicle not has player, uid: %v", player.PlayerID)
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_NOT_IN_VEHICLE)
return
}
@@ -185,13 +187,13 @@ func (g *GameManager) VehicleInteractReq(player *model.Player, payloadMsg pb.Mes
// 获取载具实体
entity := g.GetSceneVehicleEntity(scene, req.EntityId)
if entity == nil {
logger.LOG.Error("vehicle entity is nil, entityId: %v", req.EntityId)
logger.Error("vehicle entity is nil, entityId: %v", req.EntityId)
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_ENTITY_NOT_EXIST)
return
}
// 判断实体类型是否为载具
if entity.entityType != uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET) || entity.gadgetEntity.gadgetType != GADGET_TYPE_VEHICLE {
logger.LOG.Error("vehicle entity error, entityType: %v", entity.entityType)
logger.Error("vehicle entity error, entityType: %v", entity.entityType)
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_GADGET_NOT_VEHICLE)
return
}

View File

@@ -40,14 +40,14 @@ func (g *GameManager) GetAllWeaponDataConfig() map[int32]*gdc.ItemData {
func (g *GameManager) AddUserWeapon(userId uint32, itemId uint32) uint64 {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", userId)
logger.Error("player is nil, uid: %v", userId)
return 0
}
weaponId := uint64(g.snowflake.GenId())
player.AddWeapon(itemId, weaponId)
weapon := player.GetWeapon(weaponId)
if weapon == nil {
logger.LOG.Error("weapon is nil, itemId: %v, weaponId: %v", itemId, weaponId)
logger.Error("weapon is nil, itemId: %v, weaponId: %v", itemId, weaponId)
return 0
}

View File

@@ -1,7 +1,6 @@
package game
import (
"hk4e/pkg/logger"
"math"
"time"
@@ -9,6 +8,7 @@ import (
"hk4e/gs/game/aoi"
"hk4e/gs/model"
"hk4e/pkg/alg"
"hk4e/pkg/logger"
"hk4e/protocol/proto"
)
@@ -27,8 +27,8 @@ func NewWorldManager(snowflake *alg.SnowflakeWorker) (r *WorldManager) {
r.snowflake = snowflake
r.worldStatic = NewWorldStatic()
r.worldStatic.InitTerrain()
//r.worldStatic.Pathfinding()
//r.worldStatic.ConvPathVectorListToAiMoveVectorList()
// r.worldStatic.Pathfinding()
// r.worldStatic.ConvPathVectorListToAiMoveVectorList()
return r
}
@@ -728,7 +728,7 @@ func (s *Scene) CreateEntityGadget(pos *model.Vector, gatherId uint32) uint32 {
func (s *Scene) CreateEntityGadgetVehicle(uid uint32, pos, rot *model.Vector, vehicleId uint32) uint32 {
player := USER_MANAGER.GetOnlineUser(uid)
if player == nil {
logger.LOG.Error("player is nil, uid: %v", uid)
logger.Error("player is nil, uid: %v", uid)
return 0
}
entityId := s.world.GetNextWorldEntityId(constant.EntityIdTypeConst.GADGET)

View File

@@ -59,7 +59,7 @@ func (w *WorldStatic) InitTerrain() bool {
decoder := gob.NewDecoder(bytes.NewReader(data))
err := decoder.Decode(&w.terrain)
if err != nil {
logger.LOG.Error("unmarshal world terrain data error: %v", err)
logger.Error("unmarshal world terrain data error: %v", err)
return false
}
return true
@@ -70,7 +70,7 @@ func (w *WorldStatic) SaveTerrain() bool {
encoder := gob.NewEncoder(&buffer)
err := encoder.Encode(w.terrain)
if err != nil {
logger.LOG.Error("marshal world terrain data error: %v", err)
logger.Error("marshal world terrain data error: %v", err)
return false
}
gdc.CONF.WriteWorldTerrain(buffer.Bytes())
@@ -140,10 +140,10 @@ func (w *WorldStatic) Pathfinding() {
)
pathVectorList := bfs.Pathfinding()
if pathVectorList == nil {
logger.LOG.Error("could not find path")
logger.Error("could not find path")
return
}
logger.LOG.Debug("find path success, path: %v", pathVectorList)
logger.Debug("find path success, path: %v", pathVectorList)
w.pathVectorList = w.ConvPFPVLToWSPVL(pathVectorList)
}

View File

@@ -49,7 +49,7 @@ func (p *Player) InitAllAvatar() {
func (p *Player) InitAvatar(avatar *Avatar) {
avatarDataConfig, ok := gdc.CONF.AvatarDataMap[int32(avatar.AvatarId)]
if !ok {
logger.LOG.Error("avatarDataConfig error, avatarId: %v", avatar.AvatarId)
logger.Error("avatarDataConfig error, avatarId: %v", avatar.AvatarId)
return
}
// 角色战斗属性
@@ -91,7 +91,7 @@ func (p *Player) GetAvatarIdByGuid(guid uint64) uint32 {
func (p *Player) AddAvatar(avatarId uint32) {
avatarDataConfig, ok := gdc.CONF.AvatarDataMap[int32(avatarId)]
if !ok {
logger.LOG.Error("avatarDataConfig error, avatarId: %v", avatarId)
logger.Error("avatarDataConfig error, avatarId: %v", avatarId)
return
}
skillDepotId := int32(0)
@@ -105,7 +105,7 @@ func (p *Player) AddAvatar(avatarId uint32) {
}
avatarSkillDepotDataConfig, ok := gdc.CONF.AvatarSkillDepotDataMap[skillDepotId]
if !ok {
logger.LOG.Error("avatarSkillDepotDataConfig error, skillDepotId: %v", skillDepotId)
logger.Error("avatarSkillDepotDataConfig error, skillDepotId: %v", skillDepotId)
return
}
avatar := &Avatar{

View File

@@ -43,9 +43,9 @@ func (i *InvokeHandler[T]) AddEntry(forward proto.ForwardType, entry *T) {
i.EntryListForwardHost = append(i.EntryListForwardHost, entry)
case proto.ForwardType_FORWARD_TYPE_ONLY_SERVER:
i.EntryListForwardServer = append(i.EntryListForwardServer, entry)
//logger.LOG.Error("forward server entry: %v", entry)
// logger.Error("forward server entry: %v", entry)
default:
logger.LOG.Error("forward type: %v, entry: %v", forward, entry)
logger.Error("forward type: %v, entry: %v", forward, entry)
}
}

View File

@@ -1,8 +1,9 @@
package model
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"hk4e/protocol/proto"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const (

View File

@@ -66,7 +66,7 @@ func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
}
itemDataConfig, ok := gdc.CONF.ItemDataMap[int32(itemId)]
if !ok {
logger.LOG.Error("config is nil, itemId: %v", itemId)
logger.Error("config is nil, itemId: %v", itemId)
return
}
if itemDataConfig.SkillAffix != nil {

View File

@@ -23,7 +23,7 @@ func NewMessageQueue(conn *nats.Conn, netMsgInput chan *cmd.NetMsg, netMsgOutput
r.natsMsgChan = make(chan *nats.Msg, 10000)
_, err := r.natsConn.ChanSubscribe("GS_CMD_HK4E", r.natsMsgChan)
if err != nil {
logger.LOG.Error("nats subscribe error: %v", err)
logger.Error("nats subscribe error: %v", err)
return nil
}
r.netMsgInput = netMsgInput
@@ -48,7 +48,7 @@ func (m *MessageQueue) startRecvHandler() {
netMsg := new(cmd.NetMsg)
err := msgpack.Unmarshal(natsMsg.Data, netMsg)
if err != nil {
logger.LOG.Error("parse bin to net msg error: %v", err)
logger.Error("parse bin to net msg error: %v", err)
continue
}
if netMsg.EventId == cmd.NormalMsg || netMsg.EventId == cmd.UserRegNotify {
@@ -56,7 +56,7 @@ func (m *MessageQueue) startRecvHandler() {
payloadMessage := m.cmdProtoMap.GetProtoObjByCmdId(netMsg.CmdId)
err = pb.Unmarshal(netMsg.PayloadMessageData, payloadMessage)
if err != nil {
logger.LOG.Error("parse bin to payload msg error: %v", err)
logger.Error("parse bin to payload msg error: %v", err)
continue
}
netMsg.PayloadMessage = payloadMessage
@@ -72,14 +72,14 @@ func (m *MessageQueue) startSendHandler() {
// msgpack NetMsg
netMsgData, err := msgpack.Marshal(netMsg)
if err != nil {
logger.LOG.Error("parse net msg to bin error: %v", err)
logger.Error("parse net msg to bin error: %v", err)
continue
}
natsMsg := nats.NewMsg("GATE_CMD_HK4E")
natsMsg.Data = netMsgData
err = m.natsConn.PublishMsg(natsMsg)
if err != nil {
logger.LOG.Error("nats publish msg error: %v", err)
logger.Error("nats publish msg error: %v", err)
continue
}
}

View File

@@ -15,7 +15,7 @@ type GMService struct {
}
func (s *GMService) Cmd(ctx context.Context, req *api.CmdRequest) (*api.CmdReply, error) {
//TODO implement me
// TODO implement me
fmt.Println("Cmd", req.FuncName, req.Param)
return &api.CmdReply{
Message: "TODO",