P_CHAR cRegion::RegionIterator4Chars::GetData(void) { if (currentCharacter == NULL) currentCharacter = FindCharBySerial(vecEntries[currentIndex]); else if (currentCharacter->serial != vecEntries[currentIndex]) currentCharacter = FindCharBySerial(vecEntries[currentIndex]); if (currentCharacter == NULL && currentIndex < vecEntries.size()) { // Dam, invalid entrie! // go next and recurse. (*this)++; return GetData(); } return currentCharacter; }
// TESTED: OKAY (i think so, but ugly -> redo it!) // guildmastercalc(guildnumber) counts all fealty settings of all members of 'guildnumber' and sets // a new guildmaster if there is a draw then there will be no master, til the next check ;) void cGuildStone::CalcMaster() { std::map<unsigned int, unsigned int> votes; // Key is member serial and data #votes unsigned int i; for ( i = 0; i < member.size(); ++i) { P_CHAR pc = FindCharBySerial( member[i] ); votes[pc->guildfealty()]++; } /* struct maxVotes : public binary_function< pair<unsigned int, unsigned int>, pair<unsigned int, unsigned int>, bool> { operator(pair<unsigned int, unsigned int> a, pair<unsigned int, unsigned int> b) { return (a.second < b.second); } };*/ std::map<unsigned int, unsigned int>::iterator it = max_element(votes.begin(), votes.end(), votes.value_comp()); unsigned int currenthighest = it->first; unsigned int currenthighestvotes = it->second; votes.erase( it ); // check for draw; it = max_element(votes.begin(), votes.end(), votes.value_comp()); bool draw = ( it->second == currenthighestvotes ); if (!draw) this->master = currenthighest; }
// guildrecruit() Let the guild members recruit some player into the guild. // Checks the guild database if "to be recruited" player already in any other guild. // puts a tag with players serial number into the guilds recruit database. void cGuildStone::Recruit(UOXSOCKET s) { if ( currchar[s]->guildstone() == INVALID_SERIAL ) { sysmessage(s,"you are in no guild"); return; } if(buffer[s][11]==0xFF && buffer[s][12]==0xFF && buffer[s][13]==0xFF && buffer[s][14]==0xFF) return; // check if user canceled operation - Morrolan int serial = calcserial(buffer[s][7],buffer[s][8],buffer[s][9],buffer[s][10]); P_CHAR pc = FindCharBySerial( serial ); if(pc != NULL) { if (pc->guildstone() != INVALID_SERIAL) sysmessage(s,"This person is already in a guild."); else { if (pc->isPlayer()) { this->recruit.push_back(pc->serial); } else sysmessage(s,"This is not a player."); } //break; //} for } this->Menu(s,1); return; }
void cRepeatAction::Expire() { P_CHAR pMage = FindCharBySerial( _mage ); if( pMage ) TempEffects::instance()->insert( new cRepeatAction( pMage, _anim, _delay ) ); }
void cTempEffects::check() { cTempEffect *tEffect = NULL; if( !teffects.empty() ) tEffect = *teffects.begin(); if( !tEffect) return; while( tEffect && tEffect->expiretime <= uiCurrentTime ) { if( isCharSerial( tEffect->getDest() ) ) { P_CHAR pChar = dynamic_cast< P_CHAR >( FindCharBySerial( tEffect->getDest() ) ); if (pChar) { pChar->removeEffect( tEffect ); } } tEffect->Expire(); std::pop_heap( teffects.begin(), teffects.end(), cTempEffects::ComparePredicate() ); teffects.pop_back(); delete tEffect; if( !teffects.empty() ) tEffect = *teffects.begin(); else break; } }
void cTrade::clearalltrades() { AllItemsIterator iterItems; for (iterItems.Begin(); !iterItems.atEnd(); iterItems++) { P_ITEM pi = iterItems.GetData(); if (pi->type==1 && pi->pos.x==26 && pi->pos.y==0 && pi->pos.z==0 && pi->id()==0x1E5E) { P_CHAR pc = FindCharBySerial(pi->contserial); P_ITEM pBackpack = Packitem(pc); SERIAL serial = pi->serial; unsigned int ci; vector<SERIAL> vecContainer = contsp.getData(serial); for (ci = 0; ci < vecContainer.size(); ci++) { P_ITEM pj = FindItemBySerial(vecContainer[ci]); if (pj != NULL) if ((pj->contserial==serial)) { if(pBackpack != NULL) { pBackpack->AddItem(pj); } } } iterItems--; // Iterator will became invalid when deletting. Items->DeleItem(pi); clConsole.send("Trade cleared\n"); } } }
void cGuildStone::SetType(enGuildType type) { guildType = type; unsigned int i; switch(type) { case order: // Convert into a order guild for(i = 0; i < member.size(); ++i) { P_CHAR holding = FindCharBySerial( member[i] ); if (holding != NULL) { RemoveShields( holding ); Items->SpawnItemBackpack2( calcSocketFromChar( holding ), "29", 1 ); // will not work for offline chars (Duke) } } Broadcast( "Your guild is now an Order guild." ); Broadcast( "An order shield has been placed in your pack!" ); break; case chaos: // Convert guild into an choas guild for(i = 0; i < member.size(); ++i) { P_CHAR holding = FindCharBySerial( member[i] ); if ( holding != NULL ) { RemoveShields( holding ); Items->SpawnItemBackpack2( calcSocketFromChar( holding ), "28", 1 ); } } Broadcast( "Your guild is now a Chaos guild." ); Broadcast( "A chaos shield has been placed in your pack!" ); break; case standard: // Convert guild into a standard guild default: // Just let it fall through for(i = 0; i < member.size(); ++i) { P_CHAR holding = FindCharBySerial( member[i] ); if( holding != NULL ) { RemoveShields( holding ); } } Broadcast( "Your guild is now a Standard guild." ); break; } }
void cDelayedHideChar::Expire() { P_PLAYER pc = dynamic_cast<P_PLAYER>(FindCharBySerial( destSer )); if( !pc || pc->socket() ) // break if the char has relogged in the meantime return; pc->setHidden( 1 ); pc->resend( true ); }
// Refresh the quest-arrow // Until our target expires virtual void Expire() { P_PLAYER pChar = dynamic_cast<P_PLAYER>(FindCharBySerial( tracker_ )); if( !pChar || !pChar->socket() ) return; P_CHAR pTarget = FindCharBySerial( target_ ); // Disable the quest-arrow if( !pTarget || pChar->trackingTime() <= uiCurrentTime ) { pChar->socket()->sendQuestArrow( false, 0, 0 ); return; } pChar->socket()->sendQuestArrow( true, pTarget->pos().x, pTarget->pos().y ); TempEffects::instance()->insert( new cRefreshTracking( tracker_, target_ ) ); }
// This checks LineOfSight before calling CombatHit (Duke, 10.7.2001) void cCombat::CombatHitCheckLoS(P_CHAR pAttacker, unsigned int currenttime) { P_CHAR pDefender = FindCharBySerial(pAttacker->swingtarg); if ( pDefender == NULL ) return; UOXSOCKET s1=calcSocketFromChar(pAttacker); unsigned short los=line_of_sight(s1,pAttacker->pos, pDefender->pos, WALLS_CHIMNEYS+DOORS+FLOORS_FLAT_ROOFING); CombatHit(pAttacker, pDefender, currenttime, los); }
/*! Returns the variant as a Character if the variant has type() StringType, DoubleType, IntType; or NULL otherwise. \sa toChar() */ cBaseChar* cVariant::toChar() const { if ( typ == BaseCharType ) return ( P_CHAR ) value.ptr; if ( typ == StringType ) return FindCharBySerial( hex2dec( *( ( QString * ) value.ptr ) ).toUInt() ); if ( typ == IntType ) return FindCharBySerial( value.i ); if ( typ == LongType ) return FindCharBySerial( ( unsigned int ) value.d ); if ( typ == DoubleType ) return FindCharBySerial( ( unsigned int ) floor( value.d ) ); return 0; }
void cDelayedHeal::Expire() { P_CHAR pSource = FindCharBySerial( destSer ); P_CHAR pTarget = FindCharBySerial( sourSer ); if( !pSource || !pTarget ) return; if( !pSource->inRange( pTarget, 5 ) ) { if( pSource->objectType() == enPlayer ) { P_PLAYER pp = dynamic_cast<P_PLAYER>(pSource); if( pp->socket() ) pp->socket()->sysMessage( tr( "You are standing too far away to apply any bandages." ) ); } return; } }
// cDelayedHideChar cDelayedHideChar::cDelayedHideChar( SERIAL serial ) { if( !isCharSerial( serial ) || !FindCharBySerial( serial ) ) { character = INVALID_SERIAL; return; } character = serial; setSerializable( true ); }
void cBoat::PlankStuff(UOXSOCKET s, P_ITEM pi_plank)//If the plank is opened, double click Will send them here { P_CHAR pc_cs,pc_b; pc_cs = currchar[s]; P_ITEM boat = GetBoat(pc_cs); if(boat == NULL)//They aren't on a boat, so put then on the plank. { // LB, bugfix for tillerman not reacting if the boat was entered via plank ! // we need to get the boat again after beaming the character to the boat's plank // otherweise only -1's will be added to the boat hash-table pc_cs->moveTo(pi_plank->pos + Coord_cl(0,0,5)); pc_cs->multis=-3; // we have to trick getboat to start the search !!! // will be corrected automatically by setserial... P_ITEM boat2 = GetBoat(pc_cs); if (boat2 == NULL) return; unsigned int a; vector<SERIAL> vecCown = cownsp.getData(pc_cs->serial); for(a = 0; a < vecCown.size(); a++)//Put all their Pets/Hirlings on the boat too { pc_b = FindCharBySerial(vecCown[a]); if (pc_b != NULL) // never log -1's that indicate non existance !!! { if (pc_b->isNpc() && pc_cs->Owns(pc_b)) { pc_b->moveTo(boat2->pos + Coord_cl(1, 1, 2)); pc_b->SetMultiSerial(boat2->serial); teleport(pc_b); } } } OpenPlank(pi_plank); //lb if (boat2 != NULL) // now set the char coords to the boat !!! { pc_cs->moveTo(boat2->pos + Coord_cl(1, 1, 2)); } sysmessage(s,"you entered a boat"); pc_cs->SetMultiSerial(boat2->serial); } else { LeaveBoat(s, pi_plank);//They are on a boat, get off } teleport(pc_cs);//Show them they moved. }
void cDragItems::dropItem( cUOSocket *socket, cUORxDropItem *packet ) { P_PLAYER pChar = socket->player(); if( !pChar ) return; // Get the data SERIAL contId = packet->cont(); Coord_cl dropPos = pChar->pos(); // plane dropPos.x = packet->x(); dropPos.y = packet->y(); dropPos.z = packet->z(); // Get possible containers P_ITEM pItem = FindItemBySerial( packet->serial() ); if( !pItem ) return; P_ITEM iCont = FindItemBySerial( packet->cont() ); P_CHAR cCont = FindCharBySerial( packet->cont() ); // >> SEE LORD BINARIES DROPFIX << // A completely invalid Drop packet if( !iCont && !cCont && ( dropPos.x == 0xFFFF ) && ( dropPos.y == 0xFFFF ) && ( (unsigned char)dropPos.z == 0xFF ) ) { socket->bounceItem( pItem, BR_NO_REASON ); return; } UINT32 weight = pChar->weight(); // Item dropped on Ground if( !iCont && !cCont ) dropOnGround( socket, pItem, dropPos ); // Item dropped on another item else if( iCont ) dropOnItem( socket, pItem, iCont, dropPos ); // Item dropped on char else if( cCont ) dropOnChar( socket, pItem, cCont ); // Handle the sound-effect if( pItem->id() == 0xEED ) goldsfx( socket, pItem->amount(), true ); // Update our weight. if( weight != pChar->weight() ) socket->sendStatWindow(); }
void cAllTmpEff::On() { unsigned int i; for (i=0; i<teffectcount; i++) { cTmpEff *pTE = &teffects[i]; P_CHAR pc = FindCharBySerial(pTE->getDest()); if (pc) pTE->On(pc); } }
void cAllTmpEff::On() { register unsigned int i; for ( i = 0; i < teffects.size(); ++i) { cTmpEff *pTE = teffects[i]; P_CHAR pc = FindCharBySerial(pTE->getDest()); if (pc) pTE->On(pc); } }
void cSetPrivLvlTarget::responsed( UOXSOCKET socket, PKGx6C targetInfo ) { if( !isCharSerial( targetInfo.Tserial ) ) return; P_CHAR pc = FindCharBySerial( targetInfo.Tserial ); if( pc == NULL ) return; pc->setPrivLvl( plevel_ ); sysmessage( socket, QString("PrivLvl set to : %1").arg(plevel_) ); };
// TESTED: OKAY // Uhm.. do i need char or socket for sysmessage? hehe.. a socket ofcourse, FiXED iT! // guildbroadcast(guildnumber, text) broadcasts message to all online members of guild void cGuildStone::Broadcast(char *text) { unsigned int i; for (i = 0; i < member.size(); ++i) { P_CHAR pc = FindCharBySerial( member[i] ); if ( pc == NULL ) continue; if ( online( pc ) ) sysmessage( calcSocketFromChar( pc ), text); } }
// guildtitlechange(character, text) copies the text info the characters title field (guildnumber // gets calculated from the double clicked guildstones), changed character was buffered in the guilds // private field (as backup buffer) and notifies editing player about the change. void cGuildStone::ChangeTitle(UOXSOCKET s, char *text) { P_CHAR member = FindCharBySerial(this->priv); if (member == NULL) member = currchar[s]; this->priv = INVALID_SERIAL; member->setGuildtitle( text ); if (member == currchar[s]) sysmessage(s,"You changed your own title."); else sysmessage(s,"You changed the title."); Menu(s,2); }
void cTmpEff::Reverse() { P_CHAR pc_s = FindCharBySerial(getDest()); switch(num) { case 1: pc_s->priv2 &= 0xFD; break; case 2: pc_s->fixedlight='\xFF';break; case 3: pc_s->chgDex(more1); break; case 4: pc_s->in+=more1; break; case 5: pc_s->st+=more1; break; case 6: pc_s->chgDex(-1 * more1);break; case 7: pc_s->in-=more1; break; case 8: pc_s->st-=more1; break; case 11: pc_s->st-=more1; pc_s->chgDex(-1 * more2); pc_s->in-=more3; break; case 12: pc_s->st+=more1; pc_s->chgDex(more2); pc_s->in+=more3; break; case 18: //Polymorph spell by AntiChrist if(pc_s->polymorph) { pc_s->setId(pc_s->xid); pc_s->polymorph=false; teleport(pc_s); } break; case 19: //Incognito spell by AntiChrist reverseIncognito(pc_s); break; case 21: int toDrop; toDrop = more1; //Effect->more1; if( ( pc_s->baseskill[PARRYING] - toDrop ) < 0 ) pc_s->baseskill[PARRYING] = 0; else pc_s->baseskill[PARRYING] -= toDrop; default: clConsole.send("ERROR: Fallout of switch\n"); //Morrolan return; }//switch Items->CheckEquipment(pc_s); //AntiChrist - checks equipments for stats requirements }
void cTempEffects::insert( cTempEffect *pT ) { // If the tempeffect has a char it affects, // then don't forge to add it to his effects if( isCharSerial( pT->getDest() ) ) { P_CHAR pChar = FindCharBySerial( pT->getDest() ); if( pChar ) pChar->addEffect( pT ); } this->teffects.push_back( pT ); std::push_heap( teffects.begin(), teffects.end(), cTempEffects::ComparePredicate() ); }
void cAccounts::reload() { QMap< SERIAL, QString > characcnames; QStringList sockaccnames; cCharIterator iterChars; P_CHAR pc; for( pc = iterChars.first(); pc; pc = iterChars.next() ) { P_PLAYER pp = dynamic_cast<P_PLAYER>(pc); if( pp && pp->account() ) { characcnames.insert( pp->serial(), pp->account()->login() ); } } cUOSocket* mSock = NULL; for( mSock = cNetwork::instance()->first(); mSock; mSock = cNetwork::instance()->next() ) { if( mSock->account() ) sockaccnames.push_back( mSock->account()->login() ); else sockaccnames.push_back( QString() ); } clear(); load(); QMap< SERIAL, QString >::Iterator it = characcnames.begin(); while( it != characcnames.end() ) { P_PLAYER pp = dynamic_cast<P_PLAYER>(FindCharBySerial( it.key() )); if( pp ) pp->setAccount( getRecord( it.data() ), false ); ++it; } QStringList::iterator sit = sockaccnames.begin(); for( mSock = cNetwork::instance()->first(); mSock; mSock = cNetwork::instance()->next() ) { if( !(*sit).isNull() ) mSock->setAccount( getRecord( (*sit) ) ); ++sit; } }
virtual void handleResponse( cUOSocket *socket, const gumpChoice_st& choice ) { P_PLAYER player = socket->player(); if( !player ) return; P_CHAR pChar = FindCharBySerial( choice.button ); if( !pChar || pChar->dist( player ) > 32 ) return; // Start the refresh-timer // Start the wearoff-timer player->setTrackingTime( uiCurrentTime + ( 30 * MY_CLOCKS_PER_SEC ) ); TempEffects::instance()->insert( new cRefreshTracking( player->serial(), choice.button ) ); }
void cCharStuff::cDragonAI::HealMagic(P_CHAR pc_i, unsigned int currenttime) { if (currenttime >= pc_i->spatimer) { if (pc_i->poisoned) { Magic->NPCCure(pc_i); } else if (pc_i->hp < (pc_i->st/2)) { Magic->NPCHeal(pc_i); } if (pc_i->targ != INVALID_SERIAL) npcattacktarget(pc_i, FindCharBySerial(pc_i->targ)); } DoneAI(pc_i, currenttime); }
// Name: item_bounce3 // Purpose: holds some statements that were COPIED some 50 times // Remarks: temporary functions to revamp the 30 occurences of the 'bouncing bugfix' // History: init Duke, 10.8.2000 static void item_bounce3(const P_ITEM pi) { pi->SetContSerial(pi->oldcontserial); pi->pos.x=pi->oldx; pi->pos.y=pi->oldy; pi->pos.z=pi->oldz; pi->layer=pi->oldlayer; pi->flags.isBeeingDragged=false; P_CHAR pc = FindCharBySerial(pi->oldcontserial); if (pi->layer > 0 && pc != NULL) { pc->st += pi->st2; pc->chgDex(pi->dx2); pc->in += pi->in; } }
bool cSetTarget::responsed( cUOSocket* socket, cUORxTarget* target ) { P_CHAR pChar = FindCharBySerial( target->serial() ); P_ITEM pItem = FindItemBySerial( target->serial() ); cUObject* pObject = NULL; if ( pItem ) pObject = pItem; else if ( pChar ) pObject = pChar; // Only characters and items if ( !pObject ) { socket->sysMessage( tr( "Please select a valid character or item" ) ); return true; } // check for rank if ( pChar && pChar->objectType() == enPlayer ) { P_PLAYER pp = dynamic_cast<P_PLAYER>( pChar ); if ( pp->account()->rank() >= socket->player()->account()->rank() && pp != socket->player() ) { socket->sysMessage( tr( "Better do not try that!" ) ); return true; } } cVariant value( this->value ); stError* error = pObject->setProperty( key, value ); if ( error ) { socket->sysMessage( error->text ); delete error; } if ( pChar ) pChar->resend(); else if ( pItem ) pItem->update(); return true; }
bool cRemoveTarget::responsed( cUOSocket* socket, cUORxTarget* target ) { P_CHAR pChar = FindCharBySerial( target->serial() ); P_ITEM pItem = FindItemBySerial( target->serial() ); if ( pChar ) { pChar->remove(); } else if ( pItem ) { pItem->remove(); } else socket->sysMessage( tr( "You need to select either an item or a character" ) ); return true; }
/* * Returns the bans list of this multi */ static PyObject* wpMulti_bans( wpMulti* self, PyObject* args ) { Q_UNUSED(args); if( !self->pMulti || self->pMulti->free ) return PyFalse; std::vector< SERIAL > bans = self->pMulti->bans(); std::vector< SERIAL >::iterator it = bans.begin(); PyObject* list = PyList_New( bans.size() ); while( it != bans.end() ) { P_CHAR pChar = FindCharBySerial( *it ); if( pChar ) PyList_Append( list, PyGetCharObject( pChar ) ); it ++; } return list; }
bool cAccount::IsOnline( int acctnum ) { if (acctnum < 0) return false; map<int, acctman_st>::iterator iter_acctman; if ((iter_acctman = acctman.find(acctnum)) != acctman.end()) { acctman_st dummy = iter_acctman->second; if ( dummy.online ) return true; else { P_CHAR pc = FindCharBySerial(dummy.character); return pc->logout > uiCurrentTime; } } else return false; }