private bool OnPlacing(Player player, TankPacket packet, World world) { if (!player.Inventory.Find(packet.Tile, out _)) { return(false); } int x = packet.Pos3.X, y = packet.Pos3.Y, index = x + y * world.Width; var tile = Tile.Parse(packet.Tile); var block = world.Blocks[index]; if (tile.ActionType == 0x8) { return(false); } player.Inventory.Remove(tile.Id, 1); if (tile.ActionType == 18) { block.Bg = tile; } else { if (block.Fg.Id != 0) { return(false); } block.Fg = tile; } return(true); }
public void SendTankData(float[] tankData, uint objectId, uint id) { TankPacket packet = new TankPacket(); packet.payload = tankData; PacketManager.Instance.SendPacket(packet, objectId, packet.reliable, id); }
public static void ApplyDrop(Player player, World world, Vector2 pos, int item, float amount, bool fromPlayer) { if (fromPlayer) { if (!player.Inventory.Find(item, out var count)) { return; } if (count < amount) { return; } player.Inventory.Remove(item, (int)amount); player.Inventory.Modify(); } Random rand = new Random(); if (rand.Next(0, 2) == 0) { pos.X += rand.Next(0, 8); } else { pos.X -= rand.Next(0, 8); } if (rand.Next(0, 2) == 0) { pos.Y -= rand.Next(0, 5); } TankPacket packet = new TankPacket() { Type = 0xe, NetId = -1, Tile = item, Pos = pos }; byte[] data = packet.Pack(); Buffer.BlockCopy(BitConverter.GetBytes(amount), 0, data, 20, 4); player.Send(data); DroppedItem drop = new DroppedItem() { ItemId = item, Amount = (int)amount, Pos = pos }; world.DroppedItems.Add(world.DropId++, drop); world.Save(); }
private bool OnWrenching(Player player, TankPacket packet, World world) { int x = packet.Pos3.X, y = packet.Pos3.Y, index = x + y * world.Width; var block = world.Blocks[index]; return(false); }
public void Send(VariantList var, int id = -1, int delay = 0) { TankPacket tank = new TankPacket() { Type = 0x1, State = 0x8, NetId = id, Tile = delay, Size = var.Size, Data = var.SerializeToMemory() }; Send(tank); }
private bool OnPunching(TankPacket packet, World world) { int x = packet.Pos3.X, y = packet.Pos3.Y, index = x + y * world.Width; var now = DateTime.Now; var block = world.Blocks[index]; var tile = block.Fg.Id == 0 ? block.Bg : block.Fg; if (tile.Id == 0) { return(false); } packet.Type = packet.Tile = 0x8; if ((now - block.Info.BrokenTime).TotalSeconds >= tile.DropChance) { block.Info.BrokenCount = 2; } else if (block.Info.BrokenCount >= tile.BreakHits) { packet.Type = 0x3; packet.Tile = 18; block.Info.BrokenCount = 1; if (block.Fg.Id == 0) { block.Bg = Tile.Zero; } else { block.Fg = Tile.Zero; } } else { block.Info.BrokenCount++; } block.Info.BrokenTime = now; Parallel.ForEach(world.Players, ply => { ply.Send(packet); }); return(false); }
private static void SerializeItemDatabase() { SerializedItemData = File.ReadAllBytes("items.dat"); TankPacket tank = new TankPacket() { Type = 0x10, NetId = -1, State = 0x8, Size = SerializedItemData.Length, Data = SerializedItemData }; ItemData = tank.Pack(); ItemDataHash = HashData(SerializedItemData); }
void OnReceivePacket(ushort type, Stream stream) { switch (type) { case (ushort)UserPacketType.Player: TankPacket tankPacket = new TankPacket(); idReceived = tankPacket.Deserialize(stream); // cuando llega el paquete, utiliza las implementaciones de la clase base OnFinishDeserializing(SetTankTransformations, tankPacket.payload); break; //case (ushort)UserPacketType.Position: // PositionPacket positionPacket = new PositionPacket(); // positionPacket.Deserialize(stream); // transform.position = positionPacket.payload; // break; //case (ushort)UserPacketType.Rotation: // if (torretPivot == null) // torretPivot = transform.Find("TorretPivot").gameObject; // RotationPacket rotationPacket = new RotationPacket(); // rotationPacket.Deserialize(stream); // torretPivot.transform.rotation = rotationPacket.payload; // break; } }
public void SendPacket(Player player) { int size = 104 + (DroppedItems.Count * 16) + Width * Height * 20, length = Name.Length; TankPacket tank = new TankPacket() { Type = 0x4, State = 0x8, Size = size, Data = new byte[size] }; tank.Write(0x0f); tank.Write((short)0x0); tank.Write((short)length); tank.Write(Name); tank.Write(Width); tank.Write(Height); tank.Write(Width * Height); List <Block> blocks = new List <Block>(); foreach (var block in Blocks) { switch (block.Fg.ActionType) { case 0x11: { tank.Write((short)block.Fg.Id); tank.Write((short)block.Bg.Id); tank.Skip(4); break; } default: { tank.Write((short)0x0); tank.Write((short)block.Bg.Id); blocks.Add(block); tank.Skip(4); break; } } } tank.Write(DroppedItems.Count); tank.Write(DropId - 1); foreach (var drop in DroppedItems) { tank.Write((short)drop.Value.ItemId); tank.Write(drop.Value.Pos); tank.Write((short)drop.Value.Amount); tank.Write(drop.Key); } tank.Write(0x0); tank.Write(Weather); // weather player.Send(tank); foreach (var block in blocks) { TankPacket packet = new TankPacket() { Type = 0x3, Pos = new Vector2(block.Pos.X, (block.Pos.X + block.Pos.Y * Width) / Height), Pos3 = block.Pos, Tile = block.Fg.Id }; player.Send(packet); } }
private void OnTileActivated(Player player, World world, TankPacket packet) { var tile = Tile.Parse(packet.Tile); if (tile.ActionType == 20 || tile.ActionType == 107) { switch (tile.ClothingType) { case 0: { player.Clothes.Mask = player.Clothes.Mask == tile.Id ? 0 : tile.Id; } break; case 1: { player.Clothes.Shirt = player.Clothes.Shirt == tile.Id ? 0 : tile.Id; } break; case 2: { player.Clothes.Pants = player.Clothes.Pants == tile.Id ? 0 : tile.Id; } break; case 3: { player.Clothes.Feet = player.Clothes.Feet == tile.Id ? 0 : tile.Id; } break; case 4: { player.Clothes.Face = player.Clothes.Face == tile.Id ? 0 : tile.Id; } break; case 5: { player.Clothes.Hand = player.Clothes.Hand == tile.Id ? 0 : tile.Id; } break; case 6: { if (tile.ClothingType == 6) { player.Clothes.Back = player.Clothes.Back == tile.Id ? 0 : tile.Id; if (player.Clothes.Back != 0) { if (Tile.Parse(player.Clothes.Back).ItemKind == 4) { //player.State.InWings = true; } } //else player.State.InWings = false; } else { player.Clothes.Ances = player.Clothes.Ances == tile.Id ? 0 : tile.Id; } } break; case 7: { player.Clothes.Hair = player.Clothes.Hair == tile.Id ? 0 : tile.Id; } break; case 8: { player.Clothes.Neck = player.Clothes.Neck == tile.Id ? 0 : tile.Id; } break; } foreach (var a in world.Players) { player.SendClothes(a, true); } } else { return; } }
private void Handle(Player player, TankPacket packet, World world) { bool send = true; packet.NetId = player.NetId; switch (packet.Type) { case 0x0: { send = OnMoving(player, packet); break; } case 0x3: { send = packet.Tile switch { 18 => OnPunching(packet, world), 32 => OnWrenching(player, packet, world), _ => OnPlacing(player, packet, world), }; if (packet.Tile != 32) { world.Save(); } break; } case 0x7: { OnTileActivated(player, world, packet); break; } case 0xa: { break; } case 0xb: { Visual.ApplyCollect(player, world, packet.Tile, packet.Pos); break; } case 0x12: { break; } default: send = false; break; } if (send) { foreach (var ply in world.Players) { ply.Send(packet); } } }
private bool OnMoving(Player player, TankPacket packet) { player.Pos = packet.Pos; player.RotatingLeft = (packet.State & 0x10) != 0; return(true); }
public TankEvent(Player player, ENetPacket packet) { Handle(player, TankPacket.Unpack(packet.Data.ToArray()), Database.GetWorld(player.CurrentWorld).Result); }
public static void ApplyCollect(Player player, World world, int dropId, Vector2 position) { var newPos = new Vector2(Math.Abs(position.X - player.Pos.X), Math.Abs(position.Y - player.Pos.Y)); if (newPos.Y > 35 || newPos.X > 35) // checks { player.SendTalkBubble($"`0Too far away``"); return; } if (world.Blocks[(int)position.X / 32 + (int)position.Y / 32 * world.Width].Fg.CollisionType == 1) { return; } if (world.DroppedItems.TryGetValue(dropId, out var drop)) { TankPacket tank = new TankPacket() { Type = 0xe, NetId = player.NetId, Tile = dropId }; var tile = Tile.Parse(drop.ItemId); world.DroppedItems.Remove(dropId); if (drop.ItemId == 112) { player.Gems += drop.Amount; } else { if (player.Inventory.Add(drop.ItemId, drop.Amount)) { string text = "Collected `w" + drop.Amount + " " + tile.Name + "``."; if (tile.Rarity != 999) { text += " Rarity: `w" + tile.Rarity + "``"; } player.SendConsoleMessage(text); } else { if (player.Inventory.Find(drop.ItemId, out var a)) { int newAmount = 200 - a; int newDropAmount = drop.Amount - newAmount; ApplyDrop(player, world, drop.Pos, drop.ItemId, newDropAmount, false); string text = "Collected `w" + drop.Amount + " " + tile.Name + "``."; if (tile.Rarity != 999) { text += " Rarity: `w" + tile.Rarity + "``"; } player.Inventory.Add(drop.ItemId, newAmount); player.SendConsoleMessage(text); } } } foreach (var ply in world.Players) { ply.Send(tank); } world.Save(); } else { Console.WriteLine(dropId); player.SendTalkBubble("`0Too far away"); } }
public void Send(TankPacket tank) => Send(tank.Pack());