Advertisement
nevadies

Untitled

Oct 2nd, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.81 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include "pvp_system.h"
  3. #include "Language.h"
  4.  
  5. /* Queue */
  6. vector<const char*> queueList, queueListTwo;
  7. const char * playerOne;
  8. const char * playerTwo;
  9. const char * victimname;
  10. const char * killername;
  11. string PlayerOneName, PlayerTwoName;
  12. const uint32 _points = 10;
  13. const uint32 _rating = 50;
  14. /* Activity */
  15. bool isMatchActive = false;
  16. bool canMatchQueue = true;
  17. bool canstart = true;
  18. int playerOneMap, playerTwoMap;
  19. float playerOnePosX, playerOnePosY, playerOnePosZ, playerOnePosO; //Old player 1 coordinates.
  20. float playerTwoPosX, playerTwoPosY, playerTwoPosZ, playerTwoPosO; //Old player 2 coordinates.
  21.  
  22. class npc_onevone : public CreatureScript
  23. {
  24. public: npc_onevone() : CreatureScript("npc_onevone"){}
  25.  
  26. bool OnGossipHello(Player * player, Creature* creature)
  27. {
  28. if(player->isInCombat())
  29. {
  30. creature->MonsterWhisper("Stop fighting before you talk to me!", player->GetGUID());
  31. return false;
  32. }
  33. if(!sPvPSystemMgr->GetGUIDFromPlayer(player->GetGUID())) // Yes, after a restart, even if you already are registered in the system
  34. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Join the league.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
  35. else
  36. {
  37. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "I am ready to fight!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
  38. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Spoils of War(Rewards)", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
  39. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "Scoreboard", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4);
  40. }
  41. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "...Nevermind", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+5);
  42. player->PlayerTalkClass->SendGossipMenu(1, creature->GetGUID());
  43. return true;
  44. }
  45.  
  46. bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 actions)
  47. {
  48. player->PlayerTalkClass->ClearMenus();
  49. if(sender != GOSSIP_SENDER_MAIN)
  50. return false;
  51.  
  52. switch (actions)
  53. {
  54. case GOSSIP_ACTION_INFO_DEF+1:
  55. for(vector<const char*>::const_iterator itr = queueList.begin(); itr != queueList.end(); ++itr)
  56. {
  57. if(player->GetName() == *itr)
  58. {
  59. ChatHandler(player->GetSession()).PSendSysMessage("You're already in the queue!");
  60. player->PlayerTalkClass->SendCloseGossip();
  61. return false;
  62. }
  63.  
  64. for(vector<const char*>::const_iterator _itr = queueListTwo.begin(); _itr != queueListTwo.end(); ++_itr)
  65. {
  66. if(player->GetName() == *itr || player->GetName() == *_itr)
  67. {
  68. ChatHandler(player->GetSession()).PSendSysMessage("You're already in the queue!");
  69. player->PlayerTalkClass->SendCloseGossip();
  70. return false;
  71. }
  72. }
  73. }
  74.  
  75. if(queueList.size() == 0)
  76. {
  77. queueList.push_back(player->GetName().c_str()); // This is a list not a db
  78. ChatHandler(player->GetSession()).PSendSysMessage("Added you to the queue.");
  79. player->PlayerTalkClass->SendCloseGossip();
  80. return false;
  81. }
  82. else if (queueListTwo.size() == 0)
  83. {
  84. queueListTwo.push_back(player->GetName().c_str());
  85. ChatHandler(player->GetSession()).PSendSysMessage("Added you to the second queue.");
  86. player->PlayerTalkClass->SendCloseGossip();
  87. return false;
  88. }
  89.  
  90. if(queueList.size() > queueListTwo.size())
  91. queueListTwo.push_back(player->GetName().c_str());
  92. else
  93. queueList.push_back(player->GetName().c_str());
  94.  
  95. if(isMatchActive)
  96. ChatHandler(player->GetSession()).PSendSysMessage("Added you to the queue. A match is already active, so you'll have to wait.");
  97. else
  98. ChatHandler(player->GetSession()).PSendSysMessage("Added you to the queue. No matches are active at this time.");
  99. player->PlayerTalkClass->SendCloseGossip();
  100. break;
  101.  
  102. case GOSSIP_ACTION_INFO_DEF+2:
  103. pvpSystem = new PvPSystem(player, player->GetName(), 0, 0);
  104. sPvPSystemMgr->SaveToList(pvpSystem);
  105. ChatHandler(player->GetSession()).PSendSysMessage("You have registered in the 1v1 League!");
  106. player->PlayerTalkClass->SendCloseGossip();
  107. break;
  108.  
  109. case GOSSIP_ACTION_INFO_DEF+3:
  110. /*
  111. Based on the player's rating, you can easily have rewards by doing:
  112. */
  113. pvpSystem = new PvPSystem();
  114. if(pvpSystem->Rating() >= 1000)
  115. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_VENDOR, "Access Rating 1000+ Rewards", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+6);
  116. else if (pvpSystem->Rating() >= 2500)
  117. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_VENDOR, "Access Rating 2500+ Rewards", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+7);
  118. else
  119. {
  120. player->GetSession()->SendAreaTriggerMessage("Your rating isn't high enough!");
  121. player->PlayerTalkClass->SendCloseGossip();
  122. }
  123. player->PlayerTalkClass->SendGossipMenu(1, creature->GetGUID());
  124. break;
  125.  
  126. case GOSSIP_ACTION_INFO_DEF+4:
  127. pvpSystem = new PvPSystem();
  128. pvpSystem->ShowScoreBoard(player);
  129. player->PlayerTalkClass->SendCloseGossip();
  130. break;
  131.  
  132. case GOSSIP_ACTION_INFO_DEF+5:
  133. creature->HandleEmoteCommand(EMOTE_ONESHOT_RUDE);
  134. player->PlayerTalkClass->SendCloseGossip();
  135. break;
  136.  
  137. case GOSSIP_ACTION_INFO_DEF+6: // Rating 1000+ Rewards
  138. break;
  139.  
  140. case GOSSIP_ACTION_INFO_DEF+7: // Rating 2500+ Rewards
  141. break;
  142. }
  143. return true;
  144. }
  145.  
  146. struct npc_onevoneAI : public ScriptedAI
  147. {
  148. uint32 m_AttackTimer;
  149. Player * _qPlayer;
  150. Player * _qPlayerTwo;
  151. npc_onevoneAI(Creature * c) : ScriptedAI(c)
  152. {
  153.  
  154.  
  155. }
  156.  
  157. void Reset()
  158. {
  159.  
  160. }
  161.  
  162. void UpdateAI(const uint32 diff)
  163. {
  164. if(!isMatchActive && canMatchQueue && queueList.size() > 0 && queueListTwo.size() > 0)
  165. {
  166. _qPlayer = sObjectAccessor->FindPlayerByName(queueList.front());
  167. _qPlayerTwo = sObjectAccessor->FindPlayerByName(queueListTwo.front());
  168.  
  169. if(_qPlayer && _qPlayerTwo)
  170. {
  171. playerOnePosX = _qPlayer->m_positionX;
  172. playerOnePosY = _qPlayer->m_positionY;
  173. playerOnePosZ = _qPlayer->m_positionZ;
  174. playerOnePosO = _qPlayer->GetOrientation();
  175. playerOneMap = _qPlayer->m_mapId;
  176. playerTwoPosX = _qPlayerTwo->m_positionX;
  177. playerTwoPosY = _qPlayerTwo->m_positionY;
  178. playerTwoPosZ = _qPlayerTwo->m_positionZ;
  179. playerTwoPosO = _qPlayerTwo->GetOrientation();
  180. playerTwoMap = _qPlayerTwo->m_mapId;
  181. PlayerOneName = _qPlayer->GetName();
  182. PlayerTwoName = _qPlayerTwo->GetName();
  183. _qPlayer->SetPhaseMask(2, true);
  184. _qPlayerTwo->SetPhaseMask(2, true);
  185. _qPlayer->TeleportTo(571, 5830.89f, 590.163f, 571.65f, 2.37108f); // Teleport Player One
  186. _qPlayerTwo->TeleportTo(571, 5723.53f, 623.611f, 571.553f, 5.59592f); // Teleport Player Two
  187. //_qPlayer->CastSpell(_qPlayer,27559,true);
  188. //_qPlayerTwo->CastSpell(_qPlayerTwo,27559,true);
  189. _qPlayer->SendDuelCountdown(3000);
  190. _qPlayerTwo->SendDuelCountdown(3000);
  191. m_AttackTimer = 3000;
  192. //ChatHandler(_qPlayer->GetSession()).PSendSysMessage(7525, PlayerTwoName);
  193. //ChatHandler(_qPlayerTwo->GetSession()).PSendSysMessage(7525, PlayerOneName);
  194. //_qPlayer->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
  195. //_qPlayerTwo->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
  196. isMatchActive = true;
  197. canMatchQueue = false;
  198. queueList.erase(queueList.begin(), queueList.begin() + 1);
  199. queueListTwo.erase(queueListTwo.begin(), queueListTwo.begin() + 1);
  200. }
  201.  
  202. }
  203.  
  204.  
  205. if(canstart)
  206. {
  207. if(isMatchActive)
  208. {
  209. playerOne : _qPlayer->GetName(); // Retrieving players name for confirmation when killing the other player
  210. playerTwo : _qPlayerTwo->GetName(); // Retrieving players name for confirmation when killing the other player
  211. if (m_AttackTimer <= diff)
  212. {
  213. //_qPlayer->RemoveAura(27559);
  214. //_qPlayerTwo->RemoveAura(27559);
  215. canstart = false;
  216. _qPlayer = NULL;
  217. _qPlayerTwo = NULL;
  218. }
  219. else
  220. m_AttackTimer -= diff;
  221. }
  222. }
  223. }
  224. };
  225.  
  226. CreatureAI * GetAI(Creature * pCreature) const
  227. {
  228. return new npc_onevoneAI(pCreature);
  229. }
  230. private:
  231. PvPSystem * pvpSystem;
  232. };
  233.  
  234. class player_onevone : public PlayerScript
  235. {
  236. public:
  237. player_onevone() : PlayerScript("player_onevone"){}
  238.  
  239. void OnPVPKill(Player * killer, Player * victim)
  240. {
  241. if(isMatchActive && !canMatchQueue)
  242. {
  243. PvPSystem * pvpsystem = new PvPSystem();
  244. victimname : victim->GetName();
  245. killername : killer->GetName();
  246. pvpsystem->UpdateScore(killer->GetGUID());
  247. pvpsystem->UpdateRating(killer->GetGUID(), false);
  248. pvpsystem->UpdateRating(victim->GetGUID(), true);
  249. ChatHandler(killer->GetSession()).PSendSysMessage("Great 1v1! Your points increased by 10.");
  250. ChatHandler(victim->GetSession()).PSendSysMessage("|cffff0000[Arena Announcer]:|r Poor %s lost the battle.|r", victim->GetName().c_str());
  251. killer->ResurrectPlayer(100, false);
  252. victim->ResurrectPlayer(100, false);
  253. if(killer->GetName() == PlayerOneName){
  254. killer->TeleportTo(playerOneMap, playerOnePosX, playerOnePosY, playerOnePosZ, playerOnePosO);
  255. victim->TeleportTo(playerTwoMap, playerTwoPosX, playerTwoPosY, playerTwoPosZ, playerTwoPosO);
  256. }else if(victim->GetName() == PlayerOneName){
  257. victim->TeleportTo(playerOneMap, playerOnePosX, playerOnePosY, playerOnePosZ, playerOnePosO);
  258. killer->TeleportTo(playerTwoMap, playerTwoPosX, playerTwoPosY, playerTwoPosZ, playerTwoPosO);
  259. }else{
  260. ChatHandler(killer->GetSession()).PSendSysMessage("Something is wrong, you will both be teleported to the mall.");
  261. ChatHandler(victim->GetSession()).PSendSysMessage("Something is wrong, you will both be teleported to the mall.");
  262. victim->TeleportTo(230, 1380.61f, -822.44f, -92.72f, 4.752445f);
  263. killer->TeleportTo(230, 1380.61f, -822.44f, -92.72f, 4.752445f);
  264.  
  265. }
  266. killer->SetPhaseMask(1, true);
  267. victim->SetPhaseMask(1, true);
  268. PlayerOneName = "";
  269. PlayerTwoName = "";
  270. isMatchActive = false;
  271. canMatchQueue = true;
  272. canstart = true;
  273. playerOne = "";
  274. playerTwo = "";
  275. }
  276. }
  277.  
  278. void OnLogout(Player * player) // Player could possibly be in the queue.. will crash if this isn't dealt with
  279. {
  280. for(vector<const char*>::const_iterator itr = queueList.begin(); itr != queueList.end(); ++itr)
  281. {
  282. if(player->GetName() == *itr)
  283. {
  284. itr = queueList.erase(itr);
  285. playerOne = "";
  286. playerTwo = "";
  287. canMatchQueue = true;
  288. isMatchActive = false;
  289. return;
  290. }
  291. for(vector<const char*>::const_iterator itr = queueListTwo.begin(); itr != queueListTwo.end(); ++itr)
  292. {
  293. if(player->GetName() == *itr)
  294. {
  295. itr = queueListTwo.erase(itr);
  296. playerOne = "";
  297. playerTwo = "";
  298. canMatchQueue = true;
  299. isMatchActive = false;
  300. return;
  301. }
  302. }
  303. }
  304. }
  305. };
  306.  
  307. void AddSC_onevone()
  308. {
  309. new npc_onevone;
  310. new player_onevone;
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement