Add battle stuff
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -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
|
||||
|
||||
16
cutscene/battle/BattleStartAction.gd
Normal file
16
cutscene/battle/BattleStartAction.gd
Normal file
@@ -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
|
||||
}
|
||||
1
cutscene/battle/BattleStartAction.gd.uid
Normal file
1
cutscene/battle/BattleStartAction.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://csas8dhfiv12o
|
||||
@@ -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")
|
||||
|
||||
@@ -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 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
|
||||
|
||||
@@ -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="."]
|
||||
|
||||
@@ -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.")
|
||||
|
||||
23
util/UUID.gd
Normal file
23
util/UUID.gd
Normal file
@@ -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]
|
||||
]
|
||||
1
util/UUID.gd.uid
Normal file
1
util/UUID.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://6jmaeuba1s1f
|
||||
Reference in New Issue
Block a user