Advertisement
Guest User

Untitled

a guest
Jul 24th, 2010
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.25 KB | None | 0 0
  1.  
  2. /* $Id: Jukebox.cpp 181 2009-12-31 04:24:55Z sausage $
  3.  * EOSERV is released under the zlib license.
  4.  * See LICENSE.txt for more info.
  5.  */
  6.  
  7. #include "handlers.h"
  8.  
  9. #include "map.hpp"
  10. #include "npc.hpp"
  11.  
  12. CLIENT_F_FUNC(Law)
  13. {
  14.     PacketBuilder reply;
  15.  
  16.     switch (action)
  17.     {
  18.         case PACKET_REQUEST: // Marriage or divorce request
  19.         {
  20.             if (this->player->character->npc_type == ENF::Law)
  21.             {
  22.                 unsigned char action = reader.GetChar();
  23.                 /*int session = */reader.GetInt();
  24.                 reader.GetByte(); // ?
  25.                 std::string partner = reader.GetEndString();
  26.                 switch (action)
  27.                 {
  28.                     case LAW_ACTION_MARRIAGE:
  29.                     {
  30.                         if (!this->player->character->partner.empty())
  31.                         {
  32.                             reply.SetID(PACKET_LAW, PACKET_REPLY);
  33.                             reply.AddChar(LAW_ALREADY_MARRIED);
  34.                         }
  35.                         else if (this->player->character->HasItem(1) < static_cast<int>(this->server->world->config["LawMarriageCost"]))
  36.                         {
  37.                             reply.SetID(PACKET_LAW, PACKET_REPLY);
  38.                             reply.AddChar(LAW_NO_GOLD);
  39.                         }
  40.                         else
  41.                         {
  42.                             this->player->character->DelItem(1, static_cast<int>(this->server->world->config["LawMarriageCost"]));
  43.  
  44.                             reply.SetID(PACKET_LAW, PACKET_REPLY);
  45.                             reply.AddChar(LAW_FIANCE);
  46.  
  47.                             reply.Reset();
  48.                             reply.SetID(PACKET_ITEM, PACKET_STOCK);
  49.                             reply.AddShort(1);
  50.                             reply.AddThree(this->player->character->HasItem(1));
  51.                             CLIENT_SEND(reply);
  52.                             this->player->character->fiance = partner;
  53.                         }
  54.                         CLIENT_SEND(reply);
  55.                     }
  56.                     break;
  57.  
  58.                     case LAW_ACTION_DIVORCE:
  59.                     {
  60.                         if (this->player->character->partner.empty())
  61.                         {
  62.                             reply.SetID(PACKET_LAW, PACKET_REPLY);
  63.                             reply.AddChar(LAW_NOT_MARRIED);
  64.                             CLIENT_SEND(reply);
  65.                         }
  66.                         else if (this->player->character->partner != partner)
  67.                         {
  68.                             reply.SetID(PACKET_LAW, PACKET_REPLY);
  69.                             reply.AddChar(LAW_INVALID_FIANCE);
  70.                             CLIENT_SEND(reply);
  71.                         }
  72.                         else if (this->player->character->HasItem(1) < static_cast<int>(this->server->world->config["LawDivorceCost"]))
  73.                         {
  74.                             reply.SetID(PACKET_LAW, PACKET_REPLY);
  75.                             reply.AddChar(LAW_NO_GOLD);
  76.                             CLIENT_SEND(reply);
  77.                         }
  78.                         else
  79.                         {
  80.                             if (this->server->world->CharacterExists(partner))
  81.                             {
  82.                                 this->player->character->DelItem(1, static_cast<int>(this->server->world->config["LawDivorceCost"]));
  83.                                 Character *divorced = this->server->world->GetCharacter(partner);
  84.                                 if (divorced)
  85.                                 {
  86.                                     PacketBuilder builder(PACKET_LAW, PACKET_REPLY);
  87.                                     builder.AddChar(LAW_DIVORCED);
  88.                                     divorced->player->client->SendBuilder(builder);
  89.                                     divorced->partner = "";
  90.                                 }
  91.                                 else
  92.                                 {
  93.                                     this->server->world->db.Query("UPDATE `characters` SET `partner` = ''  WHERE `name` = '$'", partner.c_str());
  94.                                 }
  95.  
  96.                                 reply.SetID(PACKET_LAW, PACKET_REPLY);
  97.                                 reply.AddChar(LAW_FIANCE);
  98.                                 CLIENT_SEND(reply);
  99.  
  100.                                 reply.Reset();
  101.                                 reply.SetID(PACKET_ITEM, PACKET_STOCK);
  102.                                 reply.AddShort(1);
  103.                                 reply.AddThree(this->player->character->HasItem(1));
  104.                                 CLIENT_SEND(reply);
  105.                                 this->player->character->partner = "";
  106.                             }
  107.                         }
  108.                     }
  109.                     break;
  110.                 }
  111.             }
  112.         }
  113.         break;
  114.  
  115.         case PACKET_OPEN: // Talked to a lawyer
  116.         {
  117.             short id = reader.GetShort();
  118.  
  119.             UTIL_PTR_VECTOR_FOREACH(this->player->character->map->npcs, NPC, npc)
  120.             {
  121.                 if (npc->index == id && npc->Data()->type == ENF::Law)
  122.                 {
  123.                     this->player->character->npc = *npc;
  124.                     this->player->character->npc_type = ENF::Law;
  125.  
  126.                     reply.SetID(PACKET_LAW, PACKET_OPEN);
  127.                     reply.AddInt(0); // Session token
  128.                     CLIENT_SEND(reply);
  129.  
  130.                     break;
  131.                 }
  132.             }
  133.         }
  134.         break;
  135.  
  136.  
  137.         default:
  138.             return false;
  139.     }
  140.  
  141.     return true;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement