void Attacker::attack(Actor *attacker, Actor *target) { float calcDamage = 0; float damageTaken = 0; float weaponPower = 0; Attacker *att = attacker->getAttacker(); Destructible *dest = target->getDestructible(); ostringstream attack_msg; attack_msg << attacker->getName() << " attacks!"; if (attacker->getEquipment()) weaponPower = attacker->getEquipment()->getWeaponStr(); calcDamage = att->getPower() + weaponPower; // make sure target is destructible and alive if (target->getDestructible() && !target->getDestructible()->isDead()) { if ( (damageTaken = dest->takeDamage(target, calcDamage)) ) { attack_msg << " It does " << damageTaken << " points of damage."; engine.getGUI()->message(attack_msg.str(), TCODColor::darkerRed); } else { attack_msg << " It misses."; engine.getGUI()->message(attack_msg.str(), TCODColor::white); } } }
void PlayerAttacker::attack(Actor *attacker, Actor *target) { float calcDamage = 0; float damageTaken = 0; float weaponPower = 0; Attacker *att = attacker->getAttacker(); Destructible *dest = target->getDestructible(); ostringstream attack_msg; attack_msg << "You attack the " << target->getName(); if (attacker->getEquipment()) weaponPower = attacker->getEquipment()->getWeaponStr(); calcDamage = att->getPower() + weaponPower; if (target->getDestructible() && !target->getDestructible()->isDead()) { if ( (damageTaken = dest->takeDamage(target, calcDamage)) ) { attack_msg << " for " << damageTaken << " points of damage."; } else { attack_msg << ". You miss."; } } engine.getGUI()->message(attack_msg.str(), TCODColor::white); // did we kill it? if (target->isDead()) { attacker->addExp(target->getDestructible()->getExp()); } }
Destructible *Destructible::create(TCODZip &zip) { DestructibleType type = (DestructibleType)zip.getInt(); Destructible *destructible = NULL; switch(type) { case MONSTER : destructible = new MonsterDestructible(0,0,NULL,0); break; case PLAYER : destructible = new PlayerDestructible(0,0,NULL); break; } destructible->load(zip); return destructible; }
/** * @brief This function is called when a destructible item detects a non-pixel precise collision with this entity. * @param destructible the destructible item * @param collision_mode the collision mode that detected the event */ void Hookshot::notify_collision_with_destructible(Destructible& destructible, CollisionMode collision_mode) { if (destructible.is_obstacle_for(*this) && is_flying()) { if (destructible.can_explode()) { destructible.explode(); go_back(); } else { attach_to(destructible); } } }
/** * \brief This function is called when a destructible item detects a non-pixel perfect collision with this entity. * \param destructible the destructible item * \param collision_mode the collision mode that detected the event */ void Arrow::notify_collision_with_destructible( Destructible& destructible, CollisionMode collision_mode) { if (destructible.is_obstacle_for(*this) && is_flying()) { if (destructible.get_can_explode()) { destructible.explode(); remove_from_map(); } else { attach_to(destructible); } } }
/** * \copydoc MapEntity::is_destructible_obstacle */ bool CustomEntity::is_destructible_obstacle(Destructible& destructible) { const TraversableInfo& info = get_can_traverse_entity_info(destructible.get_type()); if (!info.is_empty()) { return !info.is_traversable(*this, destructible); } return Detector::is_destructible_obstacle(destructible); }
Destructible* Destructible::Create(TCODZip& zip) { destructible_type type = (destructible_type)zip.getInt(); Destructible* destructible = nullptr; switch(type) { case DESTRUCTIBLE_TYPE_ORC: { destructible = new OrcDestructible(0, 0); } break; case DESTRUCTIBLE_TYPE_PLAYER: { destructible = new PlayerDestructible(0, 0); } break; } destructible->Load(zip); return(destructible); }