mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
refactor(武器系统): 优化武器攻击逻辑和能量检查
- 将武器攻击前的条件检查提取为独立方法 canAttackBy - 重构能量检查逻辑,增加 isEnergyEnough 方法 - 简化公鸡角色的输入处理,合并重复代码为 tryLaunch 方法 - 调整钢管武器的冷却时间为 3000.0
This commit is contained in:
@@ -25,27 +25,12 @@ func ai():
|
||||
move(direction)
|
||||
if direction.length() == 0:
|
||||
texture.play("idle")
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
startCharge(0)
|
||||
if Input.is_action_just_released("attack"):
|
||||
endCharge(0)
|
||||
if Input.is_action_just_pressed("attack2"):
|
||||
startCharge(1)
|
||||
if Input.is_action_just_released("attack2"):
|
||||
endCharge(1)
|
||||
if Input.is_action_just_pressed("smallSkill"):
|
||||
startCharge(2)
|
||||
if Input.is_action_just_released("smallSkill"):
|
||||
endCharge(2)
|
||||
if Input.is_action_just_pressed("superSkill"):
|
||||
startCharge(3)
|
||||
if Input.is_action_just_released("superSkill"):
|
||||
endCharge(3)
|
||||
tryLaunch("attack", 0)
|
||||
tryLaunch("attack2", 1)
|
||||
tryLaunch("smallSkill", 2)
|
||||
tryLaunch("superSkill", 3)
|
||||
for i in range(3):
|
||||
if Input.is_action_just_pressed("cardSkill" + str(i)):
|
||||
startCharge(4 + i)
|
||||
if Input.is_action_just_released("cardSkill" + str(i)):
|
||||
endCharge(4 + i)
|
||||
tryLaunch("cardSkill%d" % i, 4 + i)
|
||||
if Input.is_action_just_pressed("sprint"):
|
||||
trySprint()
|
||||
if Input.is_action_just_pressed("heal"):
|
||||
@@ -60,21 +45,25 @@ func sprint():
|
||||
Input.get_axis("m_up", "m_down")
|
||||
) * sprintMultiplier, true)
|
||||
|
||||
func startCharge(weaponIndex: int):
|
||||
if len(weapons) > weaponIndex:
|
||||
var weapon = weapons[weaponIndex]
|
||||
if weapon.chargable:
|
||||
chargeStartTime[weaponIndex] = Time.get_ticks_msec()
|
||||
chargeParticle.emitting = true
|
||||
func endCharge(weaponIndex: int):
|
||||
if chargeStartTime.has(weaponIndex):
|
||||
var startTime = chargeStartTime[weaponIndex]
|
||||
var endTime = Time.get_ticks_msec()
|
||||
var chargedTime = endTime - startTime
|
||||
chargeStartTime.erase(weaponIndex)
|
||||
func tryLaunch(action: String, weaponIndex: int):
|
||||
if Input.is_action_just_pressed(action):
|
||||
if len(weapons) > weaponIndex:
|
||||
var weapon = weapons[weaponIndex]
|
||||
if weapon.chargable:
|
||||
weapon.chargedTime = chargedTime
|
||||
tryAttack(weaponIndex)
|
||||
chargeParticle.emitting = false
|
||||
if weapon.chargable and weapon.canAttackBy(self):
|
||||
chargeStartTime[weaponIndex] = Time.get_ticks_msec()
|
||||
chargeParticle.emitting = true
|
||||
if Input.is_action_pressed(action):
|
||||
if !chargeStartTime.has(weaponIndex):
|
||||
tryAttack(weaponIndex)
|
||||
if Input.is_action_just_released(action):
|
||||
if chargeStartTime.has(weaponIndex):
|
||||
var startTime = chargeStartTime[weaponIndex]
|
||||
var endTime = Time.get_ticks_msec()
|
||||
var chargedTime = endTime - startTime
|
||||
chargeStartTime.erase(weaponIndex)
|
||||
if len(weapons) > weaponIndex:
|
||||
var weapon = weapons[weaponIndex]
|
||||
if weapon.chargable:
|
||||
weapon.chargedTime = chargedTime
|
||||
tryAttack(weaponIndex)
|
||||
chargeParticle.emitting = false
|
||||
|
||||
Reference in New Issue
Block a user