载具读配置表 耐力回复延迟修改
This commit is contained in:
1 parent
d710a516c8
commit
6b41772ebe
8 files changed
+218
-40
No files matched your search
@@ -22,4 +22,6 @@ const (
|
||||
STAMINA_COST_POWERED_SKIFF = 500 // 浪船加速(风圈等) (回复耐力)
|
||||
STAMINA_COST_IN_SKIFF = 500 // 处于浪船中回复角色耐力 (回复耐力)
|
||||
STAMINA_COST_SKIFF_NOBODY = 500 // 浪船无人时回复载具耐力 (回复耐力)
|
||||
// 耐力回复延迟
|
||||
STAMINA_PLAYER_RESTORE_DELAY = 15 // 玩家耐力回复延迟
|
||||
)
|
||||
@@ -70,6 +70,7 @@ type GameDataConfig struct {
|
||||
GCGSkillDataMap map[int32]*GCGSkillData // 七圣召唤卡牌技能
|
||||
GachaDropGroupDataMap map[int32]*GachaDropGroupData // 卡池掉落组 临时的
|
||||
SkillStaminaDataMap map[int32]*SkillStaminaData // 角色技能消耗体力 临时的
|
||||
VehicleDataMap map[int32]*VehicleData // 载具
|
||||
}
|
||||
|
||||
func InitGameDataConfig() {
|
||||
@@ -172,6 +173,7 @@ func (g *GameDataConfig) load() {
|
||||
g.loadGCGSkillData() // 七圣召唤卡牌技能
|
||||
g.loadGachaDropGroupData() // 卡池掉落组 临时的
|
||||
g.loadSkillStaminaData() // 角色技能消耗体力 临时的
|
||||
g.loadVehicleData() // 载具
|
||||
}
|
||||
|
||||
// CSV相关
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package gdconf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hk4e/pkg/logger"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hjson/hjson-go/v4"
|
||||
)
|
||||
|
||||
// VehicleData 载具配置表
|
||||
type VehicleData struct {
|
||||
VehicleId int32 `csv:"ID"`
|
||||
TextName string `csv:"名称$text_name_Name,omitempty"`
|
||||
|
||||
ConfigGadgetVehicle *ConfigGadgetVehicle
|
||||
}
|
||||
|
||||
type ConfigGadgetVehicle struct {
|
||||
Vehicle *ConfigVehicle `json:"vehicle"` // 载具
|
||||
Combat *ConfigVehicleCombat `json:"combat"` // 战斗
|
||||
}
|
||||
|
||||
type ConfigVehicle struct {
|
||||
VehicleType string `json:"vehicleType"` // 载具类型
|
||||
DefaultLevel int32 `json:"defaultLevel"` // 默认等级
|
||||
MaxSeatCount int32 `json:"maxSeatCount"` // 最大座位数
|
||||
Stamina *ConfigVehicleStamina `json:"stamina"` // 耐力
|
||||
}
|
||||
|
||||
type ConfigVehicleStamina struct {
|
||||
StaminaUpperLimit float32 `json:"staminaUpperLimit"` // 耐力上限
|
||||
StaminaRecoverSpeed float32 `json:"staminaRecoverSpeed"` // 耐力回复速度
|
||||
StaminaRecoverWaitTime float32 `json:"staminaRecoverWaitTime"` // 耐力回复等待时间
|
||||
ExtraStaminaUpperLimit float32 `json:"extraStaminaUpperLimit"` // 额外耐力上限
|
||||
SprintStaminaCost float32 `json:"sprintStaminaCost"` // 冲刺时耐力消耗
|
||||
DashStaminaCost float32 `json:"dashStaminaCost"` // 猛冲时耐力消耗
|
||||
}
|
||||
|
||||
type ConfigVehicleCombat struct {
|
||||
Property *ConfigVehicleCombatProperty // 属性
|
||||
}
|
||||
|
||||
type ConfigVehicleCombatProperty struct {
|
||||
HP float32 `json:"HP"` // 血量
|
||||
Attack float32 `json:"attack"` // 攻击力
|
||||
DefenseBase float32 `json:"defenseBase"` // 防御力
|
||||
Weight float32 `json:"weight"` // 重量
|
||||
}
|
||||
|
||||
func (g *GameDataConfig) loadVehicleData() {
|
||||
g.VehicleDataMap = make(map[int32]*VehicleData)
|
||||
configGadgetVehiclesMap := make(map[string]map[string]*ConfigGadgetVehicle)
|
||||
vehicleDataList := make([]*VehicleData, 0)
|
||||
readTable[VehicleData](g.txtPrefix+"GadgetData_Vehicle.txt", &vehicleDataList)
|
||||
for _, vehicleData := range vehicleDataList {
|
||||
vehicleNameSplit := strings.Split(vehicleData.TextName, "_")
|
||||
if len(vehicleNameSplit) < 3 {
|
||||
info := fmt.Sprintf("vehicle text name split len less 3, TextName: %v", vehicleData.TextName)
|
||||
panic(info)
|
||||
}
|
||||
// 载具类型
|
||||
vehicleType := vehicleNameSplit[0]
|
||||
// 先判断一下是否已读取过同类型的载具配置
|
||||
configGadgetVehicles, ok := configGadgetVehiclesMap[vehicleType]
|
||||
if !ok {
|
||||
// 读取载具config
|
||||
fileData, err := os.ReadFile(g.jsonPrefix + "gadget/ConfigGadget_Vehicle_" + vehicleType + ".json")
|
||||
if err != nil {
|
||||
info := fmt.Sprintf("open file error: %v, vehicleType: %v", err, vehicleType)
|
||||
panic(info)
|
||||
}
|
||||
err = hjson.Unmarshal(fileData, &configGadgetVehicles)
|
||||
if err != nil {
|
||||
info := fmt.Sprintf("parse file error: %v, vehicleType: %v", err, vehicleType)
|
||||
panic(info)
|
||||
}
|
||||
configGadgetVehiclesMap[vehicleType] = configGadgetVehicles
|
||||
}
|
||||
// 载具config配置是否存在
|
||||
configVehicle, ok := configGadgetVehicles[vehicleData.TextName]
|
||||
if !ok {
|
||||
logger.Info("can not find any config of vehicle, vehicleId: %v", vehicleData.VehicleId)
|
||||
}
|
||||
vehicleData.ConfigGadgetVehicle = configVehicle
|
||||
|
||||
g.VehicleDataMap[vehicleData.VehicleId] = vehicleData
|
||||
}
|
||||
logger.Info("VehicleData count: %v", len(g.VehicleDataMap))
|
||||
}
|
||||
|
||||
func GetVehicleDataById(vehicleId int32) *VehicleData {
|
||||
return CONF.VehicleDataMap[vehicleId]
|
||||
}
|
||||
|
||||
func GetVehicleDataMap() map[int32]*VehicleData {
|
||||
return CONF.VehicleDataMap
|
||||
}
|
||||
@@ -256,6 +256,14 @@ func (t *TickManager) onTick200MilliSecond(now int64) {
|
||||
}
|
||||
|
||||
func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
for _, world := range WORLD_MANAGER.GetAllWorld() {
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
if player.SceneLoadState == model.SceneEnterDone {
|
||||
// 耐力回复计数器
|
||||
GAME.RestoreCountStaminaHandler(player)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TickManager) onTick50MilliSecond(now int64) {
|
||||
|
||||
+33
-16
@@ -1,6 +1,7 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"hk4e/gdconf"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
@@ -251,6 +252,12 @@ func (s *Scene) CreateEntityGadgetClient(pos, rot *model.Vector, entityId, confi
|
||||
}
|
||||
|
||||
func (s *Scene) CreateEntityGadgetVehicle(ownerUid uint32, pos, rot *model.Vector, vehicleId uint32) uint32 {
|
||||
// 获取载具配置表
|
||||
vehicleDataConfig := gdconf.GetVehicleDataById(int32(vehicleId))
|
||||
if vehicleDataConfig == nil {
|
||||
logger.Error("vehicle config error, vehicleId: %v", vehicleId)
|
||||
return 0
|
||||
}
|
||||
entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_GADGET)
|
||||
entity := &Entity{
|
||||
id: entityId,
|
||||
@@ -262,21 +269,22 @@ func (s *Scene) CreateEntityGadgetVehicle(ownerUid uint32, pos, rot *model.Vecto
|
||||
lastMoveSceneTimeMs: 0,
|
||||
lastMoveReliableSeq: 0,
|
||||
fightProp: map[uint32]float32{
|
||||
// TODO 以后使用配置表
|
||||
constant.FIGHT_PROP_CUR_HP: 114514,
|
||||
constant.FIGHT_PROP_MAX_HP: 114514,
|
||||
constant.FIGHT_PROP_BASE_HP: float32(1),
|
||||
constant.FIGHT_PROP_BASE_DEFENSE: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.DefenseBase,
|
||||
constant.FIGHT_PROP_CUR_HP: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.HP,
|
||||
constant.FIGHT_PROP_MAX_HP: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.HP,
|
||||
constant.FIGHT_PROP_CUR_ATTACK: vehicleDataConfig.ConfigGadgetVehicle.Combat.Property.Attack,
|
||||
},
|
||||
entityType: constant.ENTITY_TYPE_GADGET,
|
||||
gadgetEntity: &GadgetEntity{
|
||||
gadgetType: GADGET_TYPE_VEHICLE,
|
||||
gadgetVehicleEntity: &GadgetVehicleEntity{
|
||||
vehicleId: vehicleId,
|
||||
worldId: s.world.id,
|
||||
ownerUid: ownerUid,
|
||||
maxStamina: 240, // TODO 应该也能在配置表找到
|
||||
curStamina: 240, // TODO 与maxStamina一致
|
||||
memberMap: make(map[uint32]*model.Player),
|
||||
vehicleId: vehicleId,
|
||||
worldId: s.world.id,
|
||||
ownerUid: ownerUid,
|
||||
maxStamina: vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaUpperLimit,
|
||||
curStamina: vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaUpperLimit,
|
||||
restoreDelay: 0,
|
||||
memberMap: make(map[uint32]*model.Player),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -636,12 +644,13 @@ func (g *GadgetClientEntity) GetPropOwnerEntityId() uint32 {
|
||||
}
|
||||
|
||||
type GadgetVehicleEntity struct {
|
||||
vehicleId uint32
|
||||
worldId uint32
|
||||
ownerUid uint32
|
||||
maxStamina float32
|
||||
curStamina float32
|
||||
memberMap map[uint32]*model.Player // uint32 = pos
|
||||
vehicleId uint32
|
||||
worldId uint32
|
||||
ownerUid uint32
|
||||
maxStamina float32
|
||||
curStamina float32
|
||||
restoreDelay uint8 // 载具耐力回复延时
|
||||
memberMap map[uint32]*model.Player // uint32 = pos
|
||||
}
|
||||
|
||||
func (g *GadgetVehicleEntity) GetVehicleId() uint32 {
|
||||
@@ -667,3 +676,11 @@ func (g *GadgetVehicleEntity) SetCurStamina(curStamina float32) {
|
||||
func (g *GadgetVehicleEntity) GetMemberMap() map[uint32]*model.Player {
|
||||
return g.memberMap
|
||||
}
|
||||
|
||||
func (g *GadgetVehicleEntity) GetRestoreDelay() uint8 {
|
||||
return g.restoreDelay
|
||||
}
|
||||
|
||||
func (g *GadgetVehicleEntity) SetRestoreDelay(restoreDelay uint8) {
|
||||
g.restoreDelay = restoreDelay
|
||||
}
|
||||
+64
-20
@@ -157,6 +157,49 @@ func (g *Game) SkillStartStamina(player *model.Player, casterId uint32, skillId
|
||||
staminaInfo.LastSkillTime = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
// RestoreCountStaminaHandler 处理耐力回复计数器
|
||||
func (g *Game) RestoreCountStaminaHandler(player *model.Player) {
|
||||
// 玩家暂停状态不更新耐力
|
||||
if player.Pause {
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
// 处理载具
|
||||
// 遍历玩家创建的载具实体
|
||||
for _, entityId := range player.VehicleInfo.CreateEntityIdMap {
|
||||
// 获取载具实体
|
||||
entity := scene.GetEntity(entityId)
|
||||
if entity == nil {
|
||||
continue
|
||||
}
|
||||
// 确保实体类型是否为载具
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
if gadgetEntity == nil || gadgetEntity.GetGadgetVehicleEntity() == nil {
|
||||
continue
|
||||
}
|
||||
// 获取载具配置表
|
||||
vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().GetVehicleId()))
|
||||
if vehicleDataConfig == nil {
|
||||
logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().GetVehicleId())
|
||||
continue
|
||||
}
|
||||
restoreDelay := gadgetEntity.GetGadgetVehicleEntity().GetRestoreDelay()
|
||||
// 做个限制不然一直加就panic了
|
||||
if restoreDelay < uint8(vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaRecoverWaitTime*10) {
|
||||
gadgetEntity.GetGadgetVehicleEntity().SetRestoreDelay(restoreDelay + 1)
|
||||
}
|
||||
}
|
||||
// 处理玩家
|
||||
// 做个限制不然一直加就panic了
|
||||
if player.StaminaInfo.RestoreDelay < constant.STAMINA_PLAYER_RESTORE_DELAY {
|
||||
player.StaminaInfo.RestoreDelay++
|
||||
}
|
||||
}
|
||||
|
||||
// VehicleRestoreStaminaHandler 处理载具持续回复耐力
|
||||
func (g *Game) VehicleRestoreStaminaHandler(player *model.Player) {
|
||||
// 玩家暂停状态不更新耐力
|
||||
@@ -241,27 +284,31 @@ func (g *Game) UpdateVehicleStamina(player *model.Player, vehicleEntity *Entity,
|
||||
return
|
||||
}
|
||||
staminaInfo := player.StaminaInfo
|
||||
// 添加的耐力大于0为恢复
|
||||
if staminaCost > 0 {
|
||||
// 耐力延迟2s(10 ticks)恢复 动作状态为加速将立刻恢复耐力
|
||||
if staminaInfo.VehicleRestoreDelay < 10 && staminaInfo.State != proto.MotionState_MOTION_SKIFF_POWERED_DASH {
|
||||
// logger.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay)
|
||||
staminaInfo.VehicleRestoreDelay++
|
||||
return // 不恢复耐力
|
||||
}
|
||||
} else {
|
||||
// 消耗耐力重新计算恢复需要延迟的tick
|
||||
// logger.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.VehicleRestoreDelay)
|
||||
staminaInfo.VehicleRestoreDelay = 0
|
||||
}
|
||||
// 确保载具实体存在
|
||||
if vehicleEntity == nil {
|
||||
return
|
||||
}
|
||||
gadgetEntity := vehicleEntity.GetGadgetEntity()
|
||||
// 获取载具配置表
|
||||
vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().GetVehicleId()))
|
||||
if vehicleDataConfig == nil {
|
||||
logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().GetVehicleId())
|
||||
return
|
||||
}
|
||||
// 添加的耐力大于0为恢复
|
||||
if staminaCost > 0 {
|
||||
// 耐力延迟1.5s(15 ticks)恢复 动作状态为加速将立刻恢复耐力
|
||||
restoreDelay := gadgetEntity.GetGadgetVehicleEntity().GetRestoreDelay()
|
||||
if restoreDelay < uint8(vehicleDataConfig.ConfigGadgetVehicle.Vehicle.Stamina.StaminaRecoverWaitTime*10) && staminaInfo.State != proto.MotionState_MOTION_SKIFF_POWERED_DASH {
|
||||
return // 不恢复耐力
|
||||
}
|
||||
} else {
|
||||
// 消耗耐力重新计算恢复需要延迟的tick
|
||||
gadgetEntity.GetGadgetVehicleEntity().SetRestoreDelay(0)
|
||||
}
|
||||
// 因为载具的耐力需要换算
|
||||
// 这里先*100后面要用的时候再换算 为了确保精度
|
||||
// 最大耐力值
|
||||
gadgetEntity := vehicleEntity.GetGadgetEntity()
|
||||
maxStamina := int32(gadgetEntity.GetGadgetVehicleEntity().GetMaxStamina() * 100)
|
||||
// 现行耐力值
|
||||
curStamina := int32(gadgetEntity.GetGadgetVehicleEntity().GetCurStamina() * 100)
|
||||
@@ -284,16 +331,13 @@ func (g *Game) UpdatePlayerStamina(player *model.Player, staminaCost int32) {
|
||||
staminaInfo := player.StaminaInfo
|
||||
// 添加的耐力大于0为恢复
|
||||
if staminaCost > 0 {
|
||||
// 耐力延迟2s(10 ticks)恢复 动作状态为加速将立刻恢复耐力
|
||||
if staminaInfo.PlayerRestoreDelay < 10 && staminaInfo.State != proto.MotionState_MOTION_POWERED_FLY {
|
||||
// logger.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay)
|
||||
staminaInfo.PlayerRestoreDelay++
|
||||
// 耐力延迟1.5s(15 ticks)恢复 动作状态为加速将立刻恢复耐力
|
||||
if staminaInfo.RestoreDelay < constant.STAMINA_PLAYER_RESTORE_DELAY && staminaInfo.State != proto.MotionState_MOTION_POWERED_FLY {
|
||||
return // 不恢复耐力
|
||||
}
|
||||
} else {
|
||||
// 消耗耐力重新计算恢复需要延迟的tick
|
||||
// logger.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.RestoreDelay)
|
||||
staminaInfo.PlayerRestoreDelay = 0
|
||||
staminaInfo.RestoreDelay = 0
|
||||
}
|
||||
// 最大耐力值
|
||||
maxStamina := int32(player.PropertiesMap[constant.PLAYER_PROP_MAX_STAMINA])
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"hk4e/gdconf"
|
||||
"time"
|
||||
|
||||
"hk4e/gs/model"
|
||||
@@ -143,9 +144,15 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
|
||||
|
||||
// EnterVehicle 进入载具
|
||||
func (g *Game) EnterVehicle(player *model.Player, entity *Entity, avatarGuid uint64) {
|
||||
maxSlot := 1 // TODO 读取配置表
|
||||
// 判断载具是否已满
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
// 获取载具配置表
|
||||
vehicleDataConfig := gdconf.GetVehicleDataById(int32(gadgetEntity.GetGadgetVehicleEntity().vehicleId))
|
||||
if vehicleDataConfig == nil {
|
||||
logger.Error("vehicle config error, vehicleId: %v", gadgetEntity.GetGadgetVehicleEntity().vehicleId)
|
||||
return
|
||||
}
|
||||
maxSlot := int(vehicleDataConfig.ConfigGadgetVehicle.Vehicle.MaxSeatCount)
|
||||
// 判断载具是否已满
|
||||
if len(gadgetEntity.GetGadgetVehicleEntity().GetMemberMap()) >= maxSlot {
|
||||
g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_VEHICLE_SLOT_OCCUPIED)
|
||||
return
|
||||
|
||||
+1
-2
@@ -8,8 +8,7 @@ import (
|
||||
type StaminaInfo struct {
|
||||
State proto.MotionState // 动作状态
|
||||
CostStamina int32 // 消耗或恢复的耐力
|
||||
PlayerRestoreDelay uint8 // 玩家耐力回复延时
|
||||
VehicleRestoreDelay uint8 // 载具耐力回复延时
|
||||
RestoreDelay uint8 // 玩家耐力回复延时
|
||||
LastSkillTime int64 // 最后释放技能的时间
|
||||
LastCostStaminaTime int64 // 最后执行技能耐力消耗的时间
|
||||
DrownBackDelay uint8 // 溺水返回安全点延时
|
||||
|
||||
Reference in new issue
Block a user