// This is the skill source.
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>

#include	"skills.h"
#include	"config.h"
#include	"structs.h"
#include	"utils.h"
#include	"db.h"
#include	"functions.h"

extern struct cmd_mode mode[];
extern	char	buf[SMALL_BUFSIZE];
extern	char	buf1[SMALL_BUFSIZE];
extern	char	buf2[SMALL_BUFSIZE];
char	temp[SMALL_BUFSIZE];

// Function will show you what skills you have.
void	do_skills(struct char_data *ch)
{
	int	skil = 0;

	sprintf(buf,"\033[1m\033[33mYour skills\033[0m:-\n\r\n\r");
	send_2_output(buf,ch->desc);

	for(skil = 0;skil < ch->NO_SKILLS;skil++)
  	{
		sprintf(buf,"%10s\n\r",ch->skills[skil].name);
		if(ch->skills[skil+1].useby != LAST_SKL)
		{
			sprintf(buf,"%10s\t\t%10s\n\r",ch->skills[skil].name,ch->skills[skil+1].name);
			skil++;
		}
		send_2_output(buf,ch->desc);
	}	
	if(skil == 0)	
		send_2_output("You have no skills yet...\n\r",ch->desc);
}
// Function will give a skill to another player, if thay can have it. The
// skill is given at base level.
void  do_giveSkill(struct char_data *ch, char *arg)
{
   struct object_data *obj, *obj_next;
	struct char_data *who;
   int count=0;
   int items=0;
	int	skil;
	char	outp[SMALL_BUFSIZE];

	if(ch->NO_SKILLS > 0 || ch->LEVEL == IMP)
	{
		if(!get_arg(buf,arg,1))
   	   send_2_output("Teach nothing, perhaps?\n\r",ch->desc);
		else
		if(!get_target(buf1,arg,2))
   	   send_2_output("Whom do you wish to teach?\n\r",ch->desc);
		else
		if(((who = get_xuser(ch,buf1)) == ch) && ch->LEVEL != IMP)
   	   send_2_output("You can't teach your self new tricks!\n\r",ch->desc);
		else
		if((!who) || !see_char_chk(ch, who))
			send_2_output("That is impossible!\n\r",ch->desc);
		else
			if(IN_ROOM(who) != IN_ROOM(ch) && ch->LEVEL != IMP)
				send_2_output("They don't seem to be here!\n\r",ch->desc);
		else
		{
			sprintf(outp,"\033[1m\033[33m%s\033[0m is trying to teach you \033[36m%s\033[0m\n\r",ch->name,buf);
			send_2_output(outp,who->desc);
			sprintf(outp,"You are trying to teach \033[1m\033[33m%s\033[0m \033[36m%s\033[0m\n\r",who->name,buf);
			send_2_output(outp,ch->desc);
			if(ch->LEVEL < GOD)
			{
				if(who->NO_SKILLS < MAX_SKILLS)
				{
					if(IsSkill(buf))
					{
						if(HasSkill(ch,buf))
						{
							if(CanHaveSkill(who,buf))
							{
								if(!HasSkill(who,buf))
								{
									GiveSkill(who,GetSkillIndex(buf));
									if(who->skills[who->NO_SKILLS].useon == SELF_SKL && who->skills[who->NO_SKILLS].type == ONES_SKL)
										ApplySkill(who,who->NO_SKILLS);
									who->NO_SKILLS++;
									sprintf(outp,"\033[1m\033[33m%s\033[0m now knows \033[36m%s\033[0m.\n\r",who->name,buf);
									send_2_output(outp,ch->desc);
									sprintf(outp,"You have been educated in \033[36m%s\033[0m by \033[1m\033[33m%s\033[0m\n\r",buf,ch->name);
									send_2_output(outp,who->desc);
								}
								else
								{
									sprintf(outp,"\033[1m\033[33m%s\033[0m already has this skill..\n\r",who->name);
									send_2_output(outp,ch->desc);
									sprintf(outp,"You already have this skill..\n\r");
									send_2_output(outp,who->desc);
								}
							}
							else
							{
								sprintf(outp,"\033[1m\033[33m%s\033[0m can not use \033[36m%s\033[0m.\n\r",who->name,buf);
								send_2_output(outp,ch->desc);
								sprintf(outp,"Only a %s can use this skill.\n\r",class[show_skill[GetSkillIndex(buf)].useby].full);
								send_2_output(outp,who->desc);
							}
						}
						else
						{
							sprintf(outp,"You don't have %s to teach!\n\r",buf);
							send_2_output(outp,ch->desc);
							sprintf(outp,"%s can't teach this skill.\n\r",ch->name);
							send_2_output(outp,who->desc);
						}
					}
					else
					{
						sprintf(outp,"There is no such skill!\n\r");
						send_2_output(outp,ch->desc);
						sprintf(outp,"%s is quite mad...There is no such skill!\n\r",ch->name);
						send_2_output(outp,who->desc);
					}
				}
				else
				{
					sprintf(outp,"\033[1m\033[33m%s\033[0m can't learn any more skills.\n\r",who->name);
					send_2_output(outp,ch->desc);
					sprintf(outp,"Your brain hurts, you can't learn \033[36m%s\033[0m\n\r",buf);
					send_2_output(outp,who->desc);
				}
			}
			else
			{
				if(who->NO_SKILLS < MAX_SKILLS)
				{
					if(IsSkill(buf) || strcmp(buf,"all") == 0)
					{
						if((who = get_xuser(ch,buf1)) == ch)
						{
							if(strcmp(buf,"all") == 0)
							{
								int idx;											
								for(idx = 0;show_skill[idx].useby != LAST_SKL;idx++)
								{
									if(!HasSkill(ch,show_skill[idx].name))	
									{
										GiveSkill(ch,idx);
										if(ch->skills[ch->NO_SKILLS].useon == SELF_SKL && ch->skills[ch->NO_SKILLS].type == ONES_SKL)
											ApplySkill(ch,ch->NO_SKILLS);
										ch->NO_SKILLS++;
									}
								}

								send_2_output("You now have all skills\n\r",ch->desc);
								return;
							}
							if(!HasSkill(ch,buf))
							{
								GiveSkill(ch,GetSkillIndex(buf));
								if(ch->skills[ch->NO_SKILLS].useon == SELF_SKL && ch->skills[ch->NO_SKILLS].type == ONES_SKL)
									ApplySkill(ch,ch->NO_SKILLS);
								ch->NO_SKILLS++;
								sprintf(outp,"You now know \033[36m%s\033[0m.\n\r",buf);
								send_2_output(outp,ch->desc);
							}
							else
							{
								sprintf(outp,"You already have this skill..\n\r");
								send_2_output(outp,ch->desc);
							}
						}
						else
						{
							if(HasSkill(ch,buf))
							{
								if(CanHaveSkill(who,buf))
								{
									if(!HasSkill(who,buf))
									{
										GiveSkill(who,GetSkillIndex(buf));
										if(who->skills[who->NO_SKILLS].useon == SELF_SKL && who->skills[who->NO_SKILLS].type == ONES_SKL)
											ApplySkill(who,who->NO_SKILLS);
										who->NO_SKILLS++;
										sprintf(outp,"\033[01m\033[33m%s\033[0m now knows \033[36m%s\033[0m.\n\r",who->name,buf);
										send_2_output(outp,ch->desc);
										sprintf(outp,"You have been educated in \033[36m%s\033[0m by \033[1m\033[33m%s\033[0m\n\r",buf,ch->name);
										send_2_output(outp,who->desc);
									}
									else
									{
										sprintf(outp,"You already have this skill..\n\r");
										send_2_output(outp,who->desc);
										sprintf(outp,"%s already has this skill.\n\r",who->name);
										send_2_output(outp,ch->desc);
									}
								}
								else
								{
									sprintf(outp,"\033[1m\033[33m%s\033[0m can not use \033[36m%s\033[0m.\n\r",who->name,buf);
									send_2_output(outp,ch->desc);
									sprintf(outp,"Only a %s can use this skill.\n\r",class[show_skill[GetSkillIndex(buf)].useby].full);
									send_2_output(outp,who->desc);
								}
							}
							else
							{
								sprintf(outp,"You do not have %s to teach!\n\r",buf);
								send_2_output(outp,ch->desc);
								sprintf(outp,"%s does not know %s to teach it!\n\r",ch->name,buf);
								send_2_output(outp,who->desc);
							}
						}
					}
					else
					{
						send_2_output("No such skill!! ! \n\r",ch->desc);
						sprintf(outp,"Be carefull, I think %s has gone quite mad.\n\rThere is no such skill as %s!\n\r",ch->name,buf);
						send_2_output(outp,who->desc);
					}
				}
				else
				{
					sprintf(outp,"\033[1m\033[33m%s\033[0m can't learn any more skills.\n\r",who->name);
					send_2_output(outp,ch->desc);
					sprintf(outp,"Your brain hurts, you can't learn \033[36m%s\033[0m\n\r",buf);
					send_2_output(outp,who->desc);
				}
			}
		}
	}
	
	return;
}
// Function will display all skills in the game.
// if you pass it a kill name it will look at that one only.
// if you pass it a skill number it will look at the list from that
// point onwards.
void	do_lstskills(struct char_data *ch,char *arg)
{
	int	tmp;
	int	strt = ch->READ_SK;

	sprintf(buf,"\033[1m\033[33mThe skill list :-\033[0m [##] name - description - use by\n\r\n\r");

	send_2_output(buf,ch->desc);

	if(get_arg(buf,arg,1))
		strt = atoi(buf);

	if(strt > (GetLastSkillIndex()-1))
		strt = 0;	

	if(IsSkill(buf))
	{
		for(tmp=0;show_skill[tmp].useby != LAST_SKL;tmp++)
		{
			if(strcmp(show_skill[tmp].name,buf) == 0)
			{
				if(show_skill[tmp].useby == UALL_SKL)
					sprintf(buf,"[%2d] %10s - %s - \033[1mALL\033[0m\n\r",tmp,show_skill[tmp].name,show_skill[tmp].desc);
				else
					sprintf(buf,"[%2d] %10s - %s - %s\n\r",tmp,show_skill[tmp].name,show_skill[tmp].desc,class[show_skill[tmp].useby].full);
			
				send_2_output(buf,ch->desc);
				sprintf(buf,"\n\r\033[32mThere are a total of \033[0m%d\033[32m skills in AXIA.\033[0m\n\r",GetLastSkillIndex());
				send_2_output(buf,ch->desc);
				return;
			}
		}
	}

	for(tmp = strt;show_skill[tmp].useby != LAST_SKL;tmp++)
	{
		if(show_skill[tmp].useby == UALL_SKL)
			sprintf(buf,"[%2d] %10s - %s - \033[1mALL\033[0m\n\r",tmp,show_skill[tmp].name,show_skill[tmp].desc);
		else
			sprintf(buf,"[%2d] %10s - %s - %s\n\r",tmp,show_skill[tmp].name,show_skill[tmp].desc,class[show_skill[tmp].useby].full);
			
		send_2_output(buf,ch->desc);
		if(!(tmp % 15)&& tmp != 0)
		{
			ch->READ_SK = tmp+1;
		
			send_2_output("\n\r\tXskills to exit or lstskils for more.\n\r",ch->desc);
			break;
		}
		else
			ch->READ_SK = 0;
	}
	sprintf(buf,"\n\r\033[32mThere are a total of \033[0m%d\033[32m skills in AXIA.\033[0m\n\r",GetLastSkillIndex());
	send_2_output(buf,ch->desc);
}
void	do_Xskills(struct char_data *ch)
{
	if(ch->READ_SK == 0)
		send_2_output("You need to be looking at the skills first.\n\r",ch->desc);
	else
	{
		ch->READ_SK = 0;
		send_2_output("You have exited the read skills function..\n\r",ch->desc);
	}
}
// function lets the skill loose on the world.
void	do_use_skill(struct char_data *ch,char *arg)
{
	int	idx = 0;
	int	roll = 0;
	int	doskill = 0;

	struct object_data	*obj, *obj_next;
	struct char_data *who;

	get_arg(buf,arg,0);
	
	if(!HasSkill(ch,buf))
	{
		sprintf(temp,"You do not have the \033[36m%s\033[0m skill.\n\rUse the 'skills' command to see what skills you have.\n\r",buf);
		send_2_output(temp,ch->desc);
	}
	else
	{
		idx = GetSkillCharIndex(ch,buf);
	
		// Is the skill a percentage skill?
		if(ch->skills[idx].type == PERC_SKL || ch->skills[idx].value[0] > 0)
		{
			if(ch->LEVEL < IMP)
			{
				roll = (rand() % 100) +1;
				// If yes roll to see if skill was used.
				if((ch->skills[idx].value[0]) >= roll)
				{
					// If successfull - Set doskill = 1.
					doskill = 1;
					ch->skills[idx].value[0] += 1;
				}
/*				else
				{
					sprintf(temp,"You have faild to use the skill...\n\r");
					send_2_output(temp,ch->desc);
				}*/
			}
			else
				doskill =1;
		}
		else // If the skill is not a percentge skill.
			doskill = 1;	// Set doskill to 1.	
		
		// If doskill is equal to 1 then do the skill
		if(doskill)
		{
			get_target(buf1,arg,1);
			// What is the skill to be used on?
			switch(ch->skills[idx].useon)
			{
				case SELF_SKL:	if(ch->skills[idx].durat[0] != EVER_SKL)
										ApplySkill(ch,GetSkillCharIndex(ch,buf));
									else
										send_2_output("You can not get any further benefit from this skill.\n\r",ch->desc);
									break;
				case OBJT_SKL:	if(strlen(buf1) > 0)
									{
										for(obj = CHAR_ROOM->objects;obj;obj=obj_next)
										{
											obj_next = obj->next_in_room;
											if(obj_cmp(buf1,obj))
											{
												UseSkillOn(ch,buf,buf1);
												break;
											}
										}
										if(!obj)
										{
											sprintf(temp,"A %s is not here for you to %s.\n\r",buf1,buf);
											send_2_output(temp,ch->desc);
											sprintf(temp,"%s has tried to %s a %s...! fool..\n\r",ch->name,buf,buf1);
											send_2_room(ch,INVIS_CHK,temp);
										}
									}
									else
									{
										sprintf(temp,"%s what ???\n\r",buf);
										send_2_output(temp,ch->desc);
									}	
									break;
				case OTHR_SKL: if(!(who = get_ch_in_room(ch,buf1)))
									{
										sprintf(temp,"They don't seem to be here..\n\r");
										send_2_output(temp,ch->desc);
									}
									else
										UseSkillOn(ch,buf,buf1);
									break;
				case ROOM_SKL:	
									UseSkillIn(ch,buf);
									break;
				case SPEC_SKL:
									break;
			}
		}
		else //	If doskill is not equal to 1 then print fail message.
		{	
			if(ch->skills[idx].useon != SELF_SKL && ch->skills[idx].useon != ROOM_SKL)
			{
				if(!(get_target(buf1,buf,1)))
				{
					sprintf(temp,"You must use this skill on somthing..\n\r");
					send_2_output(temp,ch->desc);	
				}
				else
				{
					sprintf(temp,"%s %s\n\r",ch->skills[idx].fail[0],buf1);
					send_2_output(temp,ch->desc);
					sprintf(temp,"%s %s\n\r",ch->skills[idx].fail[2],buf1);
					send_2_room(ch,INVIS_CHK,temp);
					if(ch->skills[idx].useon == OTHR_SKL)
					{
						if(!(who = get_ch_in_room(ch,buf)))
						{
							sprintf(temp,"There is no one here by that name!\n\r");
							send_2_output(temp,ch->desc);
						}
						else
						{
							sprintf(temp,"%s %s\n\r",ch->skills[idx].fail[2],buf1);
							send_2_output(temp,who->desc);
						}
					}
				}
			}
			else
			{
				sprintf(temp,"%s",ch->skills[idx].fail[0]);
				send_2_output(temp,ch->desc);
			}
				
		}
	}
}

// Apply a skill to the character.
void	ApplySkill(struct char_data *ch,int idx)
{
	int	lst;
	int	ok = 0;
	int	own;
	int	val = 0;
	
	for(lst = 0;*data_list[lst].name != '\n';lst++)
	{
		if(ch->skills[idx].stat[0] == data_list[lst].number)
		{
			ok = 1;
			val = ch->skills[idx].statto[0];
			break;
		}
	}
	// The value must be coming from my own stats!!
	if(ch->skills[idx].special[0] == OWNS_SKL)
	{
		for(own = 0;*data_list[own].name != '\n';own++)
		{
			if(ch->skills[idx].statto[0] == data_list[own].number)
			{
				val =  ch->desc->character->data[data_list[own].number]; 
				ok = 1;
				break;
			}
		}
	}
	if(ok)
	{
		ok = 0;
		switch(ch->skills[idx].opper[0])
		{
			case EQUL_SKL:
				if(data_list[lst].max >= val && data_list[lst].min <= val)
				{
					ok = 1;
					if(ch->skills[idx].durat[0] == ONOF_SKL && ch->desc->character->data[ch->skills[idx].stat[0]] == val)
					{
						ch->desc->character->data[ch->skills[idx].stat[0]] = ch->skills[idx].value[1];
						sprintf(temp,"%s\n\r",ch->skills[idx].fail[0]);
						send_2_output(temp,ch->desc);
						sprintf(temp,"%s\n\r",ch->skills[idx].fail[2]);
						send_2_room(ch,INVIS_CHK,temp);
					}
					else
					{
						ch->desc->character->data[ch->skills[idx].stat[0]] = val;
						sprintf(temp,"%s\n\r",ch->skills[idx].success[0]);
						send_2_output(temp,ch->desc);
						sprintf(temp,"%s\n\r",ch->skills[idx].success[2]);
						send_2_room(ch,INVIS_CHK,temp);
					}	
				}
				break;
			case PLUS_SKL:
				if(data_list[lst].max >= 
					ch->desc->character->data[ch->skills[idx].stat[0]] + 
					val && data_list[lst].min <= 
					ch->desc->character->data[ch->skills[idx].stat[0]] + 
					val)
				{
					ch->desc->character->data[ch->skills[idx].stat[0]] += val;
					sprintf(temp,"%s\n\r",ch->skills[idx].success[0]);
					send_2_output(temp,ch->desc);
					ok = 1;
				}
				break;
			case MINS_SKL:
				if(data_list[lst].max >= 
					ch->desc->character->data[ch->skills[idx].stat[0]] - 
					val && data_list[lst].min <= 
					ch->desc->character->data[ch->skills[idx].stat[0]] - 
					val)
				{
					ch->desc->character->data[ch->skills[idx].stat[0]] -= val;
					sprintf(temp,"%s\n\r",ch->skills[idx].success[0]);
					send_2_output(temp,ch->desc);
					ok = 1;
				}
				break;
		}
		if(!ok)
		{
			sprintf(temp,"\033[31mThe skill has not given you any benefit at this time.\033[0m\n\r");
			send_2_output(temp,ch->desc);
		}
	}
	else
	{
		// Skill does not affect stats.....
	}
}
// Actualy do the skill. - Old model, needs to be revampd or trashed.
void	DoSkill(struct char_data *ch,char *skill)
{
/*	int	idx;
	int	val = 0;
	int	lst;
	int	ok = 0;	

	idx = GetSkillCharIndex(ch,skill);

	// Is it a % skill.
	if(ch->skills[idx].stat == 0)
	{	
		int roll = (rand() % 100) +1;
		ok = 1;
		// Roll to see if successfull..
		if(roll <= ch->skills[idx].value)
		{
			send_2_output(ch->skills[idx].res,ch->desc);
			sprintf(temp,"%s %s\n\r",ch->name,ch->skills[idx].rres);
			send_2_room(ch,INVIS_CHK,temp);
		}
		else
		{
			sprintf(temp,"You failed to use \033[36m%s\033[0m.\n\r",skill);
			send_2_output(temp,ch->desc);
		}
	}
	// Is it a general skill?
	if(ch->skills[idx].stat == 99)
	{
		ok = 1;
		sprintf(temp,"%s %s\n\r",ch->name);
		send_2_room(ch,INVIS_CHK,ch->skills[idx].rres);
		send_2_output(ch->skills[idx].res,ch->desc);
	}

// Does the skill affect a players stats with a stat?
	for(lst = 0;*data_list[lst].name != '\n';lst++)
		if(ch->skills[idx].value == data_list[lst].number)
			break;
	if(lst < MAX_DATA)
	{
		val = ch->desc->character->data[ch->skills[idx].value];
		switch(ch->skills[idx].mod)
		{
			case PLUS_SKL:
				if(data_list[lst].max >= val && data_list[lst].min <= val) 
				{
					ch->desc->character->data[ch->skills[idx].stat] += val;
					sprintf(temp,"%s\n\r",ch->skills[idx].res);
					send_2_output(temp,ch->desc);
					ok = 1;
				}
				break;
			case MINS_SKL:
				if(data_list[lst].max >= val && data_list[lst].min <= val)
				{
					ch->desc->character->data[ch->skills[idx].stat] -= val;
					sprintf(temp,"%s\n\r",ch->skills[idx].res);
					send_2_output(temp,ch->desc);
					ok = 1;
				}
				break;
			case EQUL_SKL:
				if(data_list[lst].max >= val && data_list[lst].min <= val) 
				{
					if(val != ch->desc->character->data[ch->skills[idx].stat])
					{
						ch->desc->character->data[ch->skills[idx].stat] += val;
						sprintf(temp,"%s\n\r",ch->skills[idx].res);
						send_2_output(temp,ch->desc);
						ok = 1;
					}
					else
					{
						if(ch->skills[idx].durat == ONOF_SKL)
						{
							ch->desc->character->data[ch->skills[idx].stat] =
								data_list[lst].min;	
							ok = -1;
						}
						else
						{
							
						}
					}
				}
				break;
		}
		if(!ok)
		{
			sprintf(temp,"\033[31mThe skill has not given you any benefit.\033[0m\n\r");
			send_2_output(temp,ch->desc);
		}
		if(ok == 1)	
			send_2_room(ch,INVIS_CHK,ch->skills[idx].rres);
		if(ok == -1)
		{	
			send_2_output(ch->skills[idx].rend,ch->desc);
			send_2_room(ch,INVIS_CHK,ch->skills[idx].rrend);
		}
			
	}
	else
	{

	}*/
}
// Can the character use this skill ?
int	CanUseSkillOn(struct char_data *ch,char *skill,char *arg)
{
	int	idx;
	int	RetVal = 1;
	struct char_data *who, *who_next;

	idx = GetSkillIndex(skill);

	if(show_skill[idx].useon == OBJT_SKL)
	{
		struct object_data	*obj, *obj_next;
		for(obj = CHAR_ROOM->objects;obj;obj=obj_next)
		{
			obj_next = obj->next_in_room;
			if(obj_cmp(arg,obj))
			{
				sprintf(temp,"You atempt to use \033[36m%s\033[0m skill on %s\n\r",skill,obj->name);
				send_2_output(temp,ch->desc);
				break;
			}
		}
		if(!obj)
		{
			sprintf(temp,"You can't use this skill on %s!\n\r",arg);
			send_2_output(temp,ch->desc);
			RetVal = 0;
		}
	}

	if(show_skill[idx].useon == OTHR_SKL)
	{
		
		if(!(who = get_ch_in_room(ch,arg)))
		{
			sprintf(temp,"There is no one here by that name!\n\r");
			send_2_output(temp,ch->desc);
			RetVal = 0;
		}
		else
		{
			
			sprintf(temp,"%s \033[1m\033[33m%s\033[0m.\n\r",ch->skills[idx].attempt[0],who->name);
			send_2_output(temp,ch->desc);
			sprintf(temp,"%s %s %s\n\r",ch->name,ch->skills[idx].attempt[1],who->name);
			send_2_char(ch,who,INVIS_CHK,temp);
			sprintf(temp,"%s %s\n\r",ch->name,ch->skills[idx].attempt[2]);
			send_2_output(temp,who->desc);
		}
	}

	return(RetVal);
}
// Use the skill on an object or person.
void	UseSkillOn(struct char_data *ch,char *skill, char *arg)
{
	int	idx,cnt;
	int	ok = 0;
	char	failon[40];

	idx = GetSkillCharIndex(ch,skill);

	if(ch->skills[idx].useon == OBJT_SKL)
	{
		struct object_data	*obj, *obj_next;
		for(obj = CHAR_ROOM->objects;obj;obj=obj_next)
		{
			obj_next = obj->next_in_room;
			if(obj_cmp(arg,obj))
			{
				if(ch->skills[idx].opper[0] == EQUL_SKL)
				{
					if(BTST(obj->TYPE,ch->skills[idx].oftype[0]))
					{
						if(BTST(obj->data[ch->skills[idx].stat[0]],
								ch->skills[idx].statto[0]))
						{
							sprintf(temp,"There is no need to \033[36m%s\033[0m %s.\n\r",skill,obj->name);
							ok = -1;
						}
						else
						{	
							BSET(obj->data[ch->skills[idx].stat[0]],
								ch->skills[idx].statto[0]);
							ok = 1;						
						}
					}
					else
					{
						sprintf(failon,"%s",obj->name);
						break;
					}
				}

				break;
			}
		}
		if(ok == 1)
			sprintf(temp,"%s %s\n\r",ch->skills[idx].success[0],obj->name);
		if(ok == 0)
			sprintf(temp,"%s %s.\n\r",ch->skills[idx].fail[0],failon);

		send_2_output(temp,ch->desc);
	}

	if(ch->skills[idx].useon == OTHR_SKL)
	{
		struct char_data *who, *who_next;
		
		if(!(who = get_ch_in_room(ch,arg)))
		{
			sprintf(temp,"There is no one here by that name!\n\r");
			send_2_output(temp,ch->desc);
		}
		else
		{
			if(who != ch)
				sprintf(temp,"You use your \033[36m%s\033[0m skill on \033[1m\033[33m%s\033[0m.\n\r",skill,who->name);
			else
				sprintf(temp,"You use your \033[36m%s\033[0m skill.\n\r",skill);
			send_2_output(temp,ch->desc);
		}
	}
}
// use the skill in aroom - an environment skill....
void	UseSkillIn(struct char_data *ch,char *skill)
{
	struct	room_flag *room;
	int	idx;

	idx = GetSkillCharIndex(ch,skill);

	if(BTST(ch->in_room->flags,ch->skills[idx].oftype[0]))
	{	
		sprintf(temp,"%s.\n\r",ch->skills[idx].success[0]);
		send_2_output(temp,ch->desc);
		sprintf(temp,"%s %s.\n\r",ch->name,ch->skills[idx].success[2]);
		send_2_room(ch,INVIS_CHK,temp);
		
		switch(ch->skills[idx].stat[0])
		{
			case POS_NUM:	ch->POSITION = ch->skills[idx].statto[0];	
								break; 
		}
	}
	else
	{
		sprintf(temp,"You can't use %s in this room.\n\r",skill);
		send_2_output(temp,ch->desc);
	}
}

