Skip to content

Commit

Permalink
Weapons can have damage types.
Browse files Browse the repository at this point in the history
Removed unused instances of IGame.
  • Loading branch information
nightblade9 committed Dec 14, 2024
1 parent f5fb176 commit 6de8021
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
13 changes: 12 additions & 1 deletion source/TextBlade.Core/Battle/CharacterTurnProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,21 @@ private static string Attack(Character character, Monster targetMonster)
message.Append($"{character.Name} attacks {targetMonster.Name}! ");

var damage = character.TotalStrength - targetMonster.Toughness;

var characterWeapon = character.EquippedOn(Inv.ItemType.Weapon);
// TODO: DRY with SkillApplier
var effectiveMessage = "";
if (characterWeapon?.DamageType == targetMonster.Weakness)
{
effectiveMessage = "[#f80]Super effective![/]";

damage *= 2;
}

targetMonster.Damage(damage);

var damageAmount = damage <= 0 ? "NO" : damage.ToString();
message.Append($"[{Colours.Highlight}]{damageAmount}[/] damage!");
message.Append($"[{Colours.Highlight}]{damageAmount}[/] damage! {effectiveMessage}");
if (targetMonster.CurrentHealth <= 0)
{
message.Append($"{targetMonster.Name} DIES!");
Expand Down
2 changes: 1 addition & 1 deletion source/TextBlade.Core/Battle/SkillApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static string ApplyDamage(Character user, Skill skill, Entity target)

var roundedDamage = (int)damage;
target.Damage(roundedDamage);

// TODO: DRY the 2x damage part with CharacterTurnProcessor
var damageMessage = damage > 0 ? $"{roundedDamage} damage" : $"healed for [green]{-roundedDamage}[/]";
var effectiveMessage = hitWeakness ? "[#f80]Super effective![/]" : "";
return $"{user.Name} uses {skill.Name} on {target.Name}! {effectiveMessage} {damageMessage}!";
Expand Down
5 changes: 1 addition & 4 deletions source/TextBlade.Core/Commands/TakeTurnsBattleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class TakeTurnsBattleCommand : ICommand, IBattleCommand
public bool IsVictory { get; private set; }

private readonly List<Monster> _monsters = new();
private readonly IGame _game;

static TakeTurnsBattleCommand()
{
Expand All @@ -51,10 +50,8 @@ static TakeTurnsBattleCommand()
}
}

public TakeTurnsBattleCommand(IGame game, List<string> monsterNames)
public TakeTurnsBattleCommand(List<string> monsterNames)
{
_game = game;

foreach (var name in monsterNames)
{
var data = s_allMonstersData[name];
Expand Down
11 changes: 9 additions & 2 deletions source/TextBlade.Core/Inv/Equipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ namespace TextBlade.Core.Inv;

public class Equipment : Item
{
// TODO: store JSON so we can see custom attributes
// Supposed to be readonly. We need to serialize it though.
public Dictionary<CharacterStats, int> StatsModifiers { get; private set; } = new();

public string? DamageType { get; set; }

// This is obvious, but maybe not? Best to enshrine it in code.
public Equipment(string name, string itemType, Dictionary<CharacterStats, int> statsModifiers, int value = 1) : base(name, string.Empty, itemType, value)
public Equipment(string name, string itemType, Dictionary<CharacterStats, int> statsModifiers, string? damageType = null, int value = 1) : base(name, string.Empty, itemType, value)
{
if (this.ItemType == ItemType.Consumable)
{
Expand All @@ -21,7 +22,13 @@ public Equipment(string name, string itemType, Dictionary<CharacterStats, int> s
throw new ArgumentException("Equipment needs stats modifiers.");
}

if (damageType != null && damageType != "Normal" && itemType != ItemType.Weapon.ToString())
{
throw new ArgumentException("DamageType only applies to weapons", nameof(damageType));
}

StatsModifiers = statsModifiers;
DamageType = damageType;
}

public int GetStatsModifier(CharacterStats stat)
Expand Down
2 changes: 1 addition & 1 deletion source/TextBlade.Core/Locations/Dungeon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ override public ICommand GetCommandFor(string input)
var currentFloorData = _floorMonsters[_currentFloorNumber];
if (input == "f" || input == "fight")
{
return new TakeTurnsBattleCommand(_game, currentFloorData);
return new TakeTurnsBattleCommand(currentFloorData);
}
if (input == "d" || input == "down" || input == "descend" || input == ">")
{
Expand Down
3 changes: 2 additions & 1 deletion source/VoidWalker.Main/Content/Data/Items.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"$type": "TextBlade.Core.Inv.Equipment, TextBlade.Core",
"ItemType": "Weapon",
"StatsModifiers": { "Strength": 7 },
"Value": 200
"Value": 200,
"DamageType": "Fire"
},
"Iron Helmet":
{
Expand Down

0 comments on commit 6de8021

Please sign in to comment.