inventory bug fixes, multiplayer pickup sync
This commit is contained in:
parent
04a9a299d7
commit
000269875a
14 changed files with 88 additions and 43 deletions
|
|
@ -2,4 +2,21 @@ extends RigidBody3D
|
|||
|
||||
@export var item : Item
|
||||
@onready var interactable : Interactable = $Interactable
|
||||
@onready var is_interactable : bool = true
|
||||
@onready var is_interactable : bool = true
|
||||
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func pickup_item(player_id : int, item_name : String):
|
||||
print(item_name, "penis")
|
||||
# var item = get_node(item_name) as RigidBody3D
|
||||
# item.set_controller(item_holster_one)
|
||||
freeze = true
|
||||
collision_layer = 0
|
||||
hide()
|
||||
change_authority.rpc_id(1, player_id)
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func change_authority(player_id : int):
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
set_multiplayer_authority.call_deferred(player_id)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class_name Level
|
||||
extends Node
|
||||
|
||||
var player_scene : PackedScene = preload("res://Scenes/Mobs/character.tscn")
|
||||
var player_scene : PackedScene = preload("res://Scenes/Mobs/player.tscn")
|
||||
|
||||
@export var lobby : Lobby
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,11 @@ func toggle_inventory() -> bool:
|
|||
|
||||
func update_inventory():
|
||||
for i in inventory.items:
|
||||
var match_found : bool = false
|
||||
var new_item = item_scene.instantiate()
|
||||
# new_item.set_values(i.item.name, i.item.value, i.item.weight)
|
||||
item_list.add_child(new_item)
|
||||
new_item.set_values(i.item.name, 10, 10)
|
||||
print(i.item.name)
|
||||
print(i)
|
||||
pass
|
||||
for j in item_list.get_children():
|
||||
if j.id.text != str(i.item.id):
|
||||
match_found = true
|
||||
if !match_found || item_list.get_children().size() == 1:
|
||||
item_list.add_child(new_item)
|
||||
new_item.set_values(i.item.id, i.item.name, 10, 10)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
extends Node
|
||||
|
||||
@onready var id : Label = $Id
|
||||
@onready var title : Label = $Name
|
||||
@onready var value : Label = $Value
|
||||
@onready var weight : Label = $Weight
|
||||
|
||||
|
||||
func set_values(new_title : String, new_value : int, new_weight : int) -> void:
|
||||
func set_values(new_id : int, new_title : String, new_value : int, new_weight : int) -> void:
|
||||
id.text = str(new_id)
|
||||
title.text = new_title
|
||||
value.text = str(new_value)
|
||||
weight.text = str(new_weight)
|
||||
|
|
|
|||
1
Scripts/Resources/entity_resource.gd
Normal file
1
Scripts/Resources/entity_resource.gd
Normal file
|
|
@ -0,0 +1 @@
|
|||
extends Node
|
||||
1
Scripts/Resources/entity_resource.gd.uid
Normal file
1
Scripts/Resources/entity_resource.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cd0o5lwehj6cl
|
||||
|
|
@ -10,6 +10,7 @@ func get_current_slot(index : int) -> RigidBody3D:
|
|||
|
||||
func add_item(item : RigidBody3D) -> void:
|
||||
items.append(item)
|
||||
print(item.item.id, " added id")
|
||||
|
||||
func remove_items(item : RigidBody3D) -> void:
|
||||
items.erase(item)
|
||||
|
|
@ -2,8 +2,17 @@ extends Resource
|
|||
|
||||
class_name Item
|
||||
|
||||
@export var id : int
|
||||
@export var value : int
|
||||
@export var name : String
|
||||
@export var weight : int
|
||||
@export var primary_objective : bool
|
||||
@export var secondary_objective : bool
|
||||
var controller : Marker3D
|
||||
|
||||
|
||||
func set_controller(new_controller : Marker3D):
|
||||
controller = new_controller
|
||||
|
||||
func get_controller() -> Marker3D:
|
||||
return controller
|
||||
|
|
@ -57,7 +57,8 @@ extends CharacterBody3D
|
|||
@export var CROUCH_ANIMATION : AnimationPlayer
|
||||
## A reference to the the player's collision shape for use in the character script.
|
||||
@export var COLLISION_MESH : CollisionShape3D
|
||||
|
||||
## A reference to the item holster
|
||||
@onready var item_holster_one : Marker3D
|
||||
#endregion
|
||||
|
||||
#region Controls Export Group
|
||||
|
|
@ -173,6 +174,7 @@ func _ready():
|
|||
CAMERA.current = true
|
||||
inventory_menu = $UserInterface/InventoryMenu
|
||||
inventory_menu.inventory = INVENTORY
|
||||
item_holster_one = $Item_holster
|
||||
|
||||
func _process(_delta):
|
||||
# if pausing_enabled:
|
||||
|
|
@ -230,6 +232,10 @@ func teleport_player(location: Vector3, new_rotation: Vector3) -> void:
|
|||
velocity = Vector3.ZERO
|
||||
|
||||
|
||||
|
||||
# assign controller to item
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Input Handling
|
||||
|
|
@ -304,13 +310,13 @@ func handle_interact():
|
|||
interactable.interactable.outline.show()
|
||||
if "item" in interactable:
|
||||
if Input.is_action_just_pressed(controls.INTERACT):
|
||||
print(CAMERA_RAYCAST.get_collider())
|
||||
var item = interactable as RigidBody3D
|
||||
item.freeze = true
|
||||
item.collision_layer = 0
|
||||
item.hide()
|
||||
var player_id : int = name.lstrip("Player").to_int()
|
||||
item.pickup_item.rpc(player_id, item.name)
|
||||
|
||||
print('adding a item, heheheheheheheh')
|
||||
print("adding ID: ", item.item.id)
|
||||
INVENTORY.add_item(item)
|
||||
print("This is a item")
|
||||
elif HIGHLIGHTED_ITEM != null:
|
||||
HIGHLIGHTED_ITEM.get_node("Interactable").outline.hide()
|
||||
HIGHLIGHTED_ITEM = null
|
||||
Loading…
Add table
Add a link
Reference in a new issue