Forum o ots

Załorzyciel Mateusz Kornet (KiKi)

Forum Forum o ots Strona Główna -> CVS, Kody -> Najazdy potworów w wersji XML
Napisz nowy temat  Odpowiedz do tematu Zobacz poprzedni temat :: Zobacz następny temat 
Najazdy potworów w wersji XML
PostWysłany: Sob 21:55, 18 Mar 2006
KiKi
Administrator

 
Dołączył: 18 Mar 2006
Posty: 70
Przeczytał: 0 tematów

Ostrzeżeń: 0/3
Skąd: Bydgoszcz





W pliku game.cpp przy końcu pliku dodaj:
Kod:
bool Game::loadRaid(std::string name)
{
xmlDocPtr doc;
std::cout << "Executing raid named " << name << "." << std::endl;
std::string file = "data/world/raids.xml";
doc = xmlParseFile(file.c_str());
if(doc){
xmlNodePtr root, raid, command;
root = xmlDocGetRootElement(doc);
if(xmlStrcmp(root->name, (const xmlChar*)"raids")) {
xmlFreeDoc(doc);
return -1;
}
raid = root->children;
while(raid){
if(strcmp((char*) raid->name, "raid")==0){

std::string nameIN = (const char*)xmlGetProp(raid, (const xmlChar *) "name");
if(nameIN == name) {
std::string messageIN = (const char*)xmlGetProp(raid, (const xmlChar *) "message");
std::string brodcasterIN = (const char*)xmlGetProp(raid, (const xmlChar *) "brodcaster");

Creature *c = getCreatureByName(brodcasterIN);
if(c) {
creatureBroadcastMessage(c,messageIN);
} else {
std::cout << "Could not send news msg! Brodcaster does not exist" << std::endl;
}

if(nameIN == name) {
command = raid->children;

while(command) {

if(strcmp((char*) command->name, "monster")==0){
std::string monstername = (const char*)xmlGetProp(command, (const xmlChar *) "name");
int x = atoi((const char*)xmlGetProp(command, (const xmlChar *) "x"));
int y = atoi((const char*)xmlGetProp(command, (const xmlChar *) "y"));
int z = atoi((const char*)xmlGetProp(command, (const xmlChar *) "z"));

int loot = atoi((const char*)xmlGetProp(command, (const xmlChar *) "lootid")); //Not yet implemented!
int chance = atoi((const char*)xmlGetProp(command, (const xmlChar *) "chance")); //Not yet implemented!
placeRaidMonster(monstername, x, y, z);
}

if(strcmp((char*) command->name, "area")==0){
std::string monstername = (const char*)xmlGetProp(command, (const xmlChar *) "monster");
int count = atoi((const char*)xmlGetProp(command, (const xmlChar *) "count"));
int xf = atoi((const char*)xmlGetProp(command, (const xmlChar *) "posxfrom"));
int yf = atoi((const char*)xmlGetProp(command, (const xmlChar *) "posyfrom"));
int zf = atoi((const char*)xmlGetProp(command, (const xmlChar *) "poszfrom"));

int xt = atoi((const char*)xmlGetProp(command, (const xmlChar *) "posxto"));
int yt = atoi((const char*)xmlGetProp(command, (const xmlChar *) "posyto"));
int zt = atoi((const char*)xmlGetProp(command, (const xmlChar *) "poszto"));

int i = 0;
int tries = 0;
while (i<=count && tries<=(count*10)) {
int x = (int)((xt-xf) * (rand()/(RAND_MAX+1.0)) + xf);
int y = (int)((yt-yf) * (rand()/(RAND_MAX+1.0)) + yf);
int z = (int)((zt-zf) * (rand()/(RAND_MAX+1.0)) + zf);
Tile* t = map->getTile(x,y,z);
if(t && t->isPz() == false) {
placeRaidMonster(monstername, x, y, z);
i++;
}
tries++;
}
}
if(strcmp((char*) command->name, "message")==0){
std::string msg = (const char*)xmlGetProp(command, (const xmlChar *) "text");
std::string brodcaster = (const char*)xmlGetProp(command, (const xmlChar *) "brodcaster");
Creature *c = getCreatureByName(brodcaster);
if(c) {
creatureBroadcastMessage(c,msg);
} else {
std::cout << "Could not send news msg! Brodcaster does not exist." << std::endl;
}
}
command = command->next;
}
}
}
}
raid = raid->next;
}
xmlFreeDoc(doc);
return 0;
}
return -1;
}

