more tweaks to weapon script and revolvers

This commit is contained in:
derek
2025-03-04 15:27:37 -06:00
parent 88d9f0743a
commit e84aea9ef7
6 changed files with 40 additions and 47 deletions

View File

@@ -13,7 +13,7 @@ class_name weapon
@export var fire_smoke : GPUParticles3D
@export var smoke_timer : Timer
@export_group("Revolver")
@export var casing_array : Array[RayCast3D]
@export var casing_array : Array[MeshInstance3D]
@export var bullet_array : Array[MeshInstance3D]
@export var chamber : Node
@export_group("Melee")
@@ -67,46 +67,34 @@ func _process(_delta):
looking_mesh.look_at(tracker.global_position)
else:
weapon_info.tracker_asset.tracker_indicator_material.emission = TRACKER_NULL_COLOR
looking_mesh.rotation = lerp(rotation, Vector3(0,0,0), _delta * 4)
looking_mesh.rotation = lerp(rotation, Vector3(0,0,0), _delta * 4)
if check_track:
tracker_checker(_delta)
func reload_finished():
match weapon_info.reload_type:
0:
if GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] >= weapon_info.max_ammo:
GameGlobals.gun_ammo[weapon_info.gun_name] += weapon_info.max_ammo
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= weapon_info.max_ammo
casings_chamber_last = weapon_info.max_ammo
else:
GameGlobals.gun_ammo[weapon_info.gun_name] += GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
casings_chamber_last = GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
1:
#if max ammo in reserve fill all the way
0: #MAGAZINE
#calculate ammo to add from reserve --- discards ammo in previous mag
var ammo_added = clamp(weapon_info.max_ammo,1,GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)])
#add to gun and remove from reserve
GameGlobals.gun_ammo[weapon_info.gun_name] += ammo_added
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= ammo_added
1: #REVOLVER
#calculate ammo to add from reserve --- only pulls from what it is missing
var ammo_needed = weapon_info.max_ammo - GameGlobals.gun_ammo[weapon_info.gun_name]
if GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] >= weapon_info.max_ammo:
GameGlobals.gun_ammo[weapon_info.gun_name] += ammo_needed
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= ammo_needed
casings_chamber_last = weapon_info.max_ammo
for i in casing_array:
i.visible = true
for i in bullet_array:
i.visible = true
player.reloading = false
#if not max ammo in reserve add remaining ammo
else:
GameGlobals.gun_ammo[weapon_info.gun_name] += GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
var casings_in_chamber = GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
casings_chamber_last = GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)]
while casings_in_chamber > 0:
casing_array[casings_in_chamber].visible = true
bullet_array[casings_in_chamber].visible = true
casings_in_chamber -= 1
await get_tree().create_timer(.01).timeout
var ammo_added = clamp(ammo_needed,1,GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)])
#add to gun and remove from reserve
GameGlobals.gun_ammo[weapon_info.gun_name] += ammo_added
GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] -= ammo_added
#make the added-back casings visible
var index = 0
while index <= (ammo_added - 1):
if index < bullet_array.size():
bullet_array[index].visible = true
if index < casing_array.size():
casing_array[index].visible = true
index += 1
func shoot():
if weapon_info.weapon_type == 0:
@@ -177,8 +165,11 @@ func spawn_revolver_casings():
if casing_array.size() > 0:
var ammo_needed = weapon_info.max_ammo - GameGlobals.gun_ammo[weapon_info.gun_name]
var index = 0
while index < ammo_needed:
bullet_array[index].visible = false
while index <= ammo_needed - 1:
if index < bullet_array.size():
bullet_array[index].visible = false
if index < casing_array.size():
casing_array[index].visible = false
var instance_casing = weapon_info.casing.instantiate()
instance_casing.position = casing_array[index].global_position
instance_casing.random_rotation = false