@enPointe77 The question has nothing to do with existing code.
ProfMonkey07–
Possible duplicate of here.
You listed four conditions:
- Do I have enough mana for a shield?
Checkhero.earth > 3
- Does the opponent have enough mana for a ball?
Checkopponent.fire > 15
whereopponent = hero.getEnemyHero()
- Do I have a current shield?
Check truthiness ofhero.getActiveShield()
- What type is my current shield?
Checkshield.mana
whereshield = 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")