Esempio n. 1
0
        private static async Task SendPacket10(ENetPeer peer, PlayerMoving pMov)
        {
            DataItems def = new DataItems();
            var       t   = "";

            try
            {
                //itemDefs.ToList().ForEach(x => Console.WriteLine(x));
                var f = CoreData[pMov.PlantingTree].Split('|');
                def.ItemID = Convert.ToInt32(f[0]);
                def.Name   = f[1];
                t          = f[9];
            }
            catch (Exception e)
            {
                Console.WriteLine("Sendpacket10 error : " + e.Message);
            }

            var p  = peer.Data as Player;
            int id = pMov.PlantingTree;

            if (t.Contains("Hair"))
            {
                if ((peer.Data as Player).HairClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).HairClothes = 0;
                }
                else
                {
                    (peer.Data as Player).HairClothes = pMov.PlantingTree;
                }
            }
            else if (t.Contains("Shirt"))
            {
                if ((peer.Data as Player).ShirtClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).ShirtClothes = 0;
                }
                else
                {
                    (peer.Data as Player).ShirtClothes = pMov.PlantingTree;
                }
            }
            else if (t.Contains("Pants"))
            {
                if ((peer.Data as Player).PantsClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).PantsClothes = 0;
                }
                else
                {
                    (peer.Data as Player).PantsClothes = pMov.PlantingTree;
                }
            }
            else if (t.Contains("Feet"))
            {
                if ((peer.Data as Player).PantsClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).PantsClothes = 0;
                }
                else
                {
                    (peer.Data as Player).PantsClothes = pMov.PlantingTree;
                }
            }
            else if (t.Contains("Face"))
            {
                if ((peer.Data as Player).PantsClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).PantsClothes = 0;
                }
                else
                {
                    (peer.Data as Player).PantsClothes = pMov.PlantingTree;
                }
            }
            else if (t.Contains("Hand"))
            {
                if ((peer.Data as Player).HandClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).HandClothes = 0;
                }
                else
                {
                    (peer.Data as Player).HandClothes = pMov.PlantingTree;
                }
                int item = pMov.PlantingTree;
            }
            else if (t.Contains("Back"))
            {
                if ((peer.Data as Player).BackClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).BackClothes = 0;
                    (peer.Data as Player).InWings     = false;
                }
                else
                {
                    (peer.Data as Player).BackClothes = pMov.PlantingTree;
                    int item = pMov.PlantingTree;
                    if (def.Name.ToLower().Contains("wing") || def.Name.ToLower().Contains("cape") ||
                        def.Name.ToLower().Contains("aura") || def.Name.ToLower().Contains("dragon warrior's shield") ||
                        def.Name.ToLower().Contains("spirit"))
                    {
                        (peer.Data as Player).InWings = true;
                    }
                    await peer.SendState();

                    // ^^^^ wings
                }
            }
            else if (t.Contains("Mask"))
            {
                if ((peer.Data as Player).MaskClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).MaskClothes = 0;
                }
                else
                {
                    (peer.Data as Player).MaskClothes = pMov.PlantingTree;
                }
            }
            else if (t.Contains("Necklace"))
            {
                if ((peer.Data as Player).NecklaceClothes == pMov.PlantingTree)
                {
                    (peer.Data as Player).NecklaceClothes = 0;
                }
                else
                {
                    (peer.Data as Player).NecklaceClothes = pMov.PlantingTree;
                }
            }
            else
            {
                if (def.Name.ToLower().Contains("ances"))
                {
                    if ((peer.Data as Player).AncesClothes == pMov.PlantingTree)
                    {
                        (peer.Data as Player).AncesClothes = 0;
                    }
                    (peer.Data as Player).AncesClothes = pMov.PlantingTree;
                }
                else
                {
                    Console.WriteLine("Invalid item activated: " + pMov.PlantingTree + " by "
                                      + (peer.Data as Player).DisplayName);
                }
            }
            Peers.Where(x => x.InWorld(peer)).ToList().ForEach(async x => await x.SendSound("change_clothes.wav"));
            await peer.UpdateClothes();
        }
