/// <summary> /// Gets currency statistics on logged-in players. /// /// We may want to go as far as to split currency into racewar sides and /// poll pfiles for totals for not-in-game players. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Economy(CharData ch, string[] str) { if( ch == null ) return; if (str.Length > 0 && ("mostexpensive").StartsWith(str[0])) { int[] items = new int[Enum.GetValues(typeof(ObjTemplate.ObjectType)).Length]; int[] itemValues = new int[items.Length]; int[] armors = new int[31]; int[] armorValues = new int[31]; foreach (Area area in Database.AreaList) { foreach (ObjTemplate obj in area.Objects) { if (obj.Cost > itemValues[(int)obj.ItemType]) { itemValues[(int)obj.ItemType] = obj.Cost; items[(int)obj.ItemType] = obj.IndexNumber; } if (obj.ItemType == ObjTemplate.ObjectType.armor) { for (int i = 0; i < 32; i++) { if ((obj.WearFlags[0] & (1 << i)) != 0) { if (obj.Cost > armorValues[i]) { armorValues[i] = obj.Cost; armors[i] = obj.IndexNumber; } } } } } } for (int i = 0; i < items.Length; i++) { if (items[i] != 0) { ch.SendText("ItemType: " + ((ObjTemplate.ObjectType)i).ToString() + " " + Database.GetObjTemplate(items[i]).ShortDescription + " = " + itemValues[i] + "c.\r\n"); } else { ch.SendText("ItemType: " + ((ObjTemplate.ObjectType)i).ToString() + " has no items of value.\r\n"); } } for (int i = 0; i < armors.Length; i++) { if (armors[i] != 0) { ch.SendText("ArmorSlot: " + (1 << i) + " " + Database.GetObjTemplate(armors[i]).ShortDescription + "&n = " + armorValues[i] + "c.\r\n"); } else { ch.SendText("ArmorSlot: " + (1 << i) + " has no items of value.\r\n"); } } return; } Coins player = new Coins(); Coins mob = new Coins(); Coins bank = new Coins(); foreach (CharData worldChar in Database.CharList) { if (worldChar.IsNPC()) { mob.Copper += worldChar.GetCopper(); mob.Silver += worldChar.GetSilver(); mob.Gold += worldChar.GetGold(); mob.Platinum += worldChar.GetPlatinum(); } else { player.Copper += worldChar.GetCopper(); player.Silver += worldChar.GetSilver(); player.Gold += worldChar.GetGold(); player.Platinum += worldChar.GetPlatinum(); bank.Copper += ((PC)worldChar).Bank.Copper; bank.Silver += ((PC)worldChar).Bank.Silver; bank.Gold += ((PC)worldChar).Bank.Gold; bank.Platinum += ((PC)worldChar).Bank.Platinum; } } int mobcash = mob.Copper + (mob.Silver * 10) + (mob.Gold * 100) + (mob.Platinum * 100); int playercash = player.Copper + (player.Silver * 10) + (player.Gold * 100) + (player.Platinum * 100); int playerbank = bank.Copper + (bank.Silver * 10) + (bank.Gold * 100) + (bank.Platinum * 100); int totalcirculation = mobcash + playercash; int totaleconomy = totalcirculation + playerbank; string buf = "Mobiles currently control " + mobcash + " &+ycopper&n in circulating currency.\r\n"; buf += "Players currently control " + playercash + " &+ycopper&n in circulating currency.\r\n"; buf += "Players currently control " + playerbank + " &+ycopper&n in non-circulating currency.\r\n"; // Protect against divide by 0. if (mobcash == 0) mobcash = 1; double playerpct1 = ((double)playercash * 100.0) / ((double)(totalcirculation)); double playerpct2 = (((double)playercash + (double)playerbank) * 100.0) / ((double)totaleconomy); buf += "Players currently control " + playerpct1 + " percent of circulating currency.\r\n"; buf += "Players currently control " + playerpct2 + " percent of total currency.\r\n"; buf += "&+yMaterial Costs:&n\r\n"; int place = 0; foreach (Material mat in Material.Table) { buf += MUDString.PadStr(mat.ShortDescription, 14) + ":" + MUDString.PadStr(mat.Value.ToString(), 4); if ((place % 3) == 2) { buf += "\r\n"; } else { buf += " "; } ++place; } ch.SendText(buf); ch.SendText("Type 'economy mostexpensive' to show most valuable item of each type.\r\n"); }
public static void GuildDonate(CharData ch, string[] str) { if( ch == null ) return; Coins coin = new Coins(); int coinage; bool success = false; if (ch.IsNPC()) { return; } Guild guild = ((PC)ch).GuildMembership; if (guild == null) { ch.SendText("You're not in a guild!\r\n"); return; } if (str.Length == 0) { ch.SendText("Deposit what?\r\n"); return; } if (!coin.FillFromString(str, ch)) { ch.SendText("&+LSyntax: &+RSoc deposit &n&+r<&+L# of coins&n&+r> <&+Lcoin type&n&+r>&n\r\n"); return; } if (coin.Copper == 0 && coin.Silver == 0 && coin.Gold == 0 && coin.Platinum == 0) { ch.SendText("You have none of that type of &+Lcoin&n yet.\r\n"); return; } for (coinage = 0; coinage < 4; coinage++) { switch (coinage) { case 0: //copper if (coin.Copper < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Copper > ch.GetCopper()) { ch.SendText("You don't have that much &+ycopper&n coin!\r\n"); continue; } if (coin.Copper == 0) continue; ch.SpendCopper(coin.Copper); success = true; break; case 1: //silver if (coin.Silver < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Silver > ch.GetSilver()) { ch.SendText("You don't have that much &+wsilver&n coin!\r\n"); continue; } if (coin.Silver == 0) continue; ch.SpendSilver(coin.Silver); success = true; break; case 2: //gold if (coin.Gold < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Gold > ch.GetGold()) { ch.SendText("You don't have that much &+Ygold&n coin!\r\n"); continue; } if (coin.Gold == 0) continue; ch.SpendGold(coin.Gold); success = true; break; case 3: //platinum if (coin.Platinum < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Platinum > ch.GetPlatinum()) { ch.SendText("You don't have that much &+Wplatinum&n coin!\r\n"); continue; } if (coin.Platinum == 0) continue; ch.SpendPlatinum(coin.Platinum); success = true; break; } //end switch } //end for if (success) { int value = coin.Copper + 10 * coin.Silver + 100 * coin.Gold + 1000 * coin.Platinum; int count; for (count = 0; count < Limits.MAX_GUILD_MEMBERS; ++count) { if (!MUDString.StringsNotEqual(guild.Members[count].Name, ch.Name)) { guild.Members[count].Fine -= value; if (guild.Members[count].Fine < 0) { guild.Members[count].Fine = 0; ch.SendText("&+WThank you for the donation!&n\r\n"); } else { ch.SendText("You reduce your fine.\r\n"); } } } guild.GuildBankAccount.Copper += coin.Copper; guild.GuildBankAccount.Silver += coin.Silver; guild.GuildBankAccount.Gold += coin.Gold; guild.GuildBankAccount.Platinum += coin.Platinum; guild.Save(); CharData.SavePlayer(ch); } else { ch.SendText("&+LSyntax: &+RSoc deposit &n&+r<&+L# of coins&n&+r> <&+Lcoin type&n&+r>&n\r\n"); } return; }
/// <summary> /// Put coins into a bank account. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Deposit(CharData ch, string[] str) { if( ch == null ) return; int coinage; bool success = false; Coins coin = new Coins(); if (ch.IsNPC()) { ch.SendText("NPCs do not have bank accounts!\r\n"); return; } if (!ch.InRoom || !ch.InRoom.HasFlag(RoomTemplate.ROOM_BANK)) { ch.SendText("You're not in a bank!\r\n"); return; } if (str.Length == 0) { ch.SendText("Deposit what?\r\n"); return; } if (!coin.FillFromString(str, ch)) { ch.SendText("&+LSyntax: &+RDeposit &n&+r<&+L# of coins&n&+r> <&+Lcoin type&n&+r>&n\r\n"); return; } if (coin.Copper == 0 && coin.Silver == 0 && coin.Gold == 0 && coin.Platinum == 0) { ch.SendText("You have none of that type of &+Lcoin&n yet.\r\n"); return; } for (coinage = 0; coinage < 4; coinage++) { switch (coinage) { case 0: //copper if (coin.Copper < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Copper > ch.GetCopper()) { ch.SendText("You don't have that much &+ycopper&n coin!\r\n"); continue; } if (coin.Copper == 0) continue; ch.SpendCopper(coin.Copper); ((PC)ch).Bank.Copper += coin.Copper; success = true; break; case 1: //silver if (coin.Silver < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Silver > ch.GetSilver()) { ch.SendText("You don't have that much &+wsilver&n coin!\r\n"); continue; } if (coin.Silver == 0) continue; ch.SpendSilver(coin.Silver); ((PC)ch).Bank.Silver += coin.Silver; success = true; break; case 2: //gold if (coin.Gold < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Gold > ch.GetGold()) { ch.SendText("You don't have that much &+Ygold&n coin!\r\n"); continue; } if (coin.Gold == 0) continue; ch.SpendGold(coin.Gold); ((PC)ch).Bank.Gold += coin.Gold; success = true; break; case 3: //platinum if (coin.Platinum < 0) { ch.SendText("You can't deposit a debt!\r\n"); continue; } if (coin.Platinum > ch.GetPlatinum()) { ch.SendText("You don't have that much &+Wplatinum&n coin!\r\n"); continue; } if (coin.Platinum == 0) continue; ch.SpendPlatinum(coin.Platinum); ((PC)ch).Bank.Platinum += coin.Platinum; success = true; break; } //end switch } //end for if (success) { ch.SendText("You make your deposit.\r\n"); SocketConnection.Act("$n&n makes a transaction.", ch, null, null, SocketConnection.MessageTarget.room); } else { ch.SendText("&+LSyntax: &+RDeposit &n&+r<&+L# of coins&n&+r> <&+Lcoin type&n&+r>&n\r\n"); } return; }
/// <summary> /// Take money out of your bank account. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Withdraw(CharData ch, string[] str) { if( ch == null ) return; int coinage; bool success = false; Coins coin = new Coins(); if (ch.IsNPC()) { return; } if (!ch.InRoom || !ch.InRoom.HasFlag(RoomTemplate.ROOM_BANK)) { ch.SendText("You're not in a bank!\r\n"); return; } if (str.Length == 0) { ch.SendText("Withdraw what?\r\n"); return; } if (!coin.FillFromString(str, ch)) { ch.SendText("&+LSyntax: &+RWithdraw &n&+r<&+L# of coins&n&+r> <&+Lcoin type&n&+r>&n\r\n"); return; } if (coin.Copper == 0 && coin.Silver == 0 && coin.Gold == 0 && coin.Platinum == 0) { ch.SendText("The bank has none of that type of &+Lcoin&n yet.\r\n"); return; } for (coinage = 0; coinage < 4; coinage++) { switch (coinage) { case 0: //copper if (coin.Copper < 0) { ch.SendText("You can't liquidate a debt!\r\n"); continue; } if (coin.Copper > ((PC)ch).Bank.Copper) { ch.SendText("You haven't saved that much &+ycopper&n coin!\r\n"); continue; } if (coin.Copper == 0) continue; ch.ReceiveCopper(coin.Copper); ((PC)ch).Bank.Copper -= coin.Copper; success = true; break; case 1: //silver if (coin.Silver < 0) { ch.SendText("You can't liquidate a debt!\r\n"); continue; } if (coin.Silver > ((PC)ch).Bank.Silver) { ch.SendText("You haven't saved that much &+wsilver&n coin!\r\n"); continue; } if (coin.Silver == 0) continue; ch.ReceiveSilver(coin.Silver); ((PC)ch).Bank.Silver -= coin.Silver; success = true; break; case 2: //gold if (coin.Gold < 0) { ch.SendText("You can't liquidate a debt!\r\n"); continue; } if (coin.Gold > ((PC)ch).Bank.Gold) { ch.SendText("You haven't saved that much &+Ygold&n coin!\r\n"); continue; } if (coin.Gold == 0) continue; ch.ReceiveGold(coin.Gold); ((PC)ch).Bank.Gold -= coin.Gold; success = true; break; case 3: //platinum if (coin.Platinum < 0) { ch.SendText("You can't liquidate a debt!\r\n"); continue; } if (coin.Platinum > ((PC)ch).Bank.Platinum) { ch.SendText("You haven't saved that much &+Wplatinum&n coin!\r\n"); continue; } if (coin.Platinum == 0) continue; ch.ReceivePlatinum(coin.Platinum); ((PC)ch).Bank.Platinum -= coin.Platinum; success = true; break; } //end switch } //end for if (success) { ch.SendText("You make a withdrawal.\r\n"); SocketConnection.Act("$n&n makes a transaction.", ch, null, null, SocketConnection.MessageTarget.room); } else { ch.SendText("&+LSyntax: &+RDeposit &n&+r<&+L# of coins&n&+r> <&+Lcoin type&n&+r>&n\r\n"); } return; }
/// <summary> /// This modified version for the 4-type coin system by Xangis /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Split(CharData ch, string[] str) { if( ch == null ) return; int members = 0; int coinage; bool success = false; Coins coin = new Coins(); if (!ch.GroupLeader) { ch.SendText("Split with yourself? How generous!\r\n"); return; } if (str.Length == 0) { ch.SendText("Split how much?\r\n"); return; } if (!coin.FillFromString(str, ch)) { ch.SendText("Try 'split <number/all> <coin type>' or 'split all.coins' \r\n"); return; } if (coin.Copper == 0 && coin.Silver == 0 && coin.Gold == 0 && coin.Platinum == 0) { ch.SendText("Try sharing some actual coins!\r\n"); return; } foreach (CharData groupChar in ch.InRoom.People) { if (groupChar.IsSameGroup(ch)) { members++; } } if (members < 2) { ch.SendText("Just keep it all.\r\n"); Log.Error("Commandsplit: managed to find a group of 1 person\r\n", 0); return; } for (coinage = 0; coinage < 4; coinage++) { switch (coinage) { case 0: //copper if (coin.Copper <= 0) continue; //quietly ignore errors int share; int extra; string buf; if (coin.Copper <= ch.GetCopper()) { share = coin.Copper / members; extra = coin.Copper % members; if (share == 0) continue; ch.SpendCopper(coin.Copper); buf = String.Format( "You split {0} &+ycopper&n. Your share is {1} coins.\r\n", coin.Copper, share + extra); ch.SendText(buf); buf = String.Format("$n splits some &+ycopper&n. Your share is {0} coins.", share); foreach (CharData groupChar in ch.InRoom.People) { if (groupChar != ch && groupChar.IsSameGroup(ch)) { SocketConnection.Act(buf, ch, null, groupChar, SocketConnection.MessageTarget.victim); groupChar.ReceiveCopper(share); } else if (groupChar == ch) groupChar.ReceiveCopper(share + extra); } success = true; continue; } ch.SendText("You don't have that much &+ycopper&n coin!\r\n"); break; case 1: //silver if (coin.Silver <= 0) continue; //quietly ignore errors if (coin.Silver <= ch.GetSilver()) { share = coin.Silver / members; extra = coin.Silver % members; if (share == 0) continue; ch.SpendSilver(coin.Silver); buf = String.Format( "You split {0} &+wsilver&n. Your share is {1} coins.\r\n", coin.Silver, share + extra); ch.SendText(buf); buf = String.Format("$n splits some &+wsilver&n. Your share is {0} coins.", share); foreach (CharData groupChar in ch.InRoom.People) { if (groupChar != ch && groupChar.IsSameGroup(ch)) { SocketConnection.Act(buf, ch, null, groupChar, SocketConnection.MessageTarget.victim); groupChar.ReceiveSilver(share); } else if (groupChar == ch) { groupChar.ReceiveSilver(share + extra); } } success = true; continue; } else ch.SendText("You don't have that much &+wsilver&n coin!\r\n"); break; case 2: //gold if (coin.Gold <= 0) continue; //quietly ignore errors if (coin.Gold <= ch.GetGold()) { share = coin.Gold / members; extra = coin.Gold % members; if (share == 0) continue; ch.SpendGold(coin.Gold); buf = String.Format("You split {0} &+Ygold&n. Your share is {1} coins.\r\n", coin.Gold, share + extra); ch.SendText(buf); buf = String.Format("$n splits some &+Ygold&n. Your share is {0} coins.", share); foreach (CharData groupChar in ch.InRoom.People) { if (groupChar != ch && groupChar.IsSameGroup(ch)) { SocketConnection.Act(buf, ch, null, groupChar, SocketConnection.MessageTarget.victim); groupChar.ReceiveGold(share); } else if (groupChar == ch) { groupChar.ReceiveGold(share + extra); } } success = true; continue; } else { ch.SendText("You don't have that much &+Ygold&n coin!\r\n"); } break; case 3: //platinum if (coin.Platinum <= 0) continue; //quietly ignore errors if (coin.Platinum <= ch.GetPlatinum()) { share = coin.Platinum / members; extra = coin.Platinum % members; if (share == 0) continue; ch.SpendPlatinum(coin.Platinum); buf = String.Format("You split {0} &+Wplatinum&n. Your share is {1} coins.\r\n", coin.Platinum, share + extra); ch.SendText(buf); buf = String.Format("$n splits some &+Wplatinum&n. Your share is {0} coins.", share); foreach (CharData groupChar in ch.InRoom.People) { if (groupChar != ch && groupChar.IsSameGroup(ch)) { SocketConnection.Act(buf, ch, null, groupChar, SocketConnection.MessageTarget.victim); groupChar.ReceivePlatinum(share); } else if (groupChar == ch) { groupChar.ReceivePlatinum(share + extra); } } success = true; continue; } ch.SendText("You don't have that much &+Wplatinum&n coin!\r\n"); break; } //end switch } //end for if (!success) { ch.SendText("You didn't seem to split anything.\r\n"); } return; }
/// <summary> /// Initialize a new PC with default values. /// </summary> public PC() { ++NumPc; Prompt = "&+g<%hhp %mm %vmv>\r\n<&n%D %B&+g>&n "; Score = 0.0; PageLength = 25; IsSwitched = false; Speaking = 0; ActionFlags[0] = PLAYER_CAST_TICK.Vector | PLAYER_TELL.Vector | PLAYER_SHOUT.Vector | PLAYER_PROMPT.Vector | PLAYER_COMBINE.Vector | PLAYER_MAP.Vector | PLAYER_PAGER.Vector | PLAYER_AUTOWRAP.Vector | PLAYER_COLOR.Vector | PLAYER_VICIOUS.Vector; HitpointModifier = 0; GuildRank = 0; Train = 0; Frags = 0; PlayerKills = 0; PlayerDeaths = 0; MobKills = 0; MobDeaths = 0; FirstaidTimer = 0; CreationTime = new DateTime(); // Creation time, actual. Created = new ItemStatus(); Destroyed = new ItemStatus(); Birthdate = new DateTime(); // Creation time used for age calculations. Unlike creation time, it can change. OriginalHome = StaticRooms.GetRoomNumber("ROOM_NUMBER_START"); CurrentHome = StaticRooms.GetRoomNumber("ROOM_NUMBER_START"); Height = 60 + MUDMath.Dice(2, 10); Weight = 15 + (Height * 2); RaceStrMod = 0; RaceIntMod = 0; RaceWisMod = 0; RaceDexMod = 0; RaceConMod = 0; RaceAgiMod = 0; RaceChaMod = 0; RacePowMod = 0; RaceLukMod = 0; MaxStrMod = 0; MaxIntMod = 0; MaxWisMod = 0; MaxDexMod = 0; MaxConMod = 0; MaxAgiMod = 0; MaxChaMod = 0; MaxPowMod = 0; MaxLukMod = 0; AggressiveLevel = -1; Tradition = 0; SkillPoints = 0; Chi = 0; MaxChi = 0; Stance = String.Empty; LastRentLocation = 0; LostHp = 0; MonkRestriction = 0; IsWieldingTwohanded = false; Editing = SocketConnection.EditState.none; Security = 0; int count; SpellAptitude = new SerializableDictionary <String, Int32>(); SkillAptitude = new SerializableDictionary <String, Int32>(); SongAptitude = new SerializableDictionary <String, Int32>(); MonkAptitude = new SerializableDictionary <String, Int32>(); LanguageAptitude = new int[Race.MAX_LANG]; for (count = 0; count < Race.MAX_LANG; ++count) { LanguageAptitude[count] = 0; } TrophyData = new TrophyData[Limits.MAX_LEVEL]; for (count = 0; count < Limits.MAX_LEVEL; ++count) { TrophyData[count] = new TrophyData(); TrophyData[count].MobIndexNumber = 0; TrophyData[count].NumberKilled = 0; } Thirst = 48; Hunger = 48; Drunk = 0; Bank = new Coins(); Bank.Copper = 0; Bank.Silver = 0; Bank.Gold = 0; Bank.Platinum = 0; }
/// <summary> /// Initialize a new PC with default values. /// </summary> public PC() { ++NumPc; Prompt = "&+g<%hhp %mm %vmv>\r\n<&n%D %B&+g>&n "; Score = 0.0; PageLength = 25; IsSwitched = false; Speaking = 0; ActionFlags[0] = PLAYER_CAST_TICK.Vector | PLAYER_TELL.Vector | PLAYER_SHOUT.Vector | PLAYER_PROMPT.Vector | PLAYER_COMBINE.Vector | PLAYER_MAP.Vector | PLAYER_PAGER.Vector | PLAYER_AUTOWRAP.Vector | PLAYER_COLOR.Vector | PLAYER_VICIOUS.Vector; HitpointModifier = 0; GuildRank = 0; Train = 0; Frags = 0; PlayerKills = 0; PlayerDeaths = 0; MobKills = 0; MobDeaths = 0; FirstaidTimer = 0; CreationTime = new DateTime(); // Creation time, actual. Created = new ItemStatus(); Destroyed = new ItemStatus(); Birthdate = new DateTime(); // Creation time used for age calculations. Unlike creation time, it can change. OriginalHome = StaticRooms.GetRoomNumber("ROOM_NUMBER_START"); CurrentHome = StaticRooms.GetRoomNumber("ROOM_NUMBER_START"); Height = 60 + MUDMath.Dice( 2, 10 ); Weight = 15 + ( Height * 2 ); RaceStrMod = 0; RaceIntMod = 0; RaceWisMod = 0; RaceDexMod = 0; RaceConMod = 0; RaceAgiMod = 0; RaceChaMod = 0; RacePowMod = 0; RaceLukMod = 0; MaxStrMod = 0; MaxIntMod = 0; MaxWisMod = 0; MaxDexMod = 0; MaxConMod = 0; MaxAgiMod = 0; MaxChaMod = 0; MaxPowMod = 0; MaxLukMod = 0; AggressiveLevel = -1; Tradition = 0; SkillPoints = 0; Chi = 0; MaxChi = 0; Stance = String.Empty; LastRentLocation = 0; LostHp = 0; MonkRestriction = 0; IsWieldingTwohanded = false; Editing = SocketConnection.EditState.none; Security = 0; int count; SpellAptitude = new SerializableDictionary<String, Int32>(); SkillAptitude = new SerializableDictionary<String, Int32>(); SongAptitude = new SerializableDictionary<String, Int32>(); MonkAptitude = new SerializableDictionary<String, Int32>(); LanguageAptitude = new int[Race.MAX_LANG]; for (count = 0; count < Race.MAX_LANG; ++count) { LanguageAptitude[ count ] = 0; } TrophyData = new TrophyData[ Limits.MAX_LEVEL ]; for( count = 0; count < Limits.MAX_LEVEL; ++count ) { TrophyData[ count ] = new TrophyData(); TrophyData[ count ].MobIndexNumber = 0; TrophyData[ count ].NumberKilled = 0; } Thirst = 48; Hunger = 48; Drunk = 0; Bank = new Coins(); Bank.Copper = 0; Bank.Silver = 0; Bank.Gold = 0; Bank.Platinum = 0; }