|
|
|
|
@@ -14,9 +14,12 @@ class_name weapon
|
|
|
|
|
@export var smoke_timer : Timer
|
|
|
|
|
@export_group("Revolver")
|
|
|
|
|
@export var casing_array : Array[RayCast3D]
|
|
|
|
|
@export var bullet_array : Array[MeshInstance3D]
|
|
|
|
|
@export var chamber : Node
|
|
|
|
|
@export_group("Melee")
|
|
|
|
|
@export var melee_collision_shape : Node
|
|
|
|
|
@export_group("Tracker Gun")
|
|
|
|
|
@export var looking_mesh : Node
|
|
|
|
|
|
|
|
|
|
@onready var player = get_tree().current_scene.player
|
|
|
|
|
|
|
|
|
|
@@ -24,30 +27,31 @@ class_name weapon
|
|
|
|
|
var revolver_chamber_rot_amt = 0
|
|
|
|
|
var casings_chamber_last
|
|
|
|
|
|
|
|
|
|
# Tracker vars
|
|
|
|
|
var tracker
|
|
|
|
|
var check_track
|
|
|
|
|
const TRACKER_ASSIGNED_COLOR: Color = Color(0, 0.853, 0, 1)
|
|
|
|
|
const TRACKER_NULL_COLOR :Color = Color(0.743, 0.359, 0, 1)
|
|
|
|
|
|
|
|
|
|
var remaining_ammo
|
|
|
|
|
var start_position
|
|
|
|
|
var start_rotation
|
|
|
|
|
var cycle_count_start
|
|
|
|
|
var cycle_count
|
|
|
|
|
var rng = RandomNumberGenerator.new()
|
|
|
|
|
var gun_index
|
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready():
|
|
|
|
|
|
|
|
|
|
if weapon_info.weapon_type == 0:
|
|
|
|
|
if weapon_info.weapon_type != 1:
|
|
|
|
|
casings_chamber_last = weapon_info.max_ammo
|
|
|
|
|
|
|
|
|
|
if weapon_info.fire_mode == 0:
|
|
|
|
|
cycle_count = 1
|
|
|
|
|
cycle_count_start = 1
|
|
|
|
|
elif weapon_info.fire_mode == 1:
|
|
|
|
|
cycle_count = 1
|
|
|
|
|
cycle_count_start = 1
|
|
|
|
|
elif weapon_info.fire_mode == 2:
|
|
|
|
|
cycle_count = 3
|
|
|
|
|
cycle_count_start = 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cycle_count = cycle_count_start
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(_delta):
|
|
|
|
|
@@ -55,19 +59,56 @@ func _process(_delta):
|
|
|
|
|
var rot_amount = revolver_chamber_rot_amt * _delta * 10
|
|
|
|
|
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(rot_amount))
|
|
|
|
|
revolver_chamber_rot_amt -= rot_amount
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if weapon_info.weapon_type == 2:
|
|
|
|
|
if tracker != null:
|
|
|
|
|
weapon_info.tracker_asset.tracker_indicator_material.emission = TRACKER_ASSIGNED_COLOR
|
|
|
|
|
if looking_mesh != null:
|
|
|
|
|
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)
|
|
|
|
|
if check_track:
|
|
|
|
|
tracker_checker(_delta)
|
|
|
|
|
|
|
|
|
|
func reload_finished():
|
|
|
|
|
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)]
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
func shoot(delta):
|
|
|
|
|
func shoot():
|
|
|
|
|
if weapon_info.weapon_type == 0:
|
|
|
|
|
if GameGlobals.gun_ammo[weapon_info.gun_name] > 0 and cycle_count > 0:
|
|
|
|
|
if !anim_player.is_playing():
|
|
|
|
|
@@ -87,18 +128,33 @@ func shoot(delta):
|
|
|
|
|
player.recoil.add_recoil(Vector3(0,weapon_info.recoil_amount.y,weapon_info.recoil_amount.z),10,10)
|
|
|
|
|
player.recoil.add_gun_recoil(weapon_info.recoil_amount.x)
|
|
|
|
|
SignalBus.emit_signal("shot_fired")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif weapon_info.weapon_type == 2:
|
|
|
|
|
if !anim_player.is_playing():
|
|
|
|
|
if tracker == null and Input.is_action_just_pressed("shoot"):
|
|
|
|
|
check_track = true
|
|
|
|
|
weapon_info.tracker_check_mesh.visible = true
|
|
|
|
|
weapon_info.tracker_check_mesh.anim_player.play("check")
|
|
|
|
|
if tracker != null and !check_track:
|
|
|
|
|
anim_player.play("shoot")
|
|
|
|
|
|
|
|
|
|
func reload():
|
|
|
|
|
if weapon_info.weapon_type == 0:
|
|
|
|
|
if GameGlobals.gun_ammo[weapon_info.gun_name] < weapon_info.max_ammo and player.gun.anim_player.get_current_animation() != "reload" and GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] > 0:
|
|
|
|
|
#player.reloading = true
|
|
|
|
|
anim_player.play("reload")
|
|
|
|
|
audio_reload.play()
|
|
|
|
|
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
|
|
|
|
if GameGlobals.gun_ammo[weapon_info.gun_name] == 0:
|
|
|
|
|
GameGlobals.gun_ammo[weapon_info.gun_name] = 0
|
|
|
|
|
else:
|
|
|
|
|
GameGlobals.gun_ammo[weapon_info.gun_name] = 1
|
|
|
|
|
match weapon_info.weapon_type:
|
|
|
|
|
0:
|
|
|
|
|
match weapon_info.reload_type:
|
|
|
|
|
0:
|
|
|
|
|
if GameGlobals.gun_ammo[weapon_info.gun_name] < weapon_info.max_ammo and anim_player.get_current_animation() != "reload" and GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] > 0:
|
|
|
|
|
anim_player.play("reload")
|
|
|
|
|
audio_reload.play()
|
|
|
|
|
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
|
|
|
|
if GameGlobals.gun_ammo[weapon_info.gun_name] == 0:
|
|
|
|
|
GameGlobals.gun_ammo[weapon_info.gun_name] = 0
|
|
|
|
|
else:
|
|
|
|
|
GameGlobals.gun_ammo[weapon_info.gun_name] = 1
|
|
|
|
|
1:
|
|
|
|
|
if GameGlobals.gun_ammo[weapon_info.gun_name] < weapon_info.max_ammo and anim_player.get_current_animation() != "reload" and GameGlobals.ammo_reserve[str(weapon_info.bullet.ammo_type)] > 0:
|
|
|
|
|
anim_player.play("reload")
|
|
|
|
|
audio_reload.play()
|
|
|
|
|
|
|
|
|
|
func spawn_mag():
|
|
|
|
|
var instance_mag = weapon_info.mag.instantiate()
|
|
|
|
|
@@ -119,26 +175,53 @@ func spawn_casing():
|
|
|
|
|
|
|
|
|
|
func spawn_revolver_casings():
|
|
|
|
|
if casing_array.size() > 0:
|
|
|
|
|
for i in casing_array:
|
|
|
|
|
i.visible = false
|
|
|
|
|
if casings_chamber_last > 0:
|
|
|
|
|
var instance_casing = weapon_info.casing.instantiate()
|
|
|
|
|
instance_casing.position = i.global_position
|
|
|
|
|
instance_casing.random_rotation = false
|
|
|
|
|
instance_casing.transform.basis = i.global_transform.basis
|
|
|
|
|
instance_casing.player_velocity = player.velocity * transform.basis
|
|
|
|
|
instance_casing.rotation.x += deg_to_rad(90)
|
|
|
|
|
instance_casing.linear_velocity.y = -(8 + rng.randf_range(0,3))
|
|
|
|
|
get_tree().get_root().add_child(instance_casing)
|
|
|
|
|
casings_chamber_last -= 1
|
|
|
|
|
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
|
|
|
|
|
var instance_casing = weapon_info.casing.instantiate()
|
|
|
|
|
instance_casing.position = casing_array[index].global_position
|
|
|
|
|
instance_casing.random_rotation = false
|
|
|
|
|
instance_casing.transform.basis = casing_array[index].global_transform.basis
|
|
|
|
|
instance_casing.player_velocity = player.velocity * transform.basis
|
|
|
|
|
instance_casing.rotation.x += deg_to_rad(90)
|
|
|
|
|
instance_casing.linear_velocity.y = -(8 + randf_range(0,3))
|
|
|
|
|
get_tree().get_root().add_child(instance_casing)
|
|
|
|
|
|
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
|
|
func fire_tracker():
|
|
|
|
|
var instance_tracker = weapon_info.tracker_asset.instantiate()
|
|
|
|
|
get_tree().current_scene.add_child(instance_tracker)
|
|
|
|
|
if player.bullet_ray.is_colliding():
|
|
|
|
|
var spawn_loc = player.bullet_ray.get_collision_point()
|
|
|
|
|
var spawn_parent = player.bullet_ray.get_collider()
|
|
|
|
|
if spawn_parent != null:
|
|
|
|
|
spawn_parent.add_child(instance_tracker)
|
|
|
|
|
instance_tracker.global_transform.origin = spawn_loc
|
|
|
|
|
instance_tracker.anim_player.play("mark")
|
|
|
|
|
tracker = instance_tracker
|
|
|
|
|
|
|
|
|
|
func tracker_checker(_delta):
|
|
|
|
|
if player.bullet_ray.is_colliding():
|
|
|
|
|
var tracker_check_mesh = weapon_info.tracker_asset.instantiate()
|
|
|
|
|
var spawn_loc = player.bullet_ray.get_collision_point()
|
|
|
|
|
var distance_to_point = self.global_position.distance_to(spawn_loc)
|
|
|
|
|
var scale_adjusted = distance_to_point/5
|
|
|
|
|
tracker_check_mesh.global_transform.origin = spawn_loc
|
|
|
|
|
tracker_check_mesh.global_rotation = Vector3(0,0,0)
|
|
|
|
|
tracker_check_mesh.scale = Vector3(scale_adjusted,scale_adjusted,scale_adjusted)
|
|
|
|
|
if check_track == true and Input.is_action_just_released("shoot"):
|
|
|
|
|
fire_tracker()
|
|
|
|
|
check_track = false
|
|
|
|
|
|
|
|
|
|
func shotgun_pellet_spawn():
|
|
|
|
|
audio_fire.play()
|
|
|
|
|
var pellets_remaining = weapon_info.pellets_per_shot
|
|
|
|
|
|
|
|
|
|
while pellets_remaining > 0:
|
|
|
|
|
var lv_x = rng.randf_range(-weapon_info.shotgun_spread.x,weapon_info.shotgun_spread.x)
|
|
|
|
|
var lv_y = rng.randf_range(-weapon_info.shotgun_spread.y,weapon_info.shotgun_spread.y)
|
|
|
|
|
var lv_x = randf_range(-weapon_info.shotgun_spread.x,weapon_info.shotgun_spread.x)
|
|
|
|
|
var lv_y = randf_range(-weapon_info.shotgun_spread.y,weapon_info.shotgun_spread.y)
|
|
|
|
|
# instance bullet
|
|
|
|
|
var instance_bullet = projectile_initialize()
|
|
|
|
|
instance_bullet.linear_velocity += instance_bullet.transform.basis * Vector3(lv_x, lv_y, -weapon_info.bullet_speed) + player.velocity
|
|
|
|
|
|