midoking

battle

Feb 18th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.39 KB | None | 0 0
  1. void CityBattle::onHordeCaptureEnemyBase(Player* player)
  2. {
  3.     // if eastern kingdoms (alliance teritory) and zone Ironforge and horde character [capture]
  4.     if (player->GetMapId() == 0 && player->GetZoneId() == 1519 && player->GetTeamId() == TEAM_HORDE)
  5.     {
  6.         GameObject* object = NULL;
  7.    
  8.         QueryResult resultObj = WorldDatabase.PQuery("SELECT `guid` FROM `gameobject` WHERE `id`='%u' AND `map`='0' LIMIT 1;", FLAG_ALLY);
  9.    
  10.         // if the flag exists and not already re-captured then go capture
  11.         if (!resultObj)
  12.         {
  13.             ChatHandler(player->GetSession()).PSendSysMessage("|cff00FF00The flag is already captured.|r");
  14.         }
  15.         else
  16.         {
  17.             // cant capture if your base is taken, first recap ur base then attack
  18.             if (sCityBattle->isHordeCaptured)
  19.             {
  20.                 ChatHandler(player->GetSession()).PSendSysMessage("You must recapture your base!");
  21.                 return; // skip
  22.             }
  23.  
  24.             uint32 flag_guid = resultObj->Fetch()[0].GetUInt32();
  25.    
  26.             if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(flag_guid))
  27.                 object = ChatHandler(player->GetSession()).GetObjectFromPlayerMapByDbGuid(flag_guid);
  28.    
  29.             if (!object)
  30.                 return;
  31.            
  32.             object->SetRespawnTime(0);                                 // not save respawn time
  33.             object->Delete();
  34.             object->DeleteFromDB();
  35.        
  36.             // get horde flag
  37.             GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(FLAG_HORDE);
  38.        
  39.             if (!objectInfo)
  40.                 return;
  41.        
  42.             if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
  43.                 return;
  44.        
  45.             // prepare spawn object
  46.             GameObject* objectFlag = new GameObject;
  47.             Map* map = player->GetMap();
  48.             ObjectGuid::LowType guidLow = map->GenerateLowGuid<HighGuid::GameObject>();
  49.             Position pos(-8955.47f, 529.57f, 96.3554f, 3.75848f);
  50.             G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(3.75848f, 0.f, 0.f);
  51.            
  52.             // check if can create flag
  53.             if (!objectFlag->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), pos, rot, 0, GO_STATE_READY))
  54.             {
  55.                 delete objectFlag;
  56.                 return;
  57.             }
  58.        
  59.             // fill the gameobject data and save to the db
  60.             objectFlag->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
  61.             guidLow = objectFlag->GetSpawnId();
  62.        
  63.             // this will generate a new guid if the object is in an instance
  64.             /*if (!objectFlag->LoadGameObjectFromDB(guidLow, player->GetMap()))
  65.             {
  66.                 delete objectFlag;
  67.                 return; // skip everything
  68.             }*/
  69.        
  70.             sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
  71.    
  72.             SessionMap const& smap = sWorld->GetAllSessions();
  73.             for (SessionMap::const_iterator iter = smap.begin(); iter != smap.end(); ++iter)
  74.             {
  75.                 if (Player* pPlayer = iter->second->GetPlayer())
  76.                 {
  77.                     if (pPlayer->GetTeamId() == TEAM_HORDE)
  78.                     {
  79.                         ChatHandler(iter->second).PSendSysMessage(CAPTURE_IRONFORGE_HORDE_MSG, player->GetName().c_str());
  80.                         ChatHandler(iter->second).PSendSysMessage(HORDE_MSG_RATE_REWARD);
  81.                         sCityBattle->GiveRewardPlayer(pPlayer, capture_reward_mg, capture_reward_honor);
  82.                         sCityBattle->DiffRatesUpon(pPlayer, 1, false);
  83.                     }
  84.                     else // alliance
  85.                     {
  86.                         ChatHandler(iter->second).PSendSysMessage(CAPTURE_IRONFORGE_ALLY_MSG, player->GetName().c_str());
  87.                         ChatHandler(iter->second).PSendSysMessage(ALLY_MSG_RATE_LOSS);
  88.                         sCityBattle->DiffRatesUpon(pPlayer, 0, false);
  89.                     }
  90.                     pPlayer->PlayDirectSound(SOUND_PVP_FLAG_TAKEN_HORDE, pPlayer);
  91.                 }
  92.             }
  93.             sCityBattle->isHordeCaptured = false;
  94.             sCityBattle->isAllianceCaptured = true;
  95.             sCityBattle->ally_occupied_time = 0; // reset
  96.             sCityBattle->horde_occupied_time = 0; // reset
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment