mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
实现主线任务[异常的权柄]
This commit is contained in:
@@ -21,6 +21,7 @@ const (
|
||||
type UserTimer struct {
|
||||
timer *time.Timer
|
||||
action int
|
||||
data []any
|
||||
}
|
||||
|
||||
type UserTick struct {
|
||||
@@ -67,7 +68,7 @@ func (t *TickManager) DestroyUserGlobalTick(userId uint32) {
|
||||
}
|
||||
|
||||
// CreateUserTimer 创建玩家定时任务
|
||||
func (t *TickManager) CreateUserTimer(userId uint32, action int, delay uint32) {
|
||||
func (t *TickManager) CreateUserTimer(userId uint32, action int, delay uint32, data ...any) {
|
||||
userTick, exist := t.userTickMap[userId]
|
||||
if !exist {
|
||||
logger.Error("user not exist, uid: %v", userId)
|
||||
@@ -77,6 +78,7 @@ func (t *TickManager) CreateUserTimer(userId uint32, action int, delay uint32) {
|
||||
userTick.timerMap[userTick.timerIdCounter] = &UserTimer{
|
||||
timer: time.NewTimer(time.Second * time.Duration(delay)),
|
||||
action: action,
|
||||
data: data,
|
||||
}
|
||||
logger.Debug("create user timer, uid: %v, action: %v, time: %v",
|
||||
userId, action, time.Now().Add(time.Second*time.Duration(delay)).Format("2006-01-02 15:04:05"))
|
||||
@@ -103,12 +105,22 @@ func (t *TickManager) onUserTickMinute(userId uint32, now int64) {
|
||||
|
||||
const (
|
||||
UserTimerActionTest = iota
|
||||
UserTimerActionLuaCreateMonster
|
||||
)
|
||||
|
||||
func (t *TickManager) userTimerHandle(userId uint32, action int) {
|
||||
func (t *TickManager) userTimerHandle(userId uint32, action int, data []any) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
return
|
||||
}
|
||||
switch action {
|
||||
case UserTimerActionTest:
|
||||
logger.Debug("UserTimerActionTest, uid: %v", userId)
|
||||
logger.Debug("UserTimerActionTest, data: %v, uid: %v", data[0], userId)
|
||||
case UserTimerActionLuaCreateMonster:
|
||||
logger.Debug("UserTimerActionLuaCreateMonster, groupId: %v, monsterConfigId: %v, uid: %v", data[0], data[1], userId)
|
||||
groupId := data[0].(uint32)
|
||||
monsterConfigId := data[1].(uint32)
|
||||
GAME.AddSceneGroupMonster(player, groupId, monsterConfigId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +180,7 @@ func (t *TickManager) OnGameServerTick() {
|
||||
<-timer.timer.C
|
||||
timer.timer.Stop()
|
||||
delete(userTick.timerMap, timerId)
|
||||
t.userTimerHandle(userId, timer.action)
|
||||
t.userTimerHandle(userId, timer.action, timer.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,6 +304,33 @@ func (s *Scene) GetEntity(entityId uint32) *Entity {
|
||||
return s.entityMap[entityId]
|
||||
}
|
||||
|
||||
func (s *Scene) AddGroupSuiteMonster(groupId uint32, suiteId uint8, monsterConfigId uint32) uint32 {
|
||||
group, exist := s.groupMap[groupId]
|
||||
if !exist {
|
||||
logger.Error("group not exist, groupId: %v", groupId)
|
||||
return 0
|
||||
}
|
||||
suite, exist := group.suiteMap[suiteId]
|
||||
if !exist {
|
||||
logger.Error("suite not exist, suiteId: %v", suiteId)
|
||||
return 0
|
||||
}
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get scene group config is nil, groupId: %v", groupId)
|
||||
return 0
|
||||
}
|
||||
monsterConfig, exist := groupConfig.MonsterMap[int32(monsterConfigId)]
|
||||
if !exist {
|
||||
logger.Error("monster config not exist, monsterConfigId: %v", monsterConfigId)
|
||||
return 0
|
||||
}
|
||||
entityId := s.createConfigEntity(uint32(groupConfig.Id), monsterConfig)
|
||||
entity := s.GetEntity(entityId)
|
||||
suite.entityMap[entityId] = entity
|
||||
return entityId
|
||||
}
|
||||
|
||||
func (s *Scene) AddGroupSuite(groupId uint32, suiteId uint8) {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
@@ -320,27 +347,27 @@ func (s *Scene) AddGroupSuite(groupId uint32, suiteId uint8) {
|
||||
entityMap: make(map[uint32]*Entity),
|
||||
}
|
||||
for _, monsterConfigId := range suiteConfig.MonsterConfigIdList {
|
||||
monster, exist := groupConfig.MonsterMap[monsterConfigId]
|
||||
monsterConfig, exist := groupConfig.MonsterMap[monsterConfigId]
|
||||
if !exist {
|
||||
logger.Error("monster config not exist, monsterConfigId: %v", monsterConfigId)
|
||||
continue
|
||||
}
|
||||
entityId := s.createConfigEntity(uint32(groupConfig.Id), monster)
|
||||
entityId := s.createConfigEntity(uint32(groupConfig.Id), monsterConfig)
|
||||
entity := s.GetEntity(entityId)
|
||||
suite.entityMap[entityId] = entity
|
||||
}
|
||||
for _, gadgetConfigId := range suiteConfig.GadgetConfigIdList {
|
||||
gadget, exist := groupConfig.GadgetMap[gadgetConfigId]
|
||||
gadgetConfig, exist := groupConfig.GadgetMap[gadgetConfigId]
|
||||
if !exist {
|
||||
logger.Error("gadget config not exist, gadgetConfigId: %v", gadgetConfigId)
|
||||
continue
|
||||
}
|
||||
entityId := s.createConfigEntity(uint32(groupConfig.Id), gadget)
|
||||
entityId := s.createConfigEntity(uint32(groupConfig.Id), gadgetConfig)
|
||||
entity := s.GetEntity(entityId)
|
||||
suite.entityMap[entityId] = entity
|
||||
}
|
||||
for _, npc := range groupConfig.NpcMap {
|
||||
entityId := s.createConfigEntity(uint32(groupConfig.Id), npc)
|
||||
for _, npcConfig := range groupConfig.NpcMap {
|
||||
entityId := s.createConfigEntity(uint32(groupConfig.Id), npcConfig)
|
||||
entity := s.GetEntity(entityId)
|
||||
suite.entityMap[entityId] = entity
|
||||
}
|
||||
|
||||
@@ -112,6 +112,8 @@ func RegLuaScriptLibFunc() {
|
||||
gdconf.RegScriptLibFunc("ChangeGroupGadget", ChangeGroupGadget)
|
||||
gdconf.RegScriptLibFunc("SetGadgetStateByConfigId", SetGadgetStateByConfigId)
|
||||
gdconf.RegScriptLibFunc("MarkPlayerAction", MarkPlayerAction)
|
||||
gdconf.RegScriptLibFunc("AddQuestProgress", AddQuestProgress)
|
||||
gdconf.RegScriptLibFunc("CreateMonster", CreateMonster)
|
||||
}
|
||||
|
||||
func GetEntityType(luaState *lua.LState) int {
|
||||
@@ -284,3 +286,54 @@ func MarkPlayerAction(luaState *lua.LState) int {
|
||||
luaState.Push(lua.LNumber(0))
|
||||
return 1
|
||||
}
|
||||
|
||||
func AddQuestProgress(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
|
||||
}
|
||||
complexParam := luaState.ToString(2)
|
||||
GAME.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_LUA_NOTIFY, complexParam)
|
||||
luaState.Push(lua.LNumber(0))
|
||||
return 1
|
||||
}
|
||||
|
||||
type CreateMonsterInfo struct {
|
||||
ConfigId int32 `json:"config_id"`
|
||||
DelayTime int32 `json:"delay_time"`
|
||||
}
|
||||
|
||||
func CreateMonster(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, ok := luaState.GetField(ctx, "groupId").(lua.LNumber)
|
||||
if !ok {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
createMonsterInfoTable, ok := luaState.Get(2).(*lua.LTable)
|
||||
if !ok {
|
||||
luaState.Push(lua.LNumber(-1))
|
||||
return 1
|
||||
}
|
||||
createMonsterInfo := new(CreateMonsterInfo)
|
||||
gdconf.ParseLuaTableToObject[*CreateMonsterInfo](createMonsterInfoTable, createMonsterInfo)
|
||||
TICK_MANAGER.CreateUserTimer(player.PlayerID, UserTimerActionLuaCreateMonster, uint32(createMonsterInfo.DelayTime),
|
||||
uint32(groupId), uint32(createMonsterInfo.ConfigId))
|
||||
luaState.Push(lua.LNumber(0))
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -42,16 +42,8 @@ func (g *Game) SceneRegionTriggerCheck(player *model.Player, scene *Scene, oldPo
|
||||
shape.NewPolygon(&alg.Vector3{X: regionConfig.Pos.X, Y: regionConfig.Pos.Y, Z: regionConfig.Pos.Z},
|
||||
vector2PointArray, regionConfig.Height)
|
||||
}
|
||||
oldPosInRegion := shape.Contain(&alg.Vector3{
|
||||
X: float32(oldPos.X),
|
||||
Y: float32(oldPos.Y),
|
||||
Z: float32(oldPos.Z),
|
||||
})
|
||||
newPosInRegion := shape.Contain(&alg.Vector3{
|
||||
X: float32(newPos.X),
|
||||
Y: float32(newPos.Y),
|
||||
Z: float32(newPos.Z),
|
||||
})
|
||||
oldPosInRegion := shape.Contain(&alg.Vector3{X: float32(oldPos.X), Y: float32(oldPos.Y), Z: float32(oldPos.Z)})
|
||||
newPosInRegion := shape.Contain(&alg.Vector3{X: float32(newPos.X), Y: float32(newPos.Y), Z: float32(newPos.Z)})
|
||||
if !oldPosInRegion && newPosInRegion {
|
||||
logger.Debug("player enter region: %v, uid: %v", regionConfig, player.PlayerID)
|
||||
for _, triggerName := range suiteConfig.TriggerNameList {
|
||||
@@ -150,3 +142,46 @@ func (g *Game) MonsterDieTriggerCheck(player *model.Player, groupId uint32, grou
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// QuestStartTriggerCheck 任务开始触发器检测
|
||||
func (g *Game) QuestStartTriggerCheck(player *model.Player, questId uint32) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
for groupId, group := range scene.GetAllGroup() {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get group config is nil, groupId: %v, uid: %v", groupId, player.PlayerID)
|
||||
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_QUEST_START {
|
||||
continue
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID},
|
||||
&LuaEvt{param1: int32(questId)})
|
||||
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: groupId},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ func (g *Game) OnLoginOk(userId uint32, clientSeq uint32, gateAppId string, isRe
|
||||
})
|
||||
|
||||
TICK_MANAGER.CreateUserGlobalTick(userId)
|
||||
TICK_MANAGER.CreateUserTimer(userId, UserTimerActionTest, 100)
|
||||
TICK_MANAGER.CreateUserTimer(userId, UserTimerActionTest, 100, player.NickName)
|
||||
|
||||
atomic.AddInt32(&ONLINE_PLAYER_NUM, 1)
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"hk4e/common/constant"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
@@ -127,8 +130,6 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
|
||||
}
|
||||
if canAccept {
|
||||
dbQuest.AddQuest(uint32(questData.QuestId))
|
||||
// TODO 判断任务是否能开始执行
|
||||
dbQuest.ExecQuest(uint32(questData.QuestId))
|
||||
addQuestIdList = append(addQuestIdList, uint32(questData.QuestId))
|
||||
}
|
||||
}
|
||||
@@ -144,9 +145,58 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
|
||||
ntf.QuestList = append(ntf.QuestList, pbQuest)
|
||||
}
|
||||
g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
// TODO 判断任务是否能开始
|
||||
for _, questId := range addQuestIdList {
|
||||
g.StartQuest(player, questId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// StartQuest 开始一个任务
|
||||
func (g *Game) StartQuest(player *model.Player, questId uint32) {
|
||||
dbQuest := player.GetDbQuest()
|
||||
dbQuest.StartQuest(questId)
|
||||
ntf := &proto.QuestListUpdateNotify{
|
||||
QuestList: make([]*proto.Quest, 0),
|
||||
}
|
||||
pbQuest := g.PacketQuest(player, questId)
|
||||
if pbQuest == nil {
|
||||
return
|
||||
}
|
||||
ntf.QuestList = append(ntf.QuestList, pbQuest)
|
||||
g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
g.QuestExec(player, questId)
|
||||
g.QuestStartTriggerCheck(player, questId)
|
||||
}
|
||||
|
||||
// QuestExec 任务开始执行触发操作
|
||||
func (g *Game) QuestExec(player *model.Player, questId uint32) {
|
||||
questDataConfig := gdconf.GetQuestDataById(int32(questId))
|
||||
if questDataConfig == nil {
|
||||
return
|
||||
}
|
||||
for _, questExec := range questDataConfig.StartExecList {
|
||||
switch questExec.Type {
|
||||
case constant.QUEST_EXEC_TYPE_NOTIFY_GROUP_LUA:
|
||||
case constant.QUEST_EXEC_TYPE_REFRESH_GROUP_SUITE:
|
||||
if len(questExec.Param) != 2 {
|
||||
continue
|
||||
}
|
||||
split := strings.Split(questExec.Param[1], ",")
|
||||
groupId, err := strconv.Atoi(split[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
suiteId, err := strconv.Atoi(split[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
g.AddSceneGroupSuite(player, uint32(groupId), uint8(suiteId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 通用参数匹配
|
||||
func matchParamEqual(param1 []int32, param2 []int32, num int) bool {
|
||||
if len(param1) != num || len(param2) != num {
|
||||
return false
|
||||
@@ -204,6 +254,14 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin
|
||||
}
|
||||
dbQuest.ForceFinishQuest(quest.QuestId)
|
||||
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
|
||||
case constant.QUEST_FINISH_COND_TYPE_SKILL:
|
||||
// 使用技能 参数1:技能id
|
||||
ok := matchParamEqual(questCond.Param, param, 1)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
dbQuest.ForceFinishQuest(quest.QuestId)
|
||||
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,6 +366,7 @@ func (g *Game) SceneEntityDrownReq(player *model.Player, payloadMsg pb.Message)
|
||||
g.SendMsg(cmd.SceneEntityDrownRsp, player.PlayerID, player.ClientSeq, sceneEntityDrownRsp)
|
||||
}
|
||||
|
||||
// AddSceneEntityNotifyToPlayer 添加的场景实体同步给玩家
|
||||
func (g *Game) AddSceneEntityNotifyToPlayer(player *model.Player, visionType proto.VisionType, entityList []*proto.SceneEntityInfo) {
|
||||
sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{
|
||||
AppearType: visionType,
|
||||
@@ -376,6 +377,7 @@ func (g *Game) AddSceneEntityNotifyToPlayer(player *model.Player, visionType pro
|
||||
player.PlayerID, sceneEntityAppearNotify.AppearType, len(sceneEntityAppearNotify.EntityList))
|
||||
}
|
||||
|
||||
// AddSceneEntityNotifyBroadcast 添加的场景实体广播
|
||||
func (g *Game) AddSceneEntityNotifyBroadcast(player *model.Player, scene *Scene, visionType proto.VisionType, entityList []*proto.SceneEntityInfo, aec bool) {
|
||||
sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{
|
||||
AppearType: visionType,
|
||||
@@ -391,6 +393,7 @@ func (g *Game) AddSceneEntityNotifyBroadcast(player *model.Player, scene *Scene,
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveSceneEntityNotifyToPlayer 移除的场景实体同步给玩家
|
||||
func (g *Game) RemoveSceneEntityNotifyToPlayer(player *model.Player, visionType proto.VisionType, entityIdList []uint32) {
|
||||
sceneEntityDisappearNotify := &proto.SceneEntityDisappearNotify{
|
||||
EntityList: entityIdList,
|
||||
@@ -401,6 +404,7 @@ func (g *Game) RemoveSceneEntityNotifyToPlayer(player *model.Player, visionType
|
||||
player.PlayerID, sceneEntityDisappearNotify.DisappearType, len(sceneEntityDisappearNotify.EntityList))
|
||||
}
|
||||
|
||||
// RemoveSceneEntityNotifyBroadcast 移除的场景实体广播
|
||||
func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityIdList []uint32) {
|
||||
sceneEntityDisappearNotify := &proto.SceneEntityDisappearNotify{
|
||||
EntityList: entityIdList,
|
||||
@@ -413,6 +417,7 @@ func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.V
|
||||
}
|
||||
}
|
||||
|
||||
// AddSceneEntityNotify 添加的场景实体同步 封装接口
|
||||
func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.VisionType, entityIdList []uint32, broadcast bool, aec bool) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
@@ -471,6 +476,7 @@ func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.Visio
|
||||
}
|
||||
}
|
||||
|
||||
// EntityFightPropUpdateNotifyBroadcast 场景实体战斗属性变更通知广播
|
||||
func (g *Game) EntityFightPropUpdateNotifyBroadcast(world *World, entity *Entity) {
|
||||
ntf := &proto.EntityFightPropUpdateNotify{
|
||||
FightPropMap: entity.GetFightProp(),
|
||||
@@ -479,6 +485,7 @@ func (g *Game) EntityFightPropUpdateNotifyBroadcast(world *World, entity *Entity
|
||||
g.SendToWorldA(world, cmd.EntityFightPropUpdateNotify, 0, ntf)
|
||||
}
|
||||
|
||||
// KillPlayerAvatar 杀死玩家活跃角色实体
|
||||
func (g *Game) KillPlayerAvatar(player *model.Player, dieType proto.PlayerDieType) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
@@ -510,6 +517,7 @@ func (g *Game) KillPlayerAvatar(player *model.Player, dieType proto.PlayerDieTyp
|
||||
g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf)
|
||||
}
|
||||
|
||||
// RevivePlayerAvatar 复活玩家活跃角色实体
|
||||
func (g *Game) RevivePlayerAvatar(player *model.Player) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
@@ -543,6 +551,7 @@ func (g *Game) RevivePlayerAvatar(player *model.Player) {
|
||||
g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf)
|
||||
}
|
||||
|
||||
// KillEntity 杀死实体
|
||||
func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, dieType proto.PlayerDieType) {
|
||||
entity := scene.GetEntity(entityId)
|
||||
if entity == nil {
|
||||
@@ -577,6 +586,7 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
|
||||
}
|
||||
}
|
||||
|
||||
// ChangeGadgetState 改变物件实体状态
|
||||
func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state uint32) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
@@ -603,6 +613,7 @@ func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state ui
|
||||
g.SendMsg(cmd.GadgetStateNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
// GetVisionEntity 获取某位置视野内的全部实体
|
||||
func (g *Game) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]*Entity {
|
||||
visionEntity := make(map[uint32]*Entity)
|
||||
for _, entity := range scene.GetAllEntity() {
|
||||
@@ -615,6 +626,7 @@ func (g *Game) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]*Enti
|
||||
return visionEntity
|
||||
}
|
||||
|
||||
// GetNeighborGroup 获取某位置附近的场景组
|
||||
func (g *Game) GetNeighborGroup(sceneId uint32, pos *model.Vector) map[uint32]*gdconf.Group {
|
||||
aoiManager, exist := WORLD_MANAGER.GetSceneBlockAoiMap()[sceneId]
|
||||
if !exist {
|
||||
@@ -637,6 +649,7 @@ func (g *Game) GetNeighborGroup(sceneId uint32, pos *model.Vector) map[uint32]*g
|
||||
return neighborGroup
|
||||
}
|
||||
|
||||
// AddSceneGroup 加载场景组
|
||||
func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gdconf.Group) {
|
||||
initSuiteId := int(groupConfig.GroupInitConfig.Suite)
|
||||
if initSuiteId < 1 || initSuiteId > len(groupConfig.SuiteList) {
|
||||
@@ -651,6 +664,7 @@ func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gd
|
||||
g.SendMsg(cmd.GroupSuiteNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
// RemoveSceneGroup 卸载场景组
|
||||
func (g *Game) RemoveSceneGroup(player *model.Player, scene *Scene, groupConfig *gdconf.Group) {
|
||||
group := scene.GetGroupById(uint32(groupConfig.Id))
|
||||
if group == nil {
|
||||
@@ -667,6 +681,58 @@ func (g *Game) RemoveSceneGroup(player *model.Player, scene *Scene, groupConfig
|
||||
g.SendMsg(cmd.GroupUnloadNotify, player.PlayerID, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
if suiteId < 1 || suiteId > uint8(len(groupConfig.SuiteList)) {
|
||||
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)
|
||||
scene.AddGroupSuite(uint32(groupConfig.Id), 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, monsterConfigId uint32) {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get group config is nil, groupId: %v, uid: %v", groupId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
initSuiteId := int(groupConfig.GroupInitConfig.Suite)
|
||||
if initSuiteId < 1 || initSuiteId > len(groupConfig.SuiteList) {
|
||||
logger.Error("invalid init suite id: %v, uid: %v", initSuiteId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v", player.WorldId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
entityId := scene.AddGroupSuiteMonster(groupId, uint8(initSuiteId), monsterConfigId)
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
|
||||
}
|
||||
|
||||
// CreateDropGadget 创建掉落物的物件实体
|
||||
func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetId, itemId, count uint32) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
@@ -690,6 +756,8 @@ func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetI
|
||||
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
|
||||
}
|
||||
|
||||
// 打包相关封装函数
|
||||
|
||||
var SceneTransactionSeq uint32 = 0
|
||||
|
||||
func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player, enterType proto.EnterType) *proto.PlayerEnterSceneNotify {
|
||||
|
||||
@@ -62,8 +62,8 @@ func (q *DbQuest) AddQuest(questId uint32) {
|
||||
}
|
||||
}
|
||||
|
||||
// ExecQuest 开始执行一个任务
|
||||
func (q *DbQuest) ExecQuest(questId uint32) {
|
||||
// StartQuest 开始执行一个任务
|
||||
func (q *DbQuest) StartQuest(questId uint32) {
|
||||
quest, exist := q.QuestMap[questId]
|
||||
if !exist {
|
||||
logger.Error("get quest is nil, questId: %v", questId)
|
||||
|
||||
Reference in New Issue
Block a user