Skip to content

Commit

Permalink
fix: atk counter to work better with windfury
Browse files Browse the repository at this point in the history
* fix: mega-windfury recognition for atk counter

* fix: getWeapon always returning an entity even when it is not a weapon

* fix: consider Hero windfury from Inara and Sand Art Elemental

* test: megawindfury and hero windfury
  • Loading branch information
mateuscechetto authored Sep 17, 2024
1 parent dba23b4 commit 97bb2be
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
2 changes: 1 addition & 1 deletion HDTTests/BoardDamage/BoardCardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void Attack_WeaponWithWindfuryOneHitLeft()
[DataRow(CardIds.Collectible.Shaman.WalkingMountain, DisplayName = "Walking Mountain")]
public void Attack_MegaWindfury(string cardId)
{
var eb = new EntityBuilder(cardId, 4, 8).Windfury().Charge().InPlay();
var eb = new EntityBuilder(cardId, 4, 8).MegaWindfury().Charge().InPlay();

Assert.AreEqual(16, eb.ToBoardCard().Attack);
Assert.AreEqual(16, eb.Exhausted().ToBoardCard(false).Attack);
Expand Down
32 changes: 32 additions & 0 deletions HDTTests/BoardDamage/BoardHeroTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,37 @@ public void HeroHasWindfuryWithWeapon()
true);
Assert.AreEqual(4, hero.Attack);
}

[TestMethod]
public void HeroGotWindfuryFromMinion()
{
var hero = new BoardHero(
_hero.Attack(1).Windfury().ToEntity(),
null,
true
);
Assert.AreEqual(hero.Attack, 2);
}

[TestMethod]
public void WindfuryHeroAttackedOnce()
{
var hero = new BoardHero(
_hero.Attack(1).Windfury().AttacksThisTurn(1).ToEntity(),
null,
true);
Assert.AreEqual(1, hero.Attack);
}

[TestMethod]
public void HeroGotWindfuryFromMinionAndHasSingleChargeWeapon()
{
var hero = new BoardHero(
_hero.Attack(7).Windfury().ToEntity(),
_weapon.Attack(6).Damage(1).ToEntity(),
true
);
Assert.AreEqual(8, hero.Attack);
}
}
}
6 changes: 6 additions & 0 deletions HDTTests/BoardDamage/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public EntityBuilder Windfury()
return this;
}

public EntityBuilder MegaWindfury()
{
_instance.SetTag(GameTag.WINDFURY, 3);
return this;
}

public EntityBuilder InPlay()
{
_instance.SetTag(GameTag.ZONE, (int)Zone.PLAY);
Expand Down
6 changes: 5 additions & 1 deletion Hearthstone Deck Tracker/Utility/BoardDamage/BoardCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public BoardCard(Entity e, bool active = true)
Silenced = e.GetTag(SILENCED) == 1;
Charge = e.GetTag(CHARGE) == 1;
Windfury = e.GetTag(WINDFURY) == 1;
MegaWindfury = (e.CardId == HearthDb.CardIds.NonCollectible.Neutral.MimironsHead_V07Tr0NToken || e.CardId == HearthDb.CardIds.Collectible.Shaman.WalkingMountain);
MegaWindfury = e.GetTag(MEGA_WINDFURY) == 1 || e.GetTag(WINDFURY) == 3;
AttacksThisTurn = e.GetTag(NUM_ATTACKS_THIS_TURN);
_dormant = e.GetTag(DORMANT) == 1;
_isTitan = e.GetTag(TITAN) == 1;
Expand Down Expand Up @@ -127,6 +127,10 @@ private bool IsAbleToAttack(bool active, bool isWeapon)
// newly played card could be given charge
return Charge && AttacksThisTurn == 0;
}
if(AttacksThisTurn == AttacksPerTurn)
{
return false;
}
// sometimes cards seem to be in wrong zone while in play,
// these cards don't become exhausted, so check attacks.
if(Zone.ToLower() == "deck" || Zone.ToLower() == "hand")
Expand Down
19 changes: 13 additions & 6 deletions Hearthstone Deck Tracker/Utility/BoardDamage/BoardHero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BoardHero : IBoardEntity
private readonly BoardCard _hero;
private readonly BoardCard? _weapon;

public BoardHero(Entity hero, Entity weapon, bool activeTurn)
public BoardHero(Entity hero, Entity? weapon, bool activeTurn)
{
_hero = new BoardCard(hero, activeTurn);
// hero gains windfury with weapon, doubling attack get base attack
Expand Down Expand Up @@ -46,16 +46,23 @@ private int AttackWithWeapon()
{
if(Include)
{
// weapon is equipped
if(_weapon != null)
{
// windfury weapon, with 2 or more charges,
// and hero hasn't attacked yet this turn.
if(_weapon.Windfury && _weapon.Health >= 2 && _hero.AttacksThisTurn == 0)
if((_hero.Windfury || _weapon.Windfury) && _weapon.Health >= 2 && _hero.AttacksThisTurn == 0)
{
// double the hero attack value
return _baseAttack * 2;
}

if(_hero.Windfury && !_weapon.Windfury && _weapon.Health == 1)
{
return _baseAttack * 2 - _weapon.Attack;
}

}
// Hero got windfury from other means (Inara, Sand Art Elemental)
else if(_hero.Windfury && _hero.AttacksThisTurn == 0)
{
return _baseAttack * 2;
}
}
// otherwise normal hero attack is correct
Expand Down
15 changes: 13 additions & 2 deletions Hearthstone Deck Tracker/Utility/BoardDamage/PlayerBoard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using HearthDb.Enums;
using Hearthstone_Deck_Tracker.Hearthstone.Entities;
using NuGet;
using static HearthDb.Enums.GameTag;

#endregion
Expand Down Expand Up @@ -36,10 +37,20 @@ public PlayerBoard(List<Entity> list, bool activeTurn)

public int Damage => Cards.Where(x => x.Include).Sum(x => x.Attack);

public Entity GetWeapon(List<Entity> list)
public Entity? GetWeapon(List<Entity> list)
{
var weapons = list.Where(x => x.IsWeapon).ToList();
return weapons.Count == 1 ? weapons[0] : list.FirstOrDefault(x => x.HasTag(JUST_PLAYED) && x.GetTag(JUST_PLAYED) == 1);
if (weapons.IsEmpty())
{
return null;
}

if(weapons.Count == 1)
{
return weapons[0];
}

return list.FirstOrDefault(x => x.HasTag(JUST_PLAYED) && x.GetTag(JUST_PLAYED) == 1);
}

public override string ToString() => $"(H:{Hero?.Health ?? 0} A:{Damage})";
Expand Down

0 comments on commit 97bb2be

Please sign in to comment.