예제 #1
0
void Character::update()
{
    // First, deal with being generic updates
    Being::update();

    // Update character level if needed.
    if (mRecalculateLevel)
    {
        mRecalculateLevel = false;
        recalculateLevel();
    }

    // Dead character: don't regenerate anything else
    if (getAction() == DEAD)
        return;

    // Update special recharge
    for (SpecialMap::iterator it = mSpecials.begin(), it_end = mSpecials.end();
         it != it_end; it++)
    {
        SpecialValue &s = it->second;
        if (s.specialInfo->rechargeable && s.currentMana < s.specialInfo->neededMana)
        {
            s.currentMana += s.rechargeSpeed;
            if (s.currentMana >= s.specialInfo->neededMana &&
                    s.specialInfo->rechargedCallback.isValid())
            {
                Script *script = ScriptManager::currentState();
                script->prepare(s.specialInfo->rechargedCallback);
                script->push(this);
                script->push(s.specialInfo->id);
                script->execute();
            }
        }
    }

    if (mSpecialUpdateNeeded)
    {
        sendSpecialUpdate();
        mSpecialUpdateNeeded = false;
    }

    mStatusEffects.clear();
    StatusEffects::iterator it = mStatus.begin();
    while (it != mStatus.end())
    {
        mStatusEffects[it->first] = it->second.time;
        it++;
    }

    processAttacks();
}
예제 #2
0
void CharacterComponent::update(Entity &entity)
{
    // Update character level if needed.
    if (mRecalculateLevel)
    {
        mRecalculateLevel = false;
        recalculateLevel(entity);
    }

    // Dead character: don't regenerate anything else
    if (entity.getComponent<BeingComponent>()->getAction() == DEAD)
        return;

    // Update special recharge
    for (SpecialMap::iterator it = mSpecials.begin(), it_end = mSpecials.end();
         it != it_end; it++)
    {
        SpecialValue &s = it->second;
        if (s.specialInfo->rechargeable && s.currentMana < s.specialInfo->neededMana)
        {
            s.currentMana += s.rechargeSpeed;
            if (s.currentMana >= s.specialInfo->neededMana &&
                    s.specialInfo->rechargedCallback.isValid())
            {
                Script *script = ScriptManager::currentState();
                script->prepare(s.specialInfo->rechargedCallback);
                script->push(&entity);
                script->push(s.specialInfo->id);
                script->execute(entity.getMap());
            }
        }
    }

    if (mSpecialUpdateNeeded)
    {
        sendSpecialUpdate();
        mSpecialUpdateNeeded = false;
    }
}