void CChar::Use_MoonGate( CItem * pItem ) { ADDTOCALLSTACK("CChar::Use_MoonGate"); ASSERT(pItem); CPointBase pt = pItem->m_itTelepad.m_pntMark; if ( pItem->IsType(IT_MOONGATE) ) { // RES_MOONGATES // What gate are we at ? size_t i = 0; size_t iCount = g_Cfg.m_MoonGates.GetCount(); for ( ; i < iCount; i++ ) { if ( GetTopPoint().GetDist(g_Cfg.m_MoonGates[i]) <= UO_MAP_VIEW_SIZE ) break; } // Set it's current destination based on the moon phases. // ensure iTrammelPhrase isn't smaller than iFeluccaPhase, to avoid uint underflow in next calculation unsigned int iTrammelPhase = g_World.GetMoonPhase(false) % iCount; unsigned int iFeluccaPhase = g_World.GetMoonPhase(true) % iCount; if ( iTrammelPhase < iFeluccaPhase ) iTrammelPhase += iCount; size_t iMoongateIndex = (i + (iTrammelPhase - iFeluccaPhase)) % iCount; ASSERT(g_Cfg.m_MoonGates.IsValidIndex(iMoongateIndex)); pt = g_Cfg.m_MoonGates[iMoongateIndex]; } if ( m_pNPC ) { if ( pItem->m_itTelepad.m_fPlayerOnly ) return; if ( m_pNPC->m_Brain == NPCBRAIN_GUARD ) // guards won't leave the guarded region { CRegionBase *pArea = pt.GetRegion(REGION_TYPE_MULTI|REGION_TYPE_AREA); if ( !pArea || !pArea->IsGuarded() ) return; } if ( Noto_IsCriminal() ) // criminals won't enter on guarded regions { CRegionBase *pArea = pt.GetRegion(REGION_TYPE_MULTI|REGION_TYPE_AREA); if ( !pArea || pArea->IsGuarded() ) return; } } bool bCheckAntiMagic = pItem->IsAttr(ATTR_DECAY); bool bDisplayEffect = !pItem->m_itTelepad.m_fQuiet; Spell_Teleport(pt, true, bCheckAntiMagic, bDisplayEffect); }
bool CChar::NPC_CheckWalkHere( const CPointBase & pt, const CRegionBase * pArea, WORD wBlockFlags ) const { ADDTOCALLSTACK("CChar::NPC_CheckWalkHere"); UNREFERENCED_PARAMETER(wBlockFlags); // Does the NPC want to walk here ? step on this item ? if ( !m_pNPC ) return false; if ( !pt.IsValidXY() ) return true; if ( m_pArea != NULL ) { if ( m_pNPC->m_Brain == NPCBRAIN_GUARD && !IsStatFlag(STATF_War) ) // guards will want to stay in guard range { if ( m_pArea->IsGuarded() && !pArea->IsGuarded() ) return false; } if ( Noto_IsCriminal() ) { if ( !m_pArea->IsGuarded() && pArea->IsGuarded() ) return false; } } // Is there a nasty object here that will hurt us ? CWorldSearch AreaItems(pt); for (;;) { CItem * pItem = AreaItems.GetItem(); if ( pItem == NULL ) break; if ( abs(pItem->GetTopZ() - pt.m_z) > 5 ) continue; switch ( pItem->GetType() ) { case IT_WEB: return (GetDispID() == CREID_GIANT_SPIDER) ? true : false; case IT_FIRE: return Can(CAN_C_FIRE_IMMUNE); case IT_TRAP: case IT_TRAP_ACTIVE: case IT_MOONGATE: case IT_TELEPAD: return false; default: break; } } return true; }