89 lines
1.9 KiB
GDScript
89 lines
1.9 KiB
GDScript
extends Resource
|
|
|
|
class_name Quest
|
|
|
|
## Type of quest
|
|
enum Type {
|
|
## eliminate N amount of targets
|
|
Elimination,
|
|
## reach another base without deaths
|
|
Delivery,
|
|
## Escort ship to another base
|
|
Escort,
|
|
## Finish race on 1st place
|
|
Race,
|
|
## Successfully complete minigame
|
|
Diverse
|
|
}
|
|
|
|
## Quest will fail if player breaks restrictions
|
|
enum Restriction{
|
|
## Fails if player gets destroyed
|
|
NoDeaths,
|
|
## Fails if player uses weapon
|
|
NoWeapon,
|
|
## Fails if timer reaches zero
|
|
Timer
|
|
}
|
|
|
|
## Quest status
|
|
enum Status{
|
|
## Quest is not given to player
|
|
Idle,
|
|
## Quest is given to player
|
|
Taken,
|
|
## Player can take reward for this quest
|
|
Reward
|
|
}
|
|
|
|
@export var type : Type = Type.Elimination
|
|
@export var progress_max : int = 1
|
|
var progress : int = 0:
|
|
set(value):
|
|
if value >= progress_max:
|
|
end()
|
|
@export var reward_money : float
|
|
@export var restrictions : Array[Restriction] = []
|
|
@export var data : Dictionary = {}
|
|
var status: Status = Status.Idle
|
|
|
|
## Emits when quest was given to player
|
|
signal quest_added
|
|
## Emits when quest ends succesfully
|
|
signal quest_ended
|
|
## Emits when quest fails
|
|
signal quest_failed
|
|
|
|
## Creates quest with given parameters
|
|
static func create(type : Type, progress_max : int, reward_money : float, restrictions : Array[Restriction] = [], data : Dictionary = {}) -> Quest:
|
|
var quest = Quest.new()
|
|
quest.type = type
|
|
quest.progress_max = progress_max
|
|
quest.reward_money = reward_money
|
|
quest.restrictions = restrictions
|
|
quest.data = data
|
|
quest.status = Status.Taken
|
|
quest.quest_added.emit(quest)
|
|
return quest
|
|
|
|
## Progress by quest
|
|
func do_progress() -> void:
|
|
progress += 1
|
|
|
|
## Fail quest
|
|
func fail() -> void:
|
|
quest_failed.emit(false)
|
|
status = Status.Idle
|
|
|
|
func end() -> void:
|
|
quest_ended.emit(true)
|
|
status = Status.Reward
|
|
|
|
func reward() -> float:
|
|
status = Status.Idle
|
|
return reward_money
|
|
|
|
## Trigger restriction
|
|
func trigger_restriction(restriction: Restriction) -> void:
|
|
if restrictions.has(restriction):
|
|
fail()
|