Beispiel #1
0
bool TalkAction::placeNpc(Player* player, const std::string& words, const std::string& param)
{
	if (!player)
	{
		return false;
	}

	Npc* npc = Npc::createNpc(param);

	if (!npc)
	{
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "This NPC does not exist.");
		return false;
	}

	// Place the npc
	if (g_game.placeCreature(npc, player->getPosition()))
	{
		g_game.addMagicEffect(player->getPosition(), NM_ME_MAGIC_BLOOD);
		npc->setMasterPos(npc->getPosition());
		return true;
	}
	else
	{
		delete npc;
		player->sendCancelMessage(RET_NOTENOUGHROOM);
		g_game.addMagicEffect(player->getPosition(), NM_ME_PUFF);
	}

	return false;
}
Beispiel #2
0
int NpcScriptInterface::luagetDistanceTo(lua_State* L)
{
    //getDistanceTo(uid)
    ScriptEnvironment* env = getScriptEnv();

    Npc* npc = env->getNpc();
    if (!npc) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
        lua_pushnil(L);
        return 1;
    }

    uint32_t uid = getNumber<uint32_t>(L, -1);

    Thing* thing = env->getThingByUID(uid);
    if (!thing) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
        lua_pushnil(L);
        return 1;
    }

    const Position& thingPos = thing->getPosition();
    const Position& npcPos = npc->getPosition();
    if (npcPos.z != thingPos.z) {
        lua_pushnumber(L, -1);
    } else {
        int32_t dist = std::max<int32_t>(Position::getDistanceX(npcPos, thingPos), Position::getDistanceY(npcPos, thingPos));
        lua_pushnumber(L, dist);
    }
    return 1;
}
Beispiel #3
0
int NpcScriptInterface::luagetDistanceTo(lua_State *L)
{
	//getDistanceTo(uid)
	uint32_t uid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	Thing* thing = env->getThingByUID(uid);
	if(thing && npc){
		Position thing_pos = thing->getPosition();
		Position npc_pos = npc->getPosition();
		if(npc_pos.z != thing_pos.z){
			lua_pushnumber(L, -1);
		}
		else{
			int32_t dist = std::max(std::abs(npc_pos.x - thing_pos.x), std::abs(npc_pos.y - thing_pos.y));
			lua_pushnumber(L, dist);
		}
	}
	else{
		reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
		lua_pushnil(L);
	}

	return 1;
}
Beispiel #4
0
int NpcScriptInterface::luaActionSay(lua_State* L)
{
	//selfSay(words [[, target], send_to_all])
	    // send_to_all defaults to true if there is no target, false otherwise
	uint32_t parameters = lua_gettop(L);
	uint32_t target = 0;
	bool send_to_all = true;
	
	if(parameters == 3)
	{
		send_to_all = (popNumber(L) == LUA_TRUE);
		target = popNumber(L);
	}
	else if(parameters == 2)
	{
		target = popNumber(L);
		send_to_all = false;
	}
	std::string msg(popString(L));
	
	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	Player* focus = env->getPlayerByUID(target);
	if(npc){
		npc->doSay(msg, focus, send_to_all);
	}

	return 0;
}
Beispiel #5
0
int32_t NpcScriptInterface::luaActionSay(lua_State* L)
{
	//selfSay(words [[, target], publicize])
	// publicize defaults to true if there is no target, false otherwise
	uint32_t parameters = lua_gettop(L);
	uint32_t target = 0;
	bool publicize;
	if (parameters >= 3) {
		publicize = popBoolean(L);
	} else {
		publicize = true;
	}

	if (parameters >= 2) {
		target = popNumber(L);
		if (target != 0) {
			publicize = false;
		}
	}

	std::string text = popString(L);

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		if (publicize) {
			npc->doSay(text);
		} else {
			npc->doSayToPlayer(g_game.getPlayerByID(target), text);
		}
	}

	return 0;
}
Beispiel #6
0
Npc* Npc::createNpc(const std::string& name)
{
	Npc* npc = new Npc(name);
	if (!npc->load()) {
		delete npc;
		return nullptr;
	}
	return npc;
}
Beispiel #7
0
int32_t NpcScriptInterface::luaActionTurn(lua_State* L)
{
	//selfTurn(direction)
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->doTurn(static_cast<Direction>(getNumber<uint32_t>(L, 1)));
	}
	return 0;
}
Beispiel #8
0
int32_t NpcScriptInterface::luaSetNpcFocus(lua_State* L)
{
	//doNpcSetCreatureFocus(cid)
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->setCreatureFocus(g_game.getCreatureByID(popNumber(L)));
	}
	return 0;
}
Beispiel #9
0
int32_t NpcScriptInterface::luaActionTurn(lua_State* L)
{
	//selfTurn(direction)
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->doTurn((Direction)popNumber(L));
	}
	return 0;
}
Beispiel #10
0
int NpcScriptInterface::luaSetNpcFocus(lua_State* L)
{
    //doNpcSetCreatureFocus(cid)
    Npc* npc = getScriptEnv()->getNpc();
    if (npc) {
        npc->setCreatureFocus(getCreature(L, -1));
    }
    return 0;
}
Beispiel #11
0
void GamePan::addNpc(DB_Actor* pActor)
{
	CCNode* pBaseNode = m_pCcbNode->getChildByTag(kTagGamePanOpp)->getChildByTag(0);
	pBaseNode->removeAllChildren();
	Npc* npc = Npc::create();
	npc->loadCCB(pBaseNode,("scene/actor/"+pActor->resource).c_str());
	pBaseNode->addChild(npc);
	npc->doOpen();
	npc->setPosition(CCPointZero-(npc->getContentSize()/2));
}
Beispiel #12
0
int32_t NpcScriptInterface::luaGetNpcName(lua_State* L)
{
	//getNpcName()
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		LuaScriptInterface::pushString(L, npc->getName());
	} else {
		pushBoolean(L, false);
	}
	return 1;
}
Beispiel #13
0
int NpcScriptInterface::luaGetNpcCid(lua_State* L)
{
    //getNpcCid()
    Npc* npc = getScriptEnv()->getNpc();
    if (npc) {
        lua_pushnumber(L, npc->getID());
    } else {
        lua_pushnil(L);
    }
    return 1;
}
Beispiel #14
0
int32_t NpcScriptInterface::luaSelfGetPos(lua_State* L)
{
	//selfGetPosition()
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		pushPosition(L, npc->getPosition(), 0);
	} else {
		lua_pushnil(L);
	}
	return 1;
}
Beispiel #15
0
int NpcScriptInterface::luaIsNpcIdle(lua_State *L)
{
	// isNpcIdle()
	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		lua_pushboolean(L, npc->isIdle());
	}

	return 1;
}
Beispiel #16
0
int NpcScriptInterface::luaUpdateNpcIdle(lua_State *L)
{
	// updateNpcIdle()
	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		npc->updateIdle();
	}

	return 1;
}
Beispiel #17
0
int32_t NpcScriptInterface::luaActionMove(lua_State* L)
{
	//selfMove(direction)
	Direction dir = (Direction)popNumber(L);

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->doMove(dir);
	}

	return 0;
}
Beispiel #18
0
int NpcScriptInterface::luaActionFollow(lua_State* L)
{
    //selfFollow(player)
    Npc* npc = getScriptEnv()->getNpc();
    if (!npc) {
        pushBoolean(L, false);
        return 1;
    }

    pushBoolean(L, npc->setFollowCreature(getPlayer(L, 1)));
    return 1;
}
Beispiel #19
0
int NpcScriptInterface::luaNpcSetFocus(lua_State* L)
{
    // npc:setFocus(creature)
    Creature* creature = getCreature(L, 2);
    Npc* npc = getUserdata<Npc>(L, 1);
    if (npc) {
        npc->setCreatureFocus(creature);
        pushBoolean(L, true);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
Beispiel #20
0
int NpcScriptInterface::luaSetNpcFocus(lua_State *L)
{
	//doNpcSetCreatureFocus(cid)
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if(npc){
		Creature* creature = env->getCreatureByUID(cid);
		npc->setCreatureFocus(creature);
	}
	return 0;
}
Beispiel #21
0
int32_t NpcScriptInterface::luaSetNpcFocus(lua_State* L)
{
	//doNpcSetCreatureFocus(cid)
	uint32_t cid = popNumber(L);

	ScriptEnvironment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		npc->setCreatureFocus(g_game.getCreatureByID(cid));
	}

	return 0;
}
Beispiel #22
0
int32_t NpcScriptInterface::luaActionTurn(lua_State* L)
{
	//selfTurn(direction)
	Direction dir = (Direction)popNumber(L);

	ScriptEnvironment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		npc->doTurn(dir);
	}

	return 0;
}
Beispiel #23
0
int NpcScriptInterface::luaGetNpcName(lua_State* L)
{
	//getNpcName()
	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if(npc){
		lua_pushstring(L, npc->getName().c_str());
	}
	else{
		lua_pushstring(L, "");
	}

	return 1;
}
Beispiel #24
0
int32_t NpcScriptInterface::luaSelfGetPos(lua_State* L)
{
	//selfGetPosition()
	ScriptEnvironment* env = getScriptEnv();
	Npc* npc = env->getNpc();

	if (npc) {
		Position pos = npc->getPosition();
		pushPosition(L, pos);
	} else {
		lua_pushnil(L);
	}

	return 1;
}
Beispiel #25
0
int NpcScriptInterface::luaActionMoveTo(lua_State* L)
{
    //selfMoveTo(x,y,z)
    Npc* npc = getScriptEnv()->getNpc();
    if (!npc) {
        return 0;
    }

    npc->doMoveTo(Position(
                      getNumber<uint16_t>(L, 1),
                      getNumber<uint16_t>(L, 2),
                      getNumber<uint8_t>(L, 3)
                  ));
    return 0;
}
Beispiel #26
0
int32_t NpcScriptInterface::luaGetNpcPos(lua_State* L)
{
	//getNpcPos()
	Position pos;
	uint32_t stackpos = 0;

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		pos = npc->getPosition();
		stackpos = npc->getParent()->__getIndexOfThing(npc);
	}

	pushPosition(L, pos, stackpos);
	return 1;
}
Beispiel #27
0
int32_t NpcScriptInterface::luaActionMoveTo(lua_State* L)
{
	//selfMoveTo(x,y,z)
	Position target;
	target.z = (int32_t)popNumber(L);
	target.y = (int32_t)popNumber(L);
	target.x = (int32_t)popNumber(L);

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->doMoveTo(target);
	}

	return 0;
}
Beispiel #28
0
int NpcScriptInterface::luaFaceCreature(lua_State *L)
{
	// facePlayer(cid)
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		Creature* creature = env->getCreatureByUID(cid);
		if (creature) {
			g_game.internalCreatureTurn(npc, npc->getDir(creature));
		}
	}

	return 1;
}
Beispiel #29
0
/**
 * \copydoc MapEntity::is_npc_obstacle
 */
bool CustomEntity::is_npc_obstacle(Npc& npc) {

    const TraversableInfo& info = get_can_traverse_entity_info(npc.get_type());
    if (!info.is_empty()) {
        return !info.is_traversable(*this, npc);
    }
    return Detector::is_npc_obstacle(npc);
}
void Commands::placeNpc(Player* player, const std::string& cmd, const std::string& param)
{
	Npc* npc = Npc::createNpc(param);
	if (!npc) {
		return;
	}

	// Place the npc
	if (g_game.placeCreature(npc, player->getPosition())) {
		g_game.addMagicEffect(player->getPosition(), NM_ME_MAGIC_BLOOD);
		npc->setMasterPos(npc->getPosition());
	} else {
		delete npc;
		player->sendCancelMessage(RET_NOTENOUGHROOM);
		g_game.addMagicEffect(player->getPosition(), NM_ME_POFF);
	}
}