diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-29 13:43:24 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-29 13:43:24 +0000 |
commit | 291ad04d5b5c4ab08d85eadde116f968cd579b77 (patch) | |
tree | e4dced5715a5d9792cfdc0455a6b3ee6d3116079 /src/being.cpp | |
parent | 3d404e743105bb9168c89e3451cf35d7d59120b1 (diff) | |
download | manaserv-291ad04d5b5c4ab08d85eadde116f968cd579b77.tar.gz manaserv-291ad04d5b5c4ab08d85eadde116f968cd579b77.tar.bz2 manaserv-291ad04d5b5c4ab08d85eadde116f968cd579b77.tar.xz manaserv-291ad04d5b5c4ab08d85eadde116f968cd579b77.zip |
Physically split the server into one tmwserv-acount program (account +
chat + database) and multiple tmwserv-game programs (selected with
respect to the maps). Cleaned the repository by moving server-specific
source files into dedicated directories.
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 93 |
1 files changed, 77 insertions, 16 deletions
diff --git a/src/being.cpp b/src/being.cpp index 1f57b0b2..6f8b7028 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -21,19 +21,9 @@ */ #include "being.h" - -#include "controller.h" - +#include "mapcomposite.h" #include "utils/logger.h" -void Being::update() -{ - if (mController) - mController->update();
-
- mHitsTaken.clear(); -}
-
void Being::damage(Damage damage)
{
int HPloss;
@@ -44,8 +34,79 @@ void Being::damage(Damage damage) mHitsTaken.push_back(HPloss);
LOG_DEBUG("Being " << getPublicID() << " got hit", 0);
}
-
-void Being::performAttack(MapComposite* map)
-{
- //Monster attack
-}
+ +void Being::performAttack(MapComposite* map) +{ + std::list<ObjectPtr> victimList; + std::list<Point> attackZone; + + Point attackPoint = getPosition(); + + unsigned char direction = getDirection(); + if (direction & UP) + { + attackPoint.y -= 32; + attackPoint.x -= 32; + attackZone.push_back(attackPoint); + attackPoint.x += 32; + attackZone.push_back(attackPoint); + attackPoint.x += 32; + attackZone.push_back(attackPoint); + } + else if (direction & RIGHT) + { + attackPoint.x += 32; + attackPoint.y -= 32; + attackZone.push_back(attackPoint); + attackPoint.y += 32; + attackZone.push_back(attackPoint); + attackPoint.y += 32; + attackZone.push_back(attackPoint); + } + else if (direction & DOWN) + { + attackPoint.y += 32; + attackPoint.x -= 32; + attackZone.push_back(attackPoint); + attackPoint.x += 32; + attackZone.push_back(attackPoint); + attackPoint.x += 32; + attackZone.push_back(attackPoint); + } + else { + attackPoint.x -= 32; + attackPoint.y -= 32; + attackZone.push_back(attackPoint); + attackPoint.y += 32; + attackZone.push_back(attackPoint); + attackPoint.y += 32; + attackZone.push_back(attackPoint); + } + + attackZone.push_back(attackPoint); // point player is facing + + // get enemies to hurt + for (std::list<Point>::iterator i = attackZone.begin(), + i_end = attackZone.end(); i != i_end; ++i) + { + std::list<ObjectPtr> newVictimList = map->getObjectsOnTile((*i)); + victimList.splice(victimList.end(), newVictimList); + } + + // apply damage to victims + Damage damage; + + /* TODO: calculate real attack power and damage properties based on + * character equipment and stats + */ + damage = 1; + + for (std::list<ObjectPtr>::iterator i = victimList.begin(), + i_end = victimList.end(); i != i_end; ++i) + { + if ((*i)->getType() == OBJECT_PLAYER || (*i)->getType() == OBJECT_MONSTER) + { + static_cast<Being*>(&**i)->damage(damage); + } + } +} |