Ir para conteúdo

[7.92]teleport Library Xml


Posts Recomendados

Olá Xtibia,

 

Primeiramente, os créditos são inteiramente de:

Raphael Carnaúba

 

São 3 comandos:

 

!place depot -- adiciona depot a lista

/dest list -- mostra a lista de teleportes

/dest name -- vai pra o determinado local na lista

!delplace depot -- deleta o depot da lista.

 

----------------------------

commands.cpp

 

Abaixo de:

 

 

{"/raid",&Commands::forceRaid},

 

 

Adicione:

 

{"/dest",&Commands::goToDest},
{"!place", &Commands::placeDest},
{"!delplace", &Commands::deleteDest},

 

 

No final de commands.cpp adicione:

 

 

bool Commands::goToDest(Creature* creature, const std::string& cmd, const std::string& param)
{
 Player* player = creature->getPlayer();
 if(!player)
	return false;

 Position destPos = Position(0,0,0);
 std::string param2 = param;
 std::transform(destination.begin(), destination.end(), destination.begin(), tolower);

 if(param2 != "list")
 {
	 for( DestinationList::iterator it = g_game.destinationList.begin(); it != g_game.destinationList.end(); it++ )
	 {
		 if( (*it).name == param2 )
		 {
			 destPos = (*it).pos;
		 }
	 }	
	 ReturnValue ret = g_game.internalTeleport(player, destPos);
	 if( ret != RET_NOERROR )
	 {
		 player->sendTextMessage( MSG_STATUS_CONSOLE_BLUE , "Invalid destination.");
		 return false;
	 }
 }
 else
 {
	 std::stringstream ss;
	 uint32_t id = 1;
	 ss << " Destinations : \n";
	 for( DestinationList::iterator it = g_game.destinationList.begin(); it != g_game.destinationList.end(); it++)
	 {
		  ss << id << "- " << (*it).name << "\n Pos: " << (*it).pos << "\n";
		  id++;
	 }
	 player->sendTextWindow(1949, ss.str().c_str());
	 return true;
 }
 return false;
}
bool Commands::placeDest(Creature* creature, const std::string& cmd, const std::string& param)
{
 Player* player = creature->getPlayer();
 if(!player)
	return false;
 std::string place = param;
 Position pos = creature->getPosition();

 if(place.length() > 0)
 {
	 for(DestinationList::iterator it = g_game.destinationList.begin(); it != g_game.destinationList.end(); it++)
	 {
		 if((*it).name == place)
		 {
			player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "This place name already exists.");
			return false;
		 }
		 if((*it).pos == pos)
		 {
			player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "This place name already exists.");
			return false;
		 }
	 }
	 std::transform(place.begin(), place.end(), place.begin(), tolower);
	 DestinationStruct dests;
	 dests.name = place;
	 dests.pos = pos;
	 g_game.destinationList.push_back(dests);
	 player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Added succesfully.");

 }
 else{
	 player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Please enter with a destination to be placed.");
	 return false;
 }
 return true;
}
bool Commands::deleteDest(Creature* creature, const std::string& cmd, const std::string& param)
{
 Player* player = creature->getPlayer();
 if(!player)
	return false;

 std::string place = param;
 if(place.length() > 0)
 {
	for(DestinationList::iterator it = g_game.destinationList.begin(); it != g_game.destinationList.end(); it++)
	{
	   if((*it).name == place)
	   {
		  g_game.destinationList.erase(it);
		  std::string msg = "Destination ";
		  msg += place;
		  msg += " deleted.";
		  player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, msg.c_str());
		  return true;
	   }
	}
	player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Destination not found.");
	return false;
 }
  return false;
}

 

 

commands.h abaixo de:

 

 

bool forceRaid(Creature* creature, const std::string& cmd, const std::string& param);

 

 

Adicione:

 

 

bool goToDest(Creature* creature, const std::string& cmd, const std::string& param);
bool placeDest(Creature* creature, const std::string& cmd, const std::string& param);
bool deleteDest(Creature* creature, const std::string& cmd, const std::string& param);

 

 

 

Agora em game.cpp

 

 

Se você usa The Forgotten Server procure por:

 

void Game::SaveData(bool kickPlayers)

 

abaixo de:

 

 

  map->saveMap("");

 

 

adicione:

 

saveDests();

 

 

Se você usa evolutions

Procure por:

 

void Game::saveServer()

 

 

abaixo de:

 

 

if(!map->saveMap("")){
 message += "\nfailed to save map";
}

 

 

adicione:

 

saveDests();

 

 

 

No final adicione:

 

bool Game::loadDests()
{
std::string filename = "data/destinations.xml";
xmlDocPtr doc = xmlParseFile(filename.c_str());
if(doc)
{
 xmlNodePtr root, p;
 root = xmlDocGetRootElement(doc);
 if(xmlStrcmp(root->name,(const xmlChar*)"dests") != 0)
 {
		std::cout << "Malformuled destinations.xml" << std::endl;
		return false;
	}
  int32_t intValue;
  std::string strValue;

  p = root->children;
  while(p)
  {
if(xmlStrcmp(p->name, (const xmlChar*)"dest") == 0)
{
 std::string name;
 Position pos;
 if(readXMLString(p, "name", strValue))
				{
  name = strValue;
				}
 if(readXMLInteger(p, "x", intValue))
 {
  pos.x = intValue;
				}
 if(readXMLInteger(p, "y", intValue))
 {
  pos.y = intValue;
				}
 if(readXMLInteger(p, "z", intValue))
 {
  pos.z = intValue;
				}

				DestinationStruct dests;
	dests.name = name;
	dests.pos = pos;
	destinationList.push_back(dests);
			}
		   p = p->next;
		}
		xmlFreeDoc(doc);
		return true;
	 }
   return false;
}
bool Game::saveDests()
{
 std::string filename = "data/destinations.xml";
 xmlDocPtr doc = xmlNewDoc((xmlChar*) "1.0");
 xmlNodePtr node = xmlNewNode(NULL, (xmlChar*)"dests");
 xmlDocSetRootElement(doc, node);

 for(DestinationList::iterator it = destinationList.begin(); it != destinationList.end(); it++)
 {
	 xmlNodePtr p = xmlNewChild(node, NULL, (xmlChar*) "dest", NULL);

	 std::stringstream ss;
	 ss << (*it).name;
	 xmlNewProp(p, (xmlChar*)"name", (xmlChar*)ss.str().c_str());
	 ss.str("");

	 ss << (*it).pos.x;
	 xmlNewProp(p, (xmlChar*)"x", (xmlChar*) ss.str().c_str());
	 ss.str("");

	 ss << (*it).pos.y;
	 xmlNewProp(p, (xmlChar*)"y", (xmlChar*) ss.str().c_str());
	 ss.str("");

	 ss << (*it).pos.z;
	 xmlNewProp(p, (xmlChar*)"z", (xmlChar*) ss.str().c_str());
	 ss.str("");

	 xmlAddChild(node, p);
 }
 if( xmlSaveFile( filename.c_str() , doc ) != 0 )
	std::cout << "Saved a new place succesfully!" << std::endl;
 else
	 std::cout << "Failed to save a new place!" << std::endl;

 xmlFreeDoc(doc);

 return true;
}

 

 

game.h

 

abaixo de:

 

 

enum LightState_t {
LIGHT_STATE_DAY,
LIGHT_STATE_NIGHT,
LIGHT_STATE_SUNSET,
LIGHT_STATE_SUNRISE,
};

 

 

 

Adicione:

 

 

 

struct DestinationStruct
{
std::string name;
Position pos;
};

typedef std::list<DestinationStruct> DestinationList;

 

 

Agora em public abaixo de:

 

 

~Game();

 

 

Adicione:

 

 

DestinationList destinationList;
bool loadDests();
bool saveDests();

 

 

 

otserv.cpp

 

acima de:

 

std::cout << "[done]" << std::endl;
std::string worldType = g_config.getString(ConfigManager::WORLD_TYPE);
std::transform(worldType.begin(), worldType.end(), worldType.begin(), upchar);

 

 

Adicione:

 

	filename.str("");
filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "destinations.xml";
std::cout << ":: Loading destinations.xml... ";
if(!g_game.loadDests()){
 std::stringstream errormsg;
 errormsg << "Unable to load " << filename.str() << "!";
 ErrorMessage(errormsg.str().c_str());
 return -1;
}

 

 

Usem e abusem.

 

 

Atenciosamente, JV

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...