Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block #114

Merged
merged 24 commits into from
Aug 7, 2024
Merged

Block #114

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion #Scenes/MainMenu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=3 format=3 uid="uid://chw8kc2q4o3pi"]
[gd_scene load_steps=3 format=3 uid="uid://dpmfv4x71bcw7"]

[ext_resource type="Script" path="res://#Scenes/SceneScripts/MainMenu.gd" id="1_mwp8y"]
[ext_resource type="Texture2D" uid="uid://u5naod8gur3m" path="res://Art/Menus/main_menu_bg-1.png" id="2_v07no"]
Expand Down
2 changes: 1 addition & 1 deletion #Scenes/OptionsMenu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=3 format=3 uid="uid://m1u72kig8f0q"]
[gd_scene load_steps=3 format=3 uid="uid://6i7r2gngfp0p"]

[ext_resource type="Texture2D" uid="uid://dyquabho0a3me" path="res://Art/Menus/options_menu_back-1.png" id="1_a6abe"]
[ext_resource type="Script" path="res://#Scenes/SceneScripts/OptionsMenu.gd" id="1_rms2r"]
Expand Down
4 changes: 2 additions & 2 deletions #Scenes/TestingScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
[ext_resource type="Texture2D" uid="uid://caemucaya30wh" path="res://Art/Card_layout/draw_pile.png" id="11_pw70x"]
[ext_resource type="Texture2D" uid="uid://d4muqvs3etnr8" path="res://Art/Card_layout/discard_pile.png" id="12_kxw48"]
[ext_resource type="Script" path="res://UI/EndTurnButton.gd" id="14_dpe64"]
[ext_resource type="PackedScene" uid="uid://bam77cwf4emyr" path="res://#Scenes/TopBarOverlay.tscn" id="14_e54tj"]
[ext_resource type="PackedScene" path="res://#Scenes/TopBarOverlay.tscn" id="14_e54tj"]
[ext_resource type="Script" path="res://UI/EnergyLabel.gd" id="14_nckre"]
[ext_resource type="Resource" uid="uid://c5fh7bnfh3l4u" path="res://Items/test_relic.tres" id="19_prw12"]
[ext_resource type="Resource" path="res://Items/test_relic.tres" id="19_prw12"]
[ext_resource type="Texture2D" uid="uid://bl5v3bgnntoc5" path="res://Art/Card_layout/energy_count.png" id="19_spyxg"]

