/************************************************************************** * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, * * Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. * * * * Merc Diku Mud improvements 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 * * benefiting. We hope that you share your changes too. What goes * * around, comes around. * *************************************************************************** * ROM 2.4 is copyright 1993-1998 Russ Taylor * * ROM has been brought to you by the ROM consortium * * Russ Taylor (rtaylor@hypercube.org) * * Gabrielle Taylor (gtaylor@hypercube.org) * * 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 * *************************************************************************** * 1stMUD ROM Derivative (c) 2001-2002 by Ryan Jennings * * http://1stmud.dlmud.com/ <r-jenn@shaw.ca> * ***************************************************************************/ #include <sys/types.h> #include <stdio.h> #include <time.h> #include "merc.h" int share_value; #define MAX_IN_BANK 20000000 CH_CMD(do_balance) { chprintlnf(ch, "Balance : %ld gold, %ld silver\n\r" "On Hand : %ld gold, %ld silver\n\r" "Shares : %d gold in %d shares\n\r", ch->pcdata->gold_bank, ch->pcdata->silver_bank, ch->gold, ch->silver, (ch->pcdata->shares * share_value), ch->pcdata->shares); } CH_CMD(do_bank) { char arg1[MIL]; char arg2[MIL]; char arg3[MIL]; bool gold = TRUE; if (!ch) return; if (IS_NPC(ch)) { chprintln(ch, "Banking Services are only available to players!"); return; } if (!IS_SET(ch->in_room->room_flags, ROOM_BANK)) { chprintln(ch, "You can't do that here."); return; } if ((time_info.hour < 6 || time_info.hour > 18)) { chprintln(ch, "The bank is closed, it is open from 6am to 6pm."); return; } if (IS_NULLSTR(argument)) { chprintln(ch, "Bank Options :\n\r"); chprintln(ch, "Bank balance : Displays your balance."); chprintln(ch, "Bank deposit : Deposit gold into your account."); chprintln(ch, "Bank withdraw : Withdraw gold from your account."); chprintln(ch, "Bank transfer : Transfer gold to someones account."); chprintln(ch, "Bank buy # : Buy # shares"); chprintln(ch, "Bank sell # : Sell # shares"); chprintln(ch, "Bank check : Check the current rates of the shares."); return; } argument = one_argument(argument, arg1); argument = one_argument(argument, arg2); argument = one_argument(argument, arg3); if (!str_prefix(arg1, "balance")) { do_balance(ch, ""); return; } if (!str_prefix(arg1, "deposit")) { long amount; if (IS_NULLSTR(arg2) || IS_NULLSTR(arg3) || !is_number(arg2) || (str_cmp(arg3, "gold") && str_cmp(arg3, "silver"))) { chprintln(ch, "Syntax: bank deposit <amount> gold|silver"); return; } gold = !str_cmp(arg3, "gold"); amount = advatoi(arg2); if (amount > (gold ? ch->gold : ch->silver)) { chprintlnf(ch, "How can you deposit %ld %s when you only have %ld?", amount, gold ? "gold" : "silver", ch->gold); return; } if (amount < 0) { chprintlnf(ch, "Only positive figures are allowed."); return; } if ((gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank) + amount >= MAX_IN_BANK) { chprintlnf(ch, "Sorry our vaults can't hold that much!"); return; } if (gold) { ch->gold = UMAX(0, ch->gold - amount); ch->pcdata->gold_bank = UMAX(0, ch->pcdata->gold_bank + amount); } else { ch->silver = UMAX(0, ch->silver - amount); ch->pcdata->silver_bank = UMAX(0, ch->pcdata->silver_bank + amount); } chprintlnf(ch, "You deposit %ld %s. Your new balance is %ld %s.\n\r", amount, gold ? "gold" : "silver", gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank, gold ? "gold" : "silver"); return; } if (!str_prefix(arg1, "transfer")) { long amount; CHAR_DATA *victim; if (IS_NULLSTR(arg2) || IS_NULLSTR(arg3) || IS_NULLSTR(argument) || !is_number(arg2) || (str_cmp(arg3, "gold") && str_cmp(arg3, "silver"))) { chprintln(ch, "Syntax: bank transfer <amount> gold|silver <player>"); return; } gold = !str_cmp(arg3, "gold"); amount = advatoi(arg2); if (amount > (gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank)) { chprintlnf(ch, "How can you transfer %ld %s when your balance is %ld?", amount, gold ? "gold" : "silver", gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank); return; } if (amount < 0) { chprintlnf(ch, "Only positive figures are allowed."); return; } if (!(victim = get_char_world(ch, argument))) { chprintlnf(ch, "%s doesn't have a bank account.", argument); return; } if (IS_NPC(victim)) { chprintln(ch, "You can only transfer money to players."); return; } if ((gold ? victim->pcdata->gold_bank : victim->pcdata->silver_bank) + amount >= MAX_IN_BANK) { chprintlnf(ch, "Sorry %s's account can't hold that much!", victim->name); return; } if (gold) { ch->pcdata->gold_bank = UMAX(0, ch->pcdata->gold_bank - amount); victim->pcdata->gold_bank = UMAX(0, victim->pcdata->gold_bank + amount); } else { ch->pcdata->silver_bank = UMAX(0, ch->pcdata->silver_bank - amount); victim->pcdata->silver_bank = UMAX(0, victim->pcdata->silver_bank + amount); } chprintlnf (ch, "You transfer %ld %s. Your new balance is %ld %s.", amount, gold ? "gold" : "silver", gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank, gold ? "gold" : "silver"); chprintlnf (victim, "[BANK] %s has transferred %ld %s to your account.", PERS(ch, victim), amount, gold ? "gold" : "silver"); return; } if (!str_prefix(arg1, "withdraw")) { long amount; if (IS_NULLSTR(arg2) || IS_NULLSTR(arg3) || !is_number(arg2) || (str_cmp(arg3, "gold") && str_cmp(arg3, "silver"))) { chprintln(ch, "Syntax: bank withdraw <amount> gold|silver"); return; } gold = !str_cmp(arg3, "gold"); amount = advatoi(arg2); if (amount > (gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank)) { chprintlnf(ch, "How can you withdraw %ld %s when your balance is %ld?", amount, gold ? "gold" : "silver", gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank); return; } if (amount < 0) { chprintlnf(ch, "Only positive figures are allowed."); return; } if ((gold ? ch->gold : ch->silver) + amount >= MAX_IN_BANK) { chprintlnf(ch, "Sorry you can't hold that much!"); return; } if (gold) { ch->pcdata->gold_bank = UMAX(0, ch->pcdata->gold_bank - amount); ch->gold = UMAX(0, ch->gold + amount); } else { ch->pcdata->silver_bank = UMAX(0, ch->pcdata->silver_bank - amount); ch->silver = UMAX(0, ch->silver + amount); } chprintlnf(ch, "You withdraw %ld %s. Your new balance is %ld %s.\n\r", amount, gold ? "gold" : "silver", gold ? ch->pcdata->gold_bank : ch->pcdata->silver_bank, gold ? "gold" : "silver"); return; } if (!str_prefix(arg1, "buy")) { int amount; if (is_number(arg2)) { amount = advatoi(arg2); if (ch->pcdata->shares + amount > 10000) { chprintln(ch, "The Mayor has set a limit of 10000 shares."); return; } if ((amount * share_value) > ch->pcdata->gold_bank) { chprintlnf(ch, "%d shares will cost you %d gold, deposit more gold.", amount, (amount * share_value)); return; } if (amount < 0) { chprintlnf(ch, "If you want to sell shares you have to say so..."); return; } ch->pcdata->gold_bank = UMAX(0, ch->pcdata->gold_bank - (amount * share_value)); ch->pcdata->shares = URANGE(0, ch->pcdata->shares + amount, 10000); chprintlnf(ch, "You buy %d shares for %d gold, you now have %d shares.", amount, (amount * share_value), ch->pcdata->shares); return; } } if (!str_prefix(arg1, "sell")) { int amount; if (is_number(arg2)) { amount = advatoi(arg2); if (amount > ch->pcdata->shares) { chprintlnf(ch, "You only have %d shares.", ch->pcdata->shares); return; } if (amount < 0) { chprintlnf(ch, "If you want to buy shares you have to say so..."); return; } if (ch->pcdata->gold_bank + (amount * share_value) >= MAX_IN_BANK) ch->pcdata->gold_bank = MAX_IN_BANK; else ch->pcdata->gold_bank = UMAX(0, ch->pcdata->gold_bank + (amount * share_value)); ch->pcdata->shares = UMAX(0, ch->pcdata->shares - amount); chprintlnf(ch, "You sell %d shares for %d gold, you now have %d shares.", amount, (amount * share_value), ch->pcdata->shares); return; } } if (!str_prefix(arg1, "check")) { chprintlnf(ch, "The current shareprice is %d.", share_value); if (ch->pcdata->shares) { chprintlnf(ch, "You currently have %d shares, (%d a share) worth totally %d gold.", ch->pcdata->shares, share_value, (ch->pcdata->shares * share_value)); } return; } chprintlnf(ch, "I don't know what you mean"); do_bank(ch, ""); return; }