Beispiel #1
0
        /// <summary>
        /// Returns a <see cref="IReadOnlyList{T}"/> of type <see cref="HEntityAction"/> found in the <see cref="HMessage"/>.
        /// </summary>
        /// <param name="packet">The <see cref="HMessage"/> that contains the <see cref="HEntityAction"/> data to parse.</param>
        /// <returns></returns>
        public static IReadOnlyList<HEntityAction> Parse(HMessage packet)
        {
            int entityActionCount = packet.ReadInteger();
            var entityActionList = new List<HEntityAction>(entityActionCount);

            for (int i = 0; i < entityActionList.Capacity; i++)
            {
                int index = packet.ReadInteger();
                int x = packet.ReadInteger();
                int y = packet.ReadInteger();
                var z = double.Parse(packet.ReadString(), CultureInfo.InvariantCulture);

                var headDirection = (HDirection)packet.ReadInteger();
                var bodyDirection = (HDirection)packet.ReadInteger();

                string actionString = packet.ReadString();
                string[] actionData = actionString.Split(new[] { '/' },
                    StringSplitOptions.RemoveEmptyEntries);

                HSign sign = HSign.One;
                HAction action = HAction.None;
                HStance stance = HStance.Stand;

                double movingToZ = 0.0;
                bool isEmpowered = false;
                int movingToX = 0, movingToY = 0;

                foreach (string actionInfo in actionData)
                {
                    string[] actionValues = actionInfo.Split(' ');

                    if (actionValues.Length < 2) continue;
                    if (string.IsNullOrWhiteSpace(actionValues[0])) continue;

                    #region Switch Statement: actionValues[]
                    switch (actionValues[0])
                    {
                        case "flatctrl":
                        {
                            isEmpowered = true;
                            break;
                        }
                        case "mv":
                        {
                            string[] movingToValues = actionValues[1].Split(',');
                            if (movingToValues.Length >= 3)
                            {
                                movingToX = int.Parse(movingToValues[0]);
                                movingToY = int.Parse(movingToValues[1]);
                                movingToZ = double.Parse(movingToValues[2], CultureInfo.InvariantCulture);
                            }
                            action = HAction.Move;
                            break;
                        }
                        case "sit":
                        {
                            action = HAction.Sit;
                            stance = HStance.Sit;
                            break;
                        }
                        case "lay":
                        {
                            action = HAction.Lay;
                            stance = HStance.Lay;
                            break;
                        }
                        case "sign":
                        {
                            sign = (HSign)int.Parse(actionValues[1]);
                            action = HAction.Sign;
                            break;
                        }
                    }
                    #endregion
                }

                var entityAction = new HEntityAction(isEmpowered, index, new HPoint(x, y, z),
                    new HPoint(movingToX, movingToY, movingToZ), sign, stance, headDirection, bodyDirection, action);

                entityActionList.Add(entityAction);
            }
            return entityActionList;
        }
Beispiel #2
0
        /// <summary>
        /// Returns a <see cref="IReadOnlyList{T}"/> of type <see cref="HEntityAction"/> found in the <see cref="HMessage"/>.
        /// </summary>
        /// <param name="packet">The <see cref="HMessage"/> that contains the <see cref="HEntityAction"/> data to parse.</param>
        /// <returns></returns>
        public static IReadOnlyList <HEntityAction> Parse(HMessage packet)
        {
            int entityActionCount = packet.ReadInteger();
            var entityActionList  = new List <HEntityAction>(entityActionCount);

            for (int i = 0; i < entityActionList.Capacity; i++)
            {
                int index = packet.ReadInteger();
                int x     = packet.ReadInteger();
                int y     = packet.ReadInteger();
                var z     = double.Parse(packet.ReadString(), CultureInfo.InvariantCulture);

                var headDirection = (HDirection)packet.ReadInteger();
                var bodyDirection = (HDirection)packet.ReadInteger();

                string   actionString = packet.ReadString();
                string[] actionData   = actionString.Split(new[] { '/' },
                                                           StringSplitOptions.RemoveEmptyEntries);

                HSign   sign   = HSign.One;
                HAction action = HAction.None;
                HStance stance = HStance.Stand;

                double movingToZ = 0.0;
                bool   isEmpowered = false;
                int    movingToX = 0, movingToY = 0;

                foreach (string actionInfo in actionData)
                {
                    string[] actionValues = actionInfo.Split(' ');

                    if (actionValues.Length < 2)
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(actionValues[0]))
                    {
                        continue;
                    }

                    #region Switch Statement: actionValues[]
                    switch (actionValues[0])
                    {
                    case "flatctrl":
                    {
                        isEmpowered = true;
                        break;
                    }

                    case "mv":
                    {
                        string[] movingToValues = actionValues[1].Split(',');
                        if (movingToValues.Length >= 3)
                        {
                            movingToX = int.Parse(movingToValues[0]);
                            movingToY = int.Parse(movingToValues[1]);
                            movingToZ = double.Parse(movingToValues[2], CultureInfo.InvariantCulture);
                        }
                        action = HAction.Move;
                        break;
                    }

                    case "sit":
                    {
                        action = HAction.Sit;
                        stance = HStance.Sit;
                        break;
                    }

                    case "lay":
                    {
                        action = HAction.Lay;
                        stance = HStance.Lay;
                        break;
                    }

                    case "sign":
                    {
                        sign   = (HSign)int.Parse(actionValues[1]);
                        action = HAction.Sign;
                        break;
                    }
                    }
                    #endregion
                }

                var entityAction = new HEntityAction(isEmpowered, index, new HPoint(x, y, z),
                                                     new HPoint(movingToX, movingToY, movingToZ), sign, stance, headDirection, bodyDirection, action);

                entityActionList.Add(entityAction);
            }
            return(entityActionList);
        }