Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
@@ -0,0 +1,373 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
using Server.Network;
|
||||
using Server.Engines.LotterySystem;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class PowerBallStatsGump : Gump
|
||||
{
|
||||
private const int labelColor = 2101;
|
||||
private const int GMColor = 33;
|
||||
|
||||
private PowerBall m_PowerBall;
|
||||
private Mobile m_From;
|
||||
|
||||
public PowerBallStatsGump(PowerBall item, Mobile from)
|
||||
: base(50, 50)
|
||||
{
|
||||
m_PowerBall = item;
|
||||
m_From = from;
|
||||
|
||||
int gameNumber = 0;
|
||||
|
||||
if (PowerBall.Game != null)
|
||||
gameNumber = PowerBall.Game.GameNumber;
|
||||
|
||||
AddPage(0);
|
||||
|
||||
AddBackground(50, 0, 350, 350, 9250);
|
||||
|
||||
AddPage(1);
|
||||
|
||||
if (PowerBall.Game != null && PowerBall.Game.IsActive)
|
||||
AddLabel(70, 15, labelColor, String.Format("Current Powerball Game: {0}", gameNumber));
|
||||
else
|
||||
AddLabel(70, 20, GMColor, "Offline");
|
||||
|
||||
if (m_From.AccessLevel > AccessLevel.Player)
|
||||
{
|
||||
AddLabel(70, 40, GMColor, String.Format("Gold Sink: {0}", PowerBall.GoldSink));
|
||||
|
||||
if (PowerBall.Instance != null)
|
||||
{
|
||||
AddLabel(225, 40, GMColor, "Current Game's Profit:");
|
||||
AddLabel(325, 60, GMColor, String.Format("{0}", PowerBall.Instance.Profit));
|
||||
}
|
||||
|
||||
AddLabel(70, 185, GMColor, "*Warning* GM Options *Warning*");
|
||||
|
||||
AddLabel(105, 215, GMColor, "Reset All Stats");
|
||||
AddButton(70, 215, 0xFBD, 0xFBF, 2, GumpButtonType.Reply, 0);
|
||||
|
||||
AddLabel(105, 245, GMColor, "Current Game Guaratee Jackpot");
|
||||
AddButton(70, 245, 0xFBD, 0xFBF, 3, GumpButtonType.Reply, 0);
|
||||
|
||||
AddLabel(105, 275, GMColor, m_PowerBall.IsActive ? "Set Game Inactive" : "Set Active");
|
||||
AddButton(70, 275, 0xFBD, 0xFBF, 4, GumpButtonType.Reply, 0);
|
||||
|
||||
if (PowerBall.Game != null && PowerBall.Game.MaxWhiteBalls <= 20)
|
||||
{
|
||||
long odds = GetOdds();
|
||||
if (odds > 6)
|
||||
AddLabel(70, 305, GMColor, String.Format("Jackpot Odds: 1 in {0}", odds));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int hue = 2041;
|
||||
|
||||
AddImage(70, 200, 0x15A9, hue);
|
||||
AddImage(115, 265, 0x15A9, hue);
|
||||
AddImage(160, 200, 0x15A9, hue);
|
||||
AddImage(205, 265, 0x15A9, hue);
|
||||
AddImage(250, 200, 0x15A9, hue);
|
||||
AddImage(295, 265, 0x15A9, 0x21);
|
||||
|
||||
TimeSpan ts = m_PowerBall.NextGame - DateTime.Now;
|
||||
string text;
|
||||
|
||||
if (ts.TotalHours >= 1)
|
||||
{
|
||||
int minutes = (int)ts.TotalMinutes - (((int)ts.TotalHours) * 60);
|
||||
text = String.Format("Next Picks: {0} {1} and {2} {3}", ((int)ts.TotalHours).ToString(), ts.TotalHours == 1 ? "hour" : "hours", minutes.ToString(), ts.TotalMinutes == 1 ? "minute" : "minutes");
|
||||
}
|
||||
else
|
||||
text = String.Format("Next Picks: {0} {1}", ((int)ts.TotalMinutes).ToString(), ts.TotalMinutes == 1 ? "minute" : "minutes");
|
||||
|
||||
AddLabel(70, 40, labelColor, text);
|
||||
}
|
||||
|
||||
AddHtml(105, 65, 200, 16, "<Basefont Color=#FFFFFF>Purchase Ticket</Basefont>", false, false);
|
||||
if (PowerBall.Instance != null && PowerBall.Instance.CanBuyTickets)
|
||||
AddButton(70, 65, 0xFBD, 0xFBF, 1, GumpButtonType.Reply, 0);
|
||||
//else
|
||||
// AddImage(70, 65, 0xFB4);
|
||||
|
||||
AddButton(70, 95, 0xFBD, 0xFBF, 0, GumpButtonType.Page, 2);
|
||||
AddHtml(105, 95, 200, 16, "<Basefont Color=#FFFFFF>Archived Picks</Basefont>", false, false);
|
||||
|
||||
AddButton(70, 125, 0xFBD, 0xFBF, 0, GumpButtonType.Page, 3);
|
||||
AddHtml(105, 125, 200, 16, "<Basefont Color=#FFFFFF>Jackpot Winners</Basefont>", false, false);
|
||||
|
||||
AddHtml(105, 155, 200, 16, "<Basefont Color=#FFFFFF>Current Game Info</Basefont>", false, false);
|
||||
if (m_PowerBall.IsActive)
|
||||
AddButton(70, 155, 0xFBD, 0xFBF, 0, GumpButtonType.Page, 4);
|
||||
//else
|
||||
// AddImage(70, 155, 0xFB4);
|
||||
|
||||
AddPage(2); //Archived Picks
|
||||
|
||||
AddLabel(70, 20, labelColor, "Game");
|
||||
AddLabel(150, 20, labelColor, "Last 10 Picks");
|
||||
AddLabel(275, 20, labelColor, "Total Payout");
|
||||
|
||||
int count = 0;
|
||||
for (int i = PowerBallStats.PicksStats.Count - 1; i >= 0; --i)
|
||||
{
|
||||
PowerBallStats stats = PowerBallStats.PicksStats[i];
|
||||
string payout = String.Format("{0:##,###,###}", stats.Payout);
|
||||
|
||||
AddHtml(70, 50 + (count * 25), 50, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", stats.GameNumber.ToString()), false, false);
|
||||
AddHtml(305, 50 + (count * 25), 50, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", payout), false, false);
|
||||
|
||||
if (stats.Picks != null && stats.Picks.Count > 0)
|
||||
{
|
||||
for (int j = 0; j < stats.Picks.Count; ++j)
|
||||
{
|
||||
if (j + 1 < stats.Picks.Count)
|
||||
AddHtml(125 + (j * 25), 50 + (count * 25), 25, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", stats.Picks[j]), false, false);
|
||||
else
|
||||
AddHtml(250, 50 + (count * 25), 25, 16, String.Format("<Basefont Color=#FF0000>{0}</Basefont>", stats.Picks[j]), false, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (count++ >= 9)
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
AddButton(350, 300, 0xFAE, 0xFB0, 0, GumpButtonType.Page, 1);
|
||||
|
||||
AddPage(3); //Jackpot Winners
|
||||
|
||||
AddLabel(70, 20, labelColor, "Player");
|
||||
AddLabel(150, 20, labelColor, "Jackpot Amount");
|
||||
AddLabel(300, 20, labelColor, "Time");
|
||||
|
||||
count = 0;
|
||||
for (int i = PowerBallStats.JackpotStats.Count - 1; i >= 0; --i)
|
||||
{
|
||||
PowerBallStats stats = PowerBallStats.JackpotStats[i];
|
||||
Mobile mob = stats.JackpotWinner;
|
||||
string jackpotamount = String.Format("{0:##,###,### Gold}", stats.JackpotAmount);
|
||||
|
||||
AddHtml(70, 50 + (count * 25), 100, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", mob != null ? mob.Name : "Unanimous"), false, false);
|
||||
AddHtml(150, 50 + (count * 25), 100, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", jackpotamount), false, false);
|
||||
AddHtml(270, 50 + (count * 25), 100, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", stats.JackpotTime.ToString()), false, false);
|
||||
|
||||
if (count++ >= 9)
|
||||
break;
|
||||
}
|
||||
|
||||
AddButton(350, 300, 0xFAE, 0xFB0, 0, GumpButtonType.Page, 1);
|
||||
|
||||
AddPage(4); //Current Game info
|
||||
|
||||
List<Mobile> ticketList = new List<Mobile>();
|
||||
if (PowerBall.Instance != null)
|
||||
{
|
||||
foreach (PowerBallTicket ticket in PowerBall.Instance.Tickets)
|
||||
{
|
||||
if (!ticketList.Contains(ticket.Owner) && ticket.Owner != null)
|
||||
ticketList.Add(ticket.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
AddLabel(70, 20, labelColor, "Current Game Information");
|
||||
|
||||
if (PowerBall.Instance != null || PowerBall.Instance.PowerBall != null && PowerBall.Instance.PowerBall.IsActive)
|
||||
{
|
||||
AddLabel(70, 80, labelColor, "Game Number:");
|
||||
AddHtml(200, 80, 300, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", gameNumber), false, false);
|
||||
|
||||
string jackpotamount = String.Format("{0:##,###,### Gold}", PowerBall.Instance.JackPot);
|
||||
AddLabel(70, 110, labelColor, "Jackpot Amount:");
|
||||
AddHtml(200, 110, 300, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", PowerBall.Instance.JackPot > 0 ? jackpotamount : "0 Gold"), false, false);
|
||||
|
||||
AddLabel(70, 140, labelColor, "Players:");
|
||||
AddHtml(200, 140, 300, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", ticketList.Count), false, false);
|
||||
|
||||
if (PowerBall.Instance != null)
|
||||
{
|
||||
int entryCount = 0;
|
||||
foreach (PowerBallTicket t in PowerBall.Instance.Tickets)
|
||||
foreach (TicketEntry e in t.Entries)
|
||||
entryCount++;
|
||||
|
||||
AddLabel(70, 170, labelColor, "Tickets:");
|
||||
AddHtml(200, 170, 300, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", entryCount.ToString()), false, false);
|
||||
|
||||
AddLabel(70, 200, labelColor, "Next Picks:");
|
||||
AddHtml(200, 200, 300, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", PowerBall.Instance.PowerBall.NextGame), false, false);
|
||||
}
|
||||
|
||||
if (ticketList != null && ticketList.Count > 0)
|
||||
{
|
||||
AddButton(70, 300, 0x483, 0x481, 0, GumpButtonType.Page, 5);
|
||||
AddHtml(110, 300, 200, 16, "<Basefont Color=#FFFFFF>Players</Basefont>", false, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
AddLabel(70, 80, labelColor, "Inactive");
|
||||
|
||||
AddButton(350, 300, 0xFAE, 0xFB0, 0, GumpButtonType.Page, 1);
|
||||
|
||||
AddPage(5);
|
||||
|
||||
AddLabel(70, 20, labelColor, "Players in Current Game");
|
||||
|
||||
for (int k = 0; k < ticketList.Count; ++k)
|
||||
{
|
||||
if (k < 12)
|
||||
AddHtml(70, 45 + (k * 25), 100, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", ticketList[k] != null ? ticketList[k].Name : "Unanimous"), false, false);
|
||||
else if (k < 24)
|
||||
AddHtml(180, 45 + ((k - 12) * 25), 100, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", ticketList[k] != null ? ticketList[k].Name : "Unanimous"), false, false);
|
||||
else if (k < 36)
|
||||
AddHtml(290, 45 + ((k - 24) * 25), 100, 16, String.Format("<Basefont Color=#FFFFFF>{0}</Basefont>", ticketList[k] != null ? ticketList[k].Name : "Unanimous"), false, false);
|
||||
|
||||
}
|
||||
|
||||
AddButton(290, 20, 0xFB1, 0xFB3, 0, GumpButtonType.Page, 1);
|
||||
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState state, RelayInfo info)
|
||||
{
|
||||
switch (info.ButtonID)
|
||||
{
|
||||
default:
|
||||
case 0: break;
|
||||
case 1:
|
||||
{
|
||||
Container pack = m_From.Backpack;
|
||||
|
||||
if (PowerBall.Instance != null && PowerBall.Game != null && PowerBall.Instance.CanBuyTickets)
|
||||
{
|
||||
int cost = PowerBall.Game.TicketCost;
|
||||
if (pack != null && pack.GetAmount(typeof(Gold)) >= cost)
|
||||
{
|
||||
pack.ConsumeTotal(typeof(Gold), cost);
|
||||
m_From.SendMessage("You purchase a Powerball ticket with {0} gold from your backpack.", cost);
|
||||
pack.DropItem(new PowerBallTicket(m_From, m_PowerBall));
|
||||
|
||||
if (PowerBall.Instance != null)
|
||||
PowerBall.Instance.Profit += cost;
|
||||
}
|
||||
else if (Banker.Withdraw(m_From, cost, true))
|
||||
{
|
||||
var ticket = new PowerBallTicket(m_From, m_PowerBall);
|
||||
|
||||
if (!pack.TryDropItem(m_From, ticket, false))
|
||||
{
|
||||
m_From.SendMessage("There is no room in your pack, so the ticket was placed in your bank box!");
|
||||
m_From.BankBox.DropItem(ticket);
|
||||
}
|
||||
|
||||
if (PowerBall.Instance != null)
|
||||
PowerBall.Instance.Profit += cost;
|
||||
}
|
||||
else
|
||||
m_From.SendLocalizedMessage(500191); //Begging thy pardon, but thy bank account lacks these funds.
|
||||
}
|
||||
|
||||
m_From.SendGump(new PowerBallStatsGump(m_PowerBall, m_From));
|
||||
break;
|
||||
}
|
||||
case 2: //Reset all stats
|
||||
{
|
||||
if (m_From.AccessLevel == AccessLevel.Player)
|
||||
break;
|
||||
|
||||
for (int i = 0; i < PowerBallStats.PicksStats.Count; ++i)
|
||||
{
|
||||
PowerBallStats.PicksStats.Clear();
|
||||
}
|
||||
|
||||
for (int i = 0; i < PowerBallStats.JackpotStats.Count; ++i)
|
||||
{
|
||||
PowerBallStats.JackpotStats.Clear();
|
||||
}
|
||||
|
||||
if (PowerBall.Instance != null)
|
||||
{
|
||||
PowerBall.Game.InvalidateProperties();
|
||||
PowerBall.Game.UpdateSatellites();
|
||||
}
|
||||
|
||||
m_From.SendMessage("Stats erased!");
|
||||
m_From.SendGump(new PowerBallStatsGump(m_PowerBall, m_From));
|
||||
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
if (m_From.AccessLevel == AccessLevel.Player)
|
||||
break;
|
||||
|
||||
if (!m_PowerBall.DoJackpot)
|
||||
{
|
||||
m_PowerBall.DoJackpot = true;
|
||||
m_From.SendGump(new PowerBallStatsGump(m_PowerBall, m_From));
|
||||
m_From.SendMessage("Next picks will result in a jackpot!");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
if (m_From.AccessLevel == AccessLevel.Player)
|
||||
break;
|
||||
|
||||
if (m_PowerBall.IsActive)
|
||||
{
|
||||
m_PowerBall.IsActive = false;
|
||||
m_From.SendMessage("Powerball set to inactive.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_PowerBall.IsActive = true;
|
||||
m_From.SendMessage("Powerball set to active.");
|
||||
}
|
||||
m_From.SendGump(new PowerBallStatsGump(m_PowerBall, m_From));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long GetOdds()
|
||||
{
|
||||
if (PowerBall.Game == null)
|
||||
return 1;
|
||||
|
||||
int white = PowerBall.Game.MaxWhiteBalls;
|
||||
int red = PowerBall.Game.MaxRedBalls;
|
||||
|
||||
long amount1 = GetFact(white);
|
||||
long amount2 = GetFact(5);
|
||||
long amount3 = GetFact(white - 5);
|
||||
|
||||
try
|
||||
{
|
||||
return (amount1 / (amount2 * amount3)) * red;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private long GetFact(int balls)
|
||||
{
|
||||
long value = balls;
|
||||
|
||||
for (int i = balls; i > 1; --i)
|
||||
value *= (i - 1);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
using Server.Network;
|
||||
using Server.Misc;
|
||||
using Server.Engines.LotterySystem;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class PowerballTicketGump : Gump
|
||||
{
|
||||
private const int labelColor = 88;
|
||||
private const int maxEntries = 10;
|
||||
|
||||
private PowerBallTicket m_Ticket;
|
||||
private Mobile m_From;
|
||||
|
||||
public PowerballTicketGump(PowerBallTicket ticket, Mobile from) : this(ticket, from, true)
|
||||
{
|
||||
}
|
||||
|
||||
public PowerballTicketGump(PowerBallTicket ticket, Mobile from, bool powerBall)
|
||||
: base(50, 50)
|
||||
{
|
||||
m_Ticket = ticket;
|
||||
m_From = from;
|
||||
|
||||
if (ticket.Owner == null)
|
||||
ticket.Owner = from;
|
||||
|
||||
int gameNumber = 0;
|
||||
|
||||
if (PowerBall.Game != null)
|
||||
gameNumber = PowerBall.Game.GameNumber;
|
||||
|
||||
int entries = ticket.Entries.Count;
|
||||
int yoffSet = 25;
|
||||
string title = String.Format("<BASEFONT SIZE=8 COLOR=#FF0000><Center>Powerball</Center></BASEFONT>");
|
||||
|
||||
AddBackground(50, 0, 300, 200 + (yoffSet * entries), 9270);
|
||||
AddHtml(65, 170 + (yoffSet * entries), 350, 20, String.Format("<Basefont Size=2>Lotto Association of {0}, All Rights Reserved</Basefont>", ServerList.ServerName), false, false);
|
||||
|
||||
AddHtml(50, 20, 300, 30, title, false, false);
|
||||
AddLabel(65, 50, labelColor, String.Format("Picks: {0}", entries));
|
||||
AddLabel(65, 70, labelColor, String.Format("Game: {0}", m_Ticket.GameNumber));
|
||||
|
||||
if (ticket.GameNumber == gameNumber && entries < maxEntries)
|
||||
{
|
||||
AddHtml(180, 50, 80, 16, "<BASEFONT COLOR=#FFFFFF>Powerball</BASEFONT>", false, false);
|
||||
AddRadio(260, 50, 0x25F8, 0x25FB, powerBall, 0);
|
||||
AddHtml(180, 80, 80, 16, "<BASEFONT COLOR=#FFFFFF>No Powerball</BASEFONT>", false, false);
|
||||
AddRadio(260, 80, 0x25F8, 0x25FB, !powerBall, 1);
|
||||
|
||||
AddLabel(245, 120, labelColor, "Quick Picks");
|
||||
AddButton(321, 123, 0x837, 0x838, 2, GumpButtonType.Reply, 0); //Quick Pick
|
||||
}
|
||||
|
||||
if (entries > 0)
|
||||
{
|
||||
AddLabel(65, 120, labelColor, "Pick");
|
||||
|
||||
for (int i = 0; i < ticket.Entries.Count; ++i)
|
||||
{
|
||||
TicketEntry entry = ticket.Entries[i];
|
||||
int index = i + 1;
|
||||
|
||||
List<int> entryList = new List<int>();
|
||||
entryList.Add(entry.One);
|
||||
entryList.Add(entry.Two);
|
||||
entryList.Add(entry.Three);
|
||||
entryList.Add(entry.Four);
|
||||
entryList.Add(entry.Five);
|
||||
|
||||
AddLabel(75, 150 + (i * yoffSet), labelColor, String.Format("{0}", index.ToString()));
|
||||
AddHtml(270, 150 + (i * yoffSet), 50, 16, String.Format("<BASEFONT COLOR=#FF0000>{0}</BASEFONT>", entry.PowerBall > 0 ? entry.PowerBall.ToString() : "<B>-</B>"), false, false);
|
||||
AddHtml(310, 150 + (i * yoffSet), 50, 16, entry.Winner ? "<BASEFONT COLOR=#FFFFFF><b>*</b></BASEFONT>" : "", false, false);
|
||||
|
||||
for (int j = entryList.Count - 1; j >= 0; --j)
|
||||
{
|
||||
AddHtml(105 + (j * 30), 150 + (i * yoffSet), 50, 16, String.Format("<BASEFONT COLOR=#FFFFFF>{0}</BASEFONT>", entryList[j]), false, false);
|
||||
}
|
||||
|
||||
ColUtility.Free(entryList);
|
||||
}
|
||||
}
|
||||
|
||||
if (entries < maxEntries && ticket.GameNumber == gameNumber)
|
||||
{
|
||||
int yStart = 130 + (yoffSet * (entries));
|
||||
|
||||
AddButton(75, yStart + (yoffSet + 2), 0x837, 0x838, 1, GumpButtonType.Reply, 0);
|
||||
|
||||
AddTextEntry(100, yStart + yoffSet, 20, 16, labelColor, 1, "*");
|
||||
AddTextEntry(130, yStart + yoffSet, 20, 16, labelColor, 2, "*");
|
||||
AddTextEntry(160, yStart + yoffSet, 20, 16, labelColor, 3, "*");
|
||||
AddTextEntry(190, yStart + yoffSet, 20, 16, labelColor, 4, "*");
|
||||
AddTextEntry(220, yStart + yoffSet, 20, 16, labelColor, 5, "*");
|
||||
AddTextEntry(250, yStart + yoffSet, 20, 16, labelColor, 6, "*");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState state, RelayInfo info)
|
||||
{
|
||||
bool powerball = info.IsSwitched(0);
|
||||
|
||||
if (PowerBall.Game == null || m_Ticket.GameNumber != PowerBall.Game.GameNumber)
|
||||
return;
|
||||
|
||||
int white = PowerBall.Game.MaxWhiteBalls;
|
||||
int red = PowerBall.Game.MaxRedBalls;
|
||||
|
||||
switch (info.ButtonID)
|
||||
{
|
||||
default:
|
||||
case 0: m_From.CloseGump(typeof(PowerballTicketGump)); break;
|
||||
case 1:
|
||||
{
|
||||
int pick1 = 0; int pick2 = 0; int pick3 = 0;
|
||||
int pick4 = 0; int pick5 = 0; int pick6 = 0;
|
||||
|
||||
TextRelay s1 = info.GetTextEntry(1);
|
||||
TextRelay s2 = info.GetTextEntry(2);
|
||||
TextRelay s3 = info.GetTextEntry(3);
|
||||
TextRelay s4 = info.GetTextEntry(4);
|
||||
TextRelay s5 = info.GetTextEntry(5);
|
||||
TextRelay s6 = info.GetTextEntry(6);
|
||||
|
||||
try
|
||||
{
|
||||
pick1 = Convert.ToInt32(s1.Text);
|
||||
pick2 = Convert.ToInt32(s2.Text);
|
||||
pick3 = Convert.ToInt32(s3.Text);
|
||||
pick4 = Convert.ToInt32(s4.Text);
|
||||
pick5 = Convert.ToInt32(s5.Text);
|
||||
pick6 = Convert.ToInt32(s6.Text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if (PowerBall.Instance != null && PowerBall.Game != null)
|
||||
{
|
||||
|
||||
if (pick1 < 1 || pick2 < 1 || pick3 < 1 || pick4 < 1 || pick5 < 1)
|
||||
m_From.SendMessage(String.Format("You must choose a number from 1 to {0} on a non-powerball pick.", white.ToString()));
|
||||
else if (pick1 == pick2 || pick1 == pick3 || pick1 == pick4 || pick1 == pick5 || pick2 == pick3 || pick2 == pick4 || pick2 == pick5 || pick3 == pick4 || pick3 == pick5 || pick4 == pick5)
|
||||
m_From.SendMessage("You should think twice before picking the same number twice.");
|
||||
else if (pick1 > white || pick2 > white || pick3 > white || pick4 > white || pick5 > white)
|
||||
m_From.SendMessage(String.Format("White numbers cannot be any higher than {0}.", white.ToString()));
|
||||
else if (pick6 > red)
|
||||
m_From.SendMessage(String.Format("Red numbers cannot be any higher than {0}.", red.ToString()));
|
||||
else if (powerball)
|
||||
{
|
||||
if (pick6 < 1)
|
||||
m_From.SendMessage(String.Format("You must choose a number from 1 to {0} on your powerball pick.", red.ToString()));
|
||||
else
|
||||
{
|
||||
Container pack = m_From.Backpack;
|
||||
int price = PowerBall.Game.TicketEntryPrice + PowerBall.Game.PowerBallPrice;
|
||||
|
||||
if (pack != null && pack.GetAmount(typeof(Gold)) >= price)
|
||||
{
|
||||
pack.ConsumeTotal(typeof(Gold), price);
|
||||
m_From.SendMessage("You purchase a powerball ticket with {0} gold from your backpack.", price);
|
||||
new TicketEntry(m_Ticket, pick1, pick2, pick3, pick4, pick5, pick6, false);
|
||||
PowerBall.Instance.Profit += price;
|
||||
}
|
||||
else if (Banker.Withdraw(m_From, price, true))
|
||||
{
|
||||
new TicketEntry(m_Ticket, pick1, pick2, pick3, pick4, pick5, pick6, false);
|
||||
|
||||
PowerBall.Instance.Profit += price;
|
||||
}
|
||||
else
|
||||
m_From.SendLocalizedMessage(500191); //Begging thy pardon, but thy bank account lacks these funds.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Container pack = m_From.Backpack;
|
||||
int price = PowerBall.Game.TicketEntryPrice;
|
||||
|
||||
if (pack != null && pack.GetAmount(typeof(Gold)) >= price)
|
||||
{
|
||||
pack.ConsumeTotal(typeof(Gold), price);
|
||||
m_From.SendMessage("You purchase a powerball ticket with {0} gold from your backpack.", price);
|
||||
new TicketEntry(m_Ticket, pick1, pick2, pick3, pick4, pick5, false);
|
||||
PowerBall.Instance.Profit += price;
|
||||
}
|
||||
else if (Banker.Withdraw(m_From, price, true))
|
||||
{
|
||||
new TicketEntry(m_Ticket, pick1, pick2, pick3, pick4, pick5, false);
|
||||
|
||||
PowerBall.Instance.Profit += price;
|
||||
}
|
||||
else
|
||||
m_From.SendLocalizedMessage(500191); //Begging thy pardon, but thy bank account lacks these funds.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_From.SendGump(new PowerballTicketGump(m_Ticket, m_From, powerball));
|
||||
break;
|
||||
}
|
||||
case 2: //Quickpick
|
||||
{
|
||||
Container pack = m_From.Backpack;
|
||||
int price;
|
||||
|
||||
if (powerball)
|
||||
price = PowerBall.Game.TicketEntryPrice + PowerBall.Game.PowerBallPrice;
|
||||
else
|
||||
price = PowerBall.Game.TicketEntryPrice;
|
||||
|
||||
if (pack != null && pack.GetAmount(typeof(Gold)) >= price)
|
||||
{
|
||||
m_From.SendMessage("You purchase a powerball ticket with {0} gold from your backpack.", price);
|
||||
pack.ConsumeTotal(typeof(Gold), price);
|
||||
}
|
||||
else if (!Banker.Withdraw(m_From, price, true))
|
||||
{
|
||||
m_From.SendLocalizedMessage(1060398, price.ToString()); //~1_AMOUNT~ gold has been withdrawn from your bank box.
|
||||
|
||||
m_From.SendLocalizedMessage(500191); //Begging thy pardon, but thy bank account lacks these funds.
|
||||
m_From.SendGump(new PowerballTicketGump(m_Ticket, m_From, powerball));
|
||||
break;
|
||||
}
|
||||
|
||||
int pick1 = 0; int pick2 = 0; int pick3 = 0;
|
||||
int pick4 = 0; int pick5 = 0; int pick6 = 0;
|
||||
|
||||
List<int> whiteList = new List<int>();
|
||||
|
||||
for (int i = 1; i < white + 1; ++i)
|
||||
whiteList.Add(i);
|
||||
|
||||
int count = 0;
|
||||
while (++count < 6)
|
||||
{
|
||||
int ran = Utility.Random(whiteList.Count);
|
||||
|
||||
if (count == 1)
|
||||
pick1 = whiteList[ran];
|
||||
else if (count == 2)
|
||||
pick2 = whiteList[ran];
|
||||
else if (count == 3)
|
||||
pick3 = whiteList[ran];
|
||||
else if (count == 4)
|
||||
pick4 = whiteList[ran];
|
||||
else
|
||||
pick5 = whiteList[ran];
|
||||
|
||||
whiteList.Remove(whiteList[ran]);
|
||||
|
||||
pick6 = Utility.RandomMinMax(1, red);
|
||||
}
|
||||
|
||||
if (powerball)
|
||||
{
|
||||
new TicketEntry(m_Ticket, pick1, pick2, pick3, pick4, pick5, pick6, false);
|
||||
PowerBall.Instance.Profit += price;
|
||||
}
|
||||
else
|
||||
{
|
||||
new TicketEntry(m_Ticket, pick1, pick2, pick3, pick4, pick5, false);
|
||||
PowerBall.Instance.Profit += price;
|
||||
}
|
||||
m_From.SendGump(new PowerballTicketGump(m_Ticket, m_From, powerball));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
458
Scripts/SubSystem/LotterySystem/PowerBall/PowerBall.cs
Normal file
458
Scripts/SubSystem/LotterySystem/PowerBall/PowerBall.cs
Normal file
@@ -0,0 +1,458 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Targeting;
|
||||
using Server.Gumps;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Engines.LotterySystem
|
||||
{
|
||||
public class PowerBall : Item
|
||||
{
|
||||
public static PowerBall PowerBallInstance { get; set; }
|
||||
|
||||
#region Getters/Setters
|
||||
|
||||
private int m_TimeOfDay; //Time Powerball numbers are Picked in military time
|
||||
private int m_TicketCost; //Price per empty ticket
|
||||
private int m_TicketEntryPrice; //Price per entry, ie picks - 10 Max per ticket
|
||||
private int m_PowerBallPrice; //Price per powerball pick
|
||||
private int m_MaxWhiteBalls; //Determines amount of white balls rolled per game
|
||||
private int m_MaxRedBalls; //Determines amount of Powerballs rolled per game
|
||||
private bool m_GuaranteedJackpot; //Chance to pick a jackpot - minimum 5 games without a winner, chances increasing each jackpotless game
|
||||
private int m_GameNumber; //Current Game Number
|
||||
private bool m_HasProcessed; //Has current game been processed?
|
||||
|
||||
private TimeSpan m_GameDelay; //Time inbetween Picks
|
||||
private TimeSpan m_DeadLine; //Deadline before Picks you can purchase a ticket
|
||||
|
||||
private static List<PowerBallSatellite> m_SatList = new List<PowerBallSatellite>();
|
||||
public static List<PowerBallSatellite> SatList { get { return m_SatList; } }
|
||||
|
||||
private static PowerBallGame m_Instance; //Convenience accessor for current game instance
|
||||
private static int m_GoldSink; //Profit - Payouts = Total goldsink
|
||||
private static PowerBall m_Game; //Easily Accessed instance of the powerball item
|
||||
private static bool m_Announcement;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int TimeOfDay { get { return m_TimeOfDay; } set { m_TimeOfDay = value; m_NextGame = GetNextGameTime(); } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int TicketCost { get { return m_TicketCost; } set { m_TicketCost = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int TicketEntryPrice { get { return m_TicketEntryPrice; } set { m_TicketEntryPrice = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int PowerBallPrice { get { return m_PowerBallPrice; } set { m_PowerBallPrice = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int MaxWhiteBalls
|
||||
{
|
||||
get { return m_MaxWhiteBalls; }
|
||||
set { m_MaxWhiteBalls = value; }
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int MaxRedBalls
|
||||
{
|
||||
get { return m_MaxRedBalls; }
|
||||
set { m_MaxRedBalls = value; }
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool GuaranteedJackpot { get { return m_GuaranteedJackpot; } set { m_GuaranteedJackpot = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public TimeSpan GameDelay { get { return m_GameDelay; } set { m_GameDelay = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public TimeSpan DeadLine { get { return m_DeadLine; } set { m_DeadLine = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int NoWins { get { if (m_Instance != null) return m_Instance.NoWins; return 0; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int GameNumber { get { return m_GameNumber; } set { m_GameNumber = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool HasProcessed { get { return m_HasProcessed; } set { m_HasProcessed = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public static bool Announcement { get { return m_Announcement; } set { m_Announcement = value; } }
|
||||
|
||||
public static PowerBallGame Instance { get { return m_Instance; } set { m_Instance = value; } }
|
||||
//These 2 are backwards, but oh well!
|
||||
public static PowerBall Game { get { return m_Game; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public static int GoldSink { get { return m_GoldSink; } set { m_GoldSink = value; } }
|
||||
|
||||
private DateTime m_NextGame;
|
||||
private bool m_Active;
|
||||
private bool m_DoJackpot;
|
||||
private Timer m_Timer;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime LastGame { get { return m_NextGame - GameDelay; } }
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime NextGame { get { return m_NextGame; } set { m_NextGame = value; } }
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool DoJackpot { get { return m_DoJackpot; } set { m_DoJackpot = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool IsActive
|
||||
{
|
||||
get { return m_Active; }
|
||||
set
|
||||
{
|
||||
m_Active = value;
|
||||
|
||||
if (m_Active)
|
||||
{
|
||||
if (m_Instance == null)
|
||||
m_Instance = new PowerBallGame(this);
|
||||
|
||||
if (m_Timer != null)
|
||||
{
|
||||
m_Timer.Stop();
|
||||
m_Timer = null;
|
||||
}
|
||||
|
||||
m_NextGame = GetNextGameTime();
|
||||
m_Timer = new PowerBallTimer(this);
|
||||
m_Timer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Timer != null)
|
||||
{
|
||||
m_Timer.Stop();
|
||||
m_Timer = null;
|
||||
}
|
||||
}
|
||||
UpdateSatellites();
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Constructable]
|
||||
public PowerBall()
|
||||
: base(0xED4)
|
||||
{
|
||||
if (PowerBallInstance != null)
|
||||
{
|
||||
Console.WriteLine("You can only have one shard PowerBall Item.");
|
||||
Delete();
|
||||
return;
|
||||
}
|
||||
|
||||
Hue = 592;
|
||||
Name = "Let's Play Powerball!";
|
||||
m_Game = this;
|
||||
m_Instance = new PowerBallGame(this);
|
||||
m_Timer = new PowerBallTimer(this);
|
||||
m_Timer.Start();
|
||||
m_Active = true;
|
||||
Movable = false;
|
||||
m_HasProcessed = false;
|
||||
|
||||
/*Modify below for custom values. See readme file for info*/
|
||||
|
||||
m_TicketCost = 100;
|
||||
m_TicketEntryPrice = 1000;
|
||||
m_PowerBallPrice = 500;
|
||||
m_MaxWhiteBalls = 20;
|
||||
m_MaxRedBalls = 8;
|
||||
m_GuaranteedJackpot = true;
|
||||
m_Announcement = true;
|
||||
m_GameNumber = 1;
|
||||
|
||||
m_GameDelay = TimeSpan.FromHours(24);
|
||||
m_DeadLine = TimeSpan.FromMinutes(30);
|
||||
|
||||
m_TimeOfDay = 18;
|
||||
m_NextGame = GetNextGameTime();
|
||||
|
||||
PowerBallInstance = this;
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if (!m_Active && from.AccessLevel == AccessLevel.Player)
|
||||
from.SendMessage("Powerball is currenlty inactive at this time.");
|
||||
else if (from.InRange(Location, 3))
|
||||
{
|
||||
if (from.HasGump(typeof(PowerBallStatsGump)))
|
||||
from.CloseGump(typeof(PowerBallStatsGump));
|
||||
|
||||
from.SendGump(new PowerBallStatsGump(this, from));
|
||||
}
|
||||
else if (from.AccessLevel > AccessLevel.Player)
|
||||
from.SendGump(new PropertiesGump(from, this));
|
||||
else
|
||||
from.SendLocalizedMessage(500446); // That is too far away.
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
if (!m_Active)
|
||||
list.Add(1060658, "Status\tOffline");
|
||||
else
|
||||
list.Add(1060658, "Status\tActive");
|
||||
|
||||
if (PowerBallStats.JackpotStats.Count > 0)
|
||||
{
|
||||
int index = PowerBallStats.JackpotStats.Count - 1; //Most Recent Jackpot!
|
||||
|
||||
string name = PowerBallStats.JackpotStats[index].JackpotWinner != null ? PowerBallStats.JackpotStats[index].JackpotWinner.Name : "unknown";
|
||||
list.Add(1060659, "Last Jackpot\t{0}", name);
|
||||
list.Add(1060660, "Date\t{0}", PowerBallStats.JackpotStats[index].JackpotTime);
|
||||
list.Add(1060661, "Amount\t{0}", PowerBallStats.JackpotStats[index].JackpotAmount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DateTime GetNextGameTime()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime nDT;
|
||||
|
||||
if (now.Hour >= m_TimeOfDay && now.Second >= 0)
|
||||
{
|
||||
DateTime check = new DateTime(now.Year, now.Month, now.Day, m_TimeOfDay, 1, 0) + m_GameDelay;
|
||||
if (check < now)
|
||||
nDT = now + m_GameDelay;
|
||||
else
|
||||
nDT = check;
|
||||
}
|
||||
else
|
||||
nDT = new DateTime(now.Year, now.Month, now.Day, m_TimeOfDay, 0, 0);
|
||||
|
||||
return nDT;
|
||||
}
|
||||
|
||||
public void UpdateSatellites()
|
||||
{
|
||||
foreach (PowerBallSatellite sat in m_SatList)
|
||||
{
|
||||
if (sat != null && !sat.Deleted)
|
||||
sat.InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
if (m_Timer != null)
|
||||
m_Timer.Stop();
|
||||
|
||||
for (int i = 0; i < m_SatList.Count; ++i)
|
||||
{
|
||||
if (m_SatList[i] != null && !m_SatList[i].Deleted)
|
||||
m_SatList[i].Delete();
|
||||
}
|
||||
|
||||
base.OnAfterDelete();
|
||||
}
|
||||
|
||||
public PowerBall(Serial serial)
|
||||
: base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write((int)1); //Version
|
||||
|
||||
writer.Write(m_TimeOfDay);
|
||||
writer.Write(m_TicketCost);
|
||||
writer.Write(m_TicketEntryPrice);
|
||||
writer.Write(m_PowerBallPrice);
|
||||
writer.Write(m_MaxWhiteBalls);
|
||||
writer.Write(m_MaxRedBalls);
|
||||
writer.Write(m_GuaranteedJackpot);
|
||||
writer.Write(m_GoldSink);
|
||||
writer.Write(m_NextGame);
|
||||
writer.Write(m_Active);
|
||||
writer.Write(m_GameNumber);
|
||||
writer.Write(m_GameDelay);
|
||||
writer.Write(m_DeadLine);
|
||||
writer.Write(m_Announcement);
|
||||
//writer.Write(m_HasProcessed);
|
||||
|
||||
if (m_Instance == null)
|
||||
m_Instance = new PowerBallGame(this);
|
||||
|
||||
writer.Write(m_Instance.Profit);
|
||||
writer.Write(m_Instance.NoWins);
|
||||
|
||||
writer.Write(PowerBallStats.JackpotStats.Count);
|
||||
for (int i = 0; i < PowerBallStats.JackpotStats.Count; ++i)
|
||||
{
|
||||
PowerBallStats.JackpotStats[i].Serialize(writer);
|
||||
}
|
||||
writer.Write(PowerBallStats.PicksStats.Count);
|
||||
for (int i = 0; i < PowerBallStats.PicksStats.Count; ++i)
|
||||
{
|
||||
PowerBallStats.PicksStats[i].Serialize(writer);
|
||||
}
|
||||
|
||||
InvalidateProperties();
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
m_Game = this;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
m_TimeOfDay = reader.ReadInt();
|
||||
m_TicketCost = reader.ReadInt();
|
||||
m_TicketEntryPrice = reader.ReadInt();
|
||||
m_PowerBallPrice = reader.ReadInt();
|
||||
m_MaxWhiteBalls = reader.ReadInt();
|
||||
m_MaxRedBalls = reader.ReadInt();
|
||||
m_GuaranteedJackpot = reader.ReadBool();
|
||||
m_GoldSink = reader.ReadInt();
|
||||
m_NextGame = reader.ReadDateTime();
|
||||
m_Active = reader.ReadBool();
|
||||
m_GameNumber = reader.ReadInt();
|
||||
m_GameDelay = reader.ReadTimeSpan();
|
||||
m_DeadLine = reader.ReadTimeSpan();
|
||||
m_Announcement = reader.ReadBool();
|
||||
|
||||
if (version == 0)
|
||||
m_HasProcessed = reader.ReadBool();
|
||||
else
|
||||
m_HasProcessed = false;
|
||||
|
||||
if (m_Active)
|
||||
{
|
||||
m_Timer = new PowerBallTimer(this);
|
||||
m_Timer.Start();
|
||||
}
|
||||
|
||||
if (m_Instance == null)
|
||||
m_Instance = new PowerBallGame(this);
|
||||
|
||||
m_Instance.Profit = reader.ReadInt();
|
||||
m_Instance.NoWins = reader.ReadInt();
|
||||
|
||||
int jackpotCount = reader.ReadInt();
|
||||
for (int i = 0; i < jackpotCount; i++)
|
||||
{
|
||||
new PowerBallStats(reader);
|
||||
}
|
||||
int picksCount = reader.ReadInt();
|
||||
for (int i = 0; i < picksCount; i++)
|
||||
{
|
||||
new PowerBallStats(reader);
|
||||
}
|
||||
|
||||
PowerBallInstance = this;
|
||||
}
|
||||
|
||||
public static void AddToArchive(List<int> numbers, int payOut)
|
||||
{
|
||||
if (numbers == null || PowerBall.Game == null)
|
||||
return;
|
||||
|
||||
new PowerBallStats(numbers, PowerBall.Game.GameNumber, payOut);
|
||||
}
|
||||
|
||||
public static void AddToArchive(Mobile mob, int amount) //Jackpot entry
|
||||
{
|
||||
if (mob == null || PowerBall.Game == null)
|
||||
return;
|
||||
|
||||
new PowerBallStats(mob, amount, PowerBall.Game.GameNumber);
|
||||
PowerBall.Game.UpdateSatellites();
|
||||
}
|
||||
|
||||
public void AddToSatList(PowerBallSatellite satellite)
|
||||
{
|
||||
if (m_SatList != null && !m_SatList.Contains(satellite))
|
||||
m_SatList.Add(satellite);
|
||||
}
|
||||
|
||||
public void RemoveFromSatList(PowerBallSatellite satellite)
|
||||
{
|
||||
if (m_SatList != null && m_SatList.Contains(satellite))
|
||||
m_SatList.Remove(satellite);
|
||||
}
|
||||
|
||||
public void NewGame(bool hasjackpot)
|
||||
{
|
||||
if (hasjackpot || m_Instance == null)
|
||||
m_Instance = new PowerBallGame(this);
|
||||
else
|
||||
{
|
||||
int noWins = m_Instance.NoWins;
|
||||
int profit = m_Instance.Profit;
|
||||
|
||||
m_Instance = new PowerBallGame(this, noWins, profit); //No jackpot? Sure! carry over how many non-wins and total profit
|
||||
}
|
||||
|
||||
if (m_DoJackpot)
|
||||
m_DoJackpot = false;
|
||||
|
||||
m_GameNumber++;
|
||||
m_NextGame = GetNextGameTime();
|
||||
m_HasProcessed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public class PowerBallTimer : Timer
|
||||
{
|
||||
|
||||
private PowerBall m_PowerBall;
|
||||
|
||||
public PowerBallTimer(PowerBall pb) : base (TimeSpan.Zero, TimeSpan.FromSeconds(5))
|
||||
{
|
||||
m_PowerBall = pb;
|
||||
Priority = TimerPriority.FiveSeconds;
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (PowerBall.Instance == null || PowerBall.Game == null || m_PowerBall == null)
|
||||
{
|
||||
Stop();
|
||||
Console.WriteLine("There is a null error with Powerball.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_PowerBall.NextGame < DateTime.Now && !m_PowerBall.HasProcessed)
|
||||
{
|
||||
m_PowerBall.HasProcessed = true;
|
||||
PowerBall.Instance.ProcessGame();
|
||||
}
|
||||
else if (m_PowerBall.NextGame != DateTime.MinValue && m_PowerBall.NextGame + TimeSpan.FromSeconds(30) < DateTime.Now)
|
||||
{
|
||||
int dur = 1000;
|
||||
|
||||
foreach (PowerBallSatellite sat in PowerBall.SatList)
|
||||
{
|
||||
if (sat != null && !sat.Deleted)
|
||||
{
|
||||
Effects.SendLocationEffect(new Point3D(sat.X, sat.Y + 1, sat.Z + 3), sat.Map, 0x373A, dur, 0, 0);
|
||||
Effects.SendLocationEffect(new Point3D(sat.X + 1, sat.Y, sat.Z + 3), sat.Map, 0x373A, dur, 0, 0);
|
||||
Effects.SendLocationEffect(new Point3D(sat.X, sat.Y, sat.Z + 2), sat.Map, 0x373A, dur, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Effects.SendLocationEffect(new Point3D(m_PowerBall.X, m_PowerBall.Y + 1, m_PowerBall.Z), m_PowerBall.Map, 0x373A, dur, 0, 0);
|
||||
Effects.SendLocationEffect(new Point3D(m_PowerBall.X + 1, m_PowerBall.Y, m_PowerBall.Z), m_PowerBall.Map, 0x373A, dur, 0, 0);
|
||||
Effects.SendLocationEffect(new Point3D(m_PowerBall.X, m_PowerBall.Y, m_PowerBall.Z - 1), m_PowerBall.Map, 0x373A, dur, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
469
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallGame.cs
Normal file
469
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallGame.cs
Normal file
@@ -0,0 +1,469 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Network;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/* To give a reward for a jackpot, you can add it to GiveReward(Mobile m) method.
|
||||
* RewardChance is the chance that reward is given, on Jackpot. This reward, which
|
||||
* is NOT given by default, would be in addition to the normal jackpot.*/
|
||||
|
||||
namespace Server.Engines.LotterySystem
|
||||
{
|
||||
public class PowerBallGame
|
||||
{
|
||||
public static double RewardChance = 0.5;
|
||||
|
||||
private int m_Profit; //Total ticket/entry costs per string of games - resets to zero once a jackpot is won
|
||||
private int m_NoWins; //Increases each game there is not jackpot
|
||||
private int m_Payout; //Total payout on any winning tickets
|
||||
private bool m_Jackpot; //Did this game yeild a jackpot?
|
||||
private PowerBall m_PowerBall; //Instanced Powerball Item
|
||||
private List<PowerBallTicket> m_Tickets = new List<PowerBallTicket>(); //Tickets for current game
|
||||
private List<int> m_Picks; //Picked at the end of the game
|
||||
private int m_JackpotWinners; //Used for jackpot message
|
||||
|
||||
public int Profit { get { return m_Profit; } set { m_Profit = value; } }
|
||||
public int Payout { get { return m_Payout; } }
|
||||
public int JackPot { get { return m_Profit / 2; } }
|
||||
public int NoWins { get { return m_NoWins; } set { m_NoWins = value; } }
|
||||
public bool HasJackpot { get { return m_Jackpot; } }
|
||||
public PowerBall PowerBall { get { return m_PowerBall; } }
|
||||
public List<PowerBallTicket> Tickets { get { return m_Tickets; } }
|
||||
public List<int> Picks { get { return m_Picks; } }
|
||||
public bool CanBuyTickets { get { return m_PowerBall.NextGame - m_PowerBall.DeadLine > DateTime.Now && m_PowerBall.IsActive; } }
|
||||
public int JackpotWinners { get { return m_JackpotWinners; } }
|
||||
|
||||
public PowerBallGame(PowerBall item, int noWins, int profit)
|
||||
{
|
||||
m_PowerBall = item;
|
||||
|
||||
m_NoWins = noWins;
|
||||
m_Profit = profit;
|
||||
}
|
||||
|
||||
public PowerBallGame(PowerBall item)
|
||||
{
|
||||
m_PowerBall = item;
|
||||
|
||||
m_NoWins = 0;
|
||||
m_Profit = 0;
|
||||
}
|
||||
|
||||
public void ProcessGame()
|
||||
{
|
||||
m_Payout = 0;
|
||||
m_JackpotWinners = 0;
|
||||
|
||||
if (m_PowerBall == null)
|
||||
return;;
|
||||
|
||||
if (m_PowerBall.DoJackpot)
|
||||
m_Picks = ChooseJackpotPicks();
|
||||
|
||||
if (m_Picks == null)
|
||||
{
|
||||
m_Picks = new List<int>();
|
||||
|
||||
List<int> whiteList = new List<int>();
|
||||
int whiteCount = m_PowerBall.MaxWhiteBalls;
|
||||
|
||||
for (int i = 1; i < whiteCount + 1; ++i)
|
||||
whiteList.Add(i);
|
||||
|
||||
int count = 0;
|
||||
int pick = 0;
|
||||
int powerBall;
|
||||
|
||||
while (++count < 6)
|
||||
{
|
||||
pick = whiteList[Utility.Random(whiteList.Count)];
|
||||
m_Picks.Add(pick);
|
||||
whiteList.Remove(pick);
|
||||
}
|
||||
|
||||
powerBall = Utility.RandomMinMax(1, m_PowerBall.MaxRedBalls);
|
||||
m_Picks.Add(powerBall);
|
||||
}
|
||||
|
||||
if (m_PowerBall.GuaranteedJackpot && m_NoWins > 5 && Utility.Random(20) < m_NoWins)
|
||||
{
|
||||
List<int> list = ChooseJackpotPicks();
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
m_Picks.Clear();
|
||||
m_Picks = list;
|
||||
}
|
||||
}
|
||||
|
||||
new InternalTimer(this);
|
||||
}
|
||||
|
||||
public void CheckForWinners()
|
||||
{
|
||||
|
||||
if (m_Picks == null || m_Tickets == null || m_Tickets.Count == 0)
|
||||
return;
|
||||
|
||||
List<TicketEntry> jackpotList = new List<TicketEntry>();
|
||||
Dictionary<TicketEntry, int> prizeTable = new Dictionary<TicketEntry, int>();
|
||||
|
||||
for(int i = 0; i < m_Tickets.Count; ++i)
|
||||
{
|
||||
PowerBallTicket ticket = m_Tickets[i];
|
||||
ticket.Checked = true;
|
||||
|
||||
foreach (TicketEntry entry in ticket.Entries)
|
||||
{
|
||||
int matches = 0;
|
||||
bool powerball = false;
|
||||
|
||||
for (int j = 0; j < m_Picks.Count; ++j)
|
||||
{
|
||||
if (j == m_Picks.Count - 1)
|
||||
{
|
||||
if (entry.PowerBall == m_Picks[j])
|
||||
powerball = true;
|
||||
}
|
||||
|
||||
else if (entry.One == m_Picks[j] || entry.Two == m_Picks[j] || entry.Three == m_Picks[j] || entry.Four == m_Picks[j] || entry.Five == m_Picks[j])
|
||||
matches++;
|
||||
}
|
||||
|
||||
if (matches == 5 && powerball)
|
||||
{
|
||||
jackpotList.Add(entry);
|
||||
entry.Winner = true;
|
||||
m_Jackpot = true;
|
||||
}
|
||||
|
||||
if (matches >= 3 && !entry.Winner && !prizeTable.ContainsKey(entry))
|
||||
{
|
||||
prizeTable.Add(entry, matches);
|
||||
entry.Winner = true;
|
||||
}
|
||||
|
||||
if (powerball && !m_Jackpot)
|
||||
{
|
||||
entry.Ticket.Payout += 500;
|
||||
m_Profit -= 500;
|
||||
m_Payout += 500;
|
||||
|
||||
entry.Winner = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DistributeAwards(jackpotList, prizeTable);
|
||||
}
|
||||
|
||||
private void DistributeAwards(List<TicketEntry> jackpot, Dictionary<TicketEntry, int> prize)
|
||||
{
|
||||
|
||||
int pot = m_Profit;
|
||||
|
||||
if (jackpot != null && jackpot.Count > 0)
|
||||
{
|
||||
foreach (TicketEntry entry in jackpot)
|
||||
{
|
||||
if (entry.Ticket != null && entry.Ticket.Owner != null)
|
||||
{
|
||||
int amount = JackPot / jackpot.Count;
|
||||
|
||||
m_Jackpot = true;
|
||||
entry.Ticket.Payout += amount;
|
||||
m_Payout += amount;
|
||||
m_Profit -= amount;
|
||||
PowerBall.AddToArchive(entry.Ticket.Owner, amount);
|
||||
m_JackpotWinners++;
|
||||
m_PowerBall.InvalidateProperties();
|
||||
|
||||
if (RewardChance > Utility.RandomDouble())
|
||||
{
|
||||
GiveReward(entry.Ticket.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prize != null && prize.Count > 0)
|
||||
{
|
||||
int award = 0;
|
||||
int match3 = 0;
|
||||
int match4 = 0;
|
||||
int match5 = 0;
|
||||
|
||||
|
||||
foreach (KeyValuePair<TicketEntry, int> kvp in prize)
|
||||
{
|
||||
if (kvp.Value == 3)
|
||||
match3++;
|
||||
else if (kvp.Value == 4)
|
||||
match4++;
|
||||
else
|
||||
match5++;
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<TicketEntry, int> kvp in prize)
|
||||
{
|
||||
TicketEntry entry = kvp.Key;
|
||||
int matches = kvp.Value;
|
||||
|
||||
if (matches == 3)
|
||||
award = (pot / 50) / match3; //2% of Pot
|
||||
else if (matches == 4)
|
||||
award = (pot / 20) / match4; //5% of Pot
|
||||
else
|
||||
award = (pot / 10) / match5; //10% of Pot
|
||||
|
||||
entry.Ticket.Payout += award;
|
||||
m_Payout += award;
|
||||
m_Profit -= award;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GiveReward(Mobile m)
|
||||
{
|
||||
}
|
||||
|
||||
private List<int> ChooseJackpotPicks()
|
||||
{
|
||||
if (m_Tickets == null || m_Tickets.Count == 0)
|
||||
return null;
|
||||
|
||||
List<TicketEntry> entryList = new List<TicketEntry>();
|
||||
|
||||
foreach (PowerBallTicket ticket in m_Tickets)
|
||||
{
|
||||
if (ticket.Entries.Count > 0 && ticket.Owner != null)
|
||||
{
|
||||
foreach (TicketEntry entry in ticket.Entries)
|
||||
{
|
||||
if (entry.PowerBall > 0)
|
||||
entryList.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int random = Utility.Random(entryList.Count);
|
||||
for (int j = 0; j < entryList.Count; ++j)
|
||||
{
|
||||
if (j == random)
|
||||
{
|
||||
TicketEntry entry = entryList[j];
|
||||
List<int> list = new List<int>();
|
||||
|
||||
list.Add(entry.One);
|
||||
list.Add(entry.Two);
|
||||
list.Add(entry.Three);
|
||||
list.Add(entry.Four);
|
||||
list.Add(entry.Five);
|
||||
list.Add(entry.PowerBall);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddTicket(PowerBallTicket ticket)
|
||||
{
|
||||
if (!m_Tickets.Contains(ticket))
|
||||
m_Tickets.Add(ticket);
|
||||
}
|
||||
|
||||
public void RemoveTicket(PowerBallTicket ticket)
|
||||
{
|
||||
if (m_Tickets.Contains(ticket))
|
||||
m_Tickets.Remove(ticket);
|
||||
}
|
||||
|
||||
public class InternalTimer : Timer
|
||||
{
|
||||
private PowerBallGame m_Game;
|
||||
private int m_Ticks;
|
||||
private DateTime m_Start;
|
||||
|
||||
public InternalTimer(PowerBallGame game) : base (TimeSpan.Zero, TimeSpan.FromSeconds(1.0))
|
||||
{
|
||||
m_Game = game;
|
||||
m_Ticks = 0;
|
||||
m_Start = DateTime.Now;
|
||||
Start();
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (m_Game == null || m_Game.PowerBall == null || m_Game.Picks == null || m_Game.Picks.Count < 6)
|
||||
{
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Start > DateTime.Now)
|
||||
return;
|
||||
|
||||
if (m_Ticks <= 5)
|
||||
{
|
||||
string text;
|
||||
int num = 0;
|
||||
try
|
||||
{
|
||||
num = m_Game.Picks[m_Ticks];
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.Stop();
|
||||
Console.WriteLine("Error with PowerBallGame Timer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Ticks == 0)
|
||||
text = "The first pick is... ";
|
||||
else if (m_Ticks < 5)
|
||||
text = "The next pick is... ";
|
||||
else
|
||||
text = "And the powerball is... ";
|
||||
|
||||
if (m_Game != null && m_Game.PowerBall != null)
|
||||
{
|
||||
m_Game.PowerBall.PublicOverheadMessage(0, m_Ticks < 5 ? 2041 : 0x21, false, text);
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2), new TimerStateCallback(DoDelayMessage), new object[] { m_Game.PowerBall, num, m_Ticks });
|
||||
}
|
||||
|
||||
foreach (PowerBallSatellite sat in PowerBall.SatList)
|
||||
{
|
||||
sat.PublicOverheadMessage(0, m_Ticks < 5 ? 2041 : 0x21, false, text);
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2), new TimerStateCallback(DoDelayMessage), new object[] { sat, num, m_Ticks });
|
||||
}
|
||||
|
||||
m_Ticks++;
|
||||
m_Start = DateTime.Now + TimeSpan.FromSeconds(8 + Utility.Random(10));
|
||||
}
|
||||
else //Time to tally picks and start up a new game!
|
||||
{
|
||||
m_Game.CheckForWinners();
|
||||
PowerBall.AddToArchive(m_Game.Picks, m_Game.Payout); //Adds pickslist to Archive for stats gump
|
||||
|
||||
if (!m_Game.HasJackpot) //Still no jackpot eh?
|
||||
{
|
||||
m_Game.NoWins++;
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2), new TimerStateCallback(DoMessage), m_Game);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PowerBall.Announcement)
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2), new TimerStateCallback(DoJackpotMessage), m_Game.JackpotWinners);
|
||||
|
||||
PowerBall.GoldSink += PowerBall.Instance.Profit;
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(10), new TimerStateCallback(DoWinnersMessage), m_Game);
|
||||
m_Game.PowerBall.NewGame(m_Game.HasJackpot);
|
||||
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoDelayMessage(object state)
|
||||
{
|
||||
object[] o = (object[])state;
|
||||
Item item = o[0] as Item;
|
||||
int num = (int)o[1];
|
||||
int tick = (int)o[2];
|
||||
|
||||
item.PublicOverheadMessage(0, tick < 5 ? 2041 : 0x21, false, num.ToString());
|
||||
}
|
||||
|
||||
#region Messages
|
||||
public static void DoMessage(object state)
|
||||
{
|
||||
if (state is PowerBallGame)
|
||||
{
|
||||
PowerBallGame powerball = (PowerBallGame)state;
|
||||
List<Mobile> mobList = new List<Mobile>();
|
||||
|
||||
if (powerball == null)
|
||||
return;
|
||||
|
||||
foreach (PowerBallTicket ticket in powerball.Tickets)
|
||||
{
|
||||
if (ticket.Owner != null && !mobList.Contains(ticket.Owner))
|
||||
mobList.Add(ticket.Owner);
|
||||
}
|
||||
|
||||
if (mobList.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < mobList.Count; ++i)
|
||||
{
|
||||
mobList[i].SendMessage("New Powerball numbers have been chosen so check your tickets!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoJackpotMessage(object state)
|
||||
{
|
||||
if (state is int && (int)state > 0)
|
||||
{
|
||||
int amount = (int)state;
|
||||
foreach (NetState netState in NetState.Instances)
|
||||
{
|
||||
Mobile m = netState.Mobile;
|
||||
if (m != null)
|
||||
{
|
||||
m.PlaySound(1460);
|
||||
m.SendMessage(33, "There {0} {1} winning jackpot {2} in powerball!", amount > 1 ? "are" : "is", amount, amount > 1 ? "tickets" : "ticket");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoWinnersMessage(object state)
|
||||
{
|
||||
if (state is PowerBallGame)
|
||||
{
|
||||
PowerBallGame powerball = (PowerBallGame)state;
|
||||
List<Mobile> winList = new List<Mobile>();
|
||||
|
||||
if (powerball == null)
|
||||
return;
|
||||
|
||||
foreach (PowerBallTicket ticket in powerball.Tickets)
|
||||
{
|
||||
if (ticket.Owner != null && ticket.Owner is PlayerMobile && ticket.Owner.NetState != null)
|
||||
{
|
||||
foreach (TicketEntry entry in ticket.Entries)
|
||||
{
|
||||
if (entry.Winner && !winList.Contains(ticket.Owner))
|
||||
winList.Add(ticket.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Mobile mob in winList)
|
||||
{
|
||||
int sound;
|
||||
if (mob.Female)
|
||||
{
|
||||
sound = Utility.RandomList(0x30C, 0x30F, 0x313, 0x31A, 0x31D, 0x32B, 0x330, 0x337);
|
||||
mob.PlaySound(sound);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound = Utility.RandomList(0x41A, 0x41B, 0x41E, 0x422, 0x42A, 0x42D, 0x431, 0x429);
|
||||
mob.PlaySound(sound);
|
||||
}
|
||||
|
||||
mob.SendMessage("It looks like you have a winning ticket!");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
111
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallSatellite.cs
Normal file
111
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallSatellite.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Targeting;
|
||||
using Server.Gumps;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Engines.LotterySystem
|
||||
{
|
||||
public class PowerBallSatellite : Item
|
||||
{
|
||||
private PowerBall m_PowerBall;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public PowerBall PowerBall { get { return m_PowerBall; } set { m_PowerBall = value; } }
|
||||
|
||||
[Constructable]
|
||||
public PowerBallSatellite() : base(0xED4)
|
||||
{
|
||||
Hue = 592;
|
||||
|
||||
Name = "Let's Play Powerball!";
|
||||
Movable = false;
|
||||
|
||||
if (PowerBall.PowerBallInstance != null)
|
||||
{
|
||||
m_PowerBall = PowerBall.PowerBallInstance;
|
||||
m_PowerBall.AddToSatList(this);
|
||||
}
|
||||
else Delete();
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if (m_PowerBall == null)
|
||||
base.OnDoubleClick(from);
|
||||
|
||||
else if (!m_PowerBall.IsActive && from.AccessLevel == AccessLevel.Player)
|
||||
from.SendMessage("Powerball is currenlty inactive at this time.");
|
||||
else if (from.InRange(Location, 3))
|
||||
{
|
||||
if (from.HasGump(typeof(PowerBallStatsGump)))
|
||||
from.CloseGump(typeof(PowerBallStatsGump));
|
||||
|
||||
from.SendGump(new PowerBallStatsGump(m_PowerBall, from));
|
||||
}
|
||||
else if (from.AccessLevel > AccessLevel.Player)
|
||||
from.SendGump(new PropertiesGump(from, m_PowerBall));
|
||||
else
|
||||
from.SendLocalizedMessage(500446); // That is too far away.
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
if (m_PowerBall != null && !m_PowerBall.Deleted)
|
||||
{
|
||||
if (!m_PowerBall.IsActive)
|
||||
list.Add(1060658, "Status\tOffline");
|
||||
else
|
||||
list.Add(1060658, "Status\tActive");
|
||||
|
||||
if (PowerBallStats.JackpotStats.Count > 0)
|
||||
{
|
||||
int index = PowerBallStats.JackpotStats.Count - 1;
|
||||
|
||||
list.Add(1060659, "Last Jackpot\t{0}", PowerBallStats.JackpotStats[index].JackpotWinner.Name);
|
||||
list.Add(1060660, "Date\t{0}", PowerBallStats.JackpotStats[index].JackpotTime);
|
||||
list.Add(1060661, "Amount\t{0}", PowerBallStats.JackpotStats[index].JackpotAmount);
|
||||
}
|
||||
}
|
||||
else
|
||||
list.Add("Disabled");
|
||||
|
||||
}
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
if (m_PowerBall != null)
|
||||
m_PowerBall.RemoveFromSatList(this);
|
||||
|
||||
base.OnAfterDelete();
|
||||
}
|
||||
|
||||
public PowerBallSatellite(Serial serial) : base (serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write((int)0); //Version
|
||||
writer.Write(m_PowerBall);
|
||||
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
m_PowerBall = reader.ReadItem() as PowerBall;
|
||||
|
||||
if (m_PowerBall != null)
|
||||
m_PowerBall.AddToSatList(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
134
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallStats.cs
Normal file
134
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallStats.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Engines.LotterySystem
|
||||
{
|
||||
public class PowerBallStats
|
||||
{
|
||||
public static readonly int MaxStats = 10; //How many in the list to retain
|
||||
|
||||
private Mobile m_JackpotWinner;
|
||||
private int m_Payout;
|
||||
private int m_JackpotAmount;
|
||||
private int m_GameNumber;
|
||||
private DateTime m_JackpotTime;
|
||||
private List<int> m_Picks = new List<int>();
|
||||
private bool m_JackpotEntry;
|
||||
|
||||
public Mobile JackpotWinner { get { return m_JackpotWinner; } }
|
||||
public int Payout { get { return m_Payout; } }
|
||||
public int JackpotAmount { get { return m_JackpotAmount; } }
|
||||
public int GameNumber { get { return m_GameNumber; } }
|
||||
public DateTime JackpotTime { get { return m_JackpotTime; } }
|
||||
public List<int> Picks { get { return m_Picks; } }
|
||||
public bool IsJackpotEntry { get { return m_JackpotEntry; } }
|
||||
|
||||
private static List<PowerBallStats> m_PicksStats = new List<PowerBallStats>();
|
||||
public static List<PowerBallStats> PicksStats { get { return m_PicksStats; } }
|
||||
|
||||
private static List<PowerBallStats> m_JackpotStats = new List<PowerBallStats>();
|
||||
public static List<PowerBallStats> JackpotStats { get { return m_JackpotStats; } }
|
||||
|
||||
public PowerBallStats(Mobile winner, int amount, int gameNumber)
|
||||
{
|
||||
m_JackpotWinner = winner;
|
||||
m_JackpotAmount = amount;
|
||||
m_GameNumber = gameNumber;
|
||||
m_JackpotTime = DateTime.Now;
|
||||
m_JackpotEntry = true;
|
||||
|
||||
m_JackpotStats.Add(this);
|
||||
TrimList(m_JackpotStats); //Keeps the list at a minimum of 10
|
||||
|
||||
if (PowerBall.Game != null)
|
||||
PowerBall.Game.UpdateSatellites();
|
||||
}
|
||||
|
||||
public PowerBallStats(List<int> list, int gameNumber, int payOut)
|
||||
{
|
||||
m_Picks = list;
|
||||
m_GameNumber = gameNumber;
|
||||
m_JackpotEntry = false;
|
||||
m_Payout = payOut;
|
||||
|
||||
m_PicksStats.Add(this);
|
||||
TrimList(m_PicksStats); //Keeps the list at a minimum of 10
|
||||
}
|
||||
|
||||
public void TrimList(List<PowerBallStats> list)
|
||||
{
|
||||
if (list == null || list.Count <= MaxStats || PowerBall.Game == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
{
|
||||
PowerBallStats stat = list[i];
|
||||
|
||||
if (stat.IsJackpotEntry && i < list.Count - MaxStats && m_JackpotStats.Contains(stat))
|
||||
m_JackpotStats.Remove(stat);
|
||||
else if (stat.GameNumber < PowerBall.Game.GameNumber - MaxStats && m_PicksStats.Contains(stat))
|
||||
m_PicksStats.Remove(stat);
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.Write((int)0); //version
|
||||
|
||||
writer.Write(m_JackpotEntry);
|
||||
writer.Write(m_GameNumber);
|
||||
|
||||
if (m_JackpotEntry)
|
||||
{
|
||||
writer.Write(m_JackpotWinner);
|
||||
writer.Write(m_JackpotAmount);
|
||||
writer.Write(m_JackpotTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(m_Payout);
|
||||
writer.Write(m_Picks.Count);
|
||||
|
||||
for (int i = 0; i < m_Picks.Count; ++i)
|
||||
{
|
||||
writer.Write(m_Picks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PowerBallStats(GenericReader reader)
|
||||
{
|
||||
int version = reader.ReadInt();
|
||||
|
||||
m_JackpotEntry = reader.ReadBool();
|
||||
m_GameNumber = reader.ReadInt();
|
||||
|
||||
if (m_JackpotEntry)
|
||||
{
|
||||
m_JackpotWinner = reader.ReadMobile();
|
||||
m_JackpotAmount = reader.ReadInt();
|
||||
m_JackpotTime = reader.ReadDateTime();
|
||||
|
||||
m_JackpotStats.Add(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Payout = reader.ReadInt();
|
||||
|
||||
int count = reader.ReadInt();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
int pick = reader.ReadInt();
|
||||
m_Picks.Add(pick);
|
||||
}
|
||||
|
||||
m_PicksStats.Add(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
199
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallTicket.cs
Normal file
199
Scripts/SubSystem/LotterySystem/PowerBall/PowerBallTicket.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using Server;
|
||||
using System;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
using Server.Engines.LotterySystem;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
public class PowerBallTicket : BaseLottoTicket
|
||||
{
|
||||
private PowerBall m_PowerBall;
|
||||
private int m_Game;
|
||||
private List<TicketEntry> m_Entries = new List<TicketEntry>();
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int GameNumber { get { return m_Game; } }
|
||||
|
||||
public List<TicketEntry> Entries { get { return m_Entries; } }
|
||||
|
||||
[Constructable]
|
||||
public PowerBallTicket() : base(null, TicketType.Powerball, false)
|
||||
{
|
||||
Name = "a powerball ticket";
|
||||
LootType = LootType.Blessed;
|
||||
Hue = 2106;
|
||||
|
||||
if (PowerBall.Instance != null && PowerBall.Game != null)
|
||||
{
|
||||
m_PowerBall = PowerBall.Game;
|
||||
PowerBall.Instance.AddTicket(this);
|
||||
m_Game = m_PowerBall.GameNumber;
|
||||
}
|
||||
else
|
||||
m_Game = 0;
|
||||
}
|
||||
|
||||
[Constructable]
|
||||
public PowerBallTicket(Mobile owner, PowerBall powerball) : base (owner, TicketType.Powerball, false)
|
||||
{
|
||||
Name = "a powerball ticket";
|
||||
LootType = LootType.Blessed;
|
||||
Hue = 2106;
|
||||
|
||||
m_PowerBall = powerball;
|
||||
|
||||
if (m_PowerBall != null)
|
||||
m_Game = m_PowerBall.GameNumber;
|
||||
else
|
||||
m_Game = 0;
|
||||
|
||||
if (PowerBall.Instance != null)
|
||||
PowerBall.Instance.AddTicket(this);
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
if (Payout > 0 || m_PowerBall == null || m_Game != m_PowerBall.GameNumber )
|
||||
list.Add(1150487); //[Expired]
|
||||
else
|
||||
list.Add(3005117); //[Active]
|
||||
}
|
||||
|
||||
/*public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if (Owner == null)
|
||||
Owner = from;
|
||||
|
||||
if (!IsChildOf(from.Backpack))
|
||||
from.SendLocalizedMessage(1042001);
|
||||
|
||||
else if (from != Owner)
|
||||
from.SendMessage("Only the owner can view this ticket.");
|
||||
|
||||
else
|
||||
{
|
||||
if (from.HasGump(typeof(TicketGump)))
|
||||
from.CloseGump(typeof(TicketGump));
|
||||
|
||||
from.SendGump(new TicketGump(this, from));
|
||||
}
|
||||
|
||||
base.OnDoubleClick(from);
|
||||
}*/
|
||||
|
||||
public void AddEntry(TicketEntry entry)
|
||||
{
|
||||
if (!m_Entries.Contains(entry))
|
||||
m_Entries.Add(entry);
|
||||
}
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
if (PowerBall.Instance != null)
|
||||
PowerBall.Instance.RemoveTicket(this);
|
||||
|
||||
if (m_Entries.Count > 0)
|
||||
m_Entries.Clear();
|
||||
}
|
||||
|
||||
public PowerBallTicket(Serial serial) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write((int) 0); //Version
|
||||
|
||||
writer.Write(m_Game);
|
||||
writer.Write(m_Entries.Count);
|
||||
|
||||
for (int i = 0; i < m_Entries.Count; ++i)
|
||||
{
|
||||
TicketEntry entry = m_Entries[i];
|
||||
|
||||
writer.Write(entry.One);
|
||||
writer.Write(entry.Two);
|
||||
writer.Write(entry.Three);
|
||||
writer.Write(entry.Four);
|
||||
writer.Write(entry.Five);
|
||||
writer.Write(entry.PowerBall);
|
||||
writer.Write(entry.Winner);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
m_Game = reader.ReadInt();
|
||||
int count = reader.ReadInt();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
int one = reader.ReadInt();
|
||||
int two = reader.ReadInt();
|
||||
int three = reader.ReadInt();
|
||||
int four = reader.ReadInt();
|
||||
int five = reader.ReadInt();
|
||||
int six = reader.ReadInt();
|
||||
bool winner = reader.ReadBool();
|
||||
|
||||
new TicketEntry(this, one, two, three, four, five, six, winner);
|
||||
}
|
||||
|
||||
m_PowerBall = PowerBall.Game;
|
||||
|
||||
if (PowerBall.Instance != null && m_PowerBall != null && m_Game == m_PowerBall.GameNumber)
|
||||
PowerBall.Instance.AddTicket(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class TicketEntry
|
||||
{
|
||||
private PowerBallTicket m_Ticket;
|
||||
private int m_One;
|
||||
private int m_Two;
|
||||
private int m_Three;
|
||||
private int m_Four;
|
||||
private int m_Five;
|
||||
private int m_PowerBall;
|
||||
private bool m_Winner;
|
||||
|
||||
public PowerBallTicket Ticket { get { return m_Ticket; } }
|
||||
public int One { get { return m_One; } }
|
||||
public int Two { get { return m_Two; } }
|
||||
public int Three { get { return m_Three; } }
|
||||
public int Four { get { return m_Four; } }
|
||||
public int Five{ get { return m_Five; } }
|
||||
public int PowerBall { get { return m_PowerBall; } }
|
||||
public bool Winner { get { return m_Winner; } set { m_Winner = value; } }
|
||||
|
||||
public TicketEntry (PowerBallTicket ticket, int one, int two, int three, int four, int five, bool winner) : this (ticket, one, two, three, four, five, 0, winner)
|
||||
{
|
||||
}
|
||||
|
||||
public TicketEntry(PowerBallTicket ticket, int one, int two, int three, int four, int five, int six, bool winner)
|
||||
{
|
||||
m_Ticket = ticket;
|
||||
|
||||
m_One = one;
|
||||
m_Two = two;
|
||||
m_Three = three;
|
||||
m_Four = four;
|
||||
m_Five = five;
|
||||
m_PowerBall = six;
|
||||
m_Winner = winner;
|
||||
|
||||
m_Ticket.AddEntry(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Scripts/SubSystem/LotterySystem/PowerBall/ReadMe.docx
Normal file
BIN
Scripts/SubSystem/LotterySystem/PowerBall/ReadMe.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user