added functionality for various game modes

This commit is contained in:
Derek
2025-02-21 23:19:25 -06:00
parent 9cb57824b1
commit 777063ddeb
19 changed files with 809 additions and 183 deletions

View File

@@ -1,18 +1,13 @@
extends Node3D
@export var load_save : = true
@export var gamemode : gamemode
@export var player : Node
@export var money = 250
@export var start_health = 3
@export var MAX_PARTICLES = 100
@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")
@@ -23,7 +18,8 @@ const DEAD_ANNOUNCE = preload("res://assets/dead_announce.tscn")
var level_name
var paused = false
var health = start_health
var health
var money
var pickups = []
var held_guns = []
var ammo_current = [0]
@@ -48,10 +44,14 @@ func _ready():
#connect to signals
SignalBus.enemy_count_changed.connect(enemy_count)
health = gamemode.start_health
money = gamemode.money
#LOAD DATA
SaveLoad.load_persistent_data()
if SaveLoad.data_cleared or !load_save:
if SaveLoad.data_cleared or !gamemode.load_save:
refresh_scene()
GameGlobals.game_loaded = true
SignalBus.emit_signal("game_loaded")
@@ -83,25 +83,25 @@ func _ready():
enemy_count()
func refresh_scene():
health = start_health
health = gamemode.start_health
respawn_position = player.camera.global_position
respawn_cam_rotation = player.global_transform.basis
if player:
#Set up starting guns and ammo
if gun_1 != null:
held_guns = [gun_1]
if gamemode.gun_1 != null:
held_guns = [gamemode.gun_1]
var instance_gun = held_guns[0].instantiate()
player.add_ammo(true,instance_gun.gun_name,instance_gun.ammo_type,instance_gun.max_ammo,instance_gun.start_mags)
if gun_2 != null:
held_guns.append(gun_2)
if gamemode.gun_2 != null:
held_guns.append(gamemode.gun_2)
var instance_gun_2 = held_guns[1].instantiate()
player.add_ammo(true,instance_gun_2.gun_name,instance_gun_2.ammo_type,instance_gun_2.max_ammo,instance_gun_2.start_mags)
# Spawn first gun
if gun_1 != null:
if gamemode.gun_1 != null:
current_gun_index = 0
gun_spawn(0)
@@ -189,31 +189,47 @@ func pickup_spawn(randomized):
#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 health_weight
if gamemode.health_drop_enabled:
health_weight = (1.0 - (health / gamemode.start_health)) + drop_chance_minimum
else:
health_weight = 0
var stamina_weight
if stamina_drop_enabled:
stamina_weight = (1.0 - (player.remaining_stamina / gamemode.max_stamina)) + drop_chance_minimum
else:
stamina_weight = 0
var money_weight
if money_drop_enabled:
money_weight = (1.0 - clamp(float(money) / float(500),0,1)) + drop_chance_minimum #fix this logic later once the economy makes sense
else:
money_weight = 0
var ammo_weight
if ammo_drop_enabled:
ammo_weight = drop_chance_minimum
else: ammo_weight = 0
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)
5:
i_weight = 0
if i_weight > ammo_weight:
ammo_weight = i_weight
ammo_type_weight[i] = i_weight + drop_chance_minimum
if ammo_drop_enabled:
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)
5:
i_weight = 0
if i_weight > ammo_weight:
ammo_weight = i_weight
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})
@@ -225,9 +241,9 @@ func pickup_spawn(randomized):
ammo_type = randi_range(0,4)
value = randi_range(1,20)
"1":
value = randi_range(int(player.MAX_STAMINA * .25),player.MAX_STAMINA)
value = randi_range(int(gamemode.max_stamina * .25),gamemode.max_stamina)
"2":
value = randi_range(int(start_health * .25),start_health)
value = randi_range(int(gamemode.start_health * .25),gamemode.start_health)
"3":
var bill_denoms = [5,10,20,50,100]
value = bill_denoms.pick_random()