Advertisement
julienanid

[Trinity] Guild House

Sep 20th, 2013
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.47 KB | None | 0 0
  1. /* Made by: QQRofl Not sure
  2.    Updated by: Synth
  3.    Script: Guild Housing
  4.    Tested: untested in game
  5.    Shared For: Emudevs
  6. */
  7.  
  8. #include "ScriptPCH.h"
  9. #include <cstring>
  10. #include "GuildMgr.h"
  11. #include "ObjectMgr.h"
  12.  
  13. const uint32 GUILD_TOKEN = 37711;
  14. bool requiresGUpdate = true;
  15. std::vector<uint64> GuildHouses;
  16. char string[200];
  17.  
  18. enum Objects
  19. {
  20.     OBJECT_TABLE        = 180698,
  21.     OBJECT_TORCH        = 187988,
  22.     OBJECT_MAILBOX      = 142094,
  23.     OBJECT_CRATE        = 183992,
  24.     OBJECT_A_FLAG       = 187342,
  25.     OBJECT_H_FLAG       = 192688,
  26.     OBJECT_CHAIR        = 10201,
  27.     OBJECT_FIREPIT      = 1967,
  28.     OBJECT_GUILDVAULT   = 187390,
  29.     OBJECT_BARBER_CHAIR = 191817,
  30.     OBJECT_CRANBERRY_BUSH = 195199,
  31. };
  32.  
  33. void SpawnObject(Player * pPlayer, uint32 objectId)
  34. {
  35.     const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
  36.    
  37.     float x = float(pPlayer->GetPositionX());
  38.     float y = float(pPlayer->GetPositionY());
  39.     float z = float(pPlayer->GetPositionZ());
  40.     float o = float(pPlayer->GetOrientation());
  41.     Map* map = pPlayer->GetMap();
  42.  
  43.     GameObject* object = new GameObject;
  44.     uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
  45.    
  46.     if (!object->Create(guidLow, objectInfo->entry, map, pPlayer->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
  47.     {
  48.         delete object;
  49.         return;
  50.     }
  51.    
  52.     object->SetRespawnTime(1);
  53.     object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), pPlayer->GetPhaseMaskForSpawn());
  54.    
  55.     if (!object->LoadGameObjectFromDB(guidLow, map))
  56.     {
  57.         delete object;
  58.         return;
  59.     }
  60.    
  61.     sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
  62.     WorldDatabase.PExecute("INSERT INTO guildhouse_objects VALUES('%u', '%u')", pPlayer->GetGuildId(), guidLow);
  63. }
  64.  
  65. uint32 getGuildAreaId(Player * pPlayer)
  66. {
  67.     QueryResult Result = WorldDatabase.PQuery("SELECT area FROM guildhouses WHERE guildId='%u'", pPlayer->GetGuildId());
  68.     if(Result)
  69.     {
  70.         Field * pField = Result->Fetch();
  71.         return pField[0].GetUInt32();
  72.     }
  73.  
  74.     return -1;
  75.  
  76. }
  77.  
  78. bool isInGuildArea(Player * pPlayer)
  79. {
  80.     for(int i = 0; i < 21; i++)
  81.     {
  82.         if(pPlayer->GetAreaId() == getGuildAreaId(pPlayer))
  83.             return true;
  84.     }
  85.     return false;
  86. }
  87.  
  88. bool isGuildHouseOwner(Player * pPlayer)
  89. {
  90.     if(GuildHouses.empty() || requiresGUpdate == true)
  91.     {
  92.         if(requiresGUpdate == true)
  93.         {
  94.             GuildHouses.clear();
  95.             requiresGUpdate = false;
  96.         }
  97.         QueryResult Result = WorldDatabase.PQuery("SELECT guildId FROM guildhouses WHERE guildId != '0'");
  98.         if(Result)
  99.         {
  100.             Field * pFields = Result->Fetch();
  101.             int i = 0;
  102.             do
  103.             {
  104.                 GuildHouses.push_back(pFields[0].GetUInt64());
  105.                 i++;
  106.             }while(Result->NextRow());
  107.            
  108.             return isGuildHouseOwner(pPlayer);
  109.         }
  110.         else
  111.         {
  112.             return false;
  113.         }
  114.     }
  115.     else
  116.     {
  117.         for(std::vector<uint64>::iterator itr = GuildHouses.begin(); itr != GuildHouses.end(); itr++)
  118.         {
  119.             if(*itr != pPlayer->GetGuildId())
  120.                 continue;
  121.             else
  122.                 return true;
  123.         }
  124.         return false;
  125.     }
  126. }
  127.  
  128. bool isPlayerGuildLeader(Player *player)
  129. {
  130.     return (player->GetRank() == 0) && (player->GetGuildId() != 0);
  131. }
  132.  
  133. bool GuildOwnsHouse(Player * pPlayer)
  134. {
  135.     QueryResult pResult = WorldDatabase.PQuery("SELECT * FROM guildhouses WHERE guildId='%u'", pPlayer->GetGuildId());
  136.     if(!pResult)
  137.         return false;
  138.     else
  139.         return true;
  140. }
  141.  
  142. void CleanUpObjects(Player * pPlayer, uint32 guildId)
  143. {
  144.     QueryResult ObjectSpawns = WorldDatabase.PQuery("SELECT `guid` FROM `guildhouse_objects` WHERE `guildId` = '%u'", guildId);
  145.     if(ObjectSpawns)
  146.     {
  147.         do
  148.         {
  149.             Field * pField = ObjectSpawns->Fetch();
  150.             uint32 Object_GUID = pField[0].GetUInt32();
  151.             GameObject* object = NULL;
  152.             ChatHandler handler = ChatHandler(pPlayer->GetSession());
  153.  
  154.             if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(Object_GUID))
  155.                 object = handler.GetObjectGlobalyWithGuidOrNearWithDbGuid(Object_GUID, gameObjectData->id);
  156.  
  157.             if (!object)
  158.                 continue;
  159.  
  160.             object->SetRespawnTime(0);
  161.             object->Delete();
  162.             object->DeleteFromDB();
  163.             WorldDatabase.PExecute("DELETE FROM `guildhouse_objects` WHERE guid='%u'", Object_GUID);
  164.         }while(ObjectSpawns->NextRow());
  165.     }
  166. }
  167.  
  168. void SellGuildHouse(Player * pPlayer, Creature * pCreature)
  169. {
  170.     if(isInGuildArea(pPlayer))
  171.     {
  172.         WorldDatabase.PExecute("UPDATE `guildhouses` SET `guildId`='0' WHERE `guildId`='%u'", pPlayer->GetGuildId());
  173.         CleanUpObjects(pPlayer, pPlayer->GetGuildId());
  174.         pCreature->MonsterSay("You have successfully sold your guild house!", LANG_UNIVERSAL, pPlayer->GetGUID());
  175.         pPlayer->PlayerTalkClass->SendCloseGossip();
  176.         requiresGUpdate = true;
  177.         pPlayer->TeleportTo(530, -1861.239990f, 5437.810059f, -10.463400f, 1.353830f); // generally the mall
  178.     }
  179.     else
  180.     {
  181.         pPlayer->GetSession()->SendNotification("You must be in your guild house to sell it!");
  182.     }
  183. }
  184.  
  185. void PurchaseGuildHouse(Player * pPlayer, Creature * pCreature, uint32 &Id)
  186. {
  187.     if(pPlayer->HasItemCount(GUILD_TOKEN, 1))
  188.     {
  189.         WorldDatabase.PExecute("UPDATE `guildhouses` SET `guildId`='%u' WHERE `id`='%u'", pPlayer->GetGuildId(), Id);
  190.         pCreature->MonsterSay("Congratulations on the purchase of your new guild house!", LANG_UNIVERSAL, pPlayer->GetGUID());
  191.         pPlayer->DestroyItemCount(GUILD_TOKEN, 1, true);
  192.         requiresGUpdate = true;
  193.     }
  194.     else
  195.     {
  196.         pCreature->MonsterSay("You need a guild token to purchase a guild house!", LANG_UNIVERSAL, pPlayer->GetGUID());
  197.     }
  198.         pPlayer->PlayerTalkClass->SendCloseGossip();
  199. }
  200.  
  201. void TeleportToHouse(Player * pPlayer)
  202. {
  203.     if (pPlayer->IsInCombat());
  204.  
  205.     QueryResult result = WorldDatabase.PQuery("SELECT `x`, `y`, `z`, `map` FROM `guildhouses` WHERE `guildId` = '%u'", pPlayer->GetGuildId());
  206.     if (result)
  207.     {
  208.         Field *fields = result->Fetch();
  209.         float x = fields[0].GetFloat();
  210.         float y = fields[1].GetFloat();
  211.         float z = fields[2].GetFloat();
  212.         uint32 map = fields[3].GetUInt32();
  213.         pPlayer->TeleportTo(map, x, y, z, pPlayer->GetOrientation());
  214.     }
  215. }
  216.  
  217. class GuildHouse_NPC : public CreatureScript
  218. {
  219.     public:
  220.         GuildHouse_NPC() : CreatureScript("GuildHouse"){}
  221.  
  222.  
  223.         void ShowHouseListings(Player * pPlayer, Creature * pCreature, unsigned int start = 0)
  224.         {
  225.             pPlayer->PlayerTalkClass->ClearMenus();
  226.  
  227.             QueryResult pResult = WorldDatabase.PQuery("SELECT id, comment FROM guildhouses WHERE guildId='0'");
  228.             uint32 houses = pResult->GetRowCount();
  229.             int offset = 0;
  230.             Field * pField = pResult->Fetch();
  231.             bool ranOnce = false;
  232.             for(unsigned int i = start; i < houses; i++)
  233.             {
  234.                 if(start != 0 && ranOnce == false)
  235.                 {
  236.                     for(int x = 0; x < start; x++)
  237.                     {
  238.                         pResult->NextRow();
  239.                     }
  240.                     ranOnce = true;
  241.                 }
  242.  
  243.                 if(offset != 10)
  244.                 {
  245.                     pPlayer->ADD_GOSSIP_ITEM(6, pField[1].GetString(), GOSSIP_SENDER_MAIN, pField[0].GetUInt32());
  246.                     offset++;
  247.                     pResult->NextRow();
  248.                 }
  249.                 else
  250.                 {
  251.                     if((startid + 12) > houses)
  252.                     {
  253.                         pPlayer->ADD_GOSSIP_ITEM(7, "-------------END--------------", GOSSIP_SENDER_MAIN, 41);
  254.                     }
  255.                     else
  256.                     {
  257.                         pPlayer->ADD_GOSSIP_ITEM(7, "Next Page", GOSSIP_SENDER_MAIN, 4353);
  258.                         startid = start + offset;
  259.                         i = houses +10;
  260.                     }
  261.                 }
  262.             }
  263.             pPlayer->PlayerTalkClass->SendGossipMenu(2, pCreature->GetGUID());
  264.         }
  265.        
  266.         bool OnGossipHello(Player * pPlayer, Creature * pCreature)
  267.         {
  268.             startid = 0;
  269.  
  270.             if(pPlayer->GetGuildId() == 0)
  271.             {
  272.                 pPlayer->GetSession()->SendNotification("You must be in a guild!");
  273.                 return false;
  274.             }
  275.             else if (!GuildOwnsHouse(pPlayer) && !isPlayerGuildLeader(pPlayer))
  276.             {
  277.                 pPlayer->GetSession()->SendNotification("Your guild does not own a house!");
  278.                 return false;
  279.             }
  280.             pPlayer->ADD_GOSSIP_ITEM(4, "Guild Housing System:", GOSSIP_SENDER_MAIN, 41);
  281.             pPlayer->ADD_GOSSIP_ITEM(4, "----------------------------------------------", GOSSIP_SENDER_MAIN, 41);
  282.             if(isPlayerGuildLeader(pPlayer))
  283.             {
  284.                 if(!GuildOwnsHouse(pPlayer))
  285.                     pPlayer->ADD_GOSSIP_ITEM(6, "Buy a Guild House", GOSSIP_SENDER_MAIN, 38);
  286.                 else
  287.                     pPlayer->ADD_GOSSIP_ITEM_EXTENDED(6, "Sell Guild House", GOSSIP_SENDER_MAIN, 39, "Are you sure you want to sell your guild house?", 0, false);
  288.             }
  289.             if(GuildOwnsHouse(pPlayer))
  290.                 pPlayer->ADD_GOSSIP_ITEM(7, "Teleport to Guild House", GOSSIP_SENDER_MAIN, 40);
  291.             pPlayer->PlayerTalkClass->SendGossipMenu(2, pCreature->GetGUID());
  292.             return true;
  293.         }
  294.  
  295.         bool OnGossipSelect(Player * pPlayer, Creature * pCreature, uint32 /*uiSender*/, uint32 uiAction)
  296.         {
  297.             pPlayer->PlayerTalkClass->ClearMenus();
  298.  
  299.             switch(uiAction)
  300.             {
  301.                 case 38:
  302.                     ShowHouseListings(pPlayer, pCreature);
  303.                     break;
  304.                 case 39:
  305.                     SellGuildHouse(pPlayer, pCreature);
  306.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  307.                     break;
  308.                 case 40:
  309.                     TeleportToHouse(pPlayer);
  310.                     break;
  311.                 case 41:
  312.                     OnGossipHello(pPlayer, pCreature);
  313.                     break;
  314.                 case 4353:
  315.                     ShowHouseListings(pPlayer, pCreature, startid);
  316.                     break;
  317.                 default:
  318.                     if(uiAction < 38 && uiAction > 0)
  319.                         PurchaseGuildHouse(pPlayer, pCreature, uiAction);
  320.                     break;
  321.             }
  322.             return true;
  323.         }
  324.  
  325.         private:
  326.             uint32 startid;
  327. };
  328.  
  329.  
  330. class Table_Token : public ItemScript
  331. {
  332.     public:
  333.         Table_Token() : ItemScript("Table Token"){}
  334.  
  335.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  336.         {
  337.             if(!pPlayer)
  338.                 return false;
  339.  
  340.             if(!pItem)
  341.                 return false;
  342.  
  343.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  344.             {
  345.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  346.                 return false;
  347.             }
  348.  
  349.             if(!isInGuildArea(pPlayer))
  350.             {
  351.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  352.                 return false;
  353.             }
  354.  
  355.             SpawnObject(pPlayer, OBJECT_TABLE);
  356.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  357.             return true;
  358.         }
  359. };
  360.  
  361. class Torch_Token : public ItemScript
  362. {
  363.     public:
  364.         Torch_Token() : ItemScript("Torch Token"){}
  365.  
  366.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  367.         {
  368.             if(!pPlayer)
  369.                 return false;
  370.            
  371.             if(!pItem)
  372.                 return false;
  373.  
  374.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  375.             {
  376.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  377.                 return false;
  378.             }
  379.  
  380.             if(!isInGuildArea(pPlayer))
  381.             {
  382.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  383.                 return false;
  384.             }
  385.  
  386.             SpawnObject(pPlayer, OBJECT_TORCH);
  387.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  388.            
  389.             return true;
  390.         }
  391. };
  392.  
  393. class Mailbox_Token : public ItemScript
  394. {
  395.     public:
  396.         Mailbox_Token() : ItemScript("Mailbox Token"){}
  397.  
  398.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  399.         {
  400.             if(!pPlayer)
  401.                 return false;
  402.  
  403.             if(!pItem)
  404.                 return false;
  405.  
  406.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  407.             {
  408.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  409.                 return false;
  410.             }
  411.  
  412.             if(!isInGuildArea(pPlayer))
  413.             {
  414.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  415.                 return false;
  416.             }
  417.  
  418.             SpawnObject(pPlayer, OBJECT_MAILBOX);
  419.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  420.  
  421.             return true;
  422.         }
  423. };
  424.  
  425. class Crate_Token : public ItemScript
  426. {
  427.     public:
  428.         Crate_Token() : ItemScript("Crate Token"){}
  429.  
  430.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  431.         {
  432.             if(!pPlayer)
  433.                 return false;
  434.  
  435.             if(!pItem)
  436.                 return false;
  437.  
  438.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  439.             {
  440.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  441.                 return false;
  442.             }
  443.  
  444.             if(!isInGuildArea(pPlayer))
  445.             {
  446.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  447.                 return false;
  448.             }
  449.  
  450.             SpawnObject(pPlayer, OBJECT_CRATE);
  451.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  452.  
  453.             return true;
  454.         }
  455. };
  456.  
  457. class A_Flag_Token : public ItemScript
  458. {
  459.     public:
  460.         A_Flag_Token() : ItemScript("A_Flag Token"){}
  461.  
  462.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  463.         {
  464.             if(!pPlayer)
  465.                 return false;
  466.  
  467.             if(!pItem)
  468.                 return false;
  469.  
  470.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  471.             {
  472.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  473.                 return false;
  474.             }
  475.  
  476.             if(!isInGuildArea(pPlayer))
  477.             {
  478.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  479.                 return false;
  480.             }
  481.  
  482.             SpawnObject(pPlayer, OBJECT_A_FLAG);
  483.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  484.  
  485.             return true;
  486.         }
  487. };
  488.  
  489. class H_Flag_Token : public ItemScript
  490. {
  491.     public:
  492.         H_Flag_Token() : ItemScript("H_Flag Token"){}
  493.  
  494.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  495.         {
  496.             if(!pPlayer)
  497.                 return false;
  498.  
  499.             if(!pItem)
  500.                 return false;
  501.  
  502.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  503.             {
  504.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  505.                 return false;
  506.             }
  507.  
  508.             if(!isInGuildArea(pPlayer))
  509.             {
  510.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  511.                 return false;
  512.             }
  513.  
  514.  
  515.             SpawnObject(pPlayer, OBJECT_H_FLAG);
  516.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  517.  
  518.             return true;
  519.         }
  520. };
  521.  
  522. class Chair_Token : public ItemScript
  523. {
  524.     public:
  525.         Chair_Token() : ItemScript("Chair Token"){}
  526.  
  527.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  528.         {
  529.             if(!pPlayer)
  530.                 return false;
  531.  
  532.             if(!pItem)
  533.                 return false;
  534.  
  535.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  536.             {
  537.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  538.                 return false;
  539.             }
  540.  
  541.             if(!isInGuildArea(pPlayer))
  542.             {
  543.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  544.                 return false;
  545.             }
  546.  
  547.             SpawnObject(pPlayer, OBJECT_CHAIR);
  548.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  549.  
  550.             return true;
  551.         }
  552. };
  553.  
  554. class Firepit_Token : public ItemScript
  555. {
  556.     public:
  557.         Firepit_Token() : ItemScript("Firepit Token"){}
  558.  
  559.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  560.         {
  561.             if(!pPlayer)
  562.                 return false;
  563.  
  564.             if(!pItem)
  565.                 return false;
  566.  
  567.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  568.             {
  569.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  570.                 return false;
  571.             }
  572.  
  573.             if(!isInGuildArea(pPlayer))
  574.             {
  575.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  576.                 return false;
  577.             }
  578.  
  579.             SpawnObject(pPlayer, OBJECT_FIREPIT);
  580.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  581.  
  582.             return true;
  583.         }
  584. };
  585.  
  586. class Vault_Token : public ItemScript
  587. {
  588.     public:
  589.         Vault_Token() : ItemScript("Vault Token"){}
  590.  
  591.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  592.         {
  593.             if(!pPlayer)
  594.                 return false;
  595.  
  596.             if(!pItem)
  597.                 return false;
  598.  
  599.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  600.             {
  601.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  602.                 return false;
  603.             }
  604.  
  605.             if(!isInGuildArea(pPlayer))
  606.             {
  607.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  608.                 return false;
  609.             }
  610.  
  611.             SpawnObject(pPlayer, OBJECT_GUILDVAULT);
  612.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  613.  
  614.             return true;
  615.         }
  616. };
  617.  
  618. class Barber_Token : public ItemScript
  619. {
  620.     public:
  621.         Barber_Token() : ItemScript("Barber Token"){}
  622.  
  623.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  624.         {
  625.             if(!pPlayer)
  626.                 return false;
  627.  
  628.             if(!pItem)
  629.                 return false;
  630.  
  631.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  632.             {
  633.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  634.                 return false;
  635.             }
  636.  
  637.             if(!isInGuildArea(pPlayer))
  638.             {
  639.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  640.                 return false;
  641.             }
  642.  
  643.             SpawnObject(pPlayer, OBJECT_BARBER_CHAIR);
  644.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  645.            
  646.             return true;
  647.         }
  648. };
  649.  
  650. class Cranberry_Token : public ItemScript
  651. {
  652.     public:
  653.         Cranberry_Token() : ItemScript("Cranberry Token"){}
  654.  
  655.         bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
  656.         {
  657.             if(!pPlayer)
  658.                 return false;
  659.  
  660.             if(!pItem)
  661.                 return false;
  662.  
  663.             if(!isPlayerGuildLeader(pPlayer) || !isGuildHouseOwner(pPlayer))
  664.             {
  665.                 pPlayer->GetSession()->SendNotification("You must own a guild house to use this item!");
  666.                 return false;
  667.             };
  668.  
  669.             if(!isInGuildArea(pPlayer))
  670.             {
  671.                 pPlayer->GetSession()->SendNotification("You are not in your guild area!");
  672.                 return false;
  673.             }
  674.  
  675.             SpawnObject(pPlayer, OBJECT_CRANBERRY_BUSH);
  676.             pPlayer->DestroyItemCount(pItem->GetEntry(), 1, true);
  677.  
  678.             return true;
  679.         }
  680. };
  681.  
  682. //token vendor
  683.  
  684. class Guild_Token_Vendor : public CreatureScript
  685. {
  686.     public:
  687.         Guild_Token_Vendor() : CreatureScript("Token Vendor"){}
  688.  
  689.         bool OnGossipHello(Player * pPlayer, Creature * pCreature)
  690.         {
  691.             if(!isPlayerGuildLeader(pPlayer))
  692.             {
  693.                 pPlayer->GetSession()->SendNotification("You must be a guildmaster!");
  694.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  695.                 return false;
  696.             }
  697.             if(isGuildHouseOwner(pPlayer))
  698.             {
  699.                 pPlayer->PlayerTalkClass->ClearMenus();
  700.                 pPlayer->ADD_GOSSIP_ITEM(4, "I would like to purchase Object Tokens!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_TRADE);
  701.                 pPlayer->ADD_GOSSIP_ITEM(3, "Nevermind.", GOSSIP_SENDER_MAIN, 2);
  702.                 pPlayer->PlayerTalkClass->SendGossipMenu(2, pCreature->GetGUID());
  703.                 //return true;
  704.             }
  705.             else
  706.             {
  707.                 pPlayer->GetSession()->SendNotification("You must own a guild house!");
  708.                 return false;
  709.             }
  710.             return true;
  711.         }
  712.  
  713.         bool OnGossipSelect(Player * pPlayer, Creature * pCreature, uint32 /*uiSender*/, uint32 uiAction)
  714.         {
  715.             switch(uiAction)
  716.             {
  717.                 case GOSSIP_ACTION_TRADE:
  718.                     pPlayer->GetSession()->SendListInventory(pCreature->GetGUID());
  719.                     break;
  720.                 case 2:
  721.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  722.                     break;
  723.             }
  724.             return true;
  725.         }
  726. };
  727.  
  728.  
  729. void AddSC_GuildHouse()
  730. {
  731.     new GuildHouse_NPC();
  732.     new Table_Token();
  733.     new Torch_Token();
  734.     new Mailbox_Token();
  735.     new Crate_Token();
  736.     new A_Flag_Token();
  737.     new H_Flag_Token();
  738.     new Chair_Token();
  739.     new Firepit_Token();
  740.     new Vault_Token();
  741.     new Barber_Token();
  742.     new Guild_Token_Vendor();
  743.     new Cranberry_Token();
  744. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement