add modding support

This commit is contained in:
2022-12-31 03:48:00 +01:00
parent d2ed1afdc7
commit 56255f5473
25 changed files with 82 additions and 1782 deletions

View File

@@ -1,5 +1,10 @@
extends Node
class_name Hitable
func Hit():
print("Got hit")
var health = 200
func Hit(dmg):
#var tween = create_tween()
health -= dmg
if(health <= 0):
queue_free()

View File

@@ -8,6 +8,7 @@ const RELOAD = 3
const DRAW_TIME = 0.35
var MELEE : bool
var MAX_CLIP : int
var DAMAGE : float
var MOMENTUM : Vector2
@@ -55,9 +56,11 @@ func InitialPos():
func Shoot():
if CanShoot():
if !FIREMODE:
if not FIREMODE:
can_shoot = false
clip -= 1
if not MELEE:
clip -= 1
state = SHOOT;
var tween = create_tween()
tween.set_trans(Tween.TRANS_ELASTIC)

View File

@@ -3,99 +3,65 @@ extends Node3D
const CONFIG_PATH = "user://weapons.scoom"
const REVOLVER = 0
const UZI = 1
const REST = 0
const BOB = 1
const CHAINSAW = 2
var state = 0
@onready var player_root = get_node("../../../../PlayerQ3") as CharacterBody3D
@onready var raycast = get_node("../Camera3D/AimCast") as RayCast3D
#@onready var crosshair = $Crosshair
@onready var MainCam = get_node("../Camera3D")
@onready var GunCam = get_node("../Camera3D/SubViewportContainer/SubViewport/GunCam")
var weapons = []
var current_weapon = 0
var file_data = {
REVOLVER:
{
"HAND_POS": Vector3(0.4,-0.45,-1),
"HAND_ROT": Vector3(0,PI,0),
"MODEL": "Revolver",
"MAX_CLIP": 5,
"DAMAGE": 25,
"MOMENTUM": Vector2(0.3, -0.25),
"ANGULAR_MOMENTUM": Vector3(-60, 7, 10),
"RECOIL_COOLDOWN": 0.35,
"RPM": 120,
"DRAW_POS": Vector3(0,-0.5,-0.3),
"DRAW_ROT": Vector3(1.3, 0, 0),
"RELOAD_MOMENTUM": Vector3(-5, -9, 7),
"RELOAD_ANGULAR_MOMENTUM": Vector3(deg_to_rad(600), deg_to_rad(-800), deg_to_rad(-1000)),
"RELOAD_TIME": 0.35,
"FIREMODE": 0,
"HITSCAN": true
},
UZI:
{
"HAND_POS": Vector3(0.4,-0.45,-1),
"HAND_ROT": Vector3(0,PI,0),
"MODEL": "Uzi",
"MAX_CLIP": 30,
"DAMAGE": 25,
"MOMENTUM": Vector2(0.05, -0.15),
"ANGULAR_MOMENTUM": Vector3(-4, 1, 2),
"RECOIL_COOLDOWN": 0.35,
"RPM": 600,
"DRAW_POS": Vector3(0,-0.5,-0.3),
"DRAW_ROT": Vector3(1.3, 0, 0),
"RELOAD_MOMENTUM": Vector3(-7, -9, 7),
"RELOAD_ANGULAR_MOMENTUM": Vector3(deg_to_rad(600), deg_to_rad(-800), deg_to_rad(-1000)),
"RELOAD_TIME": 0.35,
"FIREMODE": 1,
"HITSCAN": true
}
}
var mouse_mov : Vector3
var sway_lerp = 5
func _ready():
save_data(file_data)
load_data()
var config = load_data() as ConfigFile
for i in range(0, file_data.size()):
for weapon in config.get_sections():
var root = Weapon.new()
root.name = str(i)
var resource = "res://scenes/weapons/" + file_data[i].MODEL + ".tscn"
var weapon_model_resource = load(resource)
var weapon_model = weapon_model_resource.instantiate()
root.name = weapon
var weapon_model = Runtimeloader.load_gltf(config.get_value(weapon, "MODEL")) as Node3D
var old_parent = weapon_model.get_parent()
old_parent.remove_child(weapon_model)
var mesh = weapon_model.get_child(0) as MeshInstance3D
var mat = mesh.material_override as Material
//TODO
#Set Weapon nodes
root.add_child(weapon_model)
root.position = file_data[i].HAND_POS
root.rotation = file_data[i].HAND_ROT
root.position = config.get_value(weapon, "HAND_POS")
root.rotation = config.get_value(weapon, "HAND_ROT")
root.hide()
add_child(root)
#Set Weapon Data
root.MAX_CLIP = file_data[i].MAX_CLIP
root.MELEE = config.get_value(weapon, "MELEE")
root.MAX_CLIP = config.get_value(weapon, "MAX_CLIP")
root.clip = root.MAX_CLIP
root.DAMAGE = file_data[i].DAMAGE
root.MOMENTUM = file_data[i].MOMENTUM
root.ANGULAR_MOMENTUM = file_data[i].ANGULAR_MOMENTUM
root.RECOIL_COOLDOWN = file_data[i].RECOIL_COOLDOWN
root.RELOAD_MOMENTUM = file_data[i].RELOAD_MOMENTUM
root.RELOAD_ANGULAR_MOMENTUM = file_data[i].RELOAD_ANGULAR_MOMENTUM
root.RELOAD_TIME = file_data[i].RELOAD_TIME
root.RPM = file_data[i].RPM
root.MODEL = root.get_node(file_data[i].MODEL)
root.DRAW_POS = file_data[i].DRAW_POS
root.DRAW_ROT = file_data[i].DRAW_ROT
root.HITSCAN = file_data[i].HITSCAN
root.FIREMODE = file_data[i].FIREMODE
root.DAMAGE = config.get_value(weapon, "DAMAGE")
root.RPM = config.get_value(weapon, "RPM")
root.FIREMODE = config.get_value(weapon, "FIREMODE")
root.HITSCAN = config.get_value(weapon, "HITSCAN")
if(not root.HITSCAN):
print("Projectile stats")
else:
root.RAY_LEN = config.get_value(weapon, "RAY_LEN")
#Set Anim Data
root.MODEL = weapon_model
root.DRAW_POS = config.get_value(weapon, "DRAW_POS")
root.DRAW_ROT = config.get_value(weapon, "DRAW_ROT")
root.MOMENTUM = config.get_value(weapon, "MOMENTUM")
root.ANGULAR_MOMENTUM = config.get_value(weapon, "ANGULAR_MOMENTUM")
root.RECOIL_COOLDOWN = config.get_value(weapon, "RECOIL_COOLDOWN")
root.RELOAD_MOMENTUM = config.get_value(weapon, "RELOAD_MOMENTUM")
root.RELOAD_ANGULAR_MOMENTUM = config.get_value(weapon, "RELOAD_ANGULAR_MOMENTUM")
root.RELOAD_TIME = config.get_value(weapon, "RELOAD_TIME")
weapons.append(root)
weapons[current_weapon].init()
@@ -108,11 +74,13 @@ func _input(event):
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
func _unhandled_input(_event):
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
ChangeWeapon((current_weapon + 1) % weapons.size())
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
ChangeWeapon((current_weapon - 1) % weapons.size())
if Input.is_action_just_pressed("reload"):
weapons[current_weapon].Reload()
@@ -125,6 +93,7 @@ func ChangeWeapon(i):
var time = 0
func _process(delta):
GunCam.global_transform = MainCam.global_transform
if Input.is_action_pressed("shoot") && weapons[current_weapon].Shoot():
if(weapons[current_weapon].HITSCAN):
HitScan()
@@ -157,18 +126,24 @@ func HitScan():
print_debug("Hit target ", target.name, " with ", weapons[current_weapon].MODEL.name, " ",current_weapon, ". Dealt damage ", weapons[current_weapon].DAMAGE)
if(raycast.get_collision_mask_value(10)):
if(target is Hitable):
target.Hit()
target.Hit(weapons[current_weapon].DAMAGE)
func Projectile():
pass
func save_data(data):
var file = FileAccess.open(CONFIG_PATH, FileAccess.WRITE)
file.store_var(data)
func load_data():
var file = FileAccess.open(CONFIG_PATH, FileAccess.READ)
var data = file.get_var()
file_data = data
var path = ""
if(OS.has_feature("editor")):
path = "/home/kookroach/Documents/Projects/Scoom_test/"
else:
path = OS.get_executable_path() + "/"
var config = ConfigFile.new()
var err = config.load(path+"weapons.cfg")
if err != OK:
printerr("FAILED LOADING WEAPONS DATA")
return config