Пример #1
0
        //konstruktor gracza
        public Player(ulong _id, TcpClient userClient)
        {
            //ustawienie identyfikatora gracza
            id = _id;

            //wczytanie ustawień dla połączenia z serwerem
            host = Properties.Settings.Default.Host;
            port = Properties.Settings.Default.Port;

            //inicjalizacja gniazda połączenia z serwerem
            try
            {
                client = userClient;
                code = new UTF8Encoding();
                Command request = new Command(ClientCmd.GET_PLAYER_DATA);
                request.Add(id.ToString());
                
                string[] dane = request.Send(client.Client, true);

                if (dane[0] == ServerCmd.PLAYER_DATA)
                {
                    login = dane[1];
                    password = dane[2];
                    access = int.Parse(dane[3]);
                    email = dane[4];
                }
            }
            catch
            {
                //obsługa wyjątku
            }
        }
Пример #2
0
        //konstruktor
        public Enemies(uint location, TcpClient clientTcp)
        {
            client = clientTcp.Client;

            //odpyta bazke o moby dla danej lokaclizacji
            Command command = new Command();
            command.Request(ClientCmd.GET_ENEMIES);
            command.Add(location.ToString());
            string[] result = command.Send(client, true);

            if (result[0] == ServerCmd.ENEMIES)
            {
                mobsCount = uint.Parse(result[1]);

                for (int i = 2; i < result.Length; i += 11)
                {
                    Mob mb = new Mob(
                                ulong.Parse(result[i]),
                                (result[i + 1]),
                                uint.Parse(result[i + 2]),
                                ulong.Parse(result[i + 3]),
                                uint.Parse(result[i + 4]),
                                uint.Parse(result[i + 5]),
                                uint.Parse(result[i + 6]),
                                uint.Parse(result[i + 7]),
                                uint.Parse(result[i + 8]),
                                uint.Parse(result[i + 9]),
                                (result[i + 10])
                                );

                    enemiesList.Add(mb);
                }
            }
        }
Пример #3
0
 private uint GetShortestPath()
 {
     string[] result;
     Command request = new Command();
     request.Request(ClientCmd.GET_SHORTEST_PATH);
     request.Add(currentLocation.ToString());
     request.Add(city.Id.ToString());
     result = request.Send(socket, true);
     return uint.Parse(result[1]);
 }
Пример #4
0
        public CharacterEquipment(ulong characterId, TcpClient clientTcp)
        {
            id = characterId;
            client = clientTcp.Client;

            Command command = new Command();
            command.Request(ClientCmd.GET_CHARACTER_EQUIPMENT);
            command.Add(id.ToString());
            string[] dane = command.Send(client, true);

            if (dane[0] == ServerCmd.CHARACTER_EQUIPMENT)
            {
                head = uint.Parse(dane[1]);
                chest = uint.Parse(dane[2]);
                legs = uint.Parse(dane[3]);
                weapon = uint.Parse(dane[4]);
                shield = uint.Parse(dane[5]);
            }
        }
Пример #5
0
        public Character(ulong characterId, TcpClient clientTcp)
        {
            client = clientTcp.Client;
            id = characterId;

            Command command = new Command();
            command.Request(ClientCmd.GET_CHARACTER_DATA);
            command.Add(id.ToString());
            string[] dane = command.Send(client, true);

            if (dane[0] == ServerCmd.CHARACTER_DATA)
            {
                name = dane[1];
                level = uint.Parse(dane[2]);
                exp = uint.Parse(dane[3]);
                gold = uint.Parse(dane[4]);
                strength = uint.Parse(dane[5]);
                stamina = uint.Parse(dane[6]);
                dexterity = uint.Parse(dane[7]);
                luck = uint.Parse(dane[8]);

                status = dane[9];
                lastDamage = UInt64.Parse(dane[10]);
                damage = UInt64.Parse(dane[11]);
                lastFatigue = UInt64.Parse(dane[12]);
                fatigue = UInt64.Parse(dane[13]);
                
                location = uint.Parse(dane[14]);
                travelEndTime = UInt64.Parse(dane[15]);
                travelDestination = UInt32.Parse(dane[16]);
            }
            equip = new CharacterEquipment(id, clientTcp);
            storage = new CharacterStorage(id, clientTcp);
            pointRegenerationTime = 30;
            fullRegenerationTime = 15 * 60;
            //przykładowa zmiana imienia postaci
            //this.Name = "updateTest";
        }
Пример #6
0
        public ItemsWeapon(TcpClient client)
        {
            weaponsList = new List<Weapon>();
            socket = client.Client;
            string[] result;

            Command request = new Command();
            request.Request(ClientCmd.GET_ITEMS_WEAPONS);
            result = request.Send(socket, true);

            if (result[0] == ServerCmd.WEAPONS)
            {
                for (int i = 1; i < result.Length; i += 10)
                {
                    Weapon weapon = new Weapon(
                        uint.Parse(result[i]),
                        result[i+1],
                        uint.Parse(result[i+2]),
                        result[i+3],
                        uint.Parse(result[i+4]),
                        uint.Parse(result[i+5]),
                        uint.Parse(result[i+6]),
                        uint.Parse(result[i+7]),
                        uint.Parse(result[i+8]),
                        uint.Parse(result[i+9])
                        );
                    weaponsList.Add(weapon);
                }
            }
        }
