示例#1
0
文件: shop.c 项目: rparet/darkpawns
char *
list_object(struct char_data *ch, struct obj_data *obj,
        int cnt, int index, int shop_nr)
{
  static char buf[256];
  char buf2[300], buf3[200];
  extern char *drinks[];

  if (shop_producing(obj, shop_nr))
    strcpy(buf2, "Unlimited   ");
  else
    sprintf(buf2, "%5d       ", cnt);
  sprintf(buf, " %2d)  %s", index, buf2);

  /* Compile object name and information */
  strcpy(buf3, obj->short_description);
  if ((GET_OBJ_TYPE(obj) == ITEM_DRINKCON) && (GET_OBJ_VAL(obj, 1)))
    sprintf(END_OF(buf3), " of %s", drinks[GET_OBJ_VAL(obj, 2)]);

  /* FUTURE: */
  /* Add glow/hum/etc */

  if ((GET_OBJ_TYPE(obj) == ITEM_WAND) || (GET_OBJ_TYPE(obj) == ITEM_STAFF))
    if (GET_OBJ_VAL(obj, 2) < GET_OBJ_VAL(obj, 1))
      strcat(buf3, " (partially used)");

  sprintf(buf2, "%-48s %6d\n\r", buf3, buy_price(ch, obj, shop_nr));
  strcat(buf, CAP(buf2));
  return (buf);
}
示例#2
0
文件: shop.c 项目: rparet/darkpawns
void
sort_keeper_objs(struct char_data * keeper, int shop_nr)
{
  struct obj_data *list = 0, *temp;

  while (SHOP_SORT(shop_nr) < IS_CARRYING_N(keeper))
    {
      temp = keeper->carrying;
      obj_from_char(temp);
      temp->next_content = list;
      list = temp;
    }

  while (list)
    {
      temp = list;
      list = list->next_content;
      if ((shop_producing(temp, shop_nr)) &&
      !(get_obj_in_list_num(GET_OBJ_RNUM(temp), keeper->carrying)))
    {
      obj_to_char(temp, keeper);
      SHOP_SORT(shop_nr)++;
    } else
      (void) slide_obj(temp, keeper, shop_nr);
    }
}
示例#3
0
文件: shop.c 项目: rparet/darkpawns
struct obj_data *
slide_obj(struct obj_data * obj, struct char_data * keeper, int shop_nr)
/*
   This function is a slight hack!  To make sure that duplicate items are
   only listed once on the "list", this function groups "identical"
   objects together on the shopkeeper's inventory list.  The hack involves
   knowing how the list is put together, and manipulating the order of
   the objects on the list.  (But since most of DIKU is not encapsulated,
   and information hiding is almost never used, it isn't that big a deal) -JF
*/
{
  struct obj_data *loop;
  int temp;

  if (SHOP_SORT(shop_nr) < IS_CARRYING_N(keeper))
    sort_keeper_objs(keeper, shop_nr);

  /* Extract the object if it is identical to one produced */
  if (shop_producing(obj, shop_nr))
    {
      temp = GET_OBJ_RNUM(obj);
      extract_obj(obj);
      return (&obj_proto[temp]);
    }

  /* randomly remove a piece of eq from shopkeeper inventory */
  if (number(0, 5)==0) {
    temp = GET_OBJ_RNUM(obj);
    extract_obj(obj);
    return (&obj_proto[temp]);
  }

  SHOP_SORT(shop_nr)++;
  loop = keeper->carrying;
  obj_to_char(obj, keeper);
  keeper->carrying = loop;
  while (loop)
    {
      if (same_obj(obj, loop))
    {
      obj->next_content = loop->next_content;
      loop->next_content = obj;
      return (obj);
    }
      loop = loop->next_content;
    }
  keeper->carrying = obj;
  return (obj);
}
示例#4
0
文件: shop.c 项目: rparet/darkpawns
void
shopping_buy(char *arg, struct char_data *ch,
         struct char_data *keeper, int shop_nr)
{
  char tempstr[200], buf[MAX_STRING_LENGTH];
  struct obj_data *obj, *last_obj = NULL;
  int goldamt = 0, buynum, bought = 0;

  if (!(is_ok(keeper, ch, shop_nr)))
    return;

  if (SHOP_SORT(shop_nr) < IS_CARRYING_N(keeper))
    sort_keeper_objs(keeper, shop_nr);

