public override void Spawned() { base.Spawned(); if (BlockArray == null) { return; } MonsterInfo bInfo = new MonsterInfo { HP = this.HP, Image = Monster.EvilMirBody, CanTame = false, CanPush = false, AutoRev = false }; foreach (var block in BlockArray) { BlockingObject b = new BlockingObject(this, bInfo); BlockingObjects.Add(b); if (!b.Spawn(this.CurrentMap, new Point(this.CurrentLocation.X + block.X, this.CurrentLocation.Y + block.Y))) { SMain.EnqueueDebugging(string.Format("{3} blocking mob not spawned at {0} {1}:{2}", CurrentMap.Info.FileName, block.X, block.Y, Info.Name)); } } }
public void ReceiveCommand(C.Chat p) { if (!LoggedIn) { return; } SMain.EnqueueDebugging(string.Format("Command Received : {0}", p.Message)); if (SMain.Envir.ManagerCommands != null) { SMain.Envir.ManagerCommands.Add(p.Message); } }
private void SpawnInvasionMonsters(int order) { var respawns = Info.Respawns.Where(o => o.Order == order).ToList(); if (respawns == null || respawns.Count == 0) { SMain.EnqueueDebugging(string.Format("De Activating Invasion Event:{0} Stage:{1}", Info.EventName, Stage)); IsActive = false; } SpawnMonstersForInvasion(respawns); }
public void SignUp(PlayerObject player, byte selection) { SMain.EnqueueDebugging(string.Format("[LMS BR] {0} Player {1} signing up to {2}", CurrentMap.Info.Title, player.Name, selection)); if (Started || Finished) { return; } if (player.Level < Info.MinLevel || player.Level > Info.MaxLevel) { return; } if (Info.Index != selection) { return; } if (SignedupPlayers == null) { SignedupPlayers = new List <PlayerObject>(); } bool playerFound = false; if (SignedupPlayers.Count > 0) { for (int i = 0; i < SignedupPlayers.Count; i++) { if (SignedupPlayers[i].Name == player.Name) { playerFound = true; } } if (playerFound) { SignedupPlayers.Remove(player); return; } else { SignedupPlayers.Add(player); return; } } else { SignedupPlayers.Add(player); } return; }
public void MessageToPlayer(C.Chat p) { string playerName = ""; playerName = p.Message.Replace("/", ""); string[] split = playerName.Split(' '); if (split.Length <= 1) { return; } playerName = split[0]; string message = "SYSTEM"; for (int i = 1; i < split.Length; i++) { message += string.Format(" {0}", split[i]); } PlayerObject player = SMain.Envir.GetPlayer(playerName); if (player == null) { Enqueue(new S.Chat { Message = string.Format("{0} could not be found", playerName), Type = ChatType.System }); Enqueue(new S.Chat { Message = string.Format("{0} could not be found", playerName), Type = ChatType.WhisperOut }); if (Settings.DebugServerManager) { SMain.EnqueueDebugging(string.Format("{0} could not be found.", playerName)); } return; } if (player.Connection != null && player.Connection.Connected && player.Connection.Stage == GameStage.Game) { if (Settings.DebugServerManager) { SMain.EnqueueDebugging(string.Format("Messenger > {0} : {1}", playerName, message)); } player.ReceiveChat(message, ChatType.WhisperIn); Enqueue(new S.Chat { Message = message, Type = ChatType.WhisperOut }); } }
private void SpawnMonsters() { var topLeftLocation = new Point(CurrentLocation.X - Info.EventSize, CurrentLocation.Y - Info.EventSize); foreach (var eventRespawn in Info.Respawns) { var respawnInfo = new RespawnInfo(); var monster = Envir.GetMonsterInfo(eventRespawn.MonsterName); if (monster == null) { SMain.EnqueueDebugging(string.Format("{0} Activating Event:{1} FAILED COULDN'T FIND MONSTER {2}", Map.Info.FileName, Info.EventName, eventRespawn.MonsterName)); return; } respawnInfo.Spread = eventRespawn.MonsterCount; respawnInfo.Count = eventRespawn.MonsterCount; respawnInfo.MonsterIndex = monster.Index; respawnInfo.Delay = 10000; respawnInfo.SaveRespawnTime = false; respawnInfo.RespawnIndex = 0; respawnInfo.RespawnTicks = 0; if (eventRespawn.SpreadY == 0 && eventRespawn.SpreadX == 0 && eventRespawn.MonsterCount == 1) { respawnInfo.Location = CurrentLocation; } else { respawnInfo.Location = new Point(topLeftLocation.X + eventRespawn.SpreadX * 2, topLeftLocation.Y + eventRespawn.SpreadY * 2); } MapRespawn mapRespawn = new MapRespawn(respawnInfo); RouteInfo route = new RouteInfo(); route.Location = respawnInfo.Location; route.Delay = 1000; mapRespawn.Route.Add(route); mapRespawn.Map = Map; mapRespawn.IsEventObjective = eventRespawn.IsObjective; mapRespawn.Event = this; MapRespawns.Add(mapRespawn); } Map.Respawns.AddRange(MapRespawns); }
private void SpawnMonstersForInvasion(List <EventRespawn> respawns) { var topLeftLocation = new Point(CurrentLocation.X - Info.EventSize, CurrentLocation.Y - Info.EventSize); foreach (var eventRespawn in respawns) { var monster = Envir.GetMonsterInfo(eventRespawn.MonsterName); if (monster == null) { SMain.EnqueueDebugging(string.Format("{0} Event:{1} FAILED COULDN'T FIND MONSTER {2}", Map.Info.FileName, Info.EventName, eventRespawn.MonsterName)); continue; } var respawnInfo = new RespawnInfo() { Spread = eventRespawn.MonsterCount, Count = eventRespawn.MonsterCount, MonsterIndex = monster.Index, Delay = ushort.MaxValue }; if (eventRespawn.SpreadY == 0 && eventRespawn.SpreadX == 0) { respawnInfo.Location = CurrentLocation; } else { respawnInfo.Location = new Point(topLeftLocation.X + eventRespawn.SpreadX * 2, topLeftLocation.Y + eventRespawn.SpreadY * 2); } MapRespawn mapRespawn = new MapRespawn(respawnInfo); RouteInfo route = new RouteInfo() { Location = respawnInfo.Location, Delay = 1000, }; mapRespawn.Route.Add(route); mapRespawn.Map = Map; mapRespawn.IsEventObjective = eventRespawn.IsObjective; mapRespawn.Event = this; MapRespawns.Add(mapRespawn); } Map.Respawns.AddRange(MapRespawns); }
private void ReceiveData(IAsyncResult result) { //SMain.EnqueueDebugging(string.Format("[ServerManager]Data Received Check..")); if (!Connected) { return; } if (DebugMode) { SMain.EnqueueDebugging(string.Format("[ServerManager]Data Received Connected Pass..")); } int dataRead; try { dataRead = _client.Client.EndReceive(result); } catch { Disconnecting = true; return; } if (dataRead == 0) { Disconnecting = true; return; } byte[] rawBytes = result.AsyncState as byte[]; byte[] temp = _rawData; _rawData = new byte[dataRead + temp.Length]; Buffer.BlockCopy(temp, 0, _rawData, 0, temp.Length); Buffer.BlockCopy(rawBytes, 0, _rawData, temp.Length, dataRead); Packet p; while ((p = Packet.ReceivePacket(_rawData, out _rawData)) != null) { _receiveList.Enqueue(p); } BeginReceive(); }
public void ActivateEvent() { Point randomLocation = Locations[Envir.Random.Next(Locations.Count)]; CurrentLocation = randomLocation; SMain.EnqueueDebugging(string.Format("{0} Activating Event:{1}", Map.Info.FileName, Info.EventName)); switch (Info.EventType) { case EventType.Invasion: Stage = 1; SpawnInvasionMonsters(1); break; default: SpawnMonsters(); break; } MapEventClientSide eventNotification = new MapEventClientSide() { EventName = Info.EventName, EventType = Info.EventType, Index = Info.Index, IsActive = true, Size = Info.EventSize, Location = CurrentLocation }; foreach (var player in Map.Players) { player.Enqueue(new S.ActivateEvent() { Event = eventNotification }); } #region Boundaries for (int y = CurrentLocation.Y - Info.EventSize; y <= CurrentLocation.Y + Info.EventSize; y++) { if (y < 0) { continue; } if (y >= Map.Height) { break; } for (int x = CurrentLocation.X - Info.EventSize; x <= CurrentLocation.X + Info.EventSize; x += Math.Abs(y - CurrentLocation.Y) == Info.EventSize ? 1 : Info.EventSize * 2) { if (x < 0) { continue; } if (x >= Map.Width) { break; } if (!Map.Cells[x, y].Valid) { continue; } SpellObject spell = new SpellObject { ExpireTime = long.MaxValue, Spell = this.Info.IsSafezone ? Spell.TrapHexagon : Spell.FireWall, TickSpeed = int.MaxValue, CurrentLocation = new Point(x, y), CurrentMap = Map, Decoration = true }; Map.Cells[x, y].Add(spell); Zone.Add(spell); spell.Spawned(); } } #endregion }
public void EventMonsterDied(List <PlayerObject> monsterContributers) { if (!IsActive) { return; } for (int i = 0; i < monsterContributers.Count; i++) { var monContributor = monsterContributers[i]; if (!Contributers.Contains(monContributor)) { Contributers.Add(monContributor); } } switch (Info.EventType) { case EventType.Invasion: var invasionRespawns = MapRespawns.Where(o => o.IsEventObjective); if (invasionRespawns.All(o => o.Count == 0)) { foreach (var mapRespawn in MapRespawns) { Map.Respawns.Remove(mapRespawn); } MapRespawns.Clear(); Stage++; SpawnInvasionMonsters(Stage); List <MonsterEventObjective> monObj = MapRespawns.Select(o => new MonsterEventObjective() { MonsterName = o.Monster.Name, MonsterTotalCount = o.Info.Count, MonsterAliveCount = o.Info.Count }).ToList(); var p = new S.EnterOrUpdatePublicEvent(Info.EventName, Info.EventType, Info.ObjectiveMessage, Stage, monObj); foreach (var player in Players) { player.Enqueue(p); } } else { List <MonsterEventObjective> monObj = invasionRespawns.Select(o => new MonsterEventObjective() { MonsterName = o.Monster.Name, MonsterTotalCount = o.Info.Count, MonsterAliveCount = o.Count }).ToList(); //var remainingCount = string.Format("{0}/{1}", alive, total); //var completedPerc = (int)(((decimal)dead / total) * 100); var p = new S.EnterOrUpdatePublicEvent(Info.EventName, Info.EventType, Info.ObjectiveMessage, Stage, monObj); foreach (var player in Players) { player.Enqueue(p); } } break; default: var objectiveRespawns = MapRespawns.Where(o => o.IsEventObjective); List <MonsterEventObjective> monObjectives = objectiveRespawns.Select(o => new MonsterEventObjective() { MonsterName = o.Monster.Name, MonsterTotalCount = o.Info.Count, MonsterAliveCount = o.Count }).ToList(); var packet = new S.EnterOrUpdatePublicEvent(Info.EventName, Info.EventType, Info.ObjectiveMessage, Stage, monObjectives); foreach (var player in Players) { player.Enqueue(packet); } if (objectiveRespawns.All(o => o.Count == 0)) { SMain.EnqueueDebugging(string.Format("De Activating Event:{0}", Info.EventName)); IsActive = false; } break; } }
public void CheckExternalLogin(C.ExternalToolLogin p) { if (p.Password.Length < 4 || p.Username.Length < 4) { Enqueue(new S.ExternalToolLogin { Result = 1 }); SMain.EnqueueDebugging(string.Format("[Server Manager] {0} login failure -1", IPAddress)); return; } if (Settings.ManagerUsers != null && Settings.ManagerUsers.Count > 0) { byte result = 0; bool userNameFound = false; for (int i = 0; i < Settings.ManagerUsers.Count; i++) { if (userNameFound) { continue; } if (Settings.ManagerUsers[i].UserName.ToUpper() == p.Username.ToUpper()) { userNameFound = true; if (Settings.ManagerUsers[i].Password == p.Password) { result = 0; } else { result = 1; } } } if (!userNameFound) { result = 2; } if (result == 0) { LoggedIn = true; ManagerUser = p.Username; Enqueue(new S.ExternalToolLogin { Result = result }); SMain.EnqueueDebugging(string.Format("[Server Manager] {0} login success", IPAddress)); return; } else { Enqueue(new S.ExternalToolLogin { Result = result }); SMain.EnqueueDebugging(string.Format("[Server Manager] {0} Login Failure -{1}", IPAddress, result)); return; } } else { Enqueue(new S.ExternalToolLogin { Result = 3 }); SMain.EnqueueDebugging(string.Format("[Server Manager] {0} No such user", IPAddress)); return; } }
private void ProcessPacket(Packet p) { if (DebugMode) { SMain.EnqueueDebugging(string.Format("Packet Received {0}", p.Index)); } if (p == null || Disconnecting) { return; } switch (p.Index) { case (short)ClientPacketIds.ExternalToolLogin: if (DebugMode) { SMain.EnqueueDebugging(string.Format("{0} logging in...", IPAddress)); } CheckExternalLogin((C.ExternalToolLogin)p); break; case (short)ClientPacketIds.Disconnect: SMain.EnqueueDebugging(string.Format("{0} disconnected.", ManagerUser)); Disconnect(); break; case (short)ClientPacketIds.KeepAlive: C.KeepAlive keepAlive = (C.KeepAlive)p; if (DebugMode) { SMain.EnqueueDebugging(string.Format("Keep Alive {0}", keepAlive.Time)); } break; case (short)ClientPacketIds.ToolStats: if (LoggedIn) { GetStats(); } break; case (short)ClientPacketIds.Chat: if (LoggedIn) { C.Chat chat = (C.Chat)p; string[] splits = chat.Message.Split(' '); if (splits.Length == 0) { Enqueue(new S.Chat { Message = string.Format("Invalid Input"), Type = ChatType.System }); break; } else { if (splits[0].StartsWith("@")) { ReceiveCommand((C.Chat)p); } else if (splits[0].StartsWith("/")) { if (SMain.Envir.Running) { MessageToPlayer((C.Chat)p); } } else if (splits[0].StartsWith("!")) { if (SMain.Envir.Running) { BroadcastMessage((C.Chat)p); } } break; } } break; default: SMain.EnqueueDebugging(string.Format("Invalid Packet for Server Manager\nIndex : {0}", p.Index)); break; } }
public bool BuyNow() { // Sellers cannot bid on their own items if (IsSeller) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Cannot bid on own item.", AuctionIndex)); return(false); } AuctionHouseInfo ListedItem = Envir.GetAuction(AuctionIndex); // Can't find the Auction if (ListedItem == null) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Index was not found.", AuctionIndex)); return(false); } if (ListedItem.Sold) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction has already finished or been purchased.", AuctionIndex)); return(false); } if (!ListedItem.CanBuyNow) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction is not Buy now.", AuctionIndex)); return(false); } if (ListedItem.BuyNowPrice <= 0 || ListedItem.BuyNowPrice > uint.MaxValue) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction Buy now price out of range.", AuctionIndex)); return(false); } // The Auctions ended if (SMain.Envir.Time > ListedItem.ListEndTime) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction has already finished.", AuctionIndex)); return(false); } // The Item up for Auction doesn't exist if (ListedItem.ListedItem == null) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Item not found.", AuctionIndex)); return(false); } PlayerObject bidder = Envir.GetPlayer((uint)PlayerIndex); // Can't find the player if (bidder == null) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Buyer not found {0}.", PlayerIndex)); return(false); } // Can't find the players account if (bidder.Account == null) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Buyer Account not found {0}.", PlayerIndex)); return(false); } PlayerObject seller = Envir.GetPlayer((uint)ListedItem.SellersIndex); if (seller == null) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Sellers Account not found {0}.", PlayerIndex)); return(false); } uint gold = 0; string message = ""; List <UserItem> items = new List <UserItem>(); switch (ListedItem.CurrencyType) { default: case CurrencyType.Gold: { if (bidder.Account.Gold < ListedItem.BuyNowPrice) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Player does not have enough gold.", AuctionIndex)); return(false); } gold = ListedItem.BuyNowPrice; if (gold >= bidder.Account.Gold) { gold = bidder.Account.Gold; } bidder.Account.Gold -= gold; bidder.Enqueue(new S.LoseGold { Gold = gold }); items.Add(ListedItem.ListedItem); message = string.Format("You purchased {0} from {1} for {2:#,###,###,###}.", ListedItem.ListedItem.FriendlyName, seller.Name, ListedItem.BuyNowPrice); MailInfo mail = new MailInfo(PlayerIndex, false) { Gold = 0, Message = message, Items = items, Sender = "AuctionHouse", MailID = ++Envir.NextMailID }; mail.Send(); mail = null; items.Add(ListedItem.ListedItem); message = string.Format("{0} purchased {1} from you for {2:#,###,###,###}.", bidder.Name, ListedItem.ListedItem.FriendlyName, ListedItem.BuyNowPrice); mail = new MailInfo(PlayerIndex, false) { Gold = ListedItem.BuyNowPrice - (uint)Functions.GetPercentage(ListedItem.Commission, (int)ListedItem.BuyNowPrice), Message = message, Sender = "AuctionHouse", MailID = ++Envir.NextMailID }; mail.Send(); mail = null; // End it. ListedItem.ListedItem = null; ListedItem.CurrentBid = gold; ListedItem.HighestBidderIndex = PlayerIndex; ListedItem.ListEndTime = Envir.Time; ListedItem.Sold = true; GoldRetrived = true; /* * gold = MyBid; * // Message contents. * message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid); * // Create the mail * MailInfo mail = new MailInfo(PlayerIndex, true) * { * MailID = ++Envir.NextMailID, * Sender = "AuctionHouse", * Message = message, * Gold = gold, * }; */ } break; case CurrencyType.Credits: { if (bidder.Account.Credit < ListedItem.BuyNowPrice) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Player does not have enough credits.", AuctionIndex)); return(false); } } break; case CurrencyType.Pearl: { if (bidder.Info.PearlCount < ListedItem.BuyNowPrice) { SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Player does not have enough pearls.", AuctionIndex)); return(false); } } break; } return(true); }
public void Process() { if (SMain.Envir.Time > processMsgTime) { processMsgTime = SMain.Envir.Time + 1500; Enqueue(new S.KeepAlive { Time = SMain.Envir.Time }); } if (SMain.Envir.Running) { if (SMain.Envir.Time > playerListCounter) { playerListCounter = SMain.Envir.Time + Settings.Minute; if (SMain.Envir.Players == null || SMain.Envir.Players.Count <= 0) { } else { List <ToolOnlinePlayerListItem> players = new List <ToolOnlinePlayerListItem>(); for (int i = 0; i < SMain.Envir.Players.Count; i++) { PlayerObject pOb = SMain.Envir.Players[i]; players.Add(new ToolOnlinePlayerListItem { PlayerName = pOb.Name, PlayerGuild = pOb.MyGuild != null ? pOb.MyGuild.Name : "NONE", PlayerLevel = pOb.Level, PlayerCurrentMap = pOb.CurrentMap.Info.Title, PlayerCurrentLocation = string.Format("X:[{0}] Y:[{1}]", pOb.CurrentLocation.X, pOb.CurrentLocation.Y), AccountGold = pOb.Account.Gold, AccountCredit = pOb.Account.Credit }); } if (players != null && players.Count > 0) { Enqueue(new S.ToolPlayerList { Players = players }); } } } } if (_client == null || !_client.Connected || _receiveList == null || _retryList == null) { Disconnect(); return; } while (!_receiveList.IsEmpty && !Disconnecting) { if (DebugMode) { SMain.EnqueueDebugging(string.Format("[ServerManager][IN]Processing..")); } if (!_receiveList.TryDequeue(out Packet p)) { continue; } ProcessPacket(p); } while (_retryList.Count > 0) { if (!_retryList.TryDequeue(out Packet p) || p == null) { continue; } _receiveList.Enqueue(p); } if (_sendList == null || _sendList.Count <= 0) { return; } List <byte> data = new List <byte>(); while (_sendList.Count > 0) { if (DebugMode) { SMain.EnqueueDebugging(string.Format("[ServerManager][OUT]Processing..")); } if (!_sendList.TryDequeue(out Packet p) || p == null) { continue; } data.AddRange(p.GetPacketBytes()); } //BeginReceive(); BeginSend(data); }
public void End_Match(bool foundWinner = false) { bool failed = false; string matchResult = ""; if (foundWinner) { LMS_Rank lmsRank = null; PlayerObject winningPlayer = null; for (int i = 0; i < CurrentMap.Players.Count; i++) { PlayerObject player = CurrentMap.Players[i]; if (player == null || player.Dead) { continue; } for (int x = 0; x < PlayerRanks.Count; x++) { if (player.Name == PlayerRanks[x].Player.Name && winningPlayer == null && lmsRank == null) { winningPlayer = player; lmsRank = PlayerRanks[x]; } } } if (winningPlayer != null && lmsRank != null) { // TODO Reward players (send by mail) matchResult = string.Format("{0} is the Victor of the match!", winningPlayer.Name); winningPlayer.Teleport(Envir.GetMap(winningPlayer.BindMapIndex), winningPlayer.BindLocation, true, 0); winningPlayer.InLMSBR = false; List <LMS_RewardInfo> rewards = CreateRewards(1, winningPlayer); if (rewards != null && rewards.Count > 0) { winningPlayer.ReceiveChat(string.Format("Victory is yours! Prize(s) will be sent via mail!"), ChatType.Hint); List <UserItem> items = new List <UserItem>(); for (int i = 0; i < rewards.Count; i++) { if (rewards[i].ItemReward == null) { SMain.EnqueueDebugging(string.Format("Null reward")); continue; } ItemInfo iInfo = Envir.GetItemInfo(rewards[i].ItemReward.Index); if (iInfo == null) { SMain.EnqueueDebugging(string.Format("Null item info")); continue; } UserItem item = Envir.CreateFreshItem(iInfo); if (item != null) { items.Add(item); } } MailInfo mail = new MailInfo(winningPlayer.Info.Index) { Items = items, Message = string.Format("Congratulations on winning the match! here is your prize(s)"), Sender = string.Format("LMS"), MailID = ++Envir.NextMailID }; mail.Send(); } SMain.EnqueueDebugging(string.Format("[LMS BR] Map {0} {1} wins the Match, made {2} kills.", CurrentMap.Info.Title, winningPlayer.Name, lmsRank.Kills)); } else { failed = true; } } if ((failed && foundWinner) || !foundWinner) { if (CurrentMap.Players.Count > 0) { string[] finalPlayers = new string[CurrentMap.Players.Count]; if (finalPlayers.Length >= 1) { int index = 0; for (int i = 0; i < CurrentMap.Players.Count; i++) { PlayerObject player = CurrentMap.Players[i]; if (player.Dead || player.IsGM) { continue; } finalPlayers[index] = player.Name; player.Teleport(Envir.GetMap(player.BindMapIndex), player.BindLocation); player.InLMSBR = failed; index++; } Array.Resize(ref finalPlayers, index); } matchResult = "Stalemate, Players "; for (int i = 0; i < finalPlayers.Length; i++) { matchResult += string.Format("{0}{1} ", finalPlayers[i], i - 1 <= finalPlayers.Length ? "," : " have drawn the match!"); } } } if (matchResult.Length > 0) { Envir.Broadcast(new ServerPackets.Chat { Message = matchResult, Type = ChatType.Announcement }); } StartTime = 0; EndTime = 0; SignedupPlayers = new List <PlayerObject>(); CircleLocations = new List <Point>(); PlayerRanks = new List <LMS_Rank>(); StartingLocation = Info.StartingLocation; Stage = 0; Finished = false; Started = false; }
public void Start_Match() { if (CurrentMap == null) { return; } if (SignedupPlayers == null || SignedupPlayers.Count == 0) { return; } StartingLocation = new Point( Envir.Random.Next(Info.StartingLocation.X - Info.StartingRange <= 0 ? 1 : Info.StartingLocation.X - Info.StartingRange, Info.StartingLocation.X + Info.StartingRange >= CurrentMap.Width ? CurrentMap.Width - 1 : Info.StartingLocation.X + Info.StartingRange), Envir.Random.Next(Info.StartingLocation.Y - Info.StartingRange <= 0 ? 1 : Info.StartingLocation.Y - Info.StartingRange, Info.StartingLocation.Y + Info.StartingRange >= CurrentMap.Height ? CurrentMap.Height - 1 : Info.StartingLocation.Y + Info.StartingRange)); SMain.EnqueueDebugging(string.Format("[LMS BR] Map {0} Random Start Point X:{1} Y:{2}", CurrentMap.Info.Title, StartingLocation.X, StartingLocation.Y)); ShrinkTime = Envir.Time + (Info.Duration / 4 * Settings.Minute); for (int i = 0; i < SignedupPlayers.Count; i++) { if (SignedupPlayers[i].Connection == null) { continue; } if (SignedupPlayers[i].Connection.Stage != MirNetwork.GameStage.Game) { continue; } if (SignedupPlayers[i].Dead) { continue; } Point tempPoint = GetRandomPointInCircle(); while (!CurrentMap.ValidPoint(tempPoint)) { tempPoint = GetRandomPointInCircle(); } SignedupPlayers[i].Teleport(CurrentMap, tempPoint, true); SignedupPlayers[i].InLMSBR = true; SignedupPlayers[i].CurrentLMS = this; } SMain.EnqueueDebugging(string.Format("[LMS BR] Map {0} {1} Players signed up teleported in", CurrentMap.Info.Title, SignedupPlayers.Count)); for (int i = 0; i < CurrentMap.Players.Count; i++) { PlayerObject player = CurrentMap.Players[i]; if (player.IsGM || player.IsDev) { continue; } if (player.Dead) { continue; } PlayerRanks.Add(new LMS_Rank { Player = player, Kills = 0 }); } Started = true; StartTime = Envir.Time; EndTime = Envir.Time + (Settings.Minute * Info.Duration); CurrentSize = Info.StartingSize; OriginalPlayercount = (byte)PlayerRanks.Count; CreateCircle(Info.StartingSize); CreateInnerCircle(); BroadcastMessage(string.Format("Be advised you take damage while being OUTSIDE of the circle."), ChatType.Hint); long temp = ShrinkTime - Envir.Time; string remainingTime = Functions.PrintTimeSpanFromSeconds(temp / 1000); BroadcastMessage(string.Format("The Circle will shrink in {0} be ready!", remainingTime), ChatType.Announcement); }
public bool MakeBid(uint myBid) { // Range Check if (myBid <= 0 || myBid > uint.MaxValue) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Bid amount {0} out of range.", myBid)); return(false); } // Sellers cannot bid on their own items if (IsSeller) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Cannot bid on own item.", AuctionIndex)); return(false); } AuctionHouseInfo ListedItem = Envir.GetAuction(AuctionIndex); // Can't find the Auction if (ListedItem == null) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : {0} Index was not found.", AuctionIndex)); return(false); } // The Auctions ended if (SMain.Envir.Time > ListedItem.ListEndTime) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : {0} Auction has already finished.", AuctionIndex)); return(false); } // The Item up for Auction doesn't exist if (ListedItem.ListedItem == null) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : {0} Item not found.", AuctionIndex)); return(false); } // Bidder was the previous bidder if (ListedItem.HighestBidderIndex == PlayerIndex) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Already made bid.")); return(false); } PlayerObject bidder = Envir.GetPlayer((uint)PlayerIndex); // Can't find the player if (bidder == null) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer not found {0}.", PlayerIndex)); return(false); } // Can't find the players account if (bidder.Account == null) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Account not found {0}.", PlayerIndex)); return(false); } uint gold = 0; string message = ""; // Switch between the currency switch (ListedItem.CurrencyType) { default: case CurrencyType.Gold: { // Bid was more than the Account has if (bidder.Account.Gold < myBid) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Not enough gold {0}.", myBid - bidder.Account.Gold)); return(false); } // Bid was too low if (myBid <= ListedItem.CurrentBid + 1000) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Bid is too low {0}.", myBid - ListedItem.CurrentBid)); return(false); } if (!FirstBid && !GoldRetrived) { gold = MyBid; // Message contents. message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid); // Create the mail MailInfo mail = new MailInfo(PlayerIndex, true) { MailID = ++Envir.NextMailID, Sender = "AuctionHouse", Message = message, Gold = gold, }; GoldRetrived = true; } MyBid = myBid; if (myBid >= bidder.Account.Gold) { myBid = bidder.Account.Gold; } bidder.Account.Gold -= myBid; bidder.Enqueue(new S.LoseGold { Gold = myBid }); ListedItem.CurrentBid = myBid; ListedItem.HighestBidderIndex = PlayerIndex; GoldRetrived = false; bidder.ReceiveChat(string.Format("You bid {0:#,###,###,###} for {1}{2} has been placed.", MyBid, ListedItem.ListedItem.FriendlyName, ListedItem.ListedItem.Count >= 1 ? string.Format("[{0}]", ListedItem.ListedItem.Count) : ""), ChatType.System); if (FirstBid) { FirstBid = false; } return(true); } case CurrencyType.Credits: { if (bidder.Account.Credit < myBid) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Not enough credit {0}.", myBid - bidder.Account.Credit)); return(false); } // Only allow Increments of 1k if (myBid <= ListedItem.CurrentBid + 5) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Bid is too low {0}.", myBid - ListedItem.CurrentBid)); return(false); } if (!FirstBid && !GoldRetrived) { gold = MyBid; // Message contents. message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid); // Create the mail MailInfo mail = new MailInfo(PlayerIndex, true) { MailID = ++Envir.NextMailID, Sender = "AuctionHouse", Message = message, Gold = gold, }; GoldRetrived = true; } MyBid = myBid; if (myBid >= bidder.Account.Credit) { myBid = bidder.Account.Credit; } bidder.Account.Credit -= myBid; bidder.Enqueue(new S.LoseCredit { Credit = myBid }); ListedItem.CurrentBid = myBid; ListedItem.HighestBidderIndex = PlayerIndex; GoldRetrived = false; bidder.ReceiveChat(string.Format("You bid {0:#,###,###,###} for {1}{2} has been placed.", MyBid, ListedItem.ListedItem.FriendlyName, ListedItem.ListedItem.Count >= 1 ? string.Format("[{0}]", ListedItem.ListedItem.Count) : ""), ChatType.System); if (FirstBid) { FirstBid = false; } return(true); } case CurrencyType.Pearl: { if (bidder.Info.PearlCount < myBid) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Not enough pearl {0}.", myBid - bidder.Info.PearlCount)); return(false); } // Only allow Increments of 1k if (myBid <= ListedItem.CurrentBid + 1) { SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Bid is too low {0}.", myBid - ListedItem.CurrentBid)); return(false); } if (!FirstBid && !GoldRetrived) { gold = MyBid; // Message contents. message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid); // Create the mail MailInfo mail = new MailInfo(PlayerIndex, true) { MailID = ++Envir.NextMailID, Sender = "AuctionHouse", Message = message, Gold = gold, }; GoldRetrived = true; } MyBid = myBid; if (myBid >= bidder.Info.PearlCount) { myBid = (uint)bidder.Info.PearlCount; } bidder.Info.PearlCount -= (int)myBid; ListedItem.CurrentBid = myBid; ListedItem.HighestBidderIndex = PlayerIndex; GoldRetrived = false; bidder.ReceiveChat(string.Format("You bid {0:#,###,###,###} Pearl{2} for {1}{3} has been placed.", MyBid, ListedItem.ListedItem.FriendlyName, MyBid > 1 ? "s" : "", ListedItem.ListedItem.Count >= 1 ? string.Format("[{0}]", ListedItem.ListedItem.Count) : ""), ChatType.System); if (FirstBid) { FirstBid = false; } return(true); } } }
public void Process() { if (Info.StartDay != 7 && (DayOfWeek)Info.StartDay == DateTime.Now.DayOfWeek) { DateTime startTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Info.StartHour, Info.StartMinute, 0); DateTime hourTime = startTime.AddHours(-1); DateTime minuteTime = startTime.AddMinutes(-30); DateTime fifteen = startTime.AddMinutes(-15); DateTime five = startTime.AddMinutes(-5); if (((DateTime.Now >= hourTime && DateTime.Now <= hourTime.AddSeconds(30)) || (DateTime.Now >= minuteTime && DateTime.Now <= minuteTime.AddSeconds(30)) || (DateTime.Now >= fifteen && DateTime.Now <= fifteen.AddSeconds(30)) || (DateTime.Now >= five && DateTime.Now <= five.AddSeconds(30))) && Envir.Time > NextMessageTime) { NextMessageTime = Envir.Time + Settings.Minute; List <string> listedPlayers = new List <string>(); if (SignedupPlayers != null && SignedupPlayers.Count > 0) { for (int i = 0; i < SignedupPlayers.Count; i++) { if (SignedupPlayers[i].Connection == null || SignedupPlayers[i].Connection.Stage != MirNetwork.GameStage.Game) { continue; } listedPlayers.Add(SignedupPlayers[i].Name); SignedupPlayers[i].ReceiveChat(string.Format("LMS will start in {0} minutes", DateTime.Now == hourTime ? "60" : DateTime.Now == minuteTime ? "30" : DateTime.Now == fifteen ? "15" : "5"), ChatType.System); } } AnnounceCountDown(listedPlayers, DateTime.Now >= five && DateTime.Now <= five.AddSeconds(30)); } } else if (Info.StartDay == 7) { DateTime startTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Info.StartHour, Info.StartMinute, 0); DateTime hourTime = startTime.AddHours(-1); DateTime minuteTime = startTime.AddMinutes(-30); DateTime fifteen = startTime.AddMinutes(-15); DateTime five = startTime.AddMinutes(-5); if (((DateTime.Now >= hourTime && DateTime.Now <= hourTime.AddSeconds(30)) || (DateTime.Now >= minuteTime && DateTime.Now <= minuteTime.AddSeconds(30)) || (DateTime.Now >= fifteen && DateTime.Now <= fifteen.AddSeconds(30)) || (DateTime.Now >= five && DateTime.Now <= five.AddSeconds(30))) && Envir.Time > NextMessageTime) { NextMessageTime = Envir.Time + Settings.Minute; List <string> listedPlayers = new List <string>(); if (SignedupPlayers != null && SignedupPlayers.Count > 0) { for (int i = 0; i < SignedupPlayers.Count; i++) { if (SignedupPlayers[i].Connection == null || SignedupPlayers[i].Connection.Stage != MirNetwork.GameStage.Game) { continue; } listedPlayers.Add(SignedupPlayers[i].Name); SignedupPlayers[i].ReceiveChat(string.Format("LMS will start in {0} minutes", DateTime.Now == hourTime ? "60" : DateTime.Now == minuteTime ? "30" : DateTime.Now == fifteen ? "15" : "5"), ChatType.System); } } AnnounceCountDown(listedPlayers, DateTime.Now >= five && DateTime.Now <= five.AddSeconds(30)); } } if (Info.StartDay == 7 && DateTime.Now.Hour == Info.StartHour && DateTime.Now.Minute == Info.StartMinute && !Started && !tempStarted) { tempStarted = true; SMain.EnqueueDebugging(string.Format("[LMS BR] {0} Started at {1}:{2}", CurrentMap.Info.Title, Info.StartHour, Info.StartMinute)); Start_Match(); return; } else if ((byte)DateTime.Now.DayOfWeek == Info.StartDay && DateTime.Now.Hour == Info.StartHour && DateTime.Now.Minute == Info.StartMinute && !Started && !tempStarted) { tempStarted = true; SMain.EnqueueDebugging(string.Format("[LMS BR] {0} Started at {1}:{2} on {3}", CurrentMap.Info.Title, Info.StartHour, Info.StartMinute, (DayOfWeek)Info.StartDay)); Start_Match(); return; } else if (DateTime.Now.Hour != Info.StartHour && DateTime.Now.Minute != Info.StartMinute) { tempStarted = false; } if (Started && Stage < 4) { if (CurrentMap.Players.Count == 0) { End_Match(); return; } if (GetAlivePlayers() == 1) { End_Match(true); return; } else { if (Envir.Time >= NextRemainingPlayerMsgTime) { SMain.EnqueueDebugging(string.Format("[LMS BR] {0} {1}/{2} Players remaining", CurrentMap.Info.Title, PlayerCount, OriginalPlayercount)); NextRemainingPlayerMsgTime = Envir.Time + (Settings.Second * 90); BroadcastMessage(string.Format("{0}/{1} players remaining", PlayerCount, OriginalPlayercount), ChatType.Hint, 2); } if (Envir.Time >= NextMessageTime) { if (ShrinkTime - Settings.Second * 60 == Envir.Time) { NextMessageTime = Settings.Second * 11; long temp = ShrinkTime - Envir.Time; string remainingTime = Functions.PrintTimeSpanFromSeconds(temp / 1000); SMain.EnqueueDebugging(string.Format("[LMS BR] {0} Circle will Shrink in {1}", CurrentMap.Info.Title, remainingTime)); BroadcastMessage(string.Format("The circle will shrink in {0}", remainingTime), ChatType.Announcement, 2); } else if (ShrinkTime - Settings.Second * 30 == Envir.Time) { CreateInnerCircle(); NextMessageTime = Settings.Second * 11; long temp = ShrinkTime - Envir.Time; string remainingTime = Functions.PrintTimeSpanFromSeconds(temp / 1000); SMain.EnqueueDebugging(string.Format("[LMS BR] {0} Circle will Shrink in {1}", CurrentMap.Info.Title, remainingTime)); BroadcastMessage(string.Format("The circle will shrink in {0}", remainingTime), ChatType.Announcement, 2); } } if (Envir.Time >= ShrinkTime) { Stage++; float tempDuration = Info.Duration; switch (Stage) { case 1: ShrinkTime = Envir.Time + (long)(tempDuration / 4 * Settings.Minute); CurrentSize = (byte)(CurrentSize - (Info.StartingSize * 20 / 100)); break; case 2: CurrentSize = (byte)(CurrentSize - (Info.StartingSize * 20 / 100)); ShrinkTime = Envir.Time + (long)(tempDuration / 8 * Settings.Minute); break; case 3: CurrentSize = (byte)(CurrentSize - (Info.StartingSize * 20 / 100)); ShrinkTime = Envir.Time + (long)(tempDuration / 8 * Settings.Minute); break; } if (Stage < 4) { CreateCircle(CurrentSize); CreateInnerCircle(); NextMessageTime = ShrinkTime - Settings.Second * 60; long temp = ShrinkTime - Envir.Time; string remainingTime = Functions.PrintTimeSpanFromSeconds(temp / 1000); SMain.EnqueueDebugging(string.Format("[LMS BR] Circle will Shrink again in {0}", CurrentMap.Info.Title, remainingTime)); BroadcastMessage(string.Format("The circle will shrink again in {0}", remainingTime), ChatType.Announcement, 2); } } else { if (Envir.Time > NextDamageTime) { for (int i = 0; i < CurrentMap.Players.Count; i++) { if (!InLMSRange(CurrentMap.Players[i].CurrentLocation)) { if (CurrentMap.Players[i].Dead) { continue; } CurrentMap.Players[i].LMS_DamageAccumulator = CurrentMap.Players[i].LMS_DamageAccumulator == 0 ? -5 : CurrentMap.Players[i].LMS_DamageAccumulator * 2; CurrentMap.Players[i].LMS_InflictDamage(); } else if (CurrentMap.Players[i].LMS_DamageAccumulator != 0) { CurrentMap.Players[i].LMS_DamageAccumulator = 0; } } NextDamageTime = Envir.Time + Settings.Second; } } } } else if (Finished || Stage == 4) { End_Match(); } }