Exemplo n.º 1
0
WEvent * REDrawReplacement::replace(WEvent *event)
{
    if (!event) return event;
    WEventDraw * e = dynamic_cast<WEventDraw*> (event);
    if (!e) return event;
    if (DrawerOfCard != e->player) return event;
    if(!replacementAbility) return event;
    //check for dredge
    TargetChooserFactory tf(e->player->getObserver());
    TargetChooser * tcb = NULL;
    tcb = tf.createTargetChooser("dredgeable",source->source);
    tcb->targetter = NULL;
    if(tcb->validTargetsExist())
    {
        if(e->player == DrawerOfCard && e->player == source->source->controller())
        {
            SAFE_DELETE(tcb);
            return event;
        }
    }
    SAFE_DELETE(tcb);

    vector<MTGAbility*>selection;
    //look for other draw replacement effects
    list<ReplacementEffect *>::iterator it;
    GameObserver * game = source->source->getObserver();
    if(replacementAbility->source->controller() == DrawerOfCard)
    for (it = game->replacementEffects->modifiers.begin(); it != game->replacementEffects->modifiers.end(); it++)
    {
        if(REDrawReplacement * DR = dynamic_cast<REDrawReplacement *>(*it))
        {
            MTGAbility * otherA = NULL;
            if(DR->DrawerOfCard == e->player)
            {
                if(DR->replacementAbility->oneShot)
                    selection.push_back(DR->replacementAbility->clone());
                else
                {
                    otherA = NEW GenericAddToGame(game, game->mLayers->actionLayer()->getMaxId(), source->source,NULL,DR->replacementAbility->clone());
                    selection.push_back(otherA);
                }
            }
        }
    }

    
    for(int j = 0; j < e->nb_cards; j++)
    {
        if(e->player != DrawerOfCard || selection.size() < 2)
        {
            MTGAbility * toResolve = replacementAbility->clone();
            if(replacementAbility->oneShot)
                toResolve->resolve();
            else
                toResolve->addToGame();
        }
        else
        {
            MTGAbility * menuChoice = NEW MenuAbility(game, 1, source->source, source->source,true,selection,NULL,"Choose Draw Replacement");
            menuChoice->addToGame();
        }
    }

    delete event;
    event = NULL;
    return event;
}
Exemplo n.º 2
0
void Rules::addExtraRules(GameObserver* g)
{
    int id = g->mLayers->actionLayer()->getMaxId();
    MTGAllCards::sortSubtypeList();
    for (int i = 0; i < 2; ++i)
    {
        Player * p = g->players[i];
        //Trick so that the abilities don't die;
        g->ExtraRules[i].currentZone = p->game->inPlay;
        g->ExtraRules[i].lastController = p;
        g->ExtraRules[i].owner = p;
        for (size_t j = 0; j < initState.playerData[i].extraRules.size(); ++j)
        {
            AbilityFactory af(g);
            MTGPlayerCards * hand = NULL;
            int handsize = 7;
            int difficultyRating = 0;
            int Optimizedhandcheat = options[Options::OPTIMIZE_HAND].number;
            MTGAbility * a = af.parseMagicLine(initState.playerData[i].extraRules[j], id++, NULL, &(g->ExtraRules[i]));
            if (p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
                != GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode
                != GAME_TYPE_STORY && 
                g->mRules->gamemode != GAME_TYPE_DEMO && (!g->players[0] == PLAYER_TYPE_CPU && !g->players[1] == PLAYER_TYPE_CPU)
#ifdef NETWORK_SUPPORT
                && !g->players[1] == PLAYER_TYPE_REMOTE
#endif //NETWORK_SUPPORT
                    )//keep this out of momir and other game modes.
            {
                difficultyRating = g->getDeckManager()->getDifficultyRating(g->players[0], g->players[1]);
            }

            if (a)
            {
                //We make those non interruptible, so that they don't appear on the player's stack
                a->canBeInterrupted = false;
                if (a->oneShot)
                {
                    if (((p->isAI() && p->playMode
                        != Player::MODE_AI && p->opponent()->playMode
                        != Player::MODE_AI)||( !p->isAI() && Optimizedhandcheat)) && a->aType == MTGAbility::STANDARD_DRAW &&
                        difficultyRating != HARD && p->playMode
                        != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
                        != GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode
                        != GAME_TYPE_STORY)//stupid protections to keep this out of mimor and other game modes.
                    {
                        handsize = ((AADrawer *)a)->getNumCards();
                        if(difficultyRating == EASY)
                        {
                            ((AIPlayer *) p)->forceBestAbilityUse = true;
                            ((AIPlayer *) p)->agressivity += 100;
                            hand->OptimizedHand(p,handsize, 3, 1, 3);//easy decks get a major boost, open hand is 2lands,1 creature under 3 mana,3spells under 3 mana.
                        }
                        else if (difficultyRating == NORMAL)
                        {
                            hand->OptimizedHand(p,handsize, 1, 0, 2);//give the Ai deck a tiny boost by giving it 1 land and 2 spells under 3 manacost.
                        }
                        else
                        {
                            hand->OptimizedHand(p,handsize, 3, 1, 3);//no rating fall out case.
                        }
                    }
                    else
                    {//resolve normally if the deck is listed as hard.
                        a->resolve();
                    }
                    delete (a);
                }
                else
                {
                    a->addToGame();
                }

            }
        }
    }

    for (size_t j = 0; j < extraRules.size(); ++j)
    {
        AbilityFactory af(g);
        MTGAbility * a = af.parseMagicLine(extraRules[j], id++, NULL, &(g->ExtraRules[0]));
        if (a)
        {
            if (a->oneShot)
            {
                a->resolve();
                delete (a);
            }
            else
            {
                a->addToGame();
            }
        }
    }
}