bool Spawns::loadFromXml(const std::string& _filename) { if (isLoaded()) { return true; } filename = _filename; xmlDocPtr doc = xmlParseFile(filename.c_str()); if (doc) { xmlNodePtr root, spawnNode; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"spawns") != 0) { xmlFreeDoc(doc); return false; } int32_t intValue; std::string strValue; spawnNode = root->children; while (spawnNode) { if (xmlStrcmp(spawnNode->name, (const xmlChar*)"spawn") == 0) { Position centerPos; int32_t radius = -1; if (readXMLInteger(spawnNode, "centerx", intValue)) { centerPos.x = intValue; } else { xmlFreeDoc(doc); return false; } if (readXMLInteger(spawnNode, "centery", intValue)) { centerPos.y = intValue; } else { xmlFreeDoc(doc); return false; } if (readXMLInteger(spawnNode, "centerz", intValue)) { centerPos.z = intValue; } else { xmlFreeDoc(doc); return false; } if (readXMLInteger(spawnNode, "radius", intValue)) { radius = intValue; } else { xmlFreeDoc(doc); return false; } Spawn* spawn = new Spawn(centerPos, radius); spawnList.push_back(spawn); xmlNodePtr tmpNode = spawnNode->children; while (tmpNode) { if (xmlStrcmp(tmpNode->name, (const xmlChar*)"monster") == 0) { std::string name = ""; Position pos = centerPos; Direction dir = NORTH; uint32_t interval = 0; if (readXMLString(tmpNode, "name", strValue)) { name = strValue; } else { tmpNode = tmpNode->next; continue; } if (readXMLInteger(tmpNode, "direction", intValue)) { switch (intValue) { case 0: dir = NORTH; break; case 1: dir = EAST; break; case 2: dir = SOUTH; break; case 3: dir = WEST; break; } } if (readXMLInteger(tmpNode, "x", intValue)) { pos.x += intValue; } else { tmpNode = tmpNode->next; continue; } if (readXMLInteger(tmpNode, "y", intValue)) { pos.y += intValue; } else { tmpNode = tmpNode->next; continue; } if (readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue)) { interval = intValue * 1000; } else { tmpNode = tmpNode->next; continue; } if (interval > MINSPAWN_INTERVAL) { spawn->addMonster(name, pos, dir, interval); } else { std::cout << "[Warning] Spawns::loadFromXml " << name << " " << pos << " spawntime can not be less than " << MINSPAWN_INTERVAL / 1000 << " seconds." << std::endl; } } else if (xmlStrcmp(tmpNode->name, (const xmlChar*)"npc") == 0) { Direction direction = NORTH; std::string name = ""; Position placePos = centerPos; if (readXMLString(tmpNode, "name", strValue)) { name = strValue; } else { tmpNode = tmpNode->next; continue; } if (readXMLInteger(tmpNode, "direction", intValue)) { switch (intValue) { case 0: direction = NORTH; break; case 1: direction = EAST; break; case 2: direction = SOUTH; break; case 3: direction = WEST; break; } } if (readXMLInteger(tmpNode, "x", intValue)) { placePos.x += intValue; } else { tmpNode = tmpNode->next; continue; } if (readXMLInteger(tmpNode, "y", intValue)) { placePos.y += intValue; } else { tmpNode = tmpNode->next; continue; } Npc* npc = Npc::createNpc(name); if (!npc) { tmpNode = tmpNode->next; continue; } npc->setDirection(direction); npc->setMasterPos(placePos, radius); npcList.push_back(npc); } tmpNode = tmpNode->next; } } spawnNode = spawnNode->next; } xmlFreeDoc(doc); loaded = true; return true; } return false; }
void SpawnShell::updateSpawn(uint16_t id, int16_t x, int16_t y, int16_t z, int16_t xVel, int16_t yVel, int16_t zVel, int8_t heading, int8_t deltaHeading, uint8_t animation) { #ifdef SPAWNSHELL_DIAG printf("SpawnShell::updateSpawn(id=%d, x=%d, y=%d, z=%d, xVel=%d, yVel=%d, zVel=%d)\n", id, x, y, z, xVel, yVel, zVel); #endif Item* item = m_spawns.find(id); if (item != NULL) { Spawn* spawn = (Spawn*)item; spawn->setPos(x, y, z, showeq_params->walkpathrecord, showeq_params->walkpathlength); spawn->setAnimation(animation); if ((animation != 0) && (animation != 66)) { spawn->setDeltas(xVel, yVel, zVel); spawn->setHeading(heading, deltaHeading); } else { spawn->setDeltas(0, 0, 0); spawn->setHeading(heading, 0); } spawn->updateLast(); item->updateLastChanged(); emit changeItem(item, tSpawnChangedPosition); } else if (showeq_params->createUnknownSpawns) { // not the player, so check if it's a recently deleted spawn for (int i =0; i < m_cntDeadSpawnIDs; i++) { // check dead spawn list for spawnID, if it was deleted, shouldn't // see new position updates, so therefore this is probably // for a new spawn (spawn ID being reused) if ((m_deadSpawnID[i] != 0) && (m_deadSpawnID[i] == id)) { // found a match, ignore it m_deadSpawnID[i] = 0; printf("\a(%d) had been removed from the zone, but saw a position update on it, so assuming bogus update.\n", id); return; } } item = new Spawn(id, x, y, z, xVel, yVel, zVel, heading, deltaHeading, animation); updateFilterFlags(item); updateRuntimeFilterFlags(item); m_spawns.insert(id, item); emit addItem(item); // send notification of new spawn count emit numSpawns(m_spawns.count()); } }
void SpawnShell::consMessage(const considerStruct * con, uint32_t, uint8_t dir) { Item* item; Spawn* spawn; if (dir == DIR_CLIENT) { if (con->playerid != con->targetid) { item = m_spawns.find(con->targetid); if (item != NULL) { spawn = (Spawn*)item; // note that this spawn has been considered spawn->setConsidered(true); emit spawnConsidered(item); } } return; } QString lvl(""); QString hps(""); QString cn(""); QString msg("Faction: Your faction standing with "); //printf("%i, %i, %i, %i\n", con->unknown1[0], con->unknown1[1], con->unknown2[0], con->unknown2[1]); // is it you that you've conned? if (con->playerid == con->targetid) { // print it's deity printf("Diety: %s\n", (const char*)m_player->deityName()); // well, this is You msg += "YOU"; } else { // find the spawn if it exists item = m_spawns.find(con->targetid); // has the spawn been seen before? if (item != NULL) { Spawn* spawn = (Spawn*)item; // yes printf("Diety: %s\n", (const char*)spawn->deityName()); int changed = tSpawnChangedNone; /* maxhp and curhp are available when considering players, */ /* but not when considering mobs. */ if (con->maxHp || con->curHp) { if (spawn->NPC() == SPAWN_NPC_UNKNOWN) { spawn->setNPC(SPAWN_PLAYER); // player changed |= tSpawnChangedNPC; } spawn->setMaxHP(con->maxHp); spawn->setHP(con->curHp); changed |= tSpawnChangedHP; } else if (item->NPC() == SPAWN_NPC_UNKNOWN) { spawn->setNPC(SPAWN_NPC); changed |= tSpawnChangedNPC; } // note the updates if any if (changed != tSpawnChangedNone) { if (updateFilterFlags(item)) changed |= tSpawnChangedFilter; if (updateRuntimeFilterFlags(item)) changed |= tSpawnChangedRuntimeFilter; item->updateLastChanged(); emit changeItem(item, changed); } // note that this spawn has been considered spawn->setConsidered(true); emit spawnConsidered(item); msg += item->name(); } // end if spawn found else msg += "Spawn:" + QString::number(con->targetid, 16); } // else not yourself switch (con->level) { case 0: { cn.sprintf(" (even)"); break; } case 2: { cn.sprintf(" (green)"); break; } case 4: { cn.sprintf(" (blue)"); break; } case 13: { cn.sprintf(" (red)"); break; } case 15: { cn.sprintf(" (yellow)"); break; } case 18: { cn.sprintf(" (cyan)"); break; } default: { cn.sprintf(" (unknown: %d)", con->level); break; } } msg += cn; if (con->maxHp || con->curHp) { lvl.sprintf(" (%i/%i HP)", con->curHp, con->maxHp); msg += lvl; } msg += QString(" is: ") + print_faction(con->faction) + " (" + QString::number(con->faction) + ")!"; emit msgReceived(msg); } // end consMessage()
Spawn::Spawn(Spawn& s, uint16_t id) : Item(tSpawn, id) { setName(s.name()); setLastName(s.lastName()); Item::setPoint(s.x(), s.y(), s.z()); setPetOwnerID(s.petOwnerID()); setLight(s.light()); setGender(s.gender()); setDeity(s.deity()); setRace(s.race()); setClassVal(s.classVal()); setHP(s.HP()); setMaxHP(s.maxHP()); setGuildID(s.GuildID()); setLevel(s.level()); for (int i = 0; i <= tLastCoreWearSlot; i++) setEquipment(i, s.equipment(i)); setEquipment(tUnknown1, 0); setTypeflag(s.typeflag()); setNPC(s.NPC()); setAnimation(s.animation()); setDeltas(s.deltaX(), s.deltaY(), s.deltaZ()); setHeading(s.heading(), s.deltaHeading()); setConsidered(s.considered()); // the new copy will own the spawn track list m_spawnTrackList.setAutoDelete(false); m_spawnTrackList = s.m_spawnTrackList; s.m_spawnTrackList.setAutoDelete(false); m_spawnTrackList.setAutoDelete(true); }
void MessageShell::consMessage(const uint8_t* data, size_t, uint8_t dir) { const considerStruct * con = (const considerStruct*)data; const Item* item; QString lvl(""); QString hps(""); QString cn(""); QString deity; QString msg("Your faction standing with "); // is it you that you've conned? if (con->playerid == con->targetid) { deity = m_player->deityName(); // well, this is You msg += m_player->name(); } else { // find the spawn if it exists item = m_spawnShell->findID(tSpawn, con->targetid); // has the spawn been seen before? if (item != NULL) { Spawn* spawn = (Spawn*)item; // yes deity = spawn->deityName(); msg += item->name(); } // end if spawn found else msg += "Spawn:" + QString::number(con->targetid, 16); } // else not yourself switch (con->level) { case 0: case 20: msg += " (even)"; break; case 2: msg += " (green)"; break; case 4: msg += " (blue)"; break; case 13: msg += " (red)"; break; case 15: msg += " (yellow)"; break; case 18: msg += " (cyan)"; break; default: msg += " (unknown: " + QString::number(con->level) + ")"; break; } if (!deity.isEmpty()) msg += QString(" [") + deity + "]"; if (con->maxHp || con->curHp) { lvl.sprintf(" (%i/%i HP)", con->curHp, con->maxHp); msg += lvl; } msg += QString(" is: ") + print_faction(con->faction) + " (" + QString::number(con->faction) + ")!"; m_messages->addMessage(MT_Consider, msg); } // end consMessage()
int main (int argc, char *argv[]) { FILE *sdb; struct dbSpawnStruct dbSpawn; int count=0; // CGI Convenience class CGI cgiconv; // search variables QString searchName = ""; QString searchZone = ""; int searchLevel = 0; QString searchRace = ""; int searchClass = 0; // are we performing a serch (default = false) bool doSearch = false; // process any CGI data cgiconv.processCGIData(); // If there are form parameters use them for searching if (cgiconv.getParamCount() != 0) { searchName = cgiconv.getParamValue("name"); searchZone = cgiconv.getParamValue("zone"); searchLevel = cgiconv.getParamValue("level").toInt(); searchRace = cgiconv.getParamValue("race"); searchClass = cgiconv.getParamValue("class").toInt(); if (!searchName.isEmpty() || !searchZone.isEmpty() || !searchRace.isEmpty() || (searchLevel != 0) || (searchClass != 0)) doSearch = true; } else if (argc == 2) { // use the argument for the name search searchName = argv[1]; // note that a search is being done. doSearch = true; } // open the output data stream QTextStream out(stdout, IO_WriteOnly); out.setEncoding(QTextStream::Latin1); out.flags(QTextStream::showbase | QTextStream::dec); const char* header = "Content-type: text/html; charset=iso-8859-1\n\n" "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" "<HTML>\n" " <HEAD>\n" " <TITLE>ShowEQ Spawn List</TITLE>\n" " <style type=\"text/css\">\n" " <!--\n" " table { border: black 2px solid }\n" " td { border: black 1px solid }\n" " th { border: black 1px solid }\n" " -->\n" " </style>\n" " </HEAD>\n" " <BODY>\n"; /* Print HTML header */ out << header; const char* footer = " </BODY>\n" "</HTML>\n"; // check for browser type QString userAgent = cgiconv.getHTTPUserAgent(); out << " <!-- Output for UserAgent: " << userAgent << "-->\n"; out << "<FORM method=\"POST\" action=\"" << cgiconv.getScriptName() << "\">\n"; // beware Netscape 4.x style sheet brain death if ((userAgent.contains("Mozilla/4.") == 1) && (userAgent.contains("MSIE") == 0)) out << "<TABLE border=2 cellspacing=0 cellpadding=2>\n"; else out << "<TABLE cellspacing=0 cellpadding=2>\n"; out << "<TR>" "<TH>Name</TH><TH>Zone</TH><TH>Level</TH><TH>Race</TH><TH>Class</TH>\n" "<TD><INPUT type=\"reset\" value=\"Reset\"/></TD>\n" "</TR>\n"; out << "<TR>"; // name field out << "<TD><INPUT type=\"text\" name=\"name\" value=\"" << searchName << "\"/></TD>\n"; // zone field out << "<TD><INPUT type=\"text\" name=\"zone\" value=\"" << searchZone << "\"/></TD>\n"; // level field out << "<TD><INPUT type=\"text\" name=\"level\" size=\"2\" maxlength=\"2\"" " value=\""; if (searchLevel) out << searchLevel; out << "\"/></TD>\n"; // race field out << "<TD><INPUT type=\"text\" name=\"race\" value=\"" << searchRace << "\"/></TD>\n"; // Class field out << "<TD><SELECT name=\"class\" size=\"1\">\n"; out << "<OPTION value=\"0\""; if (searchClass == 0) cout << " selected"; out << ">Any</OPTION>\n"; // create a fake spawn to get class names Spawn fakeSpawn; // start at class value 1, and go until maximum known class value for (int i = 1; i <= 32; ++i) { // set the fake spawns class fakeSpawn.setClassVal(i); out << "<OPTION value=\"" << i << "\""; if (searchClass == i) cout << " selected"; // output the name corresponding to the class value out << ">" << fakeSpawn.className() << "</OPTION>\n"; } out << "</SELECT></TD>\n"; // Submission button out << "<TD><INPUT type=\"submit\" value=\"Search\"/></TD>\n"; // close the form out << "</TR>\n" "</TABLE>\n" "</FORM>\n"; sdb = fopen (SPAWNFILE, "r"); if (sdb == NULL) { // display the error out << "<H1>Unable to open file '" SPAWNFILE "' (errno = " << errno << ")</H1>\n"; // close the document out << footer; // nothing more can be done exit(1); } QString spawnName; QRegExp stripExp("[0-9]"); while (fread (&dbSpawn, sizeof(dbSpawnStruct), 1, sdb)) { Spawn spawn(&dbSpawn.spawn); // stash the name for later use and cooking spawnName = spawn.name(); // is a search being performed, then do it already... if (doSearch) { // is it a name search, if so do we have a match if ((!searchName.isEmpty()) && (spawnName.find(searchName, 0, false) == -1)) continue; // nope, you are the weakest link, good bye... // is it a zone search, if so check if ((!searchZone.isEmpty()) && (QString(dbSpawn.zoneName).find(searchZone, 0, false) == -1)) continue; // is it a level search, if so check if ((searchLevel != 0) && (searchLevel != spawn.level())) continue; // is it a race search, if so check if ((!searchRace.isEmpty()) && (spawn.raceName().find(searchRace, 0, false) == -1)) continue; // is it a class search, if so check if ((searchClass != 0) && (searchClass != spawn.classVal())) continue; } // strip the numbers off the spawn name spawnName.replace(stripExp, ""); // display the data out << "<H1>" << spawn.realName() << "</H1>\n"; out << "<P>ShortName: " << spawn.transformedName() << "<BR>\n"; out << "Level: " << spawn.level() << "<BR>\n"; out << "HP: " << spawn.HP() << "/" << spawn.maxHP() << "<BR>\n"; out << "Race: " << spawn.raceName() << "<BR>\n"; out << "Class: " << spawn.className() << "<BR>\n"; out << "Found in Zone: " << dbSpawn.zoneName << "<BR>\n"; out << "Position: " << spawn.yPos() << ", " << spawn.xPos() << ", " << spawn.zPos() << "<BR>\n"; out << "Mob ID: " << spawn.id() << "<BR>\n"; out << "<B>Packet data:</B>\n"; out <<"<PRE>\n"; printdata (out, sizeof(spawnStruct), (unsigned char *)&dbSpawn.spawn); out <<"</PRE>\n"; out <<"<HR>\n"; // increment counter count++; } // clsoe the DB fclose (sdb); // display the number of records found out << "<P>Found " << count << " matches.</P>\n"; out << footer; }
void IOMapBin::loadOTM(Map* map) { int op; bool end = false; while(!feof(fh) || !end) { op = fgetc(fh); switch(op) { case 0x10: // Information of the map { char name[100], author[100]; int pos; int len; // Map Name len = fgetc(fh); for (pos = 0; pos < len; pos++) name[pos] = fgetc(fh); name[pos] = '\0'; std::cout << ":: Map Name: " << name << std::endl; // Map Author len = fgetc(fh); for (pos = 0; pos < len; pos++) author[pos] = fgetc(fh); author[pos] = '\0'; std::cout << ":: Map Author: " << author << std::endl; } break; case 0x20: // Map dimensions { int width, height; width = fgetc(fh); width += fgetc(fh)<<8; height = fgetc(fh); height += fgetc(fh)<<8; map->mapwidth = width; map->mapheight = height; std::cout << ":: Map dimensions: " << width << "x" << height << std::endl; } break; case 0x30: // Global Temple Position { PositionEx templePos; templePos.x = fgetc(fh); templePos.x += fgetc(fh); // X templePos.y = fgetc(fh); templePos.y += fgetc(fh); // Y templePos.z = fgetc(fh); // Z int radius = fgetc(fh); // Radius // TODO: use the temple point and radius std::cout << ":: Global Temple Position: " << templePos.x << " " << templePos.y << " " << templePos.z << " Radius: " << radius << std::endl; } break; case 0x40: // Tiles and items { Tile *t; int x, y, z, id, total = 0; while(true) { // tile pos x = fgetc(fh); x += fgetc(fh) << 8; y = fgetc(fh); y += fgetc(fh) << 8; z = fgetc(fh); // end the loop if (x == 0xFFFF && y == 0xFFFF && z == 0xFF) break; id = fgetc(fh) + 100; id += fgetc(fh) << 8; total += 1; map->setTile(x, y, z, id); t = map->getTile(x, y, z); // check if the tile is pz if (fgetc(fh) == 1) t->setPz(); int op2; int tmpid; do { op2 = fgetc(fh); switch (op2) { case 0x10: // Action Id fgetc(fh); // len tmpid = fgetc(fh); tmpid += fgetc(fh) << 8; // t->ground->setActionId(tmpid); break; case 0x20: // Unique Id fgetc(fh); // len tmpid = fgetc(fh); tmpid += fgetc(fh) << 8; //t ->ground->setUniqueId(tmpid); break; case 0x30: // Target Id fgetc(fh); // len tmpid = fgetc(fh); tmpid += fgetc(fh) << 8; // TODO: implement target ids break; case 0xA0: // Item { int itemcount = fgetc(fh); for (int count = 0; count < itemcount; count++) { int itemid = fgetc(fh) + 100; itemid += fgetc(fh) << 8; Item *item = Item::CreateItem(itemid); int op3; do { op3 = fgetc(fh); switch (op3) { case 0x10: // Count fgetc(fh); //len item->setItemCountOrSubtype((unsigned char)fgetc(fh)); break; case 0x20: // Action Id fgetc(fh); //len tmpid = fgetc(fh); tmpid += fgetc(fh) << 8; // item->setActionId(tmpid); break; case 0x30: // Unique Id fgetc(fh); //len tmpid = fgetc(fh); tmpid += fgetc(fh) << 8; // item->setUniqueId(tmpid); break; case 0x40: // Target Id fgetc(fh); //len tmpid = fgetc(fh); tmpid += fgetc(fh) << 8; // item->setTargetId(tmpid); break; case 0x70: //Teleport { Teleport *tele = dynamic_cast<Teleport*>(item); Position toPos; fgetc(fh); //len toPos.x = fgetc(fh); toPos.x += fgetc(fh)<<8; toPos.y = fgetc(fh); toPos.y += fgetc(fh)<<8; toPos.z = fgetc(fh); if (tele) tele->setDestPos(toPos); } break; case 0x80: // Fluids fgetc(fh); if (item->isFluidContainer()) item->setItemCountOrSubtype((unsigned char)fgetc(fh)); else fgetc(fh); break; case 0xFF: // End break; default: // Unknow/New operators { printf("WARNING: Unknown operator loading items: 0x%X!\n",op3); int len = fgetc(fh); for (int i = 0; i < len; i++) fgetc(fh); } break; } } while (op3 < 0xFF); //item->pos.x = x; //item->pos.y = y; //item->pos.z = z; if (item->isAlwaysOnTop()) t->topItems.push_back(item); else t->downItems.push_back(item); } } break; case 0xFF: // End break; default: // Unknow/New operators { printf("WARNING: Unknown operator loading tiles: 0x%X!\n",op2); int len = fgetc(fh); for (int i = 0;i < len; i++) fgetc(fh); } break; } } while (op2 < 0xFF); } std::cout << ":: Total of tiles loaded is " << total << std::endl; } break; case 0x50: // Spawns { SpawnManager::initialize(&g_game); Position pos; int cx, cy, radius, total=0; long int secs; std::string cname; int num = fgetc(fh); num+=fgetc(fh)<<8; for (int i = 0; i < num; i++) { int len = fgetc(fh); int count; cname = ""; for (int j = 0;j < len; j++) cname.push_back(fgetc(fh)); // get the creature name //std::cout << cname.c_str() << std::endl; pos.x = fgetc(fh); pos.x += fgetc(fh) << 8; pos.y = fgetc(fh); pos.y += fgetc(fh) << 8; pos.z = fgetc(fh); radius = fgetc(fh) + 1; count = fgetc(fh); // number of creatures in this respawn total += count; secs = fgetc(fh); secs += fgetc(fh) << 8; Spawn *spawn = new Spawn(&g_game, pos, radius); SpawnManager::instance()->addSpawn(spawn); for (int j = 0; j < count; j++) { cx = (rand() % (radius * 2)) - radius; cy = (rand() % (radius * 2)) - radius; spawn->addMonster(cname, NORTH, cx, cy, secs * 1000); } fgetc(fh); // 1 = check for players near, 0 = dont check } std::cout << ":: Loaded spawns: " << total << std::endl; SpawnManager::instance()->startup(); } break; case 0xF0: end = true; break; } } fclose(fh); return; }
void SpawnShell::newSpawn(const spawnStruct& s) { #ifdef SPAWNSHELL_DIAG seqDebug("SpawnShell::newSpawn(spawnStruct *(name='%s'))", s.name); #endif // if this is the SPAWN_SELF it's the player if (s.NPC == SPAWN_SELF) return; // not the player, so check if it's a recently deleted spawn for (int i =0; i < m_cntDeadSpawnIDs; i++) { if ((m_deadSpawnID[i] != 0) && (m_deadSpawnID[i] == s.spawnId)) { // found a match, remove it from the deleted spawn list m_deadSpawnID[i] = 0; /* Commented this out because it wasn't adding shrouded spawns. Shrouded spawns get deleted from the zone first then added as a new spawn. leaving this here in case another work-around needs to be found. (ieatacid - 6-8-2008) // let the user know what's going on seqInfo("%s(%d) has already been removed from the zone before we processed it.", s.name, s.spawnId); // and stop the attempt to add the spawn. return; */ } } Item* item = m_spawns.find(s.spawnId); if (item != NULL) { Spawn* spawn = (Spawn*)item; spawn->update(&s); updateFilterFlags(spawn); updateRuntimeFilterFlags(spawn); item->updateLastChanged(); if (spawn->guildID() < MAX_GUILDS) spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->guildID())); else spawn->setGuildTag(""); if (!showeq_params->fast_machine) item->setDistanceToPlayer(m_player->calcDist2DInt(*item)); else item->setDistanceToPlayer(m_player->calcDist(*item)); emit changeItem(item, tSpawnChangedALL); } else { item = new Spawn(&s); Spawn* spawn = (Spawn*)item; updateFilterFlags(spawn); updateRuntimeFilterFlags(spawn); m_spawns.insert(s.spawnId, item); if (spawn->guildID() < MAX_GUILDS) spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->guildID())); else spawn->setGuildTag(""); if (!showeq_params->fast_machine) item->setDistanceToPlayer(m_player->calcDist2DInt(*item)); else item->setDistanceToPlayer(m_player->calcDist(*item)); emit addItem(item); // send notification of new spawn count emit numSpawns(m_spawns.count()); } }
void SpawnShell::newSpawn(const spawnStruct& s) { #ifdef SPAWNSHELL_DIAG printf("SpawnShell::newSpawn(spawnStruct *(name='%s'), bSelected=%s)\n", s.name, bSelected?"true":"false"); #endif // if this is the SPAWN_SELF it's the player if (s.NPC == SPAWN_SELF) return; // not the player, so check if it's a recently deleted spawn for (int i =0; i < m_cntDeadSpawnIDs; i++) { if ((m_deadSpawnID[i] != 0) && (m_deadSpawnID[i] == s.spawnId)) { // found a match, remove it from the deleted spawn list m_deadSpawnID[i] = 0; // let the user know what's going on printf("%s(%d) has already been removed from the zone before we processed it.\n", s.name, s.spawnId); // and stop the attempt to add the spawn. return; } } Item* item = m_spawns.find(s.spawnId); if (item != NULL) { Spawn* spawn = (Spawn*)item; spawn->update(&s); updateFilterFlags(spawn); updateRuntimeFilterFlags(spawn); item->updateLastChanged(); if (spawn->GuildID() < MAXGUILDS) spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->GuildID())); if (!showeq_params->fast_machine) item->setDistanceToPlayer(m_player->calcDist2DInt(*item)); else item->setDistanceToPlayer(m_player->calcDist(*item)); emit changeItem(item, tSpawnChangedALL); } else { item = new Spawn(&s); Spawn* spawn = (Spawn*)item; updateFilterFlags(spawn); updateRuntimeFilterFlags(spawn); m_spawns.insert(s.spawnId, item); if (spawn->GuildID() < MAXGUILDS) spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->GuildID())); if (!showeq_params->fast_machine) item->setDistanceToPlayer(m_player->calcDist2DInt(*item)); else item->setDistanceToPlayer(m_player->calcDist(*item)); emit addItem(item); // send notification of new spawn count emit numSpawns(m_spawns.count()); } if (item->filterFlags() & FILTER_FLAG_ALERT) emit handleAlert(item, tNewSpawn); }
bool Spawns::parseSpawnNode(xmlNodePtr p, bool checkDuplicate) { if(xmlStrcmp(p->name, (const xmlChar*)"spawn")) return false; int32_t intValue; std::string strValue; Position centerPos; if(!readXMLString(p, "centerpos", strValue)) { if(!readXMLInteger(p, "centerx", intValue)) return false; centerPos.x = intValue; if(!readXMLInteger(p, "centery", intValue)) return false; centerPos.y = intValue; if(!readXMLInteger(p, "centerz", intValue)) return false; centerPos.z = intValue; } else { IntegerVec posVec = vectorAtoi(explodeString(",", strValue)); if(posVec.size() < 3) return false; centerPos = Position(posVec[0], posVec[1], posVec[2]); } if(!readXMLInteger(p, "radius", intValue)) return false; int32_t radius = intValue; Spawn* spawn = new Spawn(centerPos, radius); if(checkDuplicate) { for(SpawnList::iterator it = spawnList.begin(); it != spawnList.end(); ++it) { if((*it)->getPosition() == centerPos) delete *it; } } spawnList.push_back(spawn); xmlNodePtr tmpNode = p->children; while(tmpNode) { if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"monster")) { std::string name; if(!readXMLString(tmpNode, "name", strValue)) { tmpNode = tmpNode->next; continue; } name = strValue; int32_t interval = MINSPAWN_INTERVAL / 1000; if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue)) { if(intValue <= interval) { std::cout << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"; std::cout << " be less than " << interval << " seconds." << std::endl; tmpNode = tmpNode->next; continue; } interval = intValue; } interval *= 1000; Position placePos = centerPos; if(readXMLInteger(tmpNode, "x", intValue)) placePos.x += intValue; if(readXMLInteger(tmpNode, "y", intValue)) placePos.y += intValue; if(readXMLInteger(tmpNode, "z", intValue)) placePos.z /*+*/= intValue; Direction direction = NORTH; if(readXMLInteger(tmpNode, "direction", intValue) && direction >= EAST && direction <= WEST) direction = (Direction)intValue; spawn->addMonster(name, placePos, direction, interval); } else if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"npc")) { std::string name; if(!readXMLString(tmpNode, "name", strValue)) { tmpNode = tmpNode->next; continue; } name = strValue; Position placePos = centerPos; if(readXMLInteger(tmpNode, "x", intValue)) placePos.x += intValue; if(readXMLInteger(tmpNode, "y", intValue)) placePos.y += intValue; if(readXMLInteger(tmpNode, "z", intValue)) placePos.z /*+*/= intValue; Direction direction = NORTH; if(readXMLInteger(tmpNode, "direction", intValue) && direction >= EAST && direction <= WEST) direction = (Direction)intValue; Npc* npc = Npc::createNpc(name); if(!npc) { tmpNode = tmpNode->next; continue; } npc->setMasterPos(placePos, radius); npc->setDirection(direction); npcList.push_back(npc); } tmpNode = tmpNode->next; } return true; }
bool SpawnManager::loadSpawnsXML(std::string filename) { std::transform(filename.begin(), filename.end(), filename.begin(), tolower); xmlDocPtr doc = xmlParseFile(filename.c_str()); if (doc){ xmlNodePtr root, p; char* nodeValue = NULL; root = xmlDocGetRootElement(doc); root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name,(const xmlChar*) "spawns")){ xmlFreeDoc(doc); return false; } p = root->children; while (p) { const char* str = (char*)p->name; if (strcmp(str, "spawn") == 0) { Position centerpos; int radius; nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"centerx"); if(nodeValue) { centerpos.x = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } else { xmlFreeOTSERV(nodeValue); return false; } nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"centery"); if(nodeValue) { centerpos.y = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } else { xmlFreeOTSERV(nodeValue); xmlFreeDoc(doc); return false; } nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"centerz"); if(nodeValue) { centerpos.z = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } else { xmlFreeOTSERV(nodeValue); xmlFreeDoc(doc); return false; } nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"radius"); if(nodeValue) { radius = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } else { xmlFreeOTSERV(nodeValue); xmlFreeDoc(doc); return false; } Spawn *spawn = new Spawn(game, centerpos, radius); spawns.push_back(spawn); std::string name; int x, y, spawntime; Direction direction = NORTH; int rawdir = 0; //NORTH xmlNodePtr tmp = p->children; while (tmp) { str = (char*)tmp->name; if (strcmp(str, "monster") == 0) { nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"name"); if(nodeValue) { name = nodeValue; xmlFreeOTSERV(nodeValue); } else { tmp = tmp->next; break; } nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"direction"); if(nodeValue) { rawdir = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"x"); if(nodeValue) { x = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } else { tmp = tmp->next; break; } nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"y"); if(nodeValue) { y = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } else { tmp = tmp->next; break; } nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"spawntime"); if(nodeValue) { spawntime = atoi(nodeValue); xmlFreeOTSERV(nodeValue); } else { tmp = tmp->next; break; } switch(rawdir) { case 0: direction = NORTH; break; case 1: direction = EAST; break; case 2: direction = SOUTH; break; case 3: direction = WEST; break; default: direction = NORTH; break; } spawn->addMonster(name, direction, x, y, spawntime * 1000); } tmp = tmp->next; } } p = p->next; } xmlFreeDoc(doc); return true; } return false; }
bool SpawnManager::loadSpawnsSQL(std::string identifier) { std::string host = g_config.getGlobalString("map_host"); std::string user = g_config.getGlobalString("map_user"); std::string pass = g_config.getGlobalString("map_pass"); std::string db = g_config.getGlobalString("map_db"); #ifdef __DEBUG__ std::cout "host" << host << "user" << user << "pass" << pass << "db" << db << std::endl; #endif mysqlpp::Connection con; try{ con.connect(db.c_str(), host.c_str(), user.c_str(), pass.c_str()); } catch(mysqlpp::BadQuery e){ std::cout << "MYSQL-ERROR: " << e.error << std::endl; return false; } mysqlpp::Result res; //Monsters //Try & Find the Monter's try{ mysqlpp::Query query = con.query(); query << "SELECT * FROM " << identifier << "_monsters WHERE name !=''"; #ifdef __DEBUG__ std::cout << query.preview() << std::endl; #endif res = query.store(); } //End Try catch(mysqlpp::BadQuery e){ std::cout << "MYSQL-ERROR: " << e.error << std::endl; return false; } std::cout << ":: Found: " << res.size() << " Monsters(s)/Spawn(s)" << std::endl; if(res.size() < 1){//No Monsters std::cout << "No Monsters found" << std::endl; return false; } //if there are any monster spawns to load else{ //Load Monsters try{ mysqlpp::Result Monster; mysqlpp::Query query = con.query(); for(int i=1; i <= res.size(); ++i){ query.reset(); query << "SELECT * FROM " << identifier << "_monsters WHERE id = '" << i <<"' and id != ''"; Monster = query.store(); mysqlpp::Row row = *Monster.begin(); //Get the Monster's Position on Map std::string pos = std::string(row.lookup_by_name("spawnpos")); boost::char_separator<char> sep(";"); tokenizer spawnpostokens(pos, sep); tokenizer::iterator spawnposit = spawnpostokens.begin(); Position spawnpos; spawnpos.x=atoi(spawnposit->c_str()); spawnposit++; spawnpos.y=atoi(spawnposit->c_str()); spawnposit++; spawnpos.z=atoi(spawnposit->c_str()); std::string name; if(std::string(row.lookup_by_name("name")) != ""){name = std::string(row.lookup_by_name("name"));} int time = row.lookup_by_name("time"); Spawn *spawn = new Spawn(game, spawnpos, 1); spawns.push_back(spawn); spawn->addMonster(name, NORTH, 0, 0, time * 1000); }//End For Loop }//End Try catch(mysqlpp::BadQuery e){ std::cout << "MYSQL-ERROR: " << e.error << std::endl; return false; }//End Catch } //NPC's //Try & Find the NPC's try{ mysqlpp::Query query = con.query(); query << "SELECT * FROM " << identifier << "_npcs WHERE name !=''"; #ifdef __DEBUG__ std::cout << query.preview() << std::endl; #endif res = query.store(); }//End Try catch(mysqlpp::BadQuery e){ std::cout << "MYSQL-ERROR: " << e.error << std::endl; return false; } std::cout << ":: Found: " << res.size() << " NPC(s)" << std::endl; if(res.size() < 1){//No NPC's std::cout << "No NPC's found" << std::endl; return false; } //if there are any NPC's to load else{ //Load Monsters try{ mysqlpp::Result Monster; mysqlpp::Query query = con.query(); for(int i=1; i <= res.size(); ++i){ query.reset(); query << "SELECT * FROM " << identifier << "_npcs WHERE id = '" << i <<"' and id != ''"; Monster = query.store(); mysqlpp::Row row = *Monster.begin(); //Get the NPC's Position on Map std::string pos = std::string(row.lookup_by_name("pos")); boost::char_separator<char> sep(";"); tokenizer postokens(pos, sep); tokenizer::iterator posit = postokens.begin(); Position npcpos; npcpos.x=atoi(posit->c_str()); posit++; npcpos.y=atoi(posit->c_str()); posit++; npcpos.z=atoi(posit->c_str()); std::string name; if(std::string(row.lookup_by_name("name")) != ""){name = std::string(row.lookup_by_name("name"));} int dir = row.lookup_by_name("dir"); Npc* npc = new Npc(name, game); npc->pos = npcpos; switch(dir){ case 1: npc->direction=(NORTH); break; case 2: npc->direction=(SOUTH); break; case 3: npc->direction=(WEST); break; case 4: npc->direction=(EAST); break; default: // std::cout << "Invalid direction for " << name << " " <<x<<" "<<y<<" "<<z<<"."; return false; break; } if(!game->placeCreature(npc->pos, npc)){ delete npc; } }//End For Loop return true; }//End Try catch(mysqlpp::BadQuery e){ std::cout << "MYSQL-ERROR: " << e.error << std::endl; return false; }//End Catch } return true; }
bool Spawns::loadFromXml(const std::string& _filename) { if (loaded) { return true; } pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(_filename.c_str()); if (!result) { std::cout << "[Error - Spawns::loadFromXml] Failed to load " << _filename << ": " << result.description() << std::endl; return false; } filename = _filename; loaded = true; for (pugi::xml_node spawnNode = doc.child("spawns").first_child(); spawnNode; spawnNode = spawnNode.next_sibling()) { Position centerPos( pugi::cast<uint16_t>(spawnNode.attribute("centerx").value()), pugi::cast<uint16_t>(spawnNode.attribute("centery").value()), pugi::cast<uint16_t>(spawnNode.attribute("centerz").value()) ); int32_t radius; pugi::xml_attribute radiusAttribute = spawnNode.attribute("radius"); if (radiusAttribute) { radius = pugi::cast<int32_t>(radiusAttribute.value()); } else { radius = -1; } Spawn* spawn = new Spawn(centerPos, radius); spawnList.push_back(spawn); for (pugi::xml_node childNode = spawnNode.first_child(); childNode; childNode = childNode.next_sibling()) { if (strcasecmp(childNode.name(), "monster") == 0) { pugi::xml_attribute nameAttribute = childNode.attribute("name"); if (!nameAttribute) { continue; } Direction dir; pugi::xml_attribute directionAttribute = childNode.attribute("direction"); if (directionAttribute) { dir = static_cast<Direction>(pugi::cast<uint16_t>(directionAttribute.value())); } else { dir = NORTH; } Position pos( centerPos.x + pugi::cast<uint16_t>(childNode.attribute("x").value()), centerPos.y + pugi::cast<uint16_t>(childNode.attribute("y").value()), centerPos.z ); uint32_t interval = pugi::cast<uint32_t>(childNode.attribute("spawntime").value()) * 1000; if (interval > MINSPAWN_INTERVAL) { spawn->addMonster(nameAttribute.as_string(), pos, dir, interval); } else { std::cout << "[Warning - Spawns::loadFromXml] " << nameAttribute.as_string() << ' ' << pos << " spawntime can not be less than " << MINSPAWN_INTERVAL / 1000 << " seconds." << std::endl; } } else if (strcasecmp(childNode.name(), "npc") == 0) { pugi::xml_attribute nameAttribute = childNode.attribute("name"); if (!nameAttribute) { continue; } Npc* npc = Npc::createNpc(nameAttribute.as_string()); if (!npc) { continue; } pugi::xml_attribute directionAttribute = childNode.attribute("direction"); if (directionAttribute) { npc->setDirection(static_cast<Direction>(pugi::cast<uint16_t>(directionAttribute.value()))); } npc->setMasterPos(Position( centerPos.x + pugi::cast<uint16_t>(childNode.attribute("x").value()), centerPos.y + pugi::cast<uint16_t>(childNode.attribute("y").value()), centerPos.z ), radius); npcList.push_back(npc); } } } return true; }
void HeroFrog::setHeroStatus(FrogStatus heroStatus){ if (m_heroStatus == heroStatus) { return; } m_heroStatus = heroStatus; Animation* ani; Animate* ac; this->stopAllActions(); ani = AnimationCache::getInstance()->getAnimation(animaName[heroStatus].c_str()); Animation* ani1; Animate* ac1; if (heroStatus == frogJumpDown) { ani1 = AnimationCache::getInstance()->getAnimation(animaName[heroStatus+1].c_str()); }else if (heroStatus == frogJumpUp&& m_isLongJump){ std::string aniName = animaName[8].c_str(); ani = AnimationCache::getInstance()->getAnimation(aniName); } Sequence* seq; float y; float dis; float time; SpriteFrame* deadFrame ; Spawn* sp; MoveTo* mvTo; Point targetPoint; // CCLOG("---------设置hero状态-----------"); switch (heroStatus) { case frogStatic: GameMainHelper::getInstance()->playSound(JUMPOVER); ac= Animate::create(ani) ; runAction(RepeatForever::create(ac)); break; case frogTakeoff: ac= Animate::create(ani) ; ani->setDelayPerUnit(0.2); runAction(RepeatForever::create(ac)); break; case frogJumpUp: if(m_isLongJump) GameMainHelper::getInstance()->playSound(JUMPSTART_1); else GameMainHelper::getInstance()->playSound(JUMPSTART_0); ani->setDelayPerUnit(0.2); //--------待计算 ac= Animate::create(ani); runAction(RepeatForever::create(ac)); break; case frogJumpDown: ani->setDelayPerUnit(downAnimSpeed); //--------待计算 ani1->setDelayPerUnit(0.2); ac= Animate::create(ani); ac1 = Animate::create(ani1); runAction(Sequence::create(ac,Repeat::create(ac1,20), NULL) ); break; case frogFall: ani->setDelayPerUnit(downAnimSpeed); ac= Animate::create(ani); targetPoint = GameMainHelper::getInstance()->getHeroPostPoint(); time =ani->getDelayPerUnit(); mvTo = MoveTo::create(downAnimSpeed,targetPoint); sp = Spawn::create(ac,mvTo, NULL); seq = Sequence::create(sp,CCCallFunc::create(CC_CALLBACK_0(HeroFrog::setHeroStatic, this)) , NULL); runAction(seq); break; case frogDead1: GameMainHelper::getInstance()->playSound(HEROOVER); deadFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_dead2.png"); this->setDisplayFrame(deadFrame); ac= Animate::create(ani); y = MIN(GameMainHelper::getInstance()->getEarthH(),getPositionY()); dis = getPositionY()-y; time = dis/downSpeed; targetPoint = Point(getPositionX(),y); mvTo = MoveTo::create(time,targetPoint); sp = Spawn::create(Repeat::create(ac,(int)(time/(0.2*3))),mvTo, NULL); sp->setTag(DEAD1TAG); seq = Sequence::create(DelayTime::create(0.5), sp,CCCallFunc::create(CC_CALLBACK_0(HeroFrog::stopAnimation, this)), NULL); runAction(seq); break; case frogDead2: GameMainHelper::getInstance()->playSound(HEROOVER); ac= Animate::create(ani) ; runAction(RepeatForever::create(ac)); break; default: ac= Animate::create(ani); runAction(RepeatForever::create(ac)); break; } }