From d916e659909515d1f1a24c82dce492e1475eacfc Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 14 Jan 2026 21:54:38 -0600 Subject: [PATCH] Add battle stuff --- battle/Battle.gd | 7 ++++-- battle/fighter/BattleFighter.gd | 10 ++++---- .../battle}/BattleAction.gd.uid | 0 .../battle}/BattleCutsceneAction.gd | 0 .../battle}/BattleCutsceneAction.gd.uid | 0 cutscene/battle/BattleStartAction.gd | 16 +++++++++++++ cutscene/battle/BattleStartAction.gd.uid | 1 + overworld/entity/Entity.gd | 11 +++++++++ overworld/entity/EntityInteractableArea.gd | 23 +++++++++++++++---- overworld/entity/EntityMovement.gd | 2 +- overworld/map/TestMap.tscn | 7 ++++++ scene/RootScene.gd | 18 +++++++-------- util/UUID.gd | 23 +++++++++++++++++++ util/UUID.gd.uid | 1 + 14 files changed, 99 insertions(+), 20 deletions(-) rename {battle/cutscene => cutscene/battle}/BattleAction.gd.uid (100%) rename {battle/cutscene => cutscene/battle}/BattleCutsceneAction.gd (100%) rename {battle/cutscene => cutscene/battle}/BattleCutsceneAction.gd.uid (100%) create mode 100644 cutscene/battle/BattleStartAction.gd create mode 100644 cutscene/battle/BattleStartAction.gd.uid create mode 100644 util/UUID.gd create mode 100644 util/UUID.gd.uid diff --git a/battle/Battle.gd b/battle/Battle.gd index 3d915d3..3863279 100644 --- a/battle/Battle.gd +++ b/battle/Battle.gd @@ -1,5 +1,5 @@ class_name BattleSingleton extends Node -const BattleCutsceneAction = preload("res://battle/cutscene/BattleCutsceneAction.gd") +const BattleCutsceneAction = preload("res://cutscene/battle/BattleCutsceneAction.gd") enum BattlePosition { LEFT_TOP_BACK, @@ -34,7 +34,10 @@ func startBattle(params) -> void: assert(!active) # Get the cutscene (or create a default one). - battleCutscene = params.get('cutscene', Cutscene.new()) + if params.has('cutscene'): + battleCutscene = params['cutscene'] + else: + battleCutscene = Cutscene.new() # Update fighters for each fighter scene. for pos in BattlePosition.values(): diff --git a/battle/fighter/BattleFighter.gd b/battle/fighter/BattleFighter.gd index ebbe43f..cedc900 100644 --- a/battle/fighter/BattleFighter.gd +++ b/battle/fighter/BattleFighter.gd @@ -37,8 +37,8 @@ var luck:int # Moves var movePrimary:BattleMove -var movesMagical:Array[BattleMove] = [] -var movesAbility:Array[BattleMove] = [] +var movesMagical:Array[BattleMove] +var movesAbility:Array[BattleMove] # Signals signal healthChanged(difference:int, crit:bool) @@ -56,8 +56,10 @@ func _init(params:Dictionary) -> void: self.team = params.get('team', FighterTeam.ENEMY) self.controller = params.get('controller', FighterController.PLAYER) self.movePrimary = params.get('movePrimary', null) - self.movesMagical = params.get('movesMagical', []) - self.movesAbility = params.get('movesAbility', []) + if params.has('movesMagical'): + movesMagical.append_array(params['movesMagical']) + if params.has('movesAbility'): + movesAbility.append_array(params['movesAbility']) self.health = self.maxHealth self.mp = self.maxMp diff --git a/battle/cutscene/BattleAction.gd.uid b/cutscene/battle/BattleAction.gd.uid similarity index 100% rename from battle/cutscene/BattleAction.gd.uid rename to cutscene/battle/BattleAction.gd.uid diff --git a/battle/cutscene/BattleCutsceneAction.gd b/cutscene/battle/BattleCutsceneAction.gd similarity index 100% rename from battle/cutscene/BattleCutsceneAction.gd rename to cutscene/battle/BattleCutsceneAction.gd diff --git a/battle/cutscene/BattleCutsceneAction.gd.uid b/cutscene/battle/BattleCutsceneAction.gd.uid similarity index 100% rename from battle/cutscene/BattleCutsceneAction.gd.uid rename to cutscene/battle/BattleCutsceneAction.gd.uid diff --git a/cutscene/battle/BattleStartAction.gd b/cutscene/battle/BattleStartAction.gd new file mode 100644 index 0000000..acbc737 --- /dev/null +++ b/cutscene/battle/BattleStartAction.gd @@ -0,0 +1,16 @@ +class_name BattleStartAction + +static func startBattleCallable(params:Dictionary) -> int: + assert(params.has('fighters')) + SCENE.setScene(SceneSingleton.SceneType.BATTLE) + BATTLE.startBattle({ + 'fighters': params['fighters'], + 'cutscene': params['cutscene'] + }) + return Cutscene.CUTSCENE_CONTINUE + +static func getStartBattleCallable(fighters:Dictionary) -> Dictionary: + return { + "function": startBattleCallable, + "fighters": fighters + } \ No newline at end of file diff --git a/cutscene/battle/BattleStartAction.gd.uid b/cutscene/battle/BattleStartAction.gd.uid new file mode 100644 index 0000000..783f75b --- /dev/null +++ b/cutscene/battle/BattleStartAction.gd.uid @@ -0,0 +1 @@ +uid://csas8dhfiv12o diff --git a/overworld/entity/Entity.gd b/overworld/entity/Entity.gd index b5536e1..9da524c 100644 --- a/overworld/entity/Entity.gd +++ b/overworld/entity/Entity.gd @@ -1,4 +1,6 @@ +@tool class_name Entity extends CharacterBody3D +const UUID = preload("res://util/UUID.gd") enum MovementType { NONE, @@ -9,8 +11,14 @@ enum MovementType { enum InteractType { NONE, CONVERSATION, + TEST_BATTLE }; +@export_category("Identification") +@export var entityId:String = UUID.uuidv4() +@export_tool_button("Regenerate ID") +var button := func(): + entityId = UUID.uuidv4() # Movement settings @export_category("Movement") @@ -20,3 +28,6 @@ enum InteractType { @export_category("Interactions") @export var interactType:InteractType = InteractType.NONE @export var conversation:Array[ConversationElement] = [] + +# TEST BATTLE +@export_category("Test Battle") diff --git a/overworld/entity/EntityInteractableArea.gd b/overworld/entity/EntityInteractableArea.gd index 3073d98..be374f1 100644 --- a/overworld/entity/EntityInteractableArea.gd +++ b/overworld/entity/EntityInteractableArea.gd @@ -1,4 +1,5 @@ class_name EntityInteractableArea extends Area3D +# const BattleStartAction = preload("res://cutscene/battle/BattleStartAction.gd") @export var entity:Entity @@ -10,13 +11,18 @@ func isInteractable() -> bool: return false if entity.interactType == Entity.InteractType.CONVERSATION: - if entity.conversation.size() == 0: - return false + if entity.conversation.size() != 0: + return true + + if entity.interactType == Entity.InteractType.TEST_BATTLE: + return true - return true + return false func _onConversationInteract(_other:Entity) -> void: - CUTSCENE.setConversation(entity.conversation) + var cutscene:Cutscene = Cutscene.new() + cutscene.addConversation(entity.conversation) + cutscene.start() func onInteract(other:Entity) -> void: if entity.interactType == Entity.InteractType.NONE: @@ -26,5 +32,14 @@ func onInteract(other:Entity) -> void: Entity.InteractType.CONVERSATION: _onConversationInteract(other) return + + Entity.InteractType.TEST_BATTLE: + var cutscene:Cutscene = Cutscene.new() + cutscene.addCallable(BattleStartAction.getStartBattleCallable({ + BATTLE.BattlePosition.RIGHT_TOP_FRONT: PartySingleton.PARTY_JOHN, + })) + cutscene.start() + return + _: pass diff --git a/overworld/entity/EntityMovement.gd b/overworld/entity/EntityMovement.gd index 3692d32..ff9282f 100644 --- a/overworld/entity/EntityMovement.gd +++ b/overworld/entity/EntityMovement.gd @@ -82,4 +82,4 @@ func _physics_process(delta:float) -> void: _applyGravity() _applyFriction(delta) _applyMovement(delta) - entity.move_and_slide() \ No newline at end of file + entity.move_and_slide() diff --git a/overworld/map/TestMap.tscn b/overworld/map/TestMap.tscn index 248b936..a5c816f 100644 --- a/overworld/map/TestMap.tscn +++ b/overworld/map/TestMap.tscn @@ -16,13 +16,20 @@ script = ExtResource("1_6ms5s") [node name="NotPlayer" parent="." instance=ExtResource("2_jmygs")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00883961, 1.11219, 0.0142021) +entityId = "bcabec96-8d33-4c16-a997-3bb3b0562b33" interactType = 1 conversation = Array[ExtResource("3_p7git")]([SubResource("Resource_p7git")]) +[node name="NotPlayer2" parent="." instance=ExtResource("2_jmygs")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00883961, 1.11219, 4.34543) +entityId = "ad5a1504-7fbf-45d6-b1bf-6e7af6314066" +interactType = 2 + [node name="TestMapBase" parent="." instance=ExtResource("1_ox0si")] [node name="Player" parent="." instance=ExtResource("2_jmygs")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.1915, 1.05, 0.125589) +entityId = "player" movementType = 2 [node name="Camera3D" type="Camera3D" parent="."] diff --git a/scene/RootScene.gd b/scene/RootScene.gd index e637740..e78b68d 100644 --- a/scene/RootScene.gd +++ b/scene/RootScene.gd @@ -8,16 +8,16 @@ class_name RootScene extends Node3D func _enter_tree() -> void: SCENE.sceneChanged.connect(onSceneChange) - # SCENE.setScene(SceneSingleton.SceneType.INITIAL) + SCENE.setScene(SceneSingleton.SceneType.INITIAL) - SCENE.setScene(SceneSingleton.SceneType.BATTLE) - # Wait a frame - await get_tree().process_frame - BATTLE.startBattle({ - 'fighters': { - BATTLE.BattlePosition.RIGHT_TOP_FRONT: PartySingleton.PARTY_JOHN, - } - }) + # SCENE.setScene(SceneSingleton.SceneType.BATTLE) + # # Wait a frame + # await get_tree().process_frame + # BATTLE.startBattle({ + # 'fighters': { + # BATTLE.BattlePosition.RIGHT_TOP_FRONT: PartySingleton.PARTY_JOHN, + # } + # }) func _exit_tree() -> void: push_error("RootScene should not be removed from the scene tree. This is a bug.") diff --git a/util/UUID.gd b/util/UUID.gd new file mode 100644 index 0000000..f8e5b8b --- /dev/null +++ b/util/UUID.gd @@ -0,0 +1,23 @@ +static func uuidv4() -> String: + var random = RandomNumberGenerator.new() + random.randomize() + var bytes = PackedByteArray() + for i in range(16): + bytes.append(random.randi_range(0, 255)) + + # Set the version to 4 -- random + bytes[6] = (bytes[6] & 0x0F) | 0x40 + # Set the variant to RFC 4122 + bytes[8] = (bytes[8] & 0x3F) | 0x80 + + var hex_parts = [] + for byte in bytes: + hex_parts.append(String("%02x" % byte)) + + return "%s%s%s%s-%s%s-%s%s-%s%s-%s%s%s%s%s%s" % [ + hex_parts[0], hex_parts[1], hex_parts[2], hex_parts[3], + hex_parts[4], hex_parts[5], + hex_parts[6], hex_parts[7], + hex_parts[8], hex_parts[9], + hex_parts[10], hex_parts[11], hex_parts[12], hex_parts[13], hex_parts[14], hex_parts[15] + ] \ No newline at end of file diff --git a/util/UUID.gd.uid b/util/UUID.gd.uid new file mode 100644 index 0000000..e58c875 --- /dev/null +++ b/util/UUID.gd.uid @@ -0,0 +1 @@ +uid://6jmaeuba1s1f