using Filter; using Filter.Database.Character; using Filter.Database.GameFilter; using Filter.Networking.Manager; using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; using System.Linq.Expressions; using System.Runtime.CompilerServices; using System.Timers; namespace Filter.Utilities { internal class Lottery { private Timer LotteryTimer; public DateTime DrawDate; public Lottery() { } public void Create() { this.LotteryTimer = new Timer() { AutoReset = true }; this.LotteryTimer.Elapsed += new ElapsedEventHandler(this.LotteryTimer_Elapsed); this.LotteryTimer.Interval = 21600000; } public string LotteryTime() { DateTime now = DateTime.Now; TimeSpan drawDate = this.DrawDate - now; TimeSpan timeSpan = TimeSpan.FromSeconds(drawDate.TotalSeconds); object[] days = new object[] { timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds }; return string.Format("{0}Days {1}Hours {2}Minutes {3}Seconds", days); } public void LotteryTimer_Elapsed(object Sender, ElapsedEventArgs Args) { this.LotteryTimer.Stop(); Echo.SendWorldMessage(true, "The lottery is being drawn...", new object[0]); List list = Program.GameFilterData.LotteryTickets.ToList(); if (list.Count == 0) { Echo.SendWorldMessage(true, "No one has joined the lottery.", new object[0]); return; } int ticketCount = 0; foreach (LotteryTicket lotteryTicket in list) { ticketCount = ticketCount + lotteryTicket.TicketCount; } int num = (new Random()).Next(0, list.Count); LotteryTicket item = list[num]; ManagerClient managerClient = ( from Character in Program.ManagerLoggedIn where Character.Character != null select Character into nUserNo where nUserNo.Character.nUserNo == item.nUserNo select nUserNo).FirstOrDefault(); ManagerClient managerClient1 = managerClient; if (managerClient == null) { object[] objArray = new object[] { Money.ConvertMoney((long)(ticketCount * Convert.ToInt32(Program.ConfigValues["Lottery_Price"]))) }; Echo.SendWorldMessage(true, "Someone has won the lottery. Winnings: {0}.", objArray); } else { object[] character = new object[] { managerClient1.Character.sID, Money.ConvertMoney((long)(ticketCount * Convert.ToInt32(Program.ConfigValues["Lottery_Price"]))) }; Echo.SendWorldMessage(true, "{0} has won the lottery. Winnings: {1}.", character); object[] objArray1 = new object[] { Money.ConvertMoney((long)(ticketCount * Convert.ToInt32(Program.ConfigValues["Lottery_Price"]))) }; Echo.SendWhisper(managerClient1, "You have won {0} from the lottery.", objArray1); } tUserMoney _tUserMoney = ( from nUserNo in Program.CharacterData.tUserMoneys where nUserNo.nUserNo == item.nUserNo select nUserNo).FirstOrDefault(); Program.CharacterData.Entry(_tUserMoney).Reload(); if (_tUserMoney != null) { _tUserMoney = ( from nUserNo in Program.CharacterData.tUserMoneys where nUserNo.nUserNo == item.nUserNo select nUserNo).FirstOrDefault(); _tUserMoney.nUserMoney = _tUserMoney.nUserMoney + (long)(ticketCount * Convert.ToInt32(Program.ConfigValues["Lottery_Price"])); Program.CharacterData.SaveChanges(); } Program.GameFilterData.LotteryTickets.RemoveRange(Program.GameFilterData.LotteryTickets); Program.GameFilterData.SaveChanges(); DateTime now = DateTime.Now; this.DrawDate = now.AddHours((double)Convert.ToInt32(Program.ConfigValues["Lottery_Timer"])); this.LotteryTimer.Start(); } public void StartLottery() { if (!Convert.ToBoolean(Program.ConfigValues["Lottery_Enabled"])) { return; } DateTime now = DateTime.Now; this.DrawDate = now.AddHours((double)Convert.ToInt32(Program.ConfigValues["Lottery_Timer"])); this.LotteryTimer.Start(); object[] objArray = new object[] { this.LotteryTime() }; Echo.SendWorldMessage(true, "The lottery will be drawn in: {0}.", objArray); } } }