* Changement de l'UI, ajouts de l'inspecteur par carte et changement de police * Ajout d'un semblant d'exploration * Ajout de la sauvegarde des entités * Restructuration mineure de l'arborescence * Fix divers et réécriture des textes
99 lines
2.4 KiB
GDScript
99 lines
2.4 KiB
GDScript
extends Resource
|
|
class_name PlantMutation
|
|
|
|
const BASE_RARITY_CHANCE : Array[float] = [
|
|
0.75,
|
|
0.9,
|
|
1,
|
|
1,
|
|
]
|
|
|
|
@export var level : int = 1
|
|
|
|
func _init(_level : int = 1):
|
|
level = _level
|
|
|
|
func get_icon() -> Texture:
|
|
return preload("res://common/icons/dna.svg")
|
|
|
|
func get_base_rarity() -> int:
|
|
return 0
|
|
|
|
func get_mutation_name() -> String:
|
|
printerr("Classe abstraite PlantMutation appelée")
|
|
return ""
|
|
|
|
func get_mutation_description() -> String:
|
|
printerr("Classe abstraite PlantMutation appelée")
|
|
return ""
|
|
|
|
func mutate_score(_plant_state : Plant.State, _plant : Plant, score,) -> int:
|
|
return score
|
|
|
|
func mutate_grow_time(_plant : Plant, grow_time : int) -> int:
|
|
return grow_time
|
|
|
|
func mutate_plant(_plant : Plant):
|
|
pass
|
|
|
|
func get_level_for_rarity(rarity : int) -> int :
|
|
return rarity - get_base_rarity() + 1
|
|
|
|
func get_rarity() -> int:
|
|
return get_base_rarity() + level - 1
|
|
|
|
func card_section() -> CardSectionInfo:
|
|
var section = CardSectionInfo.new(
|
|
get_mutation_name() + (" %d" % level if level > 1 else ""),
|
|
"[b]%s[/b] %s" % [PlantMutation.get_rarity_text(get_rarity()), get_mutation_description()]
|
|
)
|
|
|
|
section.title_color = PlantMutation.get_rarity_color(get_rarity())
|
|
section.title_colored = true
|
|
section.title_icon = get_icon()
|
|
|
|
return section
|
|
|
|
static func get_rarity_text(rarity) -> String:
|
|
var rarity_text : Array[String] = [
|
|
"Common",
|
|
"Rare",
|
|
"Very rare",
|
|
"Impossible",
|
|
"[rainbow]Absurd[/rainbow]",
|
|
]
|
|
|
|
if rarity < len(rarity_text):
|
|
return rarity_text[rarity]
|
|
else :
|
|
return rarity_text[len(rarity_text) - 1] + " " + str(rarity - len(rarity_text) + 2)
|
|
|
|
static func get_rarity_color(rarity : int) -> Color:
|
|
var rarity_colors : Array[Color] = [
|
|
Color("25C147"),
|
|
Color("8B2DFF"),
|
|
Color("FF006E"),
|
|
Color("FFA617"),
|
|
]
|
|
|
|
return rarity_colors[min(rarity, len(rarity_colors) - 1)]
|
|
|
|
static func random_rarity() -> int:
|
|
var random_float = randf()
|
|
|
|
for i in range(len(BASE_RARITY_CHANCE) - 1):
|
|
if random_float < BASE_RARITY_CHANCE[i]:
|
|
return i
|
|
return len(BASE_RARITY_CHANCE) - 1
|
|
|
|
static func random_mutation(rarity = PlantMutation.random_rarity()) -> PlantMutation:
|
|
var all_mutations = GameInfo.game_data.unlocked_plant_mutations.duplicate_deep()
|
|
all_mutations.shuffle()
|
|
for new_mutation in all_mutations:
|
|
var level_for_rarity = new_mutation.get_level_for_rarity(rarity)
|
|
if level_for_rarity >= 1:
|
|
new_mutation.level = level_for_rarity
|
|
return new_mutation
|
|
return null
|
|
|