float Animal_Wild_Flee::postCondition() { /* * Fleeing from an approaching player has the following postconditions: * - There is no character in flight range. * - There is an character attacking us. * - Our owner has come in range. * */ if( m_npc->attackTarget() ) return 1.0f; RegionIterator4Chars ri( m_npc->pos(), SrvParams->animalWildFleeRange() ); bool found = false; for(ri.Begin(); !ri.atEnd(); ri++) { P_PLAYER pPlayer = dynamic_cast<P_PLAYER>(ri.GetData()); if( pPlayer && !pPlayer->free && !pPlayer->isGMorCounselor() && !pPlayer->isHidden() && !pPlayer->isInvisible() ) found = true; if( pPlayer && m_npc->owner() == pPlayer ) return 1.0f; } if( found ) return 0.0f; return 1.0f; }
float Animal_Wild_Flee::preCondition() { return 0.0f; /* * Fleeing from an approaching player has the following preconditions: * - There is a player within flight range. * - There is no character attacking us. * - Our owner is not in range. * */ if ( m_npc->attackTarget() ) return 0.0f; MapCharsIterator ri = MapObjects::instance()->listCharsInCircle( m_npc->pos(), Config::instance()->animalWildFleeRange() ); for ( P_CHAR pChar = ri.first(); pChar; pChar = ri.next() ) { P_PLAYER pPlayer = dynamic_cast<P_PLAYER>( pChar ); if ( pPlayer && !pPlayer->free && !pPlayer->isGMorCounselor() && !pPlayer->isHidden() && !pPlayer->isInvisible() ) { pFleeFromSer = pPlayer->serial(); } if ( pPlayer && m_npc->owner() == pPlayer ) return 0.0f; } if ( pFleeFromSer != INVALID_SERIAL ) return 1.0f; return 0.0f; }
float Animal_Wild_Flee::postCondition() { /* * Fleeing from an approaching player has the following postconditions: * - There is no character in flight range. * - There is an character attacking us. * - Our owner has come in range. * */ if ( m_npc->attackTarget() ) return 1.0f; bool found = false; MapCharsIterator ri = MapObjects::instance()->listCharsInCircle( m_npc->pos(), Config::instance()->animalWildFleeRange() ); for ( P_CHAR pChar = ri.first(); pChar; pChar = ri.next() ) { P_PLAYER pPlayer = dynamic_cast<P_PLAYER>( pChar ); if ( pPlayer && !pPlayer->free && !pPlayer->isGMorCounselor() && !pPlayer->isHidden() && !pPlayer->isInvisible() ) found = true; if ( pPlayer && m_npc->owner() == pPlayer ) return 1.0f; } if ( found ) return 0.0f; return 1.0f; }
void Human_Guard::selectVictim() { if ( m_currentVictim ) { // Check if the current target is valid, including: // - Target not dead. // - Target in attack range. // - Target not innocent. if ( m_currentVictim->isDead() || m_currentVictim->isInnocent() ) m_currentVictim = NULL; else if ( !m_npc->inRange( m_currentVictim, Config::instance()->attack_distance() ) ) m_currentVictim = NULL; } if ( !m_currentVictim ) { // Get a criminal or murderer in range to attack it RegionIterator4Chars ri( m_npc->pos(), VISRANGE ); for ( ri.Begin(); !ri.atEnd(); ri++ ) { P_CHAR pChar = ri.GetData(); if ( pChar && !pChar->free && pChar != m_npc && !pChar->isInvulnerable() && !pChar->isHidden() && !pChar->isInvisible() && !pChar->isDead() && !pChar->isInnocent() ) { P_PLAYER pPlayer = dynamic_cast<P_PLAYER>( pChar ); if ( pPlayer && pPlayer->isGMorCounselor() ) continue; m_currentVictim = pChar; break; } } // If we found a new target, let us attack it if ( m_currentVictim ) m_npc->fight( m_currentVictim ); } }
/*! Calculates the amount of Stamina needed for a move of the passed character. */ bool cMovement::consumeStamina( P_PLAYER pChar, bool running ) { // Dead people and gms don't care about weight if ( pChar->isDead() || pChar->isGMorCounselor() ) { return true; } // Calculate the stones we weight too much int overWeight = ( int ) ( pChar->weight() - pChar->maxWeight() ); bool mounted = pChar->atLayer( cBaseChar::Mount ) != 0; bool update = false; // We carry too much if ( overWeight > 0 ) { // How much stamina we loose int amount = 5 + ( overWeight / 25 ); // Only one third loss if mounted if ( mounted ) { amount = amount / 3; } // Double loss if running if ( running ) { amount = amount * 2; } // Set the new stamina pChar->setStamina( wpMax<Q_INT16>( 0, pChar->stamina() - amount ), false ); update = true; // We are overloaded if ( pChar->stamina() == 0 ) { pChar->socket()->updateStamina(); pChar->socket()->clilocMessage( 500109 ); return false; } } // If we have less than 10% stamina left, we loose // stamina more quickly if ( ( pChar->stamina() * 100 ) / wpMax<ushort>( 1, pChar->maxStamina() ) < 10 ) { pChar->setStamina( wpMax<Q_INT16>( 0, pChar->stamina() - 1 ), false ); update = true; } // We can't move anymore because we are exhausted if ( pChar->stamina() == 0 ) { pChar->socket()->updateStamina(); pChar->socket()->clilocMessage( 500110 ); return false; } // Normally reduce stamina every few steps if ( pChar->stepsTaken() % ( mounted ? 48 : 16 ) == 0 ) { pChar->setStamina( wpMax<Q_INT16>( 0, pChar->stamina() - 1 ) ); update = true; } if ( update ) { pChar->socket()->updateStamina(); } return true; }
void cSkills::RandomSteal( cUOSocket* socket, SERIAL victim ) { P_PLAYER pChar = socket->player(); P_CHAR pVictim = FindCharBySerial( victim ); if ( !pVictim || !pChar ) return; if ( pVictim->serial() == pChar->serial() ) { socket->sysMessage( tr( "Why don't you simply take it?" ) ); return; } /* if( pVictim->npcaitype() == 17 ) { socket->sysMessage( tr( "You cannot steal from Playervendors." ) ); return; } */ if ( pVictim->objectType() == enPlayer ) { P_PLAYER pp = dynamic_cast<P_PLAYER>( pVictim ); if ( pp->isGMorCounselor() ) socket->sysMessage( tr( "You can't steal from game masters." ) ); return; } if ( !pChar->inRange( pVictim, 1 ) ) { socket->sysMessage( tr( "You are too far away to steal from that person." ) ); return; } P_ITEM pBackpack = pVictim->getBackpack(); if ( !pBackpack ) { socket->sysMessage( tr( "Bad luck, your victim doesn't have a backpack." ) ); return; } float maxWeight = ( float ) QMIN( 1, pChar->skillValue( STEALING ) ); // We can steal max. 10 Stones when we are a GM // 1000 Skill == 100 Weight == 10 Stones QPtrList<cItem> containment = pBackpack->getContainment(); Q_UINT32 chance = containment.count(); P_ITEM pItem = containment.first(); P_ITEM pToSteal = 0; bool sawOkItem = false; while ( !pToSteal ) { // We have nothing that could be stolen? if ( !pItem && !sawOkItem ) { socket->sysMessage( tr( "Your victim posesses nothing you could steal." ) ); return; } // Jump back to the beginning else if ( !pItem && sawOkItem ) { pItem = containment.first(); } // Check if our chance becomes true (no spellbooks!) if ( pItem->totalweight() <= maxWeight && !pItem->isLockedDown() && !pItem->newbie() && pItem->type() != 9 ) { sawOkItem = true; // We have items that could be stolen (just in case we reach the end of our list) // We have the chance of 1/chance that we reached our desired item if ( RandomNum( 1, ( int )chance ) == ( int )chance ) { pToSteal = pItem; break; } } pItem = containment.next(); } socket->sysMessage( tr( "You reach into %1's backpack and try to steal something..." ).arg( pVictim->name() ) ); // The success of our Theft depends on the weight of the stolen item bool success = pChar->checkSkill( STEALING, 0, ( long int )pToSteal->weight() ); bool caught = false; if ( success ) { socket->sysMessage( tr( "You successfully steal %1." ).arg( pToSteal->getName() ) ); P_ITEM pPack = pChar->getBackpack(); pPack->addItem( pToSteal ); // Update item onyl if still existent if ( !pToSteal->free ) pToSteal->update(); caught = pChar->skillValue( STEALING ) < rand() % 1001; } else { socket->sysMessage( tr( "You fail to steal the item." ) ); // 1 in 5 Chance if we failed caught = RandomNum( 1, 5 ) == 1; } // Did we get caught? if ( caught ) { socket->sysMessage( tr( "You have been cought!" ) ); // Human non red NPCs need special handling if ( pVictim->objectType() == enNPC && pVictim->isInnocent() && pVictim->isHuman() ) { P_NPC pn = dynamic_cast<P_NPC>( pVictim ); pVictim->talk( tr( "Guards! A thief is amoung us!" ), 0xFFFF, 0x09 ); if ( pVictim->region() && pVictim->region()->isGuarded() ) pn->callGuards(); } if ( pVictim->notoriety( pChar ) == 0x01 ) pChar->makeCriminal(); // Our Victim always notices it. if ( pVictim->objectType() == enPlayer ) { P_PLAYER pp = dynamic_cast<P_PLAYER>( pVictim ); if ( pp->socket() ) pp->socket()->showSpeech( pChar, tr( "You notice %1 trying to steal %2 from you." ).arg( pChar->name() ).arg( pToSteal->getName( true ) ) ); } QString message = tr( "You notice %1 trying to steal %2 from %3." ).arg( pChar->name() ).arg( pItem->getName() ).arg( pVictim->name() ); for ( cUOSocket*mSock = Network::instance()->first(); mSock; mSock = Network::instance()->next() ) { // Everyone within 7 Tiles notices us if ( mSock != socket && mSock->player() && mSock->player()->serial() != pVictim->serial() && mSock->player()->inRange( pChar, 7 ) ) mSock->showSpeech( pChar, message ); } } }