Changeset 8795a38 in network-game for server/server.cpp


Ignore:
Timestamp:
Jun 9, 2013, 7:27:52 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
8c74150
Parents:
fbcfc35
Message:

Fix a bug where a projectile deals damage to the wrong player when it reaches its target

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    rfbcfc35 r8795a38  
    325325            if (it->second.isAttacking && it->second.timeAttackStarted+it->second.attackCooldown <= getCurrentMillis()) {
    326326               it->second.isAttacking = false;
     327               cout << "Attack animation is complete" << endl;
    327328
    328329               //send everyone an ATTACK message
     
    355356                  mapProjectiles[proj.id] = proj;
    356357
     358                  int x = it->second.pos.x;
     359                  int y = it->second.pos.y;
     360
    357361                  serverMsg.type = MSG_TYPE_PROJECTILE;
    358                   memcpy(serverMsg.buffer, &it->second.pos.x, 4);
    359                   memcpy(serverMsg.buffer+4, &it->second.pos.y, 4);
    360                   memcpy(serverMsg.buffer+8, &it->second.targetPlayer, 4);
     362                  memcpy(serverMsg.buffer, &proj.id, 4);
     363                  memcpy(serverMsg.buffer+4, &x, 4);
     364                  memcpy(serverMsg.buffer+8, &y, 4);
     365                  memcpy(serverMsg.buffer+12, &it->second.targetPlayer, 4);
    361366               }else {
    362367                  cout << "Invalid attack type: " << it->second.attackType << endl;
     
    389394
    390395               // send a PLAYER message after dealing damage
    391                Player* target = &mapPlayers[it->second.targetPlayer];
     396               Player* target = &mapPlayers[itProj->second.target];
    392397
    393398               target->health -= itProj->second.damage;
     
    775780         source->timeAttackStarted = getCurrentMillis();
    776781         source->targetPlayer = targetId;
     782         source->isAttacking = true;
    777783
    778784         serverMsg.type = MSG_TYPE_START_ATTACK;
Note: See TracChangeset for help on using the changeset viewer.