Skip to content

Commit

Permalink
Add weapon on spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayHorizon committed Sep 14, 2024
1 parent 83d87f9 commit 3e25975
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
5 changes: 0 additions & 5 deletions source/client/instance/instance_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ func update_entity(entity_id: int, to_update: Dictionary) -> void:
for thing in to_update:
entity.set_indexed(thing, to_update[thing])

@rpc("authority", "call_remote", "reliable", 0)
func change_character_weapon(character_id: int, weapon_path: String, side: bool) -> void:
(entity_collection[character_id] as Character).change_weapon(weapon_path, side)


@rpc("any_peer", "call_remote", "reliable", 0)
func player_trying_to_change_weapon(weapon_path: String, side: bool = true) -> void:
player_trying_to_change_weapon.rpc_id(1, weapon_path, side)
Expand Down
13 changes: 12 additions & 1 deletion source/common/entities/characters/character.gd.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ enum Animations {

var hand_type: Hand.Types

var weapon_name_right: String:
set = _set_right_weapon
var weapon_name_left: String:
set = _set_left_weapon
var equiped_weapon_right: Weapon
var equiped_weapon_left: Weapon

Expand Down Expand Up @@ -54,9 +58,16 @@ func change_weapon(weapon_path: String, _side: bool = true) -> void:
func update_weapon_animation(state: String) -> void:
equiped_weapon_right.play_animation(state)
equiped_weapon_left.play_animation(state)



func _set_left_weapon(weapon_name: String) -> void:
weapon_name_left = weapon_name
change_weapon(weapon_name, false)

func _set_right_weapon(weapon_name: String) -> void:
weapon_name_right = weapon_name
change_weapon(weapon_name, true)

func _set_sprite_frames(new_sprite_frames: String) -> void:
animated_sprite.sprite_frames = ResourceLoader.load(
"res://source/common/resources/builtin/sprite_frames/" + new_sprite_frames + ".tres")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://c4mlxpbwyc1tw"]

[ext_resource type="Texture2D" uid="uid://clc768ctxxvjg" path="res://assets/sprites/items/weapons/hands/human_hands.png" id="1_on2c6"]
[ext_resource type="Script" path="res://source/common/items/weapons/hand_component/hands.gd" id="2_6u7qf"]
[ext_resource type="Script" path="res://source/common/items/hand_component/hands.gd" id="2_6u7qf"]

[node name="Hand" type="Sprite2D"]
texture = ExtResource("1_on2c6")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion source/common/items/weapons/weapon.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Script" path="res://source/common/items/weapons/weapon.gd" id="1_aiw52"]
[ext_resource type="Texture2D" uid="uid://bl4x3jlsvt3jq" path="res://assets/sprites/items/weapons/bone/bone.png" id="2_33udu"]
[ext_resource type="PackedScene" uid="uid://c4mlxpbwyc1tw" path="res://source/common/items/weapons/hand_component/hand.tscn" id="3_ydnw2"]
[ext_resource type="PackedScene" uid="uid://c4mlxpbwyc1tw" path="res://source/common/items/hand_component/hand.tscn" id="3_ydnw2"]

[sub_resource type="Animation" id="Animation_bfela"]
length = 0.001
Expand Down
12 changes: 4 additions & 8 deletions source/server/instance/instance_server.gd
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,13 @@ func fetch_player_state(sync_state: Dictionary) -> void:
entity.sync_state[key] = sync_state[key]
entity.sync_state = entity.sync_state

@rpc("authority", "call_remote", "reliable", 0)
func change_character_weapon(character_id: int, weapon_path: String, side: bool) -> void:
(entity_collection[character_id] as Character).change_weapon(weapon_path, side)
for peer_id in connected_peers:
change_character_weapon.rpc_id(peer_id, character_id, weapon_path, side)

@rpc("any_peer", "call_remote", "reliable", 0)
func player_trying_to_change_weapon(weapon_path: String, side: bool = true) -> void:
func player_trying_to_change_weapon(weapon_path: String, _side: bool = true) -> void:
var peer_id: int = multiplayer.get_remote_sender_id()
# Check if player has the weapon
change_character_weapon(peer_id, weapon_path, side)
var entity: Entity = entity_collection[peer_id] as Entity
update_entity(entity, {"weapon_name_right": weapon_path})
entity.spawn_state["weapon_name_right"] = weapon_path


@rpc("any_peer", "call_remote", "reliable", 0)
Expand Down

0 comments on commit 3e25975

Please sign in to comment.