Advertisement
Guest User

Untitled

a guest
Apr 18th, 2011
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. void Map::Mine(Character *from)
  2. {
  3.     PtrVector<Mine_Drop> drops;
  4.     Mine_Drop *drop = 0;
  5.     UTIL_PTR_VECTOR_FOREACH(this->world->mine_drops, Mine_Drop, checkdrop)
  6.     {
  7.         if (checkdrop->levelreq <= from->mlevel)
  8.         {
  9.             if ((double(util::rand(0,10000)) / 100.0) < (checkdrop->chance + (from->mlevel - checkdrop->levelreq) / 4))
  10.             {
  11.                 drops.push_back(*checkdrop);
  12.             }
  13.         }
  14.     }
  15.  
  16.     if (drops.size() > 0)
  17.     {
  18.         drop = drops[util::rand(0, drops.size()-1)];
  19.     }
  20.  
  21.     PacketBuilder builder;
  22.     if (drop)
  23.     {
  24.         from->ServerMsg("You ored " + this->world->eif->Get(drop->item)->name);
  25.         from->mexp = std::min(from->mexp + drop->exp, util::to_int(this->world->config["MaxExp"]));
  26.  
  27.         bool level_up = false;
  28.         while (from->mlevel < static_cast<int>(this->world->config["MaxLevel"]) && from->mexp >= this->world->exp_table[from->mlevel+1])
  29.         {
  30.             level_up = true;
  31.             ++from->mlevel;
  32.         }
  33.  
  34.         builder.SetID(PACKET_RECOVER, PACKET_REPLY);
  35.         builder.AddInt(from->mexp);
  36.         builder.AddShort(from->karma);
  37.         if (!from->mining_exp)
  38.         {
  39.             from->mining_exp = true;
  40.             from->ServerMsg("Switching to mining exp mode");
  41.             builder.AddChar(from->mlevel);
  42.         }
  43.         else
  44.         {
  45.             if (level_up)
  46.             {
  47.                 builder.AddChar(from->mlevel);
  48.                 PacketBuilder reply(PACKET_ITEM, PACKET_ACCEPT);
  49.                 reply.AddShort(from->player->id);
  50.                 UTIL_PTR_LIST_FOREACH(this->characters, Character, character)
  51.                 {
  52.                     if (*character != from && character->InRange(from))
  53.                     {
  54.                         character->player->client->SendBuilder(reply);
  55.                     }
  56.                 }
  57.             }
  58.             else
  59.                 builder.AddChar(0);
  60.         }
  61.         from->player->client->SendBuilder(builder);
  62.  
  63.         if (from->AddItem(drop->item, 1))
  64.         {
  65.             from->CalculateStats();
  66.             PacketBuilder builder(PACKET_ITEM, PACKET_STOCK);
  67.             builder.AddShort(drop->item);
  68.             builder.AddThree(1);
  69.             builder.AddChar(from->weight);
  70.             from->player->client->SendBuilder(builder);
  71.         }
  72.     }
  73.     else
  74.     {
  75.         from->ServerMsg("You failed to mine anything");
  76.     }
  77.  
  78.     builder.Reset();
  79.     builder.SetID(PACKET_ATTACK,PACKET_PLAYER);
  80.     builder.AddShort(from->player->id);
  81.     builder.AddChar(from->direction);
  82.  
  83.     UTIL_PTR_LIST_FOREACH(this->characters, Character, character)
  84.     {
  85.         if (from->InRange(*character))
  86.         {
  87.             character->player->client->SendBuilder(builder);
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement