Exemple #1
0
        static void Main(string[] args)
        {
            cli = new EEUClient(GetClipboardText());         //get eeu token from clipboard
            cli.Connect();                                   //don't forget to connect

            Console.WriteLine(cli.SelfInfo.ToString());      //print info about self

            var lobby = cli.CreateLobbyConnection();         //get lobby

            Console.WriteLine(lobby.LoadStats().ToString()); //print lobby stats
            foreach (var room in lobby.LoadRooms())
            {                                                //print every room in lobby
                Console.WriteLine(room.ToString());
            }

            data           = new RoomData();
            con            = cli.CreateWorldConnection("worldid"); //connect to world
            con.OnMessage += OnMessage;
            con.ChatPrefix = "[ExampleBot] ";                      //change prefix for commands like Chat
            con.Init();

            List <BlockId> blockids = (Enum.GetValues(typeof(BlockId)) as BlockId[]).ToList();//get all BlockId values and store them in a list
            int            id       = 0;

            while (cli.Connected)
            {                       //fill world with incrementing ids
                Console.ReadLine(); //wait for enter key
                for (int i = 0; i < 3; i++)
                {
                    for (int y = 0; y < data.Height; y++)
                    {
                        for (int x = 0; x < data.Width; x++)
                        {                             //loop over world
                            var bid = blockids[id++]; //get next block in list
                            if (id >= blockids.Count)
                            {
                                id = 0;                             //loop over
                            }
                            var layer = bid.IsBackground() ? 0 : 1; //if block is bg, place it in bg layer
                            if (data.Blocks[layer, x, y].Id != (ushort)bid)
                            {
                                con.PlaceBlock(layer, x, y, bid);                                            //place block
                            }
                        }//for x,y
                    }
                    Thread.Sleep(1);//small delay
                }//for

                FillWorld(0, 1);//clear foreground layer
            }//while
            Console.WriteLine("not connected");
            Console.ReadLine();
        }
Exemple #2
0
 private static void FillWorld(int id, int layer)
 {
     for (int y = 0; y < data.Height; y++)
     {
         for (int x = 0; x < data.Width; x++)
         {
             if (data.Blocks[layer, x, y].Id == id)
             {
                 continue;                                   //skip placing if the block is already there
             }
             con.PlaceBlock(layer, x, y, id);
         }
     }
 }
Exemple #3
0
        //CountdownEvent ce = new CountdownEvent(1);
        private void OnMessage(object sender, EEUniverse.Library.Message m)
        {
            void die()
            {
                cli.Dispose(); panelMain.InvokeX(() => EnableMainPanel());
            }

            switch (m.Type)
            {
            case MessageType.Init:
                re.Set();
                if (m.GetString(7) != m.GetString(1))
                {
                    die();
                    MessageBox.Show("not world owner", ".w.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                world = new RoomData(parsePlayerData: false);
                world.Parse(m);
                int       ww = world.Width, wh = world.Height;
                Stopwatch s = Stopwatch.StartNew();
                //ce.Reset();
                Task.Run(() =>
                {
                    //void PlaceBlock(int layer, int x, int y, int id)
                    //{
                    //    ce.AddCount();
                    //    con.SendAsync(MessageType.PlaceBlock, layer, x, y, id).ContinueWith((_) => ce.Signal());
                    //}
                    for (int j = 0; j < imgh; j++)    //y
                    {
                        int yy = j + y;
                        if (yy >= wh)
                        {
                            break;                     //out of bounds
                        }
                        for (int i = 0; i < imgw; i++) //x
                        {
                            int xx = i + x;
                            if (xx >= ww)
                            {
                                break;              //out of bounds
                            }
                            int b = idgrid[i, j];
                            if (skiptransparent && b == (int)BlockId.Black)
                            {
                                continue;
                            }
                            int l = ((BlockId)b).IsBackground() ? 0 : 1;

                            if (world[l, xx, yy].Id != b)
                            {
                                con.PlaceBlock(l, xx, yy, b);
                            }
                            if (l == 0)
                            {
                                if (glass)
                                {
                                    if (world[1, xx, yy].Id != (int)BlockId.Clear)
                                    {
                                        con.PlaceBlock(1, xx, yy, (int)BlockId.Clear);
                                    }
                                }
                                else if (world[1, xx, yy].Id != 0)
                                {
                                    con.PlaceBlock(1, xx, yy, 0);
                                }
                            }
                            //else if (i == 1)
                            //{
                            //    PlaceBlock(0, xx, yy, 0);//get rid of bg behind fg
                            //}
                        }
                    }
                    //Console.WriteLine(s.Elapsed);

                    //ce.Signal();
                    //ce.Wait();
                    s.Stop();
                    Console.WriteLine(s.Elapsed);
                    die();
                });
                break;
            }
        }