  if ((buynum = transaction_amt(arg)) < 0)
    {
      sprintf(buf, "%s A negative amount?  Try selling me something.",
          GET_NAME(ch));
      do_tell(keeper, buf, cmd_tell, 0);
      return;
    }
  if (!(*arg) || !(buynum))
    {
      sprintf(buf, "%s What do you want to buy??", GET_NAME(ch));
      do_tell(keeper, buf, cmd_tell, 0);
      return;
    }
  if (!(obj = get_purchase_obj(ch, arg, keeper, shop_nr, TRUE)))
    return;

  if ((buy_price(ch, obj, shop_nr) > GET_GOLD(ch)) && !IS_GOD(ch))
    {
      sprintf(buf, shop_index[shop_nr].missing_cash2, GET_NAME(ch));
      do_tell(keeper, buf, cmd_tell, 0);

      switch (SHOP_BROKE_TEMPER(shop_nr))
    {
    case 0:
      do_action(keeper, GET_NAME(ch), cmd_puke, 0);
      return;
    case 1:
      do_echo(keeper, "smokes on his joint.", cmd_emote, SCMD_EMOTE);
      return;
    default:
      return;
    }
    }
  if ((IS_CARRYING_N(ch) + 1 > CAN_CARRY_N(ch)))
    {
      sprintf(buf, "%s: You can't carry any more items.\n\r",
          fname(obj->name));
      send_to_char(buf, ch);
      return;
    }
  if ((IS_CARRYING_W(ch) + GET_OBJ_WEIGHT(obj)) > CAN_CARRY_W(ch))
    {
      sprintf(buf, "%s: You can't carry that much weight.\n\r",
          fname(obj->name));
      send_to_char(buf, ch);
      return;
    }
  while ((obj) && ((GET_GOLD(ch) >= buy_price(ch, obj, shop_nr)) || IS_GOD(ch))
     && (IS_CARRYING_N(ch) < CAN_CARRY_N(ch)) && (bought < buynum)
     && (IS_CARRYING_W(ch) + GET_OBJ_WEIGHT(obj) <= CAN_CARRY_W(ch)))
    {
      bought++;
      /* Test if producing shop ! */
      if (shop_producing(obj, shop_nr))
    obj = read_object(GET_OBJ_RNUM(obj), REAL);
      else
    {
      obj_from_char(obj);
      SHOP_SORT(shop_nr)--;
    }
      obj_to_char(obj, ch);

      goldamt += buy_price(ch, obj, shop_nr);
      if (!IS_GOD(ch))
    GET_GOLD(ch) -= buy_price(ch, obj, shop_nr);

      last_obj = obj;
      obj = get_purchase_obj(ch, arg, keeper, shop_nr, FALSE);
      if (!same_obj(obj, last_obj))
    break;
    }

  if (bought < buynum)
    {
      if (!obj || !same_obj(last_obj, obj))
    sprintf(buf, "%s I only have %d to sell you.", GET_NAME(ch), bought);
      else if (GET_GOLD(ch) < buy_price(ch, obj, shop_nr))
    sprintf(buf, "%s You can only afford %d.", GET_NAME(ch), bought);
      else if (IS_CARRYING_N(ch) >= CAN_CARRY_N(ch))
    sprintf(buf, "%s You can only hold %d.", GET_NAME(ch), bought);
      else if (IS_CARRYING_W(ch) + GET_OBJ_WEIGHT(obj) > CAN_CARRY_W(ch))
    sprintf(buf, "%s You can only carry %d.", GET_NAME(ch), bought);
      else
    sprintf(buf, "%s Something screwy only gave you %d.", GET_NAME(ch),
        bought);
      do_tell(keeper, buf, cmd_tell, 0);
    }
  if (!IS_GOD(ch))
    GET_GOLD(keeper) += goldamt;

  sprintf(tempstr, "%s", times_message(ch->carrying, 0, bought));
  sprintf(buf, "$n buys %s.", tempstr);
  act(buf, FALSE, ch, obj, 0, TO_ROOM);

  sprintf(buf, shop_index[shop_nr].message_buy, GET_NAME(ch), goldamt);
  do_tell(keeper, buf, cmd_tell, 0);
  sprintf(buf, "You now have %s.\n\r", tempstr);
  send_to_char(buf, ch);

