if (this->Harvestable(target_x, target_y) && this->world->config["EnableHarvesting"])
{
Config harvesting_config = this->world->harvesting_config;
int id = harvesting_config["HarvestingItem"];
if (from->AddItem(id, 1))
{
PacketBuilder builder(PACKET_ITEM, PACKET_GET);
builder.AddShort(0); // UID
builder.AddShort(id);
builder.AddThree(1);
builder.AddChar(from->weight);
builder.AddChar(from->maxweight);
from->player->client->SendBuilder(builder);
if (harvesting_config["Hurt"])
{
if ((double(util::rand(0,10000)) / 100.0) < static_cast<int>(harvesting_config["HurtChance"]))
{
int amount = util::rand(static_cast<int>(harvesting_config["MinHurt"]), static_cast<int>(harvesting_config["MaxHurt"]));
int limitamount = std::min(amount, int(from->hp));
if (this->world->config["LimitDamage"])
{
amount = limitamount;
}
from->hp -= limitamount;
builder.Reset();
builder.SetID(PACKET_CLOTHES, PACKET_REPLY);
builder.AddShort(from->player->id);
builder.AddShort(from->player->id);
builder.AddThree(amount);
builder.AddChar(from->direction);
builder.AddChar(int(double(from->hp) / double(from->maxhp) * 100.0));
builder.AddChar(from->hp == 0);
UTIL_PTR_LIST_FOREACH(this->characters, Character, checkchar)
{
if (from->InRange(*checkchar))
{
checkchar->player->client->SendBuilder(builder);
}
}
if (from->hp == 0)
{
from->hp = int(from->maxhp * static_cast<double>(this->world->config["DeathRecover"]) / 100.0);
if (this->world->config["Deadly"])
{
from->DropAll(0);
}
from->map->Leave(from, WARP_ANIMATION_NONE, true);
from->nowhere = true;
from->map = this->world->GetMap(from->SpawnMap());
from->mapid = from->SpawnMap();
from->x = from->SpawnX();
from->y = from->SpawnY();
PacketReader reader("");
from->player->client->queue.AddAction(PACKET_INTERNAL, PACKET_INTERNAL_NULL, reader, 1.5);
from->player->client->queue.AddAction(PACKET_INTERNAL, PACKET_INTERNAL_WARP, reader, 0.0);
}
builder.Reset();
builder.SetID(PACKET_RECOVER, PACKET_PLAYER);
builder.AddShort(from->hp);
builder.AddShort(from->tp);
from->player->client->SendBuilder(builder);
}
}
}
else Console::Err("Harvesting : Error in giving item %i", id);
return;
}