Ejemplo n.º 1
0
void LuaScript::assignCallback(Script::Ref &function)
{
    assert(lua_isfunction(mRootState, -1));

    // If there is already a callback set, replace it
    if (function.isValid())
        luaL_unref(mRootState, LUA_REGISTRYINDEX, function.value);

    function.value = luaL_ref(mRootState, LUA_REGISTRYINDEX);
}
Ejemplo n.º 2
0
static bool executeCallback(Script::Ref function, Entity &entity)
{
    if (!function.isValid())
        return false;

    Script *script = ScriptManager::currentState();
    script->prepare(function);
    script->push(&entity);
    script->execute(entity.getMap());
    return true;
}
Ejemplo n.º 3
0
static bool executeCallback(Script::Ref function, Character *character)
{
    if (!function.isValid())
        return false;

    Script *script = ScriptManager::currentState();
    script->prepare(function);
    script->push(character);
    script->execute(character->getMap());
    return true;
}
Ejemplo n.º 4
0
void Monster::processAttack()
{
    if (!mTarget)
    {
        setAction(STAND);
        return;
    }

    if (!mCurrentAttack)
        return;

    mAttackTimeout.set(mCurrentAttack->aftDelay
                                 + mCurrentAttack->preDelay);

    float damageFactor = mCurrentAttack->damageFactor;

    Damage dmg;
    dmg.skill   = 0;
    dmg.base    = getModifiedAttribute(MOB_ATTR_PHY_ATK_MIN) * damageFactor;
    dmg.delta   = getModifiedAttribute(MOB_ATTR_PHY_ATK_DELTA) * damageFactor;
    dmg.cth     = getModifiedAttribute(ATTR_ACCURACY);
    dmg.element = mCurrentAttack->element;
    dmg.range   = mCurrentAttack->range;

    int hit = performAttack(mTarget, dmg);

    if (!mCurrentAttack->scriptEvent.empty() && hit > -1)
    {
        Script::Ref function = mSpecy->getEventCallback(mCurrentAttack->scriptEvent);
        if (function.isValid())
        {
            Script *script = ScriptManager::currentState();
            script->setMap(getMap());
            script->prepare(function);
            script->push(this);
            script->push(mTarget);
            script->push(hit);
            script->execute();
        }
    }
}
Ejemplo n.º 5
0
static void callVariableCallback(Script::Ref &function, const std::string &key,
                                 const std::string &value, MapComposite *map)
{
    if (function.isValid())
    {
        Script *s = ScriptManager::currentState();
        s->prepare(function);
        s->push(key);
        s->push(value);
        s->execute(map);
    }
}
Ejemplo n.º 6
0
bool ScriptManager::performCraft(Being *crafter,
                                 const std::list<InventoryItem> &recipe)
{
    if (!_craftCallback.isValid())
    {
        LOG_WARN("No crafting callback set! Crafting disabled.");
        return false;
    }
    _currentState->prepare(_craftCallback);
    _currentState->push(crafter);
    _currentState->push(recipe);
    _currentState->execute();
    return true;
}