2024-10-20 16:44:08 -06:00
|
|
|
# player class
|
|
|
|
class_name Player
|
|
|
|
extends VBoxContainer
|
|
|
|
|
|
|
|
|
|
|
|
var area_exp := 0.0
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
SignalBus.enemy_died.connect(_on_enemy_died)
|
|
|
|
SignalBus.quest_completed.connect(_on_quest_completed)
|
|
|
|
$PlayerExpBar.value = _get_level_progress_percent()
|
|
|
|
$PlayerLabel/PlayerLevel.text = str(floor(PlayerState.player_level))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_enemy_died(enemyDifficulty, enemyTier, _enemyFaction) -> void:
|
|
|
|
var kill_exp = pow(pow(enemyTier + 1, 3), enemyDifficulty)
|
|
|
|
area_exp += kill_exp
|
2024-10-21 06:44:52 -06:00
|
|
|
if Globals.debug:
|
|
|
|
print("T: ", enemyTier, " D: ", enemyDifficulty)
|
|
|
|
print("K: ", kill_exp)
|
|
|
|
print("A: ",area_exp)
|
2024-10-20 16:44:08 -06:00
|
|
|
# TODO: maybe show earned exp on bar, separate from current
|
|
|
|
# use xp to next level and current level, subtract, figure out percentage per point exp, add to display?
|
|
|
|
|
|
|
|
|
|
|
|
func _calculate_player_level() -> float:
|
|
|
|
var current_exp = PlayerState.player_exp
|
2024-10-21 06:44:52 -06:00
|
|
|
return log((0.2 * current_exp + 5)/5.0) + 1
|
2024-10-20 16:44:08 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _get_level_progress_percent() -> float:
|
|
|
|
var current_level = _calculate_player_level()
|
|
|
|
return fmod(current_level, 1) * 100.0
|
|
|
|
|
|
|
|
|
|
|
|
func _on_quest_completed() -> void:
|
|
|
|
PlayerState.player_exp += area_exp
|
|
|
|
PlayerState.player_level = _calculate_player_level()
|
|
|
|
$PlayerExpBar.value = _get_level_progress_percent()
|
|
|
|
$PlayerLabel/PlayerLevel.text = str(floor(PlayerState.player_level))
|
2024-10-21 06:44:52 -06:00
|
|
|
if Globals.debug:
|
|
|
|
print("FA: ", area_exp)
|
|
|
|
print("L: ", PlayerState.player_level)
|
|
|
|
print("XP: ", PlayerState.player_exp)
|
|
|
|
print("CL: ", _calculate_player_level())
|
|
|
|
print("LP: ", _get_level_progress_percent())
|
2024-10-20 16:44:08 -06:00
|
|
|
Engine.time_scale = 0.0001
|