怪物死亡触发器

This commit is contained in:
flswld
2023-03-27 19:43:41 +08:00
parent f1a14ccf0e
commit f4802e1448
6 changed files with 151 additions and 9 deletions

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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 {