Пример #7
0
        public ItemsArmor(TcpClient client)
        {
            armorsList = new List<Armor>();
            socket = client.Client;
            string[] result;

            Command request = new Command();
            request.Request(ClientCmd.GET_ITEMS_ARMORS);
            result = request.Send(socket, true);

            if (result[0] == ServerCmd.ARMORS)
            {
                for (int i = 1; i < result.Length; i += 10)
                {
                    Armor armor = new Armor(
                        uint.Parse(result[i]),
                        result[i+1],
                        uint.Parse(result[i+2]),
                        result[i+3],
                        result[i+4],
                        uint.Parse(result[i+5]),
                        uint.Parse(result[i+6]),
                        uint.Parse(result[i+7]),
                        uint.Parse(result[i+8]),
                        uint.Parse(result[i+9])
                        );
                    armorsList.Add(armor);
                }
            }
        }
Пример #8
0
 public void SetAmount(uint amount, Socket socket)
 {
     this.amount = amount;
     Command command = new Command();
     //ustawienie żądania uaktualnienia bazy danych
     command.Request(ClientCmd.UPDATE_DATA_BASE);
     //w tabeli character
     command.Add("character_storage");
     //pola name
     command.Add("amount");
     //na wartość updateTest
     command.Add(amount.ToString());
     //gdzie wartość pola id
     command.Add("id");
     //jest równa identyfikatorowi gracza
     command.Add(this.CharacterId.ToString() + " AND `character_storage`.`id_item` = " + this.CharacterId);
     //uaktualnij i nie czekaj na odpowiedź
     command.Send(socket, false);
 }
Пример #9
0
        public void AddItem(uint itemId, uint amount = 1)
        {
            Storage position = storage.Find(pos => pos.ItemId == itemId);

            if (position == null)
            {
                storage.Add(new Storage(this.id, itemId, amount));
            }
            else
            {
                position.Amount += amount;
            }

            Command request = new Command();
            request.Request(ClientCmd.ADD_ITEM);
            request.Add(itemId.ToString());
            request.Add(amount.ToString());
            request.Send(socket);
        }
Пример #10
0
        public void RemoveOneItem(uint itemId)
        {
            Storage position = storage.Find(pos => pos.ItemId == itemId);
            uint am = position.Amount;

            if (position.Amount > 1)
            {
                position.Amount--;
            }
            else
            {
                storage.RemoveAll(pos => pos.ItemId == itemId);
            }

            Command request = new Command();
            request.Request(ClientCmd.REMOVE_ONE_ITEM);
            request.Add(itemId.ToString());
            request.Send(socket);
        }
Пример #11
0
        public Item GetItemById(uint id)
        {
            string[] result;
            Item item;
            Command request = new Command();
            request.Request(ClientCmd.GET_ITEM_BY_ID);
            request.Add(id.ToString());

            result = request.Send(socket, true);

            try
            {
                item = new Item(
                    uint.Parse(result[1]),
                    result[2],
                    result[3],
                    uint.Parse(result[4]),
                    result[5]
                    );
            }
            catch
            {
                item = null;
            }

            return item;
        }
Пример #12
0
        public CharacterStorage(ulong id, TcpClient client)
        {
            socket = client.Client;

            this.id = id;

            string[] result;
            items = new List<Item>();
            storage = new List<Storage>();

            Command request = new Command();
            request.Request(ClientCmd.GET_CHARACTER_STORAGE);
            request.Add(id.ToString());
            result = request.Send(socket, true);

            for (int i = 1; i < result.Length; i += 3)
            {
                Storage position = new Storage(
                    ulong.Parse(result[i]),
                    uint.Parse(result[i + 1]),
                    uint.Parse(result[i + 2])
                    );
                storage.Add(position);
            }
        }
Пример #13
0
        public Skills(TcpClient client)
        {
            skillList = new List<Skill>();
            socket = client.Client;
            string[] result;

            Command request = new Command();
            request.Request(ClientCmd.GET_SKILLS);
            result = request.Send(socket, true);

            if (result[0] == ServerCmd.SKILLS)
            {
                for (int i = 1; i < result.Length; i += 6)
                {
                    Skill skill = new Skill(
                        uint.Parse(result[i]),
                        uint.Parse(result[i+1]),
                        uint.Parse(result[i+2]),
                        uint.Parse(result[i+3]),
                        uint.Parse(result[i+4]),
                        uint.Parse(result[i+5])
                        );
                    skillList.Add(skill);
                }
            }
        }
