void Lua_V2::GetActorChores() {
	lua_Object actorObj = lua_getparam(1);
	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;
	Actor *actor = getactor(actorObj);
	Costume *costume = actor->getCurrentCostume();

	lua_Object result = lua_createtable();
	lua_pushobject(result);

	if (!costume) {
		lua_pushstring("count");
		lua_pushnumber(0);
		lua_settable();
		lua_pushobject(result);
		return;
	}

	int num = costume->getNumChores();

	lua_pushstring("count");
	lua_pushnumber(num);
	lua_settable();

	for (int i = 0; i < num; ++i) {
		lua_pushobject(result);
		lua_pushnumber(i);
		lua_pushusertag(((EMIChore *)costume->getChore(i))->getId(), MKTAG('C','H','O','R'));
		lua_settable();
	}

	lua_pushobject(result);
}
Example #2
0
void Lua_V2::PlayActorChore() {
	lua_Object actorObj = lua_getparam(1);
	lua_Object choreObj = lua_getparam(2);
	lua_Object costumeObj = lua_getparam(3);
//	lua_Object modeObj = lua_getparam(4);
//	lua_Object paramObj = lua_getparam(5);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);

	if (!lua_isstring(choreObj) || !lua_isstring(costumeObj))
		lua_pushnil();

/*	bool mode = false;
	float param = 0.0;

	if (!lua_isnil(modeObj)) {
		if (lua_getnumber(modeObj) != 0.0)
			mode = true;
		if (!lua_isnil(paramObj))
			if (lua_isnumber(paramObj))
				param = lua_getnumber(paramObj);
	}*/

	const char *choreName = lua_getstring(choreObj);
	const char *costumeName = lua_getstring(costumeObj);
	Costume *costume = actor->findCostume(costumeName);

	if (costume == NULL) {
		actor->pushCostume(costumeName);
		costume = actor->findCostume(costumeName);
	}

	PoolChore *chore = (PoolChore *)costume->getChore(choreName);
	costume->playChore(choreName);
	if (chore) {
		lua_pushusertag(chore->getId(), MKTAG('C','H','O','R'));
	} else {
		lua_pushnil();
	}

}
// TODO: Implement, verify, and rename unknown 5th parameter
void Lua_V2::PlayActorChore() {
	lua_Object actorObj = lua_getparam(1);
	lua_Object choreObj = lua_getparam(2);
	lua_Object costumeObj = lua_getparam(3);
	lua_Object modeObj = lua_getparam(4);
	/* lua_Object paramObj = */ lua_getparam(5);

	if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
		return;

	Actor *actor = getactor(actorObj);

	if (!lua_isstring(choreObj) || !lua_isstring(costumeObj))
		lua_pushnil();

	bool mode = false;
	// float param = 0.0;

	if (!lua_isnil(modeObj)) {
		if (lua_getnumber(modeObj) != 0.0)
			mode = true;
		//if (!lua_isnil(paramObj))
		//	if (lua_isnumber(paramObj))
		//		param = lua_getnumber(paramObj);
	}

	const char *choreName = lua_getstring(choreObj);

	const char *costumeName = lua_getstring(costumeObj);
	Costume *costume;
	// If a new wear chore is set and it uses a different costume than the
	// current one and neither of them is the shadow costume stop all active
	// chores and remove the old costume before setting the new one.
	//
	// This is necessary, because always the last costume on the stack, even
	// if it is not active, is returned by getCurrentCostume(). This would
	// cause an issue if the costumes would have different joints and the lua
	// code would consider a different costume active than the C code.
	if (0 == strncmp("wear_", choreName, 5)) {
		if (0 != strncmp("fx/dumbshadow.cos", costumeName, 17)) {
			if (actor->getCurrentCostume() != NULL &&
			    actor->getCurrentCostume()->getFilename() != "fx/dumbshadow.cos" &&
			    actor->getCurrentCostume()->getFilename().compareToIgnoreCase(costumeName) != 0) {
				actor->stopAllChores();
				actor->setRestChore(-1, NULL);
				actor->setWalkChore(-1, NULL);
				actor->setTurnChores(-1, -1, NULL);
				actor->setMumbleChore(-1, NULL);
				actor->popCostume();
			}
		}
	}
	if (!findCostume(costumeObj, actor, &costume))
		return;

	EMIChore *chore = (EMIChore *)costume->getChore(choreName);
	if (0 == strncmp("wear_", choreName, 5)) {
		actor->setLastWearChore(costume->getChoreId(choreName), costume);
	}

	if (mode) {
		costume->playChoreLooping(choreName);
	} else {
		costume->playChore(choreName);
	}
	if (chore) {
		lua_pushusertag(chore->getId(), MKTAG('C','H','O','R'));
	} else {
		lua_pushnil();
	}

}