[sub_resource type="GDScript" id="GDScript_g5yv1"]
Expand Down
Binary file added Art/Menus/shield-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Art/Menus/shield-1.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://162qbj2n5rm4"
path="res://.godot/imported/shield-1.png-a3ab29596ac07db89e830f72943c1d28.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Art/Menus/shield-1.png"
dest_files=["res://.godot/imported/shield-1.png-a3ab29596ac07db89e830f72943c1d28.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
10 changes: 10 additions & 0 deletions Cards/Effects/EffectAddBlock.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends EffectBase
class_name EffectAddBlock
## gives block to an entity. [br]
##
## This effect gives block to target entity equal to the value given[br]

## @Override [br]
## Refer to [EffectBase]
func apply_effect(_caster: Entity, _target: Entity, value: int) -> void:
_target.get_health_component().add_block(value, _caster)
2 changes: 1 addition & 1 deletion Cards/Effects/EffectAddEnergy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class_name EffectAddEnergy extends EffectBase
## @Override [br]
## Refer to [EffectBase]
func apply_effect(_caster: Entity, _target: Entity, value: int) -> void:
PlayerManager.player.get_energy_component().add_energy(value)
PlayerManager.player.get_energy_component().add_energy(value)
4 changes: 2 additions & 2 deletions Cards/Effects/EffectDamage.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class_name EffectDamage extends EffectBase
## Refer to [EffectBase]
func apply_effect(caster: Entity, target: Entity, value: int) -> void:
# calculate modified damage given caster and target stats
var damage: float = EntityStats.get_value_modified_by_stats(GlobalEnums.PossibleModifierNames.DAMAGE, caster, target, value)
var damage: int = EntityStats.get_value_modified_by_stats(GlobalEnums.PossibleModifierNames.DAMAGE, caster, target, value)

target.get_health_component().modify_health(damage, caster)
target.get_health_component().take_damage_block_and_health(damage, caster)

4 changes: 2 additions & 2 deletions Cards/Effects/EffectDraw.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class_name EffectDraw extends EffectBase
## @Override [br]
## Refer to [EffectBase]
func apply_effect(caster: Entity, target: Entity, value: int) -> void:
var modified_value: int = EntityStats.get_value_modified_by_stats(GlobalEnums.PossibleModifierNames.DRAW, caster, target, value)
CardManager.card_container.draw_cards(modified_value)
var modified_value: int = EntityStats.get_value_modified_by_stats(GlobalEnums.PossibleModifierNames.DRAW, caster, target, value)
CardManager.card_container.draw_cards(modified_value)
4 changes: 2 additions & 2 deletions Cards/Effects/EffectHeal.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class_name EffectHeal extends EffectBase
func apply_effect(caster: Entity, target: Entity, value: int) -> void:

# calculate modified heal given caster and target stats
var heal: float = EntityStats.get_value_modified_by_stats(GlobalEnums.PossibleModifierNames.HEAL, caster, target, value)
var heal: int = EntityStats.get_value_modified_by_stats(GlobalEnums.PossibleModifierNames.HEAL, caster, target, value)

target.get_health_component().modify_health(heal, caster, true)
target.get_health_component().heal(heal, caster)
2 changes: 1 addition & 1 deletion Cards/Effects/EffectStress.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class_name EffectStress extends EffectBase
func apply_effect(caster: Entity, target: Entity, value: int) -> void:
var stress_increase: int = EntityStats.get_value_modified_by_stats(GlobalEnums.PossibleModifierNames.STRESS, caster, target, value)

target.get_stress_component().modify_stress(stress_increase, caster)
target.get_stress_component().modify_stress(stress_increase, caster)
4 changes: 2 additions & 2 deletions Cards/Resource/Card_Banana.tres
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_resource type="Resource" script_class="CardBase" load_steps=13 format=3 uid="uid://c4nm7mbdlsf6r"]
[gd_resource type="Resource" script_class="CardBase" load_steps=13 format=3 uid="uid://c8kpsky7tt3yq"]

[ext_resource type="PackedScene" uid="uid://dicabrkoa6bvl" path="res://Cards/Animation/Scene/Anim_Banana.tscn" id="1_ggtdb"]
[ext_resource type="PackedScene" path="res://Cards/Animation/Scene/Anim_Banana.tscn" id="1_ggtdb"]
[ext_resource type="Script" path="res://Cards/Animation/CastPosition/CastPos_Caster.gd" id="2_ntgql"]
[ext_resource type="Script" path="res://Cards/Animation/CastAnimationData.gd" id="3_83qul"]
[ext_resource type="Script" path="res://Cards/Effects/EffectDamage.gd" id="4_xup0k"]
Expand Down
2 changes: 1 addition & 1 deletion Cards/Resource/Card_DamageAllEnemies.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="CardBase" load_steps=10 format=3 uid="uid://0x385c3nuq8f"]
[gd_resource type="Resource" script_class="CardBase" load_steps=10 format=3 uid="uid://cnxsrwpr52cig"]

[ext_resource type="Script" path="res://Cards/Effects/EffectDamage.gd" id="1_fpg0t"]
[ext_resource type="Script" path="res://Cards/Effects/EffectData.gd" id="2_ib0yg"]
Expand Down
25 changes: 25 additions & 0 deletions Cards/Resource/Card_Get_block.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[gd_resource type="Resource" script_class="CardBase" load_steps=8 format=3 uid="uid://b1u8retwosbc0"]