Пример #14
0
        public Map(TcpClient clientSocket)
        {
            socket = clientSocket.Client;

            uint citiesNumber = 0;
            uint spotsNumber = 0;
            string[] citiesData, spotsData;
            Command request = new Command();
            request.Request(ClientCmd.GET_CITIES);
            citiesData = request.Send(socket, true);
            request.Request(ClientCmd.GET_SPOTS);
            spotsData = request.Send(socket, true);

            //obliczenie liczby miast
            citiesNumber = uint.Parse(citiesData[1]);
            for (int i = 2; i < citiesData.Length; i += 6)
            {
                City city = new City(
                    uint.Parse(citiesData[i]),      //id
                    citiesData[i + 1],              //name
                    uint.Parse(citiesData[i + 2]),  //accessLevel
                    uint.Parse(citiesData[i + 3]),  //leftCoordinate
                    uint.Parse(citiesData[i + 4]),  //topCoordinate
                    citiesData[i + 5]               //icon
                    );
                cityData.Add(city);
            }

            //obliczenie liczby spotów
            spotsNumber = uint.Parse(spotsData[1]);
            for (int i = 2; i < spotsData.Length; i += 6)
            {
                Spot spot = new Spot(
                    uint.Parse(spotsData[i]),       //id lokacji
                    uint.Parse(spotsData[i + 1]),   //id miasta do którego przynależy
                    char.Parse(spotsData[i + 2]),   //typ lookacji
                    spotsData[i + 3],               //name
                    uint.Parse(spotsData[i + 4]),   //leftCoordinate
                    uint.Parse(spotsData[i + 5])    //topCoordinate
                    );
                spotData.Add(spot);
            }

            //tworzenie buttonów miast na podstawie danych z bazki
            foreach (City city in cityData)
            {
                //najpierw sam button
                Button btn = new Button();
                //potem stackpanel przechowujący jego zawartość
                StackPanel btnContent = new StackPanel();
                //obrazek, który będzie jego zawartością
                Image btnImage = new Image();
                //i jego źródło
                btnImage.Source = new BitmapImage(new Uri("pack://application:,,,/Images/" + city.Icon + ".png"));
                btnImage.Width = 44;
                btnImage.Height = 60;
                //oraz textblock, który będzie wyświetlał nazwę miasta
                TextBlock btnText = new TextBlock();
                //przypisanie do texblocka nazwy miasta
                btnText.Text = city.Name;
                //szerokość stała na 50 px
                btnText.Width = 50;
                //nazwa kontrolki aby można było dynamicznie zmieniać kolor tekstu w buttonie
                btnText.Name = "city" + city.Id + "Name";
                //wyśrodkowanie tekstu
                btnText.TextAlignment = TextAlignment.Center;
                //ustawienie stackpanelu na 40 szerokości i 75 wysokości (obrazek wtedy sam się zeskaluje)
                btnContent.Width = 50;
                btnContent.Height = 75;

                btnContent.Margin = new Thickness(3, 3, 3, 3);
                //wyśrodkowanie zawartości w pionie do środka
                btnContent.VerticalAlignment = VerticalAlignment.Center;
                //dodanie obrazka i texblocka z nazwą miasta do stackpanelu
                btnContent.Children.Add(btnImage);
                btnContent.Children.Add(btnText);
                //nazwanie buttona miasta
                btn.Name = "city" + city.Id;
                //jego szerokość na 55 px
                btn.Width = 55;
                //cały content wyśrodkowany
                btn.HorizontalAlignment = HorizontalAlignment.Center;
                //przypisanie stackpanelu jako zawartości buttona
                btn.Content = btnContent;
                //dodanie tagu z identyfikatorem miasta
                btn.Tag = city.Id;
                //określenie położenia na mapie
                Canvas.SetLeft(btn, city.LeftCoordinate);
                Canvas.SetTop(btn, city.TopCoordinate);
                //dodanie do listy buttonów mapy
                cityButtons.Add(btn);
            }

            //tworzenie buttonów spotów na podstawie danych z bazki
            foreach (Spot spot in spotData)
            {
                //najpierw sam button
                Button btn = new Button();
                //obrazek, który będzie jego zawartością
                Image btnImage = new Image();
                //i jego źródło
                btnImage.Source = new BitmapImage(new Uri("pack://application:,,,/Images/spot_" + spot.Type + ".png"));
                btnImage.Width = 30;
                btnImage.Height = 30;
                //dodanie obrazka do contentu
                btn.Content = btnImage;
                //nazwanie buttona spotu
                btn.Name = "city" + spot.IdCity + "spot" + spot.IdLoc;
                //jego szerokość na 30 px
                btn.Width = 30;
                //cały content wyśrodkowany
                btn.HorizontalAlignment = HorizontalAlignment.Center;
                //dodanie tagu ze spotem
                btn.Tag = spot;
                //ukrycie buttona
                btn.Visibility = Visibility.Hidden;
                //określenie położenia na mapie
                Canvas.SetLeft(btn, spot.LeftCoordinate);
                Canvas.SetTop(btn, spot.TopCoordinate);
                //dodanie do listy buttonów mapy
                spotButtons.Add(btn);
            }
        }