Very bad implementation of shop and grenade
This commit is contained in:
parent
e9f4c6e5f8
commit
3868af29e3
13 changed files with 166 additions and 3 deletions
|
|
@ -5,3 +5,11 @@ extends Button
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
icon = weapon.preview
|
icon = weapon.preview
|
||||||
text = str(weapon.cost)
|
text = str(weapon.cost)
|
||||||
|
|
||||||
|
func _pressed() -> void:
|
||||||
|
var player_data = Session.get_player_data()
|
||||||
|
if player_data["money"] >= weapon.cost:
|
||||||
|
var player: Player = Session.player_nodes[multiplayer.get_unique_id()]
|
||||||
|
|
||||||
|
player_data["money"] -= weapon.cost
|
||||||
|
player.get_node("WeaponSystem").add(weapon.weapon_system_scene.instantiate(),"ability_first")
|
||||||
|
|
|
||||||
30
scenes/weapons/molik.tscn
Normal file
30
scenes/weapons/molik.tscn
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
[gd_scene load_steps=5 format=3 uid="uid://b6qahd6q60js7"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://y1s64ppporww" path="res://scripts/weapon_system/molikman/molik/molik.gd" id="1_aqokr"]
|
||||||
|
|
||||||
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_aqokr"]
|
||||||
|
bounce = 0.53
|
||||||
|
|
||||||
|
[sub_resource type="SphereMesh" id="SphereMesh_fwcyt"]
|
||||||
|
radius = 0.05
|
||||||
|
height = 0.1
|
||||||
|
|
||||||
|
[sub_resource type="SphereShape3D" id="SphereShape3D_aqokr"]
|
||||||
|
radius = 0.05
|
||||||
|
|
||||||
|
[node name="Molik" type="RigidBody3D"]
|
||||||
|
collision_layer = 8
|
||||||
|
physics_material_override = SubResource("PhysicsMaterial_aqokr")
|
||||||
|
gravity_scale = 0.25
|
||||||
|
continuous_cd = true
|
||||||
|
contact_monitor = true
|
||||||
|
max_contacts_reported = 2
|
||||||
|
script = ExtResource("1_aqokr")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
mesh = SubResource("SphereMesh_fwcyt")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
|
shape = SubResource("SphereShape3D_aqokr")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
24
scenes/weapons/molikman_molik.tscn
Normal file
24
scenes/weapons/molikman_molik.tscn
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
[gd_scene load_steps=5 format=3 uid="uid://c5q7e5dj86187"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://e6lqknfl4ngt" path="res://scripts/weapon_system/weapon_substate_machine.gd" id="1_e53aq"]
|
||||||
|
[ext_resource type="Script" uid="uid://js2rkse5mka0" path="res://scripts/weapon_system/molikman/molik/intro_state.gd" id="2_8q75j"]
|
||||||
|
[ext_resource type="Script" uid="uid://cnre3f01a2n88" path="res://scripts/weapon_system/molikman/molik/idle_state.gd" id="3_p1i4u"]
|
||||||
|
[ext_resource type="Script" uid="uid://b6eio68csxw7v" path="res://scripts/weapon_system/molikman/molik/throw.gd" id="4_1la3w"]
|
||||||
|
|
||||||
|
[node name="MolikmanMolik" type="Node" node_paths=PackedStringArray("enter_state")]
|
||||||
|
script = ExtResource("1_e53aq")
|
||||||
|
animation_prefix = &"baked_sp_"
|
||||||
|
visibility_target = &"sp"
|
||||||
|
max_ammo = 3
|
||||||
|
ammo_mags = 0
|
||||||
|
enter_state = NodePath("Intro")
|
||||||
|
metadata/_custom_type_script = "uid://e6lqknfl4ngt"
|
||||||
|
|
||||||
|
[node name="Intro" type="Node" parent="."]
|
||||||
|
script = ExtResource("2_8q75j")
|
||||||
|
|
||||||
|
[node name="Idle" type="Node" parent="."]
|
||||||
|
script = ExtResource("3_p1i4u")
|
||||||
|
|
||||||
|
[node name="Throw" type="Node" parent="."]
|
||||||
|
script = ExtResource("4_1la3w")
|
||||||
|
|
@ -91,11 +91,11 @@ func sync_session_server(id: int):
|
||||||
data.encode_u8(4,defenders_alive)
|
data.encode_u8(4,defenders_alive)
|
||||||
data.encode_u8(5,round_state)
|
data.encode_u8(5,round_state)
|
||||||
|
|
||||||
sync_session_client.rpc_id(id,data)
|
sync_session_client.rpc_id(id,data,player_data)
|
||||||
late_player_connected.emit(id)
|
late_player_connected.emit(id)
|
||||||
|
|
||||||
@rpc("authority","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func sync_session_client(data: PackedByteArray):
|
func sync_session_client(data: PackedByteArray,players_data_sent: Dictionary[int,Dictionary]):
|
||||||
if not is_server_request():
|
if not is_server_request():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -106,7 +106,36 @@ func sync_session_client(data: PackedByteArray):
|
||||||
defenders_alive = data.decode_u8(4)
|
defenders_alive = data.decode_u8(4)
|
||||||
round_state = data.decode_u8(5) as ROUND_STATES
|
round_state = data.decode_u8(5) as ROUND_STATES
|
||||||
session_started.emit()
|
session_started.emit()
|
||||||
|
player_data = players_data_sent
|
||||||
|
|
||||||
|
func send_session_data():
|
||||||
|
if multiplayer.is_server() == false or session_started_flag == false:
|
||||||
|
return
|
||||||
|
|
||||||
|
var data: PackedByteArray
|
||||||
|
data.resize(6)
|
||||||
|
data.encode_u8(0,current_round)
|
||||||
|
data.encode_u8(1,attacker_score)
|
||||||
|
data.encode_u8(2,defender_score)
|
||||||
|
data.encode_u8(3,attackers_alive)
|
||||||
|
data.encode_u8(4,defenders_alive)
|
||||||
|
data.encode_u8(5,round_state)
|
||||||
|
|
||||||
|
recieve_session_data.rpc(data,player_data)
|
||||||
|
|
||||||
|
@rpc("authority","call_remote","unreliable")
|
||||||
|
func recieve_session_data(data: PackedByteArray,players_data_sent: Dictionary[int,Dictionary]):
|
||||||
|
if not is_server_request():
|
||||||
|
return
|
||||||
|
|
||||||
|
current_round = data.decode_u8(0)
|
||||||
|
attacker_score = data.decode_u8(1)
|
||||||
|
defender_score = data.decode_u8(2)
|
||||||
|
attackers_alive = data.decode_u8(3)
|
||||||
|
defenders_alive = data.decode_u8(4)
|
||||||
|
round_state = data.decode_u8(5) as ROUND_STATES
|
||||||
|
session_started.emit()
|
||||||
|
player_data = players_data_sent
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
if multiplayer.is_server() == false or not session_started:
|
if multiplayer.is_server() == false or not session_started:
|
||||||
|
|
@ -121,6 +150,7 @@ func _process(_delta: float) -> void:
|
||||||
_:
|
_:
|
||||||
reference_round_time = 0
|
reference_round_time = 0
|
||||||
update_clock.rpc(reference_round_time)
|
update_clock.rpc(reference_round_time)
|
||||||
|
send_session_data()
|
||||||
|
|
||||||
@rpc("authority","call_remote","unreliable")
|
@rpc("authority","call_remote","unreliable")
|
||||||
func update_clock(time: float):
|
func update_clock(time: float):
|
||||||
|
|
|
||||||
11
scripts/weapon_system/molikman/molik/idle_state.gd
Normal file
11
scripts/weapon_system/molikman/molik/idle_state.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
extends WeaponState
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
machine.animation_player.play(machine.animation_prefix +"idle")
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func use_begin() -> void:
|
||||||
|
if machine.ammo > 0:
|
||||||
|
transition.emit("Throw")
|
||||||
1
scripts/weapon_system/molikman/molik/idle_state.gd.uid
Normal file
1
scripts/weapon_system/molikman/molik/idle_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cnre3f01a2n88
|
||||||
14
scripts/weapon_system/molikman/molik/intro_state.gd
Normal file
14
scripts/weapon_system/molikman/molik/intro_state.gd
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
extends WeaponState
|
||||||
|
|
||||||
|
@export var emptyable: bool
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
machine.animation_player.play(machine.animation_prefix + "intro")
|
||||||
|
machine.animation_player.animation_finished.connect(on_animation_finished)
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
machine.animation_player.animation_finished.disconnect(on_animation_finished)
|
||||||
|
|
||||||
|
func on_animation_finished(animation):
|
||||||
|
if animation == machine.animation_prefix + "intro":
|
||||||
|
transition.emit("Idle")
|
||||||
1
scripts/weapon_system/molikman/molik/intro_state.gd.uid
Normal file
1
scripts/weapon_system/molikman/molik/intro_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://js2rkse5mka0
|
||||||
12
scripts/weapon_system/molikman/molik/molik.gd
Normal file
12
scripts/weapon_system/molikman/molik/molik.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
extends RigidBody3D
|
||||||
|
|
||||||
|
|
||||||
|
var contacts: int = 0
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node) -> void:
|
||||||
|
contacts += 1
|
||||||
|
if contacts > 2:
|
||||||
|
var grenade = load("res://scenes/projectiles/molikman/molikman_molotov_fire.tscn").instantiate()
|
||||||
|
Session.dynamic_objects_spawner.get_parent().add_child(grenade)
|
||||||
|
grenade.global_position = global_position
|
||||||
|
queue_free()
|
||||||
1
scripts/weapon_system/molikman/molik/molik.gd.uid
Normal file
1
scripts/weapon_system/molikman/molik/molik.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://y1s64ppporww
|
||||||
28
scripts/weapon_system/molikman/molik/throw.gd
Normal file
28
scripts/weapon_system/molikman/molik/throw.gd
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
extends WeaponState
|
||||||
|
|
||||||
|
const molik: PackedScene = preload("res://scenes/weapons/molik.tscn")
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
fire()
|
||||||
|
machine.animation_player.animation_finished.connect(on_animation_finished)
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
machine.animation_player.animation_finished.disconnect(on_animation_finished)
|
||||||
|
|
||||||
|
func on_animation_finished(animation):
|
||||||
|
if animation == machine.animation_prefix + "throw":
|
||||||
|
transition.emit("Idle")
|
||||||
|
|
||||||
|
func fire() -> void:
|
||||||
|
if machine.ammo == 0:
|
||||||
|
return
|
||||||
|
machine.ammo -= 1
|
||||||
|
|
||||||
|
machine.animation_player.stop()
|
||||||
|
machine.animation_player.play(machine.animation_prefix + "shoot")
|
||||||
|
|
||||||
|
if is_multiplayer_authority():
|
||||||
|
var molotov: RigidBody3D = molik.instantiate()
|
||||||
|
Session.dynamic_objects_spawner.get_parent().add_child(molotov)
|
||||||
|
molotov.global_transform = machine.player_camera.global_transform
|
||||||
|
molotov.apply_impulse(-molotov.global_basis.z * 10)
|
||||||
1
scripts/weapon_system/molikman/molik/throw.gd.uid
Normal file
1
scripts/weapon_system/molikman/molik/throw.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://b6eio68csxw7v
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
[gd_resource type="Resource" script_class="WeaponResource" load_steps=3 format=3 uid="uid://b081hg7uxx1wu"]
|
[gd_resource type="Resource" script_class="WeaponResource" load_steps=4 format=3 uid="uid://b081hg7uxx1wu"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://bmnqvop2dy5pm" path="res://textures/prototype_yellow_256x256.png" id="1_hmyxe"]
|
[ext_resource type="Texture2D" uid="uid://bmnqvop2dy5pm" path="res://textures/prototype_yellow_256x256.png" id="1_hmyxe"]
|
||||||
[ext_resource type="Script" uid="uid://bvnn2eiwqbu7t" path="res://scripts/resources/weapon_resource.gd" id="1_ktfgd"]
|
[ext_resource type="Script" uid="uid://bvnn2eiwqbu7t" path="res://scripts/resources/weapon_resource.gd" id="1_ktfgd"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c5q7e5dj86187" path="res://scenes/weapons/molikman_molik.tscn" id="3_6mu31"]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("1_ktfgd")
|
script = ExtResource("1_ktfgd")
|
||||||
cost = 300
|
cost = 300
|
||||||
preview = ExtResource("1_hmyxe")
|
preview = ExtResource("1_hmyxe")
|
||||||
|
weapon_system_scene = ExtResource("3_6mu31")
|
||||||
slot = &"ability"
|
slot = &"ability"
|
||||||
metadata/_custom_type_script = "uid://bvnn2eiwqbu7t"
|
metadata/_custom_type_script = "uid://bvnn2eiwqbu7t"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue