Ir para conteúdo

Featured Replies

Postado
  • Autor

Vou tentar, pera :D

 

Funcionou , mas esse e so o da life ne? e o da mana? tem como me passar tbm? kk

Mostrar conteúdo oculto

bool Game::combatChangeMana(Creature* attacker, Creature* target, int32_t manaChange)
{
    const Position& targetPos = target->getPosition();
    if(manaChange > 0)
    {
        bool deny = false;
        CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
        for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)
        {
            if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_MANAGAIN, COMBAT_HEALING, manaChange))
                deny = true;
        }

        if(deny)
            return false;

        target->changeMana(manaChange);
        if(g_config.getBool(ConfigManager::SHOW_HEALING_DAMAGE) && !target->isGhost() &&
            (g_config.getBool(ConfigManager::SHOW_HEALING_DAMAGE_MONSTER) || !target->getMonster()))
        {
            char buffer[20];
            sprintf(buffer, "+%d", manaChange);

            const SpectatorVec& list = getSpectators(targetPos);
            addAnimatedText(list, targetPos, COLOR_DARKPURPLE, buffer);
        }
    }
    else
    {
        const SpectatorVec& list = getSpectators(targetPos);
        if(!target->isAttackable() || Combat::canDoCombat(attacker, target) != RET_NOERROR)
        {
            addMagicEffect(list, targetPos, MAGIC_EFFECT_POFF);
            return false;
        }

        int32_t manaLoss = std::min(target->getMana(), -manaChange);
        BlockType_t blockType = target->blockHit(attacker, COMBAT_MANADRAIN, manaLoss);
        if(blockType != BLOCK_NONE)
        {
            addMagicEffect(list, targetPos, MAGIC_EFFECT_POFF);
            return false;
        }

        if(manaLoss > 0)
        {
            bool deny = false;
            CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);
            for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)
            {
                if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_MANALOSS, COMBAT_UNDEFINEDDAMAGE, manaChange))
                    deny = true;
            }

            if(deny)
                return false;

            target->drainMana(attacker, COMBAT_MANADRAIN, manaLoss);
            char buffer[20];
            sprintf(buffer, "%d", manaLoss);

            addAnimatedText(list, targetPos, COLOR_BLUE, buffer);
        }
    }

    return true;
}

void Game::addCreatureHealth(const Creature* target)
{
    const SpectatorVec& list = getSpectators(target->getPosition());
    addCreatureHealth(list, target);
}

void Game::addCreatureHealth(const SpectatorVec& list, const Creature* target)
{
    Player* player = NULL;
    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)
    {
        if((player = (*it)->getPlayer()))
            player->sendCreatureHealth(target);
    }
}

void Game::addCreatureSquare(const Creature* target, uint8_t squareColor)
{
    const SpectatorVec& list = getSpectators(target->getPosition());
    addCreatureSquare(list, target, squareColor);
}

void Game::addCreatureSquare(const SpectatorVec& list, const Creature* target, uint8_t squareColor)
{
    Player* player = NULL;
    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)
    {
        if((player = (*it)->getPlayer()))
            player->sendCreatureSquare(target, squareColor);
    }
}

void Game::addAnimatedText(const Position& pos, uint8_t textColor, const std::string& text)
{
    const SpectatorVec& list = getSpectators(pos);
    addAnimatedText(list, pos, textColor, text);
}

void Game::addAnimatedText(const SpectatorVec& list, const Position& pos, uint8_t textColor,
    const std::string& text)
{
    Player* player = NULL;
    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)
    {
        if((player = (*it)->getPlayer()))
            player->sendAnimatedText(pos, textColor, text);
    }
}

void Game::addMagicEffect(const Position& pos, uint8_t effect, bool ghostMode/* = false*/)
{
    if(ghostMode)
        return;

    const SpectatorVec& list = getSpectators(pos);
    addMagicEffect(list, pos, effect);
}

void Game::addMagicEffect(const SpectatorVec& list, const Position& pos, uint8_t effect,
    bool ghostMode/* = false*/)
{
    if(ghostMode)
        return;

    Player* player = NULL;
    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)
    {
        if((player = (*it)->getPlayer()))
            player->sendMagicEffect(pos, effect);
    }
}

void Game::addDistanceEffect(const Position& fromPos, const Position& toPos, uint8_t effect)
{
    SpectatorVec list;
    getSpectators(list, fromPos, false);
    getSpectators(list, toPos, true);
    addDistanceEffect(list, fromPos, toPos, effect);
}

void Game::addDistanceEffect(const SpectatorVec& list, const Position& fromPos,
    const Position& toPos, uint8_t effect)
{
    Player* player = NULL;
    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)
    {
        if((player = (*it)->getPlayer()))
            player->sendDistanceShoot(fromPos, toPos, effect);
    }
}

void Game::startDecay(Item* item)
{
    if(!item || !item->canDecay() || item->getDecaying() == DECAYING_TRUE)
        return;

    if(item->getDuration() > 0)
    {
        item->addRef();
        item->setDecaying(DECAYING_TRUE);
        toDecayItems.push_back(item);
    }
    else
        internalDecayItem(item);
}

void Game::internalDecayItem(Item* item)
{
    const ItemType& it = Item::items.getItemType(item->getID());
    if(it.decayTo)
    {
        Item* newItem = transformItem(item, it.decayTo);
        startDecay(newItem);
    }
    else
    {
        ReturnValue ret = internalRemoveItem(NULL, item);
        if(ret != RET_NOERROR)
            std::clog << "> DEBUG: internalDecayItem failed, error code: " << (int32_t)ret << ", item id: " << item->getID() << std::endl;
    }
}

void Game::checkDecay()
{
    checkDecayEvent = Scheduler::getInstance().addEvent(createSchedulerTask(EVENT_DECAYINTERVAL,
        boost::bind(&Game::checkDecay, this)));

    size_t bucket = (lastBucket + 1) % EVENT_DECAYBUCKETS;
    for(DecayList::iterator it = decayItems[bucket].begin(); it != decayItems[bucket].end();)
    {
        Item* item = *it;
        int32_t decreaseTime = EVENT_DECAYINTERVAL * EVENT_DECAYBUCKETS;
        if(item->getDuration() - decreaseTime < 0)
            decreaseTime = item->getDuration();

        item->decreaseDuration(decreaseTime);
        if(!item->canDecay())
        {
            item->setDecaying(DECAYING_FALSE);
            freeThing(item);
            it = decayItems[bucket].erase(it);
            continue;
        }

        int32_t dur = item->getDuration();
        if(dur <= 0)
        {
            it = decayItems[bucket].erase(it);
            internalDecayItem(item);
            freeThing(item);
        }
        else if(dur < EVENT_DECAYINTERVAL * EVENT_DECAYBUCKETS)
        {
            it = decayItems[bucket].erase(it);
            size_t newBucket = (bucket + ((dur + EVENT_DECAYINTERVAL / 2) / 1000)) % EVENT_DECAYBUCKETS;
            if(newBucket == bucket)
            {
                internalDecayItem(item);
                freeThing(item);
            }
            else
                decayItems[newBucket].push_back(item);
        }
        else
            ++it;
    }

    lastBucket = bucket;
    cleanup();
}

void Game::checkLight()
{
    checkLightEvent = Scheduler::getInstance().addEvent(createSchedulerTask(EVENT_LIGHTINTERVAL,
        boost::bind(&Game::checkLight, this)));

    lightHour = lightHour + lightHourDelta;
    if(lightHour > 1440)
        lightHour = lightHour - 1440;

    if(std::abs(lightHour - SUNRISE) < 2 * lightHourDelta)
        lightState = LIGHT_STATE_SUNRISE;
    else if(std::abs(lightHour - SUNSET) < 2 * lightHourDelta)
        lightState = LIGHT_STATE_SUNSET;

    int32_t newLightLevel = lightLevel;
    bool lightChange = false;
    switch(lightState)
    {
        case LIGHT_STATE_SUNRISE:
        {
            newLightLevel += (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30;
            lightChange = true;
            break;
        }
        case LIGHT_STATE_SUNSET:
        {
            newLightLevel -= (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30;
            lightChange = true;
            break;
        }
        default:
            break;
    }

    if(newLightLevel <= LIGHT_LEVEL_NIGHT)
    {
        lightLevel = LIGHT_LEVEL_NIGHT;
        lightState = LIGHT_STATE_NIGHT;
    }
    else if(newLightLevel >= LIGHT_LEVEL_DAY)
    {
        lightLevel = LIGHT_LEVEL_DAY;
        lightState = LIGHT_STATE_DAY;
    }
    else
        lightLevel = newLightLevel;

    if(lightChange)
    {
        LightInfo lightInfo;
        getWorldLightInfo(lightInfo);
        for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
        {
            if(!it->second->hasCustomFlag(PlayerCustomFlag_HasFullLight))
                it->second->sendWorldLight(lightInfo);
        }
    }
}
#ifdef __WAR_SYSTEM__

void Game::checkWars()
{
    IOGuild::getInstance()->checkWars();
    checkWarsEvent = Scheduler::getInstance().addEvent(createSchedulerTask(EVENT_WARSINTERVAL,
        boost::bind(&Game::checkWars, this)));
}
#endif

void Game::getWorldLightInfo(LightInfo& lightInfo)
{
    lightInfo.level = lightLevel;
    lightInfo.color = 0xD7;
}

Editado por gbik (veja o histórico de edições)

  • Respostas 21
  • Visualizações 2.4k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

Postado
  Em 11/08/2015 em 20:21, gbik disse:

Vou tentar, pera :D

 

Funcionou , mas esse e so o da life ne? e o da mana? tem como me passar tbm? kk

Mostrar conteúdo oculto

bool Game::combatChangeMana(Creature* attacker, Creature* target, int32_t manaChange)

{

    const Position& targetPos = target->getPosition();

    if(manaChange > 0)

    {

        bool deny = false;

        CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);

        for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)

        {

            if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_MANAGAIN, COMBAT_HEALING, manaChange))

                deny = true;

        }

        if(deny)

            return false;

        target->changeMana(manaChange);

        if(g_config.getBool(ConfigManager::SHOW_HEALING_DAMAGE) && !target->isGhost() &&

            (g_config.getBool(ConfigManager::SHOW_HEALING_DAMAGE_MONSTER) || !target->getMonster()))

        {

            char buffer[20];

            sprintf(buffer, "+%d", manaChange);

            const SpectatorVec& list = getSpectators(targetPos);

            addAnimatedText(list, targetPos, COLOR_DARKPURPLE, buffer);

        }

    }

    else

    {

        const SpectatorVec& list = getSpectators(targetPos);

        if(!target->isAttackable() || Combat::canDoCombat(attacker, target) != RET_NOERROR)

        {

            addMagicEffect(list, targetPos, MAGIC_EFFECT_POFF);

            return false;

        }

        int32_t manaLoss = std::min(target->getMana(), -manaChange);

        BlockType_t blockType = target->blockHit(attacker, COMBAT_MANADRAIN, manaLoss);

        if(blockType != BLOCK_NONE)

        {

            addMagicEffect(list, targetPos, MAGIC_EFFECT_POFF);

            return false;

        }

        if(manaLoss > 0)

        {

            bool deny = false;

            CreatureEventList statsChangeEvents = target->getCreatureEvents(CREATURE_EVENT_STATSCHANGE);

            for(CreatureEventList::iterator it = statsChangeEvents.begin(); it != statsChangeEvents.end(); ++it)

            {

                if(!(*it)->executeStatsChange(target, attacker, STATSCHANGE_MANALOSS, COMBAT_UNDEFINEDDAMAGE, manaChange))

                    deny = true;

            }

            if(deny)

                return false;

            target->drainMana(attacker, COMBAT_MANADRAIN, manaLoss);

            char buffer[20];

            sprintf(buffer, "%d", manaLoss);

            addAnimatedText(list, targetPos, COLOR_BLUE, buffer);

        }

    }

    return true;

}

