Added Damageable class that crating_station inherits from. Added new broken state to crafting_station with status light
This commit is contained in:
parent
63c0199d77
commit
7289eba670
@ -14,6 +14,11 @@ _global_script_classes=[ {
|
|||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://addons/dialogic/Localization/translation_service.gd"
|
"path": "res://addons/dialogic/Localization/translation_service.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Spatial",
|
||||||
|
"class": "Damageable",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://scripts/damageable_object.gd"
|
||||||
|
}, {
|
||||||
"base": "Node",
|
"base": "Node",
|
||||||
"class": "Dialogic",
|
"class": "Dialogic",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
@ -81,6 +86,7 @@ _global_script_classes=[ {
|
|||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"DTS": "",
|
"DTS": "",
|
||||||
|
"Damageable": "",
|
||||||
"Dialogic": "",
|
"Dialogic": "",
|
||||||
"DialogicAnimaPropertiesHelper": "",
|
"DialogicAnimaPropertiesHelper": "",
|
||||||
"DialogicAnimaResources": "",
|
"DialogicAnimaResources": "",
|
||||||
@ -99,7 +105,7 @@ _global_script_class_icons={
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="project-dung"
|
config/name="project-dung"
|
||||||
run/main_scene="res://scenes/main.tscn"
|
run/main_scene="res://scenes/dev-akshay.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
@ -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://scenes/item_holder.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://scripts/crafting_station/crafting_station.gd" type="Script" id=2]
|
[ext_resource path="res://scripts/crafting_station/crafting_station.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://scenes/coin_machine.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://scenes/coin_machine.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://scenes/item_dump.tscn" type="PackedScene" id=4]
|
||||||
|
[ext_resource path="res://scenes/status_light.tscn" type="PackedScene" id=5]
|
||||||
|
[ext_resource path="res://item_types/repair_kit.tres" type="Resource" id=6]
|
||||||
|
|
||||||
[sub_resource type="CylinderMesh" id=1]
|
[sub_resource type="CylinderMesh" id=1]
|
||||||
height = 0.936
|
height = 0.936
|
||||||
@ -11,8 +14,9 @@ radial_segments = 8
|
|||||||
[sub_resource type="ConvexPolygonShape" id=2]
|
[sub_resource type="ConvexPolygonShape" id=2]
|
||||||
points = PoolVector3Array( -0.0608763, 0.449247, 0.974783, -0.0608763, -0.464612, -0.974783, -0.0608763, 0.449247, -0.974783, 0.974783, -0.464612, -0.0608763, -0.974783, -0.464612, 0.0608763, 0.974783, 0.449247, 0.0608763, 0.0606902, -0.464648, 0.97486, -0.974783, 0.449247, -0.0608763, 0.7071, 0.453517, -0.7071, -0.705748, -0.468, -0.705748, -0.7071, 0.453517, 0.7071, 0.7071, 0.453517, 0.7071, 0.705748, -0.468, 0.705748, -0.705748, -0.468, 0.705748, 0.705748, -0.468, -0.705748, -0.7071, 0.453517, -0.7071, 0.0606902, -0.464648, -0.97486, -0.974783, -0.464612, -0.0608763, 0.974783, -0.464612, 0.0608763, -0.0608763, -0.464612, 0.974783, 0.0606902, 0.449283, 0.97486, 0.0606902, 0.449283, -0.97486, 0.974783, 0.449247, -0.0608763, -0.974783, 0.449247, 0.0608763, -0.642208, -0.46642, 0.73398, -0.642208, -0.46642, -0.73398, 0.578116, -0.464071, -0.760529, 0.578116, -0.464071, 0.760529, 0.760589, -0.464107, 0.577971, -0.760589, -0.464107, 0.577971, -0.760589, -0.464107, -0.577971, 0.760589, -0.464107, -0.577971 )
|
points = PoolVector3Array( -0.0608763, 0.449247, 0.974783, -0.0608763, -0.464612, -0.974783, -0.0608763, 0.449247, -0.974783, 0.974783, -0.464612, -0.0608763, -0.974783, -0.464612, 0.0608763, 0.974783, 0.449247, 0.0608763, 0.0606902, -0.464648, 0.97486, -0.974783, 0.449247, -0.0608763, 0.7071, 0.453517, -0.7071, -0.705748, -0.468, -0.705748, -0.7071, 0.453517, 0.7071, 0.7071, 0.453517, 0.7071, 0.705748, -0.468, 0.705748, -0.705748, -0.468, 0.705748, 0.705748, -0.468, -0.705748, -0.7071, 0.453517, -0.7071, 0.0606902, -0.464648, -0.97486, -0.974783, -0.464612, -0.0608763, 0.974783, -0.464612, 0.0608763, -0.0608763, -0.464612, 0.974783, 0.0606902, 0.449283, 0.97486, 0.0606902, 0.449283, -0.97486, 0.974783, 0.449247, -0.0608763, -0.974783, 0.449247, 0.0608763, -0.642208, -0.46642, 0.73398, -0.642208, -0.46642, -0.73398, 0.578116, -0.464071, -0.760529, 0.578116, -0.464071, 0.760529, 0.760589, -0.464107, 0.577971, -0.760589, -0.464107, 0.577971, -0.760589, -0.464107, -0.577971, 0.760589, -0.464107, -0.577971 )
|
||||||
|
|
||||||
[node name="crafting_station" type="Spatial"]
|
[node name="crafting_station" type="Spatial" groups=["damageable"]]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
start_broken = true
|
||||||
|
|
||||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.372095, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.372095, 0 )
|
||||||
@ -48,6 +52,18 @@ unique_name_in_owner = true
|
|||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="item_dump" parent="." instance=ExtResource( 4 )]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.366242, 0, 0 )
|
||||||
|
item_type_0 = ExtResource( 6 )
|
||||||
|
item_count_0 = 1
|
||||||
|
|
||||||
|
[node name="status_light" parent="." instance=ExtResource( 5 )]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.1, 0, 0 )
|
||||||
|
|
||||||
[connection signal="item_changed" from="item_holder" to="." method="_on_item_holder_item_changed"]
|
[connection signal="item_changed" from="item_holder" to="." method="_on_item_holder_item_changed"]
|
||||||
[connection signal="coin_requirement_met" from="coin_machine" to="." method="_on_coin_machine_coin_requirement_met"]
|
[connection signal="coin_requirement_met" from="coin_machine" to="." method="_on_coin_machine_coin_requirement_met"]
|
||||||
[connection signal="timeout" from="gen_timer" to="." method="_on_gen_timer_timeout"]
|
[connection signal="timeout" from="gen_timer" to="." method="_on_gen_timer_timeout"]
|
||||||
|
[connection signal="item_dump_completed" from="item_dump" to="." method="_on_item_dump_item_dump_completed"]
|
||||||
|
[connection signal="item_dumped" from="item_dump" to="." method="_on_item_dump_item_dumped"]
|
||||||
|
@ -295,10 +295,11 @@ modulate = Color( 0, 0, 0, 1 )
|
|||||||
text = "Galley"
|
text = "Galley"
|
||||||
|
|
||||||
[node name="dinner_table" parent="Galley_Room" instance=ExtResource( 12 )]
|
[node name="dinner_table" parent="Galley_Room" instance=ExtResource( 12 )]
|
||||||
transform = Transform( 1, 0, -1.49012e-08, 0, 1, 0, 1.49012e-08, 0, 1, 1.54321, 0, -7.74583 )
|
transform = Transform( 1, 0, -1.11759e-08, 0, 1, 0, 1.11759e-08, 0, 1, 1.77669, 0, -8.88646 )
|
||||||
|
|
||||||
[node name="oven" parent="Galley_Room" instance=ExtResource( 14 )]
|
[node name="oven" parent="Galley_Room" instance=ExtResource( 14 )]
|
||||||
transform = Transform( 1, 0, -7.45058e-09, 0, 1, 0, 7.45058e-09, 0, 1, -2.08601, 0, -7.98964 )
|
transform = Transform( 1.00001, 0, 3.72529e-09, 0, 1, 0, -3.72529e-09, 0, 1.00001, -2.828, 0, -10.6561 )
|
||||||
|
start_broken = true
|
||||||
|
|
||||||
[node name="Hydroponics_Room" type="Spatial" parent="."]
|
[node name="Hydroponics_Room" type="Spatial" parent="."]
|
||||||
transform = Transform( 0.690862, 0.000404371, 0.722986, -0.000832856, 1, 0.000236545, -0.722985, -0.000765563, 0.690862, -6.25959, -7.15916e-05, -5.86512 )
|
transform = Transform( 0.690862, 0.000404371, 0.722986, -0.000832856, 1, 0.000236545, -0.722985, -0.000765563, 0.690862, -6.25959, -7.15916e-05, -5.86512 )
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=8 format=2]
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://scripts/dinner_table.gd" type="Script" id=2]
|
[ext_resource path="res://scripts/dinner_table.gd" type="Script" id=2]
|
||||||
@ -6,19 +6,6 @@
|
|||||||
|
|
||||||
[sub_resource type="SphereShape" id=4]
|
[sub_resource type="SphereShape" id=4]
|
||||||
|
|
||||||
[sub_resource type="CylinderMesh" id=1]
|
|
||||||
height = 0.1
|
|
||||||
radial_segments = 8
|
|
||||||
|
|
||||||
[sub_resource type="CylinderMesh" id=2]
|
|
||||||
top_radius = 0.1
|
|
||||||
bottom_radius = 0.1
|
|
||||||
height = 0.738
|
|
||||||
radial_segments = 16
|
|
||||||
|
|
||||||
[sub_resource type="CylinderShape" id=3]
|
|
||||||
height = 0.87498
|
|
||||||
|
|
||||||
[node name="dinner_table" type="Area"]
|
[node name="dinner_table" type="Area"]
|
||||||
collision_layer = 8
|
collision_layer = 8
|
||||||
collision_mask = 4
|
collision_mask = 4
|
||||||
@ -29,32 +16,6 @@ all_food = [ ExtResource( 3 ) ]
|
|||||||
transform = Transform( 1.2, 0, 0, 0, 1.2, 0, 0, 0, 1.2, 0, 0, 0 )
|
transform = Transform( 1.2, 0, 0, 0, 1.2, 0, 0, 0, 1.2, 0, 0, 0 )
|
||||||
shape = SubResource( 4 )
|
shape = SubResource( 4 )
|
||||||
|
|
||||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.648164, 0 )
|
|
||||||
mesh = SubResource( 1 )
|
|
||||||
|
|
||||||
[node name="MeshInstance2" type="MeshInstance" parent="."]
|
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.274821, 0.806474 )
|
|
||||||
mesh = SubResource( 2 )
|
|
||||||
|
|
||||||
[node name="MeshInstance3" type="MeshInstance" parent="."]
|
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.831715, 0.274821, 0.00579381 )
|
|
||||||
mesh = SubResource( 2 )
|
|
||||||
|
|
||||||
[node name="MeshInstance4" type="MeshInstance" parent="."]
|
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.012414, 0.274821, -0.832128 )
|
|
||||||
mesh = SubResource( 2 )
|
|
||||||
|
|
||||||
[node name="MeshInstance5" type="MeshInstance" parent="."]
|
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.809991, 0.274821, 0.00269032 )
|
|
||||||
mesh = SubResource( 2 )
|
|
||||||
|
|
||||||
[node name="StaticBody" type="StaticBody" parent="."]
|
|
||||||
|
|
||||||
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
|
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.439889, 0 )
|
|
||||||
shape = SubResource( 3 )
|
|
||||||
|
|
||||||
[node name="item_holder" parent="." instance=ExtResource( 1 )]
|
[node name="item_holder" parent="." instance=ExtResource( 1 )]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.776869, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.776869, 0 )
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
[sub_resource type="BoxShape" id=1]
|
[sub_resource type="BoxShape" id=1]
|
||||||
|
|
||||||
[node name="item_dump" type="Area"]
|
[node name="item_dump" type="Area"]
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 4
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="CollisionShape" type="CollisionShape" parent="."]
|
[node name="CollisionShape" type="CollisionShape" parent="."]
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
extents = Vector3( 0.648623, 1, 0.516904 )
|
extents = Vector3( 0.648623, 1, 0.516904 )
|
||||||
|
|
||||||
[node name="oven" type="Spatial" groups=["damageable"]]
|
[node name="oven" type="Spatial" groups=["damageable"]]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0063355, 0.00319374, -0.00456095 )
|
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="coin_machine" parent="." instance=ExtResource( 3 )]
|
[node name="coin_machine" parent="." instance=ExtResource( 3 )]
|
||||||
@ -19,7 +18,6 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.621351, 0 )
|
|||||||
|
|
||||||
[node name="item_dump" parent="." instance=ExtResource( 4 )]
|
[node name="item_dump" parent="." instance=ExtResource( 4 )]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.733121, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.733121, 0 )
|
||||||
collision_layer = 8
|
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
item_type_0 = ExtResource( 6 )
|
item_type_0 = ExtResource( 6 )
|
||||||
item_count_0 = 1
|
item_count_0 = 1
|
||||||
@ -32,7 +30,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.14052, 0 )
|
|||||||
shape = SubResource( 4 )
|
shape = SubResource( 4 )
|
||||||
|
|
||||||
[node name="status_light" parent="." instance=ExtResource( 5 )]
|
[node name="status_light" parent="." instance=ExtResource( 5 )]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.232042, 0.967385 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.868397 )
|
||||||
|
|
||||||
[node name="cook_timer" type="Timer" parent="."]
|
[node name="cook_timer" type="Timer" parent="."]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
@ -697,7 +697,7 @@ mesh = SubResource( 1 )
|
|||||||
skin = SubResource( 2 )
|
skin = SubResource( 2 )
|
||||||
|
|
||||||
[node name="head_bone" type="BoneAttachment" parent="model_transform/DungMan/Armature/Skeleton" index="1"]
|
[node name="head_bone" type="BoneAttachment" parent="model_transform/DungMan/Armature/Skeleton" index="1"]
|
||||||
transform = Transform( 1, -2.21502e-16, 1.62129e-17, -2.37146e-19, 0.0719347, 0.997409, -2.22095e-16, -0.997409, 0.0719347, -3.31708e-16, -0.0484204, -1.49945 )
|
transform = Transform( 1, -2.22045e-16, 5.12852e-23, 1.32349e-23, 2.83122e-07, 1, -2.22045e-16, -1, 2.83122e-07, -3.33067e-16, 5.21541e-08, -1.5 )
|
||||||
bone_name = "Item"
|
bone_name = "Item"
|
||||||
|
|
||||||
[node name="ItemSpawn" type="Spatial" parent="model_transform/DungMan/Armature/Skeleton/head_bone"]
|
[node name="ItemSpawn" type="Spatial" parent="model_transform/DungMan/Armature/Skeleton/head_bone"]
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
extends Spatial
|
extends Damageable
|
||||||
|
|
||||||
export var recipes: Resource
|
export var recipes: Resource
|
||||||
export var gen_time : float = 10.0
|
export var gen_time : float = 10.0
|
||||||
|
|
||||||
const StateIdle = preload("res://scripts/crafting_station/state/idle.gd")
|
enum EState {IDLE, WORKING, BLOCKED, BROKEN, NUM_STATES}
|
||||||
const StateWorking = preload("res://scripts/crafting_station/state/working.gd")
|
|
||||||
const StateBlocked = preload("res://scripts/crafting_station/state/blocked.gd")
|
const States = {
|
||||||
|
EState.IDLE : preload("res://scripts/crafting_station/state/idle.gd"),
|
||||||
|
EState.WORKING : preload("res://scripts/crafting_station/state/working.gd"),
|
||||||
|
EState.BLOCKED : preload("res://scripts/crafting_station/state/blocked.gd"),
|
||||||
|
EState.BROKEN : preload("res://scripts/crafting_station/state/broken.gd")
|
||||||
|
}
|
||||||
|
|
||||||
|
const RepairKit : Resource = preload("res://item_types/repair_kit.tres")
|
||||||
|
|
||||||
onready var item_holder = $"%item_holder"
|
onready var item_holder = $"%item_holder"
|
||||||
onready var coin_machine = $"%coin_machine"
|
onready var coin_machine = $"%coin_machine"
|
||||||
onready var gen_timer = $"%gen_timer"
|
onready var gen_timer = $"%gen_timer"
|
||||||
onready var progress_text = $"%progress_text"
|
onready var progress_text = $"%progress_text"
|
||||||
|
onready var item_dump = $"%item_dump"
|
||||||
|
onready var status_light = $"%status_light"
|
||||||
|
|
||||||
var item_slots = null
|
var item_slots = null
|
||||||
var state = null
|
var state = null
|
||||||
@ -25,19 +34,22 @@ func _ready():
|
|||||||
|
|
||||||
gen_timer.wait_time = gen_time
|
gen_timer.wait_time = gen_time
|
||||||
|
|
||||||
state = StateIdle.new()
|
state = States[EState.BROKEN].new() if start_broken else States[EState.IDLE].new()
|
||||||
state.ctx = self
|
state.ctx = self
|
||||||
state.enter_from(null)
|
state.enter_from(null)
|
||||||
print("crafting_station: NULL -> ", state.NAME)
|
print("crafting_station: NULL -> ", state.NAME)
|
||||||
|
|
||||||
|
if start_broken:
|
||||||
|
item_holder.spawn_item(RepairKit)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
state.update(delta)
|
state.update(delta)
|
||||||
|
|
||||||
func change_state(new_state, user_data = null):
|
func change_state(new_state):
|
||||||
print("crafting_station: ", state.NAME, " -> ", new_state.NAME)
|
print("crafting_station: ", state.NAME, " -> ", new_state.NAME)
|
||||||
new_state.ctx = self
|
new_state.ctx = self
|
||||||
state.exit_to(new_state)
|
state.exit_to(new_state)
|
||||||
new_state.enter_from(state, user_data)
|
new_state.enter_from(state)
|
||||||
state = new_state
|
state = new_state
|
||||||
|
|
||||||
func _on_coin_machine_coin_requirement_met(player):
|
func _on_coin_machine_coin_requirement_met(player):
|
||||||
@ -51,3 +63,11 @@ func _on_slot_item_changed(item):
|
|||||||
|
|
||||||
func _on_item_holder_item_changed(item):
|
func _on_item_holder_item_changed(item):
|
||||||
state.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)
|
||||||
|
if state != null:
|
||||||
|
state.on_damage_taken()
|
||||||
|
@ -3,17 +3,20 @@ extends Reference
|
|||||||
const NAME = "blocked"
|
const NAME = "blocked"
|
||||||
|
|
||||||
var ctx = null
|
var ctx = null
|
||||||
|
var label : String = "Blocked!"
|
||||||
|
|
||||||
func _init():
|
func _init(block_string : String):
|
||||||
pass
|
label = block_string
|
||||||
|
|
||||||
func enter_from(state, block_string = null):
|
func enter_from(state):
|
||||||
ctx.progress_text.text = block_string
|
ctx.progress_text.text = label
|
||||||
ctx.coin_machine.enabled = false
|
ctx.coin_machine.enabled = false
|
||||||
|
ctx.item_dump.enabled = false
|
||||||
ctx.item_holder.add_enabled = true
|
ctx.item_holder.add_enabled = true
|
||||||
for item_slot in ctx.item_slots:
|
for item_slot in ctx.item_slots:
|
||||||
item_slot.add_enabled = true
|
item_slot.add_enabled = true
|
||||||
item_slot.remove_enabled = true
|
item_slot.remove_enabled = true
|
||||||
|
ctx.status_light.warn()
|
||||||
|
|
||||||
func exit_to(state):
|
func exit_to(state):
|
||||||
pass
|
pass
|
||||||
@ -32,4 +35,11 @@ func on_slot_item_changed(item):
|
|||||||
|
|
||||||
func on_item_holder_item_changed(item):
|
func on_item_holder_item_changed(item):
|
||||||
if item == null:
|
if item == null:
|
||||||
ctx.change_state(ctx.StateIdle.new())
|
ctx.change_state(ctx.States[ctx.EState.IDLE].new())
|
||||||
|
|
||||||
|
func on_item_dump_item_dump_completed():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func on_damage_taken():
|
||||||
|
if ctx.current_hp <= 0:
|
||||||
|
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
|
||||||
|
46
scripts/crafting_station/state/broken.gd
Normal file
46
scripts/crafting_station/state/broken.gd
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
extends Reference
|
||||||
|
|
||||||
|
const NAME = "broken"
|
||||||
|
|
||||||
|
var ctx = null
|
||||||
|
|
||||||
|
func _init():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func enter_from(state):
|
||||||
|
ctx.coin_machine.enabled = false
|
||||||
|
ctx.item_dump.enabled = true
|
||||||
|
ctx.item_dump.reset()
|
||||||
|
ctx.item_holder.add_enabled = true
|
||||||
|
ctx.progress_text.text = "Broken"
|
||||||
|
for item_slot in ctx.item_slots:
|
||||||
|
item_slot.add_enabled = true
|
||||||
|
item_slot.remove_enabled = true
|
||||||
|
ctx.status_light.fail()
|
||||||
|
|
||||||
|
func exit_to(state):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func update(delta):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func on_coin_machine_coin_requirement_met(player):
|
||||||
|
assert(false)
|
||||||
|
|
||||||
|
func on_gen_timer_timeout():
|
||||||
|
assert(false)
|
||||||
|
|
||||||
|
func on_slot_item_changed(item):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func on_item_holder_item_changed(item):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func on_item_dump_item_dump_completed():
|
||||||
|
if ctx.item_holder.item_in_hold == null:
|
||||||
|
ctx.change_state(ctx.States[ctx.EState.IDLE].new())
|
||||||
|
else:
|
||||||
|
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Blocked!"))
|
||||||
|
|
||||||
|
func on_damage_taken():
|
||||||
|
assert(false, "cant take damage if already broken")
|
@ -8,11 +8,12 @@ var item_to_craft = null
|
|||||||
func _init():
|
func _init():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func enter_from(state, user_data = null):
|
func enter_from(state):
|
||||||
for item_slot in ctx.item_slots:
|
for item_slot in ctx.item_slots:
|
||||||
item_slot.add_enabled = true
|
item_slot.add_enabled = true
|
||||||
item_slot.remove_enabled = true
|
item_slot.remove_enabled = true
|
||||||
ctx.item_holder.add_enabled = true
|
ctx.item_holder.add_enabled = true
|
||||||
|
ctx.item_dump.enabled = false
|
||||||
ctx.progress_text.text = "Ready!"
|
ctx.progress_text.text = "Ready!"
|
||||||
update_coin_machine_status()
|
update_coin_machine_status()
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ func update(delta):
|
|||||||
func on_coin_machine_coin_requirement_met(player):
|
func on_coin_machine_coin_requirement_met(player):
|
||||||
item_to_craft = get_craft_recipe_item()
|
item_to_craft = get_craft_recipe_item()
|
||||||
assert(item_to_craft != null)
|
assert(item_to_craft != null)
|
||||||
ctx.change_state(ctx.StateWorking.new(), item_to_craft)
|
ctx.change_state(ctx.States[ctx.EState.WORKING].new(item_to_craft) )
|
||||||
|
|
||||||
func on_gen_timer_timeout():
|
func on_gen_timer_timeout():
|
||||||
assert(false, "gen timer shouldn't trigger while idle")
|
assert(false, "gen timer shouldn't trigger while idle")
|
||||||
@ -37,8 +38,15 @@ func on_slot_item_changed(item):
|
|||||||
func on_item_holder_item_changed(item):
|
func on_item_holder_item_changed(item):
|
||||||
# if target spot is occupied, go to blocked state
|
# if target spot is occupied, go to blocked state
|
||||||
if item != null:
|
if item != null:
|
||||||
ctx.change_state(ctx.StateBlocked.new(), "Blocked!")
|
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Blocked!"))
|
||||||
|
|
||||||
|
func on_item_dump_item_dump_completed():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func on_damage_taken():
|
||||||
|
if ctx.current_hp <= 0:
|
||||||
|
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
|
||||||
|
|
||||||
func get_craft_recipe_item():
|
func get_craft_recipe_item():
|
||||||
var items_in_slots = []
|
var items_in_slots = []
|
||||||
for item_slot in ctx.item_slots:
|
for item_slot in ctx.item_slots:
|
||||||
@ -49,4 +57,9 @@ func get_craft_recipe_item():
|
|||||||
return ctx.recipes.find_recipe(items_in_slots)
|
return ctx.recipes.find_recipe(items_in_slots)
|
||||||
|
|
||||||
func update_coin_machine_status():
|
func update_coin_machine_status():
|
||||||
ctx.coin_machine.enabled = get_craft_recipe_item() != null
|
var can_craft_recipe : bool = get_craft_recipe_item() != null
|
||||||
|
ctx.coin_machine.enabled = can_craft_recipe
|
||||||
|
if can_craft_recipe:
|
||||||
|
ctx.status_light.prime()
|
||||||
|
else:
|
||||||
|
ctx.status_light.idle()
|
||||||
|
@ -5,18 +5,19 @@ const NAME = "working"
|
|||||||
var ctx = null
|
var ctx = null
|
||||||
var crafting_item = null
|
var crafting_item = null
|
||||||
|
|
||||||
func _init():
|
func _init(item_to_craft : Resource):
|
||||||
pass
|
|
||||||
|
|
||||||
func enter_from(state, item_to_craft = null):
|
|
||||||
crafting_item = item_to_craft
|
crafting_item = item_to_craft
|
||||||
assert(crafting_item != null)
|
assert(crafting_item != null)
|
||||||
|
|
||||||
|
func enter_from(state):
|
||||||
ctx.coin_machine.enabled = false
|
ctx.coin_machine.enabled = false
|
||||||
|
ctx.item_dump.enabled = false
|
||||||
ctx.item_holder.add_enabled = false
|
ctx.item_holder.add_enabled = false
|
||||||
for item_slot in ctx.item_slots:
|
for item_slot in ctx.item_slots:
|
||||||
item_slot.add_enabled = false
|
item_slot.add_enabled = false
|
||||||
item_slot.remove_enabled = false
|
item_slot.remove_enabled = false
|
||||||
ctx.gen_timer.start()
|
ctx.gen_timer.start()
|
||||||
|
ctx.status_light.activate()
|
||||||
ctx.progress_text.text = "Progress: 0%"
|
ctx.progress_text.text = "Progress: 0%"
|
||||||
|
|
||||||
func exit_to(state):
|
func exit_to(state):
|
||||||
@ -31,15 +32,22 @@ func update(delta):
|
|||||||
func on_coin_machine_coin_requirement_met(player):
|
func on_coin_machine_coin_requirement_met(player):
|
||||||
assert(false, "coin machine should be disabled while crafting")
|
assert(false, "coin machine should be disabled while crafting")
|
||||||
|
|
||||||
|
func on_item_dump_item_dump_completed():
|
||||||
|
pass
|
||||||
|
|
||||||
func on_gen_timer_timeout():
|
func on_gen_timer_timeout():
|
||||||
for item_slot in ctx.item_slots:
|
for item_slot in ctx.item_slots:
|
||||||
if item_slot.has_item():
|
if item_slot.has_item():
|
||||||
item_slot.destroy_item()
|
item_slot.destroy_item()
|
||||||
ctx.item_holder.spawn_item(crafting_item)
|
ctx.item_holder.spawn_item(crafting_item)
|
||||||
ctx.change_state(ctx.StateBlocked.new(), "Finished: %s" % crafting_item.name)
|
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Finished: %s" % crafting_item.name))
|
||||||
|
|
||||||
func on_slot_item_changed(item):
|
func on_slot_item_changed(item):
|
||||||
assert(item == null, "slot items can only be destroyed at this point")
|
assert(item == null, "slot items can only be destroyed at this point")
|
||||||
|
|
||||||
func on_item_holder_item_changed(item):
|
func on_item_holder_item_changed(item):
|
||||||
assert(item.item_type == crafting_item, "only the crafted item can be added to the item holder")
|
assert(item.item_type == crafting_item, "only the crafted item can be added to the item holder")
|
||||||
|
|
||||||
|
func on_damage_taken():
|
||||||
|
if ctx.current_hp <= 0:
|
||||||
|
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
|
||||||
|
28
scripts/damageable_object.gd
Normal file
28
scripts/damageable_object.gd
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
extends Spatial
|
||||||
|
class_name Damageable
|
||||||
|
|
||||||
|
const GROUP_STRING : String = "damageable"
|
||||||
|
|
||||||
|
export var max_hp : int = 1
|
||||||
|
export var start_broken : bool = false
|
||||||
|
|
||||||
|
var current_hp : int = 1 setget set_hp
|
||||||
|
|
||||||
|
func _init():
|
||||||
|
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)
|
||||||
|
|
||||||
|
func set_hp(hp_to_set : int):
|
||||||
|
current_hp = clamp(hp_to_set,0,max_hp)
|
||||||
|
if current_hp == 0 and is_in_group(GROUP_STRING):
|
||||||
|
remove_from_group(GROUP_STRING)
|
||||||
|
if current_hp > 0 and !is_in_group(GROUP_STRING):
|
||||||
|
add_to_group(GROUP_STRING)
|
@ -16,7 +16,6 @@ func enter_from(state):
|
|||||||
ctx.get_node("%item_holder").remove_enabled = false
|
ctx.get_node("%item_holder").remove_enabled = false
|
||||||
|
|
||||||
ctx.get_node("cook_timer").start()
|
ctx.get_node("cook_timer").start()
|
||||||
ctx.get_node("status_light").light_color = Color.green
|
|
||||||
ctx.get_node("status_light").activate()
|
ctx.get_node("status_light").activate()
|
||||||
|
|
||||||
func exit_to(state):
|
func exit_to(state):
|
||||||
|
@ -12,7 +12,7 @@ func enter_from(state):
|
|||||||
ctx.get_node("coin_machine").enabled = false
|
ctx.get_node("coin_machine").enabled = false
|
||||||
ctx.get_node("%item_holder").add_enabled = true
|
ctx.get_node("%item_holder").add_enabled = true
|
||||||
ctx.get_node("%item_holder").remove_enabled = false # not possible
|
ctx.get_node("%item_holder").remove_enabled = false # not possible
|
||||||
ctx.get_node("status_light").light_color = Color.white
|
ctx.get_node("status_light").idle()
|
||||||
|
|
||||||
func exit_to(state):
|
func exit_to(state):
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user