当前位置: 首页>>代码示例>>C++>>正文


C++ Npc类代码示例

本文整理汇总了C++中Npc的典型用法代码示例。如果您正苦于以下问题:C++ Npc类的具体用法?C++ Npc怎么用?C++ Npc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Npc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: placeNpc

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;
}
开发者ID:edubart,项目名称:otserv,代码行数:31,代码来源:talkaction.cpp

示例2: getScriptEnv

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;
}
开发者ID:marksamman,项目名称:forgottenserver,代码行数:31,代码来源:npc.cpp

示例3: popNumber

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;
}
开发者ID:cp1337,项目名称:devland,代码行数:27,代码来源:npc.cpp

示例4: lua_gettop

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;
}
开发者ID:cp1337,项目名称:devland,代码行数:30,代码来源:npc.cpp

示例5: lua_gettop

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;
}
开发者ID:Jonas21,项目名称:forgottenserver,代码行数:33,代码来源:npc.cpp

示例6: Npc

Npc* Npc::createNpc(const std::string& name)
{
	Npc* npc = new Npc(name);
	if (!npc->load()) {
		delete npc;
		return nullptr;
	}
	return npc;
}
开发者ID:Jonas21,项目名称:forgottenserver,代码行数:9,代码来源:npc.cpp

示例7: getScriptEnv

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;
}
开发者ID:NoyiGao,项目名称:forgottenserver,代码行数:9,代码来源:npc.cpp

示例8: getScriptEnv

int32_t NpcScriptInterface::luaSetNpcFocus(lua_State* L)
{
	//doNpcSetCreatureFocus(cid)
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->setCreatureFocus(g_game.getCreatureByID(popNumber(L)));
	}
	return 0;
}
开发者ID:Jonas21,项目名称:forgottenserver,代码行数:9,代码来源:npc.cpp

示例9: addNpc

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));
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例10: getScriptEnv

int NpcScriptInterface::luaIsNpcIdle(lua_State *L)
{
	// isNpcIdle()
	ScriptEnviroment* env = getScriptEnv();

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

	return 1;
}
开发者ID:Codex-NG,项目名称:avesta74,代码行数:12,代码来源:npc.cpp

示例11: getCreature

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;
}
开发者ID:marksamman,项目名称:forgottenserver,代码行数:13,代码来源:npc.cpp

示例12: popNumber

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;
}
开发者ID:fabianobn,项目名称:forgottenserver,代码行数:14,代码来源:npc.cpp

示例13: getScriptEnv

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;
}
开发者ID:fabianobn,项目名称:forgottenserver,代码行数:14,代码来源:npc.cpp

示例14: getScriptEnv

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;
}
开发者ID:cp1337,项目名称:devland,代码行数:15,代码来源:npc.cpp

示例15: popNumber

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;
}
开发者ID:Codex-NG,项目名称:avesta74,代码行数:17,代码来源:npc.cpp


注:本文中的Npc类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。