Exemple #1
0
	/*!
	\brief initializes pointer maps
	\author Luxor
	*/
	void init()
	{


		pStableMap.clear();
		pContMap.clear();
		pMounted.clear();
		pOwnCharMap.clear();
		pOwnItemMap.clear();
		//Chars and Stablers
		P_CHAR pc = 0;

		cAllObjectsIter objs;

		for( objs.rewind(); !objs.IsEmpty(); objs++ )
		{
			if( isCharSerial( objs.getSerial() ) ) {
				pc=(P_CHAR)objs.getObject();
				{
					if( pc->isStabled() ) {
						pStableMap[pc->getStablemaster()].push_back(pc);
					}
					if( pc->mounted )
						pMounted[pc->getOwnerSerial32()]=pc;

					P_CHAR own=pointers::findCharBySerial(pc->getOwnerSerial32());
					pc->setOwnerSerial32( DEREF_P_CHAR(own), true );
				}
			}
			else {

				P_ITEM pi = (P_ITEM)objs.getObject();

				updContMap(pi);

				P_CHAR own=pointers::findCharBySerial(pi->getOwnerSerial32());
				pi->setOwnerSerial32( DEREF_P_CHAR(own), true );
			}
		}

		std::map< SERIAL, P_CHAR >::iterator iter( pMounted.begin() ), end( pMounted.end() );
		for( ; iter!=end; iter++)
		{
			pc = pointers::findCharBySerial(iter->first);
			if(ISVALIDPC(pc))
				pc->setOnHorse();
		}
	}
