It was a suggestion by Remmington I think.
Here is the code.
Change the cost of the bets by changing the -> static int cost <- in the code
- Code: Select all
using System;
using System.Collections.Generic;
using System.IO;
using i = MCDzienny.InfectionSystem;
namespace MCDzienny
{
public class CmdBet : Command
{
#region Toolbox
string path = "extra/bet.bool";
static int cost = 1; //change this to how much a bet should cost.
List<Player> bhuman = new List<Player>();
List<Player> bzombie = new List<Player>();
int dist = 0;
public override string name { get { return "bet"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "other"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
#endregion
#region Player Input
public override void Init()
{
if (!File.Exists(path))
File.WriteAllText(path, "true");
i.InfectionSystem.AnnounceWinners += new EventHandler<i.AnnounceWinnersEventArgs>(InfectionSystem_AnnounceWinners);
}
void InfectionSystem_AnnounceWinners(object sender, i.AnnounceWinnersEventArgs e)
{
if (e.NotInfected.Count != 0)
{
dist /= bhuman.Count;
bhuman.ForEach(delegate(Player p)
{
Player.SendMessage(p, "You know how to bet! %c+%e " + dist.ToString());
p.money += 1;
});
}
else
{
dist /= bzombie.Count;
bzombie.ForEach(delegate(Player p)
{
Player.SendMessage(p, "You know how to bet! %c+%e " + dist.ToString());
p.money += dist;
});
}
bhuman.Clear();
bzombie.Clear();
dist = 0;
}
public override void Use(Player p, string message)
{
if (enabled())
{
if (message == "") { Help(p); return; }
string[] split = message.Trim().Split(' ');
if (split[0] != "odds" && (p.money - cost) < 0)
{
Player.SendMessage(p, "You do not have enough money to bet.");
return;
}
switch (split[0])
{
case "alive":
case "humans":
bhuman.Add(p);
Player.GlobalMessage(p.PublicName + " has just bet on humans.");
SayStatistics(null);
dist += cost;
p.money -= cost;
return;
case "infected":
case "zombies":
bzombie.Add(p);
Player.GlobalMessage(p.PublicName + " has just bet on zombies.");
SayStatistics(null);
dist += cost;
p.money -= cost;
return;
case "odds":
SayStatistics(p);
return;
case "toggle":
if (p.group.Permission >= LevelPermission.Admin)
{
bool bo = !bool.Parse(path);
File.WriteAllText(path, bo.ToString());
Player.SendMessage(p, "Betting has been set to " + bo.ToString());
}
return;
default:
Help(p);
return;
}
}
else
{
Player.SendMessage(p, "Betting is not currently enabled.");
}
}
void SayStatistics(Player p)
{
int percentage;
int ex;
string who;
if (bzombie.Count > bhuman.Count)
{
if (bzombie.Count == 0)
ex = 1;
else
ex = bzombie.Count;
percentage = bhuman.Count / ex * 100;
who = "zombies";
}
else
{
if (bhuman.Count == 0)
ex = 1;
else
ex = bhuman.Count;
percentage = bzombie.Count / ex * 100;
who = "humans";
}
if (p == null)
Player.GlobalMessage("The odds are on " + who + " by " + percentage.ToString() + "%.");
else
Player.SendMessage(p, "The odds are on " + who + " by " + percentage.ToString() + "%.");
}
bool enabled()
{
try
{
return bool.Parse(path);
}
catch
{
return false;
}
}
public override void Help(Player p)
{
Player.SendMessage(p, "/bet humans -- bets that humans will win");
Player.SendMessage(p, "/bet zombies -- bets that zombies will win");
Player.SendMessage(p, "/bet odds -- tells you who people think will win");
if (p.group.Permission >= LevelPermission.Admin)
Player.SendMessage(p, "/bet toggle -- toggles betting");
}
#endregion
}
}