seeding-planets/entities/plants/scripts/plant_mutation.gd
Zacharie Guet ef392595de ajout des mutation et refonte de l'inspecteur
* ajout des mutations #86
* changement de l'objectif #85
* refonte de l'inspecteur #71
* changement léger de la plantation
* les plantes ne donnent que des graines de leurs espèces
* refonte partielle du code, refacto
2025-10-12 01:03:08 +02:00

112 lines
2.8 KiB
GDScript

extends Resource
class_name PlantMutation
const BASE_RARITY_CHANCE : Array[float] = [
0.6,
0.8,
0.9,
0.95,
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 : 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
static func get_rarity(mutation : PlantMutation) -> int:
return mutation.get_base_rarity() + mutation.level - 1
static func get_rarity_text(mutation : PlantMutation) -> String:
var rarity_text : Array[String] = [
"Common",
"Rare",
"Very rare",
"Impossible",
"Absurd",
]
var rarity = PlantMutation.get_rarity(mutation)
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_bg_color(mutation : PlantMutation) -> Color:
var rarity_colors : Array[Color] = [
Color("4b3700"),
Color("6d2300"),
Color("001f50"),
Color("311558"),
Color("780235"),
]
return rarity_colors[min(PlantMutation.get_rarity(mutation), len(rarity_colors) - 1)]
static func get_rarity_color(mutation : PlantMutation) -> Color:
var rarity_colors : Array[Color] = [
Color("FFBE0B"),
Color("FB5607"),
Color("3A86FF"),
Color("8338EC"),
Color("FF006E"),
]
return rarity_colors[min(PlantMutation.get_rarity(mutation), len(rarity_colors) - 1)]
static func get_framed_info_from_mutation(
mutation : PlantMutation
) -> Inspector.FramedInfo:
return Inspector.FramedInfo.new(
mutation.get_mutation_name() + (" %d" % mutation.level if mutation.level > 1 else ""),
"[b]%s[/b] %s" % [PlantMutation.get_rarity_text(mutation), mutation.get_mutation_description()],
mutation.get_icon(),
PlantMutation.get_rarity_bg_color(mutation)
)
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