int response(UOXSOCKET s, P_CHAR pPlayer, char* SpeechUpr)
{
	char *comm=SpeechUpr;

    if (strstr( comm, "#EMPTY") && online(currchar[s]) && !pPlayer->dead && pPlayer->isGM())
	{ // restricted to GMs for now. It's too powerful (Duke, 5.6.2001)
		target(s, 0, 1, 0, 71, "Select container to empty:");
		return 1;
	}

    if (!online(DEREF_P_CHAR(pPlayer)) || pPlayer->dead)
		return 0;

	P_CHAR pc;
	cRegion::RegionIterator4Chars ri(pPlayer->pos);
	for (ri.Begin(); (pc=ri.GetData()) != ri.End(); ri++)
	{
		if (pc->isPlayer())		// only npcs will respond automagically, players still have to do that themselves ;)
			continue;
		if (pPlayer->dist(pc) > 16)	// at least they should be on the screen
			continue;
		if (pPlayer->isSameAs(pc))	// not talking to ourselves
			continue;
		
		if (StableSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (UnStableSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (ShieldSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (QuestionSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (PackupSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (TriggerSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (EscortSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (BankerSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (TrainerSpeech(pc, comm, pPlayer, s))
			return 1;
		
		if (PetCommand(pc, comm, pPlayer, s))
			return 1;
		
		if (VendorSpeech(pc, comm, pPlayer, s))
			return 1;
	}
	
	return 0;
}
bool TriggerSpeech(cChar* pc, char* comm, cChar* pPlayer, UOXSOCKET s)
{
	if (abs(pPlayer->pos.x-pc->pos.x)<=4 &&
		abs(pPlayer->pos.y-pc->pos.y)<=4 &&
		abs(pPlayer->pos.z-pc->pos.z)<=5)
	{
		if (pc->trigger)
		{
			if (strlen(pc->trigword))
			{
				char twtmp[150];
				strcpy(twtmp, pc->trigword);
				strupr(twtmp);
				if (strstr( comm, twtmp))
				{
					if (pc->disabled>0 && pc->disabled>uiCurrentTime)//AntiChrist
					{
						npctalkall(pc,"I'm a little busy now! Leave me be!",0);
					}
					else
					{
						triggernpc(s,DEREF_P_CHAR(pc),1);
					}
					return 1;
				}
			}
		}
	}
	return 0;
}
bool EscortSpeech(cChar* pEscortee, char* comm, cChar* pPlayer, UOXSOCKET s)
{
	// Dupois - Added Dec 20, 1999
	// Escort text matches
	if (pPlayer->dist(pEscortee) > 1 || pEscortee->questType!=ESCORTQUEST )
		return 0;	// not close enough / not an escortee
	
	char *response1=strstr( comm, "I WILL TAKE THEE");
	char *response2=strstr( comm, "DESTINATION");
	if ( response1 || response2 )	// If either of the above responses match
	{
		// I WILL TAKE THEE
		// If this is a request for hire
		if ( response1 )
		{
			if ( pEscortee->ftarg==-1 )
			{
				pEscortee->ftarg = currchar[s];		// Set the NPC to follow the PC
				pEscortee->npcWander = 1;			// Set the NPC to wander freely
				// Set the expire time if nobody excepts the quest
				pEscortee->summontimer = ( uiCurrentTime + ( MY_CLOCKS_PER_SEC * SrvParms->escortactiveexpire ) );
				// Send out the rant about accepting the escort
				sprintf(temp, "Lead on! Payment shall be made when we arrive at %s.", region[pEscortee->questDestRegion].name);
				npctalkall(pEscortee,temp, 0);
				MsgBoardQuestEscortRemovePost( DEREF_P_CHAR(pEscortee) );	// Remove post from message board
				return 1;	// Return 1 so that we indicate that we handled the message
			}
			else
			{
				response2 = response1;	// If the current NPC already has an ftarg then respond to query for quest
			}
		}
		
		// DESTINATION
		// If this is a request to find out where a NPC wants to go and the PC is within range of the NPC and the NPC is waiting for an ESCORT
		if (response2)
		{
			if ( pEscortee->ftarg == currchar[s] )
			{
				// Send out the rant about accepting the escort
				sprintf(temp, "Lead on to %s. I shall pay thee when we arrive.", region[pEscortee->questDestRegion].name);
			}
			else if ( pEscortee->ftarg == -1 )  // If nobody has been accepted for the quest yet
			{
				// Send out the rant about accepting the escort
				sprintf(temp, "I am seeking an escort to %s. Wilt thou take me there?", region[pEscortee->questDestRegion].name);
			}
			else // The must be enroute
			{
				// Send out a message saying we are already being escorted
				sprintf(temp, "I am already being escorted to %s by %s.", region[pEscortee->questDestRegion].name, chars[pEscortee->ftarg].name );
			}
			npctalkall(pEscortee,temp, 0);
			return 1;	// Return success ( we handled the message )
		}
	}
	return 0;	// speech was not handled
}
static bool ItemDroppedOnBanker(P_CLIENT ps, PKGx08 *pp, P_ITEM pi)
{
	UOXSOCKET s=ps->GetSocket();
	CHARACTER cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LRV(cc,true);
	int t=calcCharFromSer(pp->Tserial);
	P_ITEM bankbox = pc_currchar->GetBankBox();
	int amt = pi->amount;
	int value = pi->value;
	
	if (pi->id() == 0x14F0 && pi->type == 1000)
	{
		 const P_ITEM pi_n = Items->SpawnItem(DEREF_P_CHAR(pc_currchar), DEREF_P_CHAR(pc_currchar),value,"#",1,0x0E,0xED,0,0,0,0);
	     if(pi_n == NULL) return false;
		 sprintf((char*)temp,"%s I have cashed your check and deposited %i gold.",pc_currchar->name, value);
		 npctalk(s,t,(char*)temp,0);
		 bankbox->AddItem(pi_n);
	     statwindow(s, DEREF_P_CHAR(pc_currchar));
		 return true;
	}
    else
	{	    
	if (pi->id() == 0x0EED)
	{
		sprintf((char*)temp,"%s you have deposited %i gold.",pc_currchar->name, amt);
		npctalk(s,t,(char*)temp,0);
		bankbox->AddItem(pi);
	    statwindow(s, DEREF_P_CHAR(pc_currchar));
		return true;
	}
    else
	{
		  sprintf((char*)temp,"Sorry %s i can only deposit gold",pc_currchar->name);
		  npctalk(s,t,(char*)temp,0);
		  Sndbounce5(s);
		  if (ps->IsDragging())
		  {
			 ps->ResetDragging();
			 item_bounce5(s,pi);
			 return true;
		  }
	}
	return true;
	}
}
static bool ItemDroppedOnTrainer(P_CLIENT ps, PKGx08 *pp, P_ITEM pi)
{
	UOXSOCKET s=ps->GetSocket();
	CHARACTER cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LRV(cc,true);
	int t=calcCharFromSer(pp->Tserial);

	if( pi->id() ==0x0EED )
	{ // They gave the NPC gold
		char sk=chars[t].trainingplayerin;
		npctalk(s, t, "I thank thee for thy payment. That should give thee a good start on thy way. Farewell!",0);

		int sum = pc_currchar->getSkillSum();
		int delta = chars[t].getTeachingDelta(pc_currchar, 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
			Items->DeleItem(pi);
		}
		pc_currchar->baseskill[sk]+=delta;
		Skills->updateSkillLevel(DEREF_P_CHAR(pc_currchar), sk);
		updateskill(s,sk);

		pc_currchar->trainer=-1;
		chars[t].trainingplayerin='\xFF';
		itemsfx(s, pi->id());//AntiChrist - do the gold sound
		return true;
	}
	else // Did not give gold
	{
		npctalk(s, t, "I am sorry, but I can only accept gold.",0);
		Sndbounce5(s);
		if (ps->IsDragging())
		{
			ps->ResetDragging();
			item_bounce5(s,pi);
			return true;
		}
		else
			return true;
	}//if items[i]=gold
	return true;
}
void cCommands::KillSpawn(int s, int r)  //courtesy of Revana
{
	int killed=0;

	char temp[512];

	r++; // synch with 1-indexed real storage, casue 0 is no region indicator, LB

	if (r<=0 || r>=255) return;

	sysmessage(s,"Killing spawn, this may cause lag...");

	AllCharsIterator iter_char;
	for(iter_char.Begin(); iter_char.GetData() != NULL; iter_char++)
	{
		P_CHAR toCheck = iter_char.GetData();
		if(toCheck->spawnregion==r && !toCheck->free)
		{
			bolteffect(DEREF_P_CHAR(toCheck), true);
			soundeffect2(DEREF_P_CHAR(toCheck), 0x00, 0x29);
			Npcs->DeleteChar(DEREF_P_CHAR(toCheck));
            killed++;
		}
	}

	AllItemsIterator iter_item;
	for(iter_item.Begin(); iter_item.GetData() != NULL; iter_item++)
	{
		P_ITEM toCheck = iter_item.GetData();
		if(toCheck->spawnregion == r && !toCheck->free)
		{			
			iter_item--; // Iterator will became invalid when we delete it.
			Items->DeleItem(toCheck);
            killed++;
		}
	}

	gcollect();
	sysmessage(s, "Done.");
	sprintf(temp, "%i of Spawn %i have been killed.",killed,r-1);
	sysmessage(s, temp);
}
void cCommands::KillAll(int s, int percent, const char* sysmsg)
{
	sysmessage(s,"Killing all characters, this may cause some lag...");
	sysbroadcast(sysmsg);
	AllCharsIterator iter_char;
	for (iter_char.Begin(); iter_char.GetData() != NULL; iter_char++)
	{
		P_CHAR pc = iter_char.GetData();
		if(!pc->isGM())
		{
			if(rand()%100+1<=percent)
			{
				bolteffect(DEREF_P_CHAR(pc), true);
				soundeffect2(DEREF_P_CHAR(pc), 0x00, 0x29);
				deathstuff(DEREF_P_CHAR(pc));
			}
		}
	}
	sysmessage(s, "Done.");
}
static bool ItemDroppedOnPet(P_CLIENT ps, PKGx08 *pp, P_ITEM pi)
{
	UOXSOCKET s = ps->GetSocket();
	CHARACTER cc = ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHAR_REF(cc);
	P_CHAR pc_target = FindCharBySerial(pp->Tserial);

	if( pc_target->hunger < 6 && pi->type == 14 )//AntiChrist new hunger code for npcs
	{
		soundeffect2(DEREF_P_CHAR(pc_currchar), 0x00, 0x3A+(rand()%3));	//0x3A - 0x3C three different sounds

		if((pi->poisoned)&&(pc_target->poisoned<pi->poisoned)) 
		{
			soundeffect2(DEREF_P_CHAR(pc_target), 0x02, 0x46); //poison sound - SpaceDog
			pc_target->poisoned=pi->poisoned;
			pc_target->poisontime=uiCurrentTime+(MY_CLOCKS_PER_SEC*(40/pc_target->poisoned)); // a lev.1 poison takes effect after 40 secs, a deadly pois.(lev.4) takes 40/4 secs - AntiChrist
			pc_target->poisonwearofftime=pc_target->poisontime+(MY_CLOCKS_PER_SEC*SrvParms->poisontimer); //wear off starts after poison takes effect - AntiChrist
			impowncreate(s,DEREF_P_CHAR(pc_target),1); //Lb, sends the green bar ! 
		}
		
		if(pi->name[0]=='#') pi->getName(temp2);
		sprintf((char*)temp,"* You see %s eating %s *",pc_target->name,temp2);
		pc_target->emotecolor1=0x00;
		pc_target->emotecolor2=0x26;
		npcemoteall(DEREF_P_CHAR(pc_target),(char*)temp,1);
		pc_target->hunger++;
	} 
	else
	{
		sysmessage(s,"It doesn't appear to want the item");
		Sndbounce5(s);
		if (ps->IsDragging())
		{
			ps->ResetDragging();
			item_bounce5(s,pi);
		}
	}
	return true;
}
//Ripper...Packup a player vendor without redeeding house.
bool PackupSpeech(cChar* pc, char* comm, cChar* pPlayer, UOXSOCKET s)
{
	if (   pc->npcaitype != 17	// player vendor
		|| !pPlayer->Owns(pc)	// you own the vendor
		|| pPlayer->dist(pc) > 3) // must be within 3 tiles.
		return 0;

	if (strstr( comm, "PACKUP"))
	{
		// lets make the deed and place in your pack and delete vendor.
		P_ITEM pDeed = Items->SpawnItem(DEREF_P_CHAR(pPlayer), 1, "employment deed", 0, 0x14F0, 0, 1);
		if (pDeed)
		{
			pDeed->type = 217;
			pDeed->value = 2000;
			RefreshItem( pDeed );
			Npcs->DeleteChar( DEREF_P_CHAR(pc) );
			sysmessage(s, "Packed up vendor %s.", pc->name);
		}
		return 1;
	}
	return 0;
}
static bool ItemDroppedOnSelf(P_CLIENT ps, PKGx08 *pp, P_ITEM pi)
{
	UOXSOCKET s=ps->GetSocket();
	CHARACTER cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LRV(cc,true);
	
	if (pi->id1>=0x40) // crashfix , prevents putting multi-objects ni your backback
	{
		sysmessage(s,"Hey, putting houses in your pack crashes your back and client !");
		pi->MoveTo(pc_currchar->pos.x,pc_currchar->pos.y,pc_currchar->pos.z);
		RefreshItem(pi);//AntiChrist
		return true;
	}
	
	if (pi->glow>0) // glowing items
	{
		pc_currchar->addHalo(pi);
		pc_currchar->glowHalo(pi);
	}
	
	P_ITEM pack = Packitem(pc_currchar); // LB ...
	if (pack == NULL) // if player has no pack, put it at its feet
	{ 
		pi->MoveTo(pc_currchar->pos.x,pc_currchar->pos.y,pc_currchar->pos.z);
		RefreshItem(pi);//AntiChrist
	}
	else
	{
		pack->AddItem(pi); // player has a pack, put it in there
		
		Weight->NewCalc(DEREF_P_CHAR(pc_currchar));//AntiChrist bugfixes
		statwindow(s,DEREF_P_CHAR(pc_currchar));
		itemsfx(s, pi->id());
	}
	return true;
}
void cFishing::FishTarget(P_CLIENT ps)
{
	// fixes an exploit with fishing, LB
	int px,py,cx,cy;
	UOXSOCKET s=ps->GetSocket();
	P_CHAR pPlayer=ps->getPlayer();
	if (!pPlayer) return;

	px=((buffer[s][0x0b]<<8)+(buffer[s][0x0c]%256));
	py=((buffer[s][0x0d]<<8)+(buffer[s][0x0e]%256));
	cx=abs(pPlayer->pos.x-px);
	cy=abs(pPlayer->pos.y-py);
//	int cz=abs(pPlayer->z-buffer[s][0x10]);

	if(!(cx<=6 && cy<=6))
	{
		ps->SysMsg("You are too far away to reach that");
		return;
	}
	// end exploit fix

	bool ok=false;
	if (IsFishWater(ShortFromCharPtr(buffer[s]+0x11)))
		ok = true;
	else
	{	// it might be offshore fishing (client returns id=0 for deep sea ) Duke, Thx for the hint goes to Avanoon guys
		map_st map = Map->SeekMap0(px, py);	// search the ground tile where they casted
		if ( map.id == 0x00A8 || map.id == 0x00A9 || map.id == 0x00AA || map.id == 0x00AB )
			ok = true;
	}
	if (ok)
	{
		action(s,0x0b);
		if ((buffer[s][1]==1 || buffer[s][1]==0)&&(buffer[s][2]==0)&&(buffer[s][3]==1)&&(buffer[s][4]==0))
		{
			if (fishing_data.randomtime!=0)
				pPlayer->fishingtimer=rand()%fishing_data.randomtime+fishing_data.basetime;
			else
				pPlayer->fishingtimer=fishing_data.basetime;
		}
		soundeffect(s, 0x02, 0x3F);
		pPlayer->unhide();
		Fish(DEREF_P_CHAR(pPlayer));
	}
	else
		ps->SysMsg("You need to be closer to the water to fish!");
}
bool VendorSpeech(cChar* pVendor, char* comm, cChar* pPlayer, UOXSOCKET s)
{
	CHARACTER vendor = DEREF_P_CHAR(pVendor);

	if (pPlayer->dist(pVendor) > 4)
		return 0;
	
	if (strstr(comm, " BUY"))
	{
		if (!VendorChkName(pVendor,comm))
			return false;

		if(pVendor->npcaitype==17)
		{					
			addx[s]=vendor;
			npctalk(s,pVendor,"What would you like to buy?",0);
			target(s,0,1,0,224," ");
			return true;
		}
		else
			if(Targ->BuyShop(s, vendor))
				return true;
	}
	
	if (strstr( comm, " GOLD"))
	{
		if (!VendorChkName(pVendor,comm))
			return false;

		if (pVendor->npcaitype==17)	//PlayerVendors
		{
			PlVGetgold(s, pVendor);
			return true;
		}
	}
	
	if (strstr( comm, " SELL"))
	{						
		if (!VendorChkName(pVendor,comm))
			return false;

		sellstuff(s, vendor);						
		return true;
	}
	return false;
}
Exemple #14
0
/*!
\brief gets world coordinates from a serial
\author Xanathar
\param sr serial
\param px x coordinate
\param py y coordinate
\param pz z coordinate
\param ch eventual index to char
\param it eventual index to item
*/
void getWorldCoordsFromSerial (int sr, UI16& px, UI16& py, SI08& pz, int& ch, int& it)
{
    int serial = sr;
    int loop = 0;
    it = ch = INVALID;

	P_CHAR pc=0;
	P_ITEM pi=0;

    while ((++loop) < 500)
    {

		pc=pointers::findCharBySerial(serial);
		ch = DEREF_P_CHAR(pc);
		pi=pointers::findItemBySerial(serial);
        it = DEREF_P_ITEM(pi);
        if (ISVALIDPI(pi)) {
            if (pi->getContSerial()!=INVALID) {
                serial = pi->getContSerial();
                continue;
            }
        }
        break;
    }

    if (ISVALIDPC(pc)) {
		Location charpos= pc->getPosition();
        px = charpos.x;
        py = charpos.y;
        pz = charpos.z;
    } else if ( ISVALIDPI(pi) && (pi->getContSerial()==INVALID)) {
        px = pi->getPosition("x");
        py = pi->getPosition("y");
        pz = pi->getPosition("z");
    } else {
        px = 0;
        py = 0;
        pz = 0;
    }
}
Exemple #15
0
void RcvAttack(NXWCLIENT ps)
{

	if ( ps == NULL )
			return;
	NXWSOCKET  s=ps->toInt();
	P_CHAR pc = ps->currChar();
	VALIDATEPC( pc );
	P_CHAR victim=pointers::findCharBySerPtr(buffer[s] +1);
	VALIDATEPC( victim );

	if( pc->dead )
			deadattack( s, DEREF_P_CHAR(victim) );
	else
		if( pc->jailed )
			sysmessage(s,TRANSLATE("There is no fighting in the jail cells!"));
		else
			AttackStuff(s,victim);



}
/////////////
// Name:	reverseIncognito
// Purpose:	undo the effects of the incognito spell
// History: by AntiChrist
//			isolated from two functions by Duke, 10.6.2001
//
static void reverseIncognito(P_CHAR pc)
{
    CHARACTER c = DEREF_P_CHAR(pc);

    if(pc->incognito)//let's ensure it's under incognito effect!
    {
        pc->id1=pc->xid1;	// SEX
        pc->id2=pc->xid2;

        pc->skin = pc->xskin;	// SKIN COLOR

        strcpy(pc->name,pc->orgname);	// NAME

        if(pc->hairserial>-1)//if hairs exist, restore hair style/color
        {
            P_ITEM pHair = FindItemBySerial(pc->hairserial);
            if(pHair)
            {
                if(pHair->incognito) //let's ensure it was marked as under incognito effect
                {
                    //stores old hair values
                    pHair->color1=pHair->moreb1;
                    pHair->color2=pHair->moreb2;
                    pHair->id1=pHair->moreb3;
                    pHair->id2=pHair->moreb4;
                    pHair->incognito=false;
                }
            }
        }

        if(pc->beardserial>-1)//if beard exists, restore beard style/color
        {
            P_ITEM pBeard = FindItemBySerial(pc->beardserial);
            if(pBeard)
            {
                if(pBeard->incognito) //let's ensure it was marked as under incognito effect
                {
                    //restores old beard values
                    pBeard->color1=pBeard->moreb1;
                    pBeard->color2=pBeard->moreb2;
                    pBeard->id1=pBeard->moreb3;
                    pBeard->id2=pBeard->moreb4;
                    pBeard->incognito=false;
                }
            }
        }

        //only refresh once, when poly finished
        teleport(c);
        int socket=calcSocketFromChar(c);//calculate only once
        if (socket!=-1)
        {
            wornitems(socket, c);//send update to current socket
            int j;
            for (j=0; j<now; j++)
            {   //and to all inrange sockets (without re-sending to current socket)//AntiChrist
                if (perm[j] && inrange1p(c, currchar[j]) && (j!=socket))
                    wornitems(j, c);
            }
        }
        pc->incognito=false;//AntiChrist
    }
}
void cTmpEff::Expire()
{
    int k,ccc;

    P_CHAR pc_s = FindCharBySerial(getDest());
    if (   num != 9		// grinding
            && num != 10	// create potion
            && num != 13	// door close
            && num != 14	// training dummy
            && num != 17)	// explosion
    {
        //Added by TANiS to fix errors, memory corruption and door auto-close 10-6-98
        // Check to see if it's a dead char and delete the wrong effect, or if it's just
        // a door auto-close effect and process it the right way.
        if ( pc_s == NULL )
        {
            return;		// just remove this effect
        } //End of TANiS' change
    }

    switch(num)
    {
    case 1:
        if (pc_s->priv2&0x02)
        {
            pc_s->priv2 &= 0xFD;
            int sk=calcSocketFromChar(DEREF_P_CHAR(pc_s));
            if (sk!=-1) sysmessage(sk, "You are no longer frozen.");
            Magic->afterParticles(38, DEREF_P_CHAR(pc_s));
        }
        break;
    case 2:
        pc_s->fixedlight='\xFF';
        dolight(calcSocketFromChar(DEREF_P_CHAR(pc_s)), worldbrightlevel);
        break;
    case 3:
        pc_s->chgDex(more1);
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 4:
        pc_s->in+=more1;
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 5:
        pc_s->st+=more1;
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 6:
        pc_s->chgDex(-1 * more1);
        pc_s->stm=min(pc_s->stm, (int)pc_s->effDex());
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 7:
        pc_s->in-=more1;
        pc_s->mn=min(pc_s->mn, pc_s->in);
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 8:
        pc_s->st-=more1;
        pc_s->hp=min(pc_s->hp, pc_s->st);
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 9:
        if (more1 == 0)
        {
            if (more2!=0)
            {
                sprintf((char*)temp, "*%s continues grinding.*", pc_s->name);
                npcemoteall(DEREF_P_CHAR(pc_s), (char*)temp,1);
            }
            soundeffect2(DEREF_P_CHAR(pc_s), 0x02, 0x42);
        }
        break;
    case 10:
    {
        pc_s = FindCharBySerial(getSour());
        P_ITEM pMortar = FindItemBySerial(getDest());
        if(pMortar != NULL) //AntiChrist - to prevent crashes
            Skills->CreatePotion(DEREF_P_CHAR(pc_s), more1, more2, pMortar);
    }
    break;
    case 11:
        pc_s->st-=more1;
        pc_s->hp=min(pc_s->hp, pc_s->st);
        pc_s->chgDex(-1 * more2);
        pc_s->stm=min(pc_s->stm, (int)pc_s->effDex());
        pc_s->in-=more3;
        pc_s->mn=min(pc_s->mn, pc_s->in);
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 12:
        pc_s->st+=more1;
        pc_s->chgDex(more2);
        pc_s->in+=more3;
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_s)), DEREF_P_CHAR(pc_s));
        break;
    case 13:
    {
        P_ITEM pDoor = FindItemBySerial(getDest());// door
        if (pDoor)
        {
            if (pDoor->dooropen==0)
                break;
            pDoor->dooropen=0;
            dooruse(calcSocketFromChar(DEREF_P_CHAR(pc_s)), pDoor);
        }
        break;
    }
    case 14: //- training dummies Tauriel check to see if item moved or not before searching for it
    {
        P_ITEM pTrainDummy = FindItemBySerial(getDest());
        if (pTrainDummy)
        {
            if (pTrainDummy->id()==0x1071)
            {
                pTrainDummy->setId(0x1070);
                pTrainDummy->gatetime=0;
                RefreshItem(pTrainDummy);//AntiChrist
            }
            else if (pTrainDummy->id()==0x1075)
            {
                pTrainDummy->setId(0x1074);
                pTrainDummy->gatetime=0;
                RefreshItem(pTrainDummy);//AntiChrist
            }
        }
    }
    break;
    case 15: //reactive armor
        pc_s->ra=0;
        break;
    case 16: //Explosion potion messages	Tauriel
        sprintf((char*)temp, "%i", more3);
        sysmessage(calcSocketFromChar(DEREF_P_CHAR(pc_s)), (char*)temp); // crashfix, LB
        break;
    case 17: //Explosion potion explosion	Tauriel
        pc_s = FindCharBySerial(getSour());
        explodeitem(calcSocketFromChar(DEREF_P_CHAR(pc_s)), FindItemBySerial(getDest())); //explode this item
        break;
    case 18: //Polymorph spell by AntiChrist 9/99
        if(pc_s->polymorph)//let's ensure it's under polymorph effect!
        {
            pc_s->id1=pc_s->xid1;
            pc_s->id2=pc_s->xid2;
            pc_s->polymorph=false;
            teleport(DEREF_P_CHAR(pc_s));
        }
        break;
    case 19: //Incognito spell by AntiChrist 12/99
        reverseIncognito(pc_s);
        break;

    case 20: // LSD potions, LB 5'th nov 1999
        k=calcSocketFromChar(DEREF_P_CHAR(pc_s));
        if (k==-1) return;
        LSD[k]=0;
        sysmessage(k,"LSD has worn off");
        pc_s->stm=3; // stamina near 0
        pc_s->mn=3;
        pc_s->hp=pc_s->hp/7;
        impowncreate(k,DEREF_P_CHAR(pc_s),0);
        all_items(k); // absolutely necassairy here !!!
        for (ccc =0; ccc<charcount; ccc++) // that hurts, but there's no other good way
        {
            if (chardist(DEREF_P_CHAR(pc_s),ccc)<15 && ( online(ccc) || chars[ccc].isNpc() ) ) updatechar(ccc);
        }
        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;
        break;

    case 33: // delayed hiding for gms after flamestrike effect
        k=calcSocketFromChar(DEREF_P_CHAR(pc_s));
        sysmessage(k,"You have hidden yourself well.");
        pc_s->hidden=1;
        updatechar(DEREF_P_CHAR(pc_s));
        break;

    case 34: // delayed unhide for gms
        // Changed to be uniform with delayed hideing  (Aldur)
        k = calcSocketFromChar(DEREF_P_CHAR(pc_s));
        sysmessage(k, "You are now visible.");
        pc_s->hidden = 0;
        updatechar(DEREF_P_CHAR(pc_s));
        break;

    case 35: //heals some pf - solarin
        int iHp;
        iHp=(int)more1;
        pc_s->hp+=iHp;
        updatestats(DEREF_P_CHAR(pc_s), 0);
        if (!more2)
            tempeffect(DEREF_P_CHAR(pc_s),DEREF_P_CHAR(pc_s),35,more1+1,1,more3,0);
        break;

    default:
        LogErrorVar("Fallout of switch (num = %i).", num);
        break;
    }
    Items->CheckEquipment(pc_s); //AntiChrist - checks equipments for stats requirements
}
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->id1=pc_s->xid1;
            pc_s->id2=pc_s->xid2;
            pc_s->polymorph=false;
            teleport(DEREF_P_CHAR(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 cCharStuff::CheckAI(unsigned int currenttime, int i) //Lag Fix -- Zippy
{
	int d, onl;
	unsigned int chance;
	//unsigned int StartGrid, getcell, increment, a, checkgrid;
	P_CHAR pc_i = MAKE_CHARREF_LR(i);
	if (i<0 || i>cmem) return;

	if (!(nextnpcaitime<=currenttime||(overflow))) return;
    // in npc.scp add script # for npc`s ai
	// case - script - case - script -   case - script -  case - script
	//   0   -  0     -  4    -  4     -  8    -  8     -  12   -  C
	//   1   -  1     -  5    -  5     -  9    -  9     -  13   -  D
	//   2   -  2     -  6    -  6     -  10   -  A     -  14   -  E
	//   3   -  3     -  7    -  7     -  11   -  B     -  15   -  F
	// case - script - case - script
	//   16  -  10    -  20   -  14
	//   17  -  11    -  21   -  15
	//   18  -  12    -  22   -  16
	//   19  -  13    -  23   -  17  ...this is just a guide...Ripper
	switch(pc_i->npcaitype)
	{
	case 0: // Shopkeepers greet players..Ripper
		if(server_data.VendorGreet==1 && pc_i->isNpc() && pc_i->shop==1 && pc_i->id1==0x01 && (pc_i->id2==0x90 || pc_i->id2==0x91))
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (d > 3)
						continue;
					if (pc->isInvul() || pc->isNpc() || pc->dead || !pc->isInnocent() || !onl)
					    continue;
						sprintf((char*)temp,"Hello %s, Welcome to my shop, How may i help thee?.", pc->name);
						npctalkall(i,(char*)temp,1);
						pc_i->antispamtimer=uiCurrentTime+MY_CLOCKS_PER_SEC*30;
				}
			}
		}
		break;
	case 1: // good healers
		if(!pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (!pc->dead || d > 3 || pc->isNpc() || !onl)
						continue;
					if (pc->isMurderer()) 
					{
						npctalkall(i, "I will nay give life to a scoundrel like thee!",1);
						return;
					}
					else if (pc->isCriminal()) 
					{
						npctalkall(i, "I will nay give life to thee for thou art a criminal!",1);
						return;
					}
					else if (pc->isInnocent())
					{
						npcaction(i, 0x10);
						Targ->NpcResurrectTarget(DEREF_P_CHAR(pc));
						staticeffect(DEREF_P_CHAR(pc), 0x37, 0x6A, 0x09, 0x06);
						switch(RandomNum(0, 4)) 
						{
						case 0: npctalkall(i, "Thou art dead, but 'tis within my power to resurrect thee.  Live!",1);			break;
						case 1: npctalkall(i, "Allow me to resurrect thee ghost.  Thy time of true death has not yet come.",1);	break;
						case 2: npctalkall(i, "Perhaps thou shouldst be more careful.  Here, I shall resurrect thee.",1);		break;
						case 3: npctalkall(i, "Live again, ghost!  Thy time in this world is not yet done.",1);					break;
						case 4: npctalkall(i, "I shall attempt to resurrect thee.",1);											break;
						}
					}
				}
			}
		}
		break;
	case 2 : // Monsters, PK's - (stupid NPCs)
		if (!pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					chance = RandomNum(1, 100);
					if (DEREF_P_CHAR(pc) == i)
						continue;
					if (d>SrvParms->attack_distance)
						continue;
					if (onl &&(pc->isInvul() || pc->isHidden() || pc->dead))
						continue;
					if (pc->isNpc() &&(pc->npcaitype == 2) || pc->npcaitype == 1)
						continue;
					if (server_data.monsters_vs_animals == 0 && (strlen(pc->title) > 0 || !onl))
						continue;
					if (server_data.monsters_vs_animals == 1 && chance > server_data.animals_attack_chance)
						continue;
					if (pc_i->baseskill[MAGERY]>400)
					{
						if (pc_i->hp < (pc_i->st/2))
						{
							npctalkall(i, "In Vas Mani", 0);
							Magic->NPCHeal(i);
						}
						if (pc_i->poisoned)
						{
							npctalkall(i, "An Nox", 0);
							Magic->NPCCure(i);
						}
						if (pc->priv2&0x20)
						{
							npctalkall(i, "An Ort", 0);
							Magic->NPCDispel(i, DEREF_P_CHAR(pc));
						}
					}
					npcattacktarget(i, DEREF_P_CHAR(pc));
					return;
				}
			}
		}
		break;
	case 3 : //Evil Healers
		if(!pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (!pc->dead || d > 3 || pc->isNpc() || !onl)
						continue;
					if (pc->isInnocent())
					{
						npctalkall(i, "I dispise all things good. I shall not give thee another chance!",1);
						return;
					}
					else
					{
						npcaction(i, 0x10);
						Targ->NpcResurrectTarget(DEREF_P_CHAR(pc));
						staticeffect(DEREF_P_CHAR(pc), 0x37, 0x09, 0x09, 0x19); //Flamestrike effect
						switch(RandomNum(0, 4)) 
						{
						   case 0: npctalkall(i, "Fellow minion of Mondain, Live!!",1); break;
						   case 1: npctalkall(i, "Thou has evil flowing through your vains, so I will bring you back to life.",1); break;
						   case 2: npctalkall(i, "If I res thee, promise to raise more hell!.",1); break;
						   case 3: npctalkall(i, "From hell to Britannia, come alive!.",1); break;
						   case 4: npctalkall(i, "Since you are Evil, I will bring you back to consciouness.",1); break;
						}
					}
				}
			}
		}
		break;
	case 4 : // Guards
		if (!pc_i->war	// guard isnt busy 
			&& pc_i->inGuardedArea())	// this region is guarded
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (d > 10 || pc->isInvul() || pc->dead || !onl)
						continue;
						npcattacktarget(i, DEREF_P_CHAR(pc));
						npctalkall(i, "Thou shalt regret thine actions, swine!",1); // ANTISPAM !!! LB
				}
			}
		}
		break;
	case 5: // npc beggars
		if (!pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (d > 3 || pc->isInvul() || pc->isNpc() || pc->dead || !onl || !pc->isInnocent())
					    continue;
						int beg= RandomNum (0,2);
						{
							switch (beg)
							{
								case 0: npctalkall(i,"Could thou spare a few coins?",1);
										pc_i->antispamtimer=uiCurrentTime+MY_CLOCKS_PER_SEC*30;
										break;
								case 1: npctalkall(i,"Hey buddy can you spare some gold?",1);
										pc_i->antispamtimer=uiCurrentTime+MY_CLOCKS_PER_SEC*30;
										break;
								case 2: npctalkall(i,"I have a family to feed, think of the children.",1);
										pc_i->antispamtimer=uiCurrentTime+MY_CLOCKS_PER_SEC*30;
										break;
								default:
										break;
							}
						}
				}
			}
		}
		break;
	case 6: break; // Ripper- chaos guards.
	case 7: break; // Ripper- order guards.
	case 8: break; //morrolan - old banker
	case 9 : // in world guards, they dont teleport out...Ripper
		if (!pc_i->war	// guard isnt busy 
			&& pc_i->inGuardedArea())	// this region is guarded
		{	// this bracket just to keep compiler happy
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (i==DEREF_P_CHAR(pc) || d > 3 || pc->isInvul() || pc->dead || !onl)
						continue;
					if ( pc->isPlayer() && pc->crimflag > 0 )
					{
						sprintf((char*)temp,"You better watch your step %s, I am watching thee!!", pc->name);
						npctalkall(i,(char*)temp,1);
						pc_i->antispamtimer=uiCurrentTime+MY_CLOCKS_PER_SEC*30;
					}
					else if ( pc->isPlayer() && pc->isInnocent() && !pc->dead )
					{
						sprintf((char*)temp,"%s is an upstanding citizen, I will protect thee in %s.", pc->name, region[pc->region].name);
						npctalkall(i,(char*)temp,1);
						pc_i->antispamtimer=uiCurrentTime+MY_CLOCKS_PER_SEC*30;
					}
					else if ( d<=10 && (
							(pc->isNpc() && (pc->npcaitype==2))	// evil npc
							|| (pc->isPlayer() && !(pc->isInnocent()) && !(pc->isCriminal()))	// a player, not grey or blue
							|| (pc->attackfirst==1)))	// any agressor
					{
						pc_i->pos.x=pc->pos.x; //Ripper..guards teleport to enemies.
						pc_i->pos.y=pc->pos.y;
						pc_i->pos.z=pc->pos.z;
						soundeffect2(i, 0x01, 0xFE); // crashfix, LB
						staticeffect(i, 0x37, 0x2A, 0x09, 0x06);
						npcattacktarget(i, DEREF_P_CHAR(pc));
						npctalkall(i, "Thou shalt regret thine actions, swine!",1); // ANTISPAM !!! LB
						return;
					}
				}
			}
		}
		break;
	case 10: // Tamed Dragons ..not white wyrm..Ripper
		// so regular dragons attack reds on sight while tamed.
		if(pc_i->isNpc() && pc_i->tamed)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if(d > 10 || pc->isPlayer() || pc->npcaitype!=2)
						continue;
						npcattacktarget(i,DEREF_P_CHAR(pc));
						return;
				}
			}
		}
		break;
	case 11 : // add NPCAI B in scripts to make them attack reds. (Ripper)
		if (!pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (d > 10 || pc->isInvul() || pc->dead || !onl)
						continue;
					if (pc->npcaitype!=2 || !pc->isCriminal() || !pc->isMurderer())
					    continue;
						npcattacktarget(i, DEREF_P_CHAR(pc));
				}
			}
		}
		break;
	case 17: break; //Zippy Player Vendors.
	case 30: // why is this the same as case 50???..Ripper
		if (!pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (d > 10 || pc->isInvul() || pc->dead || pc->npcaitype!=2 || !onl)
						continue;
						npcattacktarget(i, DEREF_P_CHAR(pc));
						return;
				}
			}
		}
		break;
	case 32: // Pets Guarding..Ripper
		if(pc_i->isNpc() && pc_i->tamed)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (d > 10 || pc->isNpc() || pc->dead || !pc->guarded || !onl)
						continue;
						if(pc->Owns(pc_i))
						{
							npcattacktarget(i,pc->attacker);
							return;
						}
				}
			}
		}
		break;
	case 50://EV/BS
		if (!pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (d > 10 || pc->isInvul() || pc->dead || !onl)
						continue;
						npcattacktarget(i, DEREF_P_CHAR(pc));
						return;
				}
			}
		}
		break;
		// Case 60-70 is Skyfires new AI
	case 96:
	case 60: //Skyfire - Dragon AI
		if (pc_i->war)
		{
			cRegion::RegionIterator4Chars ri(pc_i->pos);
			for (ri.Begin(); ri.GetData() != ri.End(); ri++)
			{
				P_CHAR pc = ri.GetData();
				if (pc != NULL)
				{
					onl = online(DEREF_P_CHAR(pc));
					d = chardist(i, DEREF_P_CHAR(pc));
					if (pc->isNpc() || pc->dead || !onl)
						continue;
						if (d > 4 && pc_i->attacker==DEREF_P_CHAR(pc))
						{
							if (Combat->GetBowType(DEREF_P_CHAR(pc))!=0)
							{
								pc_i->pos.x=pc->pos.x;
								pc_i->pos.y=pc->pos.y;
								pc_i->pos.z=pc->pos.z;
								pc_i->dir=pc->dir;
								teleport(i);
								npctalkall(i,"Foolish Mortal!",0);
							}
						}
						else
						{
							switch(RandomNum(0, 4))
							{
							case 0:	Magic->NPCEBoltTarget(i,DEREF_P_CHAR(pc));			break;
							case 1:	Magic->NPCFlameStrikeTarget(i,DEREF_P_CHAR(pc));	break;
							case 2:	Magic->ParalyzeSpell(i,DEREF_P_CHAR(pc));			break;
							case 3:	Magic->NPCLightningTarget(i,DEREF_P_CHAR(pc));		break;
							case 4:	Magic->ParalyzeSpell(i,DEREF_P_CHAR(pc));			break;
							}
						}
					}
					if (pc_i->hp<(pc_i->st/2))
						Magic->NPCHeal(i);
					if (pc_i->poisoned)
						Magic->NPCCure(i);
					if (pc->priv2&0x20)
						Magic->NPCDispel(i,DEREF_P_CHAR(pc));
					npcattacktarget(i, DEREF_P_CHAR(pc));
					return;
			}
		}
		else
		{
			if (pc_i->hp<(pc_i->st/2))
				Magic->NPCHeal(i);
			if (pc_i->poisoned)
				Magic->NPCCure(i);
		}
		break;
	default:
		clConsole.send("ERROR: cCharStuff::CheckAI-> Error npc %i (%x %x %x %x) has invalid AI type %i\n",i,pc_i->ser1,pc_i->ser2,pc_i->ser3,pc_i->ser4,pc_i->npcaitype); //Morrolan
		return;
	}// switch
}// void checknpcai
void get_item(P_CLIENT ps) // Client grabs an item
{
	int x,  npc=-1, c, amount, update = 0, serial;
//	tile_st tile;
	int z;// antichrist for trade fix
	UOXSOCKET s = ps->GetSocket();
	int cc = ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LR(cc);
	
	
	serial = calcserial(buffer[s][1], buffer[s][2], buffer[s][3], buffer[s][4]);
	if (serial == INVALID_SERIAL || buffer[s][1] < 0x40)
		return;	// landscape or a character
	P_ITEM pi = FindItemBySerial(serial);
	if (pi == NULL)
		return;
	
	pc_currchar->disturbMed(s); // Meditation
	
	// Zippy's stealing changes  
	x = DEREF_P_ITEM(pi);
	if (!items[x].isInWorld())  // Find character owning item
	{
		int loopexit = 0;
		do  // Find character owning item
		{
			if (isCharSerial(items[x].contserial))
			{
				npc = calcCharFromSer(items[x].contserial);
			}
			else  // its an item
			{
				if (items[x].isInWorld())
				{
					npc=-1;
					break;
				}
				x = calcItemFromSer(items[x].contserial);
				// ANTICHRIST -- SECURE TRADE FIX
				if (x!=-1) // LB overwriting x is essential here, dont change it!!!
				{
					if (items[x].layer == 0 && items[x].id() == 0x1E5E)
					{
						// Trade window???
						serial = calcserial(items[x].moreb1, items[x].moreb2, items[x].moreb3, items[x].moreb4);
						if (serial == INVALID_SERIAL)
							return;
						z = calcItemFromSer(serial);
						if (z!=-1)
							if ((items[z].morez || items[x].morez))
							{
								items[z].morez = 0;
								items[x].morez = 0;
								sendtradestatus(z, x);
							}
					}
					// Blackwinds Looting is crime implementation
					// changed slightly by Ripper
					if (items[x].corpse != 0 && !pc_currchar->Owns(&items[x])) 
					{ 
						P_CHAR co = FindCharBySerial(items[x].ownserial);
						if (items[x].more2 == 1 && Guilds->Compare(cc, DEREF_P_CHAR(co)) == 0) 
						{ 
							pc_currchar->karma -= 5; 
							criminal(cc);
							sysmessage(s, "You lost some karma!"); 
						} 
						npc = 0;
					} // Criminal stuff
					if (items[x].corpse != 0)
						npc = 0;
				} // end if x!=-1
				
				if (x==-1)
					npc = 0; 
			}
		} while ((npc==-1) &&(++loopexit < MAXLOOPS));
	}
	
	if (npc>0) // 0=corpse, hence >0 ..
	{
		if (!(pc_currchar->isGM()) && npc != cc && ! pc_currchar->Owns(&chars[npc]))
		{// Own serial stuff by Zippy -^ Pack aniamls and vendors.
			bounce[1] = 0;
			Xsend(s, bounce, 2);
			if (ps->IsDragging())
			{
				ps->ResetDragging();
				item_bounce3(pi);
				pi->magic = 3;
			} 
			return;
		}
	}
	// End Zippy's change
	
	// Boats->
	if (x!=-1 && npc!=-1)
	{
		if (items[x].multis>0)
			imultisp.remove(items[x].multis, items[x].serial);
		items[x].startDecay();
		// End Boats Change
		
		// AntiChrist -- for poisoned items
		if (items[x].layer>0)
		{
			chars[npc].removeItemBonus(&items[x]);	// remove BONUS STATS given by equipped special items
		}
		if ((items[x].trigon==1) && (items[x].layer != 0) && (items[x].layer != 15) && (items[x].layer < 19))// -Frazurbluu- Trigger Type 2 is my new trigger type *-
		{
			triggerwitem(s, DEREF_P_ITEM(pi), 1); // trigger is fired
		}	
			// AntiChrist -- for poisoned items
		if (items[x].poisoned)
		{
			chars[npc].poison -= items[x].poisoned;
			if (chars[npc].poison < 0)
				chars[npc].poison = 0;
		}
	}
	if (pi != NULL)
	{
		if (pi->corpse != 1)
		{
			UpdateStatusWindow(s, pi);
			if (!pc_currchar->canPickUp(pi))
			{
				bounce[1] = 0;
				Xsend(s, bounce, 2);
				if (ps->IsDragging()) // only restore item if it got draggged before !!!
				{
					ps->ResetDragging();
					item_bounce4(s, pi);
				}
			}
			else
			{
				// AntiChrist bugfix for the bad bouncing bug ( disappearing items when bouncing )
				DRAGGED[s] = 1;
				
				pi->oldx = pi->pos.x;	// first let's save the position
				pi->oldy = pi->pos.y;
				pi->oldz = pi->pos.z;
				pi->oldcontserial = pi->contserial;	// then let's save the container
				pi->oldlayer = pi->layer;	// then the layer
				
				pi->layer = 0;
				if (!pi->isInWorld())
					soundeffect(s, 0x00, 0x57);
				if (pi->amount>1)
				{
					amount = (buffer[s][5] << 8) + buffer[s][6];
					if (amount>pi->amount)
						amount = pi->amount;
					if (amount < pi->amount)
					{
						c=Items->MemItemFree();
						items[c].Init(0);
						memcpy(&items[c], pi, sizeof(cItem));  // Tauriel reduce code faster too
						items[c].SetSerial(itemcount2);
						itemcount2++;

						items[c].amount = pi->amount - amount;
						// Tauriel sorry, there is no way to make this call the item creation stuff
// Why doing it twice?
//						setptr(&itemsp[itemcount2%HASHMAX], c);
//						itemcount2++; // important bugfix for items disappearing, lb
						if (!items[c].isInWorld())
							contsp.insert(items[c].contserial, items[c].serial);
						if (items[c].ownserial!=-1)
							setptr(&ownsp[items[c].ownserial%HASHMAX], c);
						if (items[c].spawnserial!=-1)
							setptr(&spawnsp[items[c].spawnserial%HASHMAX], c);
						
						statwindow(s,cc);
						RefreshItem(c);//AntiChrist
					}
					
					if (pi->id() == 0x0EED) // gold coin
					{
						int packnum = packitem(currchar[s]);
						if (packnum!=-1) // lb
							if (pi->contserial == items[packnum].serial)
								update = 1;
					}
					
					pi->amount = amount;
				}
				
				// Tauriel remove item from world mapcells
				mapRegions->Remove(pi); // remove this item from a map cell
				pi->pos.x = 0;
				pi->pos.y = 0;
				pi->pos.z = 0;
				
				pi->flags.isBeeingDragged=true;
				pi->SetContSerial(-1);
				if (pi != NULL) // Ripper...adds weight to the players cursor when carrying a item.
				{
					int amt = 0, wgt;
					wgt = (int)Weight->LockeddownWeight(pi, &amt, 0);
					pc_currchar->weight += wgt;
					update = 1;
				}
			}
		}
	} // end of if i!=-1
	if (update)
		statwindow(s, DEREF_P_CHAR(pc_currchar));
}
void cCommands::NextCall(int s, int type)
{
	// Type is the same as it is in showgmqueue()
	
	int i, serial;
	int x = 0;
	
	P_CHAR pc_currchar = MAKE_CHARREF_LR(currchar[s]);
	
	if (pc_currchar->callnum != 0)
	{
		donewithcall(s, type);
	}
	if (type == 1) // Player is a GM
	{
		for (i = 1; i < MAXPAGES; i++)
		{
			if (gmpages[i].handled == 0)
			{
				serial = gmpages[i].serial;
				P_CHAR pc_player = FindCharBySerial(serial);
				if (pc_player != NULL)
				{
					sysmessage(s, "");
					sprintf((char*)temp, "Transporting to next call: %s", gmpages[i].name.c_str());
					sysmessage(s, (char*)temp);
					sprintf((char*)temp, "Problem: %s.", gmpages[i].reason.c_str());
					sysmessage(s, (char*)temp);
					sprintf((char*)temp, "Serial number %x", gmpages[i].serial);
					sysmessage(s, (char*)temp);
					sprintf((char*)temp, "Paged at %s.", gmpages[i].timeofcall);
					sysmessage(s, (char*)temp);
					gmpages[i].handled = 1;
					pc_currchar->MoveTo(pc_player->pos.x, pc_player->pos.y, pc_player->pos.z);
					pc_currchar->callnum = i;
					teleport(DEREF_P_CHAR(pc_currchar));
					x++;
				}// if
				if (x > 0)
					break;
			}// if
		}// for
		if (x == 0)
			sysmessage(s, "The GM queue is currently empty");
	} // end first IF
	else // Player is only a counselor
	{
		x = 0;
		for (i = 1; i < MAXPAGES; i++)
		{
			if (counspages[i].handled == 0)
			{
				serial = counspages[i].serial;
				P_CHAR pc_player = FindCharBySerial(serial);
				if (pc_player != NULL)
				{
					sysmessage(s, "");
					sprintf((char*)temp, "Transporting to next call: %s", counspages[i].name.c_str());
					sysmessage(s, (char*)temp);
					sprintf((char*)temp, "Problem: %s.", counspages[i].reason.c_str());
					sysmessage(s, (char*)temp);
					sprintf((char*)temp, "Serial number %x", counspages[i].serial);
					sysmessage(s, (char*)temp);
					sprintf((char*)temp, "Paged at %s.", counspages[i].timeofcall);
					sysmessage(s, (char*)temp);
					gmpages[i].handled = 1;
					pc_currchar->MoveTo(pc_player->pos.x, pc_player->pos.y, pc_player->pos.z);
					pc_currchar->callnum = i;
					teleport(DEREF_P_CHAR(pc_currchar));
					x++;
					break;
				}// if
			}// else
			if (x > 0)
				break;
		}// for
	    if (x == 0)
			sysmessage(s, "The Counselor queue is currently empty");
	}// if
}
void do_lsd(UOXSOCKET s)
{
	P_CHAR pc_currchar = MAKE_CHAR_REF(currchar[s]);
	if (rand()%15==0)
	{
		int c1,c2,color,ctr=0,b,xx,yy,di,icnt=0;
		signed char zz;
		int StartGrid=mapRegions->StartGrid(pc_currchar->pos.x,pc_currchar->pos.y);
		unsigned int increment=0;
		for (unsigned int checkgrid=StartGrid+(increment*mapRegions->GetColSize());increment<3;increment++, checkgrid=StartGrid+(increment*mapRegions->GetColSize()))
		{
			for (int a=0;a<3;a++)
			{
				vector<SERIAL> vecEntries = mapRegions->GetCellEntries(checkgrid + a);
				for ( unsigned int k = 0; k < vecEntries.size(); k++)
				{
					P_ITEM pi = FindItemBySerial(vecEntries[k]);
					P_CHAR mapchar = FindCharBySerial(vecEntries[k]);
					if (pi != NULL)
					{
						 color=(pi->color1<<8)+pi->color2; // fetch item's color and covert to 16 bit
						 if (rand()%44==0) color+=pi->pos.x-pi->pos.y; else
						 color+=pc_currchar->pos.x+pc_currchar->pos.y;
						 color+=rand()%3; // add random "noise"
						 ctr++;
						 // lots of color consistancy checks
						 color=color%0x03E9;
							 c1=color>>8;
						 c2=color%256;
						 if ((((c1<<8)+c2)<0x0002) || (((c1<<8)+c2)>0x03E9) )
						 {
							c1=0x03;
							c2=0xE9;
						 }
						 b=((((c1<<8)+c2)&0x4000)>>14)+((((c1<<8)+c2)&0x8000)>>15);
						 if (b)
						 {
							c1=0x1;
							c2=rand()%255;
						 }
	
						 if (rand()%10==0) zz=pi->pos.z+rand()%33; else zz=pi->pos.z;
						 if (rand()%10==0) xx=pi->pos.x+rand()%3; else xx=pi->pos.x;
						 if (rand()%10==0) yy=pi->pos.y+rand()%3; else yy=pi->pos.y;
						 di = itemdist(DEREF_P_CHAR(pc_currchar), pi);
						 if (di<13) if (rand()%7==0)
						 {
							icnt++;
							if (icnt%10==0 || icnt<10) 
								senditem_lsd(s, pi, c1, c2, xx, yy, zz); // attempt to cut packet-bombing by this thing
						 }
	
					}// end of if item
					else if (mapchar != NULL)// character
					{
						di = chardist(DEREF_P_CHAR(pc_currchar), DEREF_P_CHAR(mapchar));
						if (di<10) if (rand()%10==0)
						{
							icnt++;
							if (icnt%10==0 || icnt<10) 
								sendperson_lsd(s, DEREF_P_CHAR(mapchar),c1,c2); // attempt to cut packet-bombing by this thing
						}
					}
				}
			}
void cDragdrop::wear_item(P_CLIENT ps) // Item is dropped on paperdoll
{
	int j, k;
	tile_st tile;
	int serial, serhash, ci, letsbounce=0; // AntiChrist (5) - new ITEMHAND system
	UOXSOCKET s=ps->GetSocket();
	int cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LR(cc);

	int cserial=calcserial(buffer[s][6],buffer[s][7],buffer[s][8],buffer[s][9]);
	if(cserial==-1) return;
	k=calcCharFromSer( cserial );
	
	if( chars[k].dead )  //Exploit fix: Dead ppl can't equip anything.
		return;
	
	P_ITEM pi=FindItemBySerPtr(buffer[s]+1);
	if (!pi) return;
	pi->flags.isBeeingDragged=false;

//	if (clientDimension[s]==3)
//	{
	Map->SeekTile(pi->id(), &tile);
		
	// sprintf(temp, "Tiledata: name: %s flag1: %i flag2: %i flag3: %i flag4: %i layer: %i\n", tile.name, tile.flag1, tile.flag2, tile.flag3, tile.flag4, tile.layer);
	// clConsole.send(temp);
		
	if (tile.layer==0)
	{
		sysmessage(s,"You can't wear that");
		Sndbounce5(s);
		if (ps->IsDragging())
		{
			ps->ResetDragging();
			item_bounce4(s,pi);
			UpdateStatusWindow(s,pi);
		}
		return;
	}
//	}

	if (pi->id1>=0x40) return; // LB, client crashfix if multi-objects are moved to PD

	if (k==DEREF_P_CHAR(pc_currchar) || pc_currchar->isGM()) 
	{
		if (k!=-1) //lb
			if (k==DEREF_P_CHAR(pc_currchar) && pi->st>chars[k].st)
			{
				sysmessage(s,"You are not strong enough to use that.");
				Sndbounce5(s);
				if (ps->IsDragging())
				{
					ps->ResetDragging();
					item_bounce4(s,pi);
					UpdateStatusWindow(s,pi);
				}
				return;
			}
			
			if (pc_currchar->id1==0x01 && pc_currchar->id2==0x90) // Ripper...so males cant wear female armor
			if (pi->id1==0x1c && ( pi->id2==0x00 || pi->id2==0x02 || pi->id2==0x04 ||
                pi->id2==0x06 || pi->id2==0x08 || pi->id2==0x0a || pi->id2==0x0c))
			{
				sysmessage(s,"You cant wear female armor!");
				Sndbounce5(s);
				if (ps->IsDragging())
                {
					ps->ResetDragging();
					item_bounce4(s,pi);				  
					UpdateStatusWindow(s,pi);
				}
				return;
			}

//			if (clientDimension[s]==2) Map->SeekTile(pi->id(), &tile);
			if ((((pi->magic==2)||((tile.weight==255)&&(pi->magic!=1)))&&((pc_currchar->priv2&1)==0)) ||
				( (pi->magic==3|| pi->magic==4) && !pc_currchar->Owns(pi)))
			{
				item_bounce6(ps,pi);
				return;
			}
		

		// - AntiChrist (4) - checks for new ITEMHAND system
		// - now you can't equip 2 hnd weapons with 1hnd weapons nor shields!!
		serial=pc_currchar->serial;
		vector<SERIAL> vecContainer = contsp.getData(serial);
		for (ci=0;ci<vecContainer.size();ci++)
		{
			P_ITEM pi2 = FindItemBySerial(vecContainer[ci]);
			if (pi2 != NULL && pi2->contserial == serial)
			{
				if (pi2->itmhand==1 && pi->itmhand==1)
				{
					sysmessage(s,"You already have a weapon equipped!");
					letsbounce=1;
				}
				else if (pi2->itmhand==2 && pi->itmhand==1)
				{
					sysmessage(s,"Your hands are both occupied!");
					letsbounce=1;
				}
				else if (pi2->itmhand==1 && pi->itmhand==2)
				{
					sysmessage(s,"You cannot equip a two handed weapon with a weapon equipped!");
					letsbounce=1;
				}
				else if (pi2->itmhand==2 && pi->itmhand==2)
				{
					sysmessage(s,"You cannot equip a two handed weapon with a two handed weapon equipped!");
					letsbounce=1;
				}
				else if (pi2->itmhand==2 && pi->itmhand==3)
				{
					sysmessage(s,"You cannot equip a shield with a two handed weapon equipped!");
					letsbounce=1;
				}
				else if (pi2->itmhand==3 && pi->itmhand==2)
				{
					sysmessage(s,"You cannot equip a two handed weapon with a shield equipped!");
					letsbounce=1;
				}
				else if (pi2->layer == tile.layer) 
				{
 					sysmessage(s, "You already have an armor equipped!");
					letsbounce = 1;
				}
			}
			if(letsbounce)//Let's bounce the item
			{
				Sndbounce5(s);
				if (ps->IsDragging())
				{
					ps->ResetDragging();
					item_bounce4(s,pi);
					UpdateStatusWindow(s,pi);
					itemsfx(s, pi->id());		// antichrist
				}
				return;
			} 
		}
		if (!(pc_currchar->isGM())) //Ripper..players cant equip items on other players or npc`s paperdolls.
		{
			if ((k != DEREF_P_CHAR(pc_currchar)) && (!chars[k].isNpc()))
			{
				sysmessage(s, "You cant put items on other players!");
				item_bounce6(ps,pi);
				return;
			}
		}
		pi->SetContSerial(LongFromCharPtr(buffer[s]+6));
		pi->layer=buffer[s][5];
		// AntiChrist - now the STAT BONUS works -
		pc_currchar->st = (pc_currchar->st + pi->st2);
		pc_currchar->chgDex(pi->dx2);
		pc_currchar->in = (pc_currchar->in + pi->in2);
		if (pi->trigtype==2) // -Frazurbluu- Trigger Type 2 is my new trigger type *-
		{
			Trig->triggerwitem(s, pi, 1); // trigger is fired
		}	
		// AntiChrist -- for poisoned items
		if (showlayer)	clConsole.send("Item equipped on layer %i.\n",pi->layer);
		
		SndRemoveitem(pi->serial);
		
		LongToCharPtr(pi->serial,wearitem+1);
		ShortToCharPtr(pi->id(),wearitem+5);
		wearitem[8]=pi->layer;
		LongToCharPtr(pi->contserial,wearitem+9);
		wearitem[13]=pi->color1;
		wearitem[14]=pi->color2;
		Xsend(s, wearitem, 15);
		wornitems(s, k);//send update to current socket
		// -Frazurbluu- Worn item triggers will need code here
		// Trigger cod ewill also need the adjustments made for skill adding
		// An apply/unapply type of variable must be added for skill gains
		// Spell Item will have to be considered, like a necklace of reflection

		for (j=0;j<now;j++)
		{
			if (perm[j] && inrange1p(k, currchar[j]) && (j!=s))//and to all inrange sockets (without re-sending to current socket)//AntiChrist
				wornitems(j, k);
		}
		
		itemsfx(s, pi->id());	// Dupois - see itemsfx() for details	// Added Oct 09, 1998
		Weight->NewCalc(DEREF_P_CHAR(pc_currchar));	// Ison 2-20-99
		statwindow(s,DEREF_P_CHAR(pc_currchar));
		
		if (pi->glow>0)
		{
			pc_currchar->removeHalo(pi); // if gm equips on differnt player it needs to be deleted out of the hashteble
			chars[k].addHalo(pi);
			chars[k].glowHalo(pi);
		}
    }
}
void cDragdrop::get_item(P_CLIENT ps) // Client grabs an item
{
	int npc=-1, amount, update = 0, serial;
	UOXSOCKET s = ps->GetSocket();
	int cc = ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LR(cc);
	
	
	serial = calcserial(buffer[s][1], buffer[s][2], buffer[s][3], buffer[s][4]);
	if (serial == INVALID_SERIAL || buffer[s][1] < 0x40)
		return;	// landscape or a character
	P_ITEM pi = FindItemBySerial(serial);
	if (pi == NULL)
		return;
	
	pc_currchar->disturbMed(s); // Meditation
	
	// Zippy's stealing changes  
	P_ITEM px = pi;
	if (!px->isInWorld())  // Find character owning item
	{
		unsigned long loopexit = 0;
		do  // Find character owning item
		{
			if (isCharSerial(px->contserial))
			{
				npc = calcCharFromSer(px->contserial);
			}
			else  // its an item
			{
				if (px->isInWorld())
				{
					npc=-1;
					break;
				}
				px = FindItemBySerial(px->contserial);
				// ANTICHRIST -- SECURE TRADE FIX
				if (px != NULL) // LB overwriting x is essential here, dont change it!!!
				{
					if (px->layer == 0 && px->id() == 0x1E5E)
					{
						// Trade window???
						serial = calcserial(px->moreb1, px->moreb2, px->moreb3, px->moreb4);
						if (serial == INVALID_SERIAL)
							return;
						P_ITEM pi_z = FindItemBySerial(serial);
						if ( pi_z != NULL )
							if ((pi_z->morez || px->morez))
							{
								pi_z->morez = 0;
								px->morez = 0;
								sendtradestatus(pi_z, px);
							}
					}
					// Blackwinds Looting is crime implementation
					// changed slightly by Ripper
					if (px->corpse != 0 && !pc_currchar->Owns(px)) 
					{ 
						P_CHAR co = FindCharBySerial(px->ownserial);
						if (px->more2 == 1 && Guilds->Compare(DEREF_P_CHAR(pc_currchar), DEREF_P_CHAR(co)) == 0) 
						{ 
							pc_currchar->karma -= 5; 
							criminal(DEREF_P_CHAR(pc_currchar));
							sysmessage(s, "You lost some karma!"); 
						} 
						npc = 0;
					} // Criminal stuff
					if (px->corpse != 0)
						npc = 0;
				} // end if x!=-1
				
				if (px == NULL)
					npc = 0; 
			}
		} while ((npc==-1) &&(++loopexit < MAXLOOPS));
	}
	
	if (npc>0) // 0=corpse, hence >0 ..
	{
		if (!(pc_currchar->isGM()) && npc != DEREF_P_CHAR(pc_currchar) && ! pc_currchar->Owns(&chars[npc]))
		{// Own serial stuff by Zippy -^ Pack aniamls and vendors.
			bounce[1] = 0;
			Xsend(s, bounce, 2);
			if (ps->IsDragging())
			{
				ps->ResetDragging();
				item_bounce3(pi);
				pi->magic = 3;
			} 
			return;
		}
	}
	// End Zippy's change
	
	// Boats->
	if (px != NULL && npc!=-1)
	{
		if (px->multis>0)
			imultisp.remove(px->multis, px->serial);
		px->startDecay();
		// End Boats Change
		
		// AntiChrist -- for poisoned items
		if (px->layer>0)
		{
			chars[npc].removeItemBonus(px);	// remove BONUS STATS given by equipped special items
		}
		if ((px->trigon==1) && (px->layer != 0) && (px->layer != 15) && (px->layer < 19))// -Frazurbluu- Trigger Type 2 is my new trigger type *-
		{
			Trig->triggerwitem(s, pi, 1); // trigger is fired
		}	
	}
	if (pi != NULL)
	{
		if (pi->corpse != 1)
		{
			UpdateStatusWindow(s, pi);
			if (!pc_currchar->canPickUp(pi))
			{
				bounce[1] = 0;
				Xsend(s, bounce, 2);
				if (ps->IsDragging()) // only restore item if it got draggged before !!!
				{
					ps->ResetDragging();
					item_bounce4(s, pi);
				}
			}
			else
			{
				// AntiChrist bugfix for the bad bouncing bug ( disappearing items when bouncing )
				DRAGGED[s] = 1;
				
				pi->oldx = pi->pos.x;	// first let's save the position
				pi->oldy = pi->pos.y;
				pi->oldz = pi->pos.z;
				pi->oldcontserial = pi->contserial;	// then let's save the container
				pi->oldlayer = pi->layer;	// then the layer
				
				pi->layer = 0;
				if (!pi->isInWorld())
					soundeffect(s, 0x00, 0x57);
				if (pi->amount>1)
				{
					amount = (buffer[s][5] << 8) + buffer[s][6];
					if (amount>pi->amount)
						amount = pi->amount;
					if (amount < pi->amount)
					{
						P_ITEM pi_c = Items->MemItemFree();
						//	pi_c->Init(0);
#pragma note("Replace by a copy constructor before finishing items[]")
						memcpy(pi_c, pi, sizeof(cItem));  // Tauriel reduce code faster too
						pi_c->SetSerial(cItemsManager::getItemsManager().getUnusedSerial());

						pi_c->amount = pi->amount - amount;
						pi_c->SetContSerial(pi_c->contserial);
						pi_c->SetOwnSerial(pi_c->ownserial);
						pi_c->SetSpawnSerial(pi_c->spawnserial);
						
						statwindow(s,DEREF_P_CHAR(pc_currchar));
						RefreshItem(pi_c);//AntiChrist
					}
					
					if (pi->id() == 0x0EED) // gold coin
					{
						P_ITEM packnum = packitem(currchar[s]);
						if (packnum != NULL) // lb
							if (pi->contserial == packnum->serial)
								update = 1;
					}
					
					pi->amount = amount;
					
				}
				
			/*	int amt = 0, wgt; bool tooheavy=false;				
				wgt = (int)Weight->LockeddownWeight(pi, &amt, 0);
				if(pi->contserial>0)
				{
					if (( (pc_currchar->weight+wgt) > (pc_currchar->st*WEIGHT_PER_STR)+30)) // LB -> added: drop item if too heavy
					{
					  float res=float( (pc_currchar->weight+wgt) - ((pc_currchar->st*WEIGHT_PER_STR)+30))*2;
					  int diff = pc_currchar->st;
					  diff -= (int)res;
					  if (diff<=0 && !pc_currchar->isGM() )					   
					  {
						 tooheavy=true;						 						 

						 bounce[1] = 0;
						 Xsend(s, bounce, 2);
						 if (ps->IsDragging()) // only restore item if it got dragged before !!!
						 {
						   ps->ResetDragging();
						   item_bounce4(s, pi);
						 }
						 sysmessage(s, "you can't pick this up, this is too heavy");					 
						 return;
					 }
					}
				} 

                if (!tooheavy) pc_currchar->weight+=wgt;				   
				update = 1;	*/				

				// LB remark: drop item if too heavy is a good solution,
				// but there's still a small bug remaining.
				// added weight from items picked up, but not put to bp, pd,  in other words hold in ones hand, 
				// is NOT subtracted when being dropped again to ground/other chars/other chars' bp's.
				// but this bug doesnt show up becasue weight is re-calculated automatically all 10 secs.
				// without adding weight of the item curently carrying in hand.
				// a correct solutions need the weight of item in hand being stored
				// , added to auto-re-calculation all x-secs code, and being subtracted if dropped.
				// because it's now only happening for leight weight items, because heavy weight itms cant be picke up anymore
				// I haven't corrected this yet. 			
				
				// Tauriel remove item from world mapcells
				mapRegions->Remove(pi); // remove this item from a map cell				
				pi->pos.x = 0;
				pi->pos.y = 0;
				pi->pos.z = 0;
				
				pi->flags.isBeeingDragged=true;
				pi->SetContSerial(-1);
			
			
			}
		}
	} // end of if i!=-1
	if (update) statwindow(s, DEREF_P_CHAR(pc_currchar));
}
void pack_item(P_CLIENT ps, PKGx08 *pp) // Item is put into container
{
	int j, serial;
	bool abort=false;
	UOXSOCKET s=ps->GetSocket();
	CHARACTER cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LR(cc);
	
	serial=pp->Tserial;
	if(serial == INVALID_SERIAL) abort=true;
	const P_ITEM pCont= FindItemBySerial( serial );
	
	serial=pp->Iserial;
	if(serial == INVALID_SERIAL) abort=true;
	const P_ITEM pItem = FindItemBySerial( serial );
	
	if (pCont == NULL)
	{
		RefreshItem(pCont);//AntiChrist
		return;
	} 
	
	if (pItem == NULL || pCont == NULL) return; //LB
	pItem->flags.isBeeingDragged=false;

	if (pItem->id1>=0x40) 
	{ 
	   abort=true; // LB crashfix that prevents moving multi objcts in BP's
       sysmessage(s,"Hey, putting houses in your pack crashes your back and client!");
	}
	j=DEREF_P_CHAR(GetPackOwner(pCont));
	if (j>-1)
		if (chars[j].npcaitype==17 && chars[j].isNpc() && !pc_currchar->Owns(&chars[j]))
		{
			abort=true;
			sysmessage(s, "This aint your vendor!");				
		}

	if(abort)
	{//AntiChrist to preview item disappearing
		item_bounce6(ps,pItem);
		return;
	}

	if (pCont->layer==0 && pCont->id() == 0x1E5E &&
		pc_currchar->Wears(pCont))
	{
		// Trade window???
		serial=calcserial(pCont->moreb1, pCont->moreb2, pCont->moreb3, pCont->moreb4);
		if(serial == INVALID_SERIAL) return;
		P_ITEM pi_z = FindItemBySerial( serial );
		
		if (pi_z != NULL)
			if ((pi_z->morez || pCont->morez))
			{
				pi_z->morez=0;
				pCont->morez=0;
				sendtradestatus(pi_z, pCont);
			}
	}
	
	//
	//AntiChrist - Special Bank Stuff
	//
	//if morey==123  - gold only bank	
	//
	if(SrvParms->usespecialbank)//only if special bank is activated
	{
		if(pCont->morey==123 && pCont->morex==1 && pCont->type==1)
		{
			if ( pItem->id() == 0x0EED )
			{//if they're gold ok
				goldsfx(s, 2);
			} else
			{//if they're not gold..bounce on ground
				sysmessage(s,"You can only put golds in this bank box!");

				pItem->SetContSerial(-1);
				pItem->MoveTo(pc_currchar->pos.x,pc_currchar->pos.y,pc_currchar->pos.z);
				RefreshItem(pItem);//AntiChrist
				itemsfx(s,pItem->id());
				return;
			}
		}
	}
	
	//testing UOP Blocking Tauriel 1-12-99
	if (!pItem->isInWorld())
	{
		item_bounce6(ps,pItem);
		return;
	}
	
	if (!pc_currchar->canPickUp(pItem))
	{
		Sndbounce5(s);
		if (ps->IsDragging())
		{
			ps->ResetDragging();
			item_bounce3(pItem);
			if (pCont->id1>=0x40)
				senditem(s, pCont);
		}
		return;
	}
	// - Trash container
	if (pCont->type==87)
	{
		Items->DeleItem(pItem);
		sysmessage(s, "As you let go of the item it disappears.");
		return;
	}
	// - Spell Book
	if (pCont->type==9)
	{
		if (!IsSpellScroll72(pItem->id()))
		{
			sysmessage(s, "You can only place spell scrolls in a spellbook!");
			Sndbounce5(s);
			if (ps->IsDragging())
			{
				ps->ResetDragging();
				item_bounce3(pItem);
			}
			if (pCont->id1>=0x40)
				senditem(s, pCont);
			return;
		}
		P_ITEM pBackpack = Packitem(pc_currchar);
		if (pBackpack != NULL) // lb
		{
			if (!pc_currchar->Wears(pCont) &&
				(!(pCont->contserial==pBackpack->serial)) && (!(pc_currchar->canSnoop())))
			{
				sysmessage(s, "You cannot place spells in other peoples spellbooks.");
				item_bounce6(ps,pItem);
				return;
			}
			
			if(pItem->name[0]=='#')
				pItem->getName(temp2);
			else
				strcpy((char*)temp2,pItem->name);

			vector<SERIAL> vecContainer = contsp.getData(pCont->serial);
			for (unsigned int i = 0; i < vecContainer.size(); i++) // antichrist , bugfix for inscribing scrolls
			{
				P_ITEM pi = FindItemBySerial(vecContainer[i]);
				if (pi != NULL)
				{
					if(pi->name[0]=='#')
						pi->getName(temp);
					else
						strcpy((char*)temp, pi->name);

					if(!(strcmp((char*)temp,(char*)temp2)) || !(strcmp((char*)temp,"All-Spell Scroll")))
					{
						sysmessage(s,"You already have that spell!");
						item_bounce6(ps,pItem);
						return;
					}
				}
			}
		}
	}
	
	// player run vendors
	if (!(pCont->pileable && pItem->pileable && pCont->id()==pItem->id()
		|| (pCont->type!=1 && pCont->type!=9)))
	{
		j=DEREF_P_CHAR(GetPackOwner(pCont));
		if (j>-1) // bugkilling, LB, was j=!-1, arghh, C !!!
		{
			if (chars[j].npcaitype==17 && chars[j].isNpc() && pc_currchar->Owns(&chars[j]))
			{
				pc_currchar->inputitem = pItem->serial;
				pc_currchar->inputmode = cChar::enPricing;
				sysmessage(s, "Set a price for this item.");
			}
		}

		short xx=pp->TxLoc;
		short yy=pp->TyLoc;

		pCont->AddItem(pItem,xx,yy);
		
		itemsfx(s, pItem->id());// see itemsfx() for details - Dupois Added Oct 09, 1998
		statwindow(s,DEREF_P_CHAR(pc_currchar));
	}
	// end of player run vendors
	
	else
		// - Unlocked item spawner or unlockable item spawner
		if (pCont->type==63 || pCont->type==65 || pCont->type==66)
		{
			pItem->SetContSerial(pp->Tserial);

			// lb bugfix
			pItem->pos.x=pp->TxLoc;
			pItem->pos.y=pp->TyLoc;
			pItem->pos.z=pp->TzLoc;
			
			SndRemoveitem(pItem->serial);
			RefreshItem(pItem);//AntiChrist
			itemsfx(s, pItem->id());
			
		}
		else  // - Pileable
			if (pCont->pileable && pItem->pileable && pCont->id()==pItem->id())
			{		
				if ((pCont->amount+pItem->amount) > 65535)
				{
					pItem->amount -= (65535-pCont->amount);
					Commands->DupeItem(s, pCont, pItem->amount);
					pCont->amount = 65535;
					Items->DeleItem(pItem);
				}
				else
				{
					pCont->amount=pCont->amount+pItem->amount;
					itemsfx(s, pItem->id());
					Items->DeleItem(pItem);
				}
				SndRemoveitem(pItem->serial);
				RefreshItem(pCont);//AntiChrist
			}
			else
			{
				pItem->pos.x=pp->TxLoc;
				pItem->pos.y=pp->TyLoc;
				pItem->pos.z=pp->TzLoc;
//				pItem->SetContSerial(-1);
				pItem->SetContSerial(pp->Tserial);
				// Tauriel add item to world mapcells
				mapRegions->Add(pItem); //add this item to a map cell
				
				SndRemoveitem(pItem->serial);
				RefreshItem(pCont);//AntiChrist
			}
			
			// - Spell Book
	
			if (pCont->type==9)
				Magic->SpellBook(s, pCont); // LB, bugfix for showing(!) the wrong spell (clumsy) when a new spell is put into opened spellbook

			if (pItem->glow>0) // LB's glowing items stuff
			{
				int p = DEREF_P_CHAR(GetPackOwner(pCont)); 
				pc_currchar->removeHalo(pItem); // if gm put glowing object in another pack, handle glowsp correctly !
				if (p!=-1) 
				{
					chars[p].addHalo(pItem);
					chars[p].glowHalo(pItem);
				}		   
				
			}	
}
bool cAllTmpEff::Add(int source, int dest, int num, unsigned char more1, unsigned char more2, unsigned char more3, short dur)
{
    unsigned int ic; // antichrist' changes
    int color, color1, color2, socket; //used for incognito spell
    int	loopexit=0;

    P_CHAR pc_source = MAKE_CHARREF_LRV(source, 0);
    P_CHAR pc_dest   = MAKE_CHARREF_LRV(dest, 0);
    if (teffectcount>=cmem*5)
        return 0;

    cTmpEff *pTE;
    for (ic=0; ic<teffectcount; ic++)	// If there is already an effect of the same or similar kind, reverse it first (Duke)
    {
        pTE = &teffects[ic];
        if (pTE->getDest() == pc_dest->serial)
        {
            if ((pTE->num==3 && num==3)||
                    (pTE->num==4 && num==4)||
                    (pTE->num==5 && num==5)||
                    (pTE->num==6 && num==6)||
                    (pTE->num==7 && num==7)||
                    (pTE->num==8 && num==8)||
                    (pTE->num==11&& num==11)||
                    (pTE->num==12&& num==12)||
                    (pTE->num==18&& num==18)|| //added Poly reverse - AntiChrist (9/99)
                    (pTE->num==21&& num==21)||
                    (pTE->num==19&& num==19)|| //added Incognito reverse - AntiChrist (12/99)
                    (pTE->num==18&& num==19)|| //reverse poly effect if we have to use incognito - AntiChrist (12/99)
                    (pTE->num==19&& num==18) )  //reverse incognito effect if we have to use poly - AntiChrist (12/99)
            {
                pTE->Reverse();
                AllTmpEff->Remove(pTE);
            }
        }
    }

    pTE=new cTmpEff;
    pTE->Init();
    pTE->setSour(pc_source->serial);
    pTE->setDest(pc_dest->serial);
    pTE->num=num;

    switch (num)
    {
    case 1:
        pc_dest->priv2 |= 0x02;
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/100);
        pTE->more1=0;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 2:	// night sight
        pc_dest->fixedlight=worldbrightlevel;
        dolight(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), worldbrightlevel);
        Magic->afterParticles(6, DEREF_P_CHAR(pc_dest)); // shows particles for UO:3D clients, like On OSI servers

        if(dur > 0)		// if a duration is given (potions), use that (Duke, 30.12.2000)
            pTE->setExpiretime_s(dur);
        else
            pTE->setExpiretime_s(pc_source->skill[MAGERY]*10);
        pTE->more1=0;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 3:
        if (pc_dest->effDex()<more1)
            more1=pc_dest->effDex();
        pc_dest->chgDex(-1 * more1);
        pc_dest->stm=min(pc_dest->stm, (int)pc_dest->effDex());
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 4:
        if (pc_dest->in<more1)
            more1=pc_dest->in;
        pc_dest->in-=more1;
        pc_dest->mn=min(pc_dest->mn, pc_dest->in);
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 5:
        if (pc_dest->st<more1)
            more1=pc_dest->st;
        pc_dest->st-=more1;
        pc_dest->hp=min(pc_dest->hp, pc_dest->st);
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 6:
        if (pc_dest->effDex()+more1>250)
            more1=250-pc_dest->effDex();
        pc_dest->chgDex(more1);
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        if(dur > 0)		// if a duration is given (potions), use that (Duke, 31.10.2000)
            pTE->setExpiretime_s(dur);
        else
            pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 7:
        if (pc_dest->in+more1>255)
            more1=pc_dest->in-255;
        pc_dest->in+=more1;
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 8:
        if (pc_dest->st+more1>255)
            more1=pc_dest->st-255;
        pc_dest->st+=more1;
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        if(dur > 0)		// if a duration is given (potions), use that (Duke, 31.10.2000)
            pTE->setExpiretime_s(dur);
        else			// else use caster's skill
            pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=0;
        pTE->dispellable=1;
        break;
    case 9:
        pTE->setExpiretime_s(more2);
        pTE->more1=more1;
        pTE->more2=more2;
        break;
    case 10:
        pTE->setExpiretime_s(12);
        pTE->more1=more1;
        pTE->more2=more2;
        break;
    case 11: // Bless
        if (pc_dest->st+more1>255)
            more1=pc_dest->st-255;
        if (pc_dest->effDex()+more2>250)
            more2=250-pc_dest->effDex();
        if (pc_dest->in+more3>255)
            more3=pc_dest->in-255;
        pc_dest->st+=more1;
        pc_dest->chgDex(more2);
        pc_dest->in+=more3;
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=more2;
        pTE->more3=more3;
        pTE->dispellable=1;
        break;
    case 12: // Curse
        if (pc_dest->st<more1)
            more1=pc_dest->st;
        if (pc_dest->effDex()<more2)
            more2=pc_dest->effDex();
        if (pc_dest->in<more3)
            more3=pc_dest->in;
        pc_dest->st-=more1;
        pc_dest->chgDex(-1 * more2);
        pc_dest->in-=more3;
        statwindow(calcSocketFromChar(DEREF_P_CHAR(pc_dest)), DEREF_P_CHAR(pc_dest));
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->more1=more1;
        pTE->more2=more2;
        pTE->more3=more3;
        pTE->dispellable=1;
        break;
    case 15: // Reactive armor
        pTE->setExpiretime_s(pc_source->skill[MAGERY]/10);
        pTE->dispellable=1;
        break;
    case 16: //Explosion potions	Tauriel
        pTE->setExpiretime_s(more2);
        pTE->more1=more1; //item/potion
        pTE->more2=more2; //seconds
        pTE->more3=more3; //countdown#
        break;
    case 18: //Polymorph - AntiChrist 09/99
        pTE->setExpiretime_s(polyduration);

        int c1,b,k;
        //Grey flag when polymorphed - AntiChrist (9/99)
        pc_dest->crimflag=(polyduration*MY_CLOCKS_PER_SEC)+uiCurrentTime;
        if(pc_dest->onhorse) k=unmounthorse(DEREF_P_CHAR(pc_dest));
        k=(more1<<8)+more2;

        pc_dest->xid1=pc_dest->id1;//let's backup previous id
        pc_dest->xid2=pc_dest->id2;

        if (k>=0x000 && k<=0x3e1) // lord binary, body-values >0x3e crash the client
        {
            pc_dest->id1=k>>8; // allow only non crashing ones
            pc_dest->id2=k%256;

            c1 = pc_dest->skin; // transparency for monsters allowed, not for players,
            // if polymorphing from monster to player we have to switch from transparent to semi-transparent
            b=c1&0x4000;
            if (b==16384 && (k >=0x0190 && k<=0x03e1))
            {
                if (c1!=0x8000)
                {
                    pc_dest->skin = pc_dest->xskin = 0xF000;
                }
            }
        }
        pc_dest->polymorph=true;
        break;
    case 19://incognito spell - AntiChrist (10/99)//revised by AntiChrist - 9/12/99
        pTE->setExpiretime_s(90);

        //AntiChrist 11/11/99
        //If char is already under polymorph effect, let's reverse the
        //polymorph effect to avoid problems
        if(pc_dest->polymorph)
        {
            pc_dest->id1=pc_dest->xid1;
            pc_dest->id2=pc_dest->xid2;
            pc_dest->polymorph=false;
            teleport(DEREF_P_CHAR(pc_dest));
        }
        int j,ci;

        //first: let's search for beard and hair serial
        //(we could use alredy saved serials...but it's better
        //to recalculate them)
        pc_dest->hairserial=-1;
        pc_dest->beardserial=-1;

        ci=0;
        loopexit=0;
        P_ITEM pi;
        {   // ugly scope restringing... should do for now.
            vector<SERIAL> vecContainer = contsp.getData(pc_dest->serial);
            for ( ci = 0; ci < vecContainer.size(); ci++)
            {
                pi = FindItemBySerial(vecContainer[ci]);
                if(pi->layer==0x10)//beard
                    pc_dest->beardserial=pi->serial;
                if(pi->layer==0x0B)//hairs
                    pc_dest->hairserial=pi->serial;
            }
        }
        // ------ SEX ------
        pc_dest->xid1=pc_dest->id1;
        pc_dest->xid2=pc_dest->id2;
        pc_dest->id1=0x01;
        //if we already have a beard..can't turn to female
        if(pc_dest->beardserial>-1)
        {   //if character has a beard...only male
            pc_dest->id2='\x90';//male
        } else
        {   //if no beard let's randomly change
            if((rand()%2)==0) pc_dest->id2='\x90';//male
            else pc_dest->id2='\x91';//or female
        }

        // --- SKINCOLOR ---
        pc_dest->xskin = pc_dest->skin;
        color=rand()%6;
        switch(color)
        {
        case 0:
            pc_dest->skin = 0x83EA;
            break;
        case 1:
            pc_dest->skin = 0x8405;
            break;
        case 2:
            pc_dest->skin = 0x83EF;
            break;
        case 3:
            pc_dest->skin = 0x83F5;
            break;
        case 4:
            pc_dest->skin = 0x841C;
            break;
        case 5:
            pc_dest->skin = 0x83FB;
            break;
        default:
            break;
        }

        // ------ NAME -----
        strcpy(pc_dest->orgname,pc_dest->name);

        if(pc_dest->id2==0x90) setrandomname(DEREF_P_CHAR(pc_dest),"1");//get a name from male list
        else setrandomname(DEREF_P_CHAR(pc_dest),"2");//get a name from female list

        //
        //damn..this formula seems to include also some bad color...
        //i'll test this later
        //AntiChrist
        //
        //use unique color for hair&beard
        //color=0x044E+(rand()%(0x04AD-0x044E));

        //i had to track down some valid value
        //for hair/beard colors, cause that
        //formula contained some bad value =(
        //but now it works perfectly :)
        //AntiChrist-11/11/99
        color=rand()%8;
        switch(color)
        {
        case 0:
            color=0x044e;
            break;
        case 1:
            color=0x0455;
            break;
        case 2:
            color=0x045e;
            break;
        case 3:
            color=0x0466;
            break;
        case 4:
            color=0x046a;
            break;
        case 5:
            color=0x0476;
            break;
        case 6:
            color=0x0473;
            break;
        case 7:
            color=0x047c;
            break;
        default://it should not go here...but..who nows =P
            color=0x044e;
        }
        color1=color>>8;
        color2=color%256;

        // ------ HAIR -----
        if(pc_dest->hairserial>-1)//if hairs exist
        {   //change hair style/color
            P_ITEM pHair = FindItemBySerial(pc_dest->hairserial);
            if(pHair)
            {
                //stores old hair values...
                pHair->moreb1=pHair->color1;
                pHair->moreb2=pHair->color2;
                pHair->moreb3=pHair->id1;
                pHair->moreb4=pHair->id2;

                //and change them with random ones
                switch(rand()%10)
                {
                case 0:
                    pHair->id2='\x3B';
                    break;
                case 1:
                    pHair->id2='\x3C';
                    break;
                case 2:
                    pHair->id2='\x3D';
                    break;
                case 3:
                    pHair->id2='\x44';
                    break;
                case 4:
                    pHair->id2='\x45';
                    break;
                case 5:
                    pHair->id2='\x46';
                    break;
                case 6:
                    pHair->id2='\x47';
                    break;
                case 7:
                    pHair->id2='\x48';
                    break;
                case 8:
                    pHair->id2='\x49';
                    break;
                case 9:
                    pHair->id2='\x4A';
                    break;
                default:
                    pHair->id2='\x4A';
                    break;
                }

                //random color
                pHair->color1=color>>8;
                pHair->color2=color%256;
                //let's check for invalid values
                if ((((pHair->color1<<8)+pHair->color2)<0x044E) ||
                        (((pHair->color1<<8)+pHair->color2)>0x04AD) )
                {
                    pHair->color1=0x04;
                    pHair->color2=0x4E;
                }

                pHair->incognito=true;//AntiChrist
            }//if j!=-1
        }//if hairserial!=-1
static bool ItemDroppedOnChar(P_CLIENT ps, PKGx08 *pp, P_ITEM pi)
{
	UOXSOCKET s=ps->GetSocket();
	CHARACTER cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LRV(cc,true);
	P_CHAR pTC=FindCharBySerial(pp->Tserial);	// the targeted character
	if (!pTC) return true;

	if (DEREF_P_CHAR(pTC)!=DEREF_P_CHAR(pc_currchar))
	{
		if (pTC->isNpc())
		{
			if(!pTC->isHuman())						
			{
				ItemDroppedOnPet( ps, pp, pi);
			}
			else	// Item dropped on a Human character
			{
				// Item dropped on a Guard (possible bounty quest)
				if( ( pTC->isNpc() ) && ( pTC->npcaitype == 4 ) )
				{
					if (!ItemDroppedOnGuard( ps, pp, pi) )
					{
						Sndbounce5(s);
						if (ps->IsDragging())
						{
							ps->ResetDragging();
							item_bounce5(s,pi);
						}
					}
					return true;
				}
				if ( pTC->npcaitype == 5 )
				{
					if (!ItemDroppedOnBeggar( ps, pp, pi))
					{
						Sndbounce5(s);
						if (ps->IsDragging())
						{
							ps->ResetDragging();
							item_bounce5(s,pi);
						}
					}
					return true;
				}
				if ( pTC->npcaitype == 8 )
				{
					if (!ItemDroppedOnBanker( ps, pp, pi))
					{
						Sndbounce5(s);
						if (ps->IsDragging())
						{
							ps->ResetDragging();
							item_bounce5(s,pi);
						}
					}
					return true;
				}
				
				//This crazy training stuff done by Anthracks ([email protected])
				if(pc_currchar->trainer!=pTC->serial)
				{
					npctalk(s, DEREF_P_CHAR(pTC), "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);
					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()) && !online(DEREF_P_CHAR(pTC)))
			{
				// Drop the item in the players pack instead
				// Get the pack
				P_ITEM pack = Packitem(pTC);
				if (pack != NULL)	// Valid pack?
				{
					pack->AddItem(pi);	// Add it
					Weight->NewCalc(DEREF_P_CHAR(pTC));
				}
				else	// No pack, give it back to the GM
				{
					pack = Packitem(pc_currchar);
					if (pack != NULL)	// Valid pack?
					{
						pack->AddItem(pi);	// Add it
						Weight->NewCalc(DEREF_P_CHAR(pc_currchar));
					}
					else	// Even GM has no pack?
					{
						// Drop it to it's feet
						pi->MoveTo(pc_currchar->pos.x, pc_currchar->pos.y, pc_currchar->pos.z);
						RefreshItem(pi);
					}
				}
			}
			else
			{
				P_ITEM pj = Trade->tradestart(s, DEREF_P_CHAR(pTC)); //trade-stuff
				pi->SetContSerial(pj->serial);
				pi->pos.x=30;
				pi->pos.y=30;
				pi->pos.z=9;
				SndRemoveitem(pi->serial);
				RefreshItem(pi);
			}
		}


	}
	else // dumping stuff to his own backpack !
	{
		ItemDroppedOnSelf( ps, pp, pi);
	}
	return true;
}
void dump_item(P_CLIENT ps, PKGx08 *pp) // Item is dropped on ground or a character
{
//	tile_st tile;
	UOXSOCKET s=ps->GetSocket();
	CHARACTER cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LR(cc);
	
	P_ITEM pi=FindItemBySerial(pp->Iserial);
	if (!pi)
	{
		LogErrorVar("client sent bad itemserial %d",pp->Iserial);
		return;
	}

	Weight->NewCalc(DEREF_P_CHAR(pc_currchar));
	statwindow(s,DEREF_P_CHAR(pc_currchar));
	pi->flags.isBeeingDragged=false;
	
	//Ripper...so order/chaos shields disappear when on ground.
	if( pi->id1 == 0x1B && ( pi->id2 == 0xC3 || pi->id2 == 0xC4 ) )
	{
		soundeffect2(DEREF_P_CHAR(pc_currchar), 0x01, 0xFE);
		staticeffect(DEREF_P_CHAR(pc_currchar), 0x37, 0x2A, 0x09, 0x06);
		Items->DeleItem( pi );
		return;
	}
	
	//test UOP blocking Tauriel 1-12-99
	if (!pi->isInWorld())
	{
		item_bounce6(ps,pi);
		return;
	}
	
	if (!pc_currchar->canPickUp(pi))
	{
		item_bounce6(ps,pi);
		return;
	}
	
	if (buffer[s][5]!=(unsigned char)'\xFF')
	{
		pi->MoveTo(pp->TxLoc,pp->TyLoc,pp->TzLoc);
		pi->SetContSerial(-1);
		
		if (pi->glow)
		{
			pc_currchar->removeHalo(pi);
			pc_currchar->glowHalo(pi);
		}		
		SndRemoveitem(pi->serial);
		RefreshItem(pi);
	}
	else
	{
		ItemDroppedOnChar(ps, pp, pi);
		
		Weight->NewCalc(DEREF_P_CHAR(pc_currchar));  // Ison 2-20-99
		statwindow(s,DEREF_P_CHAR(pc_currchar));
		itemsfx(s, pi->id());	// Dupois - see itemsfx() for details// Added Oct 09, 1998
		
		//Boats !
		if (pc_currchar->multis>0) //How can they put an item in a multi if they aren't in one themselves Cut lag by not checking everytime something is put down
		{
			P_ITEM pi_multi = FindItemBySerial( pc_currchar->multis );
			if (pi_multi != NULL)
			{
				pi_multi = findmulti(pi->pos);
				if (pi_multi != NULL)
					pi->SetMultiSerial(pi_multi->serial);
			}
		}
		//End Bots
	}
}
Exemple #29
0
void AttackStuff(NXWSOCKET  s, P_CHAR victim)
{
	if ( s < 0 || s >= now )
		return;

	P_CHAR attacker = MAKE_CHAR_REF( currchar[s] );
	VALIDATEPC( attacker );
	VALIDATEPC( victim );

	if( attacker->getSerial32() == victim->getSerial32() )
		return;

	
	if ( attacker->amxevents[EVENT_CHR_ONBEGINATTACK]) {
		g_bByPass = false;
		attacker->amxevents[EVENT_CHR_ONBEGINATTACK]->Call( attacker->getSerial32(), victim->getSerial32() );
		if (g_bByPass==true) return;
	}

	if ( victim->amxevents[EVENT_CHR_ONBEGINDEFENSE]) {
		g_bByPass = false;
		victim->amxevents[EVENT_CHR_ONBEGINDEFENSE]->Call( victim->getSerial32(), attacker->getSerial32() );
		if (g_bByPass==true) return;
	}
	/*
	attacker->runAmxEvent( EVENT_CHR_ONBEGINATTACK, attacker->getSerial32(), victim->getSerial32() );
	if (g_bByPass==true)
		return;
	victim->runAmxEvent( EVENT_CHR_ONBEGINDEFENSE, victim->getSerial32(), attacker->getSerial32() );
	if (g_bByPass==true)
		return;
	*/
	attacker->targserial=victim->getSerial32();
	attacker->unHide();
	attacker->disturbMed();

	if( victim->dead || victim->hp <= 0 )//AntiChrist
	{
		attacker->sysmsg( TRANSLATE("That person is already dead!") );
		return;
	}

	if ( victim->npcaitype==NPCAI_PLAYERVENDOR)
	{
		attacker->sysmsg( TRANSLATE("%s cannot be harmed."), victim->getCurrentNameC() );
		return;
	}

	SndAttackOK(s, victim->getSerial32());	//keep the target highlighted
	if (!( victim->targserial== INVALID))
	{
		victim->attackerserial=attacker->getSerial32();
		victim->ResetAttackFirst();
	}
	attacker->SetAttackFirst();
	attacker->attackerserial=victim->getSerial32();

	if( victim->guarded )
	{
		NxwCharWrapper sc;
		sc.fillOwnedNpcs( victim, false, false );
		for ( sc.rewind(); !sc.isEmpty(); sc++ )
		{
			P_CHAR guard = sc.getChar();
			if ( ISVALIDPC( guard ) )
				if ( guard->npcaitype == NPCAI_PETGUARD && ( attacker->distFrom( guard )<= 10 ) )
					npcattacktarget(attacker, guard);
		}
	}

	if ((region[ victim->region].priv & RGNPRIV_GUARDED) && (SrvParms->guardsactive))
	{
		if (victim->IsGrey())
			attacker->SetGrey();

		if (victim->npc==0 && victim->IsInnocent() && (!victim->IsGrey()) && Guildz.compareGuilds( attacker->getGuild(), victim->getGuild() )==0) //REPSYS
		{
			criminal( attacker );
			if (ServerScp::g_nInstantGuard==1)
				npcs::SpawnGuard(attacker, victim,attacker->getPosition() );
		}
		else if( victim->npc && victim->IsInnocent() && !victim->HasHumanBody() && victim->npcaitype!=NPCAI_TELEPORTGUARD )
		{
			criminal( attacker );
			if (ServerScp::g_nInstantGuard==1)
				npcs::SpawnGuard(attacker, victim, attacker->getPosition() );
		}
		else if( victim->npc && victim->IsInnocent() && victim->HasHumanBody() && victim->npcaitype!=NPCAI_TELEPORTGUARD )
		{
			victim->talkAll( TRANSLATE("Help! Guards! I've been attacked!"), 1);
			criminal( victim );
			callguards(DEREF_P_CHAR(victim)); // Sparhawk must check if npcs can call guards
		}
		else if( victim->npc && victim->npcaitype==NPCAI_TELEPORTGUARD)
		{
			criminal( attacker );
			npcattacktarget(victim, attacker);
		}
		else if ((victim->npc || victim->tamed) && !victim->war && victim->npcaitype!=NPCAI_TELEPORTGUARD)
		{
			victim->fight( attacker );
		}
		else
		{
			victim->setNpcMoveTime();
		}
		//attacker->emoteall( "You see %s attacking %s!", 1, attacker->getCurrentNameC(), victim->getCurrentNameC() );
	}
	else	// not a guarded area
	{
		if ( victim->IsInnocent())
		{
			if ( victim->IsGrey())
				attacker->SetGrey();
			if (!victim->npc && (!victim->IsGrey()) && Guildz.compareGuilds(attacker->getGuild(), victim->getGuild() )==0)
			{
				criminal( attacker );
			}
			else if (victim->npc && victim->tamed)
			{
				criminal( attacker );
				npcattacktarget(victim, attacker);
			}
			else if (victim->npc)
			{
				criminal( attacker );
				npcattacktarget(victim, attacker);
				if (victim->HasHumanBody() )
				{
					victim->talkAll(TRANSLATE("Help! Guards! Tis a murder being commited!"), 1);
				}
			}
		}
	}

}
void advancementobjects(int s, int x, int allways)
{
	char sect[512];
	unsigned long loopexit=0;

	P_CHAR pc_s = MAKE_CHARREF_LR(s);

	int pos;
	if ((pc_s->advobj==0)||(allways==1))
	{
		staticeffect(s, 0x37, 0x3A, 0, 15);
		soundeffect2(s, 0x01, 0xE9);
		pc_s->advobj=x;
		openscript("advance.scp");
		sprintf(sect, "ADVANCEMENT %i", x);
		if (!i_scripts[advance_script]->find(sect))
		{
			closescript();
			clConsole.send("ADVANCEMENT OBJECT: Script section not found. Aborting.\n");
			pc_s->advobj=0;
			return;
		}
		else			
			do
			{
				read2();
				if (script1[0]!='}')
				{
					if ((!(strcmp("STR",(char*)script1)))||(!(strcmp("STRENGTH",(char*)script1))))
					{
						pc_s->st= getstatskillvalue((char*)script2);
						pc_s->st2 = pc_s->st;
					}
					if ((!(strcmp("DEX",(char*)script1)))||(!(strcmp("DEXTERITY",(char*)script1))))
					{
						pc_s->setDex(getstatskillvalue((char*)script2));
					}
					if ((!(strcmp("INT",(char*)script1)))||(!(strcmp("INTELLIGENCE",(char*)script1))))
					{
						pc_s->in= getstatskillvalue((char*)script2);
						pc_s->in2 = pc_s->in;
					}
					if ((!(strcmp("ALCHEMY",(char*)script1)))||(!(strcmp("SKILL0",(char*)script1)))) pc_s->baseskill[ALCHEMY] = getstatskillvalue((char*)script2);
					if ((!(strcmp("ANATOMY",(char*)script1)))||(!(strcmp("SKILL1",(char*)script1)))) pc_s->baseskill[ANATOMY] = getstatskillvalue((char*)script2);
					if ((!(strcmp("ANIMALLORE",(char*)script1)))||(!(strcmp("SKILL2",(char*)script1)))) pc_s->baseskill[ANIMALLORE] = getstatskillvalue((char*)script2);
					if ((!(strcmp("ITEMID",(char*)script1)))||(!(strcmp("SKILL3",(char*)script1)))) pc_s->baseskill[ITEMID] = getstatskillvalue((char*)script2);
					if ((!(strcmp("ARMSLORE",(char*)script1)))||(!(strcmp("SKILL4",(char*)script1)))) pc_s->baseskill[ARMSLORE] = getstatskillvalue((char*)script2);
					if ((!(strcmp("PARRYING",(char*)script1)))||(!(strcmp("SKILL5",(char*)script1)))) pc_s->baseskill[PARRYING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("BEGGING",(char*)script1)))||(!(strcmp("SKILL6",(char*)script1)))) pc_s->baseskill[BEGGING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("BLACKSMITHING",(char*)script1)))||(!(strcmp("SKILL7",(char*)script1)))) pc_s->baseskill[BLACKSMITHING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("BOWCRAFT",(char*)script1)))||(!(strcmp("SKILL8",(char*)script1)))) pc_s->baseskill[BOWCRAFT] = getstatskillvalue((char*)script2);
					if ((!(strcmp("PEACEMAKING",(char*)script1)))||(!(strcmp("SKILL9",(char*)script1)))) pc_s->baseskill[PEACEMAKING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("CAMPING",(char*)script1)))||(!(strcmp("SKILL10",(char*)script1)))) pc_s->baseskill[CAMPING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("CARPENTRY",(char*)script1)))||(!(strcmp("SKILL11",(char*)script1)))) pc_s->baseskill[CARPENTRY] = getstatskillvalue((char*)script2);
					if ((!(strcmp("CARTOGRAPHY",(char*)script1)))||(!(strcmp("SKILL12",(char*)script1)))) pc_s->baseskill[CARTOGRAPHY] = getstatskillvalue((char*)script2);
					if ((!(strcmp("COOKING",(char*)script1)))||(!(strcmp("SKILL13",(char*)script1)))) pc_s->baseskill[COOKING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("DETECTINGHIDDEN",(char*)script1)))||(!(strcmp("SKILL14",(char*)script1)))) pc_s->baseskill[DETECTINGHIDDEN] = getstatskillvalue((char*)script2);
					if ((!(strcmp("ENTICEMENT",(char*)script1)))||(!(strcmp("SKILL15",(char*)script1)))) pc_s->baseskill[ENTICEMENT] = getstatskillvalue((char*)script2);
					if ((!(strcmp("EVALUATINGINTEL",(char*)script1)))||(!(strcmp("SKILL16",(char*)script1)))) pc_s->baseskill[EVALUATINGINTEL] = getstatskillvalue((char*)script2);
					if ((!(strcmp("HEALING",(char*)script1)))||(!(strcmp("SKILL17",(char*)script1)))) pc_s->baseskill[HEALING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("FISHING",(char*)script1)))||(!(strcmp("SKILL18",(char*)script1)))) pc_s->baseskill[FISHING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("FORENSICS",(char*)script1)))||(!(strcmp("SKILL19",(char*)script1)))) pc_s->baseskill[FORENSICS] = getstatskillvalue((char*)script2);
					if ((!(strcmp("HERDING",(char*)script1)))||(!(strcmp("SKILL20",(char*)script1)))) pc_s->baseskill[HERDING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("HIDING",(char*)script1)))||(!(strcmp("SKILL21",(char*)script1)))) pc_s->baseskill[HIDING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("PROVOCATION",(char*)script1)))||(!(strcmp("SKILL22",(char*)script1)))) pc_s->baseskill[PROVOCATION] = getstatskillvalue((char*)script2);
					if ((!(strcmp("INSCRIPTION",(char*)script1)))||(!(strcmp("SKILL23",(char*)script1)))) pc_s->baseskill[INSCRIPTION] = getstatskillvalue((char*)script2);
					if ((!(strcmp("LOCKPICKING",(char*)script1)))||(!(strcmp("SKILL24",(char*)script1)))) pc_s->baseskill[LOCKPICKING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("MAGERY",(char*)script1)))||(!(strcmp("SKILL25",(char*)script1)))) pc_s->baseskill[MAGERY] = getstatskillvalue((char*)script2);
					if ((!(strcmp("MAGICRESISTANCE",(char*)script1)))||(!(strcmp("RESIST",(char*)script1)))||(!(strcmp("SKILL26",(char*)script1)))) pc_s->baseskill[MAGICRESISTANCE] = getstatskillvalue((char*)script2);
					if ((!(strcmp("TACTICS",(char*)script1)))||(!(strcmp("SKILL27",(char*)script1)))) pc_s->baseskill[TACTICS] = getstatskillvalue((char*)script2);
					if ((!(strcmp("SNOOPING",(char*)script1)))||(!(strcmp("SKILL28",(char*)script1)))) pc_s->baseskill[SNOOPING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("MUSICIANSHIP",(char*)script1)))||(!(strcmp("SKILL29",(char*)script1)))) pc_s->baseskill[MUSICIANSHIP] = getstatskillvalue((char*)script2);
					if ((!(strcmp("POISONING",(char*)script1)))||(!(strcmp("SKILL30",(char*)script1)))) pc_s->baseskill[POISONING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("ARCHERY",(char*)script1)))||(!(strcmp("SKILL31",(char*)script1)))) pc_s->baseskill[ARCHERY] = getstatskillvalue((char*)script2);
					if ((!(strcmp("SPIRITSPEAK",(char*)script1)))||(!(strcmp("SKILL32",(char*)script1)))) pc_s->baseskill[SPIRITSPEAK] = getstatskillvalue((char*)script2);
					if ((!(strcmp("STEALING",(char*)script1)))||(!(strcmp("SKILL33",(char*)script1)))) pc_s->baseskill[STEALING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("TAILORING",(char*)script1)))||(!(strcmp("SKILL34",(char*)script1)))) pc_s->baseskill[TAILORING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("TAMING",(char*)script1)))||(!(strcmp("SKILL35",(char*)script1)))) pc_s->baseskill[TAMING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("TASTEID",(char*)script1)))||(!(strcmp("SKILL36",(char*)script1)))) pc_s->baseskill[TASTEID] = getstatskillvalue((char*)script2);
					if ((!(strcmp("TINKERING",(char*)script1)))||(!(strcmp("SKILL37",(char*)script1)))) pc_s->baseskill[TINKERING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("TRACKING",(char*)script1)))||(!(strcmp("SKILL38",(char*)script1)))) pc_s->baseskill[TRACKING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("VETERINARY",(char*)script1)))||(!(strcmp("SKILL39",(char*)script1)))) pc_s->baseskill[VETERINARY] = getstatskillvalue((char*)script2);
					if ((!(strcmp("SWORDSMANSHIP",(char*)script1)))||(!(strcmp("SKILL40",(char*)script1)))) pc_s->baseskill[SWORDSMANSHIP] = getstatskillvalue((char*)script2);
					if ((!(strcmp("MACEFIGHTING",(char*)script1)))||(!(strcmp("SKILL41",(char*)script1)))) pc_s->baseskill[MACEFIGHTING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("FENCING",(char*)script1)))||(!(strcmp("SKILL42",(char*)script1)))) pc_s->baseskill[FENCING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("WRESTLING",(char*)script1)))||(!(strcmp("SKILL43",(char*)script1)))) pc_s->baseskill[WRESTLING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("LUMBERJACKING",(char*)script1)))||(!(strcmp("SKILL44",(char*)script1)))) pc_s->baseskill[LUMBERJACKING] = getstatskillvalue((char*)script2);
					if ((!(strcmp("MINING",(char*)script1)))||(!(strcmp("SKILL45",(char*)script1)))) pc_s->baseskill[MINING] = getstatskillvalue((char*)script2);

					// lb, new skills
					if ((!(strcmp("MEDITATION",(char*)script1)))||(!(strcmp("SKILL46",(char*)script1)))) pc_s->baseskill[MEDITATION] = getstatskillvalue((char*)script2);
					if ((!(strcmp("STEALTH",(char*)script1)))||(!(strcmp("SKILL47",(char*)script1)))) pc_s->baseskill[STEALTH] = getstatskillvalue((char*)script2);
					if ((!(strcmp("REMOVETRAPS",(char*)script1)))||(!(strcmp("SKILL48",(char*)script1)))) pc_s->baseskill[REMOVETRAPS] = getstatskillvalue((char*)script2);

					if ((!(strcmp("DYEHAIR",(char*)script1))))
					{
						unsigned int ci;
						vector<SERIAL> vecContainer = contsp.getData(pc_s->serial);
						P_ITEM pi_hair = NULL;
						for (ci = 0; ci < vecContainer.size(); ci++)
						{
							P_ITEM pi_temp = FindItemBySerial(vecContainer[ci]);
							if (pi_temp != NULL)
								if (pi_temp->layer == 0x0B)
								{
									pi_hair = pi_temp;
									break;
								}
						}
						if (pi_hair != NULL)
						{
							x=hex2num(script2);
							pi_hair->color1=x>>8;
							pi_hair->color2=x%256;
							RefreshItem(pi_hair);//AntiChrist
							teleport(DEREF_P_CHAR(pc_s));
						}
					}

					if ((!(strcmp("DYEBEARD",(char*)script1))))
					{
						int ci;
						P_ITEM pi_beard = NULL;
						vector<SERIAL> vecContainer = contsp.getData(pc_s->serial);
						for (ci = 0; ci < vecContainer.size();ci++)
						{
							P_ITEM pi_temp = FindItemBySerial(vecContainer[ci]);
							if (pi_temp != NULL)
								if (pi_temp->layer == 0x10)
								{
									pi_beard = pi_temp;
									break;
								}
						}
						if (pi_beard != NULL)
						{
							x=hex2num(script2);
							pi_beard->color1=x>>8;
							pi_beard->color2=x%256;
							RefreshItem(pi_beard);//AntiChrist
							teleport(DEREF_P_CHAR(pc_s));
						}