public AddToItemPage(ShopViewModel model, MagicProperty mp)
 {
     InitializeComponent();
     Model          = model;
     Property       = mp;
     BindingContext = this;
     Title          = Property.Name;
     UpdateItems();
 }
Exemplo n.º 2
0
        public IEnumerable <Feature> CollectOnUse(int level, IChoiceProvider provider)
        {
            List <Feature> result = new List <Feature>();

            foreach (string mp in MagicProperties)
            {
                result.AddRange(MagicProperty.Get(mp, null).CollectOnUse(level, provider, Attuned));
            }
            return(result);
        }
 public static Bitmap GetImage(this MagicProperty o)
 {
     if (o.ImageData == null)
     {
         return(null);
     }
     else
     {
         using (MemoryStream ms = new MemoryStream(o.ImageData)) return(new Bitmap(ms));
     }
 }
Exemplo n.º 4
0
        public IEnumerable <Feature> Collect(int level, IChoiceProvider provider, bool pretendEquipped = false)
        {
            List <Feature> result = new List <Feature>();
            bool           equip  = !EquipSlot.None.Equals(Equipped, StringComparison.InvariantCultureIgnoreCase);

            foreach (string mp in MagicProperties)
            {
                result.AddRange(MagicProperty.Get(mp, null).Collect(level, equip || pretendEquipped, Attuned, provider));
            }
            return(result);
        }
Exemplo n.º 5
0
        public override string ToString()
        {
            string name = Name;

            if (name == null || name == "")
            {
                name = Item.Get(BaseItem, null).Name;
            }
            foreach (string mp in MagicProperties)
            {
                name = MagicProperty.Get(mp, null).getName(name);
            }
            if (Count > 1)
            {
                name = name + " (" + Count + (Item != null && Item.Unit != null ? " " + Item.Unit : "") + ")";
            }
            else if (Count == 1 && Item != null && Item.SingleUnit != null)
            {
                name = name + " (" + Item.SingleUnit + ")";
            }
            else if (Count == 1 && Item != null && Item.Unit != null)
            {
                name = name + "(" + Count + " " + Item.Unit + ")";
            }
            if (Count == 0)
            {
                name = name + " (lost)";
            }
            if (Attuned)
            {
                name = name + " (attuned)";
            }
            if (string.Equals(Equipped, EquipSlot.Armor, StringComparison.InvariantCultureIgnoreCase))
            {
                name = name + " (worn)";
            }
            else if (string.Equals(Equipped, EquipSlot.MainHand, StringComparison.InvariantCultureIgnoreCase))
            {
                name = name + " (main hand)";
            }
            else if (string.Equals(Equipped, EquipSlot.OffHand, StringComparison.InvariantCultureIgnoreCase))
            {
                name = name + " (off hand)";
            }
            else if (!string.Equals(Equipped, EquipSlot.None, StringComparison.InvariantCultureIgnoreCase))
            {
                name = name + " (" + Equipped + ")";
            }
            if (ChargesUsed > 0)
            {
                name = name + " (" + ChargesUsed + " charges used)";
            }
            return(name);
        }
Exemplo n.º 6
0
        private void editMagic(object sender, EventArgs e)
        {
            if (magicBox.SelectedItem == null)
            {
                return;
            }
            MagicProperty selected = (MagicProperty)magicBox.SelectedItem;
            MagicForm     r        = new MagicForm(selected.Clone());

            r.Saved += MagicSaved;
            r.Show();
        }
Exemplo n.º 7
0
 public bool Redo()
 {
     if (RedoBuffer.Count > 0)
     {
         lastid = "";
         UndoBuffer.AddLast(cls);
         cls = RedoBuffer.Last.Value;
         RedoBuffer.RemoveLast();
         UnsavedChanges++;
         refresh();
         return(true);
     }
     return(false);
 }
 public static void SetImage(this MagicProperty o, Bitmap value)
 {
     if (value == null)
     {
         o.ImageData = null;
     }
     else
     {
         using (MemoryStream ms = new MemoryStream())
         {
             value.Save(ms, ImageFormat.Png);
             o.ImageData = ms.ToArray();
         }
     }
 }
Exemplo n.º 9
0
        private void Magic_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (magicBox.SelectedItem == null)
            {
                return;
            }
            MagicProperty selected = (MagicProperty)magicBox.SelectedItem;

            if (selected != null)
            {
                preview.Navigate("about:blank");
                preview.Document.OpenNew(true);
                preview.Document.Write(selected.ToHTML());
                preview.Refresh();
            }
        }
