diff --git a/scenes/hydroponics_station.tscn b/scenes/hydroponics_station.tscn index 42d69b9..05253db 100644 --- a/scenes/hydroponics_station.tscn +++ b/scenes/hydroponics_station.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=1] [ext_resource path="res://scripts/hydroponics_station/hydroponics_station.gd" type="Script" id=2] [ext_resource path="res://scenes/coin_machine.tscn" type="PackedScene" id=3] +[ext_resource path="res://scenes/status_light.tscn" type="PackedScene" id=4] +[ext_resource path="res://scenes/item_dump.tscn" type="PackedScene" id=5] +[ext_resource path="res://item_types/repair_kit.tres" type="Resource" id=6] [sub_resource type="CylinderMesh" id=1] height = 0.936 @@ -13,6 +16,7 @@ points = PoolVector3Array( -0.0608763, 0.449247, 0.974783, -0.0608763, -0.464612 [node name="hydroponics_station" type="Spatial"] script = ExtResource( 2 ) +start_broken = true [node name="MeshInstance" type="MeshInstance" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.372095, 0 ) @@ -38,6 +42,16 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.991012, 0 ) [node name="grow_timer" type="Timer" parent="."] one_shot = true +[node name="status_light" parent="." instance=ExtResource( 4 )] +unique_name_in_owner = true +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.0767, -0.147681, 0 ) + +[node name="item_dump" parent="." instance=ExtResource( 5 )] +unique_name_in_owner = true +item_type_0 = ExtResource( 6 ) +item_count_0 = 1 + [connection signal="coin_requirement_met" from="coin_machine" to="." method="_on_coin_machine_coin_requirement_met"] [connection signal="item_changed" from="item_holder" to="." method="_on_item_holder_item_changed"] [connection signal="timeout" from="grow_timer" to="." method="_on_grow_timer_timeout"] +[connection signal="item_dump_completed" from="item_dump" to="." method="_on_item_dump_item_dump_completed"] diff --git a/scripts/crafting_station/state/broken.gd b/scripts/crafting_station/state/broken.gd index 6646832..35dfc49 100644 --- a/scripts/crafting_station/state/broken.gd +++ b/scripts/crafting_station/state/broken.gd @@ -37,6 +37,7 @@ func on_item_holder_item_changed(item): pass func on_item_dump_item_dump_completed(): + ctx.full_heal() if ctx.item_holder.item_in_hold == null: ctx.change_state(ctx.States[ctx.EState.IDLE].new()) else: diff --git a/scripts/damageable_object.gd b/scripts/damageable_object.gd index 76295ce..8a027a6 100644 --- a/scripts/damageable_object.gd +++ b/scripts/damageable_object.gd @@ -9,14 +9,14 @@ export var start_broken : bool = false var current_hp : int = 1 setget set_hp func _init(): + pass + +func _ready(): var starting_hp : int = max_hp if start_broken: starting_hp = 0 set_hp(starting_hp) -func _ready(): - pass - func take_damage(damage : int = 1): set_hp(current_hp - max_hp) @@ -26,3 +26,6 @@ func set_hp(hp_to_set : int): remove_from_group(GROUP_STRING) if current_hp > 0 and !is_in_group(GROUP_STRING): add_to_group(GROUP_STRING) + +func full_heal(): + set_hp(max_hp) diff --git a/scripts/hydroponics_station/hydroponics_station.gd b/scripts/hydroponics_station/hydroponics_station.gd index 06d7054..04380d8 100644 --- a/scripts/hydroponics_station/hydroponics_station.gd +++ b/scripts/hydroponics_station/hydroponics_station.gd @@ -1,16 +1,20 @@ -extends Spatial +extends Damageable const StateIdle = preload("res://scripts/hydroponics_station/state/idle.gd") const StateGrowing = preload("res://scripts/hydroponics_station/state/growing.gd") const StateBlocked = preload("res://scripts/hydroponics_station/state/blocked.gd") +const StateBroken = preload("res://scripts/hydroponics_station/state/broken.gd") export var grow_time: float = 2.0 var state = null +onready var status_light = $"%status_light" +onready var item_dump = $"%item_dump" + func _ready(): $grow_timer.wait_time = grow_time - - state = StateIdle.new() + + state = StateBroken.new() if start_broken else StateIdle.new() state.ctx = self state.enter_from(null) print("hydroponics_station: NULL -> ", state.NAME) @@ -30,3 +34,10 @@ func _on_grow_timer_timeout(): func _on_item_holder_item_changed(item): state.on_item_holder_item_changed(item) + +func _on_item_dump_item_dump_completed(): + state.on_item_dump_item_dump_completed() + +func take_damage(damage : int = 1): + .take_damage(damage) + state.on_damage_taken() diff --git a/scripts/hydroponics_station/state/blocked.gd b/scripts/hydroponics_station/state/blocked.gd index 3e3cc0a..ed8b243 100644 --- a/scripts/hydroponics_station/state/blocked.gd +++ b/scripts/hydroponics_station/state/blocked.gd @@ -10,6 +10,9 @@ func _init(): func enter_from(state): ctx.get_node("coin_machine").enabled = false ctx.get_node("item_holder").add_enabled = true + ctx.get_node("item_holder").remove_enabled = true + ctx.status_light.warn() + ctx.item_dump.enabled = false func exit_to(state): pass @@ -23,3 +26,10 @@ func on_grow_timer_timeout(): func on_item_holder_item_changed(item): if item == null: ctx.change_state(ctx.StateIdle.new()) + +func on_item_dump_item_dump_completed(): + assert(false) + +func on_damage_taken(): + if ctx.current_hp <= 0: + ctx.change_state(ctx.StateBroken.new()) diff --git a/scripts/hydroponics_station/state/broken.gd b/scripts/hydroponics_station/state/broken.gd new file mode 100644 index 0000000..e385048 --- /dev/null +++ b/scripts/hydroponics_station/state/broken.gd @@ -0,0 +1,36 @@ +extends Reference + +const NAME = "broken" + +var ctx = null + +func _init(): + pass + +func enter_from(state): + ctx.get_node("coin_machine").enabled = false + ctx.get_node("item_holder").add_enabled = false + ctx.get_node("item_holder").remove_enabled = false + ctx.status_light.fail() + ctx.item_dump.enabled = true + ctx.item_dump.reset() + +func exit_to(state): + pass + +func on_coin_machine_coin_requirement_met(player): + assert(false) + +func on_grow_timer_timeout(): + assert(false) + +func on_item_holder_item_changed(item): + if item == null: + ctx.change_state(ctx.StateIdle.new()) + +func on_item_dump_item_dump_completed(): + ctx.full_heal() + ctx.change_state(ctx.StateIdle.new()) + +func on_damage_taken(): + assert(false, "cant take damage when broken") diff --git a/scripts/hydroponics_station/state/growing.gd b/scripts/hydroponics_station/state/growing.gd index b2b3190..0c819a6 100644 --- a/scripts/hydroponics_station/state/growing.gd +++ b/scripts/hydroponics_station/state/growing.gd @@ -12,8 +12,11 @@ func _init(): func enter_from(state): ctx.get_node("coin_machine").enabled = false ctx.get_node("item_holder").add_enabled = false + ctx.get_node("item_holder").remove_enabled = false ctx.get_node("grow_timer").start() ctx.get_node("MeshInstance").set_surface_material(0, mat) + ctx.status_light.activate() + ctx.item_dump.enabled = false func exit_to(state): ctx.get_node("MeshInstance").set_surface_material(0, null) @@ -28,3 +31,11 @@ func on_grow_timer_timeout(): func on_item_holder_item_changed(item): assert(item.item_type == raw_yam) + +func on_item_dump_item_dump_completed(): + assert(false) + +func on_damage_taken(): + ctx.get_node("grow_timer").stop() + if ctx.current_hp <= 0: + ctx.change_state(ctx.StateBroken.new()) diff --git a/scripts/hydroponics_station/state/idle.gd b/scripts/hydroponics_station/state/idle.gd index b60d10b..6e8c8c6 100644 --- a/scripts/hydroponics_station/state/idle.gd +++ b/scripts/hydroponics_station/state/idle.gd @@ -10,6 +10,9 @@ func _init(): func enter_from(state): ctx.get_node("coin_machine").enabled = true ctx.get_node("item_holder").add_enabled = true + ctx.get_node("item_holder").remove_enabled = true + ctx.status_light.idle() + ctx.item_dump.enabled = false func exit_to(state): pass @@ -23,3 +26,10 @@ func on_grow_timer_timeout(): func on_item_holder_item_changed(item): assert(item != null) ctx.change_state(ctx.StateBlocked.new()) + +func on_item_dump_item_dump_completed(): + assert(false) + +func on_damage_taken(): + if ctx.current_hp <= 0: + ctx.change_state(ctx.StateBroken.new()) diff --git a/scripts/item_generator/state/broken.gd b/scripts/item_generator/state/broken.gd index c15dc20..d57f54a 100644 --- a/scripts/item_generator/state/broken.gd +++ b/scripts/item_generator/state/broken.gd @@ -33,6 +33,7 @@ func on_item_slot_item_changed(item): assert(false, "item dump should be disabled while broken") func on_item_dump_item_dump_completed(): + ctx.full_heal() for item_slot in ctx.item_slots: if item_slot.has_item(): ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Blocked!")) diff --git a/scripts/oven/state/broken.gd b/scripts/oven/state/broken.gd index 5d1c466..f80423f 100644 --- a/scripts/oven/state/broken.gd +++ b/scripts/oven/state/broken.gd @@ -30,6 +30,7 @@ func on_item_holder_item_changed(item): assert(false, "should be impossible while broken") func on_item_dump_completed(): + ctx.full_heal() ctx.change_state(ctx.StateIdle.new()) func take_damage():