Cow_Life_Sim_RPG/Interactions/Arson/Arsonable.gd

88 lines
2.5 KiB
GDScript

extends Interaction
var fireScene = preload("res://Skills/Arson/Fire.tscn")
var smokeScene = preload("res://Skills/Arson/Smoke.tscn")
@export var ashItemClass:Resource
@export var flammability = 0
@export var weight = 0
var ashDropLocation:Vector2
var rng = RandomNumberGenerator.new()
var flintSoundPlayer
var lastSoundIndex = -1
var flintSounds = []
func _ready():
add_action("Burn", burn)
initialize_flint_sounds()
func initialize_flint_sounds():
flintSoundPlayer = $FlintSounds
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint1.mp3"))
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint2.mp3"))
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint3.mp3"))
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint4.mp3"))
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint5.mp3"))
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint6.mp3"))
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint7.mp3"))
flintSounds.append(load("res://Sounds/SFX/Fire/Flint/flint8.mp3"))
func burn():
play_flint_sound()
if "item" in get_parent():
flammability = get_parent().item.flammability
weight = get_parent().item.weight
var fireChance = LevelManager.get_skill("arson").get_ignition_chance_by_stats(flammability, weight)
if rng.randf_range(0, 100) <= fireChance:
light_up()
get_tree().call_group("FlagManager", "Arsoned")
elif fireChance >= 0.5:
smoke()
func play_flint_sound():
var newIndex = rng.randi_range(0, flintSounds.size() - 1)
if newIndex == lastSoundIndex:
newIndex = rng.randi_range(0, flintSounds.size() - 1)
flintSoundPlayer.stream = flintSounds[newIndex]
flintSoundPlayer.play()
lastSoundIndex = newIndex
func light_up():
GlobalEvents.itemBurnt.emit(get_parent().item)
var newFire = fireScene.instantiate()
newFire.set_item_burning(get_parent().item)
AchievementManager.burn_achievement_checks(get_parent().item)
var target_global_pos = get_parent().global_position + Vector2(0, 5)
get_parent().get_parent().add_child(newFire)
newFire.global_position = target_global_pos
newFire.set_item_burning(get_parent().item)
if get_parent() == GameVariables.player.currentInteractingGroundItem:
GameVariables.player.change_state("Idle")
get_parent().queue_free()
func smoke():
var newSmoke = smokeScene.instantiate()
newSmoke.position = position + Vector2(0, -20)
newSmoke.emitting = true
get_parent().add_child(newSmoke)
func generate_ash():
if ashItemClass == null:
var baseItem = get_parent().item
var ash = AshGenerator.generate_ash(baseItem)
get_parent().set_item(ash)