public void CollectItem(byte id, Client collector) { Server.Send(new NetworkPacketRemoveItem(id), collector); collector.Send(new NetworkPacketCollectItem(id, GetRandomItem(collector))); CreateItem(id); }
public void CapturePig(Client client) { Pig.Captor = client.Leprechaun; Pig.Thrower = null; client.Send(new NetworkPacket(NetworkPacketTypes.CapturePig)); }
public void SendAll(Client client) { lock (this) { foreach (Trap trap in trapList) client.Send(new NetworkPacketAddTrap(trap)); } }
public void OnClientFinish(Client client) { if (Pig.Captor == client.Leprechaun) Pig.Captor = null; if (Pig.Thrower == client.Leprechaun) Pig.Thrower = null; }
public void CheckItemCollected(Client client) { lock (this) { for (byte id = 0; id < items.Length; ++id) if (client.Leprechaun.Intersects(items[id])) CollectItem(id, client); } }
public Leprechaun(Client client) : base(Config.LeprechaunCylinderRadius, Config.LeprechaunCylinderHeight) { Client = client; Hat = new Hat(); Cane = new Cane(); IsStunned = false; IsFlying = false; IsInvulnerable = false; RainbowProgress = 0; }
public Server() { Clients = new ConcurrentDictionary<byte, Client>(Config.MaxPlayers + 1, Config.MaxPlayers); Terrain = new Terrain(); VegetationManager = new VegetationManager(Terrain); ItemsManager = new ItemsManager(this); PigAI = new PigAI(this); MushroomAI = new MushroomAI(this); TrapManager = new TrapManager(); try { var server = new Socket(AddressFamily.Unspecified, Config.SocketType, Config.ProtocolType); server.Bind(new IPEndPoint(IPAddress.Any, Config.Port)); server.Listen(Config.Backlog); Console.WriteLine("Server started. Waiting for Clients..."); new Thread(PigAI.Start).Start(); new Thread(MushroomAI.Start).Start(); while (true) { Socket socket = server.Accept(); byte playerId = 0; while (Clients.Keys.Contains(playerId)) playerId++; if (playerId > Config.MaxPlayers) continue; var newClient = new Client(this, socket, playerId); foreach (Client client in Clients.Values) newClient.Send(new NetworkPacketAddPlayer(client.PlayerId, Config.PlayerColors[client.PlayerId], Config.RainbowPositions[client.PlayerId])); Send(new NetworkPacketAddPlayer(newClient.PlayerId, Config.PlayerColors[newClient.PlayerId], Config.RainbowPositions[newClient.PlayerId])); while (!Clients.TryAdd(playerId, newClient)) Thread.Sleep(1); new Thread(newClient.Start).Start(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
public void OnClientFinish(Client client) { lock (this) { foreach (Mushroom mushroom in Mushrooms) { if (mushroom.Target == client.Leprechaun) mushroom.Target = null; if (mushroom.Owner == client.Leprechaun) mushroom.Owner = null; } } }
public void OnClientFinish(Server server, Client client) { lock (this) { int i = 0; while (i < trapList.Count) { if (trapList[i].PlayerId == client.PlayerId) trapList.RemoveAt(i); else ++i; } playerTrapIdPool.Remove(client.PlayerId); } }
private Flags.ItemTypes GetRandomItem(Client collector) { int position = 0; foreach (Client client in Server.GetClientList().OrderByDescending(c => c.Leprechaun.RainbowProgress)) { if (client == collector) break; position++; } float specialProbability = Config.ItemsSpecialItemProbability[position] / 100.0f; float pigRobberyProb = specialProbability * Config.ItemsProbabilityFactorPigRobbery; float invulnerabilityProb = specialProbability - pigRobberyProb; float[] propabilities = new float[(int)Flags.ItemTypes.Count]; float propabilityPerNormalItem = (1.0f - specialProbability) / (propabilities.Length - 3); propabilities[0] = 0; for (int i = 1; i < propabilities.Length - 2; ++i) propabilities[i] = propabilities[i-1] + propabilityPerNormalItem; propabilities[propabilities.Length - 2] = propabilities[propabilities.Length - 3] + invulnerabilityProb; propabilities[propabilities.Length - 1] = 1.0f; float r = (float)random.NextDouble(); Flags.ItemTypes item = 0; for (int i = 1; i < propabilities.Length; ++i) { if (r <= propabilities[i]) { item = (Flags.ItemTypes)i; break; } } return item; }
public void SendAll(Client client) { for (byte id = 0; id < items.Length; ++id) if (items[id] != null) client.Send(new NetworkPacketAddItem(id, items[id])); }
public void AddPlayer(Client client) { playerTrapIdPool.Add(client.PlayerId, 0); SendAll(client); }
public void ThrowPig(Client client) { if (!Pig.IsCaught) return; lock (this) { Pig.Velocity = (Pig.Captor.GetForward() + Vector3.Up) * Config.PigThrowPower; Pig.Rotation = Pig.Captor.Rotation * Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.ToRadians(-90)) * Quaternion.CreateFromAxisAngle(-Vector3.Forward, MathHelper.ToRadians(180)); Pig.Thrower = Pig.Captor; DropPig(); } client.Send(new NetworkPacket(NetworkPacketTypes.DropPig)); }
public void Send(NetworkPacket packet, Client sender = null) { foreach (Client client in GetClientList(sender)) client.Send(packet); }
public void OnClientFinish(Client client) { Client outClient; while (!Clients.TryRemove(client.PlayerId, out outClient)) Thread.Sleep(1); Send(new NetworkPacketRemovePlayer(client.PlayerId), client); MushroomAI.OnClientFinish(client); PigAI.OnClientFinish(client); TrapManager.OnClientFinish(this, client); }
public List<Client> GetClientList(Client sender = null) { return Clients.Values.Where(client => client != sender).ToList(); }