任务系统优化

This commit is contained in:
flswld committed 2024-06-12 18:58:22 +08:00
1 parent 8c660281e7
commit 9a78027a83
11 files changed
+256 -172

No files matched your search

+1
View File
@@ -330,6 +330,7 @@ func initLuaState(luaState *lua.LState) {
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))
luaState.SetField(eventType, "EVENT_SELECT_OPTION", lua.LNumber(constant.LUA_EVENT_SELECT_OPTION))
entityType := luaState.NewTable()
luaState.SetGlobal("EntityType", entityType)
+2
View File
@@ -316,6 +316,7 @@ func UpdateFrame(fileData []byte, basePos *model.Vector, rgb bool) {
Y: leftTopPos.Y - float64(h)*SCREEN_DPI,
Z: leftTopPos.Z,
}, new(model.Vector), 0, 0, constant.VISION_LEVEL_SUPER, uint32(FRAME_COLOR[w][h]), uint32(constant.GADGET_STATE_DEFAULT))
scene.CreateEntity(gadgetNormalEntity)
SCREEN_ENTITY_ID_LIST = append(SCREEN_ENTITY_ID_LIST, gadgetNormalEntity.GetId())
} else {
if !FRAME[w][h] {
@@ -324,6 +325,7 @@ func UpdateFrame(fileData []byte, basePos *model.Vector, rgb bool) {
Y: leftTopPos.Y - float64(h)*SCREEN_DPI,
Z: leftTopPos.Z,
}, new(model.Vector), 0, 0, constant.VISION_LEVEL_SUPER, uint32(GADGET_ID), uint32(constant.GADGET_STATE_DEFAULT))
scene.CreateEntity(gadgetNormalEntity)
SCREEN_ENTITY_ID_LIST = append(SCREEN_ENTITY_ID_LIST, gadgetNormalEntity.GetId())
}
}
-10
View File
@@ -160,7 +160,6 @@ func (s *Scene) CreateEntityMonster(pos, rot *model.Vector, level uint8, configI
visionLevel: visionLevel,
},
}
s.CreateEntity(entity)
return entity
}
@@ -185,7 +184,6 @@ func (s *Scene) CreateEntityNpc(pos, rot *model.Vector, configId, groupId uint32
visionLevel: constant.VISION_LEVEL_NORMAL,
},
}
s.CreateEntity(entity)
return entity
}
@@ -214,7 +212,6 @@ func (s *Scene) CreateEntityGadgetNormal(pos, rot *model.Vector, configId, group
gadgetState: gadgetState,
},
}
s.CreateEntity(entity)
return entity
}
@@ -241,7 +238,6 @@ func (s *Scene) CreateEntityGadgetTrifleItem(pos, rot *model.Vector, visionLevel
gadgetState: gadgetState,
},
}
s.CreateEntity(entity)
return entity
}
@@ -270,7 +266,6 @@ func (s *Scene) CreateEntityGadgetGather(pos, rot *model.Vector, configId, group
gadgetState: gadgetState,
},
}
s.CreateEntity(entity)
return entity
}
@@ -300,7 +295,6 @@ func (s *Scene) CreateEntityGadgetWorktop(pos, rot *model.Vector, configId, grou
},
optionMap: make(map[uint32]struct{}),
}
s.CreateEntity(entity)
return entity
}
@@ -325,9 +319,6 @@ func (s *Scene) CreateEntityGadgetClient(entityId uint32, pos, rot *model.Vector
gadgetId: gadgetId,
},
}
if s.CreateEntity(entity) == 0 {
return nil
}
return entity
}
@@ -348,7 +339,6 @@ func (s *Scene) CreateEntityGadgetVehicle(pos, rot *model.Vector, gadgetId uint3
gadgetId: gadgetId,
},
}
s.CreateEntity(entity)
return entity
}
+27 -1
View File
@@ -260,7 +260,7 @@ func (g *Game) GadgetCreateTriggerCheck(player *model.Player, group *Group, enti
}
// GadgetStateChangeTriggerCheck 物件状态变更触发器检测
func (g *Game) GadgetStateChangeTriggerCheck(player *model.Player, group *Group, entity IEntity, state uint8) {
func (g *Game) GadgetStateChangeTriggerCheck(player *model.Player, group *Group, entity IEntity, state uint32) {
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
if triggerConfig.Event != constant.LUA_EVENT_GADGET_STATE_CHANGE {
return
@@ -367,3 +367,29 @@ func (g *Game) TimerEventTriggerCheck(player *model.Player, group *Group, source
}
})
}
// SelectOptionTriggerCheck 操作台选择触发器检测
func (g *Game) SelectOptionTriggerCheck(player *model.Player, group *Group, entity IEntity, option uint32) {
forEachGroupTrigger(player, group, func(triggerConfig *gdconf.Trigger, groupConfig *gdconf.Group) {
if triggerConfig.Event != constant.LUA_EVENT_SELECT_OPTION {
return
}
if triggerConfig.Condition != "" {
cond := CallSceneLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
&LuaCtx{uid: player.PlayerId, groupId: uint32(groupConfig.Id)},
&LuaEvt{param1: int32(entity.GetConfigId()), param2: int32(option)})
if !cond {
return
}
}
if triggerConfig.Action != "" {
logger.Debug("scene group trigger do action, trigger: %+v, uid: %v", triggerConfig, player.PlayerId)
ok := CallSceneLuaFunc(groupConfig.GetLuaState(), triggerConfig.Action,
&LuaCtx{uid: player.PlayerId, groupId: uint32(groupConfig.Id), targetEntityId: entity.GetId()},
&LuaEvt{})
if !ok {
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerId)
}
}
})
}
+1 -1
View File
@@ -124,7 +124,7 @@ func (g *Game) GetWorldLevelByPlayerLevel(playerLevel uint32) uint32 {
}
}
// TriggerOpenState 触发检测功能开放状态更新
// TriggerOpenState 触发功能开放状态
func (g *Game) TriggerOpenState(userId uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
+26 -31
View File
@@ -134,15 +134,12 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa
if motionInfo == nil || motionInfo.Pos == nil || motionInfo.Rot == nil {
break
}
g.handleEntityMove(player, world, scene, entityMoveInfo.EntityId, &model.Vector{
X: float64(motionInfo.Pos.X),
Y: float64(motionInfo.Pos.Y),
Z: float64(motionInfo.Pos.Z),
}, &model.Vector{
X: float64(motionInfo.Rot.X),
Y: float64(motionInfo.Rot.Y),
Z: float64(motionInfo.Rot.Z),
}, false, entityMoveInfo)
g.handleEntityMove(
player, world, scene, entityMoveInfo.EntityId,
&model.Vector{X: float64(motionInfo.Pos.X), Y: float64(motionInfo.Pos.Y), Z: float64(motionInfo.Pos.Z)},
&model.Vector{X: float64(motionInfo.Rot.X), Y: float64(motionInfo.Rot.Y), Z: float64(motionInfo.Rot.Z)},
false, entityMoveInfo,
)
// 众里寻他千百度 蓦然回首 那人却在灯火阑珊处
if motionInfo.State == proto.MotionState_MOTION_NOTIFY || motionInfo.State == proto.MotionState_MOTION_FIGHT {
// 只要转发了这两个包的其中之一 客户端的动画就会被打断
@@ -259,6 +256,25 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
return
}
oldPos := g.GetPlayerPos(player)
// 更新玩家角色实体的位置信息
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
worldAvatarEntityId := worldAvatar.GetAvatarEntityId()
worldAvatarEntity := scene.GetEntity(worldAvatarEntityId)
if worldAvatarEntity == nil {
logger.Error("world avatar entity is nil, worldAvatar: %+v, uid: %v", worldAvatar, player.PlayerId)
continue
}
worldAvatarEntity.SetPos(pos)
worldAvatarEntity.SetRot(rot)
worldWeaponEntityId := worldAvatar.GetWeaponEntityId()
worldWeaponEntity := scene.GetEntity(worldWeaponEntityId)
if worldWeaponEntity == nil {
logger.Error("world weapon entity is nil, worldAvatar: %+v, uid: %v", worldAvatar, player.PlayerId)
continue
}
worldWeaponEntity.SetPos(pos)
worldWeaponEntity.SetRot(rot)
}
if !WORLD_MANAGER.IsAiWorld(world) {
if !world.IsValidScenePos(scene.GetId(), float32(pos.X), 0.0, float32(pos.Z)) {
return
@@ -282,25 +298,6 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
}
// 场景天气区域变更检测
g.SceneWeatherAreaCheck(player, oldPos, pos)
// 更新玩家角色实体的位置信息
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
worldAvatarEntityId := worldAvatar.GetAvatarEntityId()
worldAvatarEntity := scene.GetEntity(worldAvatarEntityId)
if worldAvatarEntity == nil {
logger.Error("world avatar entity is nil, worldAvatar: %+v, uid: %v", worldAvatar, player.PlayerId)
continue
}
worldAvatarEntity.SetPos(pos)
worldAvatarEntity.SetRot(rot)
worldWeaponEntityId := worldAvatar.GetWeaponEntityId()
worldWeaponEntity := scene.GetEntity(worldWeaponEntityId)
if worldWeaponEntity == nil {
logger.Error("world weapon entity is nil, worldAvatar: %+v, uid: %v", worldAvatar, player.PlayerId)
continue
}
worldWeaponEntity.SetPos(pos)
worldWeaponEntity.SetRot(rot)
}
}
// 更新场景实体的位置信息
entity.SetPos(pos)
@@ -861,10 +858,8 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message
&model.Vector{X: float64(ntf.InitEulerAngles.X), Y: float64(ntf.InitEulerAngles.Y), Z: float64(ntf.InitEulerAngles.Z)},
ntf.ConfigId,
)
if gadgetClientEntity == nil {
return
}
gadgetClientEntity.CreateGadgetClientEntity(ntf.CampId, ntf.CampType, ntf.OwnerEntityId, ntf.TargetEntityId, ntf.PropOwnerEntityId)
scene.CreateEntity(gadgetClientEntity)
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{ntf.EntityId}, true, true)
// 触发事件
+94 -92
View File
@@ -1,6 +1,7 @@
package game
import (
"hk4e/pkg/object"
"strconv"
"strings"
@@ -108,7 +109,7 @@ func matchParamEqual(param1 []int32, param2 []int32, num int) bool {
}
// AcceptQuest 接取任务
func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
func (g *Game) AcceptQuest(player *model.Player, notify bool) {
g.EndlessLoopCheck(EndlessLoopCheckTypeAcceptQuest)
dbQuest := player.GetDbQuest()
addQuestIdList := make([]uint32, 0)
@@ -116,7 +117,7 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
if dbQuest.GetQuestById(uint32(questData.QuestId)) != nil {
continue
}
acceptCondResultList := make([]bool, 0)
resultList := make([]bool, 0)
for _, acceptCond := range questData.AcceptCondList {
result := false
switch acceptCond.Type {
@@ -149,30 +150,30 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
default:
break
}
acceptCondResultList = append(acceptCondResultList, result)
resultList = append(resultList, result)
}
canAccept := false
accept := false
switch questData.AcceptCondCompose {
case constant.QUEST_LOGIC_TYPE_NONE:
fallthrough
case constant.QUEST_LOGIC_TYPE_AND:
canAccept = true
for _, acceptCondResult := range acceptCondResultList {
if !acceptCondResult {
canAccept = false
accept = true
for _, result := range resultList {
if !result {
accept = false
break
}
}
case constant.QUEST_LOGIC_TYPE_OR:
canAccept = false
for _, acceptCondResult := range acceptCondResultList {
if acceptCondResult {
canAccept = true
accept = false
for _, result := range resultList {
if result {
accept = true
break
}
}
}
if canAccept {
if accept {
if questData.QuestId == 35304 {
// TODO 任务异常的权柄释放元素爆发时没有能量
world := WORLD_MANAGER.GetWorldById(player.WorldId)
@@ -205,7 +206,7 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
addQuestIdList = append(addQuestIdList, uint32(questData.QuestId))
}
}
if notifyClient {
if notify {
ntf := &proto.QuestListUpdateNotify{
QuestList: make([]*proto.Quest, 0),
}
@@ -219,21 +220,20 @@ func (g *Game) AcceptQuest(player *model.Player, notifyClient bool) {
g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerId, player.ClientSeq, ntf)
}
for _, questId := range addQuestIdList {
g.StartQuest(player, questId, notifyClient)
g.StartQuest(player, questId, notify)
}
}
// StartQuest 开始任务
func (g *Game) StartQuest(player *model.Player, questId uint32, notifyClient bool) {
func (g *Game) StartQuest(player *model.Player, questId uint32, notify bool) {
g.EndlessLoopCheck(EndlessLoopCheckTypeStartQuest)
dbQuest := player.GetDbQuest()
dbQuest.StartQuest(questId)
g.ExecQuest(player, questId, QuestExecTypeStart)
g.QuestStartTriggerCheck(player, questId)
g.CheckQuestFinishedCond(player, questId)
if notifyClient {
if notify {
ntf := &proto.QuestListUpdateNotify{
QuestList: make([]*proto.Quest, 0),
}
@@ -244,6 +244,16 @@ func (g *Game) StartQuest(player *model.Player, questId uint32, notifyClient boo
ntf.QuestList = append(ntf.QuestList, pbQuest)
g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerId, player.ClientSeq, ntf)
}
// 任务开始时主动触发检测是否完成
questDataConfig := gdconf.GetQuestDataById(int32(questId))
if questDataConfig == nil {
logger.Error("get quest data config is nil, questId: %v", questId)
return
}
for _, finishCond := range questDataConfig.FinishCondList {
g.TriggerQuest(player, finishCond.Type, "")
}
}
// ExecQuest 执行任务
@@ -414,40 +424,13 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int
}
dbQuest := player.GetDbQuest()
rollbackQuest := dbQuest.GetQuestById(uint32(rollbackQuestId))
if rollbackQuest.State != constant.QUEST_STATE_FAILED {
continue
}
rollbackQuest.State = constant.QUEST_STATE_UNSTARTED
g.StartQuest(player, rollbackQuest.QuestId, true)
default:
logger.Error("not support quest exec type: %v, uid: %v", questExec.Type, player.PlayerId)
}
}
}
// CheckQuestFinishedCond 检测任务已完成的条件
func (g *Game) CheckQuestFinishedCond(player *model.Player, questId uint32) {
g.EndlessLoopCheck(EndlessLoopCheckTypeCheckFinishedCond)
questDataConfig := gdconf.GetQuestDataById(int32(questId))
if questDataConfig == nil {
return
}
// TODO 检测已经完成的失败条件
// 检测已经完成的完成条件
for _, cond := range questDataConfig.FinishCondList {
switch cond.Type {
case constant.QUEST_FINISH_COND_TYPE_UNLOCK_TRANS_POINT:
sceneId := uint32(cond.Param[0])
pointId := uint32(cond.Param[1])
dbWorld := player.GetDbWorld()
dbScene := dbWorld.GetSceneById(sceneId)
if dbScene == nil {
logger.Error("get dbScene is nil, sceneId: %v, uid: %v", sceneId, player.PlayerId)
continue
}
unlock := dbScene.CheckPointUnlock(pointId)
if !unlock {
continue
}
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_TRANS_POINT, "", int32(sceneId), int32(pointId))
logger.Error("not support quest exec type: %v, questId: %v, uid: %v", questExec.Type, questId, player.PlayerId)
}
}
}
@@ -456,7 +439,7 @@ func (g *Game) CheckQuestFinishedCond(player *model.Player, questId uint32) {
func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam string, param ...int32) {
g.EndlessLoopCheck(EndlessLoopCheckTypeTriggerQuest)
dbQuest := player.GetDbQuest()
updateQuestIdList := make([]uint32, 0)
updateQuestIdMap := make(map[uint32]struct{})
for _, quest := range dbQuest.GetQuestMap() {
if quest.State != constant.QUEST_STATE_UNFINISHED {
continue
@@ -465,89 +448,106 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin
if questDataConfig == nil {
continue
}
for _, questCond := range questDataConfig.FailCondList {
if questCond.Type != cond {
for _, failCond := range questDataConfig.FailCondList {
if failCond.Type != cond {
continue
}
switch cond {
case constant.QUEST_FINISH_COND_TYPE_LUA_NOTIFY:
// LUA侧通知 复杂参数
if questCond.ComplexParam != complexParam {
if failCond.ComplexParam != complexParam {
continue
}
dbQuest.FailQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
default:
logger.Error("not support quest cond type: %v, questId: %v, uid: %v", cond, quest.QuestId, player.PlayerId)
}
updateQuestIdMap[quest.QuestId] = struct{}{}
}
for _, questCond := range questDataConfig.FinishCondList {
if questCond.Type != cond {
for index, finishCond := range questDataConfig.FinishCondList {
if finishCond.Type != cond {
continue
}
switch cond {
case constant.QUEST_FINISH_COND_TYPE_FINISH_PLOT:
ok := matchParamEqual(questCond.Param, param, 1)
// 完成剧情 参数1:剧情id
ok := matchParamEqual(finishCond.Param, param, 1)
if !ok {
continue
}
dbQuest.ForceFinishQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_TRIGGER_FIRE:
// 场景触发器跳了 参数1:触发器id
ok := matchParamEqual(questCond.Param, param, 1)
ok := matchParamEqual(finishCond.Param, param, 1)
if !ok {
continue
}
dbQuest.ForceFinishQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_UNLOCK_TRANS_POINT:
// 解锁传送锚点 参数1:场景id 参数2:传送锚点id
ok := matchParamEqual(questCond.Param, param, 2)
if !ok {
dbWorld := player.GetDbWorld()
dbScene := dbWorld.GetSceneById(uint32(finishCond.Param[0]))
if dbScene == nil {
continue
}
dbQuest.ForceFinishQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
unlock := dbScene.CheckPointUnlock(uint32(finishCond.Param[1]))
if !unlock {
continue
}
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_COMPLETE_TALK:
// 与NPC对话 参数1:对话id
ok := matchParamEqual(questCond.Param, param, 1)
ok := matchParamEqual(finishCond.Param, param, 1)
if !ok {
continue
}
dbQuest.ForceFinishQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_LUA_NOTIFY:
// LUA侧通知 复杂参数
if questCond.ComplexParam != complexParam {
if finishCond.ComplexParam != complexParam {
continue
}
dbQuest.ForceFinishQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_SKILL:
// 使用技能 参数1:技能id
ok := matchParamEqual(questCond.Param, param, 1)
ok := matchParamEqual(finishCond.Param, param, 1)
if !ok {
continue
}
dbQuest.ForceFinishQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_OBTAIN_ITEM:
// 获得道具 参数1:道具id
ok := matchParamEqual(questCond.Param, param, 1)
ok := matchParamEqual(finishCond.Param, param, 1)
if !ok {
continue
}
dbQuest.ForceFinishQuest(quest.QuestId)
updateQuestIdList = append(updateQuestIdList, quest.QuestId)
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_UNLOCK_AREA:
// 解锁场景区域 参数1:场景id 参数2:场景区域id
dbWorld := player.GetDbWorld()
dbScene := dbWorld.GetSceneById(uint32(finishCond.Param[0]))
if dbScene == nil {
continue
}
unlock := dbScene.CheckAreaUnlock(uint32(finishCond.Param[1]))
if !unlock {
continue
}
dbQuest.AddQuestFinishCount(quest.QuestId, index)
case constant.QUEST_FINISH_COND_TYPE_ADD_QUEST_PROGRESS:
// TODO 这你妈到底是加父任务的进度还是子任务的进度
continue
default:
logger.Error("not support quest cond type: %v, uid: %v", cond, player.PlayerId)
logger.Error("not support quest cond type: %v, questId: %v, uid: %v", cond, quest.QuestId, player.PlayerId)
}
updateQuestIdMap[quest.QuestId] = struct{}{}
}
dbQuest.CheckQuestFinish(quest.QuestId)
}
if len(updateQuestIdList) > 0 {
if len(updateQuestIdMap) > 0 {
// 更新客户端任务列表
questList := make([]*proto.Quest, 0)
for _, questId := range updateQuestIdList {
for questId := range updateQuestIdMap {
pbQuest := g.PacketQuest(player, questId)
if pbQuest == nil {
continue
@@ -557,30 +557,32 @@ func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam strin
g.SendMsg(cmd.QuestListUpdateNotify, player.PlayerId, player.ClientSeq, &proto.QuestListUpdateNotify{
QuestList: questList,
})
parentQuestList := g.PacketParentQuestList(player, updateQuestIdList)
// 更新客户端父任务
parentQuestList := g.PacketParentQuestList(player, object.ConvMapKeyToList[uint32, struct{}](updateQuestIdMap))
if len(parentQuestList) > 0 {
g.SendMsg(cmd.FinishedParentQuestUpdateNotify, player.PlayerId, player.ClientSeq, &proto.FinishedParentQuestUpdateNotify{
ParentQuestList: parentQuestList,
})
}
for _, questId := range updateQuestIdList {
// 任务事件
for questId := range updateQuestIdMap {
quest := dbQuest.GetQuestById(questId)
questDataConfig := gdconf.GetQuestDataById(int32(quest.QuestId))
if questDataConfig == nil {
continue
}
if quest.State == constant.QUEST_STATE_FINISHED {
// 任务完成执行
g.ExecQuest(player, quest.QuestId, QuestExecTypeFinish)
// 任务完成发奖
questDataConfig := gdconf.GetQuestDataById(int32(quest.QuestId))
if questDataConfig == nil {
continue
}
if len(questDataConfig.ItemIdList) != 0 {
for index, itemId := range questDataConfig.ItemIdList {
questItem := []*ChangeItem{{ItemId: uint32(itemId), ChangeCount: uint32(questDataConfig.ItemCountList[index])}}
g.AddPlayerItem(player.PlayerId, questItem, proto.ActionReasonType_ACTION_REASON_QUEST_ITEM)
}
}
}
if quest.State == constant.QUEST_STATE_FAILED {
} else if quest.State == constant.QUEST_STATE_FAILED {
// 任务失败执行
g.ExecQuest(player, quest.QuestId, QuestExecTypeFail)
}
}
@@ -611,7 +613,7 @@ func (g *Game) PacketQuest(player *model.Player, questId uint32) *proto.Quest {
ParentQuestId: uint32(questDataConfig.ParentQuestId),
StartGameTime: 0,
AcceptTime: quest.AcceptTime,
FinishProgressList: quest.FinishProgressList,
FinishProgressList: quest.FinishCountList,
}
return pbQuest
}
+9 -1
View File
@@ -985,7 +985,7 @@ func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state ui
sceneGroup.ChangeGadgetState(entity.GetConfigId(), uint8(iGadgetEntity.GetGadgetState()))
// 物件状态变更触发器检测
g.GadgetStateChangeTriggerCheck(player, group, entity, uint8(iGadgetEntity.GetGadgetState()))
g.GadgetStateChangeTriggerCheck(player, group, entity, iGadgetEntity.GetGadgetState())
}
// GetVisionEntity 获取某位置视野内的全部实体
@@ -1305,6 +1305,7 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any
monsterLevel, uint32(monster.ConfigId), groupId, int(monster.VisionLevel),
)
monsterEntity.CreateMonsterEntity(uint32(monster.MonsterId))
scene.CreateEntity(monsterEntity)
return monsterEntity.GetId()
case *gdconf.Npc:
npc := entityConfig.(*gdconf.Npc)
@@ -1314,6 +1315,7 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any
uint32(npc.ConfigId), groupId,
)
npcEntity.CreateNpcEntity(uint32(npc.NpcId), 0, 0, 0)
scene.CreateEntity(npcEntity)
return npcEntity.GetId()
case *gdconf.Gadget:
gadget := entityConfig.(*gdconf.Gadget)
@@ -1334,6 +1336,7 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any
uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), uint32(gatherDataConfig.GadgetId), uint32(constant.GADGET_STATE_DEFAULT),
)
gadgetGatherEntity.CreateGadgetGatherEntity(uint32(gatherDataConfig.ItemId))
scene.CreateEntity(gadgetGatherEntity)
return gadgetGatherEntity.GetId()
case constant.GADGET_TYPE_WORKTOP:
state := uint8(gadget.State)
@@ -1346,6 +1349,7 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any
&model.Vector{X: float64(gadget.Rot.X), Y: float64(gadget.Rot.Y), Z: float64(gadget.Rot.Z)},
uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), uint32(gadget.GadgetId), uint32(state),
)
scene.CreateEntity(gadgetWorktopEntity)
return gadgetWorktopEntity.GetId()
default:
state := uint8(gadget.State)
@@ -1358,6 +1362,7 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any
&model.Vector{X: float64(gadget.Rot.X), Y: float64(gadget.Rot.Y), Z: float64(gadget.Rot.Z)},
uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), uint32(gadget.GadgetId), uint32(state),
)
scene.CreateEntity(gadgetNormalEntity)
return gadgetNormalEntity.GetId()
}
}
@@ -1448,6 +1453,7 @@ func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId
rot.Y = random.GetRandomFloat64(0.0, 360.0)
monsterEntity := scene.CreateEntityMonster(pos, rot, level, 0, 0, constant.VISION_LEVEL_NORMAL)
monsterEntity.CreateMonsterEntity(monsterId)
scene.CreateEntity(monsterEntity)
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{monsterEntity.GetId()}, true, false)
return monsterEntity.GetId()
}
@@ -1471,6 +1477,7 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui
rot := new(model.Vector)
rot.Y = random.GetRandomFloat64(0.0, 360.0)
gadgetNormalEntity := scene.CreateEntityGadgetNormal(pos, rot, 0, 0, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT)
scene.CreateEntity(gadgetNormalEntity)
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{gadgetNormalEntity.GetId()}, true, false)
return gadgetNormalEntity.GetId()
}
@@ -1495,6 +1502,7 @@ func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetI
rot.Y = random.GetRandomFloat64(0.0, 360.0)
gadgetTrifleItemEntity := scene.CreateEntityGadgetTrifleItem(pos, rot, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT)
gadgetTrifleItemEntity.CreateGadgetTrifleItemEntity(itemId, count)
scene.CreateEntity(gadgetTrifleItemEntity)
g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{gadgetTrifleItemEntity.GetId()}, true, false)
return gadgetTrifleItemEntity.GetId()
}
+1 -4
View File
@@ -47,11 +47,8 @@ func (g *Game) CreateVehicleReq(player *model.Player, payloadMsg pb.Message) {
pos := &model.Vector{X: float64(req.Pos.X), Y: float64(req.Pos.Y), Z: float64(req.Pos.Z)}
rot := &model.Vector{X: float64(req.Rot.X), Y: float64(req.Rot.Y), Z: float64(req.Rot.Z)}
gadgetVehicleEntity := scene.CreateEntityGadgetVehicle(pos, rot, req.VehicleId)
if gadgetVehicleEntity == nil {
g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
return
}
gadgetVehicleEntity.CreateGadgetVehicleEntity(player.PlayerId)
scene.CreateEntity(gadgetVehicleEntity)
GAME.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{gadgetVehicleEntity.GetId()}, true, false)
// 记录创建的载具信息
player.VehicleInfo.CreateEntityIdMap[req.VehicleId] = gadgetVehicleEntity.GetId()
+22 -3
View File
@@ -505,7 +505,26 @@ func (g *Game) ExitTransPointRegionNotify(player *model.Player, payloadMsg pb.Me
func (g *Game) SelectWorktopOptionReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.SelectWorktopOptionReq)
_ = req
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world == nil {
return
}
scene := world.GetSceneById(player.SceneId)
entity := scene.GetEntity(req.GadgetEntityId)
if entity == nil {
return
}
group := scene.GetGroupById(entity.GetGroupId())
if group == nil {
return
}
g.SelectOptionTriggerCheck(player, group, entity, req.OptionId)
g.SendMsg(cmd.SelectWorktopOptionRsp, player.PlayerId, player.ClientSeq, &proto.SelectWorktopOptionRsp{
GadgetEntityId: req.GadgetEntityId,
OptionId: req.OptionId,
})
}
/************************************************** 游戏功能 **************************************************/
@@ -533,7 +552,7 @@ func (g *Game) UnlockPlayerScenePoint(player *model.Player, sceneId uint32, poin
SceneId: sceneId,
PointList: []uint32{pointId},
}, 0)
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_TRANS_POINT, "", int32(sceneId), int32(pointId))
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_TRANS_POINT, "")
return proto.Retcode_RET_SUCC
}
@@ -560,7 +579,7 @@ func (g *Game) UnlockPlayerSceneArea(player *model.Player, sceneId uint32, areaI
SceneId: sceneId,
AreaList: []uint32{areaId},
}, 0)
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_AREA, "", int32(sceneId), int32(areaId))
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_AREA, "")
}
// ChangeGameTime 修改游戏时间
+73 -29
View File
@@ -15,11 +15,11 @@ type DbQuest struct {
// Quest 任务
type Quest struct {
QuestId uint32 // 任务id
State uint8 // 任务状态
AcceptTime uint32 // 接取时间
StartTime uint32 // 开始执行时间
FinishProgressList []uint32 // 任务进度
QuestId uint32 // 任务id
State uint8 // 任务状态
AcceptTime uint32 // 接取时间
StartTime uint32 // 开始执行时间
FinishCountList []uint32 // 任务完成进度
}
func (p *Player) GetDbQuest() *DbQuest {
@@ -55,11 +55,11 @@ func (q *DbQuest) AddQuest(questId uint32) {
return
}
q.QuestMap[questId] = &Quest{
QuestId: uint32(questDataConfig.QuestId),
State: constant.QUEST_STATE_UNSTARTED,
AcceptTime: uint32(time.Now().Unix()),
StartTime: 0,
FinishProgressList: nil,
QuestId: uint32(questDataConfig.QuestId),
State: constant.QUEST_STATE_UNSTARTED,
AcceptTime: uint32(time.Now().Unix()),
StartTime: 0,
FinishCountList: make([]uint32, len(questDataConfig.FinishCondList)),
}
}
@@ -74,14 +74,8 @@ func (q *DbQuest) StartQuest(questId uint32) {
logger.Error("invalid quest state, questId: %v, state: %v", questId, quest.State)
return
}
questDataConfig := gdconf.GetQuestDataById(int32(questId))
if questDataConfig == nil {
logger.Error("get quest data config is nil, questId: %v", questId)
return
}
quest.State = constant.QUEST_STATE_UNFINISHED
quest.StartTime = uint32(time.Now().Unix())
quest.FinishProgressList = make([]uint32, len(questDataConfig.FinishCondList))
}
// DeleteQuest 删除一个任务
@@ -94,8 +88,25 @@ func (q *DbQuest) DeleteQuest(questId uint32) {
delete(q.QuestMap, questId)
}
// AddQuestProgress 添加一个任务的进度
func (q *DbQuest) AddQuestProgress(questId uint32, index int, progress uint32) {
// AddQuestFinishCount 添加一个任务的完成进度
func (q *DbQuest) AddQuestFinishCount(questId uint32, index int) {
quest, exist := q.QuestMap[questId]
if !exist {
logger.Error("get quest is nil, questId: %v", questId)
return
}
if quest.State != constant.QUEST_STATE_UNFINISHED {
return
}
if index >= len(quest.FinishCountList) {
logger.Error("invalid quest cond index, questId: %v, index: %v", questId, index)
return
}
quest.FinishCountList[index] += 1
}
// CheckQuestFinish 检查任务是否完成
func (q *DbQuest) CheckQuestFinish(questId uint32) {
quest, exist := q.QuestMap[questId]
if !exist {
logger.Error("get quest is nil, questId: %v", questId)
@@ -109,28 +120,55 @@ func (q *DbQuest) AddQuestProgress(questId uint32, index int, progress uint32) {
logger.Error("get quest data config is nil, questId: %v", questId)
return
}
if index >= len(quest.FinishProgressList) || index >= len(questDataConfig.FinishCondList) {
logger.Error("invalid quest progress index, questId: %v, index: %v", questId, index)
return
resultList := make([]bool, 0)
for index, finishCond := range questDataConfig.FinishCondList {
result := false
finishCount := finishCond.Count
if finishCount == 0 {
finishCount = 1
}
if quest.FinishCountList[index] >= uint32(finishCount) {
result = true
}
resultList = append(resultList, result)
}
quest.FinishProgressList[index] += progress
if quest.FinishProgressList[index] >= uint32(questDataConfig.FinishCondList[index].Count) {
finish := false
switch questDataConfig.FinishCondCompose {
case constant.QUEST_LOGIC_TYPE_NONE:
fallthrough
case constant.QUEST_LOGIC_TYPE_AND:
finish = true
for _, result := range resultList {
if !result {
finish = false
break
}
}
case constant.QUEST_LOGIC_TYPE_OR:
finish = false
for _, result := range resultList {
if result {
finish = true
break
}
}
}
if finish {
quest.State = constant.QUEST_STATE_FINISHED
}
}
// ForceFinishQuest 强制完成一个任务
func (q *DbQuest) ForceFinishQuest(questId uint32) {
questDataConfig := gdconf.GetQuestDataById(int32(questId))
if questDataConfig == nil {
logger.Error("get quest data config is nil, questId: %v", questId)
quest, exist := q.QuestMap[questId]
if !exist {
logger.Error("get quest is nil, questId: %v", questId)
return
}
for index, finishCond := range questDataConfig.FinishCondList {
q.AddQuestProgress(questId, index, uint32(finishCond.Count))
}
quest.State = constant.QUEST_STATE_FINISHED
}
// FailQuest 失败一个任务
func (q *DbQuest) FailQuest(questId uint32) {
quest, exist := q.QuestMap[questId]
if !exist {
@@ -141,4 +179,10 @@ func (q *DbQuest) FailQuest(questId uint32) {
return
}
quest.State = constant.QUEST_STATE_FAILED
questDataConfig := gdconf.GetQuestDataById(int32(questId))
if questDataConfig == nil {
logger.Error("get quest data config is nil, questId: %v", questId)
return
}
quest.FinishCountList = make([]uint32, len(questDataConfig.FinishCondList))
}