Example #1
0
//building the map
bool Game::handleSpawn(ENetPeer *peer, ENetPacket *packet) {
   StatePacket2 start(PKT_S2C_StartSpawn);
   bool p1 = sendPacket(peer, reinterpret_cast<uint8 *>(&start), sizeof(StatePacket2), CHL_S2C);
   printf("Spawning map\r\n");

   int playerId = 0;
   ClientInfo* playerInfo = 0;

   for(auto p : players) {
      if (p->getPeer() == peer) {
         playerInfo = p;
      }
      
      HeroSpawn spawn(p, playerId++);
      sendPacket(peer, spawn, CHL_S2C);
            
      PlayerInfo info(p);
      sendPacket(peer, info, CHL_S2C);

      p->getChampion()->getStats().setSummonerSpellEnabled(0, true);
      p->getChampion()->getStats().setSummonerSpellEnabled(1, true);
      
      // TODO: Recall slot
   }

   const std::map<uint32, Object*>& objects = map->getObjects();
 
   for(auto kv : objects) {
      Turret* t = dynamic_cast<Turret*>(kv.second);
      if(t) {
         TurretSpawn turretSpawn(t);
         sendPacket(peer, turretSpawn, CHL_S2C);
         continue;
      }
   
      LevelProp* lp = dynamic_cast<LevelProp*>(kv.second);
      if(lp) {
         LevelPropSpawn lpsPacket(lp);
         sendPacket(peer, lpsPacket, CHL_S2C);
      }
   }

   // Level props are just models, we need button-object minions to allow the client to interact with it
   if (playerInfo != 0 && playerInfo->getTeam() == TEAM_BLUE) {
      // Shop (blue side)
      MinionSpawn ms1(0xff10c6db);
      sendPacket(peer, ms1, CHL_S2C);
      SetHealth sh1(0xff10c6db);
      sendPacket(peer, sh1, CHL_S2C);
      
      // Vision for hardcoded objects
      // Top inhib
      MinionSpawn ms2(0xffd23c3e);
      sendPacket(peer, ms2, CHL_S2C);
      SetHealth sh2(0xffd23c3e);
      sendPacket(peer, sh2, CHL_S2C);
      
      // Mid inhib
      MinionSpawn ms3(0xff4a20f1);
      sendPacket(peer, ms3, CHL_S2C);
      SetHealth sh3(0xff4a20f1);
      sendPacket(peer, sh3, CHL_S2C);
      
      // Bottom inhib
      MinionSpawn ms4(0xff9303e1);
      sendPacket(peer, ms4, CHL_S2C);
      SetHealth sh4(0xff9303e1);
      sendPacket(peer, sh4, CHL_S2C);
      
      // Nexus
      MinionSpawn ms5(0xfff97db5);
      sendPacket(peer, ms5, CHL_S2C);
      SetHealth sh5(0xfff97db5);
      sendPacket(peer, sh5, CHL_S2C);
      
   } else if (playerInfo != 0 && playerInfo->getTeam() == TEAM_PURPLE) {
      // Shop (purple side)
      MinionSpawn ms1(0xffa6170e); 
      sendPacket(peer, ms1, CHL_S2C);
      SetHealth sh1(0xffa6170e);
      sendPacket(peer, sh1, CHL_S2C);
      
      // Vision for hardcoded objects
      // Top inhib
      MinionSpawn ms2(0xff6793d0);
      sendPacket(peer, ms2, CHL_S2C);
      SetHealth sh2(0xff6793d0);
      sendPacket(peer, sh2, CHL_S2C);
      
      // Mid inhib
      MinionSpawn ms3(0xffff8f1f);
      sendPacket(peer, ms3, CHL_S2C);
      SetHealth sh3(0xffff8f1f);
      sendPacket(peer, sh3, CHL_S2C);
      
      // Bottom inhib
      MinionSpawn ms4(0xff26ac0f); 
      sendPacket(peer, ms4, CHL_S2C);
      SetHealth sh4(0xff26ac0f);
      sendPacket(peer, sh4, CHL_S2C);
      
      // Nexus
      MinionSpawn ms5(0xfff02c0f);
      sendPacket(peer, ms5, CHL_S2C);
      SetHealth sh5(0xfff02c0f);
      sendPacket(peer, sh5, CHL_S2C);
   }

   StatePacket end(PKT_S2C_EndSpawn);
   bool p3 = sendPacket(peer, reinterpret_cast<uint8 *>(&end), sizeof(StatePacket), CHL_S2C);

   return true;
}