From 6de8021137c1a76ce0cd6727f33473751fbe935c Mon Sep 17 00:00:00 2001 From: nightblade9 Date: Sat, 14 Dec 2024 16:40:05 -0500 Subject: [PATCH] Weapons can have damage types. Removed unused instances of IGame. --- .../TextBlade.Core/Battle/CharacterTurnProcessor.cs | 13 ++++++++++++- source/TextBlade.Core/Battle/SkillApplier.cs | 2 +- .../Commands/TakeTurnsBattleCommand.cs | 5 +---- source/TextBlade.Core/Inv/Equipment.cs | 11 +++++++++-- source/TextBlade.Core/Locations/Dungeon.cs | 2 +- source/VoidWalker.Main/Content/Data/Items.json | 3 ++- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/source/TextBlade.Core/Battle/CharacterTurnProcessor.cs b/source/TextBlade.Core/Battle/CharacterTurnProcessor.cs index 9d5fd7d..162623a 100644 --- a/source/TextBlade.Core/Battle/CharacterTurnProcessor.cs +++ b/source/TextBlade.Core/Battle/CharacterTurnProcessor.cs @@ -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!"); diff --git a/source/TextBlade.Core/Battle/SkillApplier.cs b/source/TextBlade.Core/Battle/SkillApplier.cs index c3f001f..141671c 100644 --- a/source/TextBlade.Core/Battle/SkillApplier.cs +++ b/source/TextBlade.Core/Battle/SkillApplier.cs @@ -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}!"; diff --git a/source/TextBlade.Core/Commands/TakeTurnsBattleCommand.cs b/source/TextBlade.Core/Commands/TakeTurnsBattleCommand.cs index 5e1a899..1d7862f 100644 --- a/source/TextBlade.Core/Commands/TakeTurnsBattleCommand.cs +++ b/source/TextBlade.Core/Commands/TakeTurnsBattleCommand.cs @@ -24,7 +24,6 @@ public class TakeTurnsBattleCommand : ICommand, IBattleCommand public bool IsVictory { get; private set; } private readonly List _monsters = new(); - private readonly IGame _game; static TakeTurnsBattleCommand() { @@ -51,10 +50,8 @@ static TakeTurnsBattleCommand() } } - public TakeTurnsBattleCommand(IGame game, List monsterNames) + public TakeTurnsBattleCommand(List monsterNames) { - _game = game; - foreach (var name in monsterNames) { var data = s_allMonstersData[name]; diff --git a/source/TextBlade.Core/Inv/Equipment.cs b/source/TextBlade.Core/Inv/Equipment.cs index 2e09802..5ecc55d 100644 --- a/source/TextBlade.Core/Inv/Equipment.cs +++ b/source/TextBlade.Core/Inv/Equipment.cs @@ -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 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 statsModifiers, int value = 1) : base(name, string.Empty, itemType, value) + public Equipment(string name, string itemType, Dictionary statsModifiers, string? damageType = null, int value = 1) : base(name, string.Empty, itemType, value) { if (this.ItemType == ItemType.Consumable) { @@ -21,7 +22,13 @@ public Equipment(string name, string itemType, Dictionary 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) diff --git a/source/TextBlade.Core/Locations/Dungeon.cs b/source/TextBlade.Core/Locations/Dungeon.cs index 1a23727..caf90de 100644 --- a/source/TextBlade.Core/Locations/Dungeon.cs +++ b/source/TextBlade.Core/Locations/Dungeon.cs @@ -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 == ">") { diff --git a/source/VoidWalker.Main/Content/Data/Items.json b/source/VoidWalker.Main/Content/Data/Items.json index 625f428..51ea9b8 100644 --- a/source/VoidWalker.Main/Content/Data/Items.json +++ b/source/VoidWalker.Main/Content/Data/Items.json @@ -4,7 +4,8 @@ "$type": "TextBlade.Core.Inv.Equipment, TextBlade.Core", "ItemType": "Weapon", "StatsModifiers": { "Strength": 7 }, - "Value": 200 + "Value": 200, + "DamageType": "Fire" }, "Iron Helmet": {