i pod powyższym kodem dodaj jeszcze to:
Kod:
bool Game::placeRaidMonster(std::string name, int x, int y, int z)
{
Monster* monster = new Monster(name, this);
//For new CVS use the following line:
//Monster* monster = Monster::createMonster(name, this);
if(!monster->isLoaded()){
delete monster;
return false;
}
Position pos;
pos.x = x;
pos.y = y;
pos.z = z;

// Place the monster
if(!placeCreature(pos, monster)) {
delete monster;
return false;
}

return true;
}

W pliku game.h pod linijką:
Kod:
public:

dodaj:
Kod:
bool loadRaid(std::string name);
bool placeRaidMonster(std::string name, int x, int y, int z);

Teraz w pliku : commands.cpp znajdź linijkę:
Kod:
{"/kick",&Commands::kickPlayer},

Teraz pod powyższą linijką dodaj:
Kod:
{"/raid",&Commands::doRaid},

Teraz na samym końcu tego samego pliku dodaj:
Kod:
bool Commands::doRaid(Creature* c, const std::string &cmd, const std::string &param){
game->loadRaid(param);
return true;
}

Teraz w pliku commands.h pod linijką:
Kod:
bool kickPlayer(Creature* c, const std::string &cmd, const std::string &param);

dodaj:
Kod:
bool doRaid(Creature* c, const std::string &cmd, const std::string &param);

Teraz idź do .../data/word/ i stwórz nowy plik : raids.xml i wpisz w nim :
Kod:
<?xml version="1.0" ?> <raids> <raid name="undead" message="Heavy undead activity in the city! We need backup!" brodcaster="The King"> <area monster="Skeleton" count="30" posxfrom="160" posyfrom="2146" poszfrom="7" posxto="232" posyto="2197" poszto="7" /> <area monster="Ghoul" count="20" posxfrom="160" posyfrom="2146" poszfrom="7" posxto="232" posyto="2197" poszto="7" /> <area monster="Mummy" count="10" posxfrom="160" posyfrom="2146" poszfrom="7" posxto="232" posyto="2197" poszto="7" /> <area monster="Necromancer" count="3" posxfrom="160" posyfrom="2146" poszfrom="7" posxto="232" posyto="2197" poszto="7" /> <area monster="Beholder" count="7" posxfrom="160" posyfrom="2146" poszfrom="7" posxto="232" posyto="2197" poszto="7" /> <area monster="Vampire" count="3" posxfrom="160" posyfrom="2146" poszfrom="7" posxto="232" posyto="2197" poszto="7" /> <area monster="Demon Skeleton" count="8" posxfrom="160" posyfrom="2146" poszfrom="7" posxto="232" posyto="2197" poszto="7" /> <monster name="Elder beholder" x="199" y="2155" z="7" /> </raid> </raids>

Współrzędne + nazwa ataku + nazwa wywoływacza ataku trzeba zmienić !


Post został pochwalony 0 razy
Zobacz profil autora
Najazdy potworów w wersji XML
Forum Forum o ots Strona Główna -> CVS, Kody
Możesz pisać nowe tematy
Możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Wszystkie czasy w strefie EET (Europa)  
Strona 1 z 1  

  
  
 Napisz nowy temat  Odpowiedz do tematu  


fora.pl - załóż własne forum dyskusyjne za darmo
Powered by phpBB © 2001-2003 phpBB Group
Theme created by Vjacheslav Trushkin
Regulamin