Advertisement
yvoms

Fixed / Updated Bossevent

Mar 22nd, 2013
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.88 KB | None | 0 0
  1. /* Custom event system V2
  2. * Idea From Goliath
  3. * Some Help from Rochet2
  4. */
  5.  
  6. #include "ScriptPCH.h"
  7. #include "GroupMgr.h"
  8. #include "Group.h"
  9. #include "Language.h"
  10. //Simple MapID X,Y,Z,O
  11. const WorldLocation* eventLocation = new WorldLocation(xxx, x.xf, x.xf, x.xf, x.xf); // location of the event teleport
  12.  
  13. uint32 sGroupID = 0;
  14. bool CanJoin = false;
  15. bool AnnouncedFull = false;
  16. typedef std::map<Player*, WorldLocation*> playerLocationType;
  17. playerLocationType playerLocations;
  18.  
  19. static void endEvent(bool reward = false)
  20. {
  21.     Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
  22.     if(sGroup)
  23.         sGroup->Disband();
  24.     for(playerLocationType::iterator it = playerLocations.begin(); it != playerLocations.end(); ++it)
  25.     {
  26.         Player* player = it->first;
  27.         if(reward)
  28.         {
  29.             // player->AddItem(ItemID, Amount);
  30.             player->AddItem(xxx, x);
  31.             player->AddItem(xxx, x);
  32.             player->AddItem(xxx, x);
  33.         }
  34.         player->TeleportTo(*it->second);
  35.     }
  36.     playerLocations.clear();
  37.     AnnouncedFull = false;
  38.     CanJoin = false;
  39. }
  40.  
  41. static void removePlayer(Player* player, bool teleport = true)
  42. {
  43.     if(Group* group = player->GetGroup())
  44.     {
  45.         Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
  46.         if(sGroup)
  47.             if(group->GetDbStoreId() == sGroupID)
  48.                 sGroup->RemoveMember(player->GetGUID());
  49.     }
  50.     if(teleport && playerLocations.find(player) != playerLocations.end())
  51.     {
  52.         player->TeleportTo(*playerLocations[player]);
  53.         playerLocations.erase(player);
  54.     }
  55. }
  56.  
  57. static uint8 addPlayerToGroup(Player* player)
  58. {
  59.     ChatHandler* handler = &ChatHandler(player->GetSession());
  60.  
  61.     if (player->isInCombat())
  62.     {
  63.         handler->GetSession()->SendNotification("You are in combat");
  64.         return 1;
  65.     }
  66.  
  67.     if (player->isInFlight())
  68.     {
  69.         handler->GetSession()->SendNotification("You are in flight");
  70.         return 2;
  71.     }
  72.  
  73.     Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
  74.     if(sGroup)
  75.     {
  76.         if(Group* group = player->GetGroup())
  77.         {
  78.             if(group->GetDbStoreId() != sGroupID)
  79.                 group->RemoveMember(player->GetGUID());
  80.             else
  81.             {
  82.                 handler->GetSession()->SendNotification("You have already joined");
  83.                 return 3;
  84.             }
  85.         }
  86.         if(sGroup->IsFull())
  87.         {
  88.             handler->GetSession()->SendNotification("The group is already full");
  89.             return 4;
  90.         }
  91.  
  92.         sGroup->AddMember(player);
  93.         return 0;
  94.     }
  95.  
  96.     if(Group* group = player->GetGroup())
  97.         group->RemoveMember(player->GetGUID());
  98.  
  99.     sGroup = new Group();
  100.     sGroup->ConvertToRaid();
  101.     sGroup->Create(player);
  102.     sGroupMgr->AddGroup(sGroup);
  103.     sGroupID = sGroup->GetDbStoreId();
  104.     return 0;
  105. }
  106.  
  107. class custom_commandScript1 : public CommandScript
  108. {
  109. public:
  110.     custom_commandScript1() : CommandScript("custom_commandScript1") { }
  111.  
  112.     static bool HandleStartEvent(ChatHandler* handler, const char* args)
  113.     {
  114.         // End event
  115.         if(CanJoin)
  116.             endEvent();
  117.         CanJoin = true;
  118.         sWorld->SendServerMessage(SERVER_MSG_STRING, "You can now type .joinevent to be invited and teleported");
  119.         return true;
  120.     }
  121.     static bool HandleStopEvent(ChatHandler* handler, const char* args)
  122.     {
  123.         if(CanJoin)
  124.             endEvent();
  125.         return true;
  126.     }
  127.     static bool HandleJoinEvent(ChatHandler* handler, const char* args)
  128.     {
  129.         WorldSession* session = handler->GetSession();
  130.         Player* player = session->GetPlayer();
  131.         if(!CanJoin)
  132.             session->SendNotification("You can not join the event at this time");
  133.         else if(playerLocations.find(player) == playerLocations.end())
  134.         {
  135.             uint8 result = addPlayerToGroup(player);
  136.             if(!result)
  137.             {
  138.                 float x, y, z, o;
  139.                 player->GetPosition(x, y, z, o);
  140.                 playerLocations[player] = new WorldLocation(player->GetMapId(), x, y, z, o);
  141.                 player->TeleportTo(*eventLocation); // event area
  142.             }
  143.             else if(!AnnouncedFull && result == 4)
  144.             {
  145.                 sWorld->SendServerMessage(SERVER_MSG_STRING, "The event is now full");
  146.                 AnnouncedFull = true;
  147.             }
  148.         }
  149.         else
  150.         {
  151.             Group* sGroup = sGroupMgr->GetGroupByDbStoreId(sGroupID);
  152.             if(sGroup && !player->GetGroup() && !addPlayerToGroup(player))
  153.                 player->TeleportTo(*eventLocation); // event area
  154.         }
  155.         return true;
  156.     }
  157.  
  158.     ChatCommand* GetCommands() const
  159.     {
  160.         static ChatCommand CustomCommandscript1Table[] =
  161.         {
  162.             //In the database execute the row
  163.             { "startevent",          SEC_MODERATOR,         true,   &HandleStartEvent,        "", NULL },
  164.             { "stopevent",          SEC_MODERATOR,         true,   &HandleStopEvent,        "", NULL },
  165.             { "joinevent",          SEC_PLAYER,         false,   &HandleJoinEvent,        "", NULL },
  166.             { NULL,             0,                  false,  NULL,                            "", NULL }
  167.         };
  168.         return CustomCommandscript1Table;
  169.     }
  170. };
  171.  
  172. class custom_bossScript1 : public CreatureScript
  173. {
  174. public:
  175.     custom_bossScript1() : CreatureScript("custom_bossScript1") { }
  176.  
  177.     struct custom_bossScript1AI : public ScriptedAI
  178.     {
  179.         custom_bossScript1AI(Creature* creature) : ScriptedAI(creature) {}
  180.  
  181.         void JustDied(Unit* killer)
  182.         {
  183.             endEvent(true);
  184.         }
  185.  
  186.         /*
  187.         void Reset()
  188.         {
  189.         me->RestoreFaction();
  190.         }
  191.         */
  192.  
  193.         /*
  194.         void EnterCombat(Unit* who)
  195.         {
  196.  
  197.         }
  198.         */
  199.  
  200.         /*
  201.         void UpdateAI(const uint32 uiDiff)
  202.         {
  203.         if (!UpdateVictim())
  204.         return;
  205.         DoMeleeAttackIfReady();
  206.         }
  207.         */
  208.     };
  209.  
  210.     CreatureAI* GetAI(Creature* creature) const
  211.     {
  212.         return new custom_bossScript1AI(creature);
  213.     }
  214. };
  215.  
  216. class custom_playerScript1 : public PlayerScript
  217. {
  218. public:
  219.     custom_playerScript1() : PlayerScript("custom_playerScript1") { }
  220.  
  221.     void OnPlayerLogin(Player* player)
  222.     {
  223.         if(playerLocations.find(player) == playerLocations.end())
  224.             removePlayer(player);
  225.     }
  226.     void OnPlayerLogout(Player* player)
  227.     {
  228.         if(playerLocations.find(player) == playerLocations.end())
  229.             removePlayer(player);
  230.     }
  231.     void OnPlayerLeaveMap(Map* map, Player* player)
  232.     {
  233.         if(map && map->GetId() == eventLocation->GetMapId())
  234.             removePlayer(player);
  235.     }
  236. };
  237.  
  238. void AddSC_custom_eventScript1()
  239. {
  240.     new custom_commandScript1();
  241.     new custom_bossScript1();
  242.     new custom_playerScript1();
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement