Changeset 11d21ee in network-game


Ignore:
Timestamp:
Jun 9, 2013, 9:30:32 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
ff2133a
Parents:
8c74150
Message:

When a player tries to attack someone, they will now move toward the target until they are in range and then start the actual attack

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r8c74150 r11d21ee  
    1717   this->timeLastUpdated = 0;
    1818   this->timeAttackStarted = 0;
     19   this->isChasing = false;
    1920   this->isAttacking = false;
    2021
     
    2425   this->attackType = ATTACK_NONE;
    2526   this->damage = 0;
     27   this->range = 0;
    2628   this->attackCooldown = 0;
    2729   this->team = 0;   // blue team by default
     
    4244   this->timeLastUpdated = p.timeLastUpdated;
    4345   this->timeAttackStarted = p.timeAttackStarted;
     46   this->isChasing = p.isChasing;
    4447   this->isAttacking = p.isAttacking;
    4548
     
    4952   this->attackType = p.attackType;
    5053   this->damage = p.damage;
     54   this->range = p.range;
    5155   this->attackCooldown = p.attackCooldown;
    5256   this->team = p.team;
     
    6569   this->timeLastUpdated = 0;
    6670   this->timeAttackStarted = 0;
     71   this->isChasing = false;
    6772   this->isAttacking = false;
    6873
     
    7277   this->attackType = ATTACK_NONE;
    7378   this->damage = 0;
     79   this->range = 0;
    7480   this->attackCooldown = 0;
    7581   this->team = 0;   // blue team by default
     
    100106         this->attackType = ATTACK_MELEE;
    101107         this->damage = 10;
     108         this->range = 30;
    102109         this->attackCooldown = 800;
    103110         break;
     
    107114         this->attackType = ATTACK_RANGED;
    108115         this->damage = 6;
     116         this->range = 100;
    109117         this->attackCooldown = 1000;
    110118         break;
  • common/Player.h

    r8c74150 r11d21ee  
    5959   unsigned long long timeLastUpdated;
    6060   unsigned long long timeAttackStarted;
     61   bool isChasing;
    6162   bool isAttacking;
    6263   int targetPlayer;
     
    6768   int attackType;
    6869   int damage;
     70   int range;
    6971   unsigned long long attackCooldown;
    7072   int team; // 0 is blue, 1 is red
  • server/server.cpp

    r8c74150 r11d21ee  
    145145         timeLastUpdated = curTime;
    146146
     147         map<unsigned int, Player>::iterator it;
     148
     149         // set targets for all chasing players (or make them attack if they're close enough)
     150         for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) {
     151            Player* p = &it->second;
     152
     153            if (p->isChasing) {
     154               p->target.x = mapPlayers[p->targetPlayer].pos.x;
     155               p->target.y = mapPlayers[p->targetPlayer].pos.y;
     156
     157               if (posDistance(p->pos, p->target.toFloat()) <= p->range) {
     158                  p->target.x = p->pos.x;
     159                  p->target.y = p->pos.y;
     160
     161                  p->isChasing = false;
     162                  p->isAttacking = true;
     163                  p->timeAttackStarted = getCurrentMillis();
     164               }
     165            }
     166         }
     167
    147168         // move all players
    148169         // maybe put this in a separate method
    149          map<unsigned int, Player>::iterator it;
    150170         FLOAT_POSITION oldPos;
    151171         bool broadcastMove = false;
     
    778798
    779799         Player* source = &mapPlayers[id];
    780          source->timeAttackStarted = getCurrentMillis();
    781800         source->targetPlayer = targetId;
    782          source->isAttacking = true;
    783 
     801         source->isChasing = true;
     802
     803         // this is irrelevant since the client doesn't even listen for START_ATTACK messages
     804         // actually, the client should not ignore this and should instead perform the same movement
     805         // algorithm on its end (following the target player until in range) that the server does.
     806         // Once the attacker is in range, the client should stop movement and wait for messages
     807         // from the server
    784808         serverMsg.type = MSG_TYPE_START_ATTACK;
    785809         memcpy(serverMsg.buffer, &id, 4);
Note: See TracChangeset for help on using the changeset viewer.