void Game::addCreatureHealth(const Creature* target)

{

    const SpectatorVec& list = getSpectators(target->getPosition());

    addCreatureHealth(list, target);

}

void Game::addCreatureHealth(const SpectatorVec& list, const Creature* target)

{

    Player* player = NULL;

    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)

    {

        if((player = (*it)->getPlayer()))

            player->sendCreatureHealth(target);

    }

}

void Game::addCreatureSquare(const Creature* target, uint8_t squareColor)

{

    const SpectatorVec& list = getSpectators(target->getPosition());

    addCreatureSquare(list, target, squareColor);

}

void Game::addCreatureSquare(const SpectatorVec& list, const Creature* target, uint8_t squareColor)

{

    Player* player = NULL;

    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)

    {

        if((player = (*it)->getPlayer()))

            player->sendCreatureSquare(target, squareColor);

    }

}

void Game::addAnimatedText(const Position& pos, uint8_t textColor, const std::string& text)

{

    const SpectatorVec& list = getSpectators(pos);

    addAnimatedText(list, pos, textColor, text);

}

void Game::addAnimatedText(const SpectatorVec& list, const Position& pos, uint8_t textColor,

    const std::string& text)

{

    Player* player = NULL;

    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)

    {

        if((player = (*it)->getPlayer()))

            player->sendAnimatedText(pos, textColor, text);

    }

}

void Game::addMagicEffect(const Position& pos, uint8_t effect, bool ghostMode/* = false*/)

{

    if(ghostMode)

        return;

    const SpectatorVec& list = getSpectators(pos);

    addMagicEffect(list, pos, effect);

}

void Game::addMagicEffect(const SpectatorVec& list, const Position& pos, uint8_t effect,

    bool ghostMode/* = false*/)

{

    if(ghostMode)

        return;

    Player* player = NULL;

    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)

    {

        if((player = (*it)->getPlayer()))

            player->sendMagicEffect(pos, effect);

    }

}

void Game::addDistanceEffect(const Position& fromPos, const Position& toPos, uint8_t effect)

{

    SpectatorVec list;

    getSpectators(list, fromPos, false);

    getSpectators(list, toPos, true);

    addDistanceEffect(list, fromPos, toPos, effect);

}

void Game::addDistanceEffect(const SpectatorVec& list, const Position& fromPos,

    const Position& toPos, uint8_t effect)

{

    Player* player = NULL;

    for(SpectatorVec::const_iterator it = list.begin(); it != list.end(); ++it)

    {

        if((player = (*it)->getPlayer()))

            player->sendDistanceShoot(fromPos, toPos, effect);

    }

}

void Game::startDecay(Item* item)

{

    if(!item || !item->canDecay() || item->getDecaying() == DECAYING_TRUE)

        return;

    if(item->getDuration() > 0)

    {

        item->addRef();

        item->setDecaying(DECAYING_TRUE);

        toDecayItems.push_back(item);

    }

    else

        internalDecayItem(item);

}

void Game::internalDecayItem(Item* item)

{

    const ItemType& it = Item::items.getItemType(item->getID());

    if(it.decayTo)

    {

        Item* newItem = transformItem(item, it.decayTo);

        startDecay(newItem);

    }

    else

    {

        ReturnValue ret = internalRemoveItem(NULL, item);

        if(ret != RET_NOERROR)

            std::clog << "> DEBUG: internalDecayItem failed, error code: " << (int32_t)ret << ", item id: " << item->getID() << std::endl;

    }

}

void Game::checkDecay()

{

    checkDecayEvent = Scheduler::getInstance().addEvent(createSchedulerTask(EVENT_DECAYINTERVAL,

        boost::bind(&Game::checkDecay, this)));

    size_t bucket = (lastBucket + 1) % EVENT_DECAYBUCKETS;

    for(DecayList::iterator it = decayItems[bucket].begin(); it != decayItems[bucket].end() ;)

    {

        Item* item = *it;

        int32_t decreaseTime = EVENT_DECAYINTERVAL * EVENT_DECAYBUCKETS;

        if(item->getDuration() - decreaseTime < 0)

            decreaseTime = item->getDuration();

        item->decreaseDuration(decreaseTime);

        if(!item->canDecay())

        {

            item->setDecaying(DECAYING_FALSE);

            freeThing(item);

            it = decayItems[bucket].erase(it);

            continue;

        }

        int32_t dur = item->getDuration();

        if(dur <= 0)

        {

            it = decayItems[bucket].erase(it);

            internalDecayItem(item);

            freeThing(item);

        }

        else if(dur < EVENT_DECAYINTERVAL * EVENT_DECAYBUCKETS)

        {

            it = decayItems[bucket].erase(it);

            size_t newBucket = (bucket + ((dur + EVENT_DECAYINTERVAL / 2) / 1000)) % EVENT_DECAYBUCKETS;

            if(newBucket == bucket)

            {

                internalDecayItem(item);

                freeThing(item);

            }

            else

                decayItems[newBucket].push_back(item);

        }

        else

            ++it;

    }

    lastBucket = bucket;

    cleanup();

}

void Game::checkLight()

{

    checkLightEvent = Scheduler::getInstance().addEvent(createSchedulerTask(EVENT_LIGHTINTERVAL,

        boost::bind(&Game::checkLight, this)));

    lightHour = lightHour + lightHourDelta;

    if(lightHour > 1440)

        lightHour = lightHour - 1440;

    if(std::abs(lightHour - SUNRISE) < 2 * lightHourDelta)

        lightState = LIGHT_STATE_SUNRISE;

    else if(std::abs(lightHour - SUNSET) < 2 * lightHourDelta)

        lightState = LIGHT_STATE_SUNSET;

    int32_t newLightLevel = lightLevel;

    bool lightChange = false;

    switch(lightState)

    {

        case LIGHT_STATE_SUNRISE:

        {

            newLightLevel += (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30;

            lightChange = true;

            break;

        }

        case LIGHT_STATE_SUNSET:

        {

            newLightLevel -= (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30;

            lightChange = true;

            break;

        }

        default:

            break;

    }

    if(newLightLevel <= LIGHT_LEVEL_NIGHT)

    {

        lightLevel = LIGHT_LEVEL_NIGHT;

        lightState = LIGHT_STATE_NIGHT;

    }

    else if(newLightLevel >= LIGHT_LEVEL_DAY)

    {

        lightLevel = LIGHT_LEVEL_DAY;

        lightState = LIGHT_STATE_DAY;

    }

    else

        lightLevel = newLightLevel;

    if(lightChange)

    {

        LightInfo lightInfo;

        getWorldLightInfo(lightInfo);

        for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)

        {

            if(!it->second->hasCustomFlag(PlayerCustomFlag_HasFullLight))

                it->second->sendWorldLight(lightInfo);

        }

    }

}

#ifdef __WAR_SYSTEM__

void Game::checkWars()

{

    IOGuild::getInstance()->checkWars();

    checkWarsEvent = Scheduler::getInstance().addEvent(createSchedulerTask(EVENT_WARSINTERVAL,

        boost::bind(&Game::checkWars, this)));

}

#endif

void Game::getWorldLightInfo(LightInfo& lightInfo)

{

    lightInfo.level = lightLevel;

    lightInfo.color = 0xD7;

}

 

Mostrar conteúdo oculto

Postado
  • Autor
  Em 11/08/2015 em 21:30, MaTTch disse:

Mostrar conteúdo oculto

Muito Obrigado :)

Mano, qual notepad tu usa? kkk :(

Editado por gbik (veja o histórico de edições)

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo