Esempio n. 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (_selected == null)
            {
                _selected = new NPCEquipment
                {
                    TemplateID = _templateId,
                    ObjectId   = null
                };
                _equipment.Add(_selected);
            }

            BindingService.SyncData(_selected, this);

            // template id has changed
            if (!string.IsNullOrWhiteSpace(_selected.TemplateID) && _selected.TemplateID != _templateId)
            {
                _equipment.ForEach(x =>
                {
                    x.TemplateID = _selected.TemplateID;
                    _npcEquipmentService.Save(x);
                });

                LoadItems(_selected.TemplateID);
                return;
            }

            var templateId = _npcEquipmentService.Save(_selected);

            LoadItems(templateId);
        }
Esempio n. 2
0
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            BindingService.ClearData(this);
            pictureBox1.Image = null;
            _TemplateID.Text  = _templateId;

            var selected = GetSelected();

            if (selected == null)
            {
                _selected = null;
                return;
            }

            groupBox1.Text     = selected.Value;
            _Slot.SelectedItem = _Slot.Items.Cast <ComboboxService.SelectItemModel>().First(x => x.Id == selected.SlotId);

            if (selected.Item == null)
            {
                _selected = null;
                return;
            }

            _selected = selected.Item;
            BindingService.BindData(selected.Item, this);
            _imageService.LoadItem(selected.Item.Model, pictureBox1.Width, pictureBox1.Height)
            .ContinueWith(x => _imageService.AttachImage(pictureBox1, x));
        }
        public string Save(NPCEquipment template)
        {
            if (string.IsNullOrWhiteSpace(template.TemplateID))
            {
                template.TemplateID = IDGenerator.GenerateID();
            }

            if (string.IsNullOrWhiteSpace(template.ObjectId))
            {
                if (string.IsNullOrWhiteSpace(template.TemplateID))
                {
                    template.ObjectId = IDGenerator.GenerateID();
                }

                DatabaseManager.Database.AddObject(template);
                return(template.TemplateID);
            }

            DatabaseManager.Database.SaveObject(template);
            return(template.TemplateID);
        }
        /// <summary>
        /// Save the inventory template to Database
        /// </summary>
        /// <returns>success</returns>
        public override bool SaveIntoDatabase(string templateID)
        {
            lock (m_items)
            {
                try
                {
                    if (templateID == null)
                    {
                        throw new ArgumentNullException("templateID");
                    }

                    var npcEquipment = DOLDB <NPCEquipment> .SelectObjects(DB.Column(nameof(NPCEquipment.TemplateID)).IsEqualTo(templateID));

                    // delete removed item templates
                    foreach (NPCEquipment npcItem in npcEquipment)
                    {
                        if (!m_items.ContainsKey((eInventorySlot)npcItem.Slot))
                        {
                            GameServer.Database.DeleteObject(npcItem);
                        }
                    }

                    // save changed item templates
                    foreach (InventoryItem item in m_items.Values)
                    {
                        bool foundInDB = false;
                        foreach (NPCEquipment npcItem in npcEquipment)
                        {
                            if (item.SlotPosition != npcItem.Slot)
                            {
                                continue;
                            }

                            if (item.Model != npcItem.Model || item.Color != npcItem.Color || item.Effect != npcItem.Effect || item.Emblem != npcItem.Emblem)
                            {
                                npcItem.Model     = item.Model;
                                npcItem.Color     = item.Color;
                                npcItem.Effect    = item.Effect;
                                npcItem.Extension = item.Extension;
                                npcItem.Emblem    = item.Emblem;
                                GameServer.Database.SaveObject(npcItem);
                            }

                            foundInDB = true;

                            break;
                        }

                        if (!foundInDB)
                        {
                            NPCEquipment npcItem = new NPCEquipment();
                            npcItem.Slot       = item.SlotPosition;
                            npcItem.Model      = item.Model;
                            npcItem.Color      = item.Color;
                            npcItem.Effect     = item.Effect;
                            npcItem.TemplateID = templateID;
                            npcItem.Extension  = item.Extension;
                            npcItem.Emblem     = item.Emblem;
                            GameServer.Database.AddObject(npcItem);
                        }
                    }

                    return(true);
                }
                catch (Exception e)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("Error saving NPC inventory template, templateID=" + templateID, e);
                    }

                    return(false);
                }
            }
        }