Added broken state to hydroponic station and fixed a bug with all the brokens tates where they wouldn't heal the object back up on repair
This commit is contained in:
1 parent
6e6da14975
commit
ef4b8bd7cf
10 files changed
+105
-7
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
@@ -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()
|
||||
@@ -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())
|
||||
@@ -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")
|
||||
@@ -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())
|
||||
@@ -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())
|
||||
@@ -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!"))
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in new issue
Block a user