mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
修复读表引号问题
This commit is contained in:
@@ -10,7 +10,6 @@ type GadgetData struct {
|
||||
Type int32 `csv:"类型,omitempty"`
|
||||
DefaultCamp int32 `csv:"默认阵营,omitempty"`
|
||||
CanInteract int32 `csv:"能否交互,omitempty"`
|
||||
Desc string `csv:"描述,omitempty"`
|
||||
}
|
||||
|
||||
func (g *GameDataConfig) loadGadgetData() {
|
||||
|
||||
@@ -243,6 +243,7 @@ func readTable[T any](tablePath string, table *[]*T) {
|
||||
}
|
||||
reader := csv.NewReader(bytes.NewBuffer(fileData))
|
||||
reader.Comma = '\t'
|
||||
reader.LazyQuotes = true
|
||||
dec, err := csvutil.NewDecoder(reader)
|
||||
if err != nil {
|
||||
info := fmt.Sprintf("create decoder error: %v", err)
|
||||
|
||||
@@ -12,7 +12,6 @@ type ItemData struct {
|
||||
Weight int32 `csv:"重量,omitempty"`
|
||||
RankLevel int32 `csv:"排序权重,omitempty"`
|
||||
GadgetId int32 `csv:"物件ID,omitempty"`
|
||||
Name string `csv:"数值用类型,omitempty"`
|
||||
// 材料
|
||||
MaterialType int32 `csv:"材料类型,omitempty"`
|
||||
Use1Param1 string `csv:"[使用]1参数1,omitempty"`
|
||||
|
||||
153
gs/game/lua_trigger.go
Normal file
153
gs/game/lua_trigger.go
Normal file
@@ -0,0 +1,153 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"hk4e/common/constant"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/alg"
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
// SceneRegionTriggerCheck 场景区域触发器检测
|
||||
func (g *GameManager) SceneRegionTriggerCheck(player *model.Player, scene *Scene, oldPos *model.Vector, newPos *model.Vector, entityId uint32) {
|
||||
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 _, regionConfigId := range suiteConfig.RegionConfigIdList {
|
||||
regionConfig := groupConfig.RegionMap[regionConfigId]
|
||||
if regionConfig == nil {
|
||||
logger.Error("get region config is nil, regionConfigId: %v, uid: %v", regionConfigId, player.PlayerID)
|
||||
continue
|
||||
}
|
||||
shape := alg.NewShape()
|
||||
switch uint8(regionConfig.Shape) {
|
||||
case constant.REGION_SHAPE_SPHERE:
|
||||
shape.NewSphere(&alg.Vector3{X: regionConfig.Pos.X, Y: regionConfig.Pos.Y, Z: regionConfig.Pos.Z}, regionConfig.Radius)
|
||||
case constant.REGION_SHAPE_CUBIC:
|
||||
shape.NewCubic(&alg.Vector3{X: regionConfig.Pos.X, Y: regionConfig.Pos.Y, Z: regionConfig.Pos.Z},
|
||||
&alg.Vector3{X: regionConfig.Size.X, Y: regionConfig.Size.Y, Z: regionConfig.Size.Z})
|
||||
case constant.REGION_SHAPE_CYLINDER:
|
||||
shape.NewCylinder(&alg.Vector3{X: regionConfig.Pos.X, Y: regionConfig.Pos.Y, Z: regionConfig.Pos.Z},
|
||||
regionConfig.Radius, regionConfig.Height)
|
||||
case constant.REGION_SHAPE_POLYGON:
|
||||
vector2PointArray := make([]*alg.Vector2, 0)
|
||||
for _, vector := range regionConfig.PointArray {
|
||||
// z就是y
|
||||
vector2PointArray = append(vector2PointArray, &alg.Vector2{X: vector.X, Z: vector.Y})
|
||||
}
|
||||
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),
|
||||
})
|
||||
if !oldPosInRegion && newPosInRegion {
|
||||
logger.Debug("player enter region: %v, uid: %v", regionConfig, player.PlayerID)
|
||||
for _, triggerName := range suiteConfig.TriggerNameList {
|
||||
triggerConfig := groupConfig.TriggerMap[triggerName]
|
||||
if triggerConfig.Event != constant.LUA_EVENT_ENTER_REGION {
|
||||
continue
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID},
|
||||
&LuaEvt{param1: regionConfig.ConfigId, 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},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
for _, triggerDataConfig := range gdconf.GetTriggerDataMap() {
|
||||
if triggerDataConfig.TriggerName == triggerConfig.Name {
|
||||
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_TRIGGER_FIRE, triggerDataConfig.TriggerId)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if oldPosInRegion && !newPosInRegion {
|
||||
logger.Debug("player leave region: %v, uid: %v", regionConfig, player.PlayerID)
|
||||
for _, triggerName := range suiteConfig.TriggerNameList {
|
||||
triggerConfig := groupConfig.TriggerMap[triggerName]
|
||||
if triggerConfig.Event != constant.LUA_EVENT_LEAVE_REGION {
|
||||
continue
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID},
|
||||
&LuaEvt{param1: regionConfig.ConfigId, 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},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MonsterDieTriggerCheck 怪物死亡触发器检测
|
||||
func (g *GameManager) MonsterDieTriggerCheck(player *model.Player, groupId uint32, group *Group) {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get group config is nil, groupId: %v, uid: %v", groupId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
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, groupId: groupId},
|
||||
&LuaEvt{})
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,7 @@ package game
|
||||
|
||||
import (
|
||||
"hk4e/common/constant"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/alg"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/pkg/reflection"
|
||||
"hk4e/protocol/cmd"
|
||||
@@ -163,7 +161,8 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
|
||||
Y: float64(motionInfo.Pos.Y),
|
||||
Z: float64(motionInfo.Pos.Z),
|
||||
})
|
||||
g.TriggerCheck(player, player.Pos, &model.Vector{
|
||||
// 场景区域触发器检测
|
||||
g.SceneRegionTriggerCheck(player, scene, player.Pos, &model.Vector{
|
||||
X: float64(motionInfo.Pos.X),
|
||||
Y: float64(motionInfo.Pos.Y),
|
||||
Z: float64(motionInfo.Pos.Z),
|
||||
@@ -304,119 +303,6 @@ func (g *GameManager) AoiPlayerMove(player *model.Player, oldPos *model.Vector,
|
||||
}
|
||||
}
|
||||
|
||||
// TriggerCheck 场景区域触发器检测
|
||||
func (g *GameManager) TriggerCheck(player *model.Player, oldPos *model.Vector, newPos *model.Vector, entityId uint32) {
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get player world is nil, uid: %v", player.PlayerID)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
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 _, regionConfigId := range suiteConfig.RegionConfigIdList {
|
||||
regionConfig := groupConfig.RegionMap[regionConfigId]
|
||||
shape := alg.NewShape()
|
||||
switch uint8(regionConfig.Shape) {
|
||||
case constant.REGION_SHAPE_SPHERE:
|
||||
shape.NewSphere(&alg.Vector3{X: regionConfig.Pos.X, Y: regionConfig.Pos.Y, Z: regionConfig.Pos.Z}, regionConfig.Radius)
|
||||
case constant.REGION_SHAPE_CUBIC:
|
||||
shape.NewCubic(&alg.Vector3{X: regionConfig.Pos.X, Y: regionConfig.Pos.Y, Z: regionConfig.Pos.Z},
|
||||
&alg.Vector3{X: regionConfig.Size.X, Y: regionConfig.Size.Y, Z: regionConfig.Size.Z})
|
||||
case constant.REGION_SHAPE_CYLINDER:
|
||||
shape.NewCylinder(&alg.Vector3{X: regionConfig.Pos.X, Y: regionConfig.Pos.Y, Z: regionConfig.Pos.Z},
|
||||
regionConfig.Radius, regionConfig.Height)
|
||||
case constant.REGION_SHAPE_POLYGON:
|
||||
vector2PointArray := make([]*alg.Vector2, 0)
|
||||
for _, vector := range regionConfig.PointArray {
|
||||
// z就是y
|
||||
vector2PointArray = append(vector2PointArray, &alg.Vector2{X: vector.X, Z: vector.Y})
|
||||
}
|
||||
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),
|
||||
})
|
||||
if !oldPosInRegion && newPosInRegion {
|
||||
logger.Debug("player enter region: %v, uid: %v", regionConfig, player.PlayerID)
|
||||
for _, triggerName := range suiteConfig.TriggerNameList {
|
||||
triggerConfig := groupConfig.TriggerMap[triggerName]
|
||||
if triggerConfig.Event != constant.LUA_EVENT_ENTER_REGION {
|
||||
continue
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID},
|
||||
&LuaEvt{param1: regionConfig.ConfigId, 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},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
g.TriggerFire(player, triggerConfig)
|
||||
}
|
||||
} else if oldPosInRegion && !newPosInRegion {
|
||||
logger.Debug("player leave region: %v, uid: %v", regionConfig, player.PlayerID)
|
||||
for _, triggerName := range suiteConfig.TriggerNameList {
|
||||
triggerConfig := groupConfig.TriggerMap[triggerName]
|
||||
if triggerConfig.Event != constant.LUA_EVENT_LEAVE_REGION {
|
||||
continue
|
||||
}
|
||||
if triggerConfig.Condition != "" {
|
||||
cond := CallLuaFunc(groupConfig.GetLuaState(), triggerConfig.Condition,
|
||||
&LuaCtx{uid: player.PlayerID},
|
||||
&LuaEvt{param1: regionConfig.ConfigId, 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},
|
||||
&LuaEvt{})
|
||||
if !ok {
|
||||
logger.Error("trigger action fail, trigger: %+v, uid: %v", triggerConfig, player.PlayerID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameManager) TriggerFire(player *model.Player, trigger *gdconf.Trigger) {
|
||||
for _, triggerDataConfig := range gdconf.GetTriggerDataMap() {
|
||||
if triggerDataConfig.TriggerName == trigger.Name {
|
||||
g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_TRIGGER_FIRE, triggerDataConfig.TriggerId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameManager) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.AbilityInvocationsNotify)
|
||||
if player.SceneLoadState != model.SceneEnterDone {
|
||||
|
||||
@@ -563,40 +563,9 @@ func (g *GameManager) KillEntity(player *model.Player, scene *Scene, entityId ui
|
||||
}
|
||||
group.DestroyEntity(entity.GetId())
|
||||
scene.DestroyEntity(entity.GetId())
|
||||
// 怪物死亡触发器
|
||||
// 怪物死亡触发器检测
|
||||
if entity.GetEntityType() == constant.ENTITY_TYPE_MONSTER {
|
||||
groupConfig := gdconf.GetSceneGroup(int32(entity.groupId))
|
||||
if groupConfig == nil {
|
||||
logger.Error("get group config is nil, groupId: %v, uid: %v", entity.groupId, player.PlayerID)
|
||||
return
|
||||
}
|
||||
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, groupId: entity.groupId},
|
||||
&LuaEvt{})
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
g.MonsterDieTriggerCheck(player, entity.GetGroupId(), group)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user