/* $Id: Attack.cpp 182 2010-01-08 10:35:27Z sausage $ * EOSERV is released under the zlib license. * See LICENSE.txt for more info. */ #include "handlers.h" #include "map.hpp" #include <fstream> #include <string> #include <iostream> using namespace std; CLIENT_F_FUNC(Attack) { PacketBuilder reply; PacketBuilder builder; switch (action) { case PACKET_USE: // Player attacking { if (this->state < EOClient::Playing) return false; CLIENT_QUEUE_ACTION(0.58) Direction direction = static_cast<Direction>(reader.GetChar()); /*int timestamp = */reader.GetThree(); if (this->player->character->sitting != SIT_STAND) { return true; } if (direction != this->player->character->direction) { if (direction >= 0 && direction <= 3) { this->player->character->map->Face(this->player->character, direction); CLIENT_FORCE_QUEUE_ACTION(0.67) } else { return false; } } if (this->player->character) { int target_x = this->player->character->x; int target_y = this->player->character->y; switch (this->player->character->direction) { case DIRECTION_UP: target_y -= 1; break; case DIRECTION_RIGHT: target_x += 1; break; case DIRECTION_DOWN: target_y += 1; break; case DIRECTION_LEFT: target_x -= 1; break; } if (this->player->character->map->GetSpec(target_x, target_y) == Map_Tile::Unknown2 || (this->player->character->x == target_x && this->player->character->y == target_y)) { if (this->player->character->HasItem(1) < 1000) { this->player->character->map->Msg(this->player->character, " You dont have enough gold to play ", true); break; } if (this->player->character->HasItem(1) >= 1000) { short id = 1; int amount = 1000; if(this->player->character->DelItem(id, amount)); { builder.SetID(PACKET_ITEM, PACKET_KICK); builder.AddShort(id); builder.AddInt(this->player->character->HasItem(id)); builder.AddChar(this->player->character->weight); builder.AddChar(this->player->character->maxweight); this->player->character->player->client->SendBuilder(builder); int gold = 1; int amount1 = util::rand(1, 35000); int random = util::rand(0, 100); if (random < 10) { this->player->character->map->Msg(this->player->character," You won " + util::to_string(amount1), true); this->player->character->AddItem(gold, amount1); reply.SetID(PACKET_ITEM, PACKET_GET); reply.AddShort(0); // UID reply.AddShort(gold); reply.AddThree(amount1); reply.AddChar(this->player->character->weight); reply.AddChar(this->player->character->maxweight); this->player->character->player->client->SendBuilder(reply); break; } else if (random < 100 && random >= 10) { this->player->character->map->Msg(this->player->character," To bad, you lost! " + util::to_string(amount), true); break; } } } } this->player->character->Attack(direction); if(this->player->character->paperdoll[Character::Weapon] == 271) { //HARVESTING WEP 271 ITEM TO GAIN 667 if (this->player->character->map->GetSpec(target_x, target_y) == Map_Tile::Unknown1 || (this->player->character->x == target_x && this->player->character->y == target_y)) { int id = 667; int amount1 = util::rand(1, 4); int random = util::rand(0, 150); if (random < 15) { this->player->character->AddItem(id, amount1); reply.SetID(PACKET_ITEM, PACKET_GET); reply.AddShort(0); // UID reply.AddShort(id); reply.AddThree(amount1); reply.AddChar(this->player->character->weight); reply.AddChar(this->player->character->maxweight); this->player->character->player->client->SendBuilder(reply); break; } else if (random < 150 && random >= 15) { break; } } } // MINEING WEP 225 ID YO GAIN 668 this->player->character->Attack(direction); if(this->player->character->paperdoll[Character::Weapon] == 225) { if (this->player->character->map->GetSpec(target_x, target_y) == Map_Tile::Unknown5 || (this->player->character->x == target_x && this->player->character->y == target_y)) { int id = 668; int amount1 = util::rand(1, 4); int random = util::rand(0, 150); if (random < 15) { this->player->character->AddItem(id, amount1); reply.SetID(PACKET_ITEM, PACKET_GET); reply.AddShort(0); // UID reply.AddShort(id); reply.AddThree(amount1); reply.AddChar(this->player->character->weight); reply.AddChar(this->player->character->maxweight); this->player->character->player->client->SendBuilder(reply); break; } else if (random < 150 && random >= 15) { break; } } } //WOOD CUTTING WEP 31 ID TO GAIN 669 this->player->character->Attack(direction); if(this->player->character->paperdoll[Character::Weapon] == 31) { if (this->player->character->map->GetSpec(target_x, target_y) == Map_Tile::Unknown4 || (this->player->character->x == target_x && this->player->character->y == target_y)) { int id = 669; int amount1 = util::rand(1, 4); int random = util::rand(0, 150); if (random < 15) { this->player->character->AddItem(id, amount1); reply.SetID(PACKET_ITEM, PACKET_GET); reply.AddShort(0); // UID reply.AddShort(id); reply.AddThree(amount1); reply.AddChar(this->player->character->weight); reply.AddChar(this->player->character->maxweight); this->player->character->player->client->SendBuilder(reply); break; } else if (random < 150 && random >= 15) { break; } } } // this->player->character->Attack(direction); if(this->player->character->paperdoll[Character::Weapon] == 520) { if (this->player->character->map->GetSpec(target_x, target_y) == Map_Tile::Water || (this->player->character->x == target_x && this->player->character->y == target_y)) { int id = 475; int amount1 = util::rand(1, 4); int random = util::rand(0, 150); if (random < 15) { this->player->character->AddItem(id, amount1); reply.SetID(PACKET_ITEM, PACKET_GET); reply.AddShort(0); // UID reply.AddShort(id); reply.AddThree(amount1); reply.AddChar(this->player->character->weight); reply.AddChar(this->player->character->maxweight); this->player->character->player->client->SendBuilder(reply); break; } else if (random < 150 && random >= 15) { break; } } } this->player->character->Attack(direction); UTIL_PTR_LIST_FOREACH(this->player->character->map->characters, Character, character) { if (*character != this->player->character && this->player->character->InRange(*character)) { character->player->client->SendBuilder(reply); } } CLIENT_SEND(reply); } } break; default: return false; } return true; }