Exemple #1
0
 public void Change_pos()    // Вызов метода происходит когда персонаж переходит в другую комнату
 {
     Calc_pos();
     all_room = GameObject.FindGameObjectsWithTag("Room"); // Берем все комнаты
     foreach (var room in all_room)                        // Ищем нужную
     {
         if ((room.transform.position.y == curent_ch_position.y) && (room.transform.position.x == curent_ch_position.x))
         {
             curent_room = room;
             break;
         }
     }
     curent_Room_info = curent_room.GetComponent <Room_info> ();
     if (!curent_Room_info.cleared)
     {
         curent_Room_info.Close_door();
         if ((curent_Room_info.room_name == "Monster_room") || ((curent_Room_info.room_name == "Boss_room")))
         {
             curent_Room_info.Enable_monsters();
         }
         if (curent_Room_info.room_name == "Boss_room")
         {
             s_m.Boss_track(true);
         }
     }
 }
Exemple #2
0
        public void CheckPassword(NetworkStream Stream)
        {
            string message = "l";
            var    json    = new TextOperations().ReadRoom_info(Stream, message);
            var    d       = Listener.Rooms.Find(e => e.name.Equals(json.name));

            if (d.password.Equals(json.password))
            {
                var g = new Room_info()
                {
                    name = json.name, password = "******"
                };
                var SJson = JsonConvert.SerializeObject(g);
                var msg   = "?PAS?" + SJson + "?END";
                msg = msg.Length + msg;
                byte[] bmsg = System.Text.Encoding.UTF8.GetBytes(msg);
                Stream.Write(bmsg, 0, bmsg.Length);
            }
            else
            {
                var g = new Room_info()
                {
                    name = json.name, password = "******"
                };
                var SJson = JsonConvert.SerializeObject(g);
                var msg   = "?PAS?" + SJson + "?END";
                msg = msg.Length + msg;
                byte[] bmsg = System.Text.Encoding.UTF8.GetBytes(msg);
                Stream.Write(bmsg, 0, bmsg.Length);
            }
        }