  if (SHOP_USES_BANK(shop_nr))
    if (GET_GOLD(keeper) > MAX_OUTSIDE_BANK)
      {
    SHOP_BANK(shop_nr) += (GET_GOLD(keeper) - MAX_OUTSIDE_BANK);
    GET_GOLD(keeper) = MAX_OUTSIDE_BANK;
      }
}
示例#5
0
文件: shop.c 项目: frasten/openleu
void shopping_buy( const char *arg, struct char_data *ch,
         struct char_data *keeper, int shop_nr)
{
  char argm[100], buf[MAX_STRING_LENGTH], newarg[100];
  int num = 1;
  struct obj_data *temp1;
  int i;
  float mult = 0;
  
  if(!(is_ok(keeper,ch,shop_nr)))
    return;

  if(keeper->generic != 0)
     for(i = 0; i <= MAX_TRADE; i++) {
       if(keeper->generic == FAMINE)
          if(shop_index[shop_nr].type[i] == ITEM_FOOD) {
            mult = shop_multiplier; /* we're in a famine, we sell food, so we */
            break;             /* our prices to hell ;-) -DM */ 
          }
       if(keeper->generic == DWARVES_STRIKE)
          if((shop_index[shop_nr].type[i] == ITEM_ARMOR) || (shop_index[shop_nr].type[i] == ITEM_WEAPON)) {
          mult = shop_multiplier;
          break;
       }        
     }
  
  only_argument(arg, argm);
  if(!(*argm))   {
      sprintf(buf,
              "%s what do you want to buy??"
              ,GET_NAME(ch));
      do_tell(keeper,buf,19);
      return;
    };
  
  if( ( num = getabunch( argm, newarg ) ) != 0 ) 
  {
    strcpy(argm,newarg);
  }
  if (num == 0) num = 1;
  
  if(!( temp1 = 
       get_obj_in_list_vis(ch,argm,keeper->carrying)))    {
      sprintf(buf,
              shop_index[shop_nr].no_such_item1
              ,GET_NAME(ch));
      do_tell(keeper,buf,19);
      return;
    }
  
  if(temp1->obj_flags.cost <= 0)    {
      sprintf(buf,
              shop_index[shop_nr].no_such_item1
              ,GET_NAME(ch));
      do_tell(keeper,buf,19);
      extract_obj(temp1);
      return;
    }
  
  if( GET_GOLD(ch) < (int) (num*(temp1->obj_flags.cost*
      shop_index[shop_nr].profit_buy -
      ((chr_apply[ (int)GET_CHR(ch) ].reaction*temp1->obj_flags.cost)/100) +
      (mult * temp1->obj_flags.cost))) && GetMaxLevel(ch)<DEMIGOD)    {
    sprintf(buf, shop_index[shop_nr].missing_cash2, GET_NAME(ch));
    do_tell(keeper,buf,19);
      
    switch(shop_index[shop_nr].temper1)        {
        case 0:
          do_action(keeper,GET_NAME(ch),30);
          return;
        case 1:
          do_emote(keeper,"grins happily",36);
          return;
        default:
          return;
    }
  }
  
  if ((IS_CARRYING_N(ch) + num) > (CAN_CARRY_N(ch)))
    {
      sprintf(buf,"%s : You can't carry that many items.\n\r", 
              fname(temp1->name));
      send_to_char(buf, ch);
      return;
    }
  
  if ((IS_CARRYING_W(ch) + (num * temp1->obj_flags.weight)) > CAN_CARRY_W(ch))
    {
      sprintf(buf,"%s : You can't carry that much weight.\n\r", 
              fname(temp1->name));
      send_to_char(buf, ch);
      return;
    }
  
  act("$n buys $p.", FALSE, ch, temp1, 0, TO_ROOM);
  
  sprintf(buf, shop_index[shop_nr].message_buy,
          GET_NAME(ch), (int) (num * (temp1->obj_flags.cost*
          shop_index[shop_nr].profit_buy -
          ((chr_apply[ (int)GET_CHR(ch)].reaction*temp1->obj_flags.cost)/100) + 
          (mult * temp1->obj_flags.cost))));
  
  do_tell(keeper,buf,19);
  
  sprintf(buf,"You now have %s (*%d).\n\r",
          temp1->short_description,num);
  
  send_to_char(buf,ch);
  
