mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2025-12-19 18:32:23 +08:00
整理代码
This commit is contained in:
@@ -290,12 +290,14 @@ func initLuaState(luaState *lua.LState) {
|
||||
luaState.SetField(eventType, "EVENT_NONE", lua.LNumber(constant.LUA_EVENT_NONE))
|
||||
luaState.SetField(eventType, "EVENT_ENTER_REGION", lua.LNumber(constant.LUA_EVENT_ENTER_REGION))
|
||||
luaState.SetField(eventType, "EVENT_LEAVE_REGION", lua.LNumber(constant.LUA_EVENT_LEAVE_REGION))
|
||||
luaState.SetField(eventType, "EVENT_ANY_MONSTER_DIE", lua.LNumber(constant.LUA_EVENT_ANY_MONSTER_DIE))
|
||||
luaState.SetField(eventType, "EVENT_ANY_MONSTER_LIVE", lua.LNumber(constant.LUA_EVENT_ANY_MONSTER_LIVE))
|
||||
luaState.SetField(eventType, "EVENT_QUEST_START", lua.LNumber(constant.LUA_EVENT_QUEST_START))
|
||||
luaState.SetField(eventType, "EVENT_ANY_MONSTER_LIVE", lua.LNumber(constant.LUA_EVENT_ANY_MONSTER_LIVE))
|
||||
luaState.SetField(eventType, "EVENT_ANY_MONSTER_DIE", lua.LNumber(constant.LUA_EVENT_ANY_MONSTER_DIE))
|
||||
luaState.SetField(eventType, "EVENT_GADGET_CREATE", lua.LNumber(constant.LUA_EVENT_GADGET_CREATE))
|
||||
luaState.SetField(eventType, "EVENT_GADGET_STATE_CHANGE", lua.LNumber(constant.LUA_EVENT_GADGET_STATE_CHANGE))
|
||||
luaState.SetField(eventType, "EVENT_ANY_GADGET_DIE", lua.LNumber(constant.LUA_EVENT_ANY_GADGET_DIE))
|
||||
luaState.SetField(eventType, "EVENT_GROUP_LOAD", lua.LNumber(constant.LUA_EVENT_GROUP_LOAD))
|
||||
luaState.SetField(eventType, "EVENT_TIMER_EVENT", lua.LNumber(constant.LUA_EVENT_TIMER_EVENT))
|
||||
|
||||
entityType := luaState.NewTable()
|
||||
luaState.SetGlobal("EntityType", entityType)
|
||||
|
||||
@@ -235,18 +235,24 @@ func (g *GMCmd) GMUnlockAllPoint(userId uint32, sceneId uint32) {
|
||||
})
|
||||
}
|
||||
|
||||
// GMCreateGadget 在玩家附近创建物件实体
|
||||
func (g *GMCmd) GMCreateGadget(userId uint32, posX, posY, posZ float64, gadgetId uint32) {
|
||||
// GMCreateMonster 在玩家附近创建怪物
|
||||
func (g *GMCmd) GMCreateMonster(userId uint32, monsterId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
GAME.CreateGadget(player, &model.Vector{
|
||||
X: posX,
|
||||
Y: posY,
|
||||
Z: posZ,
|
||||
}, gadgetId, nil)
|
||||
GAME.CreateMonster(player, nil, monsterId)
|
||||
}
|
||||
|
||||
// GMCreateGadget 在玩家附近创建物件
|
||||
func (g *GMCmd) GMCreateGadget(userId uint32, gadgetId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
GAME.CreateGadget(player, nil, gadgetId, nil)
|
||||
}
|
||||
|
||||
// 系统级GM指令
|
||||
|
||||
@@ -3,6 +3,7 @@ package game
|
||||
import (
|
||||
"time"
|
||||
|
||||
"hk4e/common/constant"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/logger"
|
||||
@@ -108,6 +109,7 @@ func (t *TickManager) onUserTickMinute(userId uint32, now int64) {
|
||||
const (
|
||||
UserTimerActionTest = iota
|
||||
UserTimerActionLuaCreateMonster
|
||||
UserTimerActionLuaGroupTimerEvent
|
||||
)
|
||||
|
||||
func (t *TickManager) userTimerHandle(userId uint32, action int, data []any) {
|
||||
@@ -122,7 +124,23 @@ func (t *TickManager) userTimerHandle(userId uint32, action int, data []any) {
|
||||
logger.Debug("UserTimerActionLuaCreateMonster, groupId: %v, configId: %v, uid: %v", data[0], data[1], userId)
|
||||
groupId := data[0].(uint32)
|
||||
configId := data[1].(uint32)
|
||||
GAME.AddSceneGroupMonster(player, groupId, configId)
|
||||
GAME.SceneGroupCreateEntity(player, groupId, configId, constant.ENTITY_TYPE_MONSTER)
|
||||
case UserTimerActionLuaGroupTimerEvent:
|
||||
logger.Debug("UserTimerActionLuaGroupTimerEvent, groupId: %v, source: %v, uid: %v", data[0], data[1], userId)
|
||||
groupId := data[0].(uint32)
|
||||
source := data[1].(string)
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, userId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
group := scene.GetGroupById(groupId)
|
||||
if group == nil {
|
||||
logger.Error("get group is nil, groupId: %v, uid: %v", groupId, userId)
|
||||
return
|
||||
}
|
||||
GAME.TimerEventTriggerCheck(player, group, source)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -312,9 +312,16 @@ func (s *Scene) AddGroupSuite(groupId uint32, suiteId uint8, entityMap map[uint3
|
||||
}
|
||||
s.groupMap[groupId] = group
|
||||
}
|
||||
group.suiteMap[suiteId] = &Suite{
|
||||
id: suiteId,
|
||||
entityMap: entityMap,
|
||||
suite, exist := group.suiteMap[suiteId]
|
||||
if !exist {
|
||||
suite = &Suite{
|
||||
id: suiteId,
|
||||
entityMap: make(map[uint32]*Entity),
|
||||
}
|
||||
group.suiteMap[suiteId] = suite
|
||||
}
|
||||
for k, v := range entityMap {
|
||||
suite.entityMap[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,12 @@ import (
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxCallLuaFuncLoopCount = 10 // 调用LUA方法递归层数限制
|
||||
)
|
||||
|
||||
var CallLuaFuncLoopCount = 0
|
||||
|
||||
type LuaCtx struct {
|
||||
uid uint32
|
||||
ownerUid uint32
|
||||
@@ -36,6 +42,14 @@ type LuaEvt struct {
|
||||
|
||||
// CallLuaFunc 调用LUA方法
|
||||
func CallLuaFunc(luaState *lua.LState, luaFuncName string, luaCtx *LuaCtx, luaEvt *LuaEvt) bool {
|
||||
if CallLuaFuncLoopCount > MaxCallLuaFuncLoopCount {
|
||||
logger.Error("above max call lua func loop count, stack: %v", logger.Stack())
|
||||
return false
|
||||
}
|
||||
CallLuaFuncLoopCount++
|
||||
defer func() {
|
||||
CallLuaFuncLoopCount--
|
||||
}()
|
||||
ctx := luaState.NewTable()
|
||||
luaState.SetField(ctx, "uid", lua.LNumber(luaCtx.uid))
|
||||
luaState.SetField(ctx, "owner_uid", lua.LNumber(luaCtx.ownerUid))
|
||||
@@ -59,7 +73,7 @@ func CallLuaFunc(luaState *lua.LState, luaFuncName string, luaCtx *LuaCtx, luaEv
|
||||
Protect: true,
|
||||
}, ctx, evt)
|
||||
if err != nil {
|
||||
logger.Error("call lua error, func: %v, error: %v", luaFuncName, err)
|
||||
logger.Error("call lua error, groupId: %v, func: %v, error: %v", luaCtx.groupId, luaFuncName, err)
|
||||
return false
|
||||
}
|
||||
luaRet := luaState.Get(-1)
|
||||
@@ -139,6 +153,7 @@ func RegLuaScriptLibFunc() {
|
||||
gdconf.RegScriptLibFunc("ChangeGroupVariableValue", ChangeGroupVariableValue)
|
||||
gdconf.RegScriptLibFunc("ChangeGroupVariableValueByGroup", ChangeGroupVariableValueByGroup)
|
||||
gdconf.RegScriptLibFunc("GetRegionEntityCount", GetRegionEntityCount)
|
||||
gdconf.RegScriptLibFunc("CreateGroupTimerEvent", CreateGroupTimerEvent)
|
||||
}
|
||||
|
||||
func GetEntityType(luaState *lua.LState) int {
|
||||
@@ -427,18 +442,7 @@ func CreateGadget(luaState *lua.LState) int {
|
||||
}
|
||||
luaTableParam := new(LuaTableParam)
|
||||
gdconf.ParseLuaTableToObject[*LuaTableParam](luaTable, luaTableParam)
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
gadget := groupConfig.GadgetMap[luaTableParam.ConfigId]
|
||||
if gadget == nil {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
GAME.CreateGadget(player, &model.Vector{X: float64(gadget.Pos.X), Y: float64(gadget.Pos.Y), Z: float64(gadget.Pos.Z)},
|
||||
uint32(gadget.GadgetId), nil)
|
||||
GAME.SceneGroupCreateEntity(player, uint32(groupId), uint32(luaTableParam.ConfigId), constant.ENTITY_TYPE_GADGET)
|
||||
luaState.Push(lua.LNumber(0))
|
||||
return 1
|
||||
}
|
||||
@@ -725,3 +729,23 @@ func GetRegionEntityCount(luaState *lua.LState) int {
|
||||
luaState.Push(lua.LNumber(count))
|
||||
return 1
|
||||
}
|
||||
|
||||
func CreateGroupTimerEvent(luaState *lua.LState) int {
|
||||
ctx, ok := luaState.Get(1).(*lua.LTable)
|
||||
if !ok {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
player := GetContextPlayer(ctx, luaState)
|
||||
if player == nil {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
groupId := luaState.ToInt(2)
|
||||
source := luaState.ToString(3)
|
||||
delay := luaState.ToInt(4)
|
||||
TICK_MANAGER.CreateUserTimer(player.PlayerID, UserTimerActionLuaGroupTimerEvent, uint32(delay),
|
||||
uint32(groupId), source)
|
||||
luaState.Push(lua.LNumber(0))
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func (g *Game) SceneRegionTriggerCheck(player *model.Player, oldPos *model.Vecto
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID, groupId: uint32(groupConfig.Id)},
|
||||
&LuaEvt{param1: regionConfig.ConfigId, targetEntityId: entityId})
|
||||
&LuaEvt{param1: regionConfig.ConfigId, targetEntityId: entityId, sourceEntityId: uint32(regionConfig.ConfigId)})
|
||||
if !cond {
|
||||
continue
|
||||
}
|
||||
@@ -155,16 +155,16 @@ func (g *Game) SceneRegionTriggerCheck(player *model.Player, oldPos *model.Vecto
|
||||
})
|
||||
}
|
||||
|
||||
// MonsterDieTriggerCheck 怪物死亡触发器检测
|
||||
func (g *Game) MonsterDieTriggerCheck(player *model.Player, group *Group) {
|
||||
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
if triggerConfig.Event != constant.LUA_EVENT_ANY_MONSTER_DIE {
|
||||
// QuestStartTriggerCheck 任务开始触发器检测
|
||||
func (g *Game) QuestStartTriggerCheck(player *model.Player, questId uint32) {
|
||||
forEachPlayerSceneGroupTrigger(player, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
if triggerConfig.Event != constant.LUA_EVENT_QUEST_START {
|
||||
return
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID, groupId: uint32(groupConfig.Id)},
|
||||
&LuaEvt{})
|
||||
&LuaEvt{param1: int32(questId)})
|
||||
if !cond {
|
||||
return
|
||||
}
|
||||
@@ -181,16 +181,42 @@ func (g *Game) MonsterDieTriggerCheck(player *model.Player, group *Group) {
|
||||
})
|
||||
}
|
||||
|
||||
// QuestStartTriggerCheck 任务开始触发器检测
|
||||
func (g *Game) QuestStartTriggerCheck(player *model.Player, questId uint32) {
|
||||
forEachPlayerSceneGroupTrigger(player, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
if triggerConfig.Event != constant.LUA_EVENT_QUEST_START {
|
||||
// MonsterCreateTriggerCheck 怪物创建触发器检测
|
||||
func (g *Game) MonsterCreateTriggerCheck(player *model.Player, group *Group, configId uint32) {
|
||||
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
if triggerConfig.Event != constant.LUA_EVENT_ANY_MONSTER_LIVE {
|
||||
return
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID, groupId: uint32(groupConfig.Id)},
|
||||
&LuaEvt{param1: int32(questId)})
|
||||
&LuaEvt{param1: int32(configId)})
|
||||
if !cond {
|
||||
return
|
||||
}
|
||||
}
|
||||
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: uint32(groupConfig.Id)},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// MonsterDieTriggerCheck 怪物死亡触发器检测
|
||||
func (g *Game) MonsterDieTriggerCheck(player *model.Player, group *Group) {
|
||||
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
if triggerConfig.Event != constant.LUA_EVENT_ANY_MONSTER_DIE {
|
||||
return
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID, groupId: uint32(groupConfig.Id)},
|
||||
&LuaEvt{})
|
||||
if !cond {
|
||||
return
|
||||
}
|
||||
@@ -259,6 +285,32 @@ func (g *Game) GadgetStateChangeTriggerCheck(player *model.Player, group *Group,
|
||||
})
|
||||
}
|
||||
|
||||
// GadgetDieTriggerCheck 物件死亡触发器检测
|
||||
func (g *Game) GadgetDieTriggerCheck(player *model.Player, group *Group, configId uint32) {
|
||||
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
if triggerConfig.Event != constant.LUA_EVENT_ANY_GADGET_DIE {
|
||||
return
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID, groupId: uint32(groupConfig.Id)},
|
||||
&LuaEvt{param1: int32(configId)})
|
||||
if !cond {
|
||||
return
|
||||
}
|
||||
}
|
||||
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: uint32(groupConfig.Id)},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// GroupLoadTriggerCheck 场景组加载触发器检测
|
||||
func (g *Game) GroupLoadTriggerCheck(player *model.Player, group *Group) {
|
||||
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
@@ -284,3 +336,34 @@ func (g *Game) GroupLoadTriggerCheck(player *model.Player, group *Group) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TimerEventTriggerCheck 场景组定时事件触发器检测
|
||||
func (g *Game) TimerEventTriggerCheck(player *model.Player, group *Group, source string) {
|
||||
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
|
||||
if triggerConfig.Event != constant.LUA_EVENT_TIMER_EVENT {
|
||||
return
|
||||
}
|
||||
if triggerConfig.Source != "" {
|
||||
if triggerConfig.Source != source {
|
||||
return
|
||||
}
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID, groupId: uint32(groupConfig.Id)},
|
||||
&LuaEvt{sourceName: source})
|
||||
if !cond {
|
||||
return
|
||||
}
|
||||
}
|
||||
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: uint32(groupConfig.Id)},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -623,9 +623,15 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
|
||||
dbSceneGroup.AddKill(entity.GetConfigId())
|
||||
|
||||
group.DestroyEntity(entity.GetId())
|
||||
// 怪物死亡触发器检测
|
||||
if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER {
|
||||
|
||||
// 触发器检测
|
||||
switch entity.GetEntityType() {
|
||||
case constant.ENTITY_TYPE_MONSTER:
|
||||
// 怪物死亡触发器检测
|
||||
g.MonsterDieTriggerCheck(player, group)
|
||||
case constant.ENTITY_TYPE_GADGET:
|
||||
// 物件死亡触发器检测
|
||||
g.GadgetDieTriggerCheck(player, group, entity.GetConfigId())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -724,6 +730,8 @@ func (g *Game) GetNeighborGroup(sceneId uint32, pos *model.Vector) map[uint32]*g
|
||||
return neighborGroup
|
||||
}
|
||||
|
||||
// TODO Group和Suite的初始化和加载卸载逻辑还没完全理清 所以现在这里写得略答辩
|
||||
|
||||
// AddSceneGroup 加载场景组
|
||||
func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gdconf.Group) {
|
||||
group := scene.GetGroupById(uint32(groupConfig.Id))
|
||||
@@ -763,15 +771,6 @@ func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gd
|
||||
}
|
||||
// 场景组加载触发器检测
|
||||
g.GroupLoadTriggerCheck(player, group)
|
||||
// 物件创建触发器检测
|
||||
suiteConfig, exist := groupConfig.SuiteMap[initSuiteId]
|
||||
if !exist {
|
||||
logger.Error("invalid suiteId: %v, uid: %v", initSuiteId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
for _, gadgetConfigId := range suiteConfig.GadgetConfigIdList {
|
||||
GAME.GadgetCreateTriggerCheck(player, group, uint32(gadgetConfigId))
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveSceneGroup 卸载场景组
|
||||
@@ -791,6 +790,38 @@ func (g *Game) RemoveSceneGroup(player *model.Player, scene *Scene, groupConfig
|
||||
g.SendMsg(cmd.GroupUnloadNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
// AddSceneGroupSuite 向场景组中添加场景小组
|
||||
func (g *Game) AddSceneGroupSuite(player *model.Player, groupId uint32, suiteId uint8) {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get group config is nil, groupId: %v, uid: %v", groupId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
_, exist := groupConfig.SuiteMap[int32(suiteId)]
|
||||
if !exist {
|
||||
logger.Error("invalid suite id: %v, uid: %v", suiteId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
g.AddSceneGroupSuiteCore(player, scene, groupId, suiteId)
|
||||
ntf := &proto.GroupSuiteNotify{
|
||||
GroupMap: make(map[uint32]uint32),
|
||||
}
|
||||
ntf.GroupMap[uint32(groupConfig.Id)] = uint32(suiteId)
|
||||
g.SendMsg(cmd.GroupSuiteNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
group := scene.GetGroupById(groupId)
|
||||
suite := group.GetSuiteById(suiteId)
|
||||
entityIdList := make([]uint32, 0)
|
||||
for _, entity := range suite.GetAllEntity() {
|
||||
entityIdList = append(entityIdList, entity.GetId())
|
||||
}
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, entityIdList, true, false)
|
||||
}
|
||||
|
||||
func (g *Game) AddSceneGroupSuiteCore(player *model.Player, scene *Scene, groupId uint32, suiteId uint8) {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
@@ -938,40 +969,9 @@ func getTempFightPropMap() map[uint32]float32 {
|
||||
return fpm
|
||||
}
|
||||
|
||||
// TODO Group和Suite的初始化和加载卸载逻辑还没完全理清 所以现在这里写得略答辩
|
||||
|
||||
func (g *Game) AddSceneGroupSuite(player *model.Player, groupId uint32, suiteId uint8) {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get group config is nil, groupId: %v, uid: %v", groupId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
_, exist := groupConfig.SuiteMap[int32(suiteId)]
|
||||
if !exist {
|
||||
logger.Error("invalid suite id: %v, uid: %v", suiteId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
g.AddSceneGroupSuiteCore(player, scene, groupId, suiteId)
|
||||
ntf := &proto.GroupSuiteNotify{
|
||||
GroupMap: make(map[uint32]uint32),
|
||||
}
|
||||
ntf.GroupMap[uint32(groupConfig.Id)] = uint32(suiteId)
|
||||
g.SendMsg(cmd.GroupSuiteNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
group := scene.GetGroupById(groupId)
|
||||
suite := group.GetSuiteById(suiteId)
|
||||
entityIdList := make([]uint32, 0)
|
||||
for _, entity := range suite.GetAllEntity() {
|
||||
entityIdList = append(entityIdList, entity.GetId())
|
||||
}
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, entityIdList, true, false)
|
||||
}
|
||||
|
||||
func (g *Game) AddSceneGroupMonster(player *model.Player, groupId uint32, configId uint32) {
|
||||
// SceneGroupCreateEntity 创建场景组配置物件实体
|
||||
func (g *Game) SceneGroupCreateEntity(player *model.Player, groupId uint32, configId uint32, entityType uint8) {
|
||||
// 添加到初始小组
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get group config is nil, groupId: %v, uid: %v", groupId, player.PlayerID)
|
||||
@@ -983,32 +983,78 @@ func (g *Game) AddSceneGroupMonster(player *model.Player, groupId uint32, config
|
||||
logger.Error("invalid init suite id: %v, uid: %v", initSuiteId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
// 添加场景实体
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
group, exist := scene.groupMap[groupId]
|
||||
if !exist {
|
||||
logger.Error("group not exist, groupId: %v", groupId)
|
||||
var entityConfig any = nil
|
||||
switch entityType {
|
||||
case constant.ENTITY_TYPE_MONSTER:
|
||||
monsterConfig, exist := groupConfig.MonsterMap[int32(configId)]
|
||||
if !exist {
|
||||
logger.Error("monster config not exist, configId: %v", configId)
|
||||
return
|
||||
}
|
||||
entityConfig = monsterConfig
|
||||
case constant.ENTITY_TYPE_GADGET:
|
||||
gadgetConfig, exist := groupConfig.GadgetMap[int32(configId)]
|
||||
if !exist {
|
||||
logger.Error("gadget config not exist, configId: %v", configId)
|
||||
return
|
||||
}
|
||||
entityConfig = gadgetConfig
|
||||
default:
|
||||
logger.Error("unknown entity type: %v", entityType)
|
||||
return
|
||||
}
|
||||
suite, exist := group.suiteMap[uint8(initSuiteId)]
|
||||
if !exist {
|
||||
logger.Error("suite not exist, suiteId: %v", initSuiteId)
|
||||
return
|
||||
}
|
||||
monsterConfig, exist := groupConfig.MonsterMap[int32(configId)]
|
||||
if !exist {
|
||||
logger.Error("monster config not exist, configId: %v", configId)
|
||||
return
|
||||
}
|
||||
entityId := g.CreateConfigEntity(player, scene, uint32(groupConfig.Id), monsterConfig)
|
||||
entityId := g.CreateConfigEntity(player, scene, uint32(groupConfig.Id), entityConfig)
|
||||
if entityId == 0 {
|
||||
return
|
||||
}
|
||||
entity := scene.GetEntity(entityId)
|
||||
suite.entityMap[entityId] = entity
|
||||
// 实体添加到场景小组
|
||||
scene.AddGroupSuite(groupId, uint8(initSuiteId), map[uint32]*Entity{entity.GetId(): entity})
|
||||
// 通知客户端
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
|
||||
// 触发器检测
|
||||
group := scene.GetGroupById(groupId)
|
||||
if group == nil {
|
||||
logger.Error("group not exist, groupId: %v, uid: %v", groupId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
switch entityType {
|
||||
case constant.ENTITY_TYPE_MONSTER:
|
||||
// 怪物创建触发器检测
|
||||
GAME.MonsterCreateTriggerCheck(player, group, configId)
|
||||
case constant.ENTITY_TYPE_GADGET:
|
||||
// 物件创建触发器检测
|
||||
GAME.GadgetCreateTriggerCheck(player, group, configId)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateMonster 创建怪物实体
|
||||
func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId uint32) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
if pos == nil {
|
||||
pos = &model.Vector{
|
||||
X: player.Pos.X + random.GetRandomFloat64(1.0, 10.0),
|
||||
Y: player.Pos.Y + 1.0,
|
||||
Z: player.Pos.Z + random.GetRandomFloat64(1.0, 10.0),
|
||||
}
|
||||
}
|
||||
rot := new(model.Vector)
|
||||
rot.Y = random.GetRandomFloat64(0.0, 360.0)
|
||||
entityId := scene.CreateEntityMonster(
|
||||
pos, rot,
|
||||
monsterId, uint8(random.GetRandomInt32(1, 90)), getTempFightPropMap(),
|
||||
0, 0,
|
||||
)
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
|
||||
}
|
||||
|
||||
@@ -1026,13 +1072,18 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
if pos == nil {
|
||||
pos = &model.Vector{
|
||||
X: player.Pos.X + random.GetRandomFloat64(1.0, 10.0),
|
||||
Y: player.Pos.Y + 1.0,
|
||||
Z: player.Pos.Z + random.GetRandomFloat64(1.0, 10.0),
|
||||
}
|
||||
}
|
||||
rot := new(model.Vector)
|
||||
rot.Y = random.GetRandomFloat64(0.0, 360.0)
|
||||
entityId := scene.CreateEntityGadgetNormal(
|
||||
pos, rot,
|
||||
gadgetId,
|
||||
constant.GADGET_STATE_DEFAULT,
|
||||
normalEntity,
|
||||
gadgetId, constant.GADGET_STATE_DEFAULT, normalEntity,
|
||||
0, 0,
|
||||
)
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
|
||||
|
||||
Reference in New Issue
Block a user