[ext_resource type="Script" path="res://Cards/Effects/EffectAddBlock.gd" id="1_2ga3f"]
[ext_resource type="Script" path="res://Cards/CardBase.gd" id="1_f1j0k"]
[ext_resource type="Script" path="res://Cards/Effects/EffectData.gd" id="2_up8rw"]
[ext_resource type="Script" path="res://Cards/Targeting/TargetPlayer.gd" id="3_hmcm7"]

[sub_resource type="Resource" id="Resource_1hvmi"]
script = ExtResource("1_2ga3f")

[sub_resource type="Resource" id="Resource_frq70"]
script = ExtResource("3_hmcm7")

[sub_resource type="Resource" id="Resource_4tqh2"]
script = ExtResource("2_up8rw")
effect = SubResource("Resource_1hvmi")
value = 5
targeting_function = SubResource("Resource_frq70")

[resource]
script = ExtResource("1_f1j0k")
application_type = 0
card_title = "Get Block"
card_description = "Get 5 Block"
card_effects_data = Array[ExtResource("2_up8rw")]([SubResource("Resource_4tqh2")])
2 changes: 1 addition & 1 deletion Cards/Resource/Card_Poison.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_resource type="Resource" script_class="CardBase" load_steps=17 format=3 uid="uid://ctx8jsvac84so"]

[ext_resource type="Script" path="res://Cards/Effects/EffectApplyStatus.gd" id="1_5lji7"]
[ext_resource type="PackedScene" uid="uid://c13302ahcfpuy" path="res://Cards/Animation/Scene/Anim_Poison.tscn" id="1_q5mb6"]
[ext_resource type="PackedScene" path="res://Cards/Animation/Scene/Anim_Poison.tscn" id="1_q5mb6"]
[ext_resource type="Script" path="res://Cards/CardBase.gd" id="1_u6k7h"]
[ext_resource type="Script" path="res://Status/Debuffs/Debuff_Poison.gd" id="2_6vdl1"]
[ext_resource type="Script" path="res://Cards/Effects/EffectData.gd" id="2_omhae"]
Expand Down
2 changes: 1 addition & 1 deletion Cards/Resource/Card_damage_and_poison.tres
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[ext_resource type="Script" path="res://Cards/Targeting/TargetingBase.gd" id="3_0biqs"]
[ext_resource type="Script" path="res://Cards/Effects/EffectApplyStatus.gd" id="3_l3hyf"]
[ext_resource type="Script" path="res://Status/Debuffs/Debuff_Poison.gd" id="4_84i11"]
[ext_resource type="PackedScene" uid="uid://c13302ahcfpuy" path="res://Cards/Animation/Scene/Anim_Poison.tscn" id="4_vlagw"]
[ext_resource type="PackedScene" path="res://Cards/Animation/Scene/Anim_Poison.tscn" id="4_vlagw"]
[ext_resource type="Script" path="res://Cards/EnergyData.gd" id="5_ajuey"]
[ext_resource type="Script" path="res://Cards/Animation/CastPosition/CastPos_AllTargets.gd" id="5_rlt1d"]
[ext_resource type="Script" path="res://Cards/Animation/CastAnimationData.gd" id="6_0uuxe"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="CardBase" load_steps=8 format=3 uid="uid://dliguwgspqyx0"]
[gd_resource type="Resource" script_class="CardBase" load_steps=8 format=3 uid="uid://dmgrkemuj71na"]

[ext_resource type="Script" path="res://Cards/Effects/EffectDamage.gd" id="1_x1diw"]
[ext_resource type="Script" path="res://Cards/Effects/EffectData.gd" id="2_ovjct"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="CardBase" load_steps=8 format=3 uid="uid://6thyux8u44dk"]
[gd_resource type="Resource" script_class="CardBase" load_steps=8 format=3 uid="uid://b2isycb5jkern"]

