/* This code was written for Destiny Mud which has located to destiny.boue.ca port 7000 */

/* Well I figured it was time to get some more of my codes out there, since Kyndig.com says I have 2 really good codes on there (one does suck I admit it, there are things on it that on the mud I own where its at, I have troubles with, I shouldn't have released it, hehe, all well. Here's my cool arena code that I'm gonna release now to the public, enjoy! */

/* fight.c */

/* somewhere in bool damage, after the player has been killed */

    for ( d = descriptor_list; d != NULL; d = d->next )
    {
        if (d->character != NULL && d->connected == CON_PLAYING)
        {

        int value;
        CHAR_DATA *wch;

        wch   = ( d->original != NULL ) ? d->original : d->character;
        value = wch->pot * 1.5;

        if (IS_SET(wch->act2,PLR2_BET) && IS_SET(victim->act,PLR_ARENA) )
        {
            if (!IS_NPC(wch) && !str_cmp(wch->pcdata->bet,ch->name))
                {
                        wch->gold += value;
                        send_to_char("You won the bet!\n\r",wch);
                        REMOVE_BIT(wch->act2,PLR2_BET);
                }
            if (!IS_NPC(wch) && !str_cmp(wch->pcdata->bet,victim->name))
                {
                        send_to_char("You lost the bet!\n\r",wch);
                        REMOVE_BIT(wch->act2,PLR2_BET);
                }
        }
        }
     }

/* merc.h */

#define PLR_ARENA               (M)
#define PLR2_BET        (D)

/* in struct pc_data */

    char *              bet;

/* still in merc.h...........*/
/* arena.c */
int pot                 args( (int value ) );

/* now, you'll need to add in your own SET'S, and REMOVE_BITS, for wherever you want to put them, I have mine scattered all over hehe, don't forget to add in the appropriate things in interp.c and interp.h */

/* now for a file called arena.c */


/***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
 *                                                                         *
 *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
 *  Chastain, Michael Quan, and Mitchell Tse.                              *
 *                                                                         *
 *  In order to use any part of this Merc Diku Mud, you must comply with   *
 *  both the original Diku license in 'license.doc' as well the Merc       *
 *  license in 'license.txt'.  In particular, you may not remove either of *
 *  these copyright notices.                                               *
 *                                                                         *
 *  Much time and thought has gone into this software and you are          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/

/***************************************************************************
*       ROM 2.4 is copyright 1993-1996 Russ Taylor                         *
*       ROM has been brought to you by the ROM consortium                  *
*           Russ Taylor (rtaylor@efn.org)                                  *
*           Gabrielle Taylor                                               *
*           Brian Moore (zump@rom.org)                                     *
*       By using this code, you have agreed to follow the terms of the     *
*       ROM license, in the file Rom24/doc/rom.license                     *
***************************************************************************/
/***************************************************************************
*      Arena code written by Shinji for Destiny Mud                        *
*      Written in the summer of '01 released for the public in '02         *
*    All rights reserved for this code to Tim Hoye (tim_hoye@hotmail.com)  *
*      Destiny Mud is located at destiny.boue.ca port 7000                 *
***************************************************************************/

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

int     atoi            args( ( const char *string ) );


DECLARE_DO_FUN( do_transfer );
DECLARE_DO_FUN( do_echo     );

void do_challenge(CHAR_DATA *ch, char *argument)
{

   CHAR_DATA *victim;
   char buf[MAX_INPUT_LENGTH];
   char arg [MAX_INPUT_LENGTH];

    one_argument(argument,arg);

    if IS_NPC(ch)
    {
        return;
    }


    if (arg[0] == '\0')
    {
	send_to_char("Syntax: challenge <person>\n\r",ch);
	return;
    }

    if ( ( victim = get_char_world( ch, arg ) ) == NULL )
    {
        send_to_char( "They aren't here.\n\r", ch );
        return;
    }

    if ( IS_SET(ch->in_room->room_flags, ROOM_NO_RECALL)
    ||   IS_AFFECTED(ch, AFF_CURSE))
    {
        send_to_char( "The Gods have forsaken you.\n\r", ch );
        return;
    }

    if (is_clan(ch))
    {
	send_to_char("Your in a clan, you must PK them in a real fight to kill them\n\r",ch);
	return;
    }

    if (ch->level < 20)
    {
	send_to_char("You must be level 20 before entering the arena.\n\r",ch);
	return;
    }

    if (victim->level < ch->level - 15)
    {
	send_to_char("Nope this person is out of your reach.\n\r",ch);
	return;
    }

    if (victim == ch)
    {
	return;
    }

    if (IS_SET(victim->act,PLR_ARENA))
    {
	send_to_char("They are already in the arena.\n\r",ch);
	return;
    }

    SET_BIT( ch->act, PLR_ARENA );

    sprintf(buf, "%s 8801",ch->name);
    do_transfer(ch,buf); 

    sprintf( buf, "{R[ARENA]: {W%s {bhas just challenged {W%s {bto a friendly duel{x\n\r",ch->name,victim->name );    
    do_echo( ch, buf );
    send_to_char("You have been challenged in the arena to deny challenge, just sit there and do nothing.\n\r",victim);

} 


void do_accept(CHAR_DATA *ch, char *argument)
{
         
   CHAR_DATA *victim;
   char buf[MAX_INPUT_LENGTH];
   char arg [MAX_INPUT_LENGTH];
        
    one_argument(argument,arg);
     
    if IS_NPC(ch)
    {
        return;
    }

    if (arg[0] == '\0')
    {
        send_to_char("Syntax: accept <person>\n\r",ch);
        return;
    }

    if ( ( victim = get_char_world( ch, arg ) ) == NULL )
    {
        send_to_char( "They aren't here.\n\r", ch );
        return;
    }

    if ( IS_SET(ch->in_room->room_flags, ROOM_NO_RECALL)
    ||   IS_AFFECTED(ch, AFF_CURSE))
    {
        send_to_char( "The Gods have forsaken you.\n\r", ch );
        return;
    }

    if (ch->level < 20)
    {
        send_to_char("You must be level 20 before entering the arena.\n\r",ch);
        return;
    }

    if (is_clan(ch))
    {
        send_to_char("Your in a clan, you must PK them in a real fight to kill them\n\r",ch);
        return;
    }

    if (victim == ch)
    {
        return;
    }
    
    if ( !IS_SET(victim->act,PLR_ARENA))
    {
        send_to_char("They are not in the arena.\n\r",ch);
        return;
    }

    SET_BIT( ch->act, PLR_ARENA );
    
    sprintf(buf, "%s 8802",ch->name);
    do_transfer(ch,buf);
    sprintf(buf,"{R[ARENA] {W%s {bhas just accepted the challenge.\n\r",ch->name);
    do_echo( ch, buf );

}
 
void do_leave(CHAR_DATA *ch)
{

   char buf[MAX_INPUT_LENGTH];
    
    
    if IS_NPC(ch)
    {
        return;
    }

    if ( !IS_SET(ch->act,PLR_ARENA))
    {   
        send_to_char("You are not in the arena.\n\r",ch);
        return;
    }

        if (ch->position == POS_FIGHTING)
        {
            send_to_char("Maybe you should finish fighting first?\n\r",ch);
            return;
        }

    REMOVE_BIT(ch->act,PLR_ARENA);

    sprintf(buf,"{R[ARENA] {W%s {bhas just left the arena.\n\r",ch->name);
    do_echo( ch, buf );
    sprintf(buf,"%s 3001",ch->name);
    do_transfer(ch,buf);
}

void do_arena( CHAR_DATA *ch )
{
    char buf[MSL];
    DESCRIPTOR_DATA *d;
    bool found; 
    found = FALSE;   

    sprintf(buf,"{Y<><><><><> {bDestiny Arena Status {Y<><><><><>{x\n\r");
    send_to_char(buf,ch);
    sprintf(buf,"{Y<><><><><> {bPlayers In The Arena {Y<><><><><>{x\n\r");        
    send_to_char(buf,ch);
    sprintf(buf,"{Y<>                                      <>{x\n\r");
    send_to_char(buf,ch);
        
    for (d = descriptor_list; d != NULL; d = d->next)
    {
        CHAR_DATA *wch;
        
        if (d->connected != CON_PLAYING || !can_see(ch,d->character))
            continue;
    
        wch = ( d->original != NULL ) ? d->original : d->character;
    
        if (!can_see(ch,wch))
            continue;
 
        if (!IS_SET(wch->act,PLR_ARENA))
            continue;
    
        found = TRUE;  
            sprintf(buf,"{Y<> {wName: {r%12s       {wLevel: {r%3d  {Y<>{x\n\r",wch->name,wch->level);
	    send_to_char(buf,ch);
        }

   if (!found)
   {
	sprintf(buf,"There isn't anyone inside the arena right now.\n\r");
	send_to_char(buf,ch);
   }

    sprintf(buf,"{Y<>                                      <>{x\n\r");
    send_to_char(buf,ch);
    sprintf(buf,"{Y<><><><><><><><><><><><><><><><><><><><><>{x\n\r");
    send_to_char(buf,ch);

} 

void do_bet(CHAR_DATA *ch, char *argument)
{
    char arg1 [MAX_INPUT_LENGTH];  /* Lot of arguments */
    char arg2 [MAX_INPUT_LENGTH];
    char buf[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    int value;

    argument = one_argument( argument, arg1 );  /* Combine the arguments */
    argument = one_argument( argument, arg2 );
 
 if (IS_NPC(ch))
 {
   send_to_char("Mobs cant bet on the arena.\r\n",ch);
   return;
 }
 
    if (arg1[0] == '\0' || arg2[0] == '\0')
    {
        send_to_char("Syntax: bet <amnt> <person>\n\r",ch);
        return;
    }

    if ( ( victim = get_char_world( ch, arg2 ) ) == NULL )
    {
		send_to_char("That person is not here.\n\r",ch);
	return;
    }

 if (IS_SET(ch->act,PLR_ARENA))
 {
	send_to_char("Yeah, you'd like to do this wouldn't you.\n\r",ch);
	return;
 }
 
 if(!IS_SET(victim->act,PLR_ARENA))
  {
	send_to_char("That person isn't in the arena to bet on right now!.\n\r",ch);
	return;
  }

  if (victim == ch)
  {
      send_to_char("That doesn't make much sense, does it?\r\n", ch);
	return;
  }

  value = atoi(arg1);
    
  if(value == 0)
  {
    send_to_char("Bet some gold why dont you!\r\n", ch);
	return;
  }

  if (value > ch->gold)
  {
    send_to_char ("You don't have that much money!\n\r",ch);
    return;
  }

  if(value > 100000)
  {
   sprintf(buf,"Not so much!\n\r");
   send_to_char(buf,ch);
   return;
  }
 
  SET_BIT(ch->act2,PLR2_BET);
  ch->pcdata->bet = str_dup(victim->name);
  victim->pcdata->bet = str_dup( ch->name ); 

  sprintf(buf, "You place %d coins on %s.\r\n", value, victim->name);
  send_to_char(buf,ch);
  ch->gold -= value;
  ch->pot += value;
  sprintf(buf,"%s has placed %d coins on %s.", ch->name,
          value, victim->name);
	do_sendinfo(ch,buf);
}