Rework of damage mechanic

This commit is contained in:
leca 2024-02-29 17:43:41 +03:00
parent 528a9bc425
commit 945b96e05b
3 changed files with 97 additions and 37 deletions

22
scenes/models/target.tscn Normal file
View File

@ -0,0 +1,22 @@
[gd_scene load_steps=4 format=3 uid="uid://ut1ssyeu88ui"]
[ext_resource type="ArrayMesh" uid="uid://cqomvoochvl6s" path="res://models/target.obj" id="1_5q4vg"]
[sub_resource type="BoxShape3D" id="BoxShape3D_dliev"]
size = Vector3(0.624695, 0.569092, 0.129181)
[sub_resource type="BoxShape3D" id="BoxShape3D_7mpxi"]
size = Vector3(0.877014, 1.24915, 0.123413)
[node name="target" type="StaticBody3D"]
[node name="Mesh" type="MeshInstance3D" parent="."]
mesh = ExtResource("1_5q4vg")
[node name="head" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00143433, 1.52753, 0.000686646)
shape = SubResource("BoxShape3D_dliev")
[node name="body" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.15527e-05, 0.621679, -0.000305176)
shape = SubResource("BoxShape3D_7mpxi")

View File

@ -225,41 +225,64 @@ func shot(client_id):
weapon_raycast.force_update_transform()
var target = weapon_raycast.get_collider()
if (not target is CharacterBody3D): return
#var target_internal_id = int(target.get_node("..").name.get_slice("player", 1))
var target_internal_id = int(target.name.get_slice("player", 1))
var target_client
for checking_client_id in clients.keys():
if (clients[checking_client_id]["internal_id"] == target_internal_id):
target_client = clients[checking_client_id]
#var target_playermodel = find_playermodel_by_internal_id(target_internal_id)
var target_client_id = int(clients.find_key(target_client))
var damage = current_weapon_settings["damage"];
var time_since_last_shot = (Time.get_ticks_msec() - client["last_shot"]) / 1000.
if (time_since_last_shot < current_weapon_settings["fireRate"] and client["last_shot"] > 0):
return
if (client["current_weapon"]["magazine"] == 0):
return
client["last_shot"] = Time.get_ticks_msec()
target_client["HP"] -= damage
if (target_client["HP"] <= 0):
#target_cb3d.teleport.rpc_id(target_client_id, Vector3(0, 10, 0))
var index = abs(client["class_type"])
var respawn = Vector3(0, 10 ,0)
if (target_client["class_type"] > 0):
respawn = spawnpoints_os.pick_random().get_class_spawnpoint(index)
elif (target_client["class_type"] < 0):
respawn = spawnpoints_cs.pick_random().get_class_spawnpoint(index)
target_client["position"] = respawn
target_client["HP"] = 100
target.teleport.rpc_id(target_client_id, target_client["position"])
target.set_hp.rpc_id(target_client_id, target_client["HP"])
if (target is CharacterBody3D):
var target_internal_id = int(target.name.get_slice("player", 1))
var target_client
for checking_client_id in clients.keys():
if (clients[checking_client_id]["internal_id"] == target_internal_id):
target_client = clients[checking_client_id]
var target_client_id = int(clients.find_key(target_client))
var shape_num = weapon_raycast.get_collider_shape()
print("shape num: " + str(shape_num))
var collision_shapes:Array
for s in target.get_children():
if s is CollisionShape3D:
collision_shapes.push_back(s)
var shape
for i in range(0, collision_shapes.size()):
if i == shape_num:
shape = collision_shapes[i]
break
#for i in range(0, target.get_children().size()):
#var checking_shape = target.get_children()[i]
#print("Checking shape: " + str(checking_shape))
#if checking_shape is CollisionShape3D and i == shape_num:
#print("Shape found: " + str(checking_shape))
#shape = checking_shape
#break
var shapes:Array = ["head", "body", "hand", "leg"]
var damage
for s in shapes:
if s in shape.name:
damage = current_weapon_settings["damage"][s]
break
var time_since_last_shot = (Time.get_ticks_msec() - client["last_shot"]) / 1000.
if (time_since_last_shot < current_weapon_settings["fireRate"] and client["last_shot"] > 0):
return
if (client["current_weapon"]["magazine"] == 0):
return
client["last_shot"] = Time.get_ticks_msec()
target_client["HP"] -= damage
if (target_client["HP"] <= 0):
var index = abs(client["class_type"])
var respawn = Vector3(0, 10 ,0)
if (target_client["class_type"] > 0):
respawn = spawnpoints_os.pick_random().get_class_spawnpoint(index)
elif (target_client["class_type"] < 0):
respawn = spawnpoints_cs.pick_random().get_class_spawnpoint(index)
target_client["position"] = respawn
target_client["HP"] = 100
target.teleport.rpc_id(target_client_id, target_client["position"])
target.set_hp.rpc_id(target_client_id, target_client["HP"])
@rpc("reliable", "call_remote", "any_peer")
func change_weapon(client_id, new_weapon_number):

View File

@ -14,7 +14,12 @@
"weapons": {
"knife": {
"number": 0,
"damage": 50,
"damage": {
"head": 70,
"body": 40,
"hand": 10,
"leg": 20
},
"reload": 3,
"magazine": -1,
"fireRate": 3,
@ -24,7 +29,12 @@
},
"pistol": {
"number": 1,
"damage": 10,
"damage": {
"head": 90,
"body": 60,
"hand": 30,
"leg": 10
},
"reload": 2,
"magazine": 10,
"fireRate": 0.5,
@ -34,7 +44,12 @@
},
"ak-47": {
"number": 2,
"damage": 5,
"damage": {
"head": 35,
"body": 20,
"hand": 10,
"leg": 15
},
"reload": 4,
"magazine": 30,
"fireRate": 0.2,