From a8640e1df61c06faf6edb89c5c4b9f025c0dff33 Mon Sep 17 00:00:00 2001 From: wushin Date: Tue, 9 Jun 2015 00:53:20 -0500 Subject: Magic -> Map Npcs --- src/map/npc.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/map/npc.cpp') 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 @@ -145,6 +145,75 @@ dumb_ptr npc_name2id(NpcName name) return npcs_by_name.get(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 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 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(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; +} + /*========================================== * イベントキューのイベント処理 *------------------------------------------ -- cgit v1.2.3-70-g09d2