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: {