Esempio n. 1
0
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;
}
Esempio n. 2
0
void cDragItems::dropOnTrainer( P_CLIENT client, P_ITEM pItem, P_CHAR pTrainer )
{
	P_CHAR pChar = client->player();

	if( pItem->id() != 0xEED )
	{
		pTrainer->talk( "You need to give me gold if you want me to train you!" );
		bounceItem( client, pItem );
		return;
	}

	pTrainer->talk( "I thank thee for thy payment. That should give thee a good start on thy way. Farewell!" );

	Q_UINT8 skill = pTrainer->trainingplayerin();
	Q_INT32 skillSum = pChar->getSkillSum();
	Q_INT32 skillDelta = pTrainer->getTeachingDelta( pChar, skill, skillSum );

	goldsfx( client->socket(), pItem->amount() );

	if( pItem->amount() > skillDelta )
	{
		pItem->ReduceAmount( skillDelta );
		bounceItem( client, pItem );
	}
	else
	{
		skillDelta = pItem->amount();
		Items->DeleItem( pItem );
	}
	
	pChar->setBaseSkill( skill, pChar->baseSkill( skill ) + skillDelta );
	Skills->updateSkillLevel( pChar, skill );
	updateskill( client->socket(), skill );

	// we will not reset the trainer id here because he may want to give him more money
}