/*! \brief Add item to container \author Endymion \param pItem the item to add \param xx the x location or INVALID if use rand pos \param yy the y location or INVALID if use rand pos */ LOGICAL cItem::AddItem(P_ITEM pItem, short xx, short yy) { VALIDATEPIR(pItem,false); NxwSocketWrapper sw; sw.fillOnline( pItem ); for( sw.rewind(); !sw.isEmpty(); sw++ ) SendDeleteObjectPkt(sw.getSocket(), pItem->getSerial32() ); if (xx!=-1) // use the given position { pItem->setContSerial( getSerial32() ); pItem->setPosition(xx, yy, 9); } else // no pos given { if( !ContainerPileItem(pItem) ) { // try to pile pItem->SetRandPosInCont(this); // not piled, random pos pItem->setContSerial( getSerial32() ); } else return true; //Luxor: we cannot do a refresh because item was piled } pItem->Refresh(); return true; }
static bool ItemDroppedOnTrainer(NXWCLIENT ps, PKGx08 *pp, P_ITEM pi) { if (ps == NULL) return false; VALIDATEPIR(pi, false); NXWSOCKET s = ps->toInt(); P_CHAR pc = ps->currChar(); VALIDATEPCR(pc,false); P_CHAR pc_t = pointers::findCharBySerial(pp->Tserial); VALIDATEPCR(pc_t,false); if( pi->getId() == ITEMID_GOLD ) { // They gave the NPC gold UI08 sk=pc_t->trainingplayerin; pc_t->talk( s, TRANSLATE("I thank thee for thy payment. That should give thee a good start on thy way. Farewell!"),0); int sum = pc->getSkillSum(); int delta = pc_t->getTeachingDelta(pc, sk, sum); if(pi->amount>delta) // Paid too much { pi->amount-=delta; Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); item_bounce5(s,pi); } } else { if(pi->amount < delta) // Gave less gold delta = pi->amount; // so adjust skillgain pi->Delete(); } pc->baseskill[sk]+=delta; Skills::updateSkillLevel(pc, sk); updateskill(s,sk); pc->trainer=-1; pc_t->trainingplayerin=0xFF; pc->playSFX( itemsfx(pi->getId()) ); } else // Did not give gold { pc_t->talk( s, TRANSLATE("I am sorry, but I can only accept gold."),0); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); item_bounce5(s,pi); } }//if items[i]=gold return true; }
static bool ItemDroppedOnGuard(NXWCLIENT ps, PKGx08 *pp, P_ITEM pi) { if (ps == NULL) return false; VALIDATEPIR(pi, false); char temp[TEMP_STR_SIZE]; //xan -> this overrides the global temp var NXWSOCKET s=ps->toInt(); P_CHAR pc = ps->currChar(); VALIDATEPCR(pc,false); P_CHAR pc_t=pointers::findCharBySerial(pp->Tserial); //the guard VALIDATEPCR(pc_t,false); // Search for the key word "the head of" if( strstr( pi->getCurrentNameC(), "the head of" ) ) //!!! Wrong! it must check the ItemID, not the name :( { // This is a head of someone, see if the owner has a bounty on them P_CHAR own=pointers::findCharBySerial(pi->getOwnerSerial32()); VALIDATEPCR(own,false); if( own->questBountyReward > 0 ) { // Give the person the bounty assuming that they are not the // same person as the reward is for if( pc->getSerial32() != own->getSerial32() ) { // give them the gold for bringing the villan to justice addgold( s, own->questBountyReward ); pc->playSFX( goldsfx( own->questBountyReward ) ); // Now thank them for their hard work sprintf( temp, TRANSLATE("Excellent work! You have brought us the head of %s. Here is your reward of %d gold coins."), own->getCurrentNameC(), own->questBountyReward ); pc_t->talk( s, temp, 0); // Delete the Bounty from the bulletin board BountyDelete(own ); // xan : increment fame & karma :) pc->modifyFame( ServerScp::g_nBountyFameGain ); pc->IncreaseKarma(ServerScp::g_nBountyKarmaGain); } else pc_t->talk( s, TRANSLATE("You can not claim that prize scoundrel. You are lucky I don't strike you down where you stand!"),0); // Delete the item pi->Delete(); } } return true; }
static bool ItemDroppedOnBeggar(NXWCLIENT ps, PKGx08 *pp, P_ITEM pi) { if (ps == NULL) return false; VALIDATEPIR(pi, false); char temp[TEMP_STR_SIZE]; //xan -> this overrides the global temp var NXWSOCKET s=ps->toInt(); P_CHAR pc=ps->currChar(); VALIDATEPCR(pc,false); P_CHAR pc_t=pointers::findCharBySerial(pp->Tserial); //beggar VALIDATEPCR(pc_t,false); if(pi->getId()!=ITEMID_GOLD) { sprintf(temp,TRANSLATE("Sorry %s i can only use gold"), pc->getCurrentNameC()); pc_t->talk( s,temp,0); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); item_bounce5(s,pi); return true; } } else { sprintf(temp,TRANSLATE("Thank you %s for the %i gold!"), pc->getCurrentNameC(), pi->amount); pc_t->talk( s,temp,0); if(pi->amount<=100) { pc->IncreaseKarma(10); ps->sysmsg(TRANSLATE("You have gain a little karma!")); } else if(pi->amount>100) { pc->IncreaseKarma(50); ps->sysmsg(TRANSLATE("You have gain some karma!")); } pi->Delete(); return true; } return true; }
/*! \brief apply wear out to item, delete if necessary \author Ripper, rewritten by Luxor \return bool \param s socket of player who wear out the item \param pi pointer to item to wear out \todo become a method of cItem */ static bool Item_ToolWearOut(NXWSOCKET s, P_ITEM pi) { VALIDATEPIR(pi, false); if ( s < 0 || s >= now ) return false; P_CHAR pc = pointers::findCharBySerial(currchar[s]); VALIDATEPCR(pc, false); if( chance(5) ) { // has item been destroyed ?? pi->hp--; if ( pi->hp <= 0 ) { pc->sysmsg("Your %s has been destroyed", pi->getCurrentNameC()); pi->Delete(); return true; } } return false; }
static bool ItemDroppedOnPet(NXWCLIENT ps, PKGx08 *pp, P_ITEM pi) { if (ps == NULL) return false; VALIDATEPIR(pi, false); P_CHAR pet = pointers::findCharBySerial(pp->Tserial); VALIDATEPCR(pet, false); NXWSOCKET s = ps->toInt(); P_CHAR pc = ps->currChar(); VALIDATEPCR(pc, false); if((pet->hunger<6) && (pi->type==ITYPE_FOOD))//AntiChrist new hunger code for npcs { pc->playSFX( (UI16)(0x3A+(rand()%3)) ); //0x3A - 0x3C three different sounds if(pi->poisoned) { pet->applyPoison(PoisonType(pi->poisoned)); } std::string itmname; if( pi->getCurrentName() == "#" ) { char temp2[TEMP_STR_SIZE]; //xan -> this overrides the global temp var pi->getName(temp2); itmname = temp2; } else itmname = pi->getCurrentName(); pet->emotecolor = 0x0026; pet->emoteall(TRANSLATE("* You see %s eating %s *"), 1, pet->getCurrentNameC(), itmname.c_str() ); pet->hunger++; } else { ps->sysmsg(TRANSLATE("It doesn't appear to want the item")); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); item_bounce5(s,pi); } } return true; }
static bool ItemDroppedOnSelf(NXWCLIENT ps, PKGx08 *pp, P_ITEM pi) { if (ps == NULL) return false; VALIDATEPIR(pi, false); // NXWSOCKET s=ps->toInt(); // CHARACTER cc=ps->currCharIdx(); P_CHAR pc = ps->currChar(); // MAKE_CHAR_REF(cc); VALIDATEPCR(pc, false); Location charpos = pc->getPosition(); if (pi->getId() >= 0x4000 ) // crashfix , prevents putting multi-objects ni your backback { ps->sysmsg(TRANSLATE("Hey, putting houses in your pack crashes your back and client !")); pi->MoveTo( charpos ); pi->Refresh();//AntiChrist return true; } // if (pi->glow>0) // glowing items // { // pc->addHalo(pi); // pc->glowHalo(pi); // } P_ITEM pack = pc->getBackpack(); if (pack==NULL) // if player has no pack, put it at its feet { pi->MoveTo( charpos ); pi->Refresh(); } else { pack->AddItem(pi); // player has a pack, put it in there weights::NewCalc(pc);//AntiChrist bugfixes statwindow(pc,pc); pc->playSFX( itemsfx(pi->getId()) ); } return true; }
/*! \brief wrap for check usability \author Xanathar \return bool \param pc player trying using \param pi pointer to item to be used \param type type of usability \remarks Luxor - Added REQSKILL command support, three bug fix applied */ bool checkItemUsability(P_CHAR pc, P_ITEM pi, int type) { g_nType = type; VALIDATEPIR(pi, false); VALIDATEPCR(pc, false); NXWSOCKET s = pc->getSocket(); if( !pi->isNewbie() && ! pc->IsGM()) { if ( pi->st > pc->getStrength() ) { pc->sysmsg(TRANSLATE("You are not strong enough to use that.")); return false; } if ( pi->dx > pc->dx ) { pc->sysmsg(TRANSLATE("You are not quick enough to use that.")); return false; } if ( pi->in > pc->in ) { pc->sysmsg(TRANSLATE("You are not intelligent enough to use that.")); return false; } //Luxor: REQSKILL command support if (pi->reqskill[0] > 0 && pi->reqskill[1] > 0 ) { if (pi->reqskill[1] > pc->skill[pi->reqskill[0]]) { pc->sysmsg(TRANSLATE("You are not skilled enough to use that.")); return false; } } if ( (pi->getGender() != INVALID && pi->getGender() != GENDER_NEUTRAL ) && pi->getGender() != pc->getGender() ) { if ( pi->getGender() == 1 ) // it's a man item pc->sysmsg(TRANSLATE("Only males of your species may use that !")); else if ( pi->getGender() == 2 ) // it's a man item pc->sysmsg(TRANSLATE("Only females of your species may use that !")); else pc->sysmsg(TRANSLATE("You may not use that !")); // Damn, whats the political correct term for "Get some recreational extensions to your body" return false; } if ( Race::isRaceSystemActive() ) if ( pi->getRace() != INVALID && pi->getRace() != pc->getRace() ) { pc->sysmsg(TRANSLATE("Your race may not use this item!")); // Hope no one sues me because of racial discrimination in item use return false; } } if (s >-1 && s < now) //Luxor { if (pi->amxevents[EVENT_IONCHECKCANUSE]==NULL) return true; return (0!=pi->amxevents[EVENT_IONCHECKCANUSE]->Call(pi->getSerial32(), pc->getSerial32(), g_nType)); /* AmxEvent* event = pi->getAmxEvent( EVENT_IONCHECKCANUSE ); if ( !event ) return true; return ( 0 != event->Call(pi->getSerial32(), s, g_nType ) ); */ } return true; }
static bool ItemDroppedOnChar(NXWCLIENT ps, PKGx08 *pp, P_ITEM pi) { if (ps == NULL) return true; VALIDATEPIR(pi, false); NXWSOCKET s = ps->toInt(); // CHARACTER cc=ps->currCharIdx(); P_CHAR pTC = pointers::findCharBySerial(pp->Tserial); // the targeted character VALIDATEPCR(pTC, false); P_CHAR pc_currchar = ps->currChar(); //MAKE_CHAR_REF(cc); VALIDATEPCR(pc_currchar, false); Location charpos = pc_currchar->getPosition(); if (!pTC) return true; if (pi->amxevents[EVENT_IDROPONCHAR]!=NULL) { g_bByPass = false; pi->amxevents[EVENT_IDROPONCHAR]->Call( pi->getSerial32(), pc_currchar->getSerial32(), pTC->getSerial32() ); if (g_bByPass) { pi->Refresh(); return true; } } if (pc_currchar->getSerial32() != pTC->getSerial32() /*DEREF_P_CHAR(pTC)!=cc*/) { if (pTC->npc) { if(!pTC->HasHumanBody()) { ItemDroppedOnPet( ps, pp, pi); } else // Item dropped on a Human character { // Item dropped on a Guard (possible bounty quest) if( ( pTC->npc == 1 ) && ( pTC->npcaitype == NPCAI_TELEPORTGUARD ) ) { ItemDroppedOnGuard( ps, pp, pi); } if ( pTC->npcaitype == NPCAI_BEGGAR ) { ItemDroppedOnBeggar( ps, pp, pi); } //This crazy training stuff done by Anthracks ([email protected]) if(pc_currchar->isBeingTrained() ) { if ( pc_currchar->trainer != pTC->getSerial32()) { pTC->talk(s, TRANSLATE("Thank thee kindly, but I have done nothing to warrant a gift."),0); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); item_bounce5(s,pi); } return true; } else // The player is training from this NPC { ItemDroppedOnTrainer( ps, pp, pi); } } if ( pTC->isHirable() ) { // test if gold is enough if ( pi->amount < pTC->getHireFee() ) { pTC->talk(s, TRANSLATE("I need much more gold if i shall be working for you !"),0); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); item_bounce5(s,pi); } return true; } else if ( pi->amount >= pTC->getHireFee() ) { if ( pi->amount > pTC->getHireFee() ) { pi->amount=(UI16)(pi->amount - pTC->getHireFee()); pTC->talk(s, TRANSLATE("Thank thee kindly, but this is more than i need for the day."),0); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); item_bounce5(s,pi); } } pTC->setOwner(pc_currchar); tempfx::add(pTC, pc_currchar, tempfx::NPC_HIRECOST, 0, 0, 0, 0, (UI16)(MY_CLOCKS_PER_SEC*secondsperuominute*60*24 )); // call callback every uo day return true; } } }//if human or not } else // dropped on another player { // By Polygon: Avoid starting the trade if GM drops item on logged on char (crash fix) if ((pc_currchar->IsGM()) && !pTC->IsOnline()) { // Drop the item in the players pack instead // Get the pack P_ITEM pack = pTC->getBackpack(); if (pack != NULL) // Valid pack? { pack->AddItem(pi); // Add it weights::NewCalc(pTC); } else // No pack, give it back to the GM { pack = pc_currchar->getBackpack(); if (pack != NULL) // Valid pack? { pack->AddItem(pi); // Add it weights::NewCalc(pc_currchar); } else // Even GM has no pack? { // Drop it to it's feet pi->MoveTo( charpos ); pi->Refresh(); } } } else { //<Luxor>: secure trade P_ITEM tradeCont = tradestart(pc_currchar, pTC); if (ISVALIDPI(tradeCont)) { tradeCont->AddItem( pi, 30, 30 ); } else { Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); UpdateStatusWindow(s,pi); } } //</Luxor> } } } else // dumping stuff to his own backpack ! { ItemDroppedOnSelf( ps, pp, pi); } return true; }