fixes saving of party monsters, adds display of monster stats in battle ui

This commit is contained in:
Luca 2024-09-29 11:10:46 +02:00
parent 5748d34b34
commit b09eee0805
9 changed files with 201 additions and 61 deletions

View file

@ -2,9 +2,13 @@ extends CharacterBody3D
@onready var animated_mesh = $GobotSkin
var in_battle: bool = false
var enemy: MonsterData = null
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
func _ready() -> void:
Utils.set_player(self)
func on_save_game(saved_data : Array[SavedData]):
var data = SavedData.new()
data.position = global_position
@ -17,6 +21,9 @@ func on_before_load_game():
func on_load_game(saved_data: SavedData):
global_position = saved_data.position
# Update the global reference to the player
Utils.set_player(self)
func _physics_process(delta: float) -> void:
if in_battle == true:
@ -76,29 +83,37 @@ func _physics_process(delta: float) -> void:
# the player is positioned (mostly somewhere else than the current position)
# ui changes
# music changes
func start_battle(enemy: Node3D, player_position: Vector3) -> void:
position = Vector3(player_position.x, position.y, player_position.z)
func start_battle(p_enemy: Node3D) -> void:
enemy = p_enemy.data
var camera: Camera3D = $CameraRoot/SpringArm3D/Camera3D
# local z axis of the camera
var local_z = camera.global_transform.basis.z
var new_player_position = camera.global_transform.origin + local_z * 3
var monster_position = camera.global_transform.origin + local_z * 2
position = Vector3(new_player_position.x, position.y, new_player_position.z)
in_battle = true
velocity = Vector3.ZERO
animated_mesh.idle()
UI.show_battle_ui(true)
UI.show_ingame_controls(false)
# Spawn player monster
var monster_data : MonsterData = SaveManager.current_save.party[0]
var monster = Monster.new()
monster.data = monster_data
monster.idle = true
print("%s (%s), Lv. %s, %s XP" % [monster.data.name, monster.data.nickname, monster.data.level, monster.data.xp])
monster.position = Vector3(monster_position.x, position.y + 1, monster_position.z)
add_child(monster)
camera.look_at(monster.position, Vector3.UP, false)
# How to attack and finish the battle?
await get_tree().create_timer(2.0).timeout
await get_tree().create_timer(5.0).timeout
print("Battle over")
remove_child(monster)
monster.queue_free()
in_battle = false
func save() -> Dictionary:
var save_dict = {
"player_transform": {
"pos_x": global_position.x,
"pos_y": global_position.y,
"pos_z": global_position.z,
"rot_x": global_rotation.x,
"rot_y": global_rotation.y,
"rot_z": global_rotation.z
}
}
return save_dict