Skip to content

Commit

Permalink
Added toggle properties for damage dealing and receiving
Browse files Browse the repository at this point in the history
  • Loading branch information
treesgobark committed Jan 25, 2024
1 parent fa7ba93 commit 3b59566
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions Engines/FlatRedBallXNA/FlatRedBall/Entities/IDamageArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IDamageArea : ICollidable
{
event Action Destroyed;
double SecondsBetweenDamage { get; set; }
bool IsDamageDealingEnabled { get; }
object DamageDealer { get; }
int TeamIndex { get; }

Expand Down
8 changes: 6 additions & 2 deletions Engines/FlatRedBallXNA/FlatRedBall/Entities/IDamageable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IDamageable
{
Dictionary<IDamageArea, double> DamageAreaLastDamage { get; }
int TeamIndex { get; }
bool IsDamageReceivingEnabled { get; }
decimal CurrentHealth { get; set; }
decimal MaxHealth { get; set; }

Expand All @@ -30,15 +31,18 @@ public static class DamageableExtensionMethods
{
/// <summary>
/// Returns whether the argument IDamageable should take damage from the argument IDamageArea.
/// This returns true if the team indexes are different, ifthe damageable has > 0 CurrentHealth,
/// This returns true if the team indexes are different, if the damageable has > 0 CurrentHealth,
/// and if enough time has passed since the last damage was dealt by this particular IDamageArea instance.
/// </summary>
/// <param name="damageable">The damageable object, typically a Player or Enemy.</param>
/// <param name="damageArea">The damage dealing object, typically a bullet or enemy.</param>
/// <returns></returns>
public static bool ShouldTakeDamage(this IDamageable damageable, IDamageArea damageArea)
{
if (damageable.TeamIndex == damageArea.TeamIndex || damageable.CurrentHealth <= 0)
if (damageable.TeamIndex == damageArea.TeamIndex
|| damageable.CurrentHealth <= 0
|| !damageArea.IsDamageDealingEnabled
|| !damageable.IsDamageReceivingEnabled)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Engines/FlatRedBallXNA/FlatRedBall/FlatRedBallServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public object GetService(Type serviceType)

public class SyntaxVersionAttribute : Attribute
{
public int Version = 51;
public int Version = 52;
}

public static partial class FlatRedBallServices
Expand Down
5 changes: 3 additions & 2 deletions FRBDK/Glue/Glue/SaveClasses/GlueProjectSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public enum GluxVersions
GumUsesSystemTypes = 49,
// Technically this isn't referencing GumCommon project, but it's referencing code from GumCommon
GumCommonCodeReferencing = 50,
GumTextSupportsBbCode = 51
GumTextSupportsBbCode = 51,
DamageDealingToggles = 52

// Stop! If adding an entry here, modify SyntaxVersionAttribute.Version
}
Expand All @@ -143,7 +144,7 @@ public enum GluxVersions

#region Versions

public const int LatestVersion = (int)GluxVersions.GumTextSupportsBbCode;
public const int LatestVersion = (int)GluxVersions.DamageDealingToggles;

public int FileVersion { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public override void AddInheritedTypesToList(List<string> listToAddTo, IElement

#endregion

public static bool UsesDamageV2 => GlueState.Self.CurrentGlueProject.FileVersion >= (int)GlueProjectSave.GluxVersions.DamageableHasHealth;
public static bool UsesDamageV2 => GlueState.Self.CurrentMainProject.IsFrbSourceLinked()
|| GlueState.Self.CurrentGlueProject.FileVersion >= (int)GlueProjectSave.GluxVersions.DamageableHasHealth;
public static bool UsesDamageV3 => GlueState.Self.CurrentMainProject.IsFrbSourceLinked()
|| GlueState.Self.CurrentGlueProject.FileVersion >= (int)GlueProjectSave.GluxVersions.DamageDealingToggles;

public override ICodeBlock GenerateFields(ICodeBlock codeBlock, IElement element)
{
Expand Down Expand Up @@ -70,6 +73,11 @@ public override ICodeBlock GenerateFields(ICodeBlock codeBlock, IElement element
codeBlock.Line("public Action<FlatRedBall.Entities.IDamageable> RemovedByCollision { get; set; }");

}

if (UsesDamageV3)
{
codeBlock.Line("public bool IsDamageDealingEnabled { get; set; } = true;");
}
}

if (shouldImplementIDamageable)
Expand All @@ -90,6 +98,11 @@ public override ICodeBlock GenerateFields(ICodeBlock codeBlock, IElement element
codeBlock.Line("public decimal CurrentHealth { get; set; }");
codeBlock.Line("public Action<decimal, FlatRedBall.Entities.IDamageArea> Died { get; set; }");
}

if (UsesDamageV3)
{
codeBlock.Line("public bool IsDamageReceivingEnabled { get; set; } = true;");
}
}
}

Expand Down

0 comments on commit 3b59566

Please sign in to comment.