added weighted random item drops based on player needs
This commit is contained in:
@@ -8,17 +8,15 @@ extends Node3D
|
||||
@export var gun_1 : Resource
|
||||
@export var gun_2 : Resource
|
||||
@export_group("Drops")
|
||||
@export var drop_chance_minimum = .1
|
||||
@export var ammo_drop_enabled = true
|
||||
@export var expected_ammo = {"light" : 200, "medium" : 50, "heavy" : 25,"shotgun" : 20, "rocket" : 3} #light, medium,heavy,shotgun,rocket
|
||||
@export var stamina_drop_enabled = true
|
||||
@export var health_drop_enabled = true
|
||||
@export var money_drop_enabled = true
|
||||
|
||||
@onready var item_pickup = preload("res://assets/item_pickup.tscn")
|
||||
@onready var crown = preload("res://assets/crown.tscn")
|
||||
var ammo_drop = [[load("res://assets/ammo_pickup.tscn")],["ammo"]]
|
||||
var stamina_drop = [[load("res://assets/stamina_pickup.tscn")],["stamina"]]
|
||||
var health_drop = [[load("res://assets/health_pickup.tscn")],["health"]]
|
||||
var money_drop = [[load("res://assets/money_pickup.tscn")],["money"]]
|
||||
var dead_player = preload("res://assets/dead_cam.tscn")
|
||||
const CLEARED_ANNOUNCE = preload("res://assets/cleared_announce.tscn")
|
||||
const DEAD_ANNOUNCE = preload("res://assets/dead_announce.tscn")
|
||||
@@ -73,15 +71,6 @@ func _ready():
|
||||
#global randomize function
|
||||
randomize()
|
||||
|
||||
#assign pickups to array
|
||||
if ammo_drop_enabled == true:
|
||||
pickups.append(ammo_drop)
|
||||
if stamina_drop_enabled == true:
|
||||
pickups.append(stamina_drop)
|
||||
if health_drop_enabled == true:
|
||||
pickups.append(health_drop)
|
||||
if money_drop_enabled == true:
|
||||
pickups.append(money_drop)
|
||||
|
||||
#clear spawned in objects
|
||||
for node in get_tree().get_nodes_in_group("spawned"):
|
||||
@@ -186,17 +175,60 @@ func die():
|
||||
player.health_indicator.color = Color(0.471, 0, 0, 0)
|
||||
|
||||
|
||||
func pickup_spawn():
|
||||
##SET VARIABLES
|
||||
var type = randi_range(0,3)
|
||||
func pickup_spawn(randomized):
|
||||
var pickup_type
|
||||
var ammo_type
|
||||
var value
|
||||
if randomized:
|
||||
#random item
|
||||
pickup_type = randi_range(0,3)
|
||||
#if item type is ammo, pick random ammo
|
||||
if pickup_type == 0:
|
||||
var player_ammo = player.ammo_reserve.keys()
|
||||
ammo_type = int(player_ammo.pick_random())
|
||||
#random value of pickup
|
||||
value = randi_range(1,50)
|
||||
else:
|
||||
var health_weight = (1.0 - (health / start_health)) + drop_chance_minimum
|
||||
var stamina_weight = (1.0 - (player.remaining_stamina / player.MAX_STAMINA)) + drop_chance_minimum
|
||||
var money_weight = (1.0 - clamp(float(money) / float(500),0,1)) + drop_chance_minimum #fix this logic later once the economy makes sense
|
||||
var ammo_weight = drop_chance_minimum
|
||||
var ammo_type_weight = {}
|
||||
|
||||
# weight ammo player owns against expected ammo values
|
||||
for i in player.ammo_reserve.keys():
|
||||
var i_weight
|
||||
match int(i):
|
||||
0:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["light"]),0,1)
|
||||
1:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["medium"]),0,1)
|
||||
2:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["heavy"]),0,1)
|
||||
3:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["shotgun"]),0,1)
|
||||
4:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["rocket"]),0,1)
|
||||
if i_weight > ammo_weight:
|
||||
ammo_weight = i_weight + drop_chance_minimum
|
||||
ammo_type_weight[i] = i_weight + drop_chance_minimum
|
||||
|
||||
pickup_type = HelperFuncs.weighted_random({"0" : ammo_weight, "1" : stamina_weight,"2" : health_weight,"3" : money_weight})
|
||||
|
||||
match pickup_type:
|
||||
"0":
|
||||
ammo_type = int(HelperFuncs.weighted_random(ammo_type_weight))
|
||||
value = randi_range(1,20)
|
||||
"1":
|
||||
value = randi_range(int(player.MAX_STAMINA * .25),player.MAX_STAMINA)
|
||||
"2":
|
||||
value = randi_range(int(start_health * .25),start_health)
|
||||
"3":
|
||||
var bill_denoms = [5,10,20,50,100]
|
||||
value = bill_denoms.pick_random()
|
||||
|
||||
|
||||
if type == 0:
|
||||
ammo_type = randi_range(0,4)
|
||||
value = randi_range(1,10)
|
||||
|
||||
return {"pickup_type" : type,"ammo_type" : ammo_type,"value" : value}
|
||||
return {"pickup_type" : pickup_type,"ammo_type" : ammo_type,"value" : value}
|
||||
|
||||
func save_quit():
|
||||
SaveLoad.save_game_data(level_name)
|
||||
|
||||
Reference in New Issue
Block a user