Exemplo n.º 1
0
        public static void UpdateIconsAndNames()
        {
            Dictionary <string, ParsingContext> AttributeParsingTable = ParsingContext.ObjectKeyTable[typeof(PgAttribute)];

            foreach (KeyValuePair <string, ParsingContext> Entry in AttributeParsingTable)
            {
                PgAttribute Attribute = (PgAttribute)Entry.Value.Item;

                if (Attribute.IconIdList.Count > 0)
                {
                    Attribute.IconId = Attribute.IconIdList[0];
                }
                else
                {
                    Attribute.IconId = PgObject.AttributeIconId;
                }

                if (Attribute.Label.Length > 0)
                {
                    Attribute.ValidLabel = Attribute.Label;
                }
                else
                {
                    Attribute.ValidLabel = Attribute.Key;
                }

                Debug.Assert(Attribute.ObjectIconId != 0);
                Debug.Assert(Attribute.ObjectName.Length > 0);
            }
        }
Exemplo n.º 2
0
        private bool FinishItem(PgAttribute item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey)
        {
            bool Result = true;

            foreach (KeyValuePair <string, object> Entry in contentTable)
            {
                string Key   = Entry.Key;
                object Value = Entry.Value;

                switch (Key)
                {
                case "Label":
                    Result = SetStringProperty((string valueString) => item.Label = valueString, Value);
                    break;

                case "IconIds":
                    Result = ParseIcondIds(item, Value, parsedFile, parsedKey);
                    break;

                case "Tooltip":
                    Result = SetStringProperty((string valueString) => item.Tooltip = valueString, Value);
                    break;

                case "DisplayType":
                    Result = StringToEnumConversion <DisplayType> .SetEnum((DisplayType valueEnum) => item.DisplayType = valueEnum, Value);

                    break;

                case "IsHidden":
                    Result = SetBoolProperty((bool valueBool) => item.RawIsHidden = valueBool, Value);
                    break;

                case "DisplayRule":
                    Result = StringToEnumConversion <DisplayRule> .SetEnum((DisplayRule valueEnum) => item.DisplayRule = valueEnum, Value);

                    break;

                case "DefaultValue":
                    Result = SetFloatProperty((float valueFloat) => item.RawDefaultValue = valueFloat, Value);
                    break;

                default:
                    Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled");
                    break;
                }

                if (!Result)
                {
                    break;
                }
            }

            return(Result);
        }
Exemplo n.º 3
0
        private static bool ParseItemEffectAttribute(string effectString, string parsedFile, string parsedKey, out PgItemEffect itemEffect)
        {
            itemEffect = null !;

            string[] Split = effectString.Split('{');
            if (Split.Length != 2)
            {
                return(false);
            }

            string AttributeName   = Split[0];
            string AttributeEffect = Split[1];

            if (!AttributeName.EndsWith("}"))
            {
                return(false);
            }

            AttributeName = AttributeName.Substring(0, AttributeName.Length - 1);
            if (AttributeName.Contains("{") || AttributeName.Contains("}"))
            {
                return(false);
            }

            if (AttributeName.Length == 0 || AttributeEffect.Length == 0)
            {
                return(false);
            }

            PgAttribute ParsedAttribute = null !;

            if (!Inserter <PgAttribute> .SetItemByKey((PgAttribute valueAttribute) => ParsedAttribute = valueAttribute, AttributeName))
            {
                return(false);
            }

            if (!Tools.TryParseFloat(AttributeEffect, out float ParsedEffect, out FloatFormat ParsedEffectFormat))
            {
                return(false);
            }

            if (ParsedEffectFormat != FloatFormat.Standard)
            {
                return(false);
            }

            itemEffect = new PgItemEffectAttribute()
            {
                Attribute_Key = ParsedAttribute.Key, AttributeEffect = ParsedEffect, AttributeEffectFormat = ParsedEffectFormat
            };
            return(true);
        }
Exemplo n.º 4
0
        private bool FinishItem(PgAdvancement item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey)
        {
            bool Result = true;

            foreach (KeyValuePair <string, object> Entry in contentTable)
            {
                string Key   = Entry.Key;
                object Value = Entry.Value;

                PgAttribute ParsedAttribute = null !;
                float       ParsedValue     = 0;

                if (Key == "MENTAL_DEFENSE_RATING")
                {
                    continue;
                }

                Result = Inserter <PgAttribute> .SetItemByKey((PgAttribute valueAttribute) => ParsedAttribute = valueAttribute, Key);

                if (Result)
                {
                    if (Value is float FloatValue)
                    {
                        ParsedValue = FloatValue;
                    }
                    else if (Value is int IntValue)
                    {
                        ParsedValue = IntValue;
                    }
                    else
                    {
                        Result = Program.ReportFailure(parsedFile, parsedKey, $"Unknown attribute value '{Value}'");
                    }
                }

                if (Result)
                {
                    PgAdvancementEffectAttribute NewAdvancementEffectAttribute = new PgAdvancementEffectAttribute()
                    {
                        Attribute_Key = ParsedAttribute.Key, RawValue = ParsedValue
                    };

                    ParsingContext.AddSuplementaryObject(NewAdvancementEffectAttribute);
                    item.EffectAttributeList.Add(NewAdvancementEffectAttribute);
                }
            }

            return(Result);
        }
Exemplo n.º 5
0
        private static bool IsBuggedDescription(string description, List <int> iconIdList, string startPattern, string endPattern, string attributeKey, out PgPowerEffect fixedEffect)
        {
            int         StartIndex      = description.IndexOf(startPattern);
            int         EndIndex        = description.LastIndexOf(endPattern);
            PgAttribute ParsedAttribute = null !;

            if (StartIndex == 0 &&
                EndIndex > startPattern.Length &&
                Tools.TryParseFloat(description.Substring(startPattern.Length, EndIndex - startPattern.Length), out float ParsedEffect, out FloatFormat ParsedEffectFormat) &&
                Inserter <PgAttribute> .SetItemByKey((PgAttribute valueAttribute) => ParsedAttribute = valueAttribute, attributeKey))
            {
                PgPowerEffectAttribute NewPowerEffectAttribute = new PgPowerEffectAttribute()
                {
                    Description = description, IconIdList = iconIdList, AttributeEffect = ParsedEffect, AttributeEffectFormat = ParsedEffectFormat
                };
                NewPowerEffectAttribute.SetAttribute(ParsedAttribute);
                fixedEffect = NewPowerEffectAttribute;
                return(true);
            }
Exemplo n.º 6
0
        private bool ParseIcondIds(PgAttribute item, object value, string parsedFile, string parsedKey)
        {
            if (!(value is List <object> AsObjectList))
            {
                return(Program.ReportFailure(parsedFile, parsedKey, "Array of int expected for icon IDs"));
            }

            foreach (object ObjectItem in AsObjectList)
            {
                if (!(ObjectItem is int AsInt))
                {
                    return(Program.ReportFailure(parsedFile, parsedKey, "Int expected for an icon ID"));
                }

                if (item.IconIdList.Contains(AsInt))
                {
                    return(Program.ReportFailure(parsedFile, parsedKey, $"Duplicate icon ID {AsInt}"));
                }

                item.IconIdList.Add(AsInt);
            }

            return(true);
        }
Exemplo n.º 7
0
 public void SetAttribute(PgAttribute attribute)
 {
     Attribute_Key = attribute.Key;
     AttributeRef  = attribute;
 }
Exemplo n.º 8
0
        private static bool ParseItemEffectAttribute(string effectString, string parsedFile, string parsedKey, out PgPowerEffect powerEffect)
        {
            powerEffect = null !;

            string[] Split = effectString.Split('{');
            if (Split.Length != 2 && Split.Length != 3)
            {
                return(false);
            }

            string AttributeName   = Split[0];
            string AttributeEffect = Split[1];

            if (!AttributeName.EndsWith("}"))
            {
                return(false);
            }

            AttributeName = AttributeName.Substring(0, AttributeName.Length - 1);
            if (AttributeName.Contains("{") || AttributeName.Contains("}"))
            {
                return(false);
            }

            if (AttributeName.Length == 0 || AttributeEffect.Length == 0)
            {
                return(false);
            }

            PgAttribute ParsedAttribute = null !;

            if (!Inserter <PgAttribute> .SetItemByKey((PgAttribute valueAttribute) => ParsedAttribute = valueAttribute, AttributeName))
            {
                return(false);
            }

            if (Split.Length == 3)
            {
                if (!AttributeEffect.EndsWith("}"))
                {
                    return(false);
                }

                AttributeEffect = AttributeEffect.Substring(0, AttributeEffect.Length - 1);
            }

            if (!Tools.TryParseFloat(AttributeEffect, out float ParsedEffect, out FloatFormat ParsedEffectFormat))
            {
                return(false);
            }

            if (ParsedEffectFormat != FloatFormat.Standard)
            {
                return(false);
            }

            PgPowerEffectAttribute NewPowerEffectAttribute;

            if (Split.Length == 3)
            {
                string AttributeSkill = Split[2];

                PgSkill ParsedSkill = null !;

                if (AttributeSkill == "AnySkill")
                {
                    ParsedSkill = PgSkill.AnySkill;
                }
                else if (!Inserter <PgSkill> .SetItemByKey((PgSkill valueSkill) => ParsedSkill = valueSkill, AttributeSkill))
                {
                    return(false);
                }

                NewPowerEffectAttribute = new PgPowerEffectAttribute()
                {
                    AttributeEffect = ParsedEffect, AttributeEffectFormat = ParsedEffectFormat, Skill_Key = ParsedSkill.Key
                };
            }
            else
            {
                NewPowerEffectAttribute = new PgPowerEffectAttribute()
                {
                    AttributeEffect = ParsedEffect, AttributeEffectFormat = ParsedEffectFormat
                }
            };

            NewPowerEffectAttribute.SetAttribute(ParsedAttribute);
            powerEffect = NewPowerEffectAttribute;
            return(true);
        }