Beispiel #1
0
	/**
	 * Creates a new stat modifier object with the given parameters.
	 * The value of this modifier is used in the context of the type of modification.
	 * <br>This is the list of each modifier type:
	 * <ul>
	 * <li>= : Sets the stat to the given value. This mod is applied first.</li>
	 * <li>* : Multiplies the stat by the given value. This mod is applied second.</li>
	 * <li>+ : Adds the given value directly onto the stat, this value can be negative. This mod is applied third.</li>
	 * </ul>
	 *
	 * @param number value The value of this modifier.
	 * @param string type The stat modifier type.
	 * @param boolean [true] magical This currently does not change the behaviour of the modifier, however it does
	 *  allow the UI to show the origin of this mod better.
	 */
	int StatModifier_ctor(lua_State *lua)
	{
		if (lua_gettop(lua) == 0)
		{
			StatModifier *stat = new StatModifier();
		
			wrapObject<StatModifier>(lua, stat);
			return 1;
		}
		else if (lua_isnum(lua, 1) && lua_isstr(lua, 2))
		{
			StatModifierType type = getStatModifier(lua, 2);
			if (type == MOD_MAX_LENGTH)
			{
				lua_pushnil(lua);
				return 1;
			}
			bool magical = true;
			if (lua_isboolean(lua, 3))
			{
				magical = lua_tobool(lua, 3);
			}
			StatModifier *stat = new StatModifier(lua_tofloat(lua, 1), type, magical);
		
			wrapObject<StatModifier>(lua, stat);
			return 1;
		}
		return LuaState::expectedArgs(lua, "@new", 2, "", "number value, string type, boolean [true] magical");
	}
	/**
	 * Sets if the given dialogue will be available from this component.
	 * @param string dialogueId The dialogue id to set.
	 * @param boolean available The availability of the given dialogue.
	 * @returns DialogueComponent This
	 */
	int DialogueComponent_dialogue_available(lua_State *lua)
	{
		DialogueComponent *comp = castUData<DialogueComponent>(lua, 1);
		if (comp)
		{
			if (lua_isstr(lua, 2))
			{
				if (lua_gettop(lua) == 2)
				{
					lua_pushboolean(lua, comp->isDialogueAvailable(lua_tostring(lua, 2)));
					return 1;
				}
				else
				{
					if (lua_isbool(lua, 3))
					{
						comp->setDialogueAvailable(lua_tostring(lua, 2), lua_tobool(lua, 3));
						lua_first(lua);
					}
				}
				return LuaState::expectedArgs(lua, "available", "string dialogueId, boolean available");
			}
			return LuaState::expectedArgs(lua, "available", "string dialogueId");
		}
		return LuaState::expectedContext(lua, "available", "DialogueComponent");
	}
Beispiel #3
0
bool cLuaWrapper::convertVariable( int luaIndex )
{
	if( lua_isboolean( L, index ) )
	{
		return ( bool )lua_tobool( L, index );
	}
	else
	{
		lua_pop( L, 1 );
		error();
		return NULL;
	}
}
Beispiel #4
0
	/**
	 * Silently sets the quest completed/finished flag, this does not fire any events.
	 *
	 * @param boolean completed Sets if the quest has been completed/finished.
	 * @returns am.quest This
	 */
	int Quest_complete(lua_State *lua)
	{
		Quest *quest = castUData<Quest>(lua, 1);
		if (quest)
		{
			if (lua_gettop(lua) == 1)
			{
				lua_pushboolean(lua, quest->isCompleted());
				return 1;
			}
			else if (lua_isbool(lua, 2))
			{
				quest->setCompleted(lua_tobool(lua, 2));
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "complete", "boolean complete");
		}
		return LuaState::expectedContext(lua, "complete", "am.quest");
	}
Beispiel #5
0
	/**
	 * Sets if modifier is magical in nature.
	 *
	 * @param boolean magical The new magical flag for this modifier.
	 * @returns am.stat_modifier This
	 */
	int StatModifier_magical(lua_State *lua)
	{
		StatModifier *mod = castUData<StatModifier>(lua, 1);
		if (mod)
		{
			if (lua_gettop(lua) == 1)
			{
				lua_pushboolean(lua, mod->isMagical());
				return 1;
			}
			else if (lua_isbool(lua, 2))
			{
				mod->setMagical(lua_tobool(lua, 2));
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "magical", "boolean magical");
		}
		return LuaState::expectedContext(lua, "magical", "am.stat_modifier");
	}
	/**
	 * Sets if a dialogue subject is locked or unlocked for this dialogue component.
	 * Unlocked subjects will be available to use in dialogue.
	 * @param string subject The subject to lock or unlock.
	 * @param boolean locked Sets is the subject is locked or unlocked.
	 * @returns DialogueComponent This
	 */
	int DialogueComponent_subject_lock(lua_State *lua)
	{
		DialogueComponent *comp = castUData<DialogueComponent>(lua, 1);
		if (comp)
		{
			if (lua_gettop(lua) == 2)
			{
				if (lua_isstr(lua, 2))
				{
					lua_pushboolean(lua, comp->isSubjectLocked(lua_tostring(lua, 2)));
					return 1;
				}
				return LuaState::expectedArgs(lua, "locked", "string subject");
			}
			else if (lua_isbool(lua, 3))
			{
				comp->setSubjectLock(lua_tostring(lua, 2), lua_tobool(lua, 3));
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "locked", "string subject, boolean locked");
		}
		return LuaState::expectedContext(lua, "locked", "DialogueComponent");
	}
Beispiel #7
0
std::map< std::string, boost::any > cLuaWrapper::convertTable()
{
	lua_pushnil( L );
	std::map< std::string, boost::any > target;
	while ( lua_next( L, -2 ) != 0 ) 
	{
		std::string key = lua_tostring( L, -2 );
		if( lua_isboolean( L, -1 ) )
		{
			target.insert( key, ( bool )lua_tobool( L, -1 ) );
		}
		else if( lua_isstring( L, -1 ) )
		{
			target.insert( key, ( std::string )lua_tostring( L, -1 ) );
		}
		else if( lua_isnumber( L, -1 ) )
		{
			target.insert( key, ( double )lua_tonumber( L, -1 ) );
		}
		else if( lua_istable( L, -1 ) )
		{
			target.insert( key, ( std::map< std::string, boost::any > )convertTable() );
		}
		else if( lua_isnil( L, -1 ) )
		{
			target.insert( key, ( void* )NULL );
		}
		else
		{
			lua_pop( L, 1 );
			error();
			return NULL;
		}
	}
	lua_pop( L, 1 ); 
	return target;
}
Beispiel #8
0
int DemoAddEvent(lua_State *pLuaState)
{
    TEvent *pEvent    = NEW TEvent;
    pEvent->iEvent    = lua_toint  (pLuaState,1);
    pEvent->fTime     = lua_tofloat(pLuaState,2);
    pEvent->fDuration = 0.f;
    switch (pEvent->iEvent)
    {
    // For FX
    case EV_FX_ATTACH:
        pEvent->iFX         = lua_toint(pLuaState,3);
        pEvent->iSetVarInt  = lua_toint(pLuaState,4);
        break;
    case EV_FX_UNATTACH:
        pEvent->iFX         = lua_toint(pLuaState,3);
        break;
    case EV_FX_RESET:
        pEvent->iFX         = lua_toint(pLuaState,3);
        break;
    case EV_FX_ADDFILTER:
        pEvent->iFX         = lua_toint(pLuaState,3);
        strcpy_s(pEvent->pSetFilter, 32, lua_tostring(pLuaState,4));
        break;
    case EV_FX_SETSPEED:
    case EV_FX_SETALPHA:
    case EV_FX_SETTIME:
        // (EV_FX_SETXXX, TIME, FX, VALUE, VALUETO, DURATION
        pEvent->iFX          = lua_toint  (pLuaState,3);
        pEvent->fDuration    = lua_tofloat(pLuaState,6);
        pEvent->fSetVarFloat = lua_tofloat(pLuaState,4);
        if (pEvent->fDuration > 0.f) pEvent->fSetVarFloatTo = lua_tofloat(pLuaState,5);
        break;
    case EV_FX_SETBLEND:
        pEvent->iFX          = lua_toint(pLuaState,3);
        pEvent->iSetVarInt   = lua_toint(pLuaState,4);
        break;
    case EV_FX_SETVAR:
        // (EV_FX_SETVAR, TIME, FX, VARTYPE, VARSCOPE, VAROBJECT, VAR, VALUE, VALUETO, DURATION);
        pEvent->iFX          = lua_toint(pLuaState,3);
        pEvent->iSetVarType  = lua_toint(pLuaState,4);
        pEvent->iSetVarScope = g_LuaPlayer->GetVarScope (pEvent->iFX, lua_tostring(pLuaState,5));
        pEvent->iSetVarObject= g_LuaPlayer->GetVarObject(pEvent->iFX, pEvent->iSetVarScope, lua_tostring(pLuaState,6));
        pEvent->iSetVar      = g_LuaPlayer->GetVarName  (pEvent->iFX, pEvent->iSetVarScope, lua_tostring(pLuaState,7));
        pEvent->fDuration    = lua_tofloat (pLuaState,10);
        switch (pEvent->iSetVarType)
        {
        case SET_VAR_INT:
            pEvent->iSetVarInt   = lua_toint  (pLuaState,8);
            break;
        case SET_VAR_FLOAT:
            pEvent->fSetVarFloat = lua_tofloat(pLuaState,8);
            if (pEvent->fDuration > 0.f) pEvent->fSetVarFloatTo = lua_tofloat(pLuaState,9);
        case SET_VAR_BOOL:
            pEvent->bSetVarBool  = lua_tobool (pLuaState,8);
            break;
        }
        break;
    // For FF
    case EV_FF_SETVAR:
        // (EV_FF_SETVAR, TIME, FX, VARTYPE, VAR, DURATION, VALUE, VALUETO);
        pEvent->iFX          = lua_toint(pLuaState,3);
        pEvent->iSetVarType  = lua_toint   (pLuaState,4);
        strcpy_s(pEvent->pSetVar, 32, lua_tostring(pLuaState,5));
        pEvent->fDuration    = lua_tofloat (pLuaState,8);
        switch (pEvent->iSetVarType)
        {
        case SET_VAR_INT:
            pEvent->iSetVarInt   = lua_toint  (pLuaState,6);
            break;
        case SET_VAR_FLOAT:
            pEvent->fSetVarFloat = lua_tofloat(pLuaState,6);
            if (pEvent->fDuration > 0.f) pEvent->fSetVarFloatTo = lua_tofloat(pLuaState,7);
            break;
        case SET_VAR_BOOL:
            pEvent->bSetVarBool  = lua_tobool (pLuaState,6);
            break;
        }
        break;
    }
    g_LuaPlayer->AddEvent(pEvent);
    return 0;
}
Beispiel #9
0
//---------------------------------------------------------------------------//
// Funciones
//
//---------------------------------------------------------------------------//
int DemoInit(lua_State *pLuaState)
{
    g_LuaPlayer->DemoInit(lua_tofloat(pLuaState,1), lua_tofloat(pLuaState,2), lua_toint(pLuaState,3), lua_tobool(pLuaState,4));
    return 0;
}