Example #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.Apply(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
            }
        }
Example #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);
                }
            }
        }
        /// <summary>
        /// Evaluates the current expression.
        /// </summary>
        /// <param name="context">The context of the evaluation.</param>
        /// <param name="res">The variable which will contain the result of the evaluation.</param>
        protected override void Evaluate(EvaluationContext context, out EvaluationResult res)
        {
            Commands.Command cmd = null;

            if (context.State != null)
            {
                cmd = context.State.GetCommand(CommandName);
            }

            if (cmd == null)
            {
                cmd = context.Host.GetCommand(CommandName);
            }

            if (cmd == null)
            {
                res = new EvaluationResult(CommonStatusCodes.CommandNotFound, this
                                           , string.Format(CultureInfo.InvariantCulture
                                                           , "Command not found: {0}"
                                                           , CommandName)
                                           , this.CommandName);

                return;
            }

            res            = cmd.Invoke(Toggle, context, args_a ?? args.ToArray());
            res.Expression = this;
        }
Example #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]);
            }
        }
Example #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";
        }
Example #6
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.Apply(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);
                }
            }
        }
Example #7
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);
                }
            }
        }
Example #8
0
        private void ExecuteCommand(string commandLine)
        {
            if (!string.IsNullOrWhiteSpace(commandLine))
            {
                var command = new Command(commandLine);

                string commandResult;
                try
                {
                    switch (command.CommandName)
                    {
                        case "AddTheatre":

                            var addTheatreCmd =
                                new AddThratreCommand(commandLine);

                            commandResult =
                                CommandExecuter.ExecuteAddTheatreCommand(this.DataBase, addTheatreCmd);

                            break;

                        case "PrintAllTheatres":
                            commandResult =
                                CommandExecuter.ExecutePrintAllTheatresCommand(this.DataBase);

                            break;

                        case "AddPerformance":

                            var addPerformanceCmd =
                                new AddPerformanceCommand(commandLine);

                            commandResult =
                                CommandExecuter.ExecuteAddPerformanceCommand(this.DataBase, addPerformanceCmd);

                            break;

                        case "PrintAllPerformances":
                            commandResult = CommandExecuter.ExecutePrintAllPerformancesCommand(this.DataBase);

                            break;

                        case "PrintPerformances":

                            var printPerformances =
                                new PrintPerformancesCommand(commandLine);

                            commandResult =
                                CommandExecuter.ExecutePrintPerformancesCommand(this.DataBase, printPerformances);

                            break;

                        default:
                            commandResult = "Invalid command!";
                            break;
                    }

                    this.OutputMethod.Output(commandResult);
                }
                catch (Exception ex)
                {
                    OutputMethod.Output("Error: "+ ex.Message);
                    
                }
            }
        }
Example #9
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);
                }
            }
        }
Example #10
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(client, true);

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

            return item;
        }
Example #11
0
 /// <summary>
 /// Sends a command over the stream
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="command"></param>
 public static void SendCommand(Stream stream, Command command)
 {
     stream.Write(new byte[] { (byte)command }, 0, 1);
 }