[ext_resource type="Script" path="res://Cards/Effects/EffectSooth.gd" id="1_40224"]
[ext_resource type="Script" path="res://Cards/Effects/EffectData.gd" id="2_rs3h8"]
Expand Down
2 changes: 1 addition & 1 deletion Core/PlayerPersistentData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class_name PlayerPersistentData
## Store player data that we want to persist between scenes here.


var saved_health: float
var saved_health: int
var saved_stats: EntityStats


Expand Down
102 changes: 80 additions & 22 deletions Entity/Components/HealthComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,35 @@ class_name HealthComponent
## Emit when health is changed
signal on_health_changed(new_health: int)

signal on_block_changed(new_block: int)

## The maximum health the entity can have; this is a hard limit
@export var max_health: float = 100
@export var max_health: int = 100
## The health the entity currently has [br]
## Between 0 and max_health
var current_health: float = 100 # ? change this to max health, or just unset since it's init by the ready
var current_health: int = 100 # ? change this to max health, or just unset since it's init by the ready

var current_block: int = 0

## might need to find a better way to get which team the enitiy is on
var team: GlobalEnums.Team

## Initialize the health component, putting health to max health
## This only happens at game start for the player, the value is then tracked inside the [PlayerManager] singleton [br]
## For enemies, this is called when the scene is instantiated (or more accurately, when each enemy is instanciated) [br]
func _ready() -> void:
_set_health(max_health)

## This is a is a temporary solution to block removal while #118 and #120 are done
## should be removed with those issues
PhaseManager.temp_before_phase_changed.connect(reset_block_on_round_start)


## Modify the health of the entity [br]
## Use the is_healing boolean if you want to heal. [br]
## If the amount is negative, nothing will change. [br]
## Caster can be null [br]
func modify_health(amount: float, caster: Entity, is_healing: bool = false) -> void:
# Allow caster to be null, but not the target.
# If caster is null, we assume that the modification came from an unknown source,
# so status won't calculate.
var new_health: float

if amount <= 0.0:
## The intended way for entities to take damage.[br]
## Removes block first and then deals excess damage to the health[br]
func take_damage_block_and_health(amount : int, caster: Entity) -> void:
if amount <= 0:
return

assert(owner != null, "No owner was set. Please call init on the Entity.")

var target: Entity = entity_owner # TODO change this name entity_owner to make it clearer
Expand All @@ -41,18 +44,73 @@ func modify_health(amount: float, caster: Entity, is_healing: bool = false) -> v
if caster == target:
caster = null

# apply modification to our health
if is_healing:
new_health = clampf(current_health + amount, 0, max_health)
else:
new_health = clampf(current_health - amount, 0, max_health)


var leftover_damage: int = block_damage(amount)
_health_damage(leftover_damage)

## removes health without considering block [br]
## primarily a helper function, but could be used in future for block ignoring attacks[br]
func _health_damage(damage : int) -> void:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
if damage <= 0:
return

var new_health : int = clamp(current_health - damage, 0, max_health)

_set_health(new_health)

## adds health to the unit[br]
func heal(amount : int, _caster : Entity) -> void:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
if amount <= 0:
return

var new_health : int = clamp(current_health + amount, 0, max_health)
_set_health(new_health)

## Set the health of the entity [br]
func _set_health(new_health: float) -> void:
func _set_health(new_health: int) -> void:
if (new_health == current_health):
return
current_health = new_health
on_health_changed.emit(current_health)

## Removes block from the entity[br]
func block_damage(damage: int) -> int:
if damage <= 0:
return 0

var leftover_damage : int = max(damage - current_block, 0)

var new_block : int = max(current_block - damage, 0)
_set_block(new_block)

return leftover_damage

## Adds block to the entity[br]
func add_block(amount : int, _caster : Entity) -> void:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
if amount <= 0:
return

var new_block : int = current_block + amount

_set_block(new_block)


## Set the block of the entity [br]
func _set_block(new_block: int) -> void:
if (new_block == current_block):
return

current_block = new_block
on_block_changed.emit(current_block)

