mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
refactor(BulletBase/EntityBase): 重构子弹和实体属性系统
将子弹的fields属性拆分为独立的speed、damage和penerate变量 为所有子弹和实体添加register方法用于初始化属性 统一攻击冷却时间管理为attackCooldownMap 移除FieldStore中不再使用的Bullet相关枚举和映射
This commit is contained in:
@@ -17,11 +17,6 @@ animations = [{
|
||||
|
||||
[node name="Diamond" instance=ExtResource("1_8udva")]
|
||||
script = ExtResource("2_yxtyj")
|
||||
fields = {
|
||||
0: 10,
|
||||
1: 2,
|
||||
2: 0
|
||||
}
|
||||
lifeTime = 5000.0
|
||||
indisDamage = true
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
extends BulletBase
|
||||
class_name BigLaser # 这个子弹是玩家的超级武器,耗能高,dps也高
|
||||
|
||||
func register():
|
||||
speed = 0
|
||||
damage = 35
|
||||
penerate = 1
|
||||
func spawn():
|
||||
CameraManager.shake(5000, 150) # 激光会运行5秒(5000毫秒),期间震屏超高强度
|
||||
CameraManager.playAnimation("bigLaser")
|
||||
fields[FieldStore.Bullet.DAMAGE] *= launcher.fields[FieldStore.Entity.ATTACK_SPEED]
|
||||
damage *= launcher.fields[FieldStore.Entity.ATTACK_SPEED]
|
||||
func ai():
|
||||
rotation = lerp_angle(rotation, ((get_global_mouse_position() - position).angle()), 0.1)
|
||||
position = launcher.texture.global_position
|
||||
|
||||
@@ -3,6 +3,8 @@ class_name Diamond
|
||||
|
||||
const traceTime = 2000
|
||||
|
||||
func register():
|
||||
damage = 2
|
||||
func ai():
|
||||
rotation = lerp_angle(rotation, position.angle_to_point(launcher.currentFocusedBoss.position), 0.1 * clamp((traceTime - timeLived()) / traceTime, 0, INF))
|
||||
canDamageSelf = !(timeLived() >= traceTime)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
extends BulletBase
|
||||
class_name FireScan
|
||||
|
||||
func _ready():
|
||||
fields[FieldStore.Bullet.SPEED] = 5
|
||||
fields[FieldStore.Bullet.DAMAGE] = 20
|
||||
super._ready()
|
||||
func register():
|
||||
speed = 5
|
||||
damage = 20
|
||||
|
||||
func ai():
|
||||
forward(Vector2.from_angle(rotation))
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
extends BulletBase
|
||||
class_name Pencil
|
||||
|
||||
func register():
|
||||
damage = 20
|
||||
func spawn():
|
||||
await TickTool.millseconds(1000)
|
||||
hitbox.disabled = false
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
extends BulletBase
|
||||
class_name Star
|
||||
|
||||
func register():
|
||||
damage = 1
|
||||
func ai():
|
||||
forward(Vector2.from_angle(rotation))
|
||||
|
||||
@@ -1,17 +1,2 @@
|
||||
extends EntityBase
|
||||
class_name Bear
|
||||
|
||||
func ai():
|
||||
pass
|
||||
func attack(type):
|
||||
if type == 0:
|
||||
var weaponPos = findWeaponAnchor("normal")
|
||||
return BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), self, weaponPos, (get_global_mouse_position() - weaponPos).angle())
|
||||
func sprint():
|
||||
move(Vector2(
|
||||
Input.get_axis("m_left", "m_right"),
|
||||
Input.get_axis("m_up", "m_down")
|
||||
) * sprintMultiplier, true)
|
||||
func heal(count: float):
|
||||
health += count
|
||||
DamageLabel.create(-count, false, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
|
||||
|
||||
@@ -5,10 +5,12 @@ class_name Chick
|
||||
|
||||
const laserCount = 4
|
||||
|
||||
func _ready():
|
||||
func register():
|
||||
fields[FieldStore.Entity.MAX_HEALTH] = 2000
|
||||
fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.1
|
||||
super._ready()
|
||||
fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.35
|
||||
attackCooldownMap[0] = 2000
|
||||
attackCooldownMap[1] = 3000
|
||||
attackCooldownMap[2] = 100
|
||||
|
||||
func ai():
|
||||
move(currentFocusedBoss.position - position)
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
extends EntityBase
|
||||
class_name Hen
|
||||
|
||||
func _ready():
|
||||
func register():
|
||||
fields[FieldStore.Entity.MAX_HEALTH] = 75
|
||||
fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.25
|
||||
fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.15
|
||||
fields[FieldStore.Entity.OFFSET_SHOOT] = 10
|
||||
super._ready()
|
||||
|
||||
func ai():
|
||||
cooldownUnit = randi_range(1500, 4000)
|
||||
attackCooldownMap[0] = randi_range(1500, 4000)
|
||||
move(currentFocusedBoss.position - position)
|
||||
tryAttack(0)
|
||||
func attack(type):
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
extends EntityBase
|
||||
class_name Rooster
|
||||
|
||||
func register():
|
||||
attackCooldownMap[0] = 200
|
||||
attackCooldownMap[1] = 6000
|
||||
func ai():
|
||||
texture.play("walk")
|
||||
var direction = Vector2(
|
||||
@@ -11,10 +14,8 @@ func ai():
|
||||
if direction.length() == 0:
|
||||
texture.play("idle")
|
||||
if Input.is_action_pressed("attack"):
|
||||
cooldownUnit = 200
|
||||
tryAttack(0)
|
||||
elif Input.is_action_pressed("attack2"):
|
||||
cooldownUnit = 6000
|
||||
tryAttack(1)
|
||||
if Input.is_action_just_pressed("sprint"):
|
||||
trySprint()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
extends Area2D
|
||||
class_name BulletBase
|
||||
|
||||
@export var fields = {
|
||||
FieldStore.Bullet.SPEED: 10,
|
||||
FieldStore.Bullet.DAMAGE: 10,
|
||||
FieldStore.Bullet.PENERATE: 0
|
||||
}
|
||||
@export var speed: float = 10.0
|
||||
@export var damage: float = 10.0
|
||||
@export var penerate: float = 0.0
|
||||
@export var lifeDistance: float = -1 # -1表示无限距离
|
||||
@export var lifeTime: float = -1 # -1表示无限时间
|
||||
@export var indisDamage: bool = false # 是否无差别伤害(不区分敌我)
|
||||
@@ -26,6 +24,7 @@ var spawnInWhen: float = 0
|
||||
var spawnInWhere: Vector2 = Vector2.ZERO
|
||||
|
||||
func _ready():
|
||||
register()
|
||||
area_entered.connect(hit)
|
||||
spawnInWhen = WorldManager.getTime()
|
||||
spawnInWhere = position
|
||||
@@ -56,16 +55,16 @@ func hit(target: Node):
|
||||
if !canDamageSelf && entity == launcher: return
|
||||
if !indisDamage && !GameRule.allowFriendlyFire:
|
||||
if entity.isPlayer() == launcher.isPlayer(): return
|
||||
var damage = entity.takeDamage(self, MathTool.rate(launcher.fields.get(FieldStore.Entity.CRIT_RATE) + GameRule.critRateInfluenceByLuckValue * launcher.fields[FieldStore.Entity.LUCK_VALUE]))
|
||||
succeedToHit(damage)
|
||||
var damages = entity.takeDamage(self, MathTool.rate(launcher.fields.get(FieldStore.Entity.CRIT_RATE) + GameRule.critRateInfluenceByLuckValue * launcher.fields[FieldStore.Entity.LUCK_VALUE]))
|
||||
succeedToHit(damages)
|
||||
if MathTool.rate(fullPenerate()):
|
||||
fields[FieldStore.Bullet.PENERATE] -= entity.fields[FieldStore.Entity.PENARATION_RESISTANCE]
|
||||
penerate -= entity.fields[FieldStore.Entity.PENARATION_RESISTANCE]
|
||||
else:
|
||||
destroy()
|
||||
func forward(direction: Vector2):
|
||||
position += direction.normalized() * fields.get(FieldStore.Bullet.SPEED) * GameRule.bulletSpeedMultiplier
|
||||
position += direction.normalized() * speed * GameRule.bulletSpeedMultiplier
|
||||
func fullPenerate():
|
||||
return fields.get(FieldStore.Bullet.PENERATE) + launcher.fields.get(FieldStore.Entity.PENERATE) + GameRule.penerateRateInfluenceByLuckValue * launcher.fields[FieldStore.Entity.LUCK_VALUE]
|
||||
return penerate + launcher.fields.get(FieldStore.Entity.PENERATE) + GameRule.penerateRateInfluenceByLuckValue * launcher.fields[FieldStore.Entity.LUCK_VALUE]
|
||||
func timeLived():
|
||||
return WorldManager.getTime() - spawnInWhen
|
||||
func dotLoop():
|
||||
@@ -82,6 +81,8 @@ func applyDot():
|
||||
pass
|
||||
func succeedToHit(_dmg: float):
|
||||
pass
|
||||
func register():
|
||||
pass
|
||||
|
||||
static func generate(
|
||||
bullet: PackedScene,
|
||||
|
||||
@@ -38,6 +38,9 @@ var fields = {
|
||||
FieldStore.Entity.SAVE_ENERGY: 1,
|
||||
FieldStore.Entity.ENERGY_REGENERATION: 1,
|
||||
}
|
||||
var attackCooldownMap = {
|
||||
0: 100
|
||||
}
|
||||
var inventory = {
|
||||
ItemStore.ItemType.BASEBALL: 100,
|
||||
ItemStore.ItemType.BASKETBALL: 100,
|
||||
@@ -49,7 +52,7 @@ var inventoryMax = {
|
||||
ItemStore.ItemType.APPLE: 5, # 最多5个苹果
|
||||
}
|
||||
|
||||
@export var cooldownUnit: float = 100 # 100毫秒每次攻击
|
||||
@export var defaultCooldownUnit: float = 100
|
||||
@export var isBoss: bool = false
|
||||
@export var displayName: String = "未知实体"
|
||||
@export var sprintMultiplier: float = 4
|
||||
@@ -57,6 +60,7 @@ var inventoryMax = {
|
||||
@export var dropCounts: Array[Vector2] = []
|
||||
@export var appleCount: Vector2i = Vector2(0, 2) # 死亡后掉落的苹果数量
|
||||
@export var level: int = 1 # 等级
|
||||
@export var sprintEnergy: float = 5
|
||||
|
||||
@onready var animatree: AnimationTree = $"%animatree"
|
||||
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||
@@ -75,6 +79,7 @@ var lastAttack: int = 0
|
||||
var currentFocusedBoss: EntityBase = null
|
||||
|
||||
func _ready():
|
||||
register()
|
||||
var selfStatebar: EntityStateBar = $"%statebar"
|
||||
if isBoss:
|
||||
selfStatebar.hide()
|
||||
@@ -140,7 +145,7 @@ func move(direction: Vector2, isSprinting: bool = false):
|
||||
lastDirection = currentDirection
|
||||
func takeDamage(bullet: BulletBase, crit: bool):
|
||||
hurtAnimator.play("hurt")
|
||||
var baseDamage: float = bullet.fields.get(FieldStore.Bullet.DAMAGE) * bullet.launcher.fields.get(FieldStore.Entity.DAMAGE_MULTIPILER) * randf_range(1 - GameRule.damageOffset, 1 + GameRule.damageOffset)
|
||||
var baseDamage: float = bullet.damage * bullet.launcher.fields.get(FieldStore.Entity.DAMAGE_MULTIPILER) * randf_range(1 - GameRule.damageOffset, 1 + GameRule.damageOffset)
|
||||
var damage = baseDamage + baseDamage * int(crit) * fields.get(FieldStore.Entity.CRIT_DAMAGE)
|
||||
if sprinting:
|
||||
playSound("miss")
|
||||
@@ -175,23 +180,24 @@ func useEnergy(value: float):
|
||||
energy -= value
|
||||
energyChanged.emit(energy)
|
||||
return state
|
||||
func isCooldowned():
|
||||
return WorldManager.getTime() - lastAttack >= cooldownUnit / fields.get(FieldStore.Entity.ATTACK_SPEED)
|
||||
func startCooldown():
|
||||
var state = isCooldowned()
|
||||
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):
|
||||
var state = startCooldown()
|
||||
var state = startCooldown(type)
|
||||
if state:
|
||||
if attack(type):
|
||||
playSound("attack" + str(type))
|
||||
return state
|
||||
func trySprint():
|
||||
playSound("sprint")
|
||||
sprint()
|
||||
sprinting = true
|
||||
if useEnergy(sprintEnergy):
|
||||
playSound("sprint")
|
||||
sprint()
|
||||
sprinting = true
|
||||
func tryDie(by: BulletBase):
|
||||
for drop in range(min(len(drops), len(dropCounts))):
|
||||
var item = drops[drop]
|
||||
@@ -250,6 +256,8 @@ func sprint():
|
||||
func heal(count: float):
|
||||
health += count
|
||||
return count
|
||||
func register():
|
||||
pass
|
||||
|
||||
static func generate(
|
||||
entity: PackedScene,
|
||||
|
||||
@@ -101,20 +101,4 @@ static var entityViewCastMap = {
|
||||
Entity.EXTRA_APPLE_MAX: func(entity, _value):
|
||||
return entity.inventoryMax[ItemStore.ItemType.APPLE]
|
||||
,
|
||||
}
|
||||
|
||||
enum Bullet {
|
||||
SPEED,
|
||||
DAMAGE,
|
||||
PENERATE
|
||||
}
|
||||
static var bulletMap = {
|
||||
Bullet.SPEED: "速度",
|
||||
Bullet.DAMAGE: "伤害",
|
||||
Bullet.PENERATE: "穿透"
|
||||
}
|
||||
static var bulletMapType = {
|
||||
Bullet.SPEED: DataType.VALUE,
|
||||
Bullet.DAMAGE: DataType.VALUE,
|
||||
Bullet.PENERATE: DataType.PERCENT
|
||||
}
|
||||
@@ -3,7 +3,7 @@ class_name WorldManager
|
||||
|
||||
static var rootNode: Node2D
|
||||
static var tree: SceneTree
|
||||
static var runningTime: float = 0
|
||||
static var runningTime: int = 0
|
||||
|
||||
func _ready():
|
||||
tree = get_tree()
|
||||
|
||||
Reference in New Issue
Block a user