From 16b5c64933bf29d8e56e0d989ebab18ddae143a8 Mon Sep 17 00:00:00 2001 From: Joseph Botosh Date: Tue, 17 Feb 2015 21:47:01 +0200 Subject: Add key to heal most damaged player --- src/actions/actions.cpp | 15 +++++++++++++++ src/actions/actions.h | 1 + src/actormanager.cpp | 34 ++++++++++++++++++++++++++++++++++ src/actormanager.h | 5 +++++ src/input/inputaction.h | 1 + src/input/inputactionmap.h | 5 +++++ src/input/pages/other.cpp | 6 ++++++ 7 files changed, 67 insertions(+) (limited to 'src') diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index 1e70a6540..965702539 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -512,6 +512,21 @@ impHandler(heal) return false; } +impHandler0(healmd) +{ + if (actorManager) + { + Being *target = actorManager->findMostDamagedPlayer(); + if (target) + actorManager->heal(target); + + if (Game::instance()) + Game::instance()->setValidSpeed(); + return true; + } + return false; +} + impHandler0(itenplz) { if (actorManager) diff --git a/src/actions/actions.h b/src/actions/actions.h index 17b4900a0..2b32545da 100644 --- a/src/actions/actions.h +++ b/src/actions/actions.h @@ -42,6 +42,7 @@ namespace Actions decHandler(dropItemIdAll); decHandler(dropItemInvAll); decHandler(heal); + decHandler(healmd); decHandler(itenplz); decHandler(setHome); decHandler(magicAttack); diff --git a/src/actormanager.cpp b/src/actormanager.cpp index ec9ec41ba..fb999ac68 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -1280,6 +1280,40 @@ void ActorManager::heal(const Being *const target) const } } +Being* ActorManager::findMostDamagedPlayer() const +{ + if (!localPlayer) + return nullptr; + + int maxDamageTaken = 0; + Being *target = nullptr; + + for_actors + { + if ((*it)->getType() != ActorType::Player) + continue; + + Being *const being = static_cast(*it); + + if ((!being) || (!being->isAlive()) || // don't heal dead + (player_relations.getRelation(being->getName()) == + PlayerRelation::ENEMY2) || // don't heal enemy + (localPlayer == being)) // don't heal self + { + continue; + } + + + if (being->getDamageTaken() > maxDamageTaken) + { + maxDamageTaken = being->getDamageTaken(); + target = being; + } + } + + return target; +} + void ActorManager::itenplz() const { if (!localPlayer || !chatWindow || !localPlayer->isAlive() diff --git a/src/actormanager.h b/src/actormanager.h index c3fc8d195..411129e3b 100644 --- a/src/actormanager.h +++ b/src/actormanager.h @@ -172,6 +172,11 @@ class ActorManager final: public ConfigListener const ActorType::Type &type = ActorType::Unknown) const A_WARN_UNUSED; + /** + * Finds most damaged player, non-enemy and alive + */ + Being *findMostDamagedPlayer() const A_WARN_UNUSED; + /** * Heal all players in distance. * diff --git a/src/input/inputaction.h b/src/input/inputaction.h index 9bc25f49d..8ce40ffe2 100644 --- a/src/input/inputaction.h +++ b/src/input/inputaction.h @@ -536,6 +536,7 @@ namespace InputAction CHAT_GUILD_TAB, DROP_CLEAR, WINDOW_CART, + HEAL_MOST_DAMAGED, TOTAL }; } // namespace InputAction diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index 013efa81f..57cd4d7fe 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -3974,6 +3974,11 @@ static const InputActionData inputActionData[InputAction::TOTAL] = { InputCondition::SHORTCUT0, "cart|opencart", false}, + {"keyMagicHealMostDamaged", + defaultAction(&Actions::healmd), + InputCondition::GAME | InputCondition::VALIDSPEED, + "healmd|saveass", + false}, }; #undef defaultAction diff --git a/src/input/pages/other.cpp b/src/input/pages/other.cpp index 92de50f58..98714bd9a 100644 --- a/src/input/pages/other.cpp +++ b/src/input/pages/other.cpp @@ -145,6 +145,12 @@ SetupActionData setupActionDataOther[] = InputAction::MAGIC_INMA1, "", }, + { + // TRANSLATORS: input action name + N_("Heal the most injured player"), + InputAction::HEAL_MOST_DAMAGED, + "", + }, { // TRANSLATORS: input action name N_("Use #itenplz spell"), -- cgit v1.2.3-60-g2f50