Esempio n. 2
0
        public static async Task SendTileUpdate(int x, int y, int tile, int causedBy, ENetPeer peer)
        {
            try
            {
                if (tile == 18)
                {
                    (peer.Data as Player).LastPunchX = x;
                    (peer.Data as Player).LastPunchY = y;
                }
                else if (tile == 32)
                {
                    (peer.Data as Player).LastWrenchX = x;
                    (peer.Data as Player).LastWrenchY = y;
                }
                PlayerMoving data = new PlayerMoving
                {
                    PacketType     = 0x3,
                    CharacterState = 0x0,
                    X            = x,
                    Y            = y,
                    PunchX       = x,
                    PunchY       = y,
                    XSpeed       = 0,
                    YSpeed       = 0,
                    NetID        = causedBy,
                    PlantingTree = tile
                };
                World world = (peer.Data as Player).PWorld;
                int   b     = world.Items[x + y * world.Width].Background;
                if (world == null)
                {
                    return;
                }
                if (x < 0 || y < 0 || x > world.Width || y > world.Height)
                {
                    return;
                }
                await SendNothingHappened(peer, x, y);

                if ((peer.Data as Player).AdminID < 666)
                {
                    if (world.Items[x + (y * world.Width)].Foreground == 6 || world.Items[x + (y * world.Width)].Foreground == 8 || world.Items[x + (y * world.Width)].Foreground == 3760)
                    {
                        return;
                    }
                    if (tile == 6 || tile == 8 || tile == 3760)
                    {
                        return;
                    }
                }
                if ((peer.Data as Player).RawName != world.OwnerName)
                {
                    if (world.Items[x + (y * world.Width)].Foreground == 242)
                    {
                        return;
                    }
                }
                if (world.Name == "ADMIN" && (peer.Data as Player).AdminID > 0)
                {
                    if (world.Items[x + (y * world.Width)].Foreground == 758)
                    {
                        await peer.SendRoulette();
                    }
                    return;
                }
                if (tile == 32 && world.Items[x + y * world.Width].Foreground == 6016)
                {
                    await SendGrowScanDialog(peer);
                }
                if (tile != 18 && tile != 32 && !ItemsData[tile].IsBackground && world.Items[x + (y * world.Width)].Foreground != 0)
                {
                    if (tile != 822)
                    { // allowed to place water on other blocks
                        await SendNothingHappened(peer, x, y);

                        return;
                    }
                }
                if (world.Name != "ADMIN")
                {
                    if (world.OwnerName != "")
                    {
                        int fg = world.Items[x + (y * world.Width)].Foreground;
                        if (world.OwnerName != "")
                        {
                            var p = peer.Data as Player;
                            if (!world.IsPublic)
                            {
                                if (p.RawName != world.OwnerName)
                                {
                                    await peer.OnPlayPositioned("audio/punch_locked.wav");

                                    await peer.SendSound("punch_locked.wav");

                                    if (ItemsData[fg].Name.ToLower().Contains("lock"))
                                    {
                                        await peer.OnConsoleMessage(world.OwnerName + "'s `9World Lock");
                                    }
                                }
                            }
                            else
                            {
                                if (p.RawName != world.OwnerName && ItemsData[fg].Name.ToLower().Contains("lock"))
                                {
                                    await peer.OnPlayPositioned("audio/punch_locked.wav");

                                    await peer.SendSound("punch_locked.wav");

                                    await peer.OnConsoleMessage(world.OwnerName + "'s World Lock `o(`$Open to Public`o)");
                                }
                            }
                        }
                        else if (world.IsPublic)
                        {
                            if (world.Items[x + (y * world.Width)].Foreground == 242)
                            {
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                if (tile == 32)
                {
                    // TODO
                    return;
                }
                DataItems def = new DataItems();
                try
                {
                    def = ItemsData[tile];
                }
                catch
                {
                    def.BreakHits = 4;
                }

                if (tile == 544 || tile == 546 || tile == 4520 || tile == 382 || tile == 3116 || tile == 4520 || tile == 1792 || tile == 5666 || tile == 2994 || tile == 4368)
                {
                    return;
                }
                if (tile == 5708 || tile == 5709 || tile == 5780 || tile == 5781 || tile == 5782 || tile == 5783 || tile == 5784 || tile == 5785 || tile == 5710 || tile == 5711 || tile == 5786 || tile == 5787 || tile == 5788 || tile == 5789 || tile == 5790 || tile == 5791 || tile == 6146 || tile == 6147 || tile == 6148 || tile == 6149 || tile == 6150 || tile == 6151 || tile == 6152 || tile == 6153 || tile == 5670 || tile == 5671 || tile == 5798 || tile == 5799 || tile == 5800 || tile == 5801 || tile == 5802 || tile == 5803 || tile == 5668 || tile == 5669 || tile == 5792 || tile == 5793 || tile == 5794 || tile == 5795 || tile == 5796 || tile == 5797 || tile == 544 || tile == 546 || tile == 4520 || tile == 382 || tile == 3116 || tile == 1792 || tile == 5666 || tile == 2994 || tile == 4368)
                {
                    return;
                }
                if (tile == 1902 || tile == 1508 || tile == 428)
                {
                    return;
                }
                if (tile == 1770 || tile == 4720 || tile == 4882 || tile == 6392 || tile == 3212 || tile == 1832 || tile == 4742 || tile == 3496 || tile == 3270 || tile == 4722 || tile == 6864)
                {
                    return;
                }
                if (tile >= 7068)
                {
                    return;
                }
                if (tile == 18)
                {
                    if (world.Items[x + (y * world.Width)].Background == 6864 && world.Items[x + (y * world.Width)].Foreground == 0)
                    {
                        return;
                    }
                    if (world.Items[x + (y * world.Width)].Background == 0 && world.Items[x + (y * world.Width)].Foreground == 0)
                    {
                        return;
                    }
                    //data.netID = -1;

                    data.PacketType   = 0x8;
                    data.PlantingTree = 4;
                    long time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                    //if (world->Items[x + (y*world->Width)].foreground == 0) return;
                    int a = world.Items[x + y * world.Width].Foreground;
                    if (time - world.Items[x + (y * world.Width)].BreakTime >= 4000)
                    {
                        world.Items[x + (y * world.Width)].BreakTime  = time;
                        world.Items[x + (y * world.Width)].BreakLevel = 6;
                        if (world.Items[x + (y * world.Width)].Foreground == 758)
                        {
                            await peer.SendRoulette();
                        }
                    }
                    else if (y < world.Height && world.Items[x + (y * world.Width)].BreakLevel + 6 >= ItemsData[a].BreakHits)
                    {
                        data.PacketType   = 0x3;
                        data.NetID        = -1;
                        data.PlantingTree = 18;
                        data.PunchX       = x;
                        data.PunchY       = y;
                        world.Items[x + (y * world.Width)].BreakLevel = 0;
                        int brokentile = world.Items[x + (y * world.Width)].Foreground;

                        if (world.Items[x + (y * world.Width)].Foreground != 0)
                        {
                            if (world.Items[x + (y * world.Width)].Foreground == 242)
                            {
                                world.OwnerName      = "";
                                world.IsPublic       = false;
                                world.AccessedPlayer = "";
                                foreach (var p in Peers)
                                {
                                    if (p.State != ENetPeerState.Connected)
                                    {
                                        continue;
                                    }
                                    await p.OnConsoleMessage("`oWorld `0" + world.Name + " `ohas had it's World Lock's removed!");
                                }
                            }
                            world.Items[x + y * world.Width].Foreground = 0;
                        }
                        else
                        {
                            world.Items[x + (y * world.Width)].Background = 0;
                        }
                    }
                    else
                    {
                        world.Items[x + (y * world.Width)].BreakTime   = time;
                        world.Items[x + (y * world.Width)].BreakLevel += 6; // TODO
                        if (world.Items[x + (y * world.Width)].Foreground == 758)
                        {
                            await peer.SendRoulette();
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < (peer.Data as Player).PlayerInventory.Items.Length; i++)
                    {
                        if ((peer.Data as Player).PlayerInventory.Items[i].ItemID == tile)
                        {
                            if ((uint)(peer.Data as Player).PlayerInventory.Items[i].ItemCount > 1)
                            {
                                (peer.Data as Player).PlayerInventory.Items[i].ItemCount--;
                            }
                            else
                            {
                                Array.Clear((peer.Data as Player).PlayerInventory.Items, i, 1);
                            }
                        }
                    }
                    if (ItemsData[tile].IsBackground)
                    {
                        world.Items[x + (y * world.Width)].Background = (short)tile;
                    }
                    if (world.Items[x + (y * world.Width)].Foreground != 0)
                    {
                        Console.WriteLine("return 11");
                        return;
                    }
                    else
                    {
                        int xx = data.PunchX;
                        int yy = data.PunchY;
                        foreach (ENetPeer currentPeer in Peers)
                        {
                            if (currentPeer.State != ENetPeerState.Connected)
                            {
                                continue;
                            }
                            if (peer.InWorld(currentPeer))
                            {
                                //dont allow to put consumbales
                                if (tile == 1368)
                                {
                                    return;
                                }
                                if (tile == 276)
                                {
                                    return;
                                }
                            }
                        }
                        world.Items[x + (y * world.Width)].Foreground = (short)tile;
                        if (tile == 242)
                        {
                            world.OwnerName  = (peer.Data as Player).RawName;
                            world.OwnerNetID = (peer.Data as Player).NetID;
                            world.IsPublic   = false;
                            await peer.OnPlayPositioned("audio/use_lock.wav");

                            await peer.SendSound("use_lock.wav");

                            foreach (ENetPeer currentPeer in Peers)
                            {
                                if (currentPeer.State != ENetPeerState.Connected)
                                {
                                    continue;
                                }
                                if (peer.InWorld(currentPeer))
                                {
                                    await currentPeer.OnConsoleMessage("`3[`w" + world.Name + " `ohas been World Locked by `2" + (peer.Data as Player).DisplayName + "`3]");
                                }
                            }
                        }
                    }

                    world.Items[x + (y * world.Width)].BreakLevel = 0;
                }
                Random r  = new Random();
                byte   xd = (byte)r.Next(1, 5);
                foreach (ENetPeer currentPeer in Peers)
                {
                    byte[] raw = PlayerMovingPack(data);
                    if (currentPeer.State != ENetPeerState.Connected)
                    {
                        continue;
                    }
                    if (peer.InWorld(currentPeer))
                    {
                        await SendPacketRaw(4, raw, 56, 0, currentPeer);
                    }
                    //cout << "Tile update at: " << data2->punchX << "x" << data2->punchY << endl;
                }
                // To save all the worlds DB (memory)
                await SaveOrAddWorldAsync(world);
            }
            catch (Exception e)
            {
                Console.WriteLine("error in async Task sendtileupdate");
                await peer.OnConsoleMessage(e.Message + " " + e.TargetSite + ",SOURCE : " + e.Source);
            }
        }