Quest generating + quest adding interface + some bugfixes

This commit is contained in:
gotfishmakesticks 2023-11-16 16:46:31 +03:00
commit f4cf1ef4e9
7 changed files with 71 additions and 20 deletions

View file

@ -10,7 +10,14 @@ var want_to_buy : Array[Item] = []
var sell_prices : Array[float] = []
var buy_prices : Array[float] = []
var quest : Quest = Quest.new()
const available_quests : Array[Quest.TYPE]= [Quest.TYPE.ELIMINATION]
const restrictions_foreach_type : Dictionary = {
Quest.TYPE.ELIMINATION : [Quest.RESTRICTIONS.NO_DEATHS, Quest.RESTRICTIONS.TIMER]
}
func _ready():
randomize()
ship.minimap.add_marker(self, "base")
match type:
Game.BASE_TYPE.POWER:
@ -38,6 +45,7 @@ func _ready():
want_to_buy.append(Game.get_item("Energy Cell"))
want_to_buy.append(Game.get_item("Raw Materials"))
update_prices()
generate_quest()
func update_prices():
sell_prices = []
@ -55,3 +63,28 @@ func update_prices():
else:
price = randi_range(item.min_price * 100, (item.max_price + item.min_price) / 2 * 100) / 100.0
buy_prices.append(price)
func generate_quest():
var difficulty : float = randi_range(100, 300) / 100.0
var reward_multi : float = randi_range(100, max(difficulty/1.5 * 100, 100)) / 100.0
var quest_type : Quest.TYPE = available_quests.pick_random()
var progress_max : int
var reward_money : int
var restrictions : Array[Quest.RESTRICTIONS] = []
var data : Dictionary = {}
for restriction in restrictions_foreach_type[quest_type]:
var hit = randi_range(0, 1)
if hit:
restrictions.append(restriction)
match quest_type:
Quest.TYPE.ELIMINATION:
progress_max = difficulty * 2
reward_money = 50 * progress_max * reward_multi
if restrictions.has(Quest.RESTRICTIONS.NO_DEATHS):
reward_money *= 1.5
if restrictions.has(Quest.RESTRICTIONS.NO_WEAPON):
reward_money *= 1.5
if restrictions.has(Quest.RESTRICTIONS.TIMER):
reward_money *= 1.5
data['timer'] = int(difficulty * 30)
quest.create(quest_type, progress_max, reward_money, restrictions, data)

View file

@ -27,7 +27,7 @@ func _ready():
secondary_slot.add_child(Game.get_weapon("SingleRocketMk1").instantiate())
quest.create(Quest.TYPE.ELIMINATION, 2, 200)
#quest.create(Quest.TYPE.ELIMINATION, 2, 200)
func _process(_delta):
if hull.hp < 0: destroy()

View file

@ -37,8 +37,10 @@ func _physics_process(_delta):
runawaystate()
var format = {"HP" : "%0.2f" % hull.hp, "SC" : "%0.2f" % shield.capacity}
healthbar.text = "{HP} HS + {SC} SC".format(format)
if Vector2.ZERO.distance_to(global_position) > 5800 or hull.hp <= 0:
if hull.hp <= 0:
destroy()
if Vector2.ZERO.distance_to(global_position) > 5800:
destroy(true)
func switchdestination():
engine.destination_angle = randi_range(0, 360)
@ -71,7 +73,7 @@ func runawaystate():
if global_position.distance_to(ship.global_position) > 1024 or !ship.allow_shooting:
state = "idle"
func destroy():
func destroy(silent : bool = false):
hull.hp = hull.max_hp
hull.fuel = hull.max_fuel
shield.capacity = shield.max_capacity
@ -82,4 +84,5 @@ func destroy():
bounty_inst.amount = randi_range(bounty_min, bounty_max)
bounty_inst.text.text = str(bounty_inst.amount) + " MU"
global_position = Vector2(randi_range(-4096, 4096), randi_range(-4096, 4096))
destroyed.emit(self)
if !silent:
destroyed.emit(self)