semi-idle-arpg/scripts/Quest.gd

65 lines
1.7 KiB
GDScript3
Raw Normal View History

class_name Quest
2024-10-18 09:11:15 -06:00
extends PanelContainer
@export var goalType := WorldArea.GoalType.KILL
@export var faction := WorldArea.Faction.CREATURE
@export var goalTotal := 1
@export var goalCurrent := 0
2024-10-18 09:11:15 -06:00
var questComplete := false
func _ready() -> void:
SignalBus.enemy_died.connect(_on_enemy_died)
_generate_random_quest()
_set_goal_text()
_set_goal_val()
func _process(_delta: float) -> void:
2024-10-18 09:11:15 -06:00
if questComplete:
_quest_progress_hide()
_quest_complete_show()
func _set_goal_text() -> void:
2024-10-18 14:30:41 -06:00
var goalStr = WorldArea.GoalType.keys()[self.goalType].capitalize()
var factionStr = WorldArea.Faction.keys()[self.faction].capitalize()
2024-10-18 14:30:41 -06:00
$QuestProgress/GoalTypeVal.text = goalStr + " " + factionStr + "s"
func _set_goal_val() -> void:
2024-10-18 09:11:15 -06:00
$QuestProgress/GoalVal.text = str(self.goalTotal)
func _quest_goal_check(enemyKillType: WorldArea.Faction) -> void:
if enemyKillType == self.faction:
self.goalCurrent += 1
2024-10-18 09:11:15 -06:00
$QuestProgress/CompletedVal.text = str(self.goalCurrent)
if self.goalCurrent == self.goalTotal:
SignalBus.quest_completed.emit()
2024-10-18 09:11:15 -06:00
questComplete = true
func _quest_progress_hide() -> void:
$QuestProgress.modulate.a -= 0.05
func _quest_complete_show() -> void:
$QuestComplete.modulate.a += 0.05
func _generate_random_quest() -> void:
# TODO: generate random quest
2024-10-18 14:30:41 -06:00
self.goalType = WorldArea.GoalType.KILL
self.faction = WorldArea.Faction.CREATURE
self.goalTotal = randi_range(20, 50)
# match self.goalType:
# GoalTypes.KILLMANY:
# self.faction = KillTypes.NATURAL
func _on_enemy_died(_enemyDifficulty: NPC.NPCDifficulty, enemyFaction: WorldArea.Faction):
_quest_goal_check(enemyFaction)