adapted monster structure and save game
This commit is contained in:
parent
04873e3880
commit
aa4afc4c4b
22 changed files with 358 additions and 183 deletions
66
resources/monster_data.gd
Normal file
66
resources/monster_data.gd
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
class_name MonsterData
|
||||
extends Resource
|
||||
|
||||
@export var unique_id : String = ""
|
||||
|
||||
@export var display_name : String = ""
|
||||
@export var nickname: String = ""
|
||||
@export var description: String = ""
|
||||
@export var thumbnail: CompressedTexture2D = preload("res://assets/logo/logo.png")
|
||||
@export var model: PackedScene
|
||||
@export var primary_type: MonsterType.Type = MonsterType.Type.NORMAL
|
||||
@export var secondary_type: MonsterType.Type = MonsterType.Type.NONE
|
||||
|
||||
# Base Values
|
||||
@export var base_attack: int = 1
|
||||
@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
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# the ID is the filename of the monster from res://resources/monsters/<filename>.tres
|
||||
func set_data(p_unique_id = "", current_values: Dictionary = {}, p_level: int = 1) -> void:
|
||||
if p_unique_id.is_empty():
|
||||
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)
|
||||
|
||||
# set all the values here
|
||||
self.display_name = base_monster.display_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
|
||||
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
|
||||
|
||||
# process custom and current values
|
||||
if current_values.is_empty():
|
||||
return
|
||||
|
||||
if current_values.has("nickname"):
|
||||
self.nickname = current_values.nickname
|
||||
|
||||
func load_base_monster_data(p_unique_id):
|
||||
var path = "res://resources/monsters/" + p_unique_id + ".tres"
|
||||
if FileAccess.file_exists(path):
|
||||
var base_monster = load(path)
|
||||
return base_monster
|
||||
|
||||
printerr("Monster.gd: No monster with the ID %s found" % p_unique_id)
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
class_name MonsterStats
|
||||
extends Resource
|
||||
|
||||
@export var thumbnail: CompressedTexture2D = preload("res://assets/logo/logo.png")
|
||||
@export var name: String = "MISSINGNO"
|
||||
var spitzname: String = ""
|
||||
@export var level: int = 1
|
||||
@export var base_health: int = 100
|
||||
@export var base_attack: int = 10
|
||||
@export var base_defense: int = 10
|
||||
@export var base_speed: int = 10
|
||||
@export var base_experience_for_next_level: int = 50
|
||||
@export var model: PackedScene
|
||||
|
||||
var health: int
|
||||
var max_health: int
|
||||
var attack: int
|
||||
var defense: int
|
||||
var speed: int
|
||||
var experience: int
|
||||
var experience_for_next_level: int
|
||||
|
||||
func _init() -> void:
|
||||
max_health = roundi(base_health + 1.05 * level)
|
||||
health = max_health
|
||||
attack = base_attack
|
||||
defense = base_defense
|
||||
speed = base_speed
|
||||
experience = 0
|
||||
experience_for_next_level = roundi(base_experience_for_next_level + 1.10 * level)
|
||||
|
||||
func manual_init(p_name: String, p_level: int) -> void:
|
||||
print("TODO: Manual init")
|
||||
name = p_name
|
||||
level = p_level
|
||||
24
resources/monster_type.gd
Normal file
24
resources/monster_type.gd
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class_name MonsterType
|
||||
extends Resource
|
||||
|
||||
enum Type {
|
||||
NONE,
|
||||
NORMAL,
|
||||
FIRE,
|
||||
WATER,
|
||||
GRASS,
|
||||
FLYING,
|
||||
FIGHTING,
|
||||
POISON,
|
||||
ELECTRIC,
|
||||
GROUND,
|
||||
ROCK,
|
||||
PSYCHIC,
|
||||
ICE,
|
||||
BUG,
|
||||
GHOST,
|
||||
STEEL,
|
||||
DRAGON,
|
||||
DARK,
|
||||
FAIRY
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="MonsterStats" load_steps=4 format=3 uid="uid://ym438vedcdyl"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://h2we7rb772hy" path="res://assets/models/round_bat/model/bat.glb" id="1_ajl37"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_8r754"]
|
||||
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="2_ec3n5"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_ec3n5")
|
||||
thumbnail = ExtResource("2_8r754")
|
||||
name = "Debug Monster 1"
|
||||
health = 110
|
||||
attack_value = 12
|
||||
defense_value = 15
|
||||
speed_value = 8
|
||||
model = ExtResource("1_ajl37")
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="MonsterStats" load_steps=3 format=3 uid="uid://br8opay3hdptg"]
|
||||
|
||||
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="1_saexp"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_3x4e0"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_saexp")
|
||||
health = 100
|
||||
thumbnail = ExtResource("2_3x4e0")
|
||||
name = "Debug Monster 2"
|
||||
attack_value = 10
|
||||
defense_value = 10
|
||||
speed_value = 10
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="MonsterStats" load_steps=3 format=3 uid="uid://y250cwuiq5y"]
|
||||
|
||||
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="1_eka2r"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_b7c7s"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_eka2r")
|
||||
thumbnail = ExtResource("2_b7c7s")
|
||||
name = "Debug Monster 3"
|
||||
health = 120
|
||||
attack_value = 13
|
||||
defense_value = 18
|
||||
speed_value = 30
|
||||
21
resources/monsters/debuggy.tres
Normal file
21
resources/monsters/debuggy.tres
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[gd_resource type="Resource" script_class="MonsterData" load_steps=4 format=3 uid="uid://0xqaef8uftnv"]
|
||||
|
||||
[ext_resource type="Script" path="res://resources/monster_data.gd" id="1_2n3ph"]
|
||||
[ext_resource type="PackedScene" uid="uid://h2we7rb772hy" path="res://assets/models/round_bat/model/bat.glb" id="1_dsg0f"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_a4t2w"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_2n3ph")
|
||||
unique_id = "debuggy"
|
||||
display_name = "Debuggy"
|
||||
nickname = "Debuggy"
|
||||
description = "A debug monster"
|
||||
thumbnail = ExtResource("2_a4t2w")
|
||||
model = ExtResource("1_dsg0f")
|
||||
primary_type = 5
|
||||
secondary_type = 17
|
||||
base_attack = 10
|
||||
base_health = 20
|
||||
base_defense = 30
|
||||
base_tempo = 40
|
||||
base_xp_for_next_level = 50
|
||||
24
resources/save_data.gd
Normal file
24
resources/save_data.gd
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class_name SaveData
|
||||
extends Resource
|
||||
|
||||
# Player data
|
||||
var player_name: String = "Player"
|
||||
var money: int = 0
|
||||
|
||||
# Inventory data
|
||||
|
||||
func _init() -> void:
|
||||
set_name("SaveData")
|
||||
|
||||
func save():
|
||||
var player_data = {
|
||||
"player_name": player_name,
|
||||
"money": money
|
||||
}
|
||||
|
||||
# Collect all data to save in one dictionary
|
||||
var save_dict = {
|
||||
"player_data": player_data
|
||||
}
|
||||
|
||||
return save_dict
|
||||
Loading…
Add table
Add a link
Reference in a new issue