  while (num-- > 0) {
    
    if (GetMaxLevel(ch)<DEMIGOD)
      GET_GOLD(ch) -= (int)(temp1->obj_flags.cost*
      shop_index[shop_nr].profit_buy -
      ((chr_apply[ (int)GET_CHR(ch) ].reaction*temp1->obj_flags.cost)/100)+
      (mult * temp1->obj_flags.cost));
    
      GET_GOLD(keeper) += (int)(temp1->obj_flags.cost*
                shop_index[shop_nr].profit_buy -
                ((chr_apply[(int)GET_CHR(ch)].reaction*temp1->obj_flags.cost)/100)+
                (mult * temp1->obj_flags.cost));
    
    /* Test if producing shop ! */
    if (shop_producing(temp1,shop_nr))
      temp1 = read_object(temp1->item_number, REAL);
    else {
      obj_from_char(temp1);
      if (temp1 == NULL) {
        send_to_char("Sorry, I just ran out of those.\n\r",ch);
        GET_GOLD(ch) += (int)(temp1->obj_flags.cost*
                shop_index[shop_nr].profit_buy -
                ((chr_apply[ (int)GET_CHR(ch) ].reaction * 
                temp1->obj_flags.cost)/100)+
                (mult * temp1->obj_flags.cost));
        return;
      }
    }
    
    obj_to_char(temp1,ch);
    
  }
  return; 
}
示例#6
0
void shopping_buy( char *arg, struct char_data *ch,
	 struct char_data *keeper, int shop_nr)
{
	char argm[100], buf[MAX_STRING_LENGTH];
	struct obj_data *temp1;
	struct char_data *temp_char;

	if(!(is_ok(keeper,ch,shop_nr)))
		return;
	

	one_argument(arg, argm);
	if(!(*argm))
	{
		sprintf(buf,
		"%s what do you want to buy??"
		,GET_NAME(ch));
		do_tell(keeper,buf,19);
		return;
	};
	if(!( temp1 = 
		get_obj_in_list_vis(ch,argm,keeper->carrying)))
	{
		sprintf(buf,
		shop_index[shop_nr].no_such_item1
		,GET_NAME(ch));
		do_tell(keeper,buf,19);
		return;
	}

	if(temp1->obj_flags.cost <= 0)
	{
		sprintf(buf,
		shop_index[shop_nr].no_such_item1
		,GET_NAME(ch));
		do_tell(keeper,buf,19);
		extract_obj(temp1);
		return;
	}

	if(GET_GOLD(ch) < (int) (temp1->obj_flags.cost*
		shop_index[shop_nr].profit_buy) && GET_LEVEL(ch)<22)
	{
		sprintf(buf,
		shop_index[shop_nr].missing_cash2,
		GET_NAME(ch));
		do_tell(keeper,buf,19);

		switch(shop_index[shop_nr].temper1)
		{
			case 0:
				do_action(keeper,GET_NAME(ch),30);
				return;
			case 1:
				do_emote(keeper,"smokes on his joint",36);
				return;
			default:
				return;
		}
	}
	
	if ((IS_CARRYING_N(ch) + 1 > CAN_CARRY_N(ch)))
	{
		sprintf(buf,"%s : You can't carry that many items.\n\r", 
			fname(temp1->name));
		send_to_char(buf, ch);
		return;
	}

	if ((IS_CARRYING_W(ch) + temp1->obj_flags.weight) > CAN_CARRY_W(ch))
	{
		sprintf(buf,"%s : You can't carry that much weight.\n\r", 
			fname(temp1->name));
		send_to_char(buf, ch);
		return;
	}


	act("$n buys $p.", FALSE, ch, temp1, 0, TO_ROOM);

	sprintf(buf,
		shop_index[shop_nr].message_buy,
		GET_NAME(ch),
		(int) (temp1->obj_flags.cost*
			shop_index[shop_nr].profit_buy));
	do_tell(keeper,buf,19);
	sprintf(buf,"You now have %s.\n\r",
		temp1->short_description);
	send_to_char(buf,ch);
   if(GET_LEVEL(ch)<22)
		GET_GOLD(ch) -= (int)(temp1->obj_flags.cost*
			shop_index[shop_nr].profit_buy);

   GET_GOLD(keeper) += (int)(temp1->obj_flags.cost*
      shop_index[shop_nr].profit_buy);

	/* Test if producing shop ! */
	if(shop_producing(temp1,shop_nr))
		temp1 = read_object(temp1->item_number, REAL);
	else
		obj_from_char(temp1);

	obj_to_char(temp1,ch);

	return; 
}