-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
309cf31
commit e729aaf
Showing
5 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
extends Area2D | ||
class_name Anvil | ||
|
||
# Define the states of this block | ||
enum AnvilState { | ||
IDLE, | ||
SMITHING, | ||
SMITHED | ||
} | ||
|
||
@export var flip_horizontally: bool = false | ||
|
||
@onready var collision: CollisionPolygon2D = get_node("CollisionShape") | ||
# In the future these two will be merged into a single animatedsprite2d | ||
@onready var sprite: Sprite2D = get_node("Sprite") | ||
@onready var animation: AnimatedSprite2D = get_node("Animation") | ||
@onready var toast: Node2D = get_node("InventoryToast") | ||
|
||
var type: Enums.StationType = Enums.StationType.FURNACE | ||
var inventory: PackedStringArray = PackedStringArray([]) | ||
var max_size: int = 1 | ||
var recipes: Array[Recipe] = [] | ||
var state: AnvilState = AnvilState.IDLE | ||
|
||
var allowed_items: RegEx = RegEx.new(); | ||
|
||
func interact(player: Blacksmith, input: StringName) -> bool: | ||
match input: | ||
&"interaction": | ||
match state: | ||
AnvilState.IDLE: | ||
if player.heldItem == null: | ||
if !is_empty(): | ||
var item = remove_first_item() | ||
player.equip_item(item) | ||
return true | ||
else: | ||
if inventory.size() == max_size: | ||
return false | ||
|
||
var item = player.heldItem.get_groups()[0] | ||
|
||
if allowed_items.search(item).strings.size() == 0: | ||
return false | ||
|
||
if !Array(inventory).all(func(r): return r == item): | ||
return false | ||
|
||
add_item(item) | ||
player.unequip_item() | ||
state = AnvilState.SMITHING | ||
|
||
var recipe = find_recipe() | ||
if recipe != null: | ||
print("Starting Smithing") | ||
player.immobile = true | ||
await get_tree().create_timer(5).timeout | ||
print("Finished Smithing") | ||
player.immobile = false | ||
state = AnvilState.SMITHED | ||
return true | ||
AnvilState.SMITHED: | ||
var recipe = find_recipe() | ||
if recipe != null: | ||
var item = recipe.product | ||
inventory = [] | ||
player.equip_item(item) | ||
return true | ||
return false | ||
|
||
func add_item(item: StringName) -> void: | ||
inventory.append(item) | ||
toast.add_material(item) | ||
|
||
func remove_item() -> StringName: | ||
return &"HELLO" | ||
pass | ||
|
||
func remove_first_item() -> StringName: | ||
var item = inventory[0] | ||
inventory = inventory.slice(1) | ||
update_toast() | ||
return item | ||
|
||
func update_toast(): | ||
toast.clear() | ||
for item in inventory: | ||
toast.add_material(item) | ||
|
||
func is_empty(): | ||
return inventory.size() == 0 | ||
|
||
func find_recipe() -> Recipe: | ||
for recipe in recipes: | ||
if recipe.ingredients == inventory: | ||
return recipe | ||
return null | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
if flip_horizontally: | ||
flip_station() | ||
|
||
allowed_items.compile("chunk$") | ||
|
||
var recipe = Recipe.new() | ||
recipe.add_ingredient(&"bronze_shield_chunk") | ||
recipe.product = &"bronze_shield" | ||
|
||
recipes.append(recipe) | ||
|
||
func flip_station(): | ||
var collision = get_node("CollisionShape") | ||
collision.scale.x = collision.scale.x * -1 | ||
sprite.flip_h = true | ||
animation.flip_h = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[gd_scene load_steps=4 format=3 uid="uid://tjdkpgoqr6lw"] | ||
|
||
[ext_resource type="Script" path="res://nodes/wip/Anvils/Anvil.gd" id="1_37r6u"] | ||
[ext_resource type="Texture2D" uid="uid://d2icifub1b3j1" path="res://art/anvil.png" id="2_qnqcg"] | ||
[ext_resource type="PackedScene" uid="uid://dpsr055c1v16j" path="res://nodes/ui/MaterialToast.tscn" id="3_vsw8d"] | ||
|
||
[node name="Anvil" type="Area2D" groups=["anvil", "interactable"]] | ||
z_index = 1 | ||
collision_layer = 2 | ||
collision_mask = 2 | ||
script = ExtResource("1_37r6u") | ||
|
||
[node name="CollisionShape" type="CollisionPolygon2D" parent="."] | ||
polygon = PackedVector2Array(6, 0, 20, -6, 19, -22, -9, -36, -20, -30, -19, -11) | ||
|
||
[node name="Sprite" type="Sprite2D" parent="."] | ||
texture_filter = 1 | ||
position = Vector2(0, -17.5) | ||
texture = ExtResource("2_qnqcg") | ||
region_enabled = true | ||
region_rect = Rect2(0, 29, 39, 35) | ||
|
||
[node name="Animation" type="AnimatedSprite2D" parent="."] | ||
|
||
[node name="InventoryToast" parent="." instance=ExtResource("3_vsw8d")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters