casino.c

./mudd/src/casino.c · 39.1 KB

From the archive emlen.tar.gz

Download the archive   « Back to the archive contents

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mud.h"

/* ======================================================================== */
/*  This command check for a dealer in the room (used in play for certain   */
/*  games). It returns no value, but if a dealer is found, the dealer_vnum  */
/*        is set to the dealer's vnum for further update checks.            */
/* ======================================================================== */

void
find_dealer (CHAR_DATA *ch)
{
  CHAR_DATA *dealer;
  
  ch->pcdata->play_dealer_vnum = 0;

  for (dealer = ch->in_room->people; dealer; dealer = dealer->next_in_room)
   {
     if (IS_MOB (dealer) && IS_SET (dealer->act, ACT_DEALER) && can_see (ch, dealer))
      {
        ch->pcdata->play_dealer_vnum = dealer->pIndexData->vnum;
        break;
      }
   }
}

/* ======================================================================== */
/*           This command is used to clear all the play data.               */
/* ======================================================================== */

void
clear_play_data (CHAR_DATA *ch)
{
  int i;

  ch->pcdata->play = 0;
  ch->pcdata->play_dealer_vnum = 0;
  ch->pcdata->play_obj_vnum = 0;
  ch->pcdata->play_room_vnum = 0;
  ch->pcdata->play_ticks = 0;
    for (i = 0; i < 10; i++)
       ch->pcdata->play_outcome[i] = 0;
  ch->pcdata->play_bet = 0;
}

/* ======================================================================== */
/*  The play command will allow you to use items to add special games on    */
/*  them. The format of this command is "play <object> <amount> <cointype>" */
/* ======================================================================== */

void do_play (CHAR_DATA *ch, char *argy)
{
  char arg[SML_LENGTH];
  char arg2[SML_LENGTH];
  char arg3[SML_LENGTH];
  ROOM_DATA *cur_room;
  SINGLE_OBJECT *obj;
  char buf[SML_LENGTH];
  unsigned int bet;
  int i;
  bool found = FALSE;
  DEFINE_COMMAND( "play", do_play, POSITION_STANDING, 0, LOG_NORMAL, "This lets you play on special item types.")

    if (IS_MOB(ch))
      return;

/* ======================================================================== */
/*     Check for the the right object. (furniture with playable flag)       */
/* ======================================================================== */

  argy = one_argy (argy, arg);
  if (arg[0] == '\0')
    {
      send_to_char ("Play what?\n\r", ch);
      return;
    }
  if ((obj = get_obj_here (ch, arg, SEARCH_ROOM_FIRST)) == NULL)
    {
      send_to_char ("Play what?\n\r", ch);
      return;
    }
  if (obj->pIndexData->item_type != ITEM_FURNITURE)
    {
      send_to_char ("How do you expect to play that?\n\r", ch);
      return;
    }
  if (obj->pIndexData->item_type == ITEM_FURNITURE && (!IS_SET(((I_FURNITURE *) obj->more)->type, FURN_PLAYABLE)))
    {
      send_to_char ("How do you expect to play that?\n\r", ch);
      return;
    }
  if (ch->pcdata->play)
    {
      send_to_char("You are already playing something else.\n\r", ch);
      return;
    }

/* ======================================================================== */
/*      Droping the vnum of the used object for the game for updates.       */
/* ======================================================================== */

    ch->pcdata->play_obj_vnum = obj->pIndexData->vnum;

/* ======================================================================== */
/*                          Get the bet number.                             */
/* ======================================================================== */

  argy = one_argy(argy, arg2);
  if (!is_number(arg2))
    {
      send_to_char("Syntax: Play <object> <amount> <cointype>.\n\r", ch);
      return;
    }
  else
    bet = atoi(arg2);

  if (bet < 10)
    {
      send_to_char("You cannot bet less than 10 coins.\n\r", ch);
      return;
    }

/* ======================================================================== */
/*                         Check for coin type.                             */
/* ======================================================================== */

  argy = one_argy(argy, arg3);
  for (i = 0; i < MAX_COINS; i++)
    {
      if (!str_cmp(arg3, coin_name[i]))
	{
	  found = TRUE;
	  bet *= coin_mult[i];
          break;
	}
    }
  if (!found)
    {
      send_to_char("Syntax: Play <object> <amount> <cointype>.\n\r", ch);
      return;
    }

  if (tally_coins(ch) < bet)
    {
      send_to_char("You don't have enough to cover this bet.\n\r", ch);
      return;
    }

  if (bet > 100000)
    {
      sprintf(buf, "You cannot bet more than 100000 %s on any one game.\n\r", coin_color[0]);
      send_to_char(buf, ch);
      return;
    }

/* ======================================================================== */
/*      Droping the vnum of the current room for game updates checks.       */
/* ======================================================================== */

  cur_room = ch->in_room;
  ch->pcdata->play_room_vnum = cur_room->vnum;

/* ======================================================================== */
/*   If the object is furniture type , playable and the value3 is set to    */
/*                        1 it plays deck of fate.                          */
/*    Dont forget to start the object's short_descr with "the" so the       */
/*                         messages can fit in.                             */
/* ======================================================================== */

  if (((I_FURNITURE *) obj->more)->gametype == 1)
    {

     find_dealer(ch);

     if (ch->pcdata->play_dealer_vnum == 0)
      {
        send_to_char ("There is no dealer around, how do you expect to play?\n\r", ch);
        return;
      }

      sprintf(buf, "You put %s %s %s on %s, and prepare to pick a card.\n\r", arg2, coin_color[i], (atoi(arg2) > 1 ? "coins" : "coin"), obj->pIndexData->short_descr);
      send_to_char(buf, ch);
      sprintf(buf, "$n puts %s %s, %s on %s and prepares to pick a card.\n\r", arg2, coin_color[i], (atoi(arg2) > 1 ? "coins" : "coin"), obj->pIndexData->short_descr);
      act (buf, ch, NULL, NULL, TO_ROOM);  

      ch->pcdata->play = GAME_DECK;
      ch->pcdata->play_ticks = (number_range(12,15) + 160/get_stat(ch, CHA));
      for (i = 0; i < 10; i++)
        ch->pcdata->play_outcome[i] = 0;
      ch->pcdata->play_bet = bet;
      sub_coins(bet, ch);
      return;
    }
  
/* ======================================================================== */
/*   If the object is furniture type , playable and the value3 is set to    */
/*                          2 it plays roulette.                            */
/*    Dont forget to start the object's short_descr with "the" so the       */
/*                         messages can fit in.                             */
/* ======================================================================== */

  if (((I_FURNITURE *) obj->more)->gametype == 2)
    {

     find_dealer(ch);

     if (ch->pcdata->play_dealer_vnum == 0)
      {
        send_to_char ("There is no dealer around, how do you expect to play?\n\r", ch);
        return;
      }

      sprintf(buf, "You bet %s %s %s on %s, and the whell starts spinning around.\n\r", arg2, coin_color[i], (atoi(arg2) > 1 ? "coins" : "coin"), obj->pIndexData->short_descr);
      send_to_char(buf, ch);
      sprintf(buf, "$n bets %s %s %s on %s, and the whell starts spinning around.\n\r", arg2, coin_color[i], (atoi(arg2) > 1 ? "coins" : "coin"), obj->pIndexData->short_descr);
      act (buf, ch, NULL, NULL, TO_ROOM);  

      ch->pcdata->play = GAME_ROULETTE;
      ch->pcdata->play_ticks = 4;
      for (i = 0; i < 10; i++)
        ch->pcdata->play_outcome[i] = 0;
      ch->pcdata->play_bet = bet;
      sub_coins(bet, ch);
      return;
    }

/* ======================================================================== */
/*   If the object is furniture type , playable and the value3 is set to    */
/*                          3 it plays slots.                               */
/*    Dont forget to start the object's short_descr with "the" so the       */
/*                         messages can fit in.                             */
/* ======================================================================== */

  if (((I_FURNITURE *) obj->more)->gametype == 3)
    {
      sprintf(buf, "You insert %s %s %s in %s, and yank the lever down.\n\r", arg2, coin_color[i], (atoi(arg2) > 1 ? "coins" : "coin"), obj->pIndexData->short_descr);
      send_to_char(buf, ch);
      sprintf(buf, "$n inserts %s %s %s in %s, and yanks the lever down.\n\r", arg2, coin_color[i], (atoi(arg2) > 1 ? "coins" : "coin"), obj->pIndexData->short_descr);
      act (buf, ch, NULL, NULL, TO_ROOM);  

      ch->pcdata->play = GAME_SLOTS;
      ch->pcdata->play_ticks = 4 + number_range(0,3);
      for (i = 0; i < 10; i++)
        ch->pcdata->play_outcome[i] = 0;
      ch->pcdata->play_bet = bet;
      sub_coins(bet, ch);
      ch->pcdata->play_bet = (ch->pcdata->play_bet * ((990 +get_stat(ch, LCK))/1000));
      return;
    }
  send_to_char("Syntax: Play <amount> <amount> <cointype>.\n\r", ch);
  return;
}

/* ======================================================================== */
/* This command is used in upd.c to verify is everything needed to continue */
/*   the game is there, and if so it wil redirect to the proper game code.  */
/* ======================================================================== */

void play_update (CHAR_DATA *ch)
{
  
  ROOM_DATA *cur_room;
  int i;

  if (ch->pcdata->play == 0)
    return;

  cur_room = ch->in_room;
  
/* ======================================================================== */
/*  If you leave the room or are not in standing position, the game stops.  */
/*  Except for slots of course because dont dont need anyone to continue.   */
/* ======================================================================== */

 if (ch->pcdata->play != GAME_SLOTS)
   {
   if (cur_room->vnum != ch->pcdata->play_room_vnum)
    {
      send_to_char("You left your game and someone walked off with your money, too bad for you.\n\r", ch);
      clear_play_data (ch);
      return;
    }
   if (!ch->in_room || ch->position != POSITION_STANDING)
    {
      if (ch->position == POSITION_SLEEPING)
        {
      send_to_char("You suddenly have a strange feeling that you forgot to finish something.\n\r", ch);
      clear_play_data (ch);
      return;
        }
      if (ch->position == POSITION_DEAD || ch->position == POSITION_MORTAL || ch->position == POSITION_INCAP || ch->position == POSITION_STUNNED);
        {
      send_to_char("It seems that your condition makes it impossible for you to finish your game.\n\r", ch);
      send_to_char("Someone has probably already pocketed your wager anyway.\n\r", ch);
      clear_play_data (ch);
      return;
        }
      if (ch->position != POSITION_STANDING)
        {
      send_to_char("Oops you weren't paying attention and someone took all your money!\n\r", ch);
      clear_play_data (ch);
      return;
        }
    }
   }

  if (ch->pcdata->play == GAME_ROULETTE)
    {
      roulette_update (ch);
      return;
    }
  if (ch->pcdata->play == GAME_DECK)
    {
      deck_update(ch);
      return;
    }
  if (ch->pcdata->play == GAME_SLOTS)
    {
      slots_update (ch);
      return;
    }
  send_to_char("Unknown play game, Resetting data. Please inform an admin.\n\r", ch);
  ch->pcdata->play = 0;
  ch->pcdata->play_ticks = 0;
  ch->pcdata->play_bet = 0;
  for (i = 0; i < 10; i++)
    ch->pcdata->play_outcome[i] = 0;
  return;
}

/* ======================================================================== */
/*                         Deck game procedure.                             */
/* ======================================================================== */

void
deck_update (CHAR_DATA *ch)
{
 
  MOB_PROTOTYPE *dealer;
  char buf[SML_LENGTH];
  int i;

  if (number_range(1,3) != 2)
    return;

  if (IS_MOB(ch))
    return;

  dealer = get_mob_index (ch->pcdata->play_dealer_vnum);

  ch->pcdata->play_ticks--;
  if (ch->pcdata->play_ticks > 7)
    {
      switch (number_range(0,6))
	{
	case 0:
          sprintf(buf, "%s is shuffling the deck of fate for you.\n\r", capitalize (dealer->short_descr));
          send_to_char(buf, ch);
          sprintf(buf, "%s is shuffling the deck of fate for $n.\n\r", capitalize (dealer->short_descr));
          act (buf, ch, NULL, NULL, TO_ROOM);  
          return;
	case 1:
          sprintf(buf, "You watch closely as %s cuts the Deck and proceeds to reshuffle.\n\r", dealer->short_descr);
          send_to_char(buf, ch);
          sprintf(buf, "$n watch closely as %s cuts the Deck and proceeds to reshuffle.\n\r", dealer->short_descr);
          act (buf, ch, NULL, NULL, TO_ROOM);  
          return;
	case 2:
          sprintf(buf, "%s winks at you and continues to shuffle the cards.\n\r", capitalize (dealer->short_descr));
          send_to_char(buf, ch);
          sprintf(buf, "%s winks at $n and continues to shuffle the cards.\n\r", capitalize (dealer->short_descr));
          act (buf, ch, NULL, NULL, TO_ROOM);  
          return;
	case 3:
          sprintf(buf, "%s stops shuffling for a moment as you nervously watch.\n\r", capitalize (dealer->short_descr));
          send_to_char(buf, ch);
          sprintf(buf, "%s stops shuffling for a moment as $n nervously watches.\n\r", capitalize (dealer->short_descr));
          act (buf, ch, NULL, NULL, TO_ROOM);  
          return;
	case 4:
          sprintf(buf, "You stand patiently by as %s inspects the cards for imperfections.\n\r", dealer->short_descr);
          send_to_char(buf, ch);
          sprintf(buf, "$n stands patiently by as %s inspects the cards for imperfections.\n\r", dealer->short_descr);
          act (buf, ch, NULL, NULL, TO_ROOM);  
          return;
	case 5:
          sprintf(buf, "%s lets out a small chuckle at your plight.\n\r", capitalize (dealer->short_descr));
          send_to_char(buf, ch);
          sprintf(buf, "%s lets out a small chuckle at $n's plight.\n\r", capitalize (dealer->short_descr));
          act (buf, ch, NULL, NULL, TO_ROOM);  
          return;
	case 6:
          sprintf(buf, "You can only stand mum as %s proceeds to switch decks.\n\r", dealer->short_descr);
          send_to_char(buf, ch);
          sprintf(buf, "$n can only stand mum as %s proceeds to switch decks.\n\r", dealer->short_descr);
          act (buf, ch, NULL, NULL, TO_ROOM);  
          return;
	}
    }
  switch (ch->pcdata->play_ticks)
    {
    case 7:
      sprintf (buf, "You get very nervous as %s puts down the deck for the last time.\n\r", dealer->short_descr);
      send_to_char(buf, ch);
      sprintf (buf, "$n gets very nervous as %s puts down the deck for the last time.\n\r", dealer->short_descr);
      act (buf, ch, NULL, NULL, TO_ROOM);  
      return;
    case 6:
      sprintf(buf, "Slowly, you reach out toward the deck.\n\r");
      send_to_char(buf, ch);
      sprintf(buf, "Slowly, $n reaches out toward the deck.\n\r");
      act (buf, ch, NULL, NULL, TO_ROOM);  
      return;
    case 5:
      sprintf(buf, "You place your hand on the top of the deck prepared to pick up a card.\n\r");
      send_to_char(buf, ch);
      sprintf(buf, "$n places $s hand on the top of the deck prepared to pick up a card.\n\r");
      act (buf, ch, NULL, NULL, TO_ROOM);  
      return;
    case 4:
      sprintf(buf, "You hesitate as %s reminds you that you may leave the play now, and avoid the possibly awful effects of the deck!\n\r", dealer->short_descr);
      send_to_char(buf, ch);
      sprintf(buf, "$n hesitates as %s reminds $m that $e may leave the play now, and avoid the possibly awful effects of the deck!\n\r", dealer->short_descr);
      act (buf, ch, NULL, NULL, TO_ROOM);  
      return;
    case 3:
      sprintf(buf, "Sweat drops from your forehead as you think your last move.\n\r");
      send_to_char(buf, ch);
      sprintf(buf, "Sweat drops from $n's forehead as $e thinks $s last move.\n\r");
      act (buf, ch, NULL, NULL, TO_ROOM);  
      return;
    case 2:
      sprintf (buf, "Undaunted, you draw from the deck of fate, then %s looks at the card.\n\r", dealer->short_descr);
      send_to_char(buf, ch);
      sprintf (buf, "Undaunted, $n draws from the deck of fate, then %s looks at the card.\n\r", dealer->short_descr);
      act (buf, ch, NULL, NULL, TO_ROOM);  

      if (number_range(1,2) == 2)
       {
      sprintf (buf, "YOU WIN, yay, you hear the croud cheering you in the background.");
      send_to_char(buf, ch);
      sprintf (buf, "$n WINS, yay, *CHEER*, bah.");
      act (buf, ch, NULL, NULL, TO_ROOM);  
      give_deck_prize(ch);
      ch->pcdata->play = 0;
      ch->pcdata->play_dealer_vnum = 0;
      ch->pcdata->play_obj_vnum = 0;
      ch->pcdata->play_ticks = 0;
      for (i = 0; i < 10; i++)
        ch->pcdata->play_outcome[i] = 0;
      ch->pcdata->play_bet = 0;
      return;
       }
      else
       {
      sprintf (buf, "YOU LOOSE, what a fucking looser, muahaha.");
      send_to_char(buf, ch);
      sprintf (buf, "$n LOOSES, what a fucking looser, muahaha.");
      act (buf, ch, NULL, NULL, TO_ROOM);  
      ch->pcdata->play = 0;
      ch->pcdata->play_dealer_vnum = 0;
      ch->pcdata->play_obj_vnum = 0;
      ch->pcdata->play_ticks = 0;
      for (i = 0; i < 10; i++)
        ch->pcdata->play_outcome[i] = 0;
      ch->pcdata->play_bet = 0;
      return;
       }
    }
  return;
}


void 
roulette_update (CHAR_DATA *ch)
{
  int i;
  if (ch->pcdata->play_ticks > 4)
    ch->pcdata->play_ticks = 4 + number_range(1,2);
  switch (--ch->pcdata->play_ticks)
    {
    case 3:
    default:
      act("The wheel spins round and round..", ch, NULL, NULL, TO_ROOM);
      send_to_char("The wheel spins round and round.\n\r", ch);
      break;
    case 2:
      act("The wheel starts to slow down..", ch, NULL, NULL, TO_ROOM);
      send_to_char("The wheel starts to slow down.\n\r", ch);
      break;
    case 1:
      act("The wheel is slowing almost to a stop.", ch, NULL, NULL, TO_ROOM);
      send_to_char("The wheel is slowing almost to a stop.\n\r", ch);
      break;
    case 0:
      act("The wheel stops!", ch, NULL, NULL, TO_ROOM);
      send_to_char("The wheel stops!\n\n\n\r", ch);
      
      if (number_range(1,45) == 32)
	{
	  act ("$n wins! Payout is 43:1.", ch, NULL, NULL, TO_ROOM);
	  send_to_char("You win! Payout is 43:1\n\r", ch);
          create_amount ((ch->pcdata->play_bet *44), ch, NULL, NULL);
	}
      else
	{
	  act ("$n loses!", ch, NULL, NULL, TO_ROOM);
	  send_to_char("\n\rYou lose!\n\r", ch);
	}
      ch->pcdata->play = 0;
      ch->pcdata->play_ticks = 0;
      ch->pcdata->play_bet = 0;
      for (i = 0; i < 10; i++)
        ch->pcdata->play_outcome[i] = 0;
      break;
    }
  return;
}

void
slots_update (CHAR_DATA *ch)
{
  int i;
  int num_up = 0;
  if (ch->pcdata->play_ticks > 4)
    ch->pcdata->play_ticks = 4;
  switch (--ch->pcdata->play_ticks)
    {
    case 2:
      act("The first number comes up", ch, NULL, NULL, TO_ROOM);
      send_to_char("The first number comes up.\n\r", ch);
      break;
    case 1:
      act("The second number comes up", ch, NULL, NULL, TO_ROOM);
      send_to_char("The second number comes up.\n\r", ch);
      break;
    case 0:
      act("The third number comes up", ch, NULL, NULL, TO_ROOM);
      send_to_char("The third number comes up.\n\r", ch);
      break;
    case 3:
    default:
      act ("The slot machine spins and spins...", ch, NULL, NULL, TO_ROOM);
      send_to_char("The slot machine spins and spins...\n\r", ch);
      return;
    }
  num_up = number_range(1,10);
  switch (num_up)
    {
    default:
    case 1:
    case 2:
    case 3:
      if (ch->pcdata->play_ticks == 0 && num_up == 3)
	{
	  act("It's a star!", ch, NULL, NULL, TO_ROOM);
	  send_to_char("It's a star!\n\r", ch);
	  num_up = 3;
	}
      else
	{
	  act("It's a bell!", ch, NULL, NULL, TO_ROOM);
	  send_to_char("It's a bell!\n\r", ch);
	  num_up = 1;
	}
      break;
    case 4:
    case 5:
      act("It's a lemon!", ch, NULL, NULL, TO_ROOM);
      send_to_char("It's a lemon!\n\r", ch);
      num_up = 4;
      break;
    case 6:
    case 7:
      num_up = 6;
      act("It's a cherry!", ch, NULL, NULL, TO_ROOM);
      send_to_char("It's a cherry!\n\r", ch);
      break;
    case 8:
    case 9:
      num_up = 8;
      act("It's a pear!", ch, NULL, NULL, TO_ROOM);
      send_to_char("It's a pear!\n\r", ch);
	  break;
    case 10:
      num_up = 10;
      act("It's a bar!", ch, NULL, NULL, TO_ROOM);
	  send_to_char("It's a bar!\n\r", ch);
	  break;
    }
  ch->pcdata->play_outcome[2-ch->pcdata->play_ticks] = num_up;
  if (ch->pcdata->play_ticks > 0)
    return;
  if (ch->pcdata->play_outcome[0] == 10 &&
      ch->pcdata->play_outcome[1] == 10 &&
      ch->pcdata->play_outcome[2] == 10)
    {
      act("$n wins with three bars! Payoff is 100 to 1.", ch, NULL, NULL, TO_ROOM);
      send_to_char("You win with three bars! Payoff is 100 to 1.", ch);
      ch->pcdata->play_bet  *= 101;
      create_amount(ch->pcdata->play_bet,ch, NULL,NULL);
    }
  else if (ch->pcdata->play_outcome[0] == 1 &&
           ch->pcdata->play_outcome[1] == 1 &&
           ch->pcdata->play_outcome[2] == 1)
    {
      act("$n wins with three bells! Payoff is 5 to 1.", ch, NULL, NULL, TO_ROOM);
      send_to_char("You win with three bells! Payoff is 5 to 1.", ch);
      ch->pcdata->play_bet  *= 6;
      create_amount(ch->pcdata->play_bet, ch,NULL,NULL);
    }
  else if (ch->pcdata->play_outcome[0] == 4 &&
           ch->pcdata->play_outcome[1] == 4 &&
           ch->pcdata->play_outcome[2] == 4)
    {
      act("$n wins with three lemons! Payoff is 10 to 1.", ch, NULL, NULL, TO_ROOM);
      send_to_char("You win with three lemons! Payoff is 10 to 1.", ch);
      ch->pcdata->play_bet  *= 11;
      create_amount(ch->pcdata->play_bet, ch, NULL, NULL);
    }
  else if (ch->pcdata->play_outcome[0] == 6 &&
           ch->pcdata->play_outcome[1] == 6 &&
           ch->pcdata->play_outcome[2] == 6)
    {
      act("$n wins with three cherries! Payoff is 20 to 1.", ch, NULL, NULL, TO_ROOM);
      send_to_char("You win with three cherries! Payoff is 20 to 1.", ch);
      ch->pcdata->play_bet  *= 21;
      create_amount(ch->pcdata->play_bet, ch, NULL,NULL);
    }
  else if (ch->pcdata->play_outcome[0] == 8 &&
           ch->pcdata->play_outcome[1] == 8 &&
           ch->pcdata->play_outcome[2] == 8)
    {
      act("$n wins with three cherries! Payoff is 25 to 1.", ch, NULL, NULL, TO_ROOM);
      send_to_char("You win with three cherries! Payoff is 25 to 1.", ch);
      ch->pcdata->play_bet  *= 26;
      create_amount(ch->pcdata->play_bet, ch, NULL,NULL);
    }
  else if (ch->pcdata->play_outcome[2] == 3)
    {
      if (ch->pcdata->play_outcome[0] == 
          ch->pcdata->play_outcome[1])
	{
	  act("$n wins with a pair and a star!", ch, NULL, NULL,TO_ROOM);
	  send_to_char("You win 1:1 with a pair and a star!\n\r",ch);
          create_amount((2*ch->pcdata->play_bet), ch, NULL, NULL);
	}
      else
	{
	  act("$n wins with a star!", ch, NULL, NULL,TO_ROOM);
	  send_to_char("You win your money back with a star!\n\r",ch);
          create_amount((ch->pcdata->play_bet), ch, NULL, NULL);
	}
    }
  else
    {
      act ("$n loses!", ch, NULL, NULL, TO_ROOM);
      send_to_char("You lose!\n\r", ch);
    }
  ch->pcdata->play = 0;
  ch->pcdata->play_ticks = 0;
  ch->pcdata->play_bet = 0;
  for (i = 0; i < 10; i++)
    ch->pcdata->play_outcome[i] = 0;
  return;
}



int 
get_prize_amount(int prize)
{
  int amount_won;
  switch (prize)
    {
    case 1:
      amount_won = number_percent() * number_percent() * number_percent();
      break;
    case 2:
      amount_won = number_range(1,10) * number_range(1,10) * number_range(1,10);
      break;
    case 3:
      amount_won = (number_range(1,3) * number_range(1,3))/3;
      break;
    case 4:
      amount_won = (number_range(1,4) * number_range(1,4))/4;
      break;
    case 5:
      amount_won = (number_range(1,10) * number_range(1,10))/3;
      break;
    case 6:
      amount_won = (number_range(1,3) * number_range(1,3))/3;
      break;
    case 7:
      amount_won = (number_range(1,4) * number_range(1,4))/4;
      break;
    case 8:
    case 9:
      amount_won = 1;
      if (number_range(1,30) == 3)
	amount_won++;
      break;
    default:
      amount_won = 1;
      break;
    }
  if (amount_won < 1)
    amount_won = 1;
  return amount_won;
}
void 
give_deck_prize (CHAR_DATA *ch)


{
  int amount_won = 0;
  CHAR_DATA *sch;
  char buf[STD_LENGTH];
  char lostwon[10];
  int prize_type;
  bool deleting = FALSE;
  bool won = (ch->pcdata->play_outcome[0] == 1);
  int count = 0;
  
  if (won)
    sprintf(lostwon, "won");
  else
    sprintf(lostwon, "lost");


  /* Get the type of prize */


  if (number_range(1,2) != 2)
    prize_type = 1; /* Money */
  else if (number_range(1,2) != 2)
    prize_type = 2; /* Warpoints */
  else if (number_range(1,2) != 2)
    prize_type = 3; /* An Item */
  else if (number_range(1,2) != 2)
    prize_type = 4; /* Enchant/ Empowerment */
  else if (number_range(1,2) != 2)
    prize_type = 5; /* Experience/levels */
  else if (number_range(1,2) != 2)
    prize_type = 6; /* Resistances */
  else if (number_range(1,2) != 2)
    prize_type = 7; /* Guilds/Guildpoints */
  else if (number_range(1,2) != 2)
    prize_type = 8; /* Augmentations */
  else if (number_range(1,2) != 2)
    prize_type = 9; /* Remorts/Deletion */
  else 
    prize_type = 1; /* Money */

  
  buf[0] = '\0';

  while (prize_type > 0 && count < 10)
    {
      count++;
      amount_won  = get_prize_amount(prize_type);
      if (!won)
        amount_won *= ch->pcdata->play_outcome[1];
      switch (prize_type)
	{
	case 1:
	  {
	    sprintf(buf + strlen(buf), "\n%s just %s %d coin%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    if (won)
	      {
		create_amount (amount_won, ch, NULL, NULL);
		prize_type = 0;
	      }
	    else
	      {
		if ((tally_coins(ch) + ch->pcdata->bank) < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\n Bah, %s does not have enough money, so %s loses warpoints!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    ch->pcdata->bank = 0;
		    sub_coins (tally_coins(ch),ch); 
		    prize_type = 2;
		  }
		else if (tally_coins(ch) < amount_won)
		  {
		    amount_won -= tally_coins(ch);
		    sub_coins(tally_coins(ch),ch);
		    ch->pcdata->bank -= amount_won;
		    prize_type = 0;
		  }
		else
		  {
		    sub_coins(amount_won, ch);
		    prize_type = 0;
		  }
	      }
	  }
	break;
	case 2: /* Warpoints */
	  {
	    sprintf(buf + strlen(buf), "\n%s just %s %d warpoint%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    if (won)
	      {
		ch->pcdata->warpoints += amount_won;
		ch->pcdata->total_wps += amount_won;
		prize_type = 0;
	      }
	    else
	      {
		if (ch->pcdata->warpoints < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\n Bah, %s does not have enough warpoints, so %s loses items!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    ch->pcdata->warpoints = 0;
		    ch->pcdata->total_wps -= (UMIN(ch->pcdata->total_wps, amount_won));
		    prize_type = 3;
		  }
		else
		  {
		    ch->pcdata->warpoints -= amount_won;
		    ch->pcdata->total_wps -= (UMIN(ch->pcdata->total_wps, amount_won));
		    prize_type = 0;
		  }
	      }
	  }
	break;
	case 3: /* Items */
	  {
	    sprintf(buf + strlen(buf), "\n%s just %s %d item%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    if (won)
	      {
		int i;
		SINGLE_OBJECT *prize;
		for (i = 0; i < amount_won; i++)
		  {
		    prize = create_object(get_obj_index(300+number_range(0,3)), 1);
		    obj_to(prize, ch);
		  }
		prize_type = 0;
	      }
	    else
	      {
		SINGLE_OBJECT *obj, *objn;
		int num_removed = 0;
		AFFECT_DATA *af;
		bool found = FALSE;
		for (obj = ch->carrying; obj != NULL; obj = obj = objn)
		  {
		    if (num_removed >= amount_won)
		      break;
		    objn = obj->next_content;
		    for (af = obj->pIndexData->affected; af != NULL; af = af->next)
		      {
			found = FALSE;
			if ((af->modifier > 0 &&
			     (af->location <= APPLY_CHA ||
			      af->location == APPLY_DAMROLL)) ||
			    (af->modifier > 10 &&
			     (af->location == APPLY_HIT ||
			      af->location == APPLY_MOVE ||
			      af->location == APPLY_SNEAK ||
			      af->location == APPLY_HIDE)) ||
			    (af->modifier > 2 && 
			     (af->location == APPLY_HITROLL ||
			      af->location == APPLY_KICK_DAMAGE)) ||
			    (af->modifier > 3 &&
			     (af->location == APPLY_AC ||
			      af->location == APPLY_SAVING_THROW)))
			  {
			    found = TRUE;
			    break;
			  }
		      }
		    if (!found)
		      {
			switch (obj->pIndexData->item_type)
			  {
			  case ITEM_ARMOR:
			    {
			      if ((obj->pIndexData->value[0] +
				   obj->pIndexData->value[1] +
				   obj->pIndexData->value[2] +
				   obj->pIndexData->value[3]) >
				  (5 + IS_SET(obj->pIndexData->wear_flags, ITEM_WEAR_SHIELD)*4))
				found = TRUE;
			    }
			  break;
			  case ITEM_GEM:
			    {
			      int i;
			      int manatypes = 0;
			      for (i = 0; i  < 5; i++)
				if (IS_SET(obj->pIndexData->value[0], (1<<i)))
				  manatypes++;
			      if ((manatypes*obj->pIndexData->value[3] + 
				   obj->pIndexData->value[2]) >= 120)
				found = TRUE;
			    }
			  case ITEM_WEAPON:
			    if (obj->pIndexData->value[7] *
				(obj->pIndexData->value[8] +1)/2 >= 10)
			      found = TRUE;
			  default:
			    found = FALSE;
			  }
		      }
		    if (found)
		      {
			obj_from(obj);
			free_it(obj);
			num_removed++;
		      }
		  }
		if (num_removed < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\n Bah, %s does not have enough items, so %s loses enchantments!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    prize_type = 4;
		  }
		else
		  { 
		    prize_type = 0;
		  }
	      }
	  }
	break;
	case 4: /* Empower/Enchant */
	  {
	    sprintf(buf + strlen(buf), "\n%s just %s %d enchantment%s/empowerment%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"), (amount_won == 1 ? "" : "s"));
	    if (won)
	      {
		int i;
		SINGLE_OBJECT *prize;
		for (i = 0; i < amount_won; i++)
		  {
		    prize = create_object(get_obj_index(304+(number_range(0,3)/3)), 1);
		    obj_to(prize, ch);
		  }
		prize_type = 0;
	      }
	    else
	      {
		SINGLE_OBJECT *obj, *objn;
		int num_removed = 0;
		bool found = FALSE;
		for (obj = ch->carrying; obj != NULL; obj = obj = objn)
		  {
		    if (num_removed >= amount_won)
		      break;
		    objn = obj->next_content;
		    if (obj->affected)
		      {
			obj_from (obj);
			free_it(obj);
			found = TRUE;
			num_removed++;
		      }
		  } 
		if (num_removed < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\n Bah, %s does not have enough enchanted/empowered items, so %s loses experience points!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    prize_type = 5;
		  }
		else
		  { 
		    prize_type = 0;
		  }
	      }
	  }
	break;
	case 5:
	  {
	    sprintf(buf + strlen(buf), "\n%s just %s %d level%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    if (won)
	      {

		ch->pcdata->exp = FIND_EXP(UMIN( 90, (LEVEL(ch) + amount_won)), 1);
		gain_exp(ch, 1);
		prize_type = 0;
	      }
	    else
	      {
		SINGLE_OBJECT *obj;
		int hps_mod = 0;
		int moves_mod = 0;
		AFFECT_DATA *af;
		int i;
		if (LEVEL(ch) < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\n Bah, %s does not have enough levels, so %s loses resistances!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    prize_type = 6;
		  }
		else
		  prize_type = 0;
		for (obj = ch->carrying; obj != NULL; obj = obj->next_content)
		  {
		    for (af = obj->affected; af != NULL; af = af->next)
		      {
			if (af->location == APPLY_HIT)
			  hps_mod += af->modifier;
			if (af->location == APPLY_MOVE)
			  moves_mod += af->modifier;
		      }
		    for (af = obj->pIndexData->affected; af != NULL; af = af->next)
		      {
			if (af->location == APPLY_HIT)
			  hps_mod += af->modifier;
			if (af->location == APPLY_MOVE)
			  moves_mod += af->modifier;
		      }
		    for (af = ch->affected; af != NULL; af = af->next)
		      {
			if (af->location == APPLY_HIT)
			  hps_mod += af->modifier;
			if (af->location == APPLY_MOVE)
			  moves_mod += af->modifier;
		      } 
		  }
		ch->pcdata->exp = 1;
		ch->max_hit = 30 + hps_mod;
		ch->max_move = 60 + moves_mod;
		ch->pcdata->practice = 5;
		ch->pcdata->learn = 2;
		for (i = 0; i < SKILL_COUNT; i++)
		  ch->pcdata->learned[i] = 0;
		if (LEVEL(ch) >= amount_won)
		  {
		    ch->pcdata->exp = FIND_EXP((LEVEL(ch) - amount_won), 1);
		    ch->pcdata->level = 1;
		    gain_exp(ch, 1);
		    prize_type = 0;
		  }
		else
		  {
		    ch->pcdata->level = 1;
		  }
	      }
	  }
	break;
	case 6: /* Resistances */
	  {
	    sprintf(buf + strlen(buf), "\n%s just %s %d resistance point%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    if (won)
	      {
		ch->pcdata->resist_points += amount_won;
		prize_type = 0;
	      }
	    else
	      {
		if (ch->pcdata->resist_points < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\n Bah, %s does not have enough resistance points, so %s loses guild points!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    ch->pcdata->resist_points = 0;
		    
		    prize_type = 7;
		  }
		else
		  {
		    ch->pcdata->resist_points -= amount_won;
		    prize_type = 0;
		  }
	      }
	  }
	break;
	case 7: /* Guild/Guild Pts */
	  {
	    sprintf(buf + strlen(buf), "\n%s just %s %d guild point%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    if (won)
	      {
		ch->pcdata->guild_points += amount_won;
		prize_type = 0;
	      }
	    else
	      {
		if (ch->pcdata->guild_points < amount_won)
		  {
		    int i;
		    sprintf (buf +strlen(buf), "\n Bah, %s does not have enough guild points, so %s loses augmentations!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    ch->pcdata->guild_points = 0;
		    for (i = 0; i < 10; i++)
		      {
			if (ch->pcdata->guilds[i] > 0 && number_range(1,20) == 3)
			  {
			    if (ch->pcdata->guilds[i] % 2 == 0 &&
				guild_data[i].stat_modified != NUM_STATS)
			      ch->pcdata->stat[guild_data[i].stat_modified]--;
			    ch->pcdata->guilds[i]--;
			    ch->pcdata->guild_points += ch->pcdata->guilds[i];
			  }
		      }
		    prize_type = 8;
		  }
		else
		  {
		    ch->pcdata->guild_points -= amount_won;
		    prize_type = 0;
		  }
	      }
	  }
	break;
	case 8: /* Augmentations */
	  {
	    int i, j;
	    int nat_augs;
	    int num_chose;
	    int current_num;
	    int current_augs;
	    int augs_permitted;
	    int num_augs_permitted = 0;
	    int augs_can_be_removed;
	    int num_augs_can_be_removed = 0;
	    sprintf(buf + strlen(buf), "\n%s just %s %d augmentation%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    current_augs = ch->pcdata->augments;
	    nat_augs = race_info[ch->pcdata->race].nat_augments | 
	      align_info[ch->pcdata->alignment].nat_augments;
	    
	    augs_can_be_removed = current_augs &~ nat_augs;
	    for (i = 0; str_cmp(augment_flagss[i].what_you_type, "end_of_list"); i++)
	      {
		if (IS_SET(augs_can_be_removed, augment_flagss[i].flagname))
		  {
		    num_augs_can_be_removed++;
		  }
	      }
	    
	    
	    for (i = 0; str_cmp(augment_flagss[i].what_you_type, "end_of_list"); i++)
	      {
		if (!IS_SET(current_augs, augment_flagss[i].flagname))
		  {
		    augs_permitted |= augment_flagss[i].flagname;
		    num_augs_permitted++;
		  }
	      }  
	    if (won)
	      {
		if (num_augs_permitted < amount_won)
		  amount_won = num_augs_permitted;
		for (j = 0; j < amount_won; j++)
		  {
		    num_chose = number_range(1,(num_augs_permitted-j));
		    current_num = 0;
		    for (i = 0; str_cmp(augment_flagss[i].what_you_type, "end_of_list"); i++)
		      {
			if (!IS_SET(ch->pcdata->augments, augment_flagss[i].flagname) && (++current_num == num_chose))
			  {
			    ch->pcdata->augments |= augment_flagss[i].flagname;
			    break;
			  }
		      }
		  }
		prize_type = 0;
	      }
	    else
	      {
		if (num_augs_can_be_removed < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\nBah, %s does not have enough augmentations, so %s loses remorts!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    ch->pcdata->augments = nat_augs;
		    prize_type = 9;
		  }
		else
		  {
		    for (j = 0; j < amount_won; j++)
		      {
			num_chose = number_range(1,(num_augs_can_be_removed-j));
			current_num = 0;
			for (i = 0; str_cmp(augment_flagss[i].what_you_type, "end_of_list"); i++)
			  {
			    if (IS_SET(augs_can_be_removed, augment_flagss[i].flagname) && (++current_num == num_chose))
			      
			      {
				REMOVE_BIT(augs_can_be_removed, augment_flagss[i].flagname);
				REMOVE_BIT(ch->pcdata->augments,augment_flagss[i].flagname); 	
			      }
			  }
		      } 
		    prize_type = 0;
		  }
	      }
	  }
	break;
	case 9:
	  {
	    int i, j;
	    int stat_chose;
	    int can_be_added;
	    int current_num;
	    int num_stat_bonuses = amount_won * pow.stats_per_remort;
	    int stat_cap[NUM_STATS];
	    
	    sprintf(buf + strlen(buf), "\n%s just %s %d remort%s!\n\r", NAME(ch), lostwon, amount_won, (amount_won == 1 ? "" : "s"));
	    /* Set up stat maxes for race and alignment */

	    for (i = 0; i < NUM_STATS; i++)
	      {
		stat_cap[i] = race_info[ch->pcdata->race].limits[i] +
		  align_info[ch->pcdata->alignment].limits[i];
		
	      }


	    /* Then give bonuses for guilds. */

	    for (i = 0; i < NUM_GUILDS; i++)
	      {
	        if (guild_data[i].stat_modified != NUM_STATS)
		  {
		    stat_cap[guild_data[i].stat_modified] += ch->pcdata->guilds[i]/2;
		  }
	      }
	    
	    if (won)
	      {
		ch->pcdata->remort_times += amount_won;
		for (i = 0; i < num_stat_bonuses; i++)
		  {
		    can_be_added = 0;
		    for (j = 0; j < NUM_STATS; j++)
		      if (ch->pcdata->stat[j] < stat_cap[j])
			can_be_added++;
		    if (can_be_added == 0)
		      break;
		    stat_chose = number_range(1,can_be_added);
		    current_num = 0;
		    for (j = 0; j < NUM_STATS; j++)
		      {
			if (ch->pcdata->stat[j] >= stat_cap[j])
			  continue;
			if (++current_num == stat_chose) 
			  {
			    ch->pcdata->stat[j]++;
			    break;
			  }
		      }
		  }
	      }
	    else
	      {
		if (ch->pcdata->remort_times < amount_won)
		  {
		    sprintf (buf +strlen(buf), "\nBah, %s does not have enough remorts, so %s gets deleted!\n\r", NAME(ch), (ch->pcdata->sex == SEX_MALE ? "he" : (ch->pcdata->sex == SEX_FEMALE ? "she" : "it")));
		    
		    deleting = TRUE;
		    prize_type = 0;
		  }
		else
		  {
		    ch->pcdata->remort_times -= amount_won;
		    for (i = 0; i < SKILL_COUNT; i++)
		      ch->pcdata->learned[i] = 0;
		    for (i = 0; i < num_stat_bonuses; i++)
		      {
			stat_chose = number_range(0, NUM_STATS-1);
			ch->pcdata->stat[stat_chose]--;
		      }
		  }
	      }
	  }
	prize_type = 0;
	break;
	}
    }
  sch=create_mobile(get_mob_index(1));
  char_to_room(sch,get_room_index(2));
  
  do_echo (sch, buf);
  extract_char(sch, TRUE);
  
  if (!deleting)
    {
      int kk;
      ch->pcdata->play = 0;
      ch->pcdata->play_ticks = 0;
      ch->pcdata->play_bet = 0;
      for (kk = 0; kk < 10; kk++)
	{
          ch->pcdata->play_outcome[kk] = 0;
	}
    }
  else
    {
      do_delete(ch, "character forever");
    }
  return;
}

Site Stats

Snippets: 1791
Codebases: 571