Changeset 483a2cb in network-game


Ignore:
Timestamp:
Dec 22, 2013, 2:29:05 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
1d96513
Parents:
b8abc90
Message:

Melee attacks and dying work in individual games

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    rb8abc90 r483a2cb  
    235235            cout << "moving player" << endl;
    236236            bool broadcastMove = false;
     237
     238            // xompute playersInGame here
    237239
    238240            // move player and perform associated tasks
     
    426428
    427429            // check if the player's attack animation is complete
    428             if (it->second->isAttacking && it->second->timeAttackStarted+it->second->attackCooldown <= getCurrentMillis())
     430            if (p->isAttacking && p->timeAttackStarted+p->attackCooldown <= getCurrentMillis())
    429431            {
    430                it->second->isAttacking = false;
     432               p->isAttacking = false;
    431433               cout << "Attack animation is complete" << endl;
    432434
     
    435437
    436438               serverMsg.type = MSG_TYPE_ATTACK;
    437                memcpy(serverMsg.buffer, &it->second->id, 4);
    438                memcpy(serverMsg.buffer+4, &it->second->targetPlayer, 4);
    439 
     439               memcpy(serverMsg.buffer, &p->id, 4);
     440               memcpy(serverMsg.buffer+4, &p->targetPlayer, 4);
     441
     442               map<unsigned int, Player*>& playersInGame = p->currentGame->getPlayers();
    440443               map<unsigned int, Player*>::iterator it2;
    441                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
     444               for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
    442445               {
    443446                  if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     
    445448               }
    446449
    447                if (it->second->attackType == Player::ATTACK_MELEE)
     450               if (p->attackType == Player::ATTACK_MELEE)
    448451               {
    449452                  cout << "Melee attack" << endl;
    450453
    451                   Player* target = mapPlayers[it->second->targetPlayer];
    452                   damagePlayer(target, it->second->damage);
     454                  Player* target = playersInGame[p->targetPlayer];
     455                  damagePlayer(target, p->damage);
    453456
    454457                  if (target->isDead)
     
    461464
    462465                     if (flagType != WorldMap::OBJECT_NONE) {
    463                         addObjectToMap(flagType, target->pos.x, target->pos.y, gameMap, mapPlayers, msgProcessor, sock, outputLog);
     466                        addObjectToMap(flagType, target->pos.x, target->pos.y, p->currentGame->getMap(), playersInGame, msgProcessor, sock, outputLog);
    464467                     }
    465468                  }
     
    468471                  target->serialize(serverMsg.buffer);
    469472               }
    470                else if (it->second->attackType == Player::ATTACK_RANGED)
     473               else if (p->attackType == Player::ATTACK_RANGED)
    471474               {
    472475                  cout << "Ranged attack" << endl;
    473476
    474                   Projectile proj(it->second->pos.x, it->second->pos.y, it->second->targetPlayer, it->second->damage);
     477                  Projectile proj(p->pos.x, p->pos.y, p->targetPlayer, p->damage);
    475478                  proj.id = unusedProjectileId;
    476479                  updateUnusedProjectileId(unusedProjectileId, mapProjectiles);
     
    491494               // broadcast either a PLAYER or PROJECTILE message
    492495               cout << "Broadcasting player or projectile message" << endl;
    493                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
     496               for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
    494497               {
    495498                  if (msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     
    503506
    504507         // move all projectiles
     508         // see if this can be moved inside the game class
    505509         map<unsigned int, Projectile>::iterator itProj;
    506510         for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++)
Note: See TracChangeset for help on using the changeset viewer.