add gathering awaiting
This commit is contained in:
@@ -31,13 +31,12 @@ func _ready() -> void:
|
||||
for i in MAX_CARRY:
|
||||
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||
gathering.initialize(anthill, skeleton, item_bones, MAX_CARRY, 0.4, 1)
|
||||
gathering.target_set.connect(_on_gathering_target_set)
|
||||
gathering.stopped_gathering.connect(_on_stopped_gathering)
|
||||
gathering.navigate_to.connect(_on_gathering_navigate_to)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if moving_to_target:
|
||||
if is_relocating:
|
||||
state = AntGathererState.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
@@ -58,7 +57,7 @@ func _handle_wandering(delta: float) -> void:
|
||||
|
||||
|
||||
func _handle_gathering() -> void:
|
||||
gathering.handle_gathering(state != AntGathererState.GATHERING, showing_info)
|
||||
gathering.handle_gathering(showing_info)
|
||||
|
||||
|
||||
func _on_moving_ended() -> void:
|
||||
@@ -71,12 +70,8 @@ func _on_moving_started() -> void:
|
||||
state = AntGathererState.MOVING
|
||||
|
||||
|
||||
func _on_gathering_target_set(pos: Vector3) -> void:
|
||||
func _on_gathering_navigate_to(pos: Vector3) -> void:
|
||||
if state != AntGathererState.GATHERING:
|
||||
return
|
||||
|
||||
nav_agent.set_target_position(pos)
|
||||
|
||||
|
||||
func _on_stopped_gathering() -> void:
|
||||
state = AntGathererState.WANDERING
|
||||
navigate(pos)
|
||||
|
||||
@@ -30,13 +30,12 @@ func _ready() -> void:
|
||||
for i in gathering.DEFAULT_MAX_CARRYING:
|
||||
item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i)))
|
||||
gathering.initialize(anthill, skeleton, item_bones)
|
||||
gathering.target_set.connect(_on_gathering_target_set)
|
||||
gathering.stopped_gathering.connect(_on_stopped_gathering)
|
||||
gathering.navigate_to.connect(_on_gathering_navigate_to)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
super._process(delta)
|
||||
if moving_to_target:
|
||||
if is_relocating:
|
||||
state = AntNitwitState.MOVING
|
||||
|
||||
_handle_wandering(delta)
|
||||
@@ -57,7 +56,7 @@ func _handle_wandering(delta: float) -> void:
|
||||
|
||||
|
||||
func _handle_gathering() -> void:
|
||||
gathering.handle_gathering(state != AntNitwitState.GATHERING, showing_info)
|
||||
gathering.handle_gathering(showing_info)
|
||||
|
||||
|
||||
func _on_moving_ended() -> void:
|
||||
@@ -70,12 +69,10 @@ func _on_moving_started() -> void:
|
||||
state = AntNitwitState.MOVING
|
||||
|
||||
|
||||
func _on_gathering_target_set(pos: Vector3) -> void:
|
||||
func _on_gathering_navigate_to(pos: Vector3) -> void:
|
||||
print('_on_gathering_navigate_to')
|
||||
if state != AntNitwitState.GATHERING:
|
||||
return
|
||||
print('_on_gathering_navigate_to 2')
|
||||
|
||||
nav_agent.set_target_position(pos)
|
||||
|
||||
|
||||
func _on_stopped_gathering() -> void:
|
||||
state = AntNitwitState.WANDERING
|
||||
navigate(pos)
|
||||
|
||||
@@ -65,7 +65,6 @@ func _handle_honeydew_spawn(delta: float) -> void:
|
||||
holder.add_child(new_honeydew)
|
||||
new_honeydew.global_position = global_position + new_pos
|
||||
_put_honeydew(new_honeydew)
|
||||
audio_player.play_polyphonic(SoundManager.pop())
|
||||
|
||||
_set_spawn_timer()
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
extends Area3D
|
||||
class_name Gathering
|
||||
|
||||
signal target_set(pos: Vector3)
|
||||
signal stopped_gathering
|
||||
signal navigate_to(pos: Vector3)
|
||||
|
||||
const DEFAULT_MAX_CARRYING = 3
|
||||
const DEFAULT_DROP_INTERVAL = 0.25
|
||||
@@ -11,6 +10,7 @@ const DROP_SPREAD: float = 0.1
|
||||
const ANTHILL_DEPOSIT_RADIUS: float = 0.5
|
||||
|
||||
enum GatherState {
|
||||
AWAITING,
|
||||
PICKING_UP,
|
||||
DEPOSITING,
|
||||
STOP,
|
||||
@@ -89,11 +89,9 @@ func initialize(
|
||||
item_bones = bones
|
||||
|
||||
|
||||
func handle_gathering(stop: bool, showing_info: bool) -> void:
|
||||
func handle_gathering(showing_info: bool) -> void:
|
||||
collision_shape.global_position = gathering_center
|
||||
collision_shape.global_rotation = Vector3.ZERO
|
||||
if stop:
|
||||
state = GatherState.STOP
|
||||
|
||||
radius_indicator.visible = (
|
||||
(state != GatherState.STOP and showing_info)
|
||||
@@ -104,7 +102,8 @@ func handle_gathering(stop: bool, showing_info: bool) -> void:
|
||||
func start_gathering(item: Honeydew) -> void:
|
||||
gathering_center = item.global_position
|
||||
showing_after_set = true
|
||||
_go_gather(item)
|
||||
state = GatherState.AWAITING
|
||||
_go_pick_up(item)
|
||||
|
||||
|
||||
func stop_gathering() -> void:
|
||||
@@ -123,7 +122,7 @@ func on_nav_agent_navigation_finished() -> void:
|
||||
_deposit()
|
||||
|
||||
|
||||
func _go_gather(item: Honeydew) -> void:
|
||||
func _go_pick_up(item: Honeydew) -> void:
|
||||
if anthill.space_left() <= 0:
|
||||
return
|
||||
if carrying_items.size() >= max_carrying:
|
||||
@@ -131,13 +130,13 @@ func _go_gather(item: Honeydew) -> void:
|
||||
return
|
||||
target = item
|
||||
state = GatherState.PICKING_UP
|
||||
target_set.emit(item.global_position)
|
||||
navigate_to.emit(item.global_position)
|
||||
|
||||
|
||||
func _go_deposit() -> void:
|
||||
state = GatherState.DEPOSITING
|
||||
var dir := anthill.global_position.direction_to(global_position)
|
||||
target_set.emit(
|
||||
navigate_to.emit(
|
||||
anthill.global_position
|
||||
+ dir
|
||||
* ANTHILL_DEPOSIT_RADIUS
|
||||
@@ -152,7 +151,7 @@ func _pick_up() -> void:
|
||||
var nearest := _find_nearest(nearby_items.values())
|
||||
if target == null or target.carried:
|
||||
if nearest != null:
|
||||
_go_gather(nearest)
|
||||
_go_pick_up(nearest)
|
||||
elif carrying_items.size() > 0:
|
||||
_go_deposit()
|
||||
return
|
||||
@@ -170,7 +169,7 @@ func _pick_up() -> void:
|
||||
_go_deposit()
|
||||
return
|
||||
|
||||
_go_gather(nearest)
|
||||
_go_pick_up(nearest)
|
||||
|
||||
|
||||
func _deposit() -> void:
|
||||
@@ -180,10 +179,8 @@ func _deposit() -> void:
|
||||
return
|
||||
|
||||
if anthill.space_left() <= 0:
|
||||
print('DROP!')
|
||||
_drop_everything()
|
||||
stop_gathering()
|
||||
stopped_gathering.emit()
|
||||
state = GatherState.AWAITING
|
||||
await _drop_everything()
|
||||
return
|
||||
|
||||
var item := carrying_items.pop_back() as Honeydew
|
||||
@@ -198,11 +195,11 @@ func _deposit() -> void:
|
||||
|
||||
var nearest := _find_nearest(nearby_items.values())
|
||||
if nearest != null:
|
||||
_go_gather(nearest)
|
||||
_go_pick_up(nearest)
|
||||
return
|
||||
|
||||
stop_gathering()
|
||||
stopped_gathering.emit()
|
||||
state = GatherState.AWAITING
|
||||
navigate_to.emit(gathering_center)
|
||||
|
||||
|
||||
func _drop_everything() -> void:
|
||||
@@ -248,6 +245,8 @@ func _on_body_entered(item: Node3D) -> void:
|
||||
return
|
||||
|
||||
nearby_items[item_id] = item as Honeydew
|
||||
if state == GatherState.AWAITING and anthill.space_left() > 0:
|
||||
_go_pick_up(item as Honeydew)
|
||||
|
||||
|
||||
func _on_body_exited(item: Node3D) -> void:
|
||||
|
||||
@@ -8,7 +8,7 @@ var anthill: Anthill
|
||||
|
||||
var hovered_rect: bool = false
|
||||
var selected: bool = false
|
||||
var moving_to_target: bool = false
|
||||
var is_relocating: bool = false
|
||||
var ground_plane: Plane = Plane(Vector3.UP, 0)
|
||||
|
||||
@onready var camera: Camera3D = get_viewport().get_camera_3d()
|
||||
@@ -40,8 +40,8 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
if moving_to_target and nav_agent.is_navigation_finished():
|
||||
moving_to_target = false
|
||||
if is_relocating and nav_agent.is_navigation_finished():
|
||||
is_relocating = false
|
||||
moving_ended.emit()
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ func _input(event: InputEvent) -> void:
|
||||
if HoveringManager.hovered_node is Interactable:
|
||||
_interact(HoveringManager.hovered_node as Interactable)
|
||||
else:
|
||||
moving_to_target = true
|
||||
moving_started.emit()
|
||||
_set_target_click(button_event.position)
|
||||
|
||||
@@ -78,6 +77,11 @@ func set_selected(on: bool) -> void:
|
||||
selected = on
|
||||
|
||||
|
||||
func navigate(to: Vector3, relocating: bool = false) -> void:
|
||||
is_relocating = relocating
|
||||
nav_agent.set_target_position(to)
|
||||
|
||||
|
||||
func _interact(with: Interactable) -> void:
|
||||
print(self, ' interacting with ', with)
|
||||
|
||||
@@ -87,7 +91,7 @@ func _set_target_click(mouse_pos: Vector2) -> void:
|
||||
if click_pos == null:
|
||||
return
|
||||
|
||||
nav_agent.set_target_position(click_pos)
|
||||
navigate(click_pos, true)
|
||||
|
||||
|
||||
func _click_raycast(mouse_pos: Vector2) -> Vector3:
|
||||
|
||||
@@ -70,8 +70,8 @@ func toggle_info(on: bool) -> void:
|
||||
|
||||
|
||||
func _click() -> void:
|
||||
toggle_info(true)
|
||||
UiManager.unit_info.open(self)
|
||||
toggle_info(true)
|
||||
|
||||
|
||||
func _navigate() -> void:
|
||||
|
||||
Reference in New Issue
Block a user