bool Client::checkAns() { checkBroadcast(); if (_ans.find("niveau") >= _ans.size()) { if (_lastCommand == INVENTORY && checkInventory() == false) getAns(); else if (_lastCommand == BASIC && _ans != "ok" && _ans != "ko") { getAns(); } else if (_lastCommand == INCANTATION && _ans != "ko") checkLvlUp(); else if (_lastCommand == LOOK && _ans.at(_ans.length() - 1) != '}' && _ans.at(0) != '{') return true; } else if (_lvlUp == false) { _lvlUp = true; ++_lvl; } return false; }
bool User::updatePos(double x, double y, double z, double stance) { if(nick.size() && logged) { //Do we send relative or absolute move values if(0) //abs(x-this->pos.x)<127 //&& abs(y-this->pos.y)<127 //&& abs(z-this->pos.z)<127) { uint8 movedata[8]; movedata[0] = 0x1f; //Relative move putSint32(&movedata[1], (sint32)this->UID); movedata[5] = (char)(x-this->pos.x); movedata[6] = (char)(y-this->pos.y); movedata[7] = (char)(z-this->pos.z); this->sendOthers(&movedata[0], 8); } else { this->pos.x = x; this->pos.y = y; this->pos.z = z; this->pos.stance = stance; uint8 teleportData[19]; teleportData[0] = 0x22; //Teleport putSint32(&teleportData[1], this->UID); putSint32(&teleportData[5], (int)(this->pos.x*32)); putSint32(&teleportData[9], (int)(this->pos.y*32)); putSint32(&teleportData[13], (int)(this->pos.z*32)); teleportData[17] = (char)this->pos.yaw; teleportData[18] = (char)this->pos.pitch; this->sendOthers(&teleportData[0], 19); } //Check if there are items in this chunk! sint32 chunk_x = blockToChunk((sint32)x); sint32 chunk_z = blockToChunk((sint32)z); uint32 chunkHash; Map::get().posToId(chunk_x, chunk_z, &chunkHash); if(Map::get().mapItems.count(chunkHash)) { //Loop through items and check if they are close enought to be picked up for(sint32 i = Map::get().mapItems[chunkHash].size()-1; i >= 0; i--) { //No more than 2 blocks away if(abs((sint32)x-Map::get().mapItems[chunkHash][i]->pos.x()/32) < 2 && abs((sint32)z-Map::get().mapItems[chunkHash][i]->pos.z()/32) < 2 && abs((sint32)y-Map::get().mapItems[chunkHash][i]->pos.y()/32) < 2) { //Dont pickup own spawns right away if(Map::get().mapItems[chunkHash][i]->spawnedBy != this->UID || Map::get().mapItems[chunkHash][i]->spawnedAt+2 < time(0)) { //Check player inventory for space! if(checkInventory(Map::get().mapItems[chunkHash][i]->item, Map::get().mapItems[chunkHash][i]->count)) { //Send player collect item packet uint8 *packet = new uint8[9]; packet[0] = PACKET_COLLECT_ITEM; putSint32(&packet[1], Map::get().mapItems[chunkHash][i]->EID); putSint32(&packet[5], this->UID); buffer.addToWrite(packet, 9); //Send everyone destroy_entity-packet packet[0] = PACKET_DESTROY_ENTITY; putSint32(&packet[1], Map::get().mapItems[chunkHash][i]->EID); //ToDo: Only send users in range this->sendAll(packet, 5); packet[0] = PACKET_ADD_TO_INVENTORY; putSint16(&packet[1], Map::get().mapItems[chunkHash][i]->item); packet[3] = Map::get().mapItems[chunkHash][i]->count; putSint16(&packet[4], Map::get().mapItems[chunkHash][i]->health); buffer.addToWrite(packet, 6); //We're done, release packet memory delete[] packet; Map::get().items.erase(Map::get().mapItems[chunkHash][i]->EID); delete Map::get().mapItems[chunkHash][i]; Map::get().mapItems[chunkHash].erase(Map::get().mapItems[chunkHash].begin()+i); } } } } } //Chunk position changed, check for map updates if((int)(x/16) != curChunk.x() || (int)(z/16) != curChunk.z()) { //This is not accurate chunk!! curChunk.x() = (int)(x/16); curChunk.z() = (int)(z/16); for(int mapx = -viewDistance+curChunk.x(); mapx <= viewDistance+curChunk.x(); mapx++) { for(int mapz = -viewDistance+curChunk.z(); mapz <= viewDistance+curChunk.z(); mapz++) { addQueue(mapx, mapz); } } for(unsigned int i = 0; i < mapKnown.size(); i++) { //If client has map data more than viesDistance+1 chunks away, remove it if(mapKnown[i].x() < curChunk.x()-viewDistance-1 || mapKnown[i].x() > curChunk.x()+viewDistance+1 || mapKnown[i].z() < curChunk.z()-viewDistance-1 || mapKnown[i].z() > curChunk.z()+viewDistance+1) addRemoveQueue(mapKnown[i].x(), mapKnown[i].z()); } } } this->pos.x = x; this->pos.y = y; this->pos.z = z; this->pos.stance = stance; return true; }
bool Player::doInput(std::string s) { // Create 2 new arrays, each to hold a word. std::string args[2]; // Put words into arrays int divisionpoint = s.find(" "); args[0] = s.substr(0,divisionpoint); args[1] = s.substr(divisionpoint+1); // Make the strings lowercase so they can be checked without being case sensitive. for (int i = 0; i < 16; i++) {if (args[0][i] <='Z' && args[0][i]>='A') args[0][i] -= ('Z'-'z');} // Convert string to lowercase. for (int i = 0; i < 16; i++) {if (args[1][i] <='Z' && args[1][i]>='A') args[1][i] -= ('Z'-'z');} // Convert string to lowercase. // Base input checker, takes the first word and uses the switch to call the needed function if (args[0] == "eat") goto eat; else if (args[0] == "get") goto get; else if (args[0] == "drop") goto drop; else if (args[0] == "go") goto go; else if (args[0] == "attack") goto attack; else if (args[0] == "search") {location->searchRoom(); return false;} else if (args[0] == "inventory") {checkInventory(); return false;} else if (args[0] == "health") {showHealth(); return false;} else if (args[0] == "weapon") goto weapon; else if (args[0] == "armor") goto armor; else if (args[0] == "suicide") {suicide(); return false;} else if (args[0] == "help") goto help; else {std::cout << "Unknown command, use 'help' to view commands.\n"; return false;} eat: if (args[1] == "0") {eat(0); return true;} else if (args[1] == "1") {eat(1); return true;} else if (args[1] == "2") {eat(2); return true;} else if (args[1] == "3") {eat(3); return true;} else if (args[1] == "4") {eat(4); return true;} else if (args[1] == "5") {eat(5); return true;} else if (args[1] == "6") {eat(6); return true;} else if (args[1] == "7") {eat(7); return true;} else if (args[1] == "8") {eat(8); return true;} else if (args[1] == "9") {eat(9); return true;} else {std::cout << "Invalid argument for 'eat'.\nValid arguments for 'eat' are numbers 0-9.\n"; return false;} get: if (args[1] == "0") {get(0); return true;} else if (args[1] == "1") {get(1); return true;} else if (args[1] == "2") {get(2); return true;} else if (args[1] == "3") {get(3); return true;} else if (args[1] == "4") {get(4); return true;} else if (args[1] == "5") {get(5); return true;} else if (args[1] == "6") {get(6); return true;} else if (args[1] == "7") {get(7); return true;} else if (args[1] == "8") {get(8); return true;} else if (args[1] == "9") {get(9); return true;} else {std::cout << "Invalid argument for 'get'.\nValid arguments for 'get' are numbers 0-9.\n"; return false;} drop: if (args[1] == "0") {drop(0); return true;} else if (args[1] == "1") {drop(1); return true;} else if (args[1] == "2") {drop(2); return true;} else if (args[1] == "3") {drop(3); return true;} else if (args[1] == "4") {drop(4); return true;} else if (args[1] == "5") {drop(5); return true;} else if (args[1] == "6") {drop(6); return true;} else if (args[1] == "7") {drop(7); return true;} else if (args[1] == "8") {drop(8); return true;} else if (args[1] == "9") {drop(9); return true;} else {std::cout << "Invalid argument for 'drop'.\nValid arguments for 'drop' are numbers 0-9.\n"; return false;} go: if (args[1] == "n") {go(0); return true;} else if (args[1] == "s") {go(1); return true;} else if (args[1] == "e") {go(2); return true;} else if (args[1] == "w") {go(3); return true;} else {std::cout << "Invalid argument for 'go'.\nValid arguments for 'go' are 'n', 's', 'e', and 'w'.\n"; return false;} attack: if (args[1] == "0") {attack(0); return true;} else if (args[1] == "1") {attack(1); return true;} else if (args[1] == "2") {attack(2); return true;} else if (args[1] == "3") {attack(3); return true;} else if (args[1] == "4") {attack(4); return true;} else {std::cout << "Invalid argument for 'attack'.\nValid arguments for 'attack' are numbers 0-4.\n"; return false;} weapon: if (args[1] == "0") {weapon(0); return true;} else if (args[1] == "1") {weapon(1); return true;} else if (args[1] == "2") {weapon(2); return true;} else if (args[1] == "3") {weapon(3); return true;} else if (args[1] == "4") {weapon(4); return true;} else if (args[1] == "5") {weapon(5); return true;} else if (args[1] == "6") {weapon(6); return true;} else if (args[1] == "7") {weapon(7); return true;} else if (args[1] == "8") {weapon(8); return true;} else if (args[1] == "9") {weapon(9); return true;} else {std::cout << "Invalid argument for 'weapon'.\nValid arguments for 'weapon' are numbers 0-9.\n"; return false;} armor: if (args[1] == "0") {armor(0); return true;} else if (args[1] == "1") {armor(1); return true;} else if (args[1] == "2") {armor(2); return true;} else if (args[1] == "3") {armor(3); return true;} else if (args[1] == "4") {armor(4); return true;} else if (args[1] == "5") {armor(5); return true;} else if (args[1] == "6") {armor(6); return true;} else if (args[1] == "7") {armor(7); return true;} else if (args[1] == "8") {armor(8); return true;} else if (args[1] == "9") {armor(9); return true;} else {std::cout << "Invalid argument for 'armor'.\nValid arguments for 'armor' are numbers 0-9.\n"; return false;} help: std::cout << "Valid commands are 'eat', 'get', 'drop', 'go', 'attack', 'search', 'inventory', 'health', 'weapon', 'armor', 'suicide', and 'help'.\n"; return false; }