Rewritten quest base
This commit is contained in:
parent
1ea6c2d296
commit
37cd28d611
4 changed files with 84 additions and 26 deletions
12
scripts/Base/Menu/quest.gd
Normal file
12
scripts/Base/Menu/quest.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
extends Node
|
||||
|
||||
var base: Base
|
||||
|
||||
var quest: Quest
|
||||
|
||||
func _ready():
|
||||
get_tree().create_timer(0.05).timeout.connect(fetch_quest)
|
||||
|
||||
func fetch_quest():
|
||||
base = get_parent().base
|
||||
quest = base.quest
|
||||
|
|
@ -25,6 +25,9 @@ signal dock_requested
|
|||
## List of items that this base buys
|
||||
@export var items_on_buy: Array[Item]
|
||||
|
||||
## Quest that is given on this base
|
||||
@export var quest: Quest
|
||||
|
||||
## List of prices for items that this base sells
|
||||
var sell_prices: Array[float]
|
||||
## List of prices for items that this base buys
|
||||
|
|
|
|||
|
|
@ -1,41 +1,80 @@
|
|||
extends Resource
|
||||
|
||||
class_name Quest
|
||||
|
||||
enum TYPE {ELIMINATION, DELIVERY, ESCORT, RACE, DIVERSE}
|
||||
enum RESTRICTIONS{NO_DEATHS,NO_WEAPON,TIMER}
|
||||
## 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
|
||||
}
|
||||
|
||||
var type : Quest.TYPE = Quest.TYPE.ELIMINATION
|
||||
var progress_max : int = 1
|
||||
var progress : int = 0
|
||||
var reward_money : float
|
||||
var restrictions : Array[RESTRICTIONS] = []
|
||||
var data : Dictionary = {}
|
||||
var new : bool = true
|
||||
## 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:
|
||||
quest_ended.emit(true)
|
||||
@export var reward_money : float
|
||||
@export var restrictions : Array[Restriction] = []
|
||||
@export var data : Dictionary = {}
|
||||
@export var status: Status
|
||||
|
||||
## 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
|
||||
|
||||
func create(type : TYPE, progress_max : int, reward_money : float, restrictions : Array[RESTRICTIONS] = [], data : Dictionary = {}) -> void:
|
||||
self.type = type
|
||||
self.progress_max = progress_max
|
||||
self.reward_money = reward_money
|
||||
self.restrictions = restrictions
|
||||
self.data = data
|
||||
quest_added.emit(self)
|
||||
self.new = false
|
||||
## Creates quest with given parameters
|
||||
static func create(type : Type, progress_max : int, reward_money : float, restrictions : Array[Restriction] = [], data : Dictionary = {}) -> void:
|
||||
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)
|
||||
|
||||
## Progress by quest
|
||||
func do_progress() -> void:
|
||||
progress += 1
|
||||
if progress >= progress_max:
|
||||
quest_ended.emit(true)
|
||||
|
||||
## Fail quest
|
||||
func fail() -> void:
|
||||
quest_failed.emit(false)
|
||||
status = Status.Idle
|
||||
|
||||
func _restriction_no_deaths() -> void:
|
||||
if restrictions.has(RESTRICTIONS.NO_DEATHS):
|
||||
fail()
|
||||
|
||||
func _restriction_no_weapon() -> void:
|
||||
if restrictions.has(RESTRICTIONS.NO_WEAPON):
|
||||
## Trigger restriction
|
||||
func trigger_restriction(restriction: Restriction) -> void:
|
||||
if restrictions.has(restriction):
|
||||
fail()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue