button press picking, rate limited
This commit is contained in:
parent
ff92434409
commit
322cdf1a05
@ -24,6 +24,12 @@ var _interaction_selection: Node3D
|
||||
var controls_disabled := false
|
||||
@export var held_thing := { "item_id": &"empty_hand", "count": 0 }
|
||||
|
||||
## Whether picking input is pressed right now
|
||||
var _picking := false
|
||||
## Used to limit picking rate, potentially upgradable
|
||||
var _last_picked := 0
|
||||
var _picks_per_second := 3
|
||||
|
||||
|
||||
# What the others see.
|
||||
func _init_bystander() -> void:
|
||||
@ -154,14 +160,9 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
return
|
||||
|
||||
if event.is_action_pressed("pick"):
|
||||
if _interaction_selection != null:
|
||||
if empty_handed():
|
||||
_interaction_selection.owner.get_picked_up.rpc()
|
||||
hold_thing.rpc(_interaction_selection.owner.item_bundle)
|
||||
elif GameState.are_bundles_stackable(held_thing, _interaction_selection.owner.item_bundle):
|
||||
_interaction_selection.owner.get_picked_up.rpc()
|
||||
var bundle := GameState.combine_bundles(held_thing, _interaction_selection.owner.item_bundle)
|
||||
hold_thing.rpc(bundle)
|
||||
_picking = true
|
||||
if event.is_action_released("pick"):
|
||||
_picking = false
|
||||
|
||||
if event.is_action_pressed("fire") and not empty_handed():
|
||||
var item := GameState.fetch().INVENTORY_ITEM_DB[held_thing["item_id"]] as InventoryItem
|
||||
@ -190,10 +191,23 @@ func _set_projectile_authority(path: NodePath, authority_id: int) -> void:
|
||||
|
||||
|
||||
func _process_input() -> void:
|
||||
if controls_disabled:
|
||||
if controls_disabled or id != multiplayer.get_unique_id():
|
||||
input_dir = Vector2.ZERO
|
||||
input_jumped = false
|
||||
return
|
||||
|
||||
input_dir = Input.get_vector("strafe_left", "strafe_right", "move_forward", "move_backward")
|
||||
input_jumped = Input.is_action_just_pressed("jump")
|
||||
|
||||
if _picking and (Time.get_ticks_msec() - _last_picked) >= (1000.0 / _picks_per_second) \
|
||||
and _interaction_selection != null:
|
||||
if empty_handed():
|
||||
_last_picked = Time.get_ticks_msec()
|
||||
_interaction_selection.owner.get_picked_up.rpc()
|
||||
hold_thing.rpc(_interaction_selection.owner.item_bundle)
|
||||
elif GameState.are_bundles_stackable(held_thing, _interaction_selection.owner.item_bundle):
|
||||
_last_picked = Time.get_ticks_msec()
|
||||
_interaction_selection.owner.get_picked_up.rpc()
|
||||
var bundle := GameState.combine_bundles(held_thing, _interaction_selection.owner.item_bundle)
|
||||
hold_thing.rpc(bundle)
|
||||
#_line_of_sight.force_shapecast_update()
|
||||
|
Loading…
Reference in New Issue
Block a user