Exemplo n.º 10
0
 public bool Undo()
 {
     if (UndoBuffer.Count > 0)
     {
         lastid = "";
         RedoBuffer.AddLast(cls);
         cls = UndoBuffer.Last.Value;
         UndoBuffer.RemoveLast();
         if (UnsavedChanges > 0)
         {
             UnsavedChanges--;
         }
         refresh();
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
        private void NewMagicProp_Click(object sender, EventArgs e)
        {
            if (magicCatBox.SelectedItem == null)
            {
                return;
            }
            MagicProperty i = new MagicProperty()
            {
                Source = Program.Context.Config.DefaultSource
            };
            string cat = (string)magicCatBox.SelectedItem;

            i.Category = cat;
            MagicForm r = new MagicForm(i);

            r.Saved += MagicSaved;
            r.Show();
        }
Exemplo n.º 12
0
 public Possession(Possession p, MagicProperty magic)
 {
     Name        = p.Name;
     Description = p.Description;
     Count       = 1;
     BaseItem    = p.BaseItem;
     if (Item != null)
     {
         Count = Item.StackSize;
     }
     Equipped        = EquipSlot.None;
     Attuned         = false;
     ChargesUsed     = 0;
     Hightlight      = false;
     MagicProperties = new List <string>(p.MagicProperties);
     MagicProperties.Add(magic.Name + " " + ConfigManager.SourceSeperator + " " + magic.Source);
     Weight = -1;
 }
Exemplo n.º 13
0
 public Possession(Item Base, MagicProperty magic)
 {
     Name        = "";
     Description = "";
     Count       = 1;
     BaseItem    = "";
     if (Base != null)
     {
         BaseItem = Base.Name + " " + ConfigManager.SourceSeperator + " " + Base.Source;
     }
     Equipped        = EquipSlot.None;
     Attuned         = false;
     ChargesUsed     = 0;
     Hightlight      = false;
     MagicProperties = new List <string>()
     {
         magic.Name + " " + ConfigManager.SourceSeperator + " " + magic.Source
     };
     Weight = -1;
 }
Exemplo n.º 14
0
        public static bool Save(this MagicProperty mp, Boolean overwrite)
        {
            mp.Name = mp.Name.Replace(ConfigManager.SourceSeperator, '-');
            MagicProperty o = null;

            if (Program.Context.Magic.ContainsKey(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source))
            {
                o = Program.Context.Magic[mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source];
            }
            if (o != null && o.Category != mp.Category)
            {
                throw new Exception("Magic Property needs a unique name");
            }
            FileInfo file = SourceManager.GetFileName(mp.Name, mp.Source, ImportExtensions.MagicPropertyCleanname(Program.Context, mp.Category));

            if (file.Exists && (mp.FileName == null || !mp.FileName.Equals(file.FullName)) && !overwrite)
            {
                return(false);
            }
            using (TextWriter writer = new StreamWriter(file.FullName)) MagicProperty.Serializer.Serialize(writer, mp);
            mp.FileName = file.FullName;
            return(true);
        }
Exemplo n.º 15
0
 public MagicForm(MagicProperty cls)
 {
     InitializeComponent();
     this.cls             = cls;
     userControl11.Editor = this;
     imageChooser1.Image  = this;
     refresh();
     Attuned.HistoryManager         = this;
     Equipped.HistoryManager        = this;
     Carried.HistoryManager         = this;
     OnUse.HistoryManager           = this;
     AttunedEquipped.HistoryManager = this;
     AttunedOnUse.HistoryManager    = this;
     imageChooser1.History          = this;
     foreach (Slot s in Enum.GetValues(typeof(Slot)))
     {
         Slot.Items.Add(s);
     }
     foreach (Rarity s in Enum.GetValues(typeof(Rarity)))
     {
         Rarity.Items.Add(s);
     }
     Program.Context.ImportItems();
 }
Exemplo n.º 16
0
        private bool PropertyIsAttributeDefinedId(MagicProperty idPropertyCandidate)
        {
            if (idPropertyCandidate.Property == null)
            {
                return false;
            }

            if (HasMongoIdentifierAttribute(idPropertyCandidate.Property))
            {
                return true;
            }

            if (_interfaceProperties != null)
            {
                var interfacePropertiesWithSameNameAsCandidate = _interfaceProperties.Where(propertyInfo => propertyInfo.Name == idPropertyCandidate.Name);
                foreach (PropertyInfo nextProperty in interfacePropertiesWithSameNameAsCandidate)
                {
                    if (HasMongoIdentifierAttribute(nextProperty))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Exemplo n.º 17
0
 /// <summary>
 /// Determines if the Id has been explicitly defined in a MongoConfigurationMap <see cref="MongoConfigurationMap"/>.
 /// </summary>
 /// <param retval="idPropertyCandidate">The property name.</param>
 private bool PropertyIsExplicitlyMappedToId(MagicProperty idPropertyCandidate)
 {
     var map = MongoTypeConfiguration.GetPropertyOrEmptyMap(_type);
     if (map.ContainsKey(idPropertyCandidate.Name))
     {
         return map[idPropertyCandidate.Name].IsId;
     }
     return false;
 }
Exemplo n.º 18
0
        public static async Task ImportMagicAsync(this OGLContext context)
        {
            context.Magic.Clear();
            context.MagicCategories.Clear();
            context.MagicCategories.Add("Magic", new MagicCategory("Magic", "Magic", 0));
            context.MagicSimple.Clear();
            var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Magic_Directory, true).ConfigureAwait(false);

            foreach (var f in files)
            {
                try
                {
                    Uri    source = new Uri(PCLSourceManager.GetDirectory(f.Value, context.Config.Magic_Directory));
                    Uri    target = new Uri(PCLSourceManager.Parent(f.Key));
                    string cat    = MagicPropertyCleanname(context, Uri.UnescapeDataString(source.MakeRelativeUri(target).ToString()));
                    if (!context.MagicCategories.ContainsKey(cat))
                    {
                        context.MagicCategories.Add(cat, MakeMagicCategory(cat));
                    }
                    String parent = PCLSourceManager.Parent(cat);
                    while (parent.StartsWith(context.Config.Magic_Directory) && !context.MagicCategories.ContainsKey(parent))
                    {
                        context.MagicCategories.Add(parent, MakeMagicCategory(parent));
                        parent = PCLSourceManager.Parent(parent);
                    }
                    using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false))
                    {
                        MagicProperty mp = ((MagicProperty)MagicProperty.Serializer.Deserialize(reader));
                        mp.Filename = f.Key.Path;
                        mp.Source   = f.Value;
                        foreach (Feature fea in mp.AttunementFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        foreach (Feature fea in mp.CarryFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        foreach (Feature fea in mp.OnUseFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        foreach (Feature fea in mp.EquipFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        mp.Category = cat;
                        context.MagicCategories[cat].Contents.Add(mp);
                        if (context.Magic.ContainsKey(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source))
                        {
                            throw new Exception("Duplicate Magic Property: " + mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source);
                        }
                        if (context.MagicSimple.ContainsKey(mp.Name))
                        {
                            context.MagicSimple[mp.Name].ShowSource = true;
                            mp.ShowSource = true;
                        }
                        context.Magic.Add(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source, mp);
                        context.MagicSimple[mp.Name] = mp;
                    }
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + f.ToString(), e);
                }

                //Collections[].AddRange(feats);
            }
        }
Exemplo n.º 19
0
        public static void ImportMagic(this OGLContext context)
        {
            if (context == null || context.Config == null)
            {
                return;
            }
            context.Magic.Clear();
            context.MagicCategories.Clear();
            context.MagicCategories.Add("Magic", new MagicCategory("Magic", "Magic", 0));
            context.MagicSimple.Clear();
            var files = SourceManager.EnumerateFiles(context, context.Config.Magic_Directory, SearchOption.AllDirectories);

            foreach (var f in files)
            {
                try
                {
                    Uri    source = new Uri(SourceManager.GetDirectory(f.Value, context.Config.Magic_Directory).FullName);
                    Uri    target = new Uri(f.Key.DirectoryName);
                    string cat    = MagicPropertyCleanname(context, Uri.UnescapeDataString(source.MakeRelativeUri(target).ToString()));
                    if (!context.MagicCategories.ContainsKey(cat))
                    {
                        context.MagicCategories.Add(cat, MakeMagicCategory(cat));
                    }
                    String parent = Path.GetDirectoryName(cat);
                    while (parent.IsSubPathOf(context.Config.Magic_Directory) && !context.MagicCategories.ContainsKey(parent))
                    {
                        context.MagicCategories.Add(parent, MakeMagicCategory(parent));
                        parent = Path.GetDirectoryName(parent);
                    }
                    using (TextReader reader = new StreamReader(f.Key.FullName))
                    {
                        MagicProperty mp = ((MagicProperty)MagicProperty.Serializer.Deserialize(reader));
                        mp.FileName = f.Key.FullName;
                        mp.Source   = f.Value;
                        foreach (Feature fea in mp.AttunementFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        foreach (Feature fea in mp.CarryFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        foreach (Feature fea in mp.OnUseFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        foreach (Feature fea in mp.EquipFeatures)
                        {
                            fea.Source = f.Value;
                        }
                        mp.Category = cat;
                        context.MagicCategories[cat].Contents.Add(mp);
                        if (context.Magic.ContainsKey(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source))
                        {
                            throw new Exception("Duplicate Magic Property: " + mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source);
                        }
                        if (context.MagicSimple.ContainsKey(mp.Name))
                        {
                            context.MagicSimple[mp.Name].ShowSource = true;
                            mp.ShowSource = true;
                        }
                        context.Magic.Add(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source, mp);
                        context.MagicSimple[mp.Name] = mp;
                    }
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + f.ToString(), e);
                }

                //Collections[].AddRange(feats);
            }
        }
Exemplo n.º 20
0
 private void AddCandidate(MagicProperty property)
 {
     if (PropertyIsExplicitlyMappedToId(property))
     {
         _idDictionary[IdType.MapDefined] = property;
     }
     else if (PropertyIsAttributeDefinedId(property))
     {
         _idDictionary[IdType.AttributeDefined] = property;
     }
     else if (property.Name.Equals("_id", StringComparison.InvariantCultureIgnoreCase))
     {
         _idDictionary[IdType.MongoDefault] = property;
     }
     else if (property.Name.Equals("Id", StringComparison.InvariantCultureIgnoreCase))
     {
         _idDictionary[IdType.Conventional] = property;
     }
 }