Esempio n. 1
0
        private void LoadFromXml(XDocument document)
        {
            var rootElem = document.Root;

            if (rootElem.Name != "LEGOPrimitive")
            {
                throw new InvalidDataException();
            }

            rootElem.TryGetIntAttribute("versionMajor", out int vMaj);
            rootElem.TryGetIntAttribute("versionMinor", out int vMin);
            FileVersion = new VersionInfo(vMaj, vMin);

            ExtraElements.Clear();
            foreach (var element in rootElem.Elements())
            {
                try { ReadPrimitiveSection(element); }
                catch (Exception ex)
                {
                    throw new Exception($"Error while reading {element.Name.LocalName}", ex);
                }
            }

            if (PhysicsAttributes == null)
            {
                PhysicsAttributes = new PhysicsAttributes();
            }

            if (ID == 0 && Aliases.Any())
            {
                ID = Aliases.First();
            }

            Comments = document.Nodes().OfType <XComment>().FirstOrDefault()?.Value ?? string.Empty;
        }
 internal void Revive(string commandLineValue)
 {
     if (ArgRevivers.CanRevive(ArgumentType) && commandLineValue != null)
     {
         try
         {
             if (ArgumentType.IsEnum)
             {
                 RevivedValue = ArgRevivers.ReviveEnum(ArgumentType, commandLineValue, IgnoreCase);
             }
             else
             {
                 RevivedValue = ArgRevivers.Revive(ArgumentType, Aliases.First(), commandLineValue);
             }
         }
         catch (ArgException)
         {
             throw;
         }
         catch (Exception ex)
         {
             if (ex.InnerException != null && ex.InnerException is ArgException)
             {
                 throw ex.InnerException;
             }
             else
             {
                 if (ArgumentType.IsEnum)
                 {
                     throw new ArgException("'" + commandLineValue + "' is not a valid value for " + Aliases.First() + ". Available values are [" + string.Join(", ", Enum.GetNames(ArgumentType)) + "]", ex);
                 }
                 else
                 {
                     throw new ArgException(ex.Message, ex);
                 }
             }
         }
     }
     else if (ArgRevivers.CanRevive(ArgumentType) && ArgumentType == typeof(SecureStringArgument))
     {
         RevivedValue = ArgRevivers.Revive(ArgumentType, Aliases.First(), commandLineValue);
     }
     else if (commandLineValue != null && ArgRevivers.CanRevive(ArgumentType))
     {
         throw new ArgException("Unexpected argument '" + Aliases.First() + "' with value '" + commandLineValue + "'");
     }
     else if (commandLineValue != null && ArgRevivers.CanRevive(ArgumentType) == false)
     {
         throw new InvalidArgDefinitionException("There is no reviver for type '" + ArgumentType.Name + '"');
     }
 }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 public void Serialize(StringBuilder message, string parent = "")
 {
     if (m_subCommands.Count != 0)
     {
         message.Append("[").Append(Aliases.First()).Append("]").Append('\n');
     }
     else
     {
         message.Append(parent).Append(Aliases.First()).Append(" : ").Append(Description).Append('\n');
     }
     foreach (var subCommand in m_subCommands)
     {
         subCommand.Serialize(message, Aliases.First() + " ");
     }
 }
Esempio n. 4
0
 public Channel GetSuggestedChannel(out SuggestionType suggestionType)
 {
     if (Channels.Count > 0)
     {
         suggestionType = SuggestionType.Channel;
         return(Channels.First());
     }
     else if (Logos.Count > 0)
     {
         suggestionType = SuggestionType.Logo;
         return(Logos.First().Channels.First());
     }
     else
     {
         suggestionType = SuggestionType.Alias;
         return(Aliases.First().Channel);
     }
 }
Esempio n. 5
0
    public override void Execute(GameCommandTrigger trigger)
    {
        string equipSlot = trigger.Get <string>("equipSlot");

        if (string.IsNullOrEmpty(equipSlot))
        {
            trigger.Session.SendNotice($"Type '/info {Aliases.First()}' for more details.");
            return;
        }

        if (!Enum.TryParse(equipSlot, ignoreCase: true, out ItemSlot itemSlot) || itemSlot == ItemSlot.NONE)
        {
            trigger.Session.SendNotice($"{equipSlot} is not a valid equip slot.");
            string slots = "";
            foreach (object slot in Enum.GetValues(typeof(ItemSlot)))
            {
                slots += $"{slot} - {((ItemSlot) slot).GetEnumDescription()}, ";
            }

            trigger.Session.SendNotice($"Available slots: {slots.TrimEnd(',', ' ')}");
            return;
        }

        Player player = trigger.Session.Player;

        if (!player.Inventory.Equips.TryGetValue(itemSlot, out Item item))
        {
            trigger.Session.SendNotice($"You don't have an item in slot {itemSlot}.");
            return;
        }

        item.Stats.Constants.Clear();
        item.Stats.Randoms.Clear();
        item.Stats.Statics.Clear();

        player.FieldPlayer.ComputeStats();

        trigger.Session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(player.FieldPlayer, item, itemSlot));

        DatabaseManager.Items.Update(item);
    }
        internal void Validate(ref string commandLineValue)
        {
            if (ArgumentType == typeof(SecureStringArgument) && Validators.Count() > 0)
            {
                throw new InvalidArgDefinitionException("Properties of type SecureStringArgument cannot be validated.  If your goal is to make the argument required then the[ArgRequired] attribute is not needed.  The SecureStringArgument is designed to prompt the user for a value only if your code asks for it after parsing.  If your code never reads the SecureString property then the user is never prompted and it will be treated as an optional parameter.  Although discouraged, if you really, really need to run custom logic against the value before the rest of your program runs then you can implement a custom ArgHook, override RunAfterPopulateProperty, and add your custom attribute to the SecureStringArgument property.");
            }

            foreach (var v in Validators)
            {
                if (v.ImplementsValidateAlways)
                {
                    try { v.ValidateAlways(this, ref commandLineValue); }
                    catch (NotImplementedException)
                    {
                        // TODO P0 - Test to make sure the old, PropertyInfo based validators properly work.
                        v.ValidateAlways(Source as PropertyInfo, ref commandLineValue);
                    }
                }
                else if (commandLineValue != null)
                {
                    v.Validate(Aliases.First(), ref commandLineValue);
                }
            }
        }
 public Func <ParseResult, IEnumerable <string> > GetForwardingFunction(Func <T, IEnumerable <string> > func)
 {
     return((ParseResult parseResult) => parseResult.HasOption(Aliases.First()) ? func(parseResult.ValueForOption <T>(Aliases.First())) : Array.Empty <string>());
 }
        private void FindMatchingArgumentInRawParseData(ArgHook.HookContext context)
        {
            var match = from k in context.ParserData.ExplicitParameters.Keys where IsMatch(k) select k;

            if (match.Count() > 1)
            {
                throw new DuplicateArgException("Argument specified more than once: " + Aliases.First());
            }
            else if (match.Count() == 1)
            {
                var key = match.First();
                context.ArgumentValue = context.ParserData.ExplicitParameters[key];
                context.ParserData.ExplicitParameters.Remove(key);
            }
            else if (context.ParserData.ImplicitParameters.ContainsKey(Position))
            {
                var position = Position;
                context.ArgumentValue = context.ParserData.ImplicitParameters[position];
                context.ParserData.ImplicitParameters.Remove(position);
            }
            else
            {
                context.ArgumentValue = null;
            }
        }
Esempio n. 9
0
 public ForwardedOption <T> SetForwardingFunction(Func <T, ParseResult, IEnumerable <string> > func)
 {
     ForwardingFunction = (ParseResult parseResult) => parseResult.HasOption(Aliases.First()) ? func(parseResult.ValueForOption <T>(Aliases.First()), parseResult) : Array.Empty <string>();
     return(this);
 }
Esempio n. 10
0
        private void LoadFromXml(XDocument document)
        {
            var rootElem = document.Root;

            if (rootElem.Name != "LXFML")
            {
                throw new InvalidDataException();
            }
            rootElem.TryGetIntAttribute("versionMajor", out int vMaj);
            rootElem.TryGetIntAttribute("versionMinor", out int vMin);
            FileVersion = new VersionInfo(vMaj, vMin);

            if (rootElem.HasElement("Meta", out XElement metaElem))
            {
                foreach (var annotationElem in metaElem.Elements("Annotation"))
                {
                    var    annotationAttr = annotationElem.FirstAttribute;
                    string annotationName = annotationAttr.Name.LocalName;
                    string value          = annotationAttr.Value;
                    //bool handled = true;

                    switch (annotationName)
                    {
                    case "aliases":
                        var aliases = value.Split(';');
                        for (int i = 0; i < aliases.Length; i++)
                        {
                            if (int.TryParse(aliases[i], out int aliasID))
                            {
                                Aliases.Add(aliasID);
                            }
                        }
                        break;

                    case "designname":
                        Name = value;
                        break;

                    case "maingroupid":
                        if (MainGroup == null)
                        {
                            MainGroup = new MainGroup();
                        }
                        MainGroup.ID = int.Parse(value);
                        break;

                    case "maingroupname":
                        if (MainGroup == null)
                        {
                            MainGroup = new MainGroup();
                        }
                        MainGroup.Name = value;
                        break;

                    case "platformid":
                        if (Platform == null)
                        {
                            Platform = new Platform();
                        }
                        Platform.ID = int.Parse(value);
                        break;

                    case "platformname":
                        if (Platform == null)
                        {
                            Platform = new Platform();
                        }
                        Platform.Name = value;
                        break;
                        //default:
                        //    handled = false;
                        //    break;
                    }

                    //if (!handled)
                    //    ExtraAnnotations.Add(annotationName, value);
                }
            }

            Bricks.Clear();
            if (rootElem.HasElement("Bricks", out XElement bricksElem))
            {
                foreach (var brickElem in bricksElem.Elements("Brick"))
                {
                    var brick = new Brick();
                    brick.LoadFromXml(brickElem);
                    Bricks.Add(brick);
                }
            }

            if (document.Root.HasAttribute("name"))
            {
                ID = document.Root.ReadAttribute("name", 0);
            }

            if (ID == 0 && Aliases.Any())
            {
                ID = Aliases.First();
            }
        }
Esempio n. 11
0
    public override void Execute(GameCommandTrigger trigger)
    {
        string equipSlot      = trigger.Get <string>("equipSlot");
        string newAttributeId = trigger.Get <string>("newAttributeId");
        float  value          = trigger.Get <float>("value");
        byte   isPercentage   = trigger.Get <byte>("isPercentage");
        byte   category       = trigger.Get <byte>("category");

        if (string.IsNullOrEmpty(equipSlot))
        {
            trigger.Session.SendNotice($"Type '/info {Aliases.First()}' for more details.");
            return;
        }

        if (!Enum.TryParse(equipSlot, ignoreCase: true, out ItemSlot itemSlot) || itemSlot == ItemSlot.NONE)
        {
            trigger.Session.SendNotice($"{equipSlot} is not a valid equip slot.");
            string slots = "";
            foreach (object slot in Enum.GetValues(typeof(ItemSlot)))
            {
                slots += $"{slot} - {((ItemSlot) slot).GetEnumDescription()}, ";
            }

            trigger.Session.SendNotice($"Available slots: {slots.TrimEnd(',', ' ')}");
            return;
        }

        if (!Enum.TryParse(newAttributeId, ignoreCase: true, out StatAttribute newAttribute))
        {
            trigger.Session.SendNotice($"{newAttributeId} is not a valid attribute. Check StatAttribute.cs");
            return;
        }

        Player player = trigger.Session.Player;

        if (!player.Inventory.Equips.TryGetValue(itemSlot, out Item item))
        {
            trigger.Session.SendNotice($"You don't have an item in slot {itemSlot}.");
            return;
        }

        ItemStat          itemStat;
        StatAttributeType attributeType = isPercentage == 1 ? StatAttributeType.Rate : StatAttributeType.Flat;

        if ((int)newAttribute > 11000)
        {
            itemStat = new SpecialStat(newAttribute, value, attributeType);
        }
        else
        {
            itemStat = new BasicStat(newAttribute, value, attributeType);
        }

        if (category == 0)
        {
            if (value == 0)
            {
                item.Stats.Constants.Remove(newAttribute);
            }
            else
            {
                item.Stats.Constants[newAttribute] = itemStat;
            }
        }
        else if (category == 1)
        {
            if (value == 0)
            {
                item.Stats.Statics.Remove(newAttribute);
            }
            else
            {
                item.Stats.Statics[newAttribute] = itemStat;
            }
        }
        else if (category == 2)
        {
            if (value == 0)
            {
                item.Stats.Randoms.Remove(newAttribute);
            }
            else
            {
                item.Stats.Randoms[newAttribute] = itemStat;
            }
        }

        trigger.Session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(player.FieldPlayer, item, itemSlot));

        player.FieldPlayer.ComputeStats();

        DatabaseManager.Items.Update(item);
    }
Esempio n. 12
0
 public override string ToString()
 {
     return(string.Format("{0}: {1}", Aliases.First(), Description));
 }