gros dev pre proto
* 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
This commit is contained in:
@@ -37,8 +37,8 @@ func pointer_text() -> String:
|
||||
func interact_text():
|
||||
return "Take"
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
return item.inspector_info()
|
||||
func card_info() -> CardInfo:
|
||||
return item.card_info()
|
||||
|
||||
func interact(player : Player) -> bool:
|
||||
player.pick_item(item)
|
||||
@@ -70,3 +70,6 @@ func generate_sprite() -> ItemObjectSprite:
|
||||
)
|
||||
|
||||
return sprite_node
|
||||
|
||||
func save() -> EntityData:
|
||||
return ItemObjectData.new(self)
|
||||
@@ -0,0 +1,11 @@
|
||||
extends EntityData
|
||||
class_name ItemObjectData
|
||||
|
||||
@export var item : Item
|
||||
|
||||
func _init(e : ItemObject):
|
||||
position = e.global_position
|
||||
item = e.item
|
||||
|
||||
func load() -> Entity:
|
||||
return ItemObject.new(item)
|
||||
@@ -0,0 +1 @@
|
||||
uid://brwd7adf8j7ff
|
||||
@@ -4,30 +4,24 @@ class_name Machine
|
||||
const MAX_MACHINE_LEVEL = 3
|
||||
|
||||
var level : int = 1
|
||||
var machine_name : String = ""
|
||||
var machine_desc : String = ""
|
||||
|
||||
func setup_machine_info(machine_type : MachineType, _level : int = 1):
|
||||
level = _level
|
||||
machine_name = machine_type.name
|
||||
machine_desc = machine_type.description
|
||||
setup_machine_sprite()
|
||||
|
||||
func setup_machine_sprite():
|
||||
pass
|
||||
var type : MachineType
|
||||
|
||||
func pointer_text() -> String:
|
||||
return machine_name
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
pointer_text(),
|
||||
machine_desc
|
||||
)
|
||||
return type.name
|
||||
|
||||
static func get_level_color(l : int) -> Color:
|
||||
match l:
|
||||
1: return Color("4ed38a")
|
||||
2: return Color("4ec6ee")
|
||||
3: return Color("bd70e2")
|
||||
_: return Color("bd70e2")
|
||||
_: return Color("bd70e2")
|
||||
|
||||
static func instantiate_machine(machine_type : MachineType, machine_level = 1) -> Machine:
|
||||
var new_machine : Machine = machine_type.scene.instantiate() as Machine
|
||||
new_machine.level = machine_level
|
||||
new_machine.type = machine_type
|
||||
|
||||
return new_machine
|
||||
|
||||
func save() -> EntityData:
|
||||
return MachineData.new(self)
|
||||
13
entities/interactables/machines/scripts/machine_data.gd
Normal file
13
entities/interactables/machines/scripts/machine_data.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
extends EntityData
|
||||
class_name MachineData
|
||||
|
||||
@export var level : int
|
||||
@export var type : MachineType
|
||||
|
||||
func _init(m : Machine):
|
||||
position = m.global_position
|
||||
level = m.level
|
||||
type = m.type
|
||||
|
||||
func load() -> Entity:
|
||||
return Machine.instantiate_machine(type, level)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b24o2jgqvfact
|
||||
@@ -1 +0,0 @@
|
||||
uid://bhncww816fjsb
|
||||
@@ -0,0 +1 @@
|
||||
uid://bepx311a3f0o
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Machine
|
||||
class_name SolarPanel
|
||||
|
||||
var charged : bool = false : set = set_charged
|
||||
var charged : bool = false
|
||||
var recharge_days : int = 0
|
||||
|
||||
func get_days_to_recharge(l : int = level) -> int:
|
||||
@@ -25,13 +25,18 @@ func _pass_day():
|
||||
if recharge_days >= get_days_to_recharge():
|
||||
set_charged(true)
|
||||
|
||||
func set_charged(_charged = true):
|
||||
func set_charged(_charged = true, with_anim : bool = true):
|
||||
charged = _charged
|
||||
recharge_days = 0
|
||||
if charged:
|
||||
%AnimationPlayer.play("charged")
|
||||
else :
|
||||
%AnimationPlayer.play_backwards("charged")
|
||||
if with_anim:
|
||||
if charged:
|
||||
%AnimationPlayer.play("charged")
|
||||
else :
|
||||
%AnimationPlayer.play_backwards("charged")
|
||||
await %AnimationPlayer.animation_finished
|
||||
%Flair.modulate = Color.WHITE if charged else Color.TRANSPARENT
|
||||
%Pannels.modulate = Color.WHITE if charged else Color("6c6c6c")
|
||||
|
||||
|
||||
func setup_machine_sprite():
|
||||
# %Base.self_modulate = Machine.get_level_color(level)
|
||||
@@ -47,3 +52,6 @@ func interact(p : Player) -> bool:
|
||||
p.recharge(get_energy_production())
|
||||
set_charged(false)
|
||||
return true
|
||||
|
||||
func save() -> EntityData:
|
||||
return SolarPanelData.new(self)
|
||||
@@ -0,0 +1,19 @@
|
||||
extends MachineData
|
||||
class_name SolarPanelData
|
||||
|
||||
@export var charged : bool = false
|
||||
@export var recharge_days : int = 0
|
||||
|
||||
func _init(m : SolarPanel):
|
||||
position = m.global_position
|
||||
level = m.level
|
||||
type = m.type
|
||||
charged = m.charged
|
||||
recharge_days = m.recharge_days
|
||||
|
||||
func load() -> Entity:
|
||||
var sp = Machine.instantiate_machine(type, level) as SolarPanel
|
||||
sp.set_charged(charged, false)
|
||||
sp.recharge_days = recharge_days
|
||||
|
||||
return sp
|
||||
@@ -0,0 +1 @@
|
||||
uid://dv1tok0civrpp
|
||||
@@ -1,11 +1,11 @@
|
||||
[gd_resource type="Resource" script_class="MachineType" load_steps=3 format=3 uid="uid://dew3p4fffjryo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bhncww816fjsb" path="res://entities/interactables/machines/scripts/machine_info.gd" id="1_ctita"]
|
||||
[ext_resource type="Script" uid="uid://bepx311a3f0o" path="res://entities/interactables/machines/scripts/machine_type.gd" id="1_ctita"]
|
||||
[ext_resource type="PackedScene" uid="uid://gwq2oos6ljyp" path="res://entities/interactables/machines/solar_pannel/solar_pannel.tscn" id="1_naexs"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ctita")
|
||||
name = "Solar Pannel"
|
||||
scene = ExtResource("1_naexs")
|
||||
description = "Produce energy every 2 days. When charged, can be used to recharge energy."
|
||||
metadata/_custom_type_script = "uid://bhncww816fjsb"
|
||||
description = "Charge every 2 days. When charged, can be used to recharge player energy."
|
||||
metadata/_custom_type_script = "uid://bepx311a3f0o"
|
||||
|
||||
@@ -8,33 +8,6 @@
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_6utw7"]
|
||||
radius = 48.0
|
||||
|
||||
[sub_resource type="Animation" id="Animation_gal8b"]
|
||||
resource_name = "charged"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprites/Pannels:modulate")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0.033333335, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(0.42365062, 0.42365065, 0.42365062, 1), Color(1, 1, 1, 1)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sprites/Flair:modulate")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_77hon"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
@@ -62,6 +35,33 @@ tracks/1/keys = {
|
||||
"values": [Color(1, 1, 1, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_gal8b"]
|
||||
resource_name = "charged"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprites/Pannels:modulate")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0.033333335, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(0.42365062, 0.42365065, 0.42365062, 1), Color(1, 1, 1, 1)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sprites/Flair:modulate")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_5vw1f"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_77hon"),
|
||||
@@ -77,6 +77,7 @@ position = Vector2(15.999999, -16.999998)
|
||||
scale = Vector2(0.09, 0.09)
|
||||
|
||||
[node name="Pannels" type="Sprite2D" parent="Sprites"]
|
||||
unique_name_in_owner = true
|
||||
modulate = Color(0.42352942, 0.42352942, 0.42352942, 1)
|
||||
texture = ExtResource("2_ny3sb")
|
||||
|
||||
@@ -85,6 +86,7 @@ unique_name_in_owner = true
|
||||
texture = ExtResource("3_bml32")
|
||||
|
||||
[node name="Flair" type="Sprite2D" parent="Sprites"]
|
||||
unique_name_in_owner = true
|
||||
modulate = Color(1, 1, 1, 0)
|
||||
texture = ExtResource("4_ob8kj")
|
||||
|
||||
|
||||
@@ -35,9 +35,6 @@ viewport_path = NodePath("IconViewPort")
|
||||
font = ExtResource("4_ux0j5")
|
||||
font_size = 30
|
||||
|
||||
[sub_resource type="Animation" id="Animation_65b0j"]
|
||||
resource_name = "empty"
|
||||
|
||||
[sub_resource type="Animation" id="Animation_8nmxn"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
@@ -69,6 +66,9 @@ tracks/0/keys = {
|
||||
"values": [Vector2(1, 1), Vector2(1.195, 0.915), Vector2(0.81, 1.195), Vector2(1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_65b0j"]
|
||||
resource_name = "empty"
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_8nmxn"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_8nmxn"),
|
||||
@@ -78,6 +78,9 @@ _data = {
|
||||
|
||||
[node name="Compost" type="Area2D"]
|
||||
script = ExtResource("1_ux0j5")
|
||||
default_interact_text = "Place Seed"
|
||||
default_info_title = "Compost"
|
||||
default_info_desc = "This research station can provide some bonus if filled with seeds."
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -3)
|
||||
|
||||
@@ -3,6 +3,7 @@ class_name Compost
|
||||
|
||||
const FILLED_ICON = preload("res://common/icons/bucket.svg")
|
||||
|
||||
signal filled(c : Compost)
|
||||
signal rewarded(c : Compost)
|
||||
|
||||
var reward : Reward = null :
|
||||
@@ -17,46 +18,19 @@ var containing_seed : int = 0 :
|
||||
func _ready():
|
||||
update_info()
|
||||
|
||||
func pointer_text() -> String:
|
||||
return "Compost"
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
var info = Inspector.Info.new(
|
||||
pointer_text(),
|
||||
"Fill this machine with seeds to get an reward",
|
||||
%Sprite.texture,
|
||||
)
|
||||
|
||||
if reward != null:
|
||||
info.framed_infos.append(
|
||||
Inspector.FramedInfo.new(
|
||||
"On filled",
|
||||
reward.desc(),
|
||||
FILLED_ICON,
|
||||
)
|
||||
)
|
||||
|
||||
return info
|
||||
|
||||
func update_info():
|
||||
%Count.text = "" if reward == null else "%d/%d" % [containing_seed, reward.get_seed_needed()]
|
||||
%Icon.texture = null if reward == null else reward.icon()
|
||||
|
||||
func interact_text():
|
||||
if reward:
|
||||
return "Put a seed (%d left)" % (reward.get_seed_needed() - containing_seed)
|
||||
else:
|
||||
return ""
|
||||
|
||||
func can_interact(p : Player) -> bool:
|
||||
return reward and p.inventory.get_item() and p.inventory.get_item() is Seed
|
||||
return reward and p.data.inventory.get_item() and p.data.inventory.get_item() is Seed
|
||||
|
||||
func interact(p : Player) -> bool:
|
||||
if not can_interact(p):
|
||||
return false
|
||||
|
||||
p.play_sfx("harvest")
|
||||
p.inventory.remove_current_item()
|
||||
p.data.inventory.remove_current_item()
|
||||
containing_seed += 1
|
||||
if containing_seed >= reward.get_seed_needed():
|
||||
containing_seed = 0
|
||||
@@ -64,66 +38,34 @@ func interact(p : Player) -> bool:
|
||||
rewarded.emit(self)
|
||||
%AnimationPlayer.play("bump")
|
||||
|
||||
filled.emit(self)
|
||||
|
||||
return true
|
||||
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
pointer_text()
|
||||
)
|
||||
|
||||
if default_info_desc != "":
|
||||
var desc_section = CardSectionInfo.new(
|
||||
"Description",
|
||||
default_info_desc
|
||||
)
|
||||
desc_section.title_icon = DESC_ICON
|
||||
info.sections.append(
|
||||
desc_section
|
||||
)
|
||||
|
||||
var reward_section = CardSectionInfo.new(
|
||||
"When filled",
|
||||
reward.desc()
|
||||
)
|
||||
reward_section.title_icon = FILLED_ICON
|
||||
|
||||
info.sections.append(reward_section)
|
||||
|
||||
return info
|
||||
|
||||
func product(_player : Player):
|
||||
pass
|
||||
|
||||
class Reward:
|
||||
|
||||
var seed_needed : int = 1
|
||||
|
||||
func _init(_seed_needed : int):
|
||||
seed_needed = _seed_needed
|
||||
|
||||
func reward(_p: Player):
|
||||
pass
|
||||
|
||||
func get_seed_needed() -> int:
|
||||
return seed_needed
|
||||
|
||||
func desc() -> String:
|
||||
return ""
|
||||
|
||||
func icon() -> Texture:
|
||||
return null
|
||||
|
||||
class UpgradeMaxEnergyReward extends Reward:
|
||||
func reward(p: Player):
|
||||
p.upgrade_max_energy(1)
|
||||
|
||||
func desc() -> String:
|
||||
return "Upgrade max energy"
|
||||
|
||||
func icon() -> Texture:
|
||||
return preload("res://common/icons/bolt.svg")
|
||||
|
||||
class UpgradeMaxInventoryReward extends Reward:
|
||||
func reward(p: Player):
|
||||
p.upgrade_inventory_size()
|
||||
|
||||
func desc() -> String:
|
||||
return "Upgrade max inventory size"
|
||||
|
||||
func icon() -> Texture:
|
||||
return preload("res://common/icons/backpack.svg")
|
||||
|
||||
class GiveItemReward extends Reward:
|
||||
|
||||
var item : Item
|
||||
|
||||
func _init(_seed_needed : int, _item : Item):
|
||||
item = _item
|
||||
seed_needed = _seed_needed
|
||||
|
||||
func reward(p: Player):
|
||||
if p.inventory.is_full():
|
||||
p.terrain.drop_item(item, p.global_position, 10)
|
||||
else:
|
||||
p.pick_item(item)
|
||||
|
||||
func desc() -> String:
|
||||
return "Give the item %s" % item.get_item_name()
|
||||
|
||||
func icon() -> Texture:
|
||||
return item.icon
|
||||
|
||||
19
entities/interactables/truck/compost/scripts/reward.gd
Normal file
19
entities/interactables/truck/compost/scripts/reward.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Resource
|
||||
class_name Reward
|
||||
|
||||
var seed_needed : int = 1
|
||||
|
||||
func _init(_seed_needed : int):
|
||||
seed_needed = _seed_needed
|
||||
|
||||
func reward(_p: Player):
|
||||
pass
|
||||
|
||||
func get_seed_needed() -> int:
|
||||
return seed_needed
|
||||
|
||||
func desc() -> String:
|
||||
return ""
|
||||
|
||||
func icon() -> Texture:
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://djtiywfr031nr
|
||||
@@ -0,0 +1,20 @@
|
||||
extends Reward
|
||||
class_name GiveItemReward
|
||||
|
||||
var item : Item
|
||||
|
||||
func _init(_seed_needed : int, _item : Item):
|
||||
item = _item
|
||||
seed_needed = _seed_needed
|
||||
|
||||
func reward(p: Player):
|
||||
if p.data.inventory.is_full():
|
||||
p.terrain.drop_item(item, p.global_position, 10)
|
||||
else:
|
||||
p.pick_item(item)
|
||||
|
||||
func desc() -> String:
|
||||
return "Give the following item : [b]%s[/b]. %s" % [item.name, item.description]
|
||||
|
||||
func icon() -> Texture:
|
||||
return item.icon
|
||||
@@ -0,0 +1 @@
|
||||
uid://cqr2dpxwn6oa8
|
||||
@@ -0,0 +1,10 @@
|
||||
extends Reward
|
||||
class_name UpgradeMaxEnergyReward
|
||||
func reward(p: Player):
|
||||
p.upgrade_max_energy(1)
|
||||
|
||||
func desc() -> String:
|
||||
return "Upgrade max energy"
|
||||
|
||||
func icon() -> Texture:
|
||||
return preload("res://common/icons/bolt.svg")
|
||||
@@ -0,0 +1 @@
|
||||
uid://ck28pmq7jv66m
|
||||
@@ -0,0 +1,11 @@
|
||||
extends Reward
|
||||
class_name UpgradeMaxInventoryReward
|
||||
|
||||
func reward(p: Player):
|
||||
p.upgrade_inventory_size()
|
||||
|
||||
func desc() -> String:
|
||||
return "Upgrade max inventory size"
|
||||
|
||||
func icon() -> Texture:
|
||||
return preload("res://common/icons/backpack.svg")
|
||||
@@ -0,0 +1 @@
|
||||
uid://dnl5erwyrn44g
|
||||
@@ -1,22 +1,9 @@
|
||||
extends Interactable
|
||||
class_name TruckLadder
|
||||
|
||||
@export var truck_interior : TruckInterior
|
||||
@export var planet_camera : Camera
|
||||
|
||||
func _ready():
|
||||
truck_interior.player_exited.connect(_on_truck_interior_player_exited)
|
||||
const TRUCK_SCENE_PATH = "res://stages/terrain/truck/truck.tscn"
|
||||
|
||||
func interact(p : Player):
|
||||
truck_interior.add_entity(p)
|
||||
p.global_position = truck_interior.spawn_position.global_position
|
||||
truck_interior.camera.make_current()
|
||||
planet_camera.following = null
|
||||
p.planet.save()
|
||||
get_tree().change_scene_to_file(TRUCK_SCENE_PATH)
|
||||
return true
|
||||
|
||||
|
||||
func _on_truck_interior_player_exited(p):
|
||||
planet.add_entity(p)
|
||||
p.global_position = global_position
|
||||
planet_camera.make_current()
|
||||
planet_camera.following = p
|
||||
|
||||
@@ -9,15 +9,3 @@ func interact(_p: Player) -> bool:
|
||||
planet.pass_day()
|
||||
|
||||
return true
|
||||
|
||||
func interact_text():
|
||||
return "Recharge"
|
||||
|
||||
func pointer_text() -> String:
|
||||
return "Recharge Station"
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
pointer_text(),
|
||||
"You can recharge your robot here. When recharging, time will pass and plants may grow."
|
||||
)
|
||||
|
||||
@@ -14,6 +14,9 @@ region = Rect2(64, 161, 101, 205)
|
||||
|
||||
[node name="TruckRecharge" type="Area2D"]
|
||||
script = ExtResource("1_ipgcv")
|
||||
default_interact_text = "Recharge"
|
||||
default_info_title = "Recharge Station"
|
||||
default_info_desc = "[b]You can recharge your robot here.[/b] When recharging, time will pass and plants may grow."
|
||||
metadata/_custom_type_script = "uid://dyprcd68fjstf"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
||||
@@ -10,25 +10,9 @@ var completed : bool = false
|
||||
func pointer_text() -> String:
|
||||
return "Contamination Objective"
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
var info : Inspector.Info = Inspector.Info.new(
|
||||
pointer_text(),
|
||||
"This dead branch can hide a treasure of life."
|
||||
)
|
||||
|
||||
info.framed_infos.append(
|
||||
Inspector.FramedInfo.new(
|
||||
"When decontamined",
|
||||
reward.get_description(),
|
||||
DECONTAMINATION_ICON
|
||||
)
|
||||
)
|
||||
|
||||
return info
|
||||
|
||||
func _end_pass_day():
|
||||
if planet and not completed:
|
||||
if not planet.is_there_contamination(global_position):
|
||||
if not planet.garden.is_there_contamination(global_position):
|
||||
reward.reward(self)
|
||||
%AnimationPlayer.play("activate")
|
||||
completed = true
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
extends ObjectiveReward
|
||||
class_name IncreaseDayLimitReward
|
||||
|
||||
@export var day_limit_increase = 5
|
||||
|
||||
func _init(_day_limit_increase : int):
|
||||
day_limit_increase = _day_limit_increase
|
||||
|
||||
func reward(objective : Objective):
|
||||
if objective.planet:
|
||||
objective.planet.day_limit += day_limit_increase
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/hourglass-empty.svg")
|
||||
|
||||
func get_text() -> String:
|
||||
return "+"+str(day_limit_increase)
|
||||
|
||||
func get_description() -> String:
|
||||
return "Increase the day limitation by " + str(day_limit_increase) + "."
|
||||
@@ -1 +0,0 @@
|
||||
uid://df6i1hivw4ymn
|
||||
@@ -15,7 +15,7 @@ func get_text() -> String:
|
||||
return ""
|
||||
|
||||
func get_description() -> String:
|
||||
return "Loot the following item: " + item.name + "."
|
||||
return "Loot the following item: [b]%s[/b]. %s" % [item.name, item.description]
|
||||
|
||||
func reward(objective : Objective):
|
||||
objective.terrain.drop_item(
|
||||
|
||||
@@ -121,6 +121,7 @@ scale = Vector2(0.426047, 0.430108)
|
||||
texture = ExtResource("4_j6jm5")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_8eofq")
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
[sub_resource type="Resource" id="Resource_cf34j"]
|
||||
script = ExtResource("1_cf34j")
|
||||
level = 1
|
||||
level = 2
|
||||
metadata/_custom_type_script = "uid://ceqx5va1ormau"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_my6by"]
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
extends InspectableEntity
|
||||
class_name Plant
|
||||
|
||||
signal harvested(p: Plant)
|
||||
signal state_changed(p: Plant)
|
||||
|
||||
const PLANT_AREA_RADIUS = 20
|
||||
const PLANT_INFLUENCE_RADIUS = 100
|
||||
const HARVESTED_SEED_DISPLACEMENT_FACTOR = 100
|
||||
|
||||
const RANDOM_MAX_GROW_INTERVAL = Planet.PASS_DAY_ANIMATION_TIME/2. - 0.1
|
||||
const PLANT_TYPE_ICON = preload("res://common/icons/seedling.svg")
|
||||
const PLANT_POINT_ICON = preload("res://common/icons/growth.svg")
|
||||
const LIFETIME_ICON = preload("res://common/icons/calendar-week.svg")
|
||||
const SHOVEL_ICON = preload("res://common/icons/shovel.svg")
|
||||
const GROWING_ICON = preload("res://common/icons/chevrons-up.svg")
|
||||
|
||||
const HARVEST_EFFECT_ICON = preload("res://common/icons/shovel.svg")
|
||||
const MATURE_EFFECT_ICON = preload("res://common/icons/chevrons-up.svg")
|
||||
const CYCLIC_EFFECT_ICON = preload("res://common/icons/rotate-rectangle.svg")
|
||||
|
||||
const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.tscn")
|
||||
|
||||
enum State {PLANTED, GROWING, MATURE}
|
||||
|
||||
@export var plant_type: PlantType
|
||||
|
||||
var state: State = State.PLANTED: set = change_state
|
||||
@export var day: int = 0 : set = set_day
|
||||
var state: State = State.PLANTED
|
||||
@export var day: int
|
||||
|
||||
@onready var plant_sprite: PlantSprite = generate_sprite()
|
||||
@onready var collision_shape: CollisionShape2D = generate_collision_shape()
|
||||
@onready var influence_zone : PlantInfluenceZone = generate_influence_zone()
|
||||
@onready var plant_sprite: PlantSprite
|
||||
@onready var collision_shape: CollisionShape2D
|
||||
@onready var influence_zone : PlantInfluenceZone
|
||||
|
||||
var harvest_effects = []
|
||||
var mature_effects = []
|
||||
@@ -32,83 +40,37 @@ var plant_mutations : Array[PlantMutation] = []
|
||||
|
||||
func _init(
|
||||
_plant_type : PlantType,
|
||||
_planet : Planet,
|
||||
_plant_mutations : Array[PlantMutation] = []
|
||||
_plant_mutations : Array[PlantMutation] = [],
|
||||
_day = 0,
|
||||
):
|
||||
plant_type = _plant_type
|
||||
harvest_effects = plant_type.default_harvest_effects.duplicate_deep()
|
||||
mature_effects = plant_type.default_mature_effects.duplicate_deep()
|
||||
cyclic_effects = plant_type.default_cyclic_effects.duplicate_deep()
|
||||
|
||||
planet = _planet
|
||||
day = _day
|
||||
|
||||
plant_mutations = _plant_mutations
|
||||
|
||||
func _ready():
|
||||
plant_sprite = generate_sprite()
|
||||
collision_shape = generate_collision_shape()
|
||||
influence_zone = generate_influence_zone()
|
||||
|
||||
update_plant(false)
|
||||
plant_sprite.update_plant_sprite(self, false)
|
||||
|
||||
func pointer_text() -> String:
|
||||
var state_text = "Growing"
|
||||
if state == State.MATURE: state_text = "Mature"
|
||||
return state_text + " " + plant_type.name
|
||||
return plant_type.name
|
||||
|
||||
func inspect(is_inspected : bool = true):
|
||||
modulate = MODULATE_INSPECTED_COLOR if is_inspected else default_modulate
|
||||
influence_zone.show_influence = is_inspected
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
var info = Inspector.Info.new(
|
||||
pointer_text(),
|
||||
"",
|
||||
plant_type.mature_texture
|
||||
)
|
||||
|
||||
for m in plant_mutations:
|
||||
info.framed_infos.append(
|
||||
PlantMutation.get_framed_info_from_mutation(m)
|
||||
)
|
||||
|
||||
info.framed_infos.append_array(
|
||||
PlantEffect.get_framed_info_from_all_trigger_effects(
|
||||
mature_effects, harvest_effects, cyclic_effects
|
||||
)
|
||||
)
|
||||
|
||||
info.stat_infos.append(
|
||||
Inspector.StatInfo.new(
|
||||
"Day [b]%d[/b]" % day,
|
||||
LIFETIME_ICON
|
||||
)
|
||||
)
|
||||
|
||||
if state != State.MATURE:
|
||||
info.stat_infos.append_array([
|
||||
Inspector.StatInfo.new(
|
||||
"Mature on day [b]%d[/b]" % calculate_grow_time(),
|
||||
GROWING_ICON,
|
||||
),
|
||||
Inspector.StatInfo.new(
|
||||
"[b]%d[/b]" % [
|
||||
calculate_plant_score()
|
||||
],
|
||||
PLANT_POINT_ICON
|
||||
),
|
||||
])
|
||||
else:
|
||||
info.stat_infos.append(
|
||||
Inspector.StatInfo.new(
|
||||
"[b]%d[/b] point%s" % [
|
||||
calculate_plant_score(),
|
||||
"s" if calculate_plant_score() > 0 else ""
|
||||
],
|
||||
PLANT_POINT_ICON
|
||||
),
|
||||
)
|
||||
|
||||
return info
|
||||
|
||||
func generate_sprite() -> PlantSprite:
|
||||
var sprite_object : PlantSprite = SPRITE_SCENE.instantiate()
|
||||
|
||||
add_child(sprite_object)
|
||||
sprite_object.update_plant_sprite(self)
|
||||
sprite_object.generate_mutation_effects(self)
|
||||
|
||||
return sprite_object
|
||||
@@ -138,24 +100,34 @@ func _pass_day():
|
||||
for effect in cyclic_effects:
|
||||
effect.effect(self)
|
||||
|
||||
day += 1
|
||||
var old_state = state
|
||||
|
||||
func set_day(d):
|
||||
day = d
|
||||
day += 1
|
||||
update_plant()
|
||||
|
||||
if old_state != state and state == State.MATURE:
|
||||
for effect in mature_effects:
|
||||
if effect : effect.effect(self)
|
||||
for effect in cyclic_effects:
|
||||
if effect : effect.effect(self)
|
||||
|
||||
func update_plant(with_animation : bool = true):
|
||||
if day + 1 > calculate_grow_time():
|
||||
if state != State.MATURE:
|
||||
change_state(State.MATURE)
|
||||
change_state(State.MATURE, with_animation)
|
||||
elif day == 0:
|
||||
change_state(State.PLANTED)
|
||||
change_state(State.PLANTED, with_animation)
|
||||
else:
|
||||
if state != State.GROWING:
|
||||
change_state(State.GROWING)
|
||||
change_state(State.GROWING, with_animation)
|
||||
|
||||
func calculate_plant_score() -> int:
|
||||
var mutated_plant_score = plant_type.default_plant_score if state == State.MATURE else 0
|
||||
func calculate_plant_score(
|
||||
overwite_state : State = state
|
||||
) -> int:
|
||||
var mutated_plant_score = plant_type.default_plant_score if overwite_state == State.MATURE else 0
|
||||
|
||||
for m in plant_mutations:
|
||||
mutated_plant_score = m.mutate_score(self, mutated_plant_score)
|
||||
mutated_plant_score = m.mutate_score(overwite_state, self, mutated_plant_score)
|
||||
|
||||
return mutated_plant_score
|
||||
|
||||
@@ -167,16 +139,12 @@ func calculate_grow_time() -> int:
|
||||
|
||||
return mutated_grow_time
|
||||
|
||||
func change_state(_state: State):
|
||||
state = _state
|
||||
|
||||
if state == State.MATURE and len(mature_effects):
|
||||
for effect in mature_effects:
|
||||
if effect : effect.effect(self)
|
||||
for effect in cyclic_effects:
|
||||
if effect : effect.effect(self)
|
||||
|
||||
plant_sprite.update_plant_sprite(self, true)
|
||||
func change_state(_state: State, with_animation : bool = true):
|
||||
if state != _state:
|
||||
state = _state
|
||||
|
||||
plant_sprite.update_plant_sprite(self, with_animation)
|
||||
state_changed.emit(self)
|
||||
|
||||
func harvest():
|
||||
if state == State.MATURE:
|
||||
@@ -185,4 +153,89 @@ func harvest():
|
||||
|
||||
plant_sprite.start_harvest_animation()
|
||||
await plant_sprite.harvest_animation_finished
|
||||
harvested.emit(self)
|
||||
queue_free()
|
||||
|
||||
func save() -> EntityData:
|
||||
return PlantData.new(self)
|
||||
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
pointer_text()
|
||||
)
|
||||
|
||||
info.important_stat_icon = PLANT_POINT_ICON
|
||||
info.important_stat_text = "%d" % calculate_plant_score()
|
||||
info.texture = plant_type.mature_texture
|
||||
info.type_icon = PLANT_TYPE_ICON
|
||||
|
||||
var state_text = "Mature"
|
||||
if state != State.MATURE:
|
||||
state_text = "Growing"
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
"Day [b]%d[/b]" % day,
|
||||
LIFETIME_ICON
|
||||
))
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
state_text,
|
||||
PLANT_TYPE_ICON
|
||||
))
|
||||
|
||||
if state != State.MATURE:
|
||||
info.stats.append(CardStatInfo.new(
|
||||
"Mature on day [b]%d[/b]" % calculate_grow_time(),
|
||||
GROWING_ICON
|
||||
))
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
"[b]%d[/b] score when mature" % calculate_plant_score(State.MATURE),
|
||||
PLANT_POINT_ICON
|
||||
))
|
||||
|
||||
|
||||
if len(plant_mutations) != 0:
|
||||
var rarest : int = plant_mutations.map(
|
||||
func(m : PlantMutation) : return m.get_rarity()
|
||||
).max()
|
||||
info.bg_color = PlantMutation.get_rarity_color(rarest)
|
||||
for m in plant_mutations:
|
||||
info.sections.append(m.card_section())
|
||||
|
||||
info.sections.append_array(card_effect_sections())
|
||||
|
||||
return info
|
||||
|
||||
func card_effect_sections() -> Array[CardSectionInfo]:
|
||||
var sections : Array[CardSectionInfo] = []
|
||||
var effects_category = [
|
||||
mature_effects,
|
||||
harvest_effects,
|
||||
cyclic_effects
|
||||
]
|
||||
var effects_category_labels : Array[String] = [
|
||||
"On mature",
|
||||
"When harvested",
|
||||
"Each day when mature",
|
||||
]
|
||||
var effects_category_icon : Array[Texture] = [
|
||||
MATURE_EFFECT_ICON,
|
||||
HARVEST_EFFECT_ICON,
|
||||
CYCLIC_EFFECT_ICON,
|
||||
]
|
||||
|
||||
for i in range(len(effects_category)):
|
||||
var effects = effects_category[i]
|
||||
if len(effects):
|
||||
var section = CardSectionInfo.new(
|
||||
effects_category_labels[i]
|
||||
)
|
||||
section.title_icon = effects_category_icon[i]
|
||||
var effects_text : Array = effects.map(
|
||||
func (e : PlantEffect): return "[b]%s[/b] %s" % [e.get_styled_effect_name() , e.get_effect_description()]
|
||||
)
|
||||
section.text = "\n".join(effects_text)
|
||||
sections.append(section)
|
||||
|
||||
return sections
|
||||
|
||||
20
entities/plants/scripts/plant_data.gd
Normal file
20
entities/plants/scripts/plant_data.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
extends EntityData
|
||||
class_name PlantData
|
||||
|
||||
var plant_type : PlantType
|
||||
var plant_mutations : Array[PlantMutation]
|
||||
var day : int
|
||||
|
||||
func _init(plant : Plant):
|
||||
position = plant.global_position
|
||||
plant_type = plant.plant_type
|
||||
plant_mutations = plant.plant_mutations
|
||||
day = plant.day
|
||||
|
||||
func load() -> Entity:
|
||||
var plant = Plant.new(
|
||||
plant_type,
|
||||
plant_mutations,
|
||||
day
|
||||
)
|
||||
return plant
|
||||
1
entities/plants/scripts/plant_data.gd.uid
Normal file
1
entities/plants/scripts/plant_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://da6j333qs7wse
|
||||
@@ -2,10 +2,6 @@
|
||||
extends Resource
|
||||
class_name PlantEffect
|
||||
|
||||
const HARVEST_EFFECT_ICON = preload("res://common/icons/shovel.svg")
|
||||
const MATURE_EFFECT_ICON = preload("res://common/icons/chevrons-up.svg")
|
||||
const CYCLIC_EFFECT_ICON = preload("res://common/icons/rotate-rectangle.svg")
|
||||
|
||||
@export var level : int
|
||||
|
||||
func _init(_level : int = 1):
|
||||
@@ -22,67 +18,17 @@ func get_effect_description() -> String:
|
||||
func effect(plant):
|
||||
printerr("Classe abstraite PlantEffect appelée")
|
||||
|
||||
static func get_framed_info_from_effects(
|
||||
effects : Array[PlantEffect],
|
||||
trigger_text = "",
|
||||
trigger_icon: Texture = null
|
||||
) -> Array[Inspector.FramedInfo]:
|
||||
if len(effects) == 0 : return []
|
||||
|
||||
var desc = "%s %s" % [PlantEffect.get_framed_info_effect_name(effects[0]), effects[0].get_effect_description()]
|
||||
|
||||
for i in range(1, len(effects)):
|
||||
if effects[i]:
|
||||
desc += "\n%s %s" % [PlantEffect.get_framed_info_effect_name(effects[i]), effects[i].get_effect_description()]
|
||||
|
||||
return [Inspector.FramedInfo.new(
|
||||
trigger_text,
|
||||
desc,
|
||||
trigger_icon
|
||||
)]
|
||||
|
||||
static func get_framed_info_effect_name(e : PlantEffect):
|
||||
func get_styled_effect_name():
|
||||
var levels_bbcode = [
|
||||
"[color=#ffffff][b]%s[/b][/color]",
|
||||
"[color=#FFBE0B][b]%s %d[/b][/color]",
|
||||
"[color=#FB5607][b]%s %d[/b][/color]",
|
||||
"[color=#3A86FF][b]%s %d[/b][/color]",
|
||||
"[color=#8338EC][b]%s %d[/b][/color]",
|
||||
"[color=#FF006E][b]%s %d[/b][/color]",
|
||||
"[rainbow][b]%s %d[/b][/rainbow]"
|
||||
"[color=#2364AA]%s[/color]",
|
||||
"[color=#25C147]%s %d[/color]",
|
||||
"[color=#8B2DFF]%s %d[/color]",
|
||||
"[color=#FF006E]%s %d[/color]",
|
||||
"[color=#FFA617]%s %d[/color]",
|
||||
"[rainbow]%s %d[/rainbow]"
|
||||
]
|
||||
|
||||
if e.level == 1:
|
||||
return levels_bbcode[0] % e.get_effect_name()
|
||||
if level == 1:
|
||||
return levels_bbcode[0] % get_effect_name()
|
||||
else :
|
||||
return levels_bbcode[min(e.level - 1, len(levels_bbcode) - 1)] % [e.get_effect_name(), e.level]
|
||||
|
||||
static func get_framed_info_from_all_trigger_effects(
|
||||
mature_effects : Array[PlantEffect],
|
||||
harvest_effects : Array[PlantEffect],
|
||||
cyclic_effects : Array[PlantEffect],
|
||||
) -> Array[Inspector.FramedInfo] :
|
||||
var framed_infos : Array[Inspector.FramedInfo] = []
|
||||
framed_infos.append_array(
|
||||
PlantEffect.get_framed_info_from_effects(
|
||||
mature_effects,
|
||||
"On maturation",
|
||||
MATURE_EFFECT_ICON
|
||||
)
|
||||
)
|
||||
framed_infos.append_array(
|
||||
PlantEffect.get_framed_info_from_effects(
|
||||
harvest_effects,
|
||||
"When harvested",
|
||||
HARVEST_EFFECT_ICON
|
||||
)
|
||||
)
|
||||
framed_infos.append_array(
|
||||
PlantEffect.get_framed_info_from_effects(
|
||||
cyclic_effects,
|
||||
"Each days",
|
||||
CYCLIC_EFFECT_ICON
|
||||
)
|
||||
)
|
||||
|
||||
return framed_infos
|
||||
return levels_bbcode[min(level - 1, len(levels_bbcode) - 1)] % [get_effect_name(), level]
|
||||
@@ -14,7 +14,7 @@ func get_effect_description() -> String:
|
||||
func effect(plant):
|
||||
var radius = get_decontamination_radius()
|
||||
|
||||
plant.planet.impact_contamination(
|
||||
plant.planet.garden.impact_contamination(
|
||||
plant.global_position,
|
||||
radius
|
||||
)
|
||||
@@ -2,11 +2,10 @@ extends Resource
|
||||
class_name PlantMutation
|
||||
|
||||
const BASE_RARITY_CHANCE : Array[float] = [
|
||||
0.6,
|
||||
0.8,
|
||||
0.75,
|
||||
0.9,
|
||||
0.95,
|
||||
1
|
||||
1,
|
||||
1,
|
||||
]
|
||||
|
||||
@export var level : int = 1
|
||||
@@ -28,7 +27,7 @@ func get_mutation_description() -> String:
|
||||
printerr("Classe abstraite PlantMutation appelée")
|
||||
return ""
|
||||
|
||||
func mutate_score(_plant : Plant, score) -> int:
|
||||
func mutate_score(_plant_state : Plant.State, _plant : Plant, score,) -> int:
|
||||
return score
|
||||
|
||||
func mutate_grow_time(_plant : Plant, grow_time : int) -> int:
|
||||
@@ -40,56 +39,44 @@ func mutate_plant(_plant : Plant):
|
||||
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
|
||||
func get_rarity() -> int:
|
||||
return get_base_rarity() + level - 1
|
||||
|
||||
static func get_rarity_text(mutation : PlantMutation) -> String:
|
||||
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",
|
||||
"Absurd",
|
||||
"[rainbow]Absurd[/rainbow]",
|
||||
]
|
||||
|
||||
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:
|
||||
static func get_rarity_color(rarity : int) -> 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("25C147"),
|
||||
Color("8B2DFF"),
|
||||
Color("FF006E"),
|
||||
Color("FFA617"),
|
||||
]
|
||||
|
||||
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)
|
||||
)
|
||||
return rarity_colors[min(rarity, len(rarity_colors) - 1)]
|
||||
|
||||
static func random_rarity() -> int:
|
||||
var random_float = randf()
|
||||
|
||||
@@ -18,7 +18,7 @@ func get_mutation_description() -> String:
|
||||
func get_day_factor():
|
||||
return max(1, DEFAULT_DAY_FACTOR - level + 1)
|
||||
|
||||
func mutate_score(plant : Plant, score) -> int:
|
||||
if plant.state != Plant.State.MATURE:
|
||||
func mutate_score(plant_state : Plant.State, plant : Plant, score) -> int:
|
||||
if plant_state != Plant.State.MATURE:
|
||||
return score
|
||||
return score + floori(plant.day / get_day_factor())
|
||||
@@ -13,8 +13,10 @@ func get_mutation_name() -> String:
|
||||
func get_mutation_description() -> String:
|
||||
return "When mature, add [b]%d[/b] to the score for each plant of the same species around, but score become 0 if none is around." % level
|
||||
|
||||
func mutate_score(plant : Plant, score) -> int:
|
||||
if plant.state != Plant.State.MATURE:
|
||||
func mutate_score(plant_state : Plant.State, plant : Plant, score) -> int:
|
||||
if plant.influence_zone == null:
|
||||
return score
|
||||
if plant_state != Plant.State.MATURE:
|
||||
return score
|
||||
var plant_count = 0
|
||||
|
||||
|
||||
@@ -2,23 +2,25 @@ extends PlantMutation
|
||||
class_name ErmitMutation
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/seedling-off.svg")
|
||||
return preload("res://common/icons/seedling-off.svg")
|
||||
|
||||
func get_base_rarity() -> int:
|
||||
return 0
|
||||
return 0
|
||||
|
||||
func get_mutation_name() -> String:
|
||||
return "Ermit"
|
||||
return "Ermit"
|
||||
|
||||
func get_mutation_description() -> String:
|
||||
return "Multiply the score by [b]%d[/b] if no plant is near, but set it to 0 otherwise." % get_score_multiplier()
|
||||
return "Multiply the score by [b]%d[/b] if no plant is near, but set it to 0 otherwise." % get_score_multiplier()
|
||||
|
||||
func get_score_multiplier():
|
||||
return level + 1
|
||||
return level + 1
|
||||
|
||||
func mutate_score(plant : Plant, score) -> int:
|
||||
for area in plant.influence_zone.get_overlapping_areas():
|
||||
if area is Plant and area != plant:
|
||||
return 0
|
||||
func mutate_score(_plant_state : Plant.State, plant : Plant, score) -> int:
|
||||
if plant.influence_zone == null:
|
||||
return score
|
||||
for area in plant.influence_zone.get_overlapping_areas():
|
||||
if area is Plant and area != plant:
|
||||
return 0
|
||||
|
||||
return score * get_score_multiplier()
|
||||
return score * get_score_multiplier()
|
||||
|
||||
@@ -13,5 +13,5 @@ func get_mutation_name() -> String:
|
||||
func get_mutation_description() -> String:
|
||||
return "Add [b]%d[/b] to the score while the plant is growing" % level
|
||||
|
||||
func mutate_score(plant : Plant, score) -> int:
|
||||
return score + (0 if plant.state == Plant.State.MATURE else level)
|
||||
func mutate_score(plant_state : Plant.State, _plant : Plant, score) -> int:
|
||||
return score + (0 if plant_state == Plant.State.MATURE else level)
|
||||
@@ -13,5 +13,5 @@ func get_mutation_name() -> String:
|
||||
func get_mutation_description() -> String:
|
||||
return "Add [b]%d[/b] to the score if the plant is mature." % level
|
||||
|
||||
func mutate_score(plant : Plant, score : int) -> int:
|
||||
return score + (level if plant.state == Plant.State.MATURE else 0)
|
||||
func mutate_score(plant_state : Plant.State, _plant : Plant, score : int) -> int:
|
||||
return score + (level if plant_state == Plant.State.MATURE else 0)
|
||||
@@ -18,8 +18,10 @@ func get_mutation_description() -> String:
|
||||
func get_score_bonus():
|
||||
return (level + 2)
|
||||
|
||||
func mutate_score(plant : Plant, score) -> int:
|
||||
if plant.state != Plant.State.MATURE:
|
||||
func mutate_score(plant_state : Plant.State, plant : Plant, score) -> int:
|
||||
if plant.influence_zone == null:
|
||||
return score
|
||||
if plant_state != Plant.State.MATURE:
|
||||
return score
|
||||
var plant_count = 0
|
||||
|
||||
|
||||
@@ -16,5 +16,5 @@ func get_mutation_description() -> String:
|
||||
func get_score_multiplier():
|
||||
return float(level)/2.
|
||||
|
||||
func mutate_score(_plant : Plant, score: int) -> int:
|
||||
func mutate_score(_plant_state : Plant.State, _plant : Plant, score: int) -> int:
|
||||
return score + roundi(score * get_score_multiplier())
|
||||
@@ -10,8 +10,8 @@ signal harvest_animation_finished
|
||||
|
||||
func update_plant_sprite(plant : Plant, with_animation = false):
|
||||
if with_animation:
|
||||
$AnimationPlayer.play("bump")
|
||||
await $AnimationPlayer.animation_finished
|
||||
%AnimationPlayer.play("bump")
|
||||
await %AnimationPlayer.animation_finished
|
||||
|
||||
%Sprite.flip_h = true if randi()%2 == 0 else false
|
||||
|
||||
@@ -43,7 +43,7 @@ func generate_mutation_effects(plant : Plant):
|
||||
particles_emitter.setup_particles(
|
||||
Particles.Parameters.new(
|
||||
m.get_icon(),
|
||||
PlantMutation.get_rarity_color(m)
|
||||
PlantMutation.get_rarity_color(m.get_rarity())
|
||||
)
|
||||
)
|
||||
add_child(particles_emitter)
|
||||
|
||||
92
entities/player/inventory/scripts/inventory.gd
Normal file
92
entities/player/inventory/scripts/inventory.gd
Normal file
@@ -0,0 +1,92 @@
|
||||
extends Resource
|
||||
class_name Inventory
|
||||
|
||||
signal updated(inventory: Inventory)
|
||||
|
||||
@export var items: Array[Item] = []
|
||||
@export var current_item_ind: int = 0
|
||||
|
||||
func _init(inventory_size: int = 1):
|
||||
items.resize(inventory_size)
|
||||
|
||||
func get_best_available_slot_ind():
|
||||
if items[current_item_ind] == null:
|
||||
return current_item_ind
|
||||
for i in items.size():
|
||||
if items[i] == null:
|
||||
return i
|
||||
return current_item_ind
|
||||
|
||||
func set_current_item(new_ind: int):
|
||||
if new_ind >= items.size():
|
||||
return
|
||||
|
||||
if new_ind != current_item_ind:
|
||||
current_item_ind = new_ind
|
||||
updated.emit(self)
|
||||
|
||||
func change_current_item(ind_mod: int):
|
||||
if items.size() == 0:
|
||||
current_item_ind = 0
|
||||
return
|
||||
var new_ind: int = current_item_ind + ind_mod
|
||||
new_ind = new_ind % items.size()
|
||||
if new_ind < 0:
|
||||
new_ind += items.size()
|
||||
set_current_item(new_ind)
|
||||
|
||||
func add_item(item: Item):
|
||||
var best_ind = get_best_available_slot_ind()
|
||||
if best_ind != current_item_ind:
|
||||
set_item(item, best_ind)
|
||||
updated.emit(self)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func set_item(item: Item, ind: int = 0) -> bool:
|
||||
if ind < 0 || ind >= items.size():
|
||||
return false
|
||||
while len(items) <= ind:
|
||||
items.append(null)
|
||||
items[ind] = item
|
||||
updated.emit(self)
|
||||
return true
|
||||
|
||||
func get_item(ind: int = current_item_ind) -> Item:
|
||||
if ind < 0 || items.size() <= ind:
|
||||
return null
|
||||
return items[ind]
|
||||
|
||||
func has_item(item: Item) -> bool:
|
||||
return item in items
|
||||
|
||||
func remove_item(item: Item):
|
||||
var ind = items.find(item)
|
||||
if ind >= 0:
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
|
||||
func remove_item_at(ind: int = current_item_ind):
|
||||
if items.size() <= ind:
|
||||
return
|
||||
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
|
||||
func remove_current_item():
|
||||
remove_item_at()
|
||||
|
||||
func pop_item(ind: int = current_item_ind) -> Item:
|
||||
if items.size() == 0:
|
||||
return
|
||||
|
||||
var item_removed: Item = items[ind]
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
return item_removed
|
||||
|
||||
func is_full():
|
||||
for i in items:
|
||||
if i == null : return false
|
||||
return true
|
||||
1
entities/player/inventory/scripts/inventory.gd.uid
Normal file
1
entities/player/inventory/scripts/inventory.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://fnu2d6wna4yc
|
||||
81
entities/player/inventory/scripts/item.gd
Normal file
81
entities/player/inventory/scripts/item.gd
Normal file
@@ -0,0 +1,81 @@
|
||||
extends Resource
|
||||
class_name Item
|
||||
|
||||
const TYPE_ICON = preload("res://common/icons/backpack.svg")
|
||||
const ACTION_ICON = preload("res://common/icons/swipe-down.svg")
|
||||
const ENERGY_ICON = preload("res://common/icons/bolt.svg")
|
||||
const ONE_TIME_ICON = preload("res://common/icons/circle-number-1.svg")
|
||||
|
||||
var name: String : get = get_item_name
|
||||
var description: String : get = get_description
|
||||
var icon: Texture2D : get = get_icon
|
||||
var usage_zone_radius: int = 5 : get = get_usage_zone_radius
|
||||
var energy_usage : int = 1 : get = get_energy_used
|
||||
|
||||
func get_item_name() -> String:
|
||||
return name
|
||||
|
||||
func get_description() -> String:
|
||||
return description
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return icon
|
||||
|
||||
func get_energy_used() -> int:
|
||||
return energy_usage
|
||||
|
||||
func get_usage_zone_radius() -> int:
|
||||
return usage_zone_radius
|
||||
|
||||
func get_usage_object_affected(_i : InspectableEntity) -> bool:
|
||||
return false
|
||||
|
||||
func is_one_time_use():
|
||||
return false
|
||||
|
||||
func can_use(_player : Player, zone: Player.ActionZone) -> bool:
|
||||
return false
|
||||
|
||||
func use_text() -> String:
|
||||
return ""
|
||||
|
||||
func use(_player : Player, zone: Player.ActionZone):
|
||||
return false
|
||||
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
get_item_name()
|
||||
)
|
||||
info.texture = icon
|
||||
info.type_icon = TYPE_ICON
|
||||
|
||||
info.stats.append(
|
||||
CardStatInfo.new(
|
||||
"Cost %d energy" % energy_usage,
|
||||
ENERGY_ICON
|
||||
)
|
||||
)
|
||||
|
||||
if is_one_time_use():
|
||||
info.stats.append(
|
||||
CardStatInfo.new(
|
||||
"One time use",
|
||||
ONE_TIME_ICON
|
||||
)
|
||||
)
|
||||
|
||||
var effect_section = CardSectionInfo.new(
|
||||
"Effect",
|
||||
get_description()
|
||||
)
|
||||
effect_section.title_icon = ACTION_ICON
|
||||
|
||||
if energy_usage > 0:
|
||||
effect_section.title_icon = ENERGY_ICON
|
||||
|
||||
info.sections.append(effect_section)
|
||||
|
||||
return info
|
||||
|
||||
func get_particles() -> Array[Particles.Parameters]:
|
||||
return []
|
||||
1
entities/player/inventory/scripts/item.gd.uid
Normal file
1
entities/player/inventory/scripts/item.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bq7admu4ahs5r
|
||||
42
entities/player/inventory/scripts/items/blueprint.gd
Normal file
42
entities/player/inventory/scripts/items/blueprint.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
extends Item
|
||||
class_name Blueprint
|
||||
|
||||
@export var machine_type: MachineType
|
||||
@export var machine_level: int = 1
|
||||
|
||||
func _init(_machine_type : MachineType = null, _machine_level : int = 1):
|
||||
machine_type = _machine_type
|
||||
machine_level = _machine_level
|
||||
|
||||
func get_item_name() -> String:
|
||||
if machine_type:
|
||||
return machine_type.name
|
||||
return ""
|
||||
|
||||
func get_description() -> String:
|
||||
if machine_type:
|
||||
return machine_type.description
|
||||
return ""
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return preload("res://common/icons/cube-3d-sphere.svg")
|
||||
|
||||
func use_text() -> String:
|
||||
if machine_type:
|
||||
return "Build " + machine_type.name
|
||||
return ""
|
||||
|
||||
func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
return player.terrain is Planet
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
if machine_type and machine_level and player.planet:
|
||||
player.planet.add_entity(
|
||||
Machine.instantiate_machine(machine_type, machine_level),
|
||||
zone.get_global_position()
|
||||
)
|
||||
return true
|
||||
return false
|
||||
1
entities/player/inventory/scripts/items/blueprint.gd.uid
Normal file
1
entities/player/inventory/scripts/items/blueprint.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dcowcvjk2m7va
|
||||
44
entities/player/inventory/scripts/items/fork.gd
Normal file
44
entities/player/inventory/scripts/items/fork.gd
Normal file
@@ -0,0 +1,44 @@
|
||||
extends Item
|
||||
class_name Fork
|
||||
|
||||
const USE_INTERVAL = 0.15
|
||||
|
||||
func get_item_name() -> String:
|
||||
return "Fork"
|
||||
|
||||
func get_description() -> String:
|
||||
return "Use it to harvest mature plants."
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return preload("res://common/icons/fork.svg")
|
||||
|
||||
func get_energy_used() -> int:
|
||||
return 1
|
||||
|
||||
func get_usage_zone_radius() -> int:
|
||||
return 50
|
||||
|
||||
func get_usage_object_affected(i : InspectableEntity) -> bool:
|
||||
return i is Plant
|
||||
|
||||
func use_text() -> String:
|
||||
return "Harvest"
|
||||
|
||||
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
|
||||
var areas = zone.get_affected_areas()
|
||||
for area in areas :
|
||||
if area is Plant:
|
||||
return true
|
||||
return false
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
for area in zone.get_affected_areas():
|
||||
if area and area is Plant:
|
||||
harvest(area, player)
|
||||
await player.get_tree().create_timer(USE_INTERVAL).timeout
|
||||
|
||||
return true
|
||||
|
||||
func harvest(p : Plant, player: Player):
|
||||
player.play_sfx("harvest")
|
||||
p.harvest()
|
||||
1
entities/player/inventory/scripts/items/fork.gd.uid
Normal file
1
entities/player/inventory/scripts/items/fork.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cg5to3g2bqyks
|
||||
19
entities/player/inventory/scripts/items/knife.gd
Normal file
19
entities/player/inventory/scripts/items/knife.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Fork
|
||||
class_name Knife
|
||||
|
||||
const KNIFE_ZONE_RADIUS = 10
|
||||
|
||||
func get_item_name() -> String:
|
||||
return "Knife"
|
||||
|
||||
func get_description() -> String:
|
||||
return "Use it to harvest mature plants. Do not cost energy."
|
||||
|
||||
func get_energy_used() -> int:
|
||||
return 0
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return preload("res://common/icons/slice.svg")
|
||||
|
||||
func get_usage_zone_radius() -> int:
|
||||
return KNIFE_ZONE_RADIUS
|
||||
1
entities/player/inventory/scripts/items/knife.gd.uid
Normal file
1
entities/player/inventory/scripts/items/knife.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://clyixfqc8rmo
|
||||
32
entities/player/inventory/scripts/items/package.gd
Normal file
32
entities/player/inventory/scripts/items/package.gd
Normal file
@@ -0,0 +1,32 @@
|
||||
extends Item
|
||||
class_name Package
|
||||
|
||||
@export var scene: PackedScene
|
||||
@export var package_name : String
|
||||
@export_multiline var package_description : String
|
||||
|
||||
|
||||
func _init(_scene : PackedScene = null):
|
||||
scene = _scene
|
||||
|
||||
func get_item_name() -> String:
|
||||
return package_name
|
||||
|
||||
func get_description() -> String:
|
||||
return package_description
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return preload("res://common/icons/package.svg")
|
||||
|
||||
func use_text() -> String:
|
||||
return "Open"
|
||||
|
||||
func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
return player.planet != null
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
player.planet.instantiate_entity(scene, zone.get_global_position())
|
||||
return true
|
||||
1
entities/player/inventory/scripts/items/package.gd.uid
Normal file
1
entities/player/inventory/scripts/items/package.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b6kubqgq0k7vj
|
||||
194
entities/player/inventory/scripts/items/seed.gd
Normal file
194
entities/player/inventory/scripts/items/seed.gd
Normal file
@@ -0,0 +1,194 @@
|
||||
extends Item
|
||||
class_name Seed
|
||||
|
||||
const MUTATION_PROBABILITY = 0.3
|
||||
|
||||
const SHOVEL_ICON = preload("res://common/icons/shovel.svg")
|
||||
const GROWING_ICON = preload("res://common/icons/chevrons-up.svg")
|
||||
const SCORE_ICON = preload("res://common/icons/growth.svg")
|
||||
|
||||
@export var plant_type: PlantType
|
||||
@export var plant_mutations: Array[PlantMutation]
|
||||
|
||||
func get_item_name() -> String:
|
||||
return "%s Seed" % plant_type.name
|
||||
|
||||
func get_description() -> String:
|
||||
return "Plant [b]%s[/b]. Must be used in decontamined zone." % plant_type.name
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return plant_type.seed_texture
|
||||
|
||||
func get_energy_used() -> int:
|
||||
return 1
|
||||
|
||||
func get_usage_zone_radius() -> int:
|
||||
return 30
|
||||
|
||||
func get_usage_object_affected(i : InspectableEntity) -> bool:
|
||||
return i is Plant
|
||||
|
||||
func _init(
|
||||
_plant_type : PlantType = null,
|
||||
_parent_mutation : Array[PlantMutation] = []
|
||||
):
|
||||
plant_type = _plant_type
|
||||
plant_mutations = Seed.mutate(_parent_mutation)
|
||||
|
||||
func use_text() -> String:
|
||||
return "Plant " + plant_type.name
|
||||
|
||||
func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
if (
|
||||
player.planet == null
|
||||
or not player.planet.garden.is_in_garden(zone.get_global_position())
|
||||
):
|
||||
return false
|
||||
|
||||
var is_there_a_plant_here = false
|
||||
for area in zone.get_affected_areas():
|
||||
if area is Plant:
|
||||
is_there_a_plant_here = true
|
||||
|
||||
var is_there_contamination_in_zone = false
|
||||
for point in zone.get_points_in_zone():
|
||||
if player.planet.garden.is_there_contamination(point):
|
||||
is_there_contamination_in_zone = true
|
||||
|
||||
return not is_there_a_plant_here and not is_there_contamination_in_zone
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
if player.planet == null:
|
||||
return false
|
||||
|
||||
player.play_sfx("dig")
|
||||
return player.planet.plant(
|
||||
plant_type,
|
||||
zone.get_global_position(),
|
||||
plant_mutations
|
||||
)
|
||||
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
get_item_name()
|
||||
)
|
||||
info.texture = icon
|
||||
info.type_icon = TYPE_ICON
|
||||
|
||||
info.stats.append(
|
||||
CardStatInfo.new(
|
||||
"Cost %d energy" % energy_usage,
|
||||
ENERGY_ICON
|
||||
)
|
||||
)
|
||||
|
||||
if is_one_time_use():
|
||||
info.stats.append(
|
||||
CardStatInfo.new(
|
||||
"One time use",
|
||||
ONE_TIME_ICON
|
||||
)
|
||||
)
|
||||
|
||||
var effect_section = CardSectionInfo.new(
|
||||
"Effect",
|
||||
get_description()
|
||||
)
|
||||
effect_section.title_icon = ACTION_ICON
|
||||
|
||||
if energy_usage > 0:
|
||||
effect_section.title_icon = ENERGY_ICON
|
||||
|
||||
info.sections.append(effect_section)
|
||||
|
||||
if len(plant_mutations) != 0:
|
||||
var rarest : int = plant_mutations.map(
|
||||
func(m : PlantMutation) : return m.get_rarity()
|
||||
).max()
|
||||
info.bg_color = PlantMutation.get_rarity_color(rarest)
|
||||
for m in plant_mutations:
|
||||
info.sections.append(m.card_section())
|
||||
|
||||
return info
|
||||
|
||||
|
||||
func get_particles() -> Array[Particles.Parameters]:
|
||||
var param : Array[Particles.Parameters] = []
|
||||
|
||||
for m in plant_mutations:
|
||||
param.append(
|
||||
Particles.Parameters.new(
|
||||
m.get_icon(),
|
||||
PlantMutation.get_rarity_color(m.get_rarity())
|
||||
)
|
||||
)
|
||||
|
||||
return param
|
||||
|
||||
static func mutate(parent_mutation : Array[PlantMutation] = []) -> Array[PlantMutation]:
|
||||
|
||||
if randf() > MUTATION_PROBABILITY:
|
||||
return parent_mutation
|
||||
|
||||
var possible_mutations : Array[MutationPossibility] = [
|
||||
AddMutation.new()
|
||||
]
|
||||
|
||||
if len(parent_mutation):
|
||||
possible_mutations.append_array( [
|
||||
UpgradeMutation.new(),
|
||||
RemoveMutation.new(),
|
||||
])
|
||||
|
||||
var chosen_mutation = possible_mutations.pick_random()
|
||||
|
||||
return chosen_mutation.mutate(parent_mutation)
|
||||
|
||||
|
||||
class MutationPossibility:
|
||||
func mutate(_parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
return []
|
||||
|
||||
class DontMutate extends MutationPossibility:
|
||||
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
return parent_mutation
|
||||
|
||||
class AddMutation extends MutationPossibility:
|
||||
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
var new_mutations = parent_mutation.duplicate_deep()
|
||||
var mut = PlantMutation.random_mutation()
|
||||
|
||||
if mut:
|
||||
var existing_mut_id = new_mutations.find_custom(func(m:PlantMutation): m.get_mutation_name() == mut.get_mutation_name())
|
||||
|
||||
if existing_mut_id >= 0:
|
||||
new_mutations[existing_mut_id].level += 1
|
||||
else :
|
||||
new_mutations.append(mut)
|
||||
|
||||
return new_mutations
|
||||
|
||||
class UpgradeMutation extends MutationPossibility:
|
||||
func mutate(
|
||||
parent_mutation : Array[PlantMutation] = []
|
||||
) -> Array[PlantMutation]:
|
||||
var new_mutations = parent_mutation.duplicate_deep()
|
||||
|
||||
new_mutations.pick_random().level += 1
|
||||
|
||||
return new_mutations
|
||||
|
||||
class RemoveMutation extends MutationPossibility:
|
||||
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
var new_mutations :Array[PlantMutation] = parent_mutation.duplicate_deep()
|
||||
|
||||
var mut_to_remove = new_mutations.pick_random()
|
||||
if mut_to_remove.level > 1:
|
||||
mut_to_remove.level -= 1
|
||||
else:
|
||||
new_mutations.remove_at(new_mutations.find(mut_to_remove))
|
||||
|
||||
return new_mutations
|
||||
1
entities/player/inventory/scripts/items/seed.gd.uid
Normal file
1
entities/player/inventory/scripts/items/seed.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bypjcvlc15gsm
|
||||
44
entities/player/inventory/scripts/items/shovel.gd
Normal file
44
entities/player/inventory/scripts/items/shovel.gd
Normal file
@@ -0,0 +1,44 @@
|
||||
extends Fork
|
||||
class_name Shovel
|
||||
|
||||
const SHOVEL_ZONE_RADIUS = 50
|
||||
|
||||
func get_item_name() -> String:
|
||||
return "Shovel"
|
||||
|
||||
func get_description() -> String:
|
||||
return "Can dig up buried seeds and can be used to harvest mature plants."
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return preload("res://common/icons/shovel.svg")
|
||||
|
||||
func get_usage_zone_radius() -> int:
|
||||
return SHOVEL_ZONE_RADIUS
|
||||
|
||||
func get_usage_object_affected(i : InspectableEntity) -> bool:
|
||||
return i is Plant or i is UndergroundLoot
|
||||
|
||||
func use_text() -> String:
|
||||
return "Dig"
|
||||
|
||||
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
|
||||
var areas = zone.get_affected_areas()
|
||||
for area in areas :
|
||||
if area is Plant or area is UndergroundLoot:
|
||||
return true
|
||||
return false
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
for area in zone.get_affected_areas():
|
||||
if area and area is Plant:
|
||||
harvest(area, player)
|
||||
await player.get_tree().create_timer(USE_INTERVAL).timeout
|
||||
if area and area is UndergroundLoot:
|
||||
dig(area, player)
|
||||
await player.get_tree().create_timer(USE_INTERVAL).timeout
|
||||
|
||||
return true
|
||||
|
||||
func dig(u: UndergroundLoot, player: Player):
|
||||
player.play_sfx("dig")
|
||||
u.dig()
|
||||
1
entities/player/inventory/scripts/items/shovel.gd.uid
Normal file
1
entities/player/inventory/scripts/items/shovel.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dya38x1h1uiyg
|
||||
21
entities/player/inventory/scripts/items/trowel.gd
Normal file
21
entities/player/inventory/scripts/items/trowel.gd
Normal file
@@ -0,0 +1,21 @@
|
||||
extends Fork
|
||||
class_name Trowel
|
||||
|
||||
const TROWEL_ZONE_RADIUS = 50
|
||||
|
||||
func get_item_name() -> String:
|
||||
return "Trowel"
|
||||
|
||||
func get_description() -> String:
|
||||
return "Use it to harvest mature plants, can get a [b]bonus seed[/b] from each plant."
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return preload("res://common/icons/trowel.svg")
|
||||
|
||||
func get_usage_zone_radius() -> int:
|
||||
return TROWEL_ZONE_RADIUS
|
||||
|
||||
func harvest(p : Plant, player: Player):
|
||||
ProduceSeedsEffect.new(1).effect(p)
|
||||
player.play_sfx("harvest")
|
||||
p.harvest()
|
||||
1
entities/player/inventory/scripts/items/trowel.gd.uid
Normal file
1
entities/player/inventory/scripts/items/trowel.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://gvq5vic12srt
|
||||
@@ -3,8 +3,6 @@ class_name Player
|
||||
|
||||
const MAX_REACH = 100
|
||||
const HOLDING_ITEM_SPRITE_SIZE = 20.
|
||||
const DEFAULT_INVENTORY_SIZE = 2
|
||||
const DEFAULT_MAX_ENERGY = 2
|
||||
|
||||
signal player_updated(player: Player)
|
||||
signal upgraded
|
||||
@@ -14,9 +12,10 @@ var planet : Planet :
|
||||
get(): return terrain if terrain is Planet else null
|
||||
@export var speed = 350
|
||||
|
||||
var max_energy : int = DEFAULT_MAX_ENERGY
|
||||
var has_just_received_instruction : bool = false # pour récupérer les zones dans les action_area, une frame doit être passée depuis la création de la zone
|
||||
|
||||
var data : PlayerData
|
||||
|
||||
var controlling_player : bool = true :
|
||||
set(v):
|
||||
controlling_player = v
|
||||
@@ -24,28 +23,23 @@ var controlling_player : bool = true :
|
||||
|
||||
var instruction : Instruction = null
|
||||
|
||||
var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
player_updated.emit(self)
|
||||
|
||||
@onready var inventory : Inventory = Inventory.new(DEFAULT_INVENTORY_SIZE)
|
||||
@onready var preview_zone : ActionZone = null
|
||||
@onready var action_zone : ActionZone = null
|
||||
@onready var preview_zone : ActionZone = setup_action_zone(Vector2.ZERO, null)
|
||||
@onready var action_zone : ActionZone = setup_action_zone(Vector2.ZERO, null)
|
||||
|
||||
func _ready():
|
||||
data = GameInfo.game_data.player_data
|
||||
data.inventory.updated.connect(_on_inventory_updated)
|
||||
player_updated.emit(self)
|
||||
inventory.inventory_changed.connect(_on_inventory_updated)
|
||||
Pointer.player = self
|
||||
|
||||
func _input(_event) -> void:
|
||||
if Input.is_action_pressed("change_item_left"):
|
||||
inventory.change_current_item(1)
|
||||
data.inventory.change_current_item(1)
|
||||
if Input.is_action_pressed("change_item_right"):
|
||||
inventory.change_current_item(-1)
|
||||
data.inventory.change_current_item(-1)
|
||||
for i in range(1, 10):
|
||||
if Input.is_action_pressed("item_" + str(i)):
|
||||
inventory.set_current_item(i - 1)
|
||||
data.inventory.set_current_item(i - 1)
|
||||
|
||||
# Méthode déclenchée par la classe planet
|
||||
func _start_pass_day():
|
||||
@@ -80,8 +74,8 @@ func _process(_delta):
|
||||
move_and_slide()
|
||||
|
||||
func _on_inventory_updated(_inventory: Inventory):
|
||||
var item : Item = inventory.get_item()
|
||||
setup_preview_zone(item)
|
||||
setup_preview_zone(data.inventory.get_item())
|
||||
var item : Item = data.inventory.get_item()
|
||||
if item:
|
||||
var item_texture = item.icon
|
||||
%ItemSprite.texture = item_texture
|
||||
@@ -128,27 +122,30 @@ func try_move(move_to : Vector2):
|
||||
|
||||
func pick_item(item : Item) -> Item:
|
||||
play_sfx("pick")
|
||||
if inventory.is_full():
|
||||
if data.inventory.is_full():
|
||||
drop_item()
|
||||
|
||||
var available_slot_ind = inventory.get_best_available_slot_ind()
|
||||
if available_slot_ind == inventory.current_item_ind && inventory.items[available_slot_ind] != null:
|
||||
var current_item : Item = inventory.get_item()
|
||||
inventory.set_item(item, available_slot_ind)
|
||||
var available_slot_ind = data.inventory.get_best_available_slot_ind()
|
||||
if (
|
||||
available_slot_ind == data.inventory.current_item_ind
|
||||
&& data.inventory.items[available_slot_ind] != null
|
||||
):
|
||||
var current_item : Item = data.inventory.get_item()
|
||||
data.inventory.set_item(item, available_slot_ind)
|
||||
return current_item
|
||||
else :
|
||||
if inventory.set_item(item, available_slot_ind):
|
||||
inventory.set_current_item(available_slot_ind);
|
||||
if data.inventory.set_item(item, available_slot_ind):
|
||||
data.inventory.set_current_item(available_slot_ind);
|
||||
return null
|
||||
|
||||
func drop_item():
|
||||
var item_to_drop = inventory.pop_item()
|
||||
var item_to_drop = data.inventory.pop_item()
|
||||
if item_to_drop:
|
||||
terrain.drop_item(item_to_drop, global_position)
|
||||
play_sfx("drop")
|
||||
|
||||
func delete_item(item: Item):
|
||||
inventory.remove_item(item)
|
||||
data.inventory.remove_item(item)
|
||||
|
||||
func try_use_item(item : Item, use_position : Vector2):
|
||||
has_just_received_instruction = true
|
||||
@@ -163,7 +160,7 @@ func preview_could_use_item(item : Item) -> bool:
|
||||
|
||||
func could_use_item_on_zone(item : Item, zone: ActionZone) -> bool:
|
||||
return (
|
||||
inventory.has_item(item)
|
||||
data.inventory.has_item(item)
|
||||
and item.can_use(self, zone)
|
||||
)
|
||||
|
||||
@@ -174,32 +171,32 @@ func can_use_item_on_zone(item : Item, zone: ActionZone) -> bool:
|
||||
)
|
||||
|
||||
func has_energy_to_use_item(item : Item):
|
||||
return (energy - item.energy_usage) >= 0
|
||||
return (data.energy - item.energy_usage) >= 0
|
||||
|
||||
func use_item(item : Item):
|
||||
if can_use_item_on_zone(item, action_zone):
|
||||
var is_item_used = await item.use(self, action_zone)
|
||||
if is_item_used:
|
||||
energy -= item.energy_usage
|
||||
data.energy -= item.energy_usage
|
||||
if item.is_one_time_use():
|
||||
inventory.remove_item(item)
|
||||
data.inventory.remove_item(item)
|
||||
|
||||
func upgrade_max_energy(amount = 1):
|
||||
max_energy += amount
|
||||
data.max_energy += amount
|
||||
upgraded.emit()
|
||||
player_updated.emit(self)
|
||||
|
||||
func upgrade_inventory_size(amount = 1):
|
||||
inventory.items.resize(inventory.items.size() + amount)
|
||||
data.inventory.items.resize(data.inventory.items.size() + amount)
|
||||
upgraded.emit()
|
||||
player_updated.emit(self)
|
||||
|
||||
func recharge(amount : int = max_energy):
|
||||
energy = energy + amount
|
||||
func recharge(amount : int = data.max_energy):
|
||||
data.energy += + amount
|
||||
upgraded.emit()
|
||||
|
||||
func full_recharge():
|
||||
energy = max(energy, max_energy)
|
||||
data.energy = max(data.energy, data.max_energy)
|
||||
|
||||
func generate_action_zone(item : Item) -> ActionZone:
|
||||
var zone = ActionZone.new(item)
|
||||
@@ -226,7 +223,7 @@ func setup_action_zone(zone_position : Vector2, item: Item) -> ActionZone:
|
||||
if action_zone:
|
||||
action_zone.destroy()
|
||||
action_zone = generate_action_zone(item)
|
||||
action_zone.area.global_position = zone_position
|
||||
action_zone.move_to_position(zone_position)
|
||||
return action_zone
|
||||
|
||||
func move_preview_zone(zone_position : Vector2):
|
||||
@@ -320,11 +317,13 @@ class ActionZone:
|
||||
affected_areas = new_affected_areas
|
||||
|
||||
func get_affected_areas() -> Array[Area2D]:
|
||||
return [] if area == null else area.get_overlapping_areas()
|
||||
var empty_array : Array[Area2D] = []
|
||||
return empty_array if area == null else area.get_overlapping_areas()
|
||||
|
||||
func destroy():
|
||||
clear_preview_on_affected_area()
|
||||
area.queue_free()
|
||||
if area:
|
||||
area.queue_free()
|
||||
|
||||
func get_global_position() -> Vector2:
|
||||
return Vector2.ZERO if area == null else area.global_position
|
||||
|
||||
17
entities/player/scripts/player_data.gd
Normal file
17
entities/player/scripts/player_data.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends Resource
|
||||
class_name PlayerData
|
||||
|
||||
signal updated(player_data : PlayerData)
|
||||
|
||||
const DEFAULT_MAX_ENERGY = 2
|
||||
const DEFAULT_INVENTORY_SIZE = 3
|
||||
|
||||
@export var max_energy : int = DEFAULT_MAX_ENERGY :
|
||||
set(v):
|
||||
max_energy = v
|
||||
updated.emit(self)
|
||||
@export var energy : int = DEFAULT_MAX_ENERGY :
|
||||
set(v):
|
||||
energy = v
|
||||
updated.emit(self)
|
||||
@export var inventory = Inventory.new(DEFAULT_INVENTORY_SIZE)
|
||||
1
entities/player/scripts/player_data.gd.uid
Normal file
1
entities/player/scripts/player_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d4kdfrdv83xve
|
||||
9
entities/scripts/entity.gd
Normal file
9
entities/scripts/entity.gd
Normal file
@@ -0,0 +1,9 @@
|
||||
extends Area2D
|
||||
class_name Entity
|
||||
|
||||
var terrain : Terrain
|
||||
var planet : Planet :
|
||||
get(): return terrain if terrain is Planet else null
|
||||
|
||||
func save() -> EntityData:
|
||||
return null
|
||||
1
entities/scripts/entity.gd.uid
Normal file
1
entities/scripts/entity.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dxb383bmy4kdx
|
||||
13
entities/scripts/entity_data.gd
Normal file
13
entities/scripts/entity_data.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
extends Resource
|
||||
class_name EntityData
|
||||
|
||||
@export var position : Vector2
|
||||
|
||||
func _init(e : Entity):
|
||||
position = e.global_position
|
||||
|
||||
func get_position() -> Vector2:
|
||||
return position
|
||||
|
||||
func load() -> Entity:
|
||||
return null
|
||||
1
entities/scripts/entity_data.gd.uid
Normal file
1
entities/scripts/entity_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bgbbce45hjv3d
|
||||
@@ -1,15 +1,12 @@
|
||||
extends Area2D
|
||||
extends Entity
|
||||
class_name InspectableEntity
|
||||
|
||||
const MODULATE_INSPECTED_COLOR = Color.GRAY
|
||||
const MODULATE_AFFECTED_COLOR = Color.RED
|
||||
|
||||
var terrain : Terrain
|
||||
var planet : Planet :
|
||||
get(): return terrain if terrain is Planet else null
|
||||
const DESC_ICON = preload("res://common/icons/align-right.svg")
|
||||
|
||||
@export var default_info_title = ""
|
||||
@export var default_info_desc = ""
|
||||
@export_multiline var default_info_desc = ""
|
||||
|
||||
@onready var default_modulate : Color = modulate
|
||||
@onready var inspectable_signals_setuped : bool = setup_inspectable_signals()
|
||||
@@ -26,7 +23,7 @@ func setup_inspectable_signals() -> bool:
|
||||
return true
|
||||
|
||||
func _on_mouse_entered():
|
||||
Pointer.inspect(self, inspector_info())
|
||||
Pointer.inspect(self)
|
||||
|
||||
func _on_mouse_excited():
|
||||
Pointer.stop_inspect(self)
|
||||
@@ -34,12 +31,23 @@ func _on_mouse_excited():
|
||||
func pointer_text() -> String:
|
||||
return default_info_title
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
pointer_text(),
|
||||
default_info_desc
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
pointer_text()
|
||||
)
|
||||
|
||||
if default_info_desc != "":
|
||||
var desc_section = CardSectionInfo.new(
|
||||
"Description",
|
||||
default_info_desc
|
||||
)
|
||||
desc_section.title_icon = DESC_ICON
|
||||
info.sections.append(
|
||||
desc_section
|
||||
)
|
||||
|
||||
return info
|
||||
|
||||
func _notification(what):
|
||||
if (what == NOTIFICATION_PREDELETE):
|
||||
Pointer.stop_inspect(self)
|
||||
|
||||
@@ -12,15 +12,13 @@ const SPRITE_SCENE : PackedScene = preload("res://entities/underground_loot/unde
|
||||
@onready var collision_shape: CollisionShape2D = generate_collision_shape()
|
||||
|
||||
|
||||
func _init(_loot : Array[Item] = []):
|
||||
loot = _loot
|
||||
default_info_desc = "Contain some random seeds. [b]Dig it with a shovel.[/b]"
|
||||
|
||||
func pointer_text() -> String:
|
||||
return "Buried Loot"
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
"Buried Loot",
|
||||
"Can contain some seeds from the past... Dig it with a shovel."
|
||||
)
|
||||
|
||||
func generate_sprite() -> Node2D:
|
||||
var object = SPRITE_SCENE.instantiate()
|
||||
|
||||
@@ -42,3 +40,6 @@ func dig():
|
||||
for item in loot:
|
||||
planet.drop_item(item, global_position, LOOTED_ITEM_RANDOM_RANGE)
|
||||
queue_free()
|
||||
|
||||
func save() -> UndergroundLootData:
|
||||
return UndergroundLootData.new(self)
|
||||
11
entities/underground_loot/scripts/underground_loot_data.gd
Normal file
11
entities/underground_loot/scripts/underground_loot_data.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends EntityData
|
||||
class_name UndergroundLootData
|
||||
|
||||
@export var loot : Array[Item]
|
||||
|
||||
func _init(e : UndergroundLoot):
|
||||
position = e.global_position
|
||||
loot = e.loot
|
||||
|
||||
func load() -> Entity:
|
||||
return UndergroundLoot.new(loot)
|
||||
@@ -0,0 +1 @@
|
||||
uid://68plwch6h4f7
|
||||
Reference in New Issue
Block a user