/**************************************************************
 *  Myth Mud improvements ALL by David Spink aka Morglum.     *
 *  This mud is NOT to be copied in whole or in part! No one  *
 *  has the permission to authorise the use of this code.     *
 *  In order to use this code you MUST comply with the terms  *
 *  and conditions in 'license.myth' (as shipped).            *
 **************************************************************/

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"

/*
 * Local functions.
 */

void do_fade( CHAR_DATA *ch, char *argument )
{
    char      arg[MIL];
    CHAR_DATA *victim;
    char buf[MIL];
    int cost = 50;
    argument = one_argument( argument, arg );

    if (IS_NPC(ch)) return;

    if (!IS_HIGHLANDER(ch))
    {
    STC( "Huh?\n\r", ch );
    return;
    }

    if (!IS_SET(ch->pcdata->disc[HIGH_POWERS],HIGH_FADE)) 
    {
    	if (ch->practice < cost) 
	{
	sprintf(buf,"You need another %d primal to be able to fade through reality.\n\r",cost - ch->practice );
	STC(buf,ch);
    	return;
    	}
        else
	{
 	ch->practice -= cost;
        STC("You are now able to fade through reailty.\n\r", ch);
        SET_BIT(ch->pcdata->disc[HIGH_POWERS],HIGH_FADE);
        }
    }
    if ( !IS_NPC(ch) && ch->mana < 500 )
 {
        STC( "You don't have enough mana.\n\r", ch );
        return;
    }
   

    if (arg[0] == '\0')
 {
		STC( "Who do you wish to fade to?\n\r", ch );
		return;
	}

	if ( ( victim = get_char_world( ch, arg))  == NULL)
 {
	STC("Nothing happens.\n\r",ch);
	return;
	}    

	victim = get_char_world(ch, arg);
        if ( victim->in_room == ch->in_room)
 {
		STC( "But you are already there!\n\r", ch );
		return;
	}

	switch (check_moveto_mob(ch, victim))
 {
	case 2:
		guardian_message(victim);
		act("$n just failed to fade into reality here.",ch,NULL,victim,TO_VICT);
		// Drop thru
	case 1:
		act("You failed.",ch,NULL,victim,TO_CHAR);
		return;
	}
	if (IS_NPC(victim) && victim->level > 199)
 {
		act("You failed.",ch,NULL,victim,TO_CHAR);
		return;
	}

    STC("You fade out of reality.\n\r",ch);
    act("$n fades out of reality and vanishes from sight.",ch,NULL,NULL,TO_ROOM);
    char_from_room(ch);
    char_to_room(ch,victim->in_room);
    do_look(ch,"");
    STC("You fade into reality.\n\r",ch);
    act("$N fades into reality.",victim,NULL,ch,TO_ROOM);
    ch->mana -= 500;
    return;
}
    
void do_weaponskill( CHAR_DATA *ch, char *argument )
 {
    char buf[MIL]; 
    int  cost = 100;
   
    if (IS_NPC(ch)) return;
    
    if (!IS_HIGHLANDER(ch) )
 {
        STC("Huh?\n\r",ch);
        return;
    }
    
    if (IS_SET(ch->pcdata->disc[HIGH_POWERS],HIGH_WEAPONSKILL))
 {
        STC("You already got that power.\n\r",ch);
        return;
    }

    if (ch->practice < cost)
 {
        sprintf(buf,"You need another %d primal to get supreme weaponskill.\n\r",cost - ch->practice );
        STC(buf,ch);
        return;
    }
 
    ch->practice -= cost;
    STC("You gain a superior insight in weapons.\n\r",ch);
    SET_BIT(ch->pcdata->disc[HIGH_POWERS],HIGH_WEAPONSKILL);
    return;
}

void do_fast_healing( CHAR_DATA *ch, char *argument )
{
    char buf  [MIL]; 
    int  cost = 75;
   
    if (IS_NPC(ch)) return;
    
    if (!IS_HIGHLANDER(ch) )
    {
        STC("Huh?\n\r",ch);
        return;
    }
    
    if (IS_SET(ch->pcdata->disc[HIGH_POWERS],HIGH_REGENERATE)) 
    {
    STC("You already got that power.\n\r",ch);
    return;
    }

      if (ch->practice < cost)
    {
        sprintf(buf,"You need another %d primal to get Fast Healing.\n\r",cost - ch->practice );
        STC(buf,ch);
        return;
    }
 
    ch->practice -= cost;
    STC("Your body gains the ability to regenerate itself.\n\r",ch);
    SET_BIT(ch->pcdata->disc[HIGH_POWERS],HIGH_REGENERATE);
    return;
}

void do_sword( CHAR_DATA *ch, char *argument )
{
    OBJ_INDEX_DATA *pObjIndex;
    OBJ_DATA *obj;
    char buf[MSL];
    char arg1[MIL];
    char arg2[MIL];
    int vnum = 0;
    int primal,amount,cost = 0;
    
    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );

    if (IS_NPC(ch)) return;
    if (!IS_HIGHLANDER(ch))
    {
    STC("Huh?\n\r",ch);
    return;
    }
  if ( arg1[0] == '\0' )
    {
    STC(" 300 primal - The Ultimate Katana \n\r",ch);
    STC(" 200 primal - Divine Wakazasi\n\r",ch);
    STC(" 175 primal - Katana of Sharpness\n\r",ch);
    STC(" 150 primal - Katana of speed\n\r",ch);
    STC(" 125 primal - Shimmering Wakazasi\n\r",ch);
    STC(" 100 primal - Gleaming Katana\n\n\r",ch);
    STC("To craft a new weapon, type sword followed by the amount of primal points you wish to spend.\n\r",ch);
    return;
    }

	if (!is_number(arg1))
 {
		STC("Please enter a numeric value.\n\r",ch);
		return;
	}

    amount = atoi( arg1 );
    primal = ch->practice;

    	   if (amount>299) {vnum = 29611;cost=300;}
    else if (amount>199) {vnum = 29610;cost=200;}
    else if (amount>174) {vnum = 29609;cost=175;}
    else if (amount>149) {vnum = 29608;cost=150;}
    else if (amount>124) {vnum = 29607;cost=125;}
    else if (amount>99)  {vnum = 29606;cost=100;}
    else if (amount<100)
 {
		STC("Please enter a higher number.\n\r",ch);
		return;
	}
    if (primal < amount)
 {
		STC("You don't have enough primal points.\n\r",ch); 
		return;
	}
    
    if ( vnum == 0 || (pObjIndex = get_obj_index( vnum )) == NULL)
 {
		STC("Missing object, please inform Morglum.\n\r",ch);
		return;
	}
    obj = create_object(pObjIndex, 50);
    obj_to_char(obj, ch);
    ch->practice -= cost;

    sprintf( buf, obj->name, "sword", ch->name );
    free_string( obj->name );
    obj->name = str_dup( buf );

    sprintf( buf, obj->short_descr);
    free_string( obj->short_descr );
    obj->short_descr = str_dup( buf );

    sprintf( buf, obj->description);
    free_string( obj->description );
    obj->description = str_dup( buf );

    free_string( obj->questmaker );
    obj->questmaker = str_dup( ch->name );

    free_string( obj->questowner );
    obj->questowner = str_dup( ch->name );
    obj->level = 60;
    SET_BIT( obj->spectype, SITEM_HIGHLANDER );

    act("$p appears in your hands in a blast of magic.",ch,obj,NULL,TO_CHAR);
    act("$p appears in $n's hands in a blast of magic.",ch,obj,NULL,TO_ROOM);
    return;
}

void do_block( CHAR_DATA *ch, char *argument )
 {
    char buf  [MIL];
    int  cost = 100;
 
    if (IS_NPC(ch)) return;
    
    if (!IS_HIGHLANDER(ch) )
    {
        STC("Huh?\n\r",ch);
        return;
    }
 
    if (IS_SET(ch->pcdata->disc[HIGH_POWERS],HIGH_BLOCK))
    {
    STC("You already got that power.\n\r",ch);
    return;
    }

      if (ch->practice < cost)
    {
        sprintf(buf,"You need another %d primal to get block.\n\r",cost - ch->practice );
        STC(buf,ch);
        return;
    }
        
    ch->practice -= cost;
    STC("You gain the ability to block the path of fleeing enemies.\n\r",ch);
    SET_BIT(ch->pcdata->disc[HIGH_POWERS],HIGH_BLOCK);
    return;
}

/*
void do_selfempower( CHAR_DATA *ch, char *argument)
 {
    
//    AFFECT_DATA af;
//    int sn =skill_lookup("selfempower");
    int mainweapon,weaponsk;
    OBJ_DATA *obj = get_eq_char( ch, WEAR_WIELD);
    if (obj == NULL)  mainweapon=0;
    else
    mainweapon = obj->value[3];
    weaponsk = ch->wpn[mainweapon];
    if (!IS_HIGHLANDER(ch))
    {
    STC("Huh?\n\r",ch);
    return;
    }
    if (ch->pcdata->absorb[ABS_MOB_HP] > 0)
 {
    ch->max_hit  -= ch->pcdata->absorb[ABS_MOB_HP];
    ch->max_mana -= ch->pcdata->absorb[ABS_MOB_HP];
    ch->max_move -= ch->pcdata->absorb[ABS_MOB_HP];
    ch->pcdata->absorb[ABS_MOB_HP] = 0;
    ch->pcdata->absorb[ABS_MOB_MAX_HP] = 0;
    STC( "You feel a lot weaker.\n\r",ch);
    act(" $n starts to look a lot weaker.", ch, NULL, NULL, TO_ROOM );
    return;
    }
 
    if (!IS_CHOSEN(ch))
 {
    ch->max_hit  += weaponsk;
    ch->max_mana += weaponsk;
    ch->max_move += weaponsk; 
    ch->pcdata->absorb[ABS_MOB_HP]   = weaponsk;
    ch->pcdata->absorb[ABS_MOB_MAX_HP]   = weaponsk * 5;
    }

    else
    {
    ch->max_hit  += weaponsk/2;
    ch->max_mana += weaponsk/2;
    ch->max_move += weaponsk/2;
    ch->pcdata->absorb[ABS_MOB_HP]   = weaponsk/2;
    ch->pcdata->absorb[ABS_MOB_MAX_HP]   = (weaponsk/2) * 5;
    }

    act( "$n suddenly looks far stronger.", ch, NULL, NULL, TO_ROOM );
    STC( "You feel much more powerful.\n\r", ch);
    return;
}
*/