Exemple #3
0
        static public void StartListener()
        {
            if (File.Exists("Server.config"))
            {
                var a = File.ReadAllText("server.config");
                config = JsonConvert.DeserializeObject <Dictionary <string, string> >(a);
                Console.WriteLine("Server.config loaded...");
            }
            else
            {
                Console.WriteLine("Creating server.config");
                config.Add("IP", "127.0.0.1");
                config.Add("Port", "8000");
                config.Add("DB-server", "");
                config.Add("DB-name", "");
                config.Add("DB-User-id", "");
                config.Add("DB-Password", "");
                config.Add("Allow-room-Creation", "true");
                File.WriteAllText("server.config", JsonConvert.SerializeObject(config));
                Console.WriteLine("server.config created...");
            }
            var       db   = new DBConnect(config);
            Room_info Main = new Room_info()
            {
                id = 0, name = "Main", RoomCreator = null
            };

            Rooms.Add(Main);
            IPHostEntry HostIp = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress   ip     = IPAddress.Parse(config["IP"]);

            try
            {
                listen = new TcpListener(ip, 8000);
                Console.WriteLine("Listener Started at " + ip.ToString());

                listen.Start();
            }catch (System.Net.Sockets.SocketException e)
            {
                Console.WriteLine(e);
            }
            try
            {
                while (true)
                {
                    TcpClient client = listen.AcceptTcpClient();
                    Task.Factory.StartNew(() =>
                    {
                        HandleUser.HandleUserStart(client);
                    });
                    id++;
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
                listen.Stop();
            }
        }
Exemple #4
0
 public void RoomChanger(User changer, Room_info OldRoom, Room_info NewRoom)
 {
     OldRoom.UserList.Remove(changer);
     NewRoom.UserList.Add(changer);
     changer.SetRoomID(NewRoom.id);
     GlobalMessage.SendUserList();
     new Room_info().Check(OldRoom.id);
     changer.SendMessage("SSG?", "You are chatting at: " + NewRoom.name);
     Task.Factory.StartNew(() =>
     {
         new Logs().saveLogs(DateTime.UtcNow + changer.Name + " Changed room to " + NewRoom.name);
     });
 }
Exemple #5
0
 public void CreateRoom(NetworkStream Stream, User oUser, string info)
 {
     try
     {
         var       d    = new TextOperations().ReadRoom_info(Stream, info);
         Room_info room = new Room_info();
         room.Create(d.name, oUser, d.isPassword, d.password);
     }
     catch (IOException)
     {
         GlobalMessage.UserDisconnected(oUser);
     }
     catch (ObjectDisposedException)
     {
         GlobalMessage.UserDisconnected(oUser);
     }
     catch (System.ArgumentOutOfRangeException) { }
     catch (System.NullReferenceException) { }
 }
Exemple #6
0
    //TODO improve the looks of this function
    void buildPaths()
    {
        Vector3 startPoint, endPoint, curPoint, midS, midE;
        bool    flag;
        float   xS, yS, xM, yM, xE, yE;

        for (int i = 1; i < AllStayingRooms.Count; i++)
        {
            Room_info r1   = stayingRoomArray[i];
            Room_info r2   = stayingRoomArray[ansMST[i, 0]];
            Transform pos1 = r1.room.transform;
            Transform pos2 = r2.room.transform;
            float     X1   = pos1.position.x;
            float     X2   = pos2.position.x;
            float     Y1   = pos1.position.y;
            float     Y2   = pos2.position.y;
            //offset = 1;
            flag = false;
            midS = midE = new Vector3(0, 0, 0);
            // contains repetitive code, which should be fixed later
            if ((X2 - (r2.width / 2) + offset) >= (X1 - (r1.width / 2) + offset) && (X2 - (r2.width / 2) + offset) <= (X1 + (r1.width / 2) - offset) || (X1 - (r1.width / 2) + offset) >= (X2 - (r2.width / 2) + offset) && (X1 - (r1.width / 2) + offset) <= (X2 + (r2.width / 2) - offset))
            {
                if ((X2 - (r2.width / 2) + offset) >= (X1 - (r1.width / 2) + offset) && (X2 + (r2.width / 2) - offset) <= (X1 + (r1.width / 2) - offset))
                {
                    xS = xE = (int)Random.Range((X2 - (r2.width / 2) + offset), (X2 + (r2.width / 2) - offset));
                }
                else if ((X1 - (r1.width / 2) + offset) >= (X2 - (r2.width / 2) + offset) && (X1 + (r1.width / 2) - offset) <= (X2 + (r2.width / 2) - offset))
                {
                    xS = xE = (int)Random.Range((X1 - (r1.width / 2) + offset), (X1 + (r1.width / 2) - offset));
                }
                else if ((X2 - (r2.width / 2) + offset) >= (X1 - (r1.width / 2) + offset) && (X2 - (r2.width / 2) + offset) <= (X1 + (r1.width / 2) - offset))
                {
                    xS = xE = (int)Random.Range((X2 - (r2.width / 2) + offset), (X1 + (r1.width / 2) - offset));
                }
                else
                {
                    xS = xE = (int)Random.Range(X1 - (r1.width / 2) + offset, (X2 + (r2.width / 2) - offset));
                }
                if (Y1 > Y2)
                {
                    yS = Y1 - (r1.height / 2) - 1;
                    yE = Y2 + (r2.height / 2);
                }
                else
                {
                    yS = Y1 + (r1.height / 2);
                    yE = Y2 - (r2.height / 2) - 1;
                }
            }
            else if ((X2 + (r2.width / 2) - offset) >= (X1 - (r1.width / 2) + offset) && (X2 + (r2.width / 2) - offset) <= (X1 + (r1.width / 2) - offset) || (X1 + (r1.width / 2) - offset) >= (X2 - (r2.width / 2) + offset) && (X1 + (r1.width / 2) - offset) <= (X2 + (r2.width / 2) - offset))
            {
                if ((X2 - (r2.width / 2) + offset) >= (X1 - (r1.width / 2) + offset) && (X2 + (r2.width / 2) - offset) <= (X1 + (r1.width / 2) - offset))
                {
                    xS = xE = (int)Random.Range((X2 - (r2.width / 2) + offset), (X2 + (r2.width / 2) - offset));
                }
                else if ((X1 - (r1.width / 2) + offset) >= (X2 - (r2.width / 2) + offset) && (X1 + (r1.width / 2) - offset) <= (X2 + (r2.width / 2) - offset))
                {
                    xS = xE = (int)Random.Range((X1 - (r1.width / 2) + offset), (X1 + (r1.width / 2) - offset));
                }
                else if ((X2 + (r2.width / 2) - offset) >= (X1 - (r1.width / 2) + offset) && (X2 + (r2.width / 2) - offset) <= (X1 + (r1.width / 2) - offset))
                {
                    xS = xE = (int)Random.Range((X1 - (r1.width / 2) + offset), (X2 + (r2.width / 2) - offset));
                }
                else
                {
                    xS = xE = (int)Random.Range((X2 - (r2.width / 2) + offset), (X1 + (r2.width / 2) - offset));
                }
                if (Y1 > Y2)
                {
                    yS = Y1 - (r1.height / 2) - 1;
                    yE = Y2 + (r2.height / 2);
                }
                else
                {
                    yS = Y1 + (r1.height / 2);
                    yE = Y2 - (r2.height / 2) - 1;
                }
            }
            else if ((Y2 - (r2.height / 2) + offset) >= (Y1 - (r1.height / 2) + offset) && (Y2 - (r2.height / 2) + offset) <= (Y1 + (r1.height / 2) - offset) || (Y1 - (r1.height / 2) + offset) >= (Y2 - (r2.height / 2) + offset) && (Y1 - (r1.height / 2) + offset) <= (Y2 + (r2.height / 2) - offset))
            {
                if ((Y2 - (r2.height / 2) + offset) >= (Y1 - (r1.height / 2) + offset) && (Y2 + (r2.height / 2) - offset) <= (Y1 + (r1.height / 2) - offset))
                {
                    yS = yE = (int)Random.Range((Y2 - (r2.height / 2) + offset), (Y2 + (r2.height / 2) - offset));
                }
                else if ((Y1 - (r1.height / 2) + offset) >= (Y2 - (r2.height / 2) + offset) && (Y1 + (r1.height / 2) - offset) <= (Y2 + (r2.height / 2) - offset))
                {
                    yS = yE = (int)Random.Range((Y1 - (r1.height / 2) + offset), (Y1 + (r1.height / 2) - offset));
                }
                else if ((Y2 - (r2.height / 2) + offset) >= (Y1 - (r1.height / 2) + offset) && (Y2 - (r2.height / 2) + offset) <= (Y1 + (r1.height / 2) - offset))
                {
                    yS = yE = (int)Random.Range((Y2 - (r2.height / 2) + offset), (Y1 + (r1.height / 2) - offset));
                }
                else
                {
                    yS = yE = (int)Random.Range((Y1 - (r1.height / 2) + offset), (Y2 + (r2.height / 2) - offset));
                }
                if (X1 > X2)
                {
                    xS = X1 - (r1.width / 2) - 1;
                    xE = X2 + (r2.width / 2);
                }
                else
                {
                    xS = X1 + (r1.width / 2);
                    xE = X2 - (r2.width / 2) - 1;
                }
            }
            else if ((Y2 + (r2.height / 2) - offset) >= (Y1 - (r1.height / 2) + offset) && (Y2 + (r2.height / 2) - offset) <= (Y1 + (r1.height / 2) - offset) || (Y1 + (r1.height / 2) - offset) >= (Y2 - (r2.height / 2) + offset) && (Y1 + (r1.height / 2) - offset) <= (Y2 + (r2.height / 2) - offset))
            {
                if ((Y2 - (r2.height / 2) + offset) >= (Y1 - (r1.height / 2) + offset) && (Y2 + (r2.height / 2) - offset) <= (Y1 + (r1.height / 2) - offset))
                {
                    yS = yE = (int)Random.Range((Y2 - (r2.height / 2) + offset), (Y2 + (r2.height / 2) - offset));
                }
                else if ((Y1 - (r1.height / 2) + offset) >= (Y2 - (r2.height / 2) + offset) && (Y1 + (r1.height / 2) - offset) <= (Y2 + (r2.height / 2) - offset))
                {
                    yS = yE = (int)Random.Range((Y1 - (r1.height / 2) + offset), (Y1 + (r1.height / 2) - offset));
                }
                else if ((Y2 + (r2.height / 2) - offset) >= (Y1 - (r1.height / 2) + offset) && (Y2 + (r2.height / 2) - offset) <= (Y1 + (r1.height / 2) - offset))
                {
                    yS = yE = (int)Random.Range((Y1 - (r1.height / 2) + offset), (Y2 + (r2.height / 2) - offset));
                }
                else
                {
                    yS = yE = (int)Random.Range((Y2 - (r2.height / 2) + offset), (Y1 + (r1.height / 2) - offset));
                }
                if (X1 > X2)
                {
                    xS = X1 - (r1.width / 2) - 1;
                    xE = X2 + (r2.width / 2);
                }
                else
                {
                    xS = X1 + (r1.width / 2);
                    xE = X2 - (r2.width / 2) - 1;
                }
            }
            else
            {
                flag = true;
                if (X1 > X2 && Y1 > Y2)
                {
                    xS = X1 - (r1.width / 2) + 2;
                    xE = X2 + (r2.width / 2);
                    yS = Y1 - (r1.height / 2) - 1;
                    yE = Y2 + (r2.height / 2) - 1 - 2;
                    TM1.SetTile(new Vector3Int((int)xS, (int)yS - 1, 0), t1);
                    TM1.SetTile(new Vector3Int((int)xE + 1, (int)yE, 0), t1);
                    midS = new Vector3(xS, yS - 2, 0);
                    midE = new Vector3(xE + 2, yE, 0);
                }
                else if ((X1 > X2 && Y1 < Y2))
                {
                    xS = X1 - (r1.width / 2) + 2;
                    xE = X2 + (r2.width / 2);
                    yS = Y1 + (r1.height / 2);
                    yE = Y2 - (r2.height / 2) + 2;
                    TM1.SetTile(new Vector3Int((int)xS, (int)yS + 1, 0), t1);
                    TM1.SetTile(new Vector3Int((int)xE + 1, (int)yE, 0), t1);
                    midS = new Vector3(xS, yS + 2, 0);
                    midE = new Vector3(xE + 2, yE, 0);
                }
                else if ((X1 < X2 && Y1 > Y2))
                {
                    xS = X1 + (r1.width / 2);
                    xE = X2 - (r2.width / 2) + 2;
                    yS = Y1 - (r1.height / 2) + 2;
                    yE = Y2 + (r2.height / 2);
                    TM1.SetTile(new Vector3Int((int)xS + 1, (int)yS, 0), t1);
                    TM1.SetTile(new Vector3Int((int)xE, (int)yE + 1, 0), t1);
                    midS = new Vector3(xS + 2, yS, 0);
                    midE = new Vector3(xE, yE + 2, 0);
                }
                else
                {
                    xS = X1 + (r1.width / 2);
                    xE = X2 - (r2.width / 2) + 2;
                    yS = Y1 + (r1.height / 2) - 1 - 2;
                    yE = Y2 - (r2.height / 2) - 1;
                    TM1.SetTile(new Vector3Int((int)xS + 1, (int)yS, 0), t1);
                    TM1.SetTile(new Vector3Int((int)xE, (int)yE - 1, 0), t1);
                    midS = new Vector3(xS + 2, yS, 0);
                    midE = new Vector3(xE, yE - 2, 0);
                }
            }

            startPoint = new Vector3(xS, yS, 0);
            endPoint   = new Vector3(xE, yE, 0);

            if (!RoomDoorCords.Contains(startPoint))
            {
                RoomDoorCords.Add(startPoint);
            }
            if (!RoomDoorCords.Contains(endPoint))
            {
                RoomDoorCords.Add(endPoint);
            }
            if (flag == true)
            {
                startPoint = midS;
                endPoint   = midE;
            }

            curPoint = startPoint;
            TM1.SetTile(new Vector3Int((int)curPoint.x, (int)curPoint.y, 0), t1);
            while (curPoint != endPoint)
            {
                if (curPoint.x == endPoint.x)
                {
                    if (curPoint.y < endPoint.y)
                    {
                        curPoint.y += 1;
                    }
                    else
                    {
                        curPoint.y -= 1;
                    }
                }
                else if (curPoint.y == endPoint.y)
                {
                    if (curPoint.x < endPoint.x)
                    {
                        curPoint.x += 1;
                    }
                    else
                    {
                        curPoint.x -= 1;
                    }
                }
                else if (curPoint.x != endPoint.x && curPoint.y != endPoint.y)
                {
                    //if((endPoint.y - startPoint.y) < (endPoint.x - startPoint.x))
                    if ((endPoint.x - startPoint.x) > 0)
                    {
                        if (curPoint.y < endPoint.y)
                        {
                            curPoint.y += 1;
                        }
                        else
                        {
                            curPoint.y -= 1;
                        }
                    }
                    else
                    {
                        if (curPoint.x < endPoint.x)
                        {
                            curPoint.x += 1;
                        }
                        else
                        {
                            curPoint.x -= 1;
                        }
                    }
                }
                TM1.SetTile(new Vector3Int((int)curPoint.x, (int)curPoint.y, 0), t1);

                if (curPoint == endPoint)
                {
                    break;
                }
                else
                {
                    TM1.SetTile(new Vector3Int((int)curPoint.x, (int)curPoint.y, 0), t1);
                }
            }
            Debug.DrawLine(new Vector3(pos1.position.x, pos1.position.y, pos1.position.z),
                           new Vector3(pos2.position.x, pos2.position.y, pos2.position.z), Color.green, 2000f, true);

            /*
             * Debug.DrawLine(new Vector3(startPoint.x, startPoint.y, startPoint.z),
             *  new Vector3(midPoint.x, midPoint.y, midPoint.z), Color.yellow, 2000f, true);
             * Debug.DrawLine(new Vector3(endPoint.x, endPoint.y, endPoint.z),
             *  new Vector3(midPoint.x, midPoint.y, midPoint.z), Color.blue, 2000f, true);
             */
            /*
             * Debug.DrawLine(new Vector3(pos1.position.x, pos1.position.y, pos1.position.z),
             *  new Vector3(midPoint.x, midPoint.y, midPoint.z), Color.yellow, 2000f, true);
             * Debug.DrawLine(new Vector3(pos2.position.x, pos2.position.y, pos2.position.z),
             *  new Vector3(midPoint.x, midPoint.y, midPoint.z), Color.blue, 2000f, true);
             */
            Debug.DrawLine(new Vector3(startPoint.x, startPoint.y, startPoint.z),
                           new Vector3(endPoint.x, endPoint.y, endPoint.z), Color.yellow, 2000f, true);
        }
        buildWalls();
    }