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

**URL:** <https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311>\
**Category:** Level Help\
**Created:** [June 12, 2021, 10:16pm UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311 "2021-06-12T22:16:43Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Hydrobolic](https://avatars.discourse-cdn.com/v4/letter/h/e47c2d/32.png) [@Hydrobolic](https://discourse.codecombat.com/u/Hydrobolic)\
**Post date:** [June 13, 2021, 2:25am UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311/3 "2021-06-13T02:25:04Z")

</div>

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

ProfMonkey07–  
Possible duplicate of [here](https://discourse.codecombat.com/t/help-on-mages-might/29284).

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.

```python
# 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")

```

---

_[View the full topic](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311)._
