Skip to content
Merged
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
12 changes: 1 addition & 11 deletions Classes/Notes/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@ public Note(
Id = id;
Name = name;
Owner = owner;
NoteEffect =
noteEffect
?? (
(BD, source, timing) =>
{
Array.ForEach(
BD.GetTargets(source), //Ok, sure
enemy => enemy.TakeDamage((int)timing * source._baseVal)
);
}
);
NoteEffect = noteEffect;
_baseVal = baseVal;
Texture = texture;
Tooltip = tooltip;
Expand Down
Binary file added Classes/StatusEffects/Assets/Status_Block.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 Classes/StatusEffects/Assets/Status_Block.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cdlepg5fxfwn0"
path="res://.godot/imported/Status_Block.png-e8facdf93b546460a44dfea789c90919.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Classes/StatusEffects/Assets/Status_Block.png"
dest_files=["res://.godot/imported/Status_Block.png-e8facdf93b546460a44dfea789c90919.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
Binary file added Classes/StatusEffects/Assets/Status_Mulligan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
163 changes: 163 additions & 0 deletions Classes/StatusEffects/StatusEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
using System;
using System.Linq;
using FunkEngine;
using Godot;

/// <summary>
/// Status Effect class.
/// Preferably set up as a static default status, then apply status using GetInstance, but custom statuses can be defined elsewhere.
/// Invoke StatusEnd to remove status.
/// </summary>
public partial class StatusEffect : TextureRect, IBattleEvent
{ //TODO: Status effects that are permanent, and status effects that don't take up a slot/are invisible
public static readonly string LoadPath = "res://Classes/StatusEffects/StatusIcon.tscn";
public PuppetTemplate Sufferer { get; private set; }
public int Count { get; private set; }

public string StatusName { get; private set; }

[Export]
private Label CountLabel { get; set; }

internal delegate void StatusEndHandler(StatusEffect status);
internal event StatusEndHandler StatusEnd;

#region DefaultStatuses
private static readonly Action<BattleEventArgs, StatusEffect> BlockEffect = (e, self) =>
{
if (e is BattleDirector.Harbinger.OnDamageInstanceArgs dmgArgs)
{
if (dmgArgs.Dmg.Target != self.Sufferer || dmgArgs.Dmg.Damage <= 0)
return;
dmgArgs.Dmg.ModifyDamage(0, 0);
self.DecCount();
}
};

/// <summary>
/// On the owner receiving a damage instance, if valid (correct target and dmg > 0) sets damage to 0 and reduces count.
/// </summary>
public static readonly StatusEffect Block = new StatusEffect()
.InitStatus(
"Block",
BlockEffect,
BattleEffectTrigger.OnDamageInstance,
GD.Load<Texture2D>("res://Classes/StatusEffects/Assets/Status_Block.png")
)
.SetTags(true);

private static readonly Action<BattleEventArgs, StatusEffect> MulliganEffect = (e, self) =>
{
if (e is not BattleDirector.Harbinger.NoteHitArgs { Timing: Timing.Miss })
return;
e.BD.NPB.SetIgnoreMiss(true); //Intercept the miss
self.DecCount();
};

/// <summary>
/// If the player missed, take damage, but don't receive combo penalty.
/// </summary>
public static readonly StatusEffect Mulligan = new StatusEffect()
.InitStatus(
"Mulligan",
MulliganEffect,
BattleEffectTrigger.NoteHit,
GD.Load<Texture2D>("res://Classes/StatusEffects/Assets/Status_Mulligan.png")
)
.SetTags(true);
#endregion

private BattleEffectTrigger _trigger;
private Action<BattleEventArgs, StatusEffect> _effect;

public BattleEffectTrigger GetTrigger()
{
return _trigger;
}

public void OnTrigger(BattleEventArgs e)
{
_effect(e, this);
}

public StatusEffect InitStatus(
string name,
Action<BattleEventArgs, StatusEffect> effect,
BattleEffectTrigger trigger,
Texture2D texture = null
)
{
_effect = effect;
_trigger = trigger;
StatusName = name;
Texture = texture;
return this;
}

public StatusEffect GetInstance(int count = 1)
{
StatusEffect result = GD.Load<PackedScene>(LoadPath).Instantiate<StatusEffect>();
result.SetCount(count);
result.InitStatus(Name, _effect, _trigger, Texture);
result.SetTags(_stackable, _refreshes);
return result;
}

public void SetOwner(PuppetTemplate owner)
{
Sufferer = owner;
}

public void IncCount(int count = 1)
{
SetCount(Count + count);
}

public void DecCount(int count = 1)
{
SetCount(Count - count);
}

public void SetCount(int count)
{
Count = count;
CountLabel.Text = Count.ToString();
if (Count <= 0)
{
StatusEnd?.Invoke(this);
}
}

/// <summary>
/// Re-applying a status increases the count.
/// </summary>
private bool _stackable;

/// <summary>
/// Re-applying a status sets the count to the higher counte
/// </summary>
private bool _refreshes;

public StatusEffect SetTags(bool stackable = false, bool refreshes = false)
{
_stackable = stackable;
_refreshes = refreshes;
return this;
}

//Called if a puppet is receiving a duplicate effect.
public void StackEffect(StatusEffect incomingEffect)
{
if (incomingEffect.StatusName != StatusName)
return;
if (_stackable)
{
IncCount(incomingEffect.Count);
}

if (_refreshes && incomingEffect.Count >= Count)
{
SetCount(incomingEffect.Count);
}
}
}
1 change: 1 addition & 0 deletions Classes/StatusEffects/StatusEffect.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://wawjisy70w1v
36 changes: 36 additions & 0 deletions Classes/StatusEffects/StatusIcon.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[gd_scene load_steps=4 format=3 uid="uid://opqtl7khulko"]

[ext_resource type="Script" uid="uid://wawjisy70w1v" path="res://Classes/StatusEffects/StatusEffect.cs" id="1_2adc3"]

[sub_resource type="Gradient" id="Gradient_y1lef"]
offsets = PackedFloat32Array(1)
colors = PackedColorArray(1, 1, 1, 1)

[sub_resource type="GradientTexture2D" id="GradientTexture2D_2adc3"]
gradient = SubResource("Gradient_y1lef")
width = 16
height = 16

[node name="StatusIcon" type="TextureRect" node_paths=PackedStringArray("CountLabel")]
custom_minimum_size = Vector2(8, 8)
offset_right = 8.0
offset_bottom = 8.0
texture = SubResource("GradientTexture2D_2adc3")
script = ExtResource("1_2adc3")
CountLabel = NodePath("Count")

[node name="Count" type="Label" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 2.0
offset_top = 4.0
offset_bottom = 2.0
grow_horizontal = 2
grow_vertical = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 12
text = "0"
horizontal_alignment = 2
vertical_alignment = 2
3 changes: 3 additions & 0 deletions Globals/FunkEngineNameSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public enum Timing

public enum Targetting
{
Player,
First,
All,
}
Expand All @@ -237,6 +238,8 @@ public enum BattleEffectTrigger
OnLoop,
OnBattleStart,
OnBattleEnd,
OnDamageInstance,
OnDamageTaken,
}

public enum Stages
Expand Down
25 changes: 15 additions & 10 deletions Globals/Scribe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public partial class Scribe : Node
1,
(director, note, timing) =>
{
director.Player.TakeDamage((3 - (int)timing) * note.GetBaseVal());
int dmg = (3 - (int)timing) * note.GetBaseVal();
director.Player.TakeDamage(new DamageInstance(dmg, null, director.Player));
}
),
new Note(
Expand All @@ -36,7 +37,7 @@ public partial class Scribe : Node
{
if (timing == Timing.Miss)
return;
director.GetFirstEnemy()?.TakeDamage((int)timing * note.GetBaseVal());
director.DealDamage(note, (int)timing * note.GetBaseVal(), director.Player);
}
),
new Note(
Expand All @@ -50,7 +51,7 @@ public partial class Scribe : Node
{
if (timing == Timing.Miss)
return;
director.GetFirstEnemy()?.TakeDamage(note.GetBaseVal() * (int)timing);
director.DealDamage(note, (int)timing * note.GetBaseVal(), director.Player);
}
),
new Note(
Expand Down Expand Up @@ -78,8 +79,9 @@ public partial class Scribe : Node
{
if (timing == Timing.Miss)
return;
director.Player.Heal((int)timing * note.GetBaseVal());
director.GetFirstEnemy()?.TakeDamage((int)timing * note.GetBaseVal());
int dmg = (int)timing * note.GetBaseVal();
director.Player.Heal(dmg);
director.DealDamage(note, dmg, director.Player);
}
),
new Note(
Expand All @@ -93,13 +95,13 @@ public partial class Scribe : Node
{
if (timing == Timing.Miss)
return;
director.GetFirstEnemy()?.TakeDamage((int)timing + note.GetBaseVal());
director.DealDamage(note, (int)timing * note.GetBaseVal(), director.Player);
},
0.25f
),
new Note(
6,
"Play-c-HoldBlock",
"PlayerBlock",
"Gives player one charge of block.",
GD.Load<Texture2D>("res://Classes/Notes/Assets/Note_PlayerBlock.png"),
null,
Expand All @@ -108,7 +110,7 @@ public partial class Scribe : Node
{
if (timing == Timing.Miss)
return;
//director.Player.GainShield(note.GetBaseVal()); //todo: should scale with timing????
director.AddStatus(Targetting.Player, StatusEffect.Block.GetInstance()); //todo: should scale with timing????
}
),
};
Expand Down Expand Up @@ -203,7 +205,10 @@ public partial class Scribe : Node
1,
(e, self, val) =>
{
e.BD.GetFirstEnemy()?.TakeDamage(val);
if (e is not BattleDirector.Harbinger.NoteHitArgs noteHitArgs)
return;
if (noteHitArgs.Timing != Timing.Miss)
e.BD.DealDamage(Targetting.First, val, null);
}
),
}
Expand All @@ -221,7 +226,7 @@ public partial class Scribe : Node
5,
(e, self, val) =>
{
e.BD.GetFirstEnemy()?.TakeDamage(val);
e.BD.DealDamage(Targetting.First, val, null);
}
),
}
Expand Down
Loading