From f494a0e08ada527827fe41c7d98e2791f915ab40 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 14 Aug 2016 22:25:15 +0300 Subject: Cast skill depend on selected cast type. --- src/actions/commands.cpp | 6 +- src/gui/windows/skilldialog.cpp | 256 ++++++++++++++++++++++++++++++++++++++-- src/gui/windows/skilldialog.h | 27 ++++- 3 files changed, 275 insertions(+), 14 deletions(-) diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 98a66df0e..1016ee6cb 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -1143,7 +1143,8 @@ impHandler(skill) AutoTarget_true, level, false, - ""); + "", + CastType::Default); } else { @@ -1151,7 +1152,8 @@ impHandler(skill) AutoTarget_true, level, true, - text); + text, + CastType::Default); } return true; } diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index 2904ea525..db58686cd 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -178,7 +178,8 @@ void SkillDialog::action(const ActionEvent &event) fromBool(config.getBoolValue("skillAutotarget"), AutoTarget), info->customSelectedLevel, info->useTextParameter, - std::string()); + std::string(), + info->customCastType); } } else if (eventId == "close") @@ -626,14 +627,18 @@ void SkillDialog::useItem(const int itemId, return; const SkillInfo *const info = (*it).second; - if (data.empty()) + CastType castType = CastType::Default; + if (!data.empty()) { - useSkill(info, autoTarget, level, false, std::string()); - } - else if (data.size() > 1) - { - + // +++ read only cast type from data + castType = static_cast(atoi(data.c_str())); } + useSkill(info, + autoTarget, + level, + false, + std::string(), + castType); } void SkillDialog::updateTabSelection() @@ -745,23 +750,28 @@ void SkillDialog::useSkill(const int skillId, const AutoTarget autoTarget, int level, const bool withText, - const std::string &text) + const std::string &text, + CastTypeT castType) { SkillInfo *const info = skillDialog->getSkill(skillId); if (!info) return; + if (castType == CastType::Default) + castType = info->customCastType; useSkill(info, autoTarget, level, withText, - text); + text, + castType); } void SkillDialog::useSkill(const SkillInfo *const info, const AutoTarget autoTarget, int level, const bool withText, - const std::string &text) + const std::string &text, + const CastTypeT castType) { if (!info || !localPlayer) return; @@ -775,6 +785,231 @@ void SkillDialog::useSkill(const SkillInfo *const info, if (!cmd.empty()) SpellManager::invokeCommand(cmd, localPlayer->getTarget()); } + switch (castType) + { + default: + case CastType::Default: + useSkillDefault(info, + autoTarget, + level, + withText, + text); + break; + case CastType::Target: + { + const Being *const being = localPlayer->getTarget(); + useSkillTarget(info, + autoTarget, + level, + withText, + text, + being); + break; + } + case CastType::Position: + { + int x = 0; + int y = 0; + viewport->getMouseTile(x, y); + useSkillPosition(info, + level, + withText, + text, + x, + y); + break; + } + case CastType::Self: + // +++ probably need call useSkillSelf + useSkillTarget(info, + autoTarget, + level, + withText, + text, + localPlayer); + break; + } +} + +void SkillDialog::useSkillTarget(const SkillInfo *const info, + const AutoTarget autoTarget, + int level, + const bool withText, + const std::string &text, + const Being *being) +{ + SkillType::SkillType type = info->type; + if ((type & SkillType::Attack) != 0) + { + if (!being && autoTarget == AutoTarget_true) + { + being = localPlayer->setNewTarget(ActorType::Monster, + AllowSort_true); + } + if (being) + { + skillHandler->useBeing(info->id, + level, + being->getId()); + } + } + else if ((type & SkillType::Support) != 0) + { + if (!being) + being = localPlayer; + if (being) + { + skillHandler->useBeing(info->id, + level, + being->getId()); + } + } + else if ((type & SkillType::Self) != 0) + { + skillHandler->useBeing(info->id, + level, + localPlayer->getId()); + } + else if ((type & SkillType::Ground) != 0) + { + if (!being) + return; + const int x = being->getTileX(); + const int y = being->getTileY(); + if (info->useTextParameter) + { + if (withText) + { + skillHandler->usePos(info->id, + level, + x, y, + text); + } + else + { + const SkillData *data = info->getData1(level); + textSkillListener.setSkill(info->id, + x, + y, + level); + TextDialog *const dialog = CREATEWIDGETR(TextDialog, + // TRANSLATORS: text skill dialog header + strprintf(_("Add text to skill %s"), + data->name.c_str()), + // TRANSLATORS: text skill dialog field + _("Text: ")); + dialog->setModal(Modal_true); + textSkillListener.setDialog(dialog); + dialog->setActionEventId("ok"); + dialog->addActionListener(&textSkillListener); + } + } + else + { + skillHandler->usePos(info->id, + level, + x, y); + } + } + else if ((type & SkillType::TargetTrap) != 0) + { + // for now unused + } + else if (type == SkillType::Unknown || + type == SkillType::Unused) + { + // unknown / unused + } + else + { + reportAlways("Unsupported skill type: %d", type); + } +} + +void SkillDialog::useSkillPosition(const SkillInfo *const info, + int level, + const bool withText, + const std::string &text, + const int x, + const int y) +{ + SkillType::SkillType type = info->type; + if ((type & SkillType::Ground) != 0) + { + if (info->useTextParameter) + { + if (withText) + { + skillHandler->usePos(info->id, + level, + x, y, + text); + } + else + { + const SkillData *data = info->getData1(level); + textSkillListener.setSkill(info->id, + x, + y, + level); + TextDialog *const dialog = CREATEWIDGETR(TextDialog, + // TRANSLATORS: text skill dialog header + strprintf(_("Add text to skill %s"), + data->name.c_str()), + // TRANSLATORS: text skill dialog field + _("Text: ")); + dialog->setModal(Modal_true); + textSkillListener.setDialog(dialog); + dialog->setActionEventId("ok"); + dialog->addActionListener(&textSkillListener); + } + } + else + { + skillHandler->usePos(info->id, + level, + x, y); + } + } + else if ((type & SkillType::Support) != 0) + { + // wrong type + skillHandler->useBeing(info->id, + level, + localPlayer->getId()); + } + else if ((type & SkillType::Self) != 0) + { + skillHandler->useBeing(info->id, + level, + localPlayer->getId()); + } + else if ((type & SkillType::Attack) != 0) + { + // do nothing + // +++ probably need select some target on x,y position? + } + else if ((type & SkillType::TargetTrap) != 0) + { + // for now unused + } + else if (type == SkillType::Unknown || + type == SkillType::Unused) + { + // unknown / unused + } + else + { + reportAlways("Unsupported skill type: %d", type); + } +} + +void SkillDialog::useSkillDefault(const SkillInfo *const info, + const AutoTarget autoTarget, + int level, + const bool withText, + const std::string &text) +{ SkillType::SkillType type = info->type; if ((type & SkillType::Attack) != 0) { @@ -825,6 +1060,7 @@ void SkillDialog::useSkill(const SkillInfo *const info, } else { + const SkillData *data = info->getData1(level); textSkillListener.setSkill(info->id, x, y, diff --git a/src/gui/windows/skilldialog.h b/src/gui/windows/skilldialog.h index 79c3ecc9c..59981c403 100644 --- a/src/gui/windows/skilldialog.h +++ b/src/gui/windows/skilldialog.h @@ -37,6 +37,7 @@ #include "utils/xml.h" +class Being; class Button; class Label; class SkillModel; @@ -144,13 +145,15 @@ class SkillDialog final : public Window, const AutoTarget autoTarget, int level, const bool withText, - const std::string &text); + const std::string &text, + CastTypeT castType); static void useSkill(const SkillInfo *const info, const AutoTarget autoTarget, int level, const bool withText, - const std::string &text); + const std::string &text, + const CastTypeT castType); SkillData *getSkillData(const int id) const; @@ -164,6 +167,26 @@ class SkillDialog final : public Window, const CastTypeT type); private: + static void useSkillDefault(const SkillInfo *const info, + const AutoTarget autoTarget, + int level, + const bool withText, + const std::string &text); + + static void useSkillTarget(const SkillInfo *const info, + const AutoTarget autoTarget, + int level, + const bool withText, + const std::string &text, + const Being *being); + + static void useSkillPosition(const SkillInfo *const info, + int level, + const bool withText, + const std::string &text, + const int x, + const int y); + void addSkillDuration(SkillInfo *const skill); SkillInfo *loadSkill(XmlNodePtr node, -- cgit v1.2.3-70-g09d2