how to check if player not using a shield-mages might

Continuing the discussion from Mages Might can someone help because i suck at coding:

so I want to run some code that first checks if the player has enough mana to make a shield, then if the opponent has 15+ mana of a specific type, then check whether or not the player has an active shield of the mana type strong against the mana the opponent has, then cast that shield spell and don’t cast it again until it is broken. I can’t seem to figure out how to detect what type of shield the player is using or whether or not they are using one at all, I know to use hero.getactiveshield but the documentation wasn’t clear on how to use it

Hi! Could you please post your code, formatting it with the </> button so we can see what’s going on?

@enPointe77 The question has nothing to do with existing code.

ProfMonkey07–
Possible duplicate of here.

You listed four conditions:

  1. Do I have enough mana for a shield?
    Check hero.earth > 3
  2. Does the opponent have enough mana for a ball?
    Check opponent.fire > 15 where opponent = hero.getEnemyHero()
  3. Do I have a current shield?
    Check truthiness of hero.getActiveShield()
  4. What type is my current shield?
    Check shield.mana where shield = hero.getActiveShield()

Sample solution, in Python, that solves a similar problem to yours. All the same concepts are here.

# Summons shields to block potential enemy ball spells
# Code is untested

opponent = hero.getEnemyHero()

ball_cost = hero.getSpellData("fire-ball").cost
shield_cost = hero.getSpellData("fire-shield").cost

elements = ["fire", "earth", "water"]
affinities = {
  "fire":  {"weak": "water", "strong": "earth"},
  "water": {"weak": "earth", "strong": "fire" },
  "earth": {"weak": "fire",  "strong": "water"},
}

while True:
  # Condition 3, do nothing if I have an active shield
  shield = hero.getActiveShield()
  if shield: continue

  # This is where you would use Condition 4 if you wish
  #   Rather than doing nothing regardless of the shield's type,
  #   you could replace your shield if it is of the incorrect type
  # `shield.mana` is one of `elements`

  for element in elements:
    shield_element = affinities[element].weak
    # Condition 2, if the enemy is able to cast a ball
    #   and Condition 1, if I can afford a shield to counter it
    if opponent[element] > ball_cost and hero[shield_element] > shield_cost:
      hero.cast(shield_element + "-shield")
2 Likes

I do not have any code, I cannot figure out how to use getactiveshield, I just need the syntax for it explained to me

1 Like

oooh, that makes more sense now, thank you so much

Yeah, I see that now.