StarrFox / wizwalker

Wizard101 scripting api
https://starrfox.github.io/wizwalker
GNU General Public License v3.0
37 stars 30 forks source link

Information about shields and traps #37

Open MGlolenstine opened 3 years ago

MGlolenstine commented 3 years ago

I'm currently trying to write a combat bot, but I'm missing some stuff. Most importantly information about shields and traps on the targets (CombatMember class).

PeechezNCreem commented 3 years ago

Here's an example of using hanging effects (not tested):

from wizwalker import ClientHandler
from wizwalker.combat import CombatHandler
from wizwalker.memory import SpellEffects

class ShieldBreaker(CombatHandler):
    async def handle_round(self):
        shielded_targets = []
        for target in await self.get_all_monster_members():
            participant = await target.get_participant()

            shields = 0
            for effect in await participant.hanging_effects():
                is_ward = await effect.effect_type() == SpellEffects.modify_incoming_damage
                negative = await effect.effect_param() < 0

                if is_ward and negative:
                    shields += 1
            shielded_targets.append((shields, target))

        # get the target with the most shields
        num_shields, target = sorted(shielded_targets, reverse=True)[0]

        if num_shields == 0:
            await self.pass_button()
            return

        client = await self.get_client_member()

        if await client.normal_pips() >= 3:
            spell_name = "shatter"
        else:
            spell_name = "pierce"

        hit = await self.get_card_named(spell_name)
        await hit.cast(target)