Ejemplo n.º 1
0
        public static CustomPropertyCollection Parse(string entries)
        {
            CustomPropertyCollection props = new CustomPropertyCollection();

            string[] pairs = entries.Replace("\"", "").Split('|');
            if (pairs != null && pairs.Length > 0)
            {
                foreach (var pair in pairs)
                {
                    // Pair Format
                    // Type=Name=Value
                    string[] values = pair.Split('=');
                    if (values != null && values.Length == 3)
                    {
                        props.Add(new CustomProperty {
                            Type = values[0], Name = values[1], Value = values[2]
                        });
                    }
                }
            }
            return(props);
        }
Ejemplo n.º 2
0
        private static void ParseItem(string[] parts, StringBuilder sb, WorldProvider provider)
        {
            // Columns
            // ItemType,Name,Skills,SkillLevelReq,EquipLocation,Power,Protection,SpellType/FoodType,Range,Durability,
            // Capacity,Currency,Emblem,Flags,Affects,ImageUri,Description,Custom Properties,IngreidentItems

            if (parts != null && parts.Length > 0)
            {
                string type        = parts[0];
                string name        = parts[1];
                string skill       = parts[2];
                string reqSkill    = parts[3];
                string equip       = parts[4];
                string power       = parts[5];
                string protection  = parts[6];
                string spellType   = parts[7];
                string range       = parts[8];
                string durability  = parts[9];
                string capacity    = parts[10];
                string currency    = parts[11];
                string emblem      = parts[12];
                string flags       = parts[13];
                string affects     = parts[14];
                string image       = parts[15];
                string desc        = parts[16];
                string props       = parts[17];
                string ingredItems = parts[18];

                CustomPropertyCollection customProps = CustomPropertyCollection.Parse(props);

                if (!String.IsNullOrEmpty(ingredItems))
                {
                    ingredItems.Replace("\"", "").Trim();
                }

                string   formattedName = FormatName(name);
                ItemType itemType      = (ItemType)Enum.Parse(typeof(ItemType), type, true);

                if (String.IsNullOrEmpty(desc))
                {
                    desc = String.Empty;
                }

                Type t = Type.GetType(String.Concat("Perenthia.", type));
                if (itemType == ItemType.Spell)
                {
                    // Spells have additional types beyond just the Spell sub class.
                    t = Type.GetType(String.Concat("Perenthia.", spellType, "Spell"));
                }
                Item item = provider.GetTemplate(t, name) as Item;
                if (item == null)
                {
                    item = Activator.CreateInstance(t) as Item;
                }
                item.Properties.IsTemplateCollection = true;
                item.TemplateID = 0;
                item.Name       = name;
                // Set description as a template item, can be overridden with a custom description.
                item.Properties.SetValue(Actor.DescriptionProperty, desc.Replace("\"", String.Empty).Trim(), true);

                switch (itemType)
                {
                case ItemType.Item:
                case ItemType.QuestItem:
                    break;

                case ItemType.Armor:
                case ItemType.Clothing:
                    (item as Armor).Protection = Convert.ToInt32(protection);
                    break;

                case ItemType.Container:
                    (item as Container).Capacity = Convert.ToInt32(capacity);
                    break;

                case ItemType.Food:
                    (item as Food).Power = Convert.ToInt32(power);
                    break;

                case ItemType.Light:
                    (item as Light).Range = Convert.ToInt32(range);
                    break;

                case ItemType.Spell:
                    (item as Spell).Power = Convert.ToInt32(power);
                    (item as Spell).Range = Convert.ToInt32(range);
                    break;

                case ItemType.Weapon:
                    (item as Weapon).Power = Convert.ToInt32(power);
                    (item as Weapon).Range = Convert.ToInt32(range);
                    break;

                case ItemType.Shield:
                    (item as Shield).Protection = Convert.ToInt32(protection);
                    if (!String.IsNullOrEmpty(power) && !String.IsNullOrEmpty(range))
                    {
                        (item as Shield).Power = Convert.ToInt32(power);
                        (item as Shield).Range = Convert.ToInt32(range);
                    }
                    break;

                case ItemType.Transport:
                    break;

                case ItemType.RepairKit:
                    break;

                case ItemType.Artifact:
                    break;

                case ItemType.Recipe:
                    (item as Recipe).SkillRequired      = skill.Trim();
                    (item as Recipe).SkillValueRequired = Convert.ToInt32(reqSkill);
                    (item as Recipe).Ingredients.IsTemplateCollection = true;
                    foreach (var ingredient in TemplateItem.Parse(ingredItems))
                    {
                        (item as Recipe).Ingredients.Add(ingredient);
                    }
                    break;

                case ItemType.TrainSkill:
                    (item as TrainSkill).Skill = skill.Trim();
                    break;

                case ItemType.Potion:
                    (item as Potion).Power = Convert.ToInt32(power);
                    (item as Potion).Type  = (PotionType)Enum.Parse(typeof(PotionType), spellType, true);
                    break;
                }

                //sb.Append("\t\t\t\t{ ").AppendLine();

                if (!String.IsNullOrEmpty(equip))
                {
                    item.EquipLocation = (EquipLocation)Enum.Parse(typeof(EquipLocation), equip, true);
                }

                // Default properties not in constructor.
                //ImageUri = "item-light-candle.png"
                //int propCount = 0;
                if (!String.IsNullOrEmpty(flags))
                {
                    item.Flags = (ActorFlags)Enum.Parse(typeof(ActorFlags), flags, true);
                    //sb.AppendFormat("\t\t\t\t\tFlags = {0}", GetFlags(flags));
                    //propCount++;
                }
                if (!String.IsNullOrEmpty(skill) && !String.IsNullOrEmpty(skill.Trim()))
                {
                    item.Skill = skill.Trim();
                    //if (propCount > 0) sb.Append(",").AppendLine();
                    //sb.AppendFormat("\t\t\t\t\tSkill = \"{0}\"", skill.Trim());
                    //propCount++;
                }
                if (!String.IsNullOrEmpty(reqSkill))
                {
                    item.SkillLevelRequiredToEquip = Convert.ToInt32(reqSkill);
                    //if (propCount > 0) sb.Append(",").AppendLine();
                    //sb.AppendFormat("\t\t\t\t\tSkillLevelRequiredToEquip = {0}", reqSkill);
                    //propCount++;
                }
                if (!String.IsNullOrEmpty(currency))
                {
                    item.Cost = new Currency(Convert.ToInt32(currency));
                    //if (propCount > 0) sb.Append(",").AppendLine();
                    //sb.AppendFormat("\t\t\t\t\tCost = new Currency({0})", currency);
                    //propCount++;
                }
                if (!String.IsNullOrEmpty(emblem))
                {
                    item.EmblemCost = Convert.ToInt32(emblem);
                    //if (propCount > 0) sb.Append(",").AppendLine();
                    //sb.AppendFormat("\t\t\t\t\tEmblemCost = {0}", emblem);
                    //propCount++;
                }
                if (!String.IsNullOrEmpty(image))
                {
                    item.ImageUri = image;
                    //if (propCount > 0) sb.Append(",").AppendLine();
                    //sb.AppendFormat("\t\t\t\t\tImageUri = \"{0}\"", image);
                    //propCount++;
                }
                if (!String.IsNullOrEmpty(durability))
                {
                    item.DurabilityMax = item.Durability = Convert.ToInt32(durability);
                    //if (propCount > 0) sb.Append(",").AppendLine();
                    //sb.AppendFormat("\t\t\t\t\tDurability = {0}", durability);
                    //propCount++;
                }
                if (!String.IsNullOrEmpty(affects))
                {
                    // Affects Format - <AffectName>=1 | Strength=1
                    foreach (var affect in affects.Replace("\"", "").Split('|'))
                    {
                        string[] pairs = affect.Split('=');
                        if (pairs != null && pairs.Length == 2)
                        {
                            item.Affects[(AttributeType)Enum.Parse(typeof(AttributeType), pairs[0], true)] = Convert.ToInt32(pairs[1]);
                        }
                    }
                }
                if (customProps.Count > 0)
                {
                    foreach (var p in customProps)
                    {
                        item.Properties.SetValue(p.Name, p.Value);
                        //if (propCount > 0) sb.Append(",").AppendLine();
                        //sb.AppendFormat("\t\t\t\t\t{0} = {1}", item.Name, item.GetValue());
                        //propCount++;
                    }
                }

                provider.SaveActor <Item>(item);
            }
        }