summaryrefslogtreecommitdiff
path: root/src/map/npc.cpp
diff options
context:
space:
mode:
authorwushin <pasekei@gmail.com>2015-06-09 00:53:20 -0500
committermekolat <mekolat@users.noreply.github.com>2016-04-15 11:44:45 -0400
commita8640e1df61c06faf6edb89c5c4b9f025c0dff33 (patch)
tree8d5b33708f7d26e4f603e34a52ec2bc163e01986 /src/map/npc.cpp
parent8ac49c6058db5bf7f06662b8370b1d0fdf17d578 (diff)
downloadtmwa-a8640e1df61c06faf6edb89c5c4b9f025c0dff33.tar.gz
tmwa-a8640e1df61c06faf6edb89c5c4b9f025c0dff33.tar.bz2
tmwa-a8640e1df61c06faf6edb89c5c4b9f025c0dff33.tar.xz
tmwa-a8640e1df61c06faf6edb89c5c4b9f025c0dff33.zip
Magic -> Map Npcs
Diffstat (limited to 'src/map/npc.cpp')
-rw-r--r--src/map/npc.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index 1707c1c..0175916 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -146,6 +146,75 @@ dumb_ptr<npc_data> npc_name2id(NpcName name)
}
/*==========================================
+ * NPCを名前で探す
+ *------------------------------------------
+ */
+NpcEvent spell_name2id(RString name)
+{
+ return spells_by_name.get(name);
+}
+
+/*==========================================
+ * Spell Toknise
+ * Return a pair of strings, {spellname, parameter}
+ * Parameter may be empty.
+ *------------------------------------------
+ */
+static
+std::pair<XString, XString> magic_tokenise(XString src)
+{
+ auto seeker = std::find(src.begin(), src.end(), ' ');
+
+ if (seeker == src.end())
+ {
+ return {src, XString()};
+ }
+ else
+ {
+ XString rv1 = src.xislice_h(seeker);
+ ++seeker;
+
+ while (seeker != src.end() && *seeker == ' ')
+ ++seeker;
+
+ // Note: this very well could be empty
+ XString rv2 = src.xislice_t(seeker);
+ return {rv1, rv2};
+ }
+}
+
+/*==========================================
+ * NPC Spell
+ *------------------------------------------
+ */
+int magic_message(dumb_ptr<map_session_data> caster, XString source_invocation)
+{
+ if (pc_isdead(caster))
+ return 0;
+ if (bool(caster->status.option & Opt0::HIDE))
+ return 0;
+ if (caster->cast_tick > gettick())
+ return 0;
+
+ auto pair = magic_tokenise(source_invocation);
+ // Spell Cast
+ NpcName spell_name = stringish<NpcName>(pair.first);
+ RString spell_params = pair.second;
+
+ NpcEvent event = spell_name2id(spell_name);
+
+ if (event)
+ {
+ PRINTF("Cast: %s\n"_fmt, spell_name);
+ PRINTF("event: %s\n"_fmt, event);
+ PRINTF("Params: %s\n"_fmt, spell_params);
+ npc_event(caster, event, 0);
+ return 1;
+ }
+ return 0;
+}
+
+/*==========================================
* イベントキューのイベント処理
*------------------------------------------
*/