mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-29 23:12:28 +08:00
refactor(Statemachine): 引入CooldownTimer类重构攻击冷却逻辑
将攻击冷却逻辑从EntityBase中提取到独立的CooldownTimer类 简化EntityBase代码并提高可维护性
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
class_name CooldownTimer
|
||||||
|
|
||||||
|
var cooldown: float = 100
|
||||||
|
var lastStart: int = 0
|
||||||
|
|
||||||
|
func isCooldowned():
|
||||||
|
return WorldManager.getTime() - lastStart >= cooldown
|
||||||
|
func startCooldown():
|
||||||
|
var state = isCooldowned()
|
||||||
|
if state:
|
||||||
|
lastStart = WorldManager.getTime()
|
||||||
|
return state
|
||||||
@@ -64,6 +64,7 @@ var inventoryMax = {
|
|||||||
@export var dropCounts: Array[Vector2] = []
|
@export var dropCounts: Array[Vector2] = []
|
||||||
@export var appleCount: Vector2i = Vector2(0, 2) # 死亡后掉落的苹果数量
|
@export var appleCount: Vector2i = Vector2(0, 2) # 死亡后掉落的苹果数量
|
||||||
@export var level: int = 1
|
@export var level: int = 1
|
||||||
|
@export var weapons: Array[Weapon] = []
|
||||||
|
|
||||||
@onready var animatree: AnimationTree = $"%animatree"
|
@onready var animatree: AnimationTree = $"%animatree"
|
||||||
@onready var texture: AnimatedSprite2D = $"%texture"
|
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||||
@@ -80,9 +81,9 @@ var sprinting: bool = false
|
|||||||
var trailing: bool = false
|
var trailing: bool = false
|
||||||
|
|
||||||
var lastDirection: int = 1
|
var lastDirection: int = 1
|
||||||
var lastAttack: int = 0
|
|
||||||
var currentFocusedBoss: EntityBase = null
|
var currentFocusedBoss: EntityBase = null
|
||||||
var charginup: bool = false
|
var charginup: bool = false
|
||||||
|
var cooldownTimer = CooldownTimer.new()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
register()
|
register()
|
||||||
@@ -188,15 +189,11 @@ func useEnergy(value: float):
|
|||||||
energy -= value
|
energy -= value
|
||||||
energyChanged.emit(energy)
|
energyChanged.emit(energy)
|
||||||
return state
|
return state
|
||||||
func isCooldowned(type: int):
|
|
||||||
return WorldManager.getTime() - lastAttack >= attackCooldownMap.get(type, defaultCooldownUnit) / fields.get(FieldStore.Entity.ATTACK_SPEED)
|
|
||||||
func startCooldown(type: int):
|
|
||||||
var state = isCooldowned(type)
|
|
||||||
if state:
|
|
||||||
lastAttack = WorldManager.getTime()
|
|
||||||
return state
|
|
||||||
func tryAttack(type: int, needChargeUp: bool = false):
|
func tryAttack(type: int, needChargeUp: bool = false):
|
||||||
var state = startCooldown(type)
|
var state
|
||||||
|
if !isPlayer():
|
||||||
|
cooldownTimer.cooldown = attackCooldownMap.get(type, defaultCooldownUnit)
|
||||||
|
state = cooldownTimer.startCooldown()
|
||||||
if state:
|
if state:
|
||||||
if needChargeUp:
|
if needChargeUp:
|
||||||
charginup = true
|
charginup = true
|
||||||
|
|||||||
Reference in New Issue
Block a user