Crafting v2
This commit is contained in:
@@ -14,6 +14,10 @@ signal loot_chest_spawned(chest_data: Dictionary)
|
||||
signal loot_chest_state_received(chest_data: Dictionary)
|
||||
signal death_loot_lost(data: Dictionary)
|
||||
signal dungeon_list_received(data: Dictionary)
|
||||
signal crafting_skills_updated(skills: Dictionary)
|
||||
signal crafting_recipes_updated(recipes: Array)
|
||||
signal crafting_result_received(result: Dictionary)
|
||||
signal recipe_discovered(recipe: Dictionary)
|
||||
|
||||
# Use constants instead of enum to avoid type issues
|
||||
const STATE_AUTH = 0
|
||||
@@ -138,6 +142,16 @@ func _on_message_received(opcode: int, data: Dictionary):
|
||||
_handle_dungeon_list(data)
|
||||
OpCodes.ASSET_MANIFEST_RESPONSE:
|
||||
_handle_asset_manifest(data)
|
||||
OpCodes.CRAFTING_SKILLS_STATE:
|
||||
_handle_crafting_skills(data)
|
||||
OpCodes.CRAFTING_RECIPES_STATE:
|
||||
_handle_crafting_recipes(data)
|
||||
OpCodes.CRAFTING_RESULT:
|
||||
_handle_crafting_result(data)
|
||||
OpCodes.RECIPE_DISCOVERED:
|
||||
_handle_recipe_discovered(data)
|
||||
OpCodes.CRAFTING_SKILL_LEVELUP:
|
||||
_handle_crafting_skill_levelup(data)
|
||||
_:
|
||||
print("[GameState] Unhandled opcode: ", opcode)
|
||||
|
||||
@@ -534,3 +548,64 @@ func create_dungeon(tier: int):
|
||||
|
||||
func join_dungeon(dungeon_id: String):
|
||||
Network.send_message(OpCodes.DUNGEON_JOIN, {"DungeonId": dungeon_id})
|
||||
|
||||
# ===== CRAFTING SYSTEM =====
|
||||
|
||||
var crafting_skills: Dictionary = {} # skillType -> {level, xp, xpForNext}
|
||||
var known_recipes: Array = []
|
||||
|
||||
func _handle_crafting_skills(data: Dictionary):
|
||||
print("[GameState] Received crafting skills")
|
||||
crafting_skills = data.get("skills", {})
|
||||
crafting_skills_updated.emit(crafting_skills)
|
||||
|
||||
func _handle_crafting_recipes(data: Dictionary):
|
||||
print("[GameState] Received crafting recipes")
|
||||
known_recipes = data.get("recipes", [])
|
||||
crafting_recipes_updated.emit(known_recipes)
|
||||
|
||||
func _handle_crafting_result(data: Dictionary):
|
||||
print("[GameState] Received crafting result: %s" % str(data))
|
||||
crafting_result_received.emit(data)
|
||||
|
||||
# Refresh inventory if successful
|
||||
if data.get("success", false):
|
||||
request_inventory()
|
||||
|
||||
func _handle_recipe_discovered(data: Dictionary):
|
||||
print("[GameState] Discovered new recipe: %s" % data.get("name", "Unknown"))
|
||||
recipe_discovered.emit(data)
|
||||
# Refresh recipes
|
||||
request_crafting_recipes()
|
||||
|
||||
func _handle_crafting_skill_levelup(data: Dictionary):
|
||||
print("[GameState] Crafting skill level up: %s to level %d" % [
|
||||
data.get("skillName", "Unknown"),
|
||||
data.get("newLevel", 1)
|
||||
])
|
||||
# Refresh skills
|
||||
request_crafting_skills()
|
||||
|
||||
func request_crafting_skills():
|
||||
Network.send_message(OpCodes.CRAFTING_SKILLS_REQUEST, {})
|
||||
|
||||
func request_crafting_recipes():
|
||||
Network.send_message(OpCodes.CRAFTING_RECIPES_REQUEST, {})
|
||||
|
||||
func request_inventory():
|
||||
Network.send_message(OpCodes.INVENTORY_REQUEST, {})
|
||||
|
||||
func send_craft_request(recipe_id: int):
|
||||
Network.send_message(OpCodes.CRAFTING_ATTEMPT, {"RecipeId": recipe_id})
|
||||
|
||||
func send_discover_recipe(ingredients: Array):
|
||||
# ingredients is an array of {itemDefinitionId, quantity}
|
||||
Network.send_message(OpCodes.CRAFTING_ATTEMPT, {"Ingredients": ingredients, "Discover": true})
|
||||
|
||||
func send_discover_recipe_with_skill(ingredients: Array, skill_type: int):
|
||||
# Discovery with specific skill type
|
||||
Network.send_message(OpCodes.CRAFTING_ATTEMPT, {
|
||||
"Ingredients": ingredients,
|
||||
"Discover": true,
|
||||
"SkillType": skill_type
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user