From f4802e1448b499035e2d06a592cd987d80d7a762 Mon Sep 17 00:00:00 2001 From: flswld Date: Mon, 27 Mar 2023 19:43:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=AA=E7=89=A9=E6=AD=BB=E4=BA=A1=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdconf/game_data_config.go | 2 +- gs/game/command_gm.go | 23 ++++++++++ gs/game/game_manager.go | 6 +-- gs/game/lua_func.go | 81 ++++++++++++++++++++++++++++++++++++ gs/game/player_fight_sync.go | 2 +- gs/game/player_scene.go | 46 ++++++++++++++++++-- 6 files changed, 151 insertions(+), 9 deletions(-) diff --git a/gdconf/game_data_config.go b/gdconf/game_data_config.go index 745787ca..1f95bc0e 100644 --- a/gdconf/game_data_config.go +++ b/gdconf/game_data_config.go @@ -353,7 +353,7 @@ func getSceneLuaConfigTable[T any](luaState *lua.LState, tableName string, objec luaValue := luaState.GetGlobal(tableName) table, ok := luaValue.(*lua.LTable) if !ok { - logger.Debug("get lua table error, table name: %v, lua type: %v", tableName, luaValue.Type().String()) + // logger.Debug("get lua table error, table name: %v, lua type: %v", tableName, luaValue.Type().String()) return true } tableObject := convLuaValueToGo(table) diff --git a/gs/game/command_gm.go b/gs/game/command_gm.go index 3d116919..0f038387 100644 --- a/gs/game/command_gm.go +++ b/gs/game/command_gm.go @@ -182,6 +182,29 @@ func (g *GMCmd) GMForceFinishAllQuest(userId uint32) { GAME_MANAGER.AcceptQuest(player, true) } +func (g *GMCmd) GMUnlockAllPoint(userId uint32, sceneId uint32) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + dbWorld := player.GetDbWorld() + dbScene := dbWorld.GetSceneById(sceneId) + if dbScene == nil { + logger.Error("db scene is nil, uid: %v", sceneId) + return + } + scenePointMapConfig := gdconf.GetScenePointMapBySceneId(int32(sceneId)) + for _, pointData := range scenePointMapConfig { + dbScene.UnlockPoint(uint32(pointData.Id)) + } + GAME_MANAGER.SendMsg(cmd.ScenePointUnlockNotify, player.PlayerID, player.ClientSeq, &proto.ScenePointUnlockNotify{ + SceneId: sceneId, + PointList: dbScene.GetUnlockPointList(), + UnhidePointList: nil, + }) +} + // 系统级GM指令 func (g *GMCmd) ChangePlayerCmdPerm(userId uint32, cmdPerm uint8) { diff --git a/gs/game/game_manager.go b/gs/game/game_manager.go index 723a620a..18c7b452 100644 --- a/gs/game/game_manager.go +++ b/gs/game/game_manager.go @@ -1,7 +1,6 @@ package game import ( - "encoding/json" "runtime" "time" @@ -170,9 +169,10 @@ func (g *GameManager) gameMainLoop() { logger.Error("!!! GAME MAIN LOOP PANIC !!!") logger.Error("error: %v", err) logger.Error("stack: %v", logger.Stack()) - motherfuckerPlayerInfo, _ := json.Marshal(SELF) - logger.Error("the motherfucker player info: %v", string(motherfuckerPlayerInfo)) if SELF != nil { + logger.Error("the motherfucker player uid: %v", SELF.PlayerID) + // info, _ := json.Marshal(SELF) + // logger.Error("the motherfucker player info: %v", string(info)) GAME_MANAGER.KickPlayer(SELF.PlayerID, kcp.EnetServerKick) } } diff --git a/gs/game/lua_func.go b/gs/game/lua_func.go index 51187664..36f5cc39 100644 --- a/gs/game/lua_func.go +++ b/gs/game/lua_func.go @@ -16,6 +16,7 @@ type LuaCtx struct { ownerUid uint32 sourceEntityId uint32 targetEntityId uint32 + groupId uint32 } type LuaEvt struct { @@ -37,6 +38,7 @@ func CallLuaFunc(luaState *lua.LState, luaFuncName string, luaCtx *LuaCtx, luaEv luaState.SetField(ctx, "owner_uid", lua.LNumber(luaCtx.ownerUid)) luaState.SetField(ctx, "source_entity_id", lua.LNumber(luaCtx.sourceEntityId)) luaState.SetField(ctx, "target_entity_id", lua.LNumber(luaCtx.targetEntityId)) + luaState.SetField(ctx, "groupId", lua.LNumber(luaCtx.groupId)) evt := luaState.NewTable() luaState.SetField(evt, "param1", lua.LNumber(luaEvt.param1)) luaState.SetField(evt, "param2", lua.LNumber(luaEvt.param2)) @@ -75,6 +77,8 @@ func RegLuaLibFunc() { gdconf.RegScriptLibFunc("PrintLog", PrintLog) gdconf.RegScriptLibFunc("PrintContextLog", PrintContextLog) gdconf.RegScriptLibFunc("BeginCameraSceneLook", BeginCameraSceneLook) + gdconf.RegScriptLibFunc("GetGroupMonsterCount", GetGroupMonsterCount) + gdconf.RegScriptLibFunc("ChangeGroupGadget", ChangeGroupGadget) } func GetEntityType(luaState *lua.LState) int { @@ -159,3 +163,80 @@ func BeginCameraSceneLook(luaState *lua.LState) int { luaState.Push(lua.LNumber(0)) return 1 } + +func GetGroupMonsterCount(luaState *lua.LState) int { + ctx, ok := luaState.Get(1).(*lua.LTable) + if !ok { + luaState.Push(lua.LNumber(-1)) + return 1 + } + uid, ok := luaState.GetField(ctx, "uid").(lua.LNumber) + if !ok { + luaState.Push(lua.LNumber(-1)) + return 1 + } + player := USER_MANAGER.GetOnlineUser(uint32(uid)) + if player == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } + world := WORLD_MANAGER.GetWorldByID(player.WorldId) + if world == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } + scene := world.GetSceneById(player.SceneId) + groupId, ok := luaState.GetField(ctx, "groupId").(lua.LNumber) + if !ok { + luaState.Push(lua.LNumber(-1)) + return 1 + } + group := scene.GetGroupById(uint32(groupId)) + monsterCount := 0 + for _, entity := range group.GetAllEntity() { + if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER { + monsterCount++ + } + } + luaState.Push(lua.LNumber(monsterCount)) + return 1 +} + +func ChangeGroupGadget(luaState *lua.LState) int { + ctx, ok := luaState.Get(1).(*lua.LTable) + if !ok { + luaState.Push(lua.LNumber(-1)) + return 1 + } + uid, ok := luaState.GetField(ctx, "uid").(lua.LNumber) + if !ok { + luaState.Push(lua.LNumber(-1)) + return 1 + } + player := USER_MANAGER.GetOnlineUser(uint32(uid)) + if player == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } + world := WORLD_MANAGER.GetWorldByID(player.WorldId) + if world == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } + scene := world.GetSceneById(player.SceneId) + groupId, ok := luaState.GetField(ctx, "groupId").(lua.LNumber) + if !ok { + luaState.Push(lua.LNumber(-1)) + return 1 + } + group := scene.GetGroupById(uint32(groupId)) + logger.Debug("%v", group) + gadgetInfo, ok := luaState.Get(2).(*lua.LTable) + if !ok { + luaState.Push(lua.LNumber(-1)) + return 1 + } + logger.Debug("%v", gadgetInfo) + luaState.Push(lua.LNumber(0)) + return 1 +} diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index 3a2190d4..ea97d78f 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -132,7 +132,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p } g.EntityFightPropUpdateNotifyBroadcast(world, target) if currHp == 0 && target.GetEntityType() == constant.ENTITY_TYPE_MONSTER { - g.KillEntity(scene, target.GetId(), proto.PlayerDieType_PLAYER_DIE_GM) + g.KillEntity(player, scene, target.GetId(), proto.PlayerDieType_PLAYER_DIE_GM) } combatData, err := pb.Marshal(evtBeingHitInfo) if err != nil { diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 82ab2fd8..7388665b 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -353,7 +353,7 @@ func (g *GameManager) SceneEntityDrownReq(player *model.Player, payloadMsg pb.Me return } scene := world.GetSceneById(player.SceneId) - g.KillEntity(scene, req.EntityId, proto.PlayerDieType_PLAYER_DIE_DRAWN) + g.KillEntity(player, scene, req.EntityId, proto.PlayerDieType_PLAYER_DIE_DRAWN) sceneEntityDrownRsp := &proto.SceneEntityDrownRsp{ EntityId: req.EntityId, @@ -538,8 +538,11 @@ func (g *GameManager) RevivePlayerAvatar(player *model.Player) { g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf) } -func (g *GameManager) KillEntity(scene *Scene, entityId uint32, dieType proto.PlayerDieType) { +func (g *GameManager) KillEntity(player *model.Player, scene *Scene, entityId uint32, dieType proto.PlayerDieType) { entity := scene.GetEntity(entityId) + if entity == nil { + return + } entity.lifeState = constant.LIFE_STATE_DEAD // 设置血量 entity.fightProp[constant.FIGHT_PROP_CUR_HP] = 0 @@ -551,10 +554,45 @@ func (g *GameManager) KillEntity(scene *Scene, entityId uint32, dieType proto.Pl MoveReliableSeq: entity.lastMoveReliableSeq, } g.SendToWorldA(scene.world, cmd.LifeStateChangeNotify, 0, ntf) - + g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_DIE, []uint32{entity.id}) // 删除实体 scene.DestroyEntity(entity.id) - g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_DIE, []uint32{entity.id}) + + if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER { + for groupId, group := range scene.GetAllGroup() { + groupConfig := gdconf.GetSceneGroup(int32(groupId)) + if groupConfig == nil { + continue + } + for suiteId := range group.GetAllSuite() { + suiteConfig := groupConfig.SuiteList[suiteId-1] + for _, triggerName := range suiteConfig.TriggerNameList { + triggerConfig := groupConfig.TriggerMap[triggerName] + if triggerConfig.Event != constant.LUA_EVENT_ANY_MONSTER_DIE { + continue + } + if triggerConfig.Condition != "" { + cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition, + &LuaCtx{uid: player.PlayerID}, + &LuaEvt{targetEntityId: entityId}) + if !cond { + continue + } + } + logger.Debug("scene group trigger fire, trigger: %v, uid: %v", triggerConfig, player.PlayerID) + if triggerConfig.Action != "" { + logger.Debug("scene group trigger do action, trigger: %v, uid: %v", triggerConfig, player.PlayerID) + ok := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Action, + &LuaCtx{uid: player.PlayerID, groupId: entity.groupId}, + &LuaEvt{}) + if !ok { + logger.Error("trigger action fail, trigger: %v, uid: %v", triggerConfig, player.PlayerID) + } + } + } + } + } + } } func (g *GameManager) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]*Entity {