Skip to content

Commit

Permalink
Let a Servant-in-Cart interact with raw file nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bozar committed Nov 13, 2024
1 parent 7860ffb commit 4ac2574
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
8 changes: 8 additions & 0 deletions library/game_specific/handle_raw_file.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ static func reduce_cooldown(states: Array, ref_RandomNumber: RandomNumber) \
break


static func can_receive_servant(state: RawFileState) -> bool:
return state.cooldown > 0


static func receive_servant(state: RawFileState) -> void:
state.cooldown -= GameData.RAW_FILE_ADD_COOLDOWN


static func switch_examine_mode(is_examine: bool, states: Array) -> void:
var state: RawFileState
var progress_bar: Sprite2D
Expand Down
38 changes: 36 additions & 2 deletions library/pc_hit_actor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ static func handle_input(actor: Sprite2D, ref_PcAction: PcAction,
SubTag.ATLAS, SubTag.BOOK, SubTag.CUP, SubTag.ENCYCLOPEDIA:
if _load_raw_file(actor, ref_PcAction, ref_ActorAction):
ref_ActorAction.send_raw_file(actor)
elif _can_unload_servant(actor, ref_PcAction) and \
ref_ActorAction.can_receive_servant(actor):
_unload_servant(ref_PcAction)
ref_ActorAction.receive_servant(actor)
else:
return
SubTag.CLERK:
Expand Down Expand Up @@ -139,10 +143,11 @@ static func _unload_document(ref_PcAction: PcAction) -> bool:

static func _load_raw_file(actor: Sprite2D, ref_PcAction: PcAction,
ref_ActorAction: ActorAction) -> bool:

if not ref_ActorAction.raw_file_is_available(actor):
return false
elif actor.is_in_group(SubTag.ENCYCLOPEDIA) and \
(ref_PcAction.count_cart() < GameData.CART_LENGTH_LONG):
elif actor.is_in_group(SubTag.ENCYCLOPEDIA) and not _is_long_cart(
ref_PcAction):
return false

var cart: Sprite2D = ref_PcAction.get_last_slot()
Expand Down Expand Up @@ -217,3 +222,32 @@ static func _load_servant(actor: Sprite2D, ref_PcAction: PcAction) -> bool:

static func _remove_all_servant(ref_PcAction: PcAction) -> bool:
return ref_PcAction.remove_all_item(SubTag.SERVANT)


static func _can_unload_servant(actor: Sprite2D, ref_PcAction: PcAction) \
-> bool:

var cart_sprite: Sprite2D = ref_PcAction.get_first_item()
var cart_state: CartState

if cart_sprite == null:
return false

cart_state = ref_PcAction.get_state(cart_sprite)
if cart_state.item_tag != SubTag.SERVANT:
return false

if actor.is_in_group(SubTag.ENCYCLOPEDIA):
return _is_long_cart(ref_PcAction)
return true


static func _unload_servant(ref_PcAction: PcAction) -> void:
var cart_sprite: Sprite2D = ref_PcAction.get_first_item()
var cart_state: CartState = ref_PcAction.get_state(cart_sprite)

cart_state.item_tag = SubTag.CART


static func _is_long_cart(ref_PcAction: PcAction) -> bool:
return ref_PcAction.count_cart() >= GameData.CART_LENGTH_LONG
10 changes: 10 additions & 0 deletions scene/main/actor_action.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func receive_raw_file(sprite: Sprite2D, item_tag: StringName) -> bool:
return false


func can_receive_servant(sprite: Sprite2D) -> bool:
var state: RawFileState = _get_actor_state(sprite)
return HandleRawFile.can_receive_servant(state)


func receive_servant(sprite: Sprite2D) -> void:
var state: RawFileState = _get_actor_state(sprite)
HandleRawFile.receive_servant(state)


func push_servant(actor: Sprite2D) -> void:
var state: ActorState = _get_actor_state(actor)

Expand Down

0 comments on commit 4ac2574

Please sign in to comment.