func reset_block_on_round_start(new_phase: GlobalEnums.Phase, _old_phase: GlobalEnums.Phase) -> void:
if(team == GlobalEnums.Team.FRIENDLY):
if(new_phase == GlobalEnums.Phase.PLAYER_ATTACKING):
reset_block()
if(team == GlobalEnums.Team.ENEMY):
if(new_phase == GlobalEnums.Phase.ENEMY_ATTACKING):
reset_block()

## Sets block to 0 [br]
func reset_block() -> void:
_set_block(0)
22 changes: 22 additions & 0 deletions Entity/Components/block_display.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[gd_scene load_steps=3 format=3 uid="uid://dbidy5j4uyopc"]

[ext_resource type="Texture2D" uid="uid://162qbj2n5rm4" path="res://Art/Menus/shield-1.png" id="1_g1qck"]
[ext_resource type="Script" path="res://Entity/Player/block_display.gd" id="2_3xjv7"]

[node name="BlockDisplay" type="Sprite2D" node_paths=PackedStringArray("label")]
visible = false
position = Vector2(-83.1875, -87.1875)
scale = Vector2(0.0563541, 0.0563541)
texture = ExtResource("1_g1qck")
script = ExtResource("2_3xjv7")
label = NodePath("BlockAmount")

[node name="BlockAmount" type="Label" parent="."]
offset_left = -428.0
offset_top = -428.0
offset_right = 380.0
offset_bottom = 380.0
theme_override_font_sizes/font_size = 376
text = "0"
horizontal_alignment = 1
vertical_alignment = 1
6 changes: 5 additions & 1 deletion Entity/Enemy/Enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://bpgsmfprnm2kk"]
[gd_scene load_steps=17 format=3 uid="uid://bpgsmfprnm2kk"]

[ext_resource type="Script" path="res://Entity/Enemy/Enemy.gd" id="1_ya6nf"]
[ext_resource type="Script" path="res://Entity/Components/StatComponent.gd" id="2_twygh"]
Expand All @@ -12,6 +12,7 @@
[ext_resource type="Script" path="res://Entity/Components/BehaviorComponent.gd" id="9_kvor6"]
[ext_resource type="Resource" uid="uid://bsrdu33ukb1ym" path="res://Cards/Resource/Card_EnemyAttack.tres" id="10_l5325"]
[ext_resource type="Script" path="res://Entity/Components/StressComponent.gd" id="11_qf75g"]
[ext_resource type="PackedScene" uid="uid://dbidy5j4uyopc" path="res://Entity/Components/block_display.tscn" id="13_u3jb7"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_b8bva"]
size = Vector2(104, 93)
Expand Down Expand Up @@ -83,6 +84,9 @@ script = ExtResource("11_qf75g")
max_stress = 80
stress_generation = 20

[node name="BlockDisplay" parent="." node_paths=PackedStringArray("healthComponent") instance=ExtResource("13_u3jb7")]
healthComponent = NodePath("../HealthComponent")

[connection signal="input_event" from="Area2D" to="ClickHandler" method="_on_input_event"]
[connection signal="mouse_entered" from="Area2D" to="ClickHandler" method="_on_mouse_entered"]
[connection signal="mouse_exited" from="Area2D" to="ClickHandler" method="_on_mouse_exited"]
2 changes: 2 additions & 0 deletions Entity/Entity.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ func _ready() -> void:
get_health_component().init_entity_component(self)
get_party_component().init_entity_component(self)
get_stat_component().init_entity_component(self)

get_health_component().team = get_party_component().team


func get_status_component() -> StatusComponent:
Expand Down
2 changes: 1 addition & 1 deletion Entity/Player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func _load_persistent_data() -> void:

# Load health data
var health_comp: HealthComponent = get_health_component()
var new_health: float = PlayerManager.player_persistent_data.saved_health
var new_health: int = PlayerManager.player_persistent_data.saved_health
health_comp._set_health(new_health)

# Load stat data
Expand Down
Loading
Loading