fixed camera script and restructured ui folder
This commit is contained in:
parent
877ebafc74
commit
5748d34b34
32 changed files with 781 additions and 162 deletions
|
|
@ -1,10 +1,10 @@
|
|||
class_name MonsterData
|
||||
extends Resource
|
||||
|
||||
@export var unique_id : String = ""
|
||||
signal on_level_up
|
||||
|
||||
@export var display_name : String = ""
|
||||
@export var nickname: String = ""
|
||||
@export var unique_id : String = ""
|
||||
@export var name : String = ""
|
||||
@export var description: String = ""
|
||||
@export var thumbnail: CompressedTexture2D = preload("res://assets/logo/logo.png")
|
||||
@export var model: PackedScene
|
||||
|
|
@ -16,16 +16,18 @@ extends Resource
|
|||
@export var base_health: int = 1
|
||||
@export var base_defense: int = 1
|
||||
@export var base_tempo: int = 1
|
||||
@export var base_xp_for_next_level: int = 1
|
||||
@export var base_xp: int = 1
|
||||
|
||||
# Current Values
|
||||
var attack: int = 1
|
||||
var current_health: int = 1
|
||||
var health: int = 1
|
||||
var defense: int = 1
|
||||
var tempo: int = 1
|
||||
var level: int = 1
|
||||
var xp: int = 1
|
||||
@export var attack: int = 1
|
||||
@export var current_health: int = 1
|
||||
@export var health: int = 1
|
||||
@export var defense: int = 1
|
||||
@export var tempo: int = 1
|
||||
@export var level: int = 1
|
||||
@export var xp: int = 1
|
||||
@export var nickname: String = ""
|
||||
@export var xp_for_levelup: int = 1
|
||||
|
||||
|
||||
# The ID is the filename of the monster from res://entities/monsters/<filename>.tres
|
||||
|
|
@ -34,34 +36,70 @@ func set_data(p_unique_id = "", current_values: Dictionary = {}, p_level: int =
|
|||
printerr("Monster.gd: No ID given")
|
||||
return
|
||||
|
||||
# Get an instance of the base monster data form the MonsterDatabase
|
||||
var base_monster = load_base_monster_data(p_unique_id)
|
||||
# Get an instance of the base monster data
|
||||
var base_monster = Utils.load_base_monster_data(p_unique_id)
|
||||
|
||||
# set all the values here
|
||||
self.display_name = base_monster.display_name
|
||||
# Set the values
|
||||
self.name = base_monster.name
|
||||
self.description = base_monster.description
|
||||
self.thumbnail = base_monster.thumbnail
|
||||
self.model = base_monster.model
|
||||
self.primary_type = base_monster.primary_type
|
||||
self.secondary_type = base_monster.secondary_type
|
||||
|
||||
# Set base values
|
||||
self.base_attack = base_monster.base_attack
|
||||
self.base_health = base_monster.base_health
|
||||
self.base_defense = base_monster.base_defense
|
||||
self.base_tempo = base_monster.base_tempo
|
||||
self.base_xp_for_next_level = base_monster.base_xp_for_next_level
|
||||
self.level = p_level
|
||||
self.base_xp = base_monster.base_xp
|
||||
|
||||
# process custom and current values
|
||||
set_level(p_level)
|
||||
|
||||
# If there are not values to edit, return
|
||||
if current_values.is_empty():
|
||||
return
|
||||
|
||||
if current_values.has("nickname"):
|
||||
self.nickname = current_values.nickname
|
||||
|
||||
# else, set custom values here
|
||||
# TODO
|
||||
|
||||
func load_base_monster_data(p_unique_id):
|
||||
var path = "res://resources/monsters/" + p_unique_id + ".tres"
|
||||
if ResourceLoader.exists(path):
|
||||
var base_monster = load(path)
|
||||
return base_monster
|
||||
## This sets the monster to the specified level
|
||||
func set_level(p_level: int) -> void:
|
||||
self.level = p_level
|
||||
update()
|
||||
|
||||
# Updates the values according to the current level of the monster
|
||||
func update() -> void:
|
||||
self.attack = int((((base_attack * 2) * level ) / 100) + (level + 5))
|
||||
self.health = int((((base_health * 2) * level ) / 100) + (level + 5))
|
||||
self.defense = int((((base_defense * 2) * level ) / 100) + (level + 5))
|
||||
self.tempo = int((((base_tempo * 2) * level ) / 100) + (level + 5))
|
||||
self.xp_for_levelup = int(pow(level + 1, 3))
|
||||
|
||||
func level_up() -> void:
|
||||
set_level(level + 1)
|
||||
emit_signal("on_level_up")
|
||||
|
||||
func calculate_gained_xp(enemy_data: MonsterData) -> int:
|
||||
var calculated_xp: int = 0
|
||||
calculated_xp = int( (enemy_data.base_xp * enemy_data.level / 5) * ( float(enemy_data.level) / float(level) ) )
|
||||
return calculated_xp
|
||||
|
||||
func add_xp(amount: int = 0) -> void:
|
||||
xp += amount
|
||||
if(xp >= xp_for_levelup):
|
||||
level_up()
|
||||
|
||||
func attack_enemy(enemy_data: MonsterData) -> int:
|
||||
var damage: int = 0
|
||||
var base_damage: int = 2
|
||||
|
||||
printerr("Monster.gd: No monster with the ID %s found" % p_unique_id)
|
||||
damage = floor(floor((level * 2/5 + 2)) * base_damage * (float(attack) / (2 * enemy_data.defense)) + 2)
|
||||
|
||||
return damage
|
||||
|
||||
func take_damage(amount: int) -> void:
|
||||
current_health = max(current_health - amount, 0)
|
||||
|
||||
func heal(amount: int) -> void:
|
||||
current_health = min(current_health + amount, health)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue