static bool testpinch(int p, int s, BS &b, int ratio, bool activate) {
        //HP Pinches activate, nothing else does if sending back
        if (turn(b,s).value("SendingBack").toBool() && !activate) {
            return false;
        }
        if (turn(b,p).value("BugBiter").toBool()) {
            b.eatBerry(s);
            return true;
        }
        //Gluttony
        if (b.hasWorkingAbility(s, Ability::Gluttony))
            ratio = 2;

        if (!b.koed(s)) {
            int lp = b.poke(s).lifePoints();
            int tp = b.poke(s).totalLifePoints();

            if (lp*ratio <= tp) {
                //Reusing 'bool activate' in order to only affect HP berries
                if (poke(b, s).value("HealBlockCount").toInt() > 0 && activate) {
                    b.sendMoveMessage(59,BS::HealByItem,s,Type::Psychic,s,b.poke(s).item());
                    return false;
                }
                b.eatBerry(s,s==p);
                return true;
            }
        }

        return false;
    }
Exemple #2
0
    static void aaf(int t, int, BS &b) {
        if (turn(b,t)["RedCardCount"] != slot(b,t)["SwitchCount"])
            return;
        int s = turn(b,t)["RedCardUser"].toInt();
        if (b.koed(s) || b.koed(t) || turn(b,t)["RedCardGiverCount"] != slot(b,s)["SwitchCount"])
            return;
        if (!b.hasWorkingItem(s, Item::RedCard))
            return;

        int target = b.player(t);
        if (b.countBackUp(target) == 0) {
            return;
        }

        b.sendItemMessage(38, s, 0, t);
        b.disposeItem(s);

        /* ingrain & suction cups */
        if (poke(b,t).value("Rooted").toBool()) {
            b.sendMoveMessage(107, 1, s, Pokemon::Grass,t);
            return;
        } else if (b.hasWorkingAbility(t,Ability::SuctionCups)) {
            b.sendMoveMessage(107, 0, s, 0,t);
            return;
        }

        QList<int> switches;

        for (int i = 0; i < 6; i++) {
            if (!b.isOut(target, i) && !b.poke(target,i).ko()) {
                switches.push_back(i);
            }
        }
        b.sendBack(t, true);
        b.sendPoke(t, switches[b.randint(switches.size())], true);
        b.sendMoveMessage(107,2,s,0,t);
        b.callEntryEffects(t);

        turn(b,t).remove("RedCardUser");
    }
 /* ripped off from focus energy */
 static void uas(int, int s, BS &b) {
     if (b.isOut(s)) {
         addFunction(poke(b,s), "TurnSettings", "FocusEnergy", &ts);
         b.sendMoveMessage(46,0,s);
     }
 }