2025-09-05 22:23:41 +08:00
|
|
|
@tool
|
|
|
|
|
extends PanelContainer
|
|
|
|
|
class_name Weapon
|
|
|
|
|
|
|
|
|
|
@export var avatarTexture: Texture2D = preload("res://icon.svg")
|
|
|
|
|
@export var displayName: String = "未命名饲料"
|
|
|
|
|
@export var quality: WeaponName.Quality = WeaponName.Quality.COMMON
|
|
|
|
|
@export var typeTopic: WeaponName.TypeTopic = WeaponName.TypeTopic.IMPACT
|
2025-09-06 11:14:02 +08:00
|
|
|
@export var costBeachball: int = 0
|
2025-09-05 22:23:41 +08:00
|
|
|
@export var store: Dictionary = {
|
|
|
|
|
"atk": 10
|
|
|
|
|
}
|
2025-09-06 08:17:10 +08:00
|
|
|
@export var storeType: Array[FieldStore.DataType] = [
|
|
|
|
|
FieldStore.DataType.VALUE
|
|
|
|
|
]
|
2025-09-05 22:23:41 +08:00
|
|
|
@export var descriptionTemplate: String = "造成$atk点伤害。"
|
|
|
|
|
@export var needEnergy: float = 0
|
|
|
|
|
@export var cooldown: float = 100
|
2025-09-06 08:17:10 +08:00
|
|
|
@export var debugRebuild: bool = false
|
2025-09-06 11:14:02 +08:00
|
|
|
@export var level: int = 0
|
2025-09-05 22:23:41 +08:00
|
|
|
|
|
|
|
|
@onready var avatarRect: TextureRect = $"%avatar"
|
|
|
|
|
@onready var nameLabel: WeaponName = $"%name"
|
|
|
|
|
@onready var energyLabel: Label = $"%energy"
|
2025-09-06 11:14:02 +08:00
|
|
|
@onready var beachballLabel: Label = $"%beachball"
|
2025-09-05 22:23:41 +08:00
|
|
|
@onready var descriptionLabel: RichTextLabel = $"%description"
|
2025-09-06 08:05:43 +08:00
|
|
|
@onready var updateButton: Button = $"%updateBtn"
|
2025-09-06 08:50:37 +08:00
|
|
|
@onready var sounds: Node2D = $"%sounds"
|
2025-09-05 22:23:41 +08:00
|
|
|
|
2025-09-06 15:24:50 +08:00
|
|
|
var cooldownTimer: CooldownTimer = null
|
2025-09-06 11:14:02 +08:00
|
|
|
var originalStore: Dictionary = {}
|
2025-09-06 07:40:21 +08:00
|
|
|
|
2025-09-05 22:23:41 +08:00
|
|
|
func _ready():
|
2025-09-06 15:24:50 +08:00
|
|
|
cooldownTimer = CooldownTimer.new()
|
|
|
|
|
cooldownTimer.cooldown = cooldown
|
2025-09-06 11:14:02 +08:00
|
|
|
originalStore = store
|
2025-09-06 08:05:43 +08:00
|
|
|
updateButton.pressed.connect(
|
2025-09-05 22:23:41 +08:00
|
|
|
func():
|
|
|
|
|
apply(UIState.player)
|
|
|
|
|
)
|
2025-09-06 08:50:37 +08:00
|
|
|
for i in sounds.get_children():
|
|
|
|
|
i.process_mode = ProcessMode.PROCESS_MODE_ALWAYS
|
2025-09-05 22:23:41 +08:00
|
|
|
rebuildInfo()
|
2025-09-06 08:17:10 +08:00
|
|
|
debugRebuild = false # 只能在编辑器里打开
|
|
|
|
|
func _physics_process(_delta):
|
|
|
|
|
if debugRebuild:
|
|
|
|
|
rebuildInfo()
|
2025-09-05 22:23:41 +08:00
|
|
|
|
|
|
|
|
func allHad(entity: EntityBase) -> bool:
|
2025-09-06 11:14:02 +08:00
|
|
|
return entity.inventory[ItemStore.ItemType.BEACHBALL] >= costBeachball
|
2025-09-05 22:23:41 +08:00
|
|
|
func apply(entity: EntityBase):
|
|
|
|
|
var allHave = allHad(entity)
|
|
|
|
|
if allHave:
|
2025-09-06 11:59:24 +08:00
|
|
|
level += 1
|
2025-09-06 11:14:02 +08:00
|
|
|
entity.inventory[ItemStore.ItemType.BEACHBALL] -= costBeachball
|
2025-09-06 11:59:24 +08:00
|
|
|
store = update(level, originalStore.duplicate(), entity)
|
|
|
|
|
costBeachball *= 2
|
|
|
|
|
rebuildInfo()
|
2025-09-05 22:23:41 +08:00
|
|
|
return allHave
|
|
|
|
|
func multipiler() -> float:
|
|
|
|
|
if is_instance_valid(UIState.player):
|
|
|
|
|
return 1 - UIState.player.fields.get(FieldStore.Entity.PRICE_REDUCTION)
|
|
|
|
|
else:
|
|
|
|
|
return 1
|
|
|
|
|
func rebuildInfo():
|
|
|
|
|
avatarRect.texture = avatarTexture
|
|
|
|
|
nameLabel.displayName = displayName
|
|
|
|
|
nameLabel.quality = quality
|
|
|
|
|
nameLabel.typeTopic = typeTopic
|
2025-09-06 11:59:24 +08:00
|
|
|
nameLabel.level = level
|
2025-09-05 22:23:41 +08:00
|
|
|
energyLabel.text = "%.1f" % needEnergy
|
2025-09-06 11:14:02 +08:00
|
|
|
beachballLabel.text = str(costBeachball)
|
2025-09-06 08:17:10 +08:00
|
|
|
descriptionLabel.text = buildDescription()
|
2025-09-06 11:14:02 +08:00
|
|
|
func buildDescription() -> String:
|
2025-09-05 22:23:41 +08:00
|
|
|
var result = descriptionTemplate
|
2025-09-06 08:17:10 +08:00
|
|
|
var i = 0
|
2025-09-05 22:23:41 +08:00
|
|
|
for key in store.keys():
|
2025-09-06 08:17:10 +08:00
|
|
|
var data = store[key]
|
|
|
|
|
var type = storeType[i]
|
|
|
|
|
if type == FieldStore.DataType.VALUE:
|
|
|
|
|
data = "%.1f" % data
|
|
|
|
|
elif type == FieldStore.DataType.PERCENT:
|
|
|
|
|
data = ("%.1f" % (data * 100)) + "%"
|
|
|
|
|
elif type == FieldStore.DataType.ANGLE:
|
|
|
|
|
data = "%.1f°" % data
|
|
|
|
|
result = result.replace("$" + key, "[color=cyan]%s[/color]" % data)
|
|
|
|
|
i += 1
|
2025-09-06 07:40:21 +08:00
|
|
|
return "[center]%s[/center]" % result
|
2025-09-05 22:23:41 +08:00
|
|
|
func readStore(key: String, default: Variant = null):
|
|
|
|
|
return store.get(key, default)
|
2025-09-06 08:50:37 +08:00
|
|
|
func playSound(sound: String):
|
|
|
|
|
var body = sounds.get_node_or_null(sound)
|
|
|
|
|
if body is AudioStreamPlayer2D:
|
|
|
|
|
var cloned = body.duplicate() as AudioStreamPlayer2D
|
|
|
|
|
add_child(cloned)
|
|
|
|
|
cloned.play()
|
|
|
|
|
await cloned.finished
|
|
|
|
|
cloned.queue_free()
|
|
|
|
|
func tryAttack(entity: EntityBase):
|
|
|
|
|
if cooldownTimer.start():
|
|
|
|
|
if entity.useEnergy(needEnergy):
|
2025-09-06 09:34:58 +08:00
|
|
|
return attack(entity)
|
2025-09-05 22:23:41 +08:00
|
|
|
|
|
|
|
|
# 抽象
|
2025-09-06 11:14:02 +08:00
|
|
|
func update(_to: int, origin: Dictionary, _entity: EntityBase):
|
|
|
|
|
return origin
|
2025-09-05 22:23:41 +08:00
|
|
|
func attack(_entity: EntityBase):
|
|
|
|
|
pass
|