From 81a034132a16644a45ceb1d8e1ef0800cb794c71 Mon Sep 17 00:00:00 2001 From: staphen Date: Sat, 17 Jun 2023 22:00:32 -0400 Subject: [PATCH] Find valid target when casting scroll from inventory --- Source/items.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index bd3688a44..7fc4c77f4 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4087,9 +4087,14 @@ void UseItem(size_t pnum, item_misc_id mid, SpellID spellID, int spellFrom) prepareSpellID = spellID; } else { const int spellLevel = player.GetSpellLevel(spellID); - // Use CMD_SPELLXY, because tile coords aren't used anyway and it's the same behavior as normal casting + // Find a valid target for the spell because tile coords + // will be validated when processing the network message + Point target = cursPosition; + if (!InDungeonBounds(target)) + target = player.position.future + Displacement(player._pdir); + // Use CMD_SPELLXY because it's the same behavior as normal casting assert(IsValidSpellFrom(spellFrom)); - NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast(spellID), static_cast(SpellType::Scroll), spellLevel, static_cast(spellFrom)); + NetSendCmdLocParam4(true, CMD_SPELLXY, target, static_cast(spellID), static_cast(SpellType::Scroll), spellLevel, static_cast(spellFrom)); } break; case IMISC_BOOK: {