71 lines
1.6 KiB
GDScript
71 lines
1.6 KiB
GDScript
class_name Entity extends Node3D
|
|
|
|
|
|
var stats: EntityStats
|
|
var equipments: Array[Equipment]
|
|
signal died_event(entity: Entity)
|
|
|
|
func init_entity(stats: EntityStats):
|
|
self.stats = stats;
|
|
|
|
func equip(newEquipment: Equipment)-> void:
|
|
equipments.append(newEquipment)
|
|
|
|
func unequip(equipmentToRemove: Equipment)-> void:
|
|
equipments.erase(equipmentToRemove)
|
|
|
|
|
|
func get_health()->int:
|
|
return stats.health.value
|
|
|
|
func get_shield()->int:
|
|
return stats.shield.value
|
|
|
|
func reduce_shield(damage: int):
|
|
stats.shield.value -= damage
|
|
if stats.shield.value <= 0:
|
|
stats.shield.value = 0
|
|
|
|
func increase_health(additional_health: int):
|
|
stats.health.value += additional_health
|
|
if stats.health.value > get_max_health():
|
|
stats.health.value = get_max_health()
|
|
|
|
func reduce_health(damage: int):
|
|
stats.health.value -= damage
|
|
if stats.health.value <= 0:
|
|
died()
|
|
|
|
func died():
|
|
died_event.emit(self)
|
|
|
|
func get_max_health()->int:
|
|
var max_health = stats.max_health
|
|
for equipment in equipments:
|
|
max_health += equipment.get_max_health()
|
|
return max_health
|
|
|
|
func get_armor()->int:
|
|
var armor = stats.armor
|
|
for equipment in equipments:
|
|
armor += equipment.get_armor()
|
|
return armor
|
|
|
|
func get_max_Shield()->int:
|
|
var shield = stats.shield
|
|
for equipment in equipments:
|
|
shield += equipment.get_max_shield()
|
|
return shield
|
|
|
|
func get_movement_speed()->int:
|
|
var movement_speed = stats.movement_speed
|
|
for equipment in equipments:
|
|
movement_speed += equipment.get_evement_speed()
|
|
return movement_speed
|
|
|
|
func get_damage()->int:
|
|
var damage = 0
|
|
for equipment in equipments:
|
|
damage += equipment.get_damage()
|
|
return damage
|