示例#1
0
        public override void SaveToDatabase(MapleCharacter owner)
        {
            base.SaveToDatabase(owner);
            if (owner == null)
            {
                return;                //delete is handled in base function
            }
            InventoryEquip dbActionEquip;

            using (LeattyContext dbContext = new LeattyContext())
            {
                dbActionEquip = dbContext.InventoryEquips.FirstOrDefault(x => x.InventoryItemId == DbId);
                if (dbActionEquip == null)
                {
                    dbActionEquip = new InventoryEquip {
                        InventoryItemId = DbId
                    };
                    dbContext.InventoryEquips.Add(dbActionEquip);
                    dbContext.SaveChanges();
                }
            }

            dbActionEquip.RemainingUpgradeCount = RemainingUpgradeCount;
            dbActionEquip.UpgradeCount          = UpgradeCount;
            dbActionEquip.Str             = Str;
            dbActionEquip.Dex             = Dex;
            dbActionEquip.Int             = Int;
            dbActionEquip.IncMhp          = IncMhp;
            dbActionEquip.IncMmp          = IncMmp;
            dbActionEquip.Pad             = Pad;
            dbActionEquip.Mad             = Mad;
            dbActionEquip.Pdd             = Pdd;
            dbActionEquip.Mdd             = Mdd;
            dbActionEquip.Acc             = Acc;
            dbActionEquip.Eva             = Eva;
            dbActionEquip.Speed           = Speed;
            dbActionEquip.Jump            = Jump;
            dbActionEquip.Durability      = Durability;
            dbActionEquip.HammerApplied   = HammersApplied;
            dbActionEquip.Enhancements    = Enhancements;
            dbActionEquip.Diligence       = Diligence;
            dbActionEquip.Potential1      = (short)Potential1;
            dbActionEquip.Potential2      = (short)Potential2;
            dbActionEquip.Potential3      = (short)Potential3;
            dbActionEquip.BonusPotential1 = (short)BonusPotential1;
            dbActionEquip.BonusPotential2 = (short)BonusPotential2;
            dbActionEquip.Socket1         = Socket1;
            dbActionEquip.Socket2         = Socket2;
            dbActionEquip.Socket3         = Socket3;
            dbActionEquip.CustomLevel     = CustomLevel;
            dbActionEquip.CustomExp       = CustomExp;
            dbActionEquip.PotentialState  = (byte)PotentialState;
            using (LeattyContext dbContext = new LeattyContext())
            {
                dbContext.Entry(dbActionEquip).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }
示例#2
0
 /// <param name="owner">if equal to null, deletes the item from the database</param>
 public virtual void SaveToDatabase(MapleCharacter owner)
 {
     using (LeattyContext dbContext = new LeattyContext())
     {
         if (owner == null)
         {
             if (InventoryType == MapleInventoryType.Equip)
             {
                 InventoryEquip equipEntry = dbContext.InventoryEquips.FirstOrDefault(x => x.Id == DbId);
                 if (equipEntry != null)
                 {
                     dbContext.InventoryEquips.Remove(equipEntry);
                 }
             }
             InventoryItem entry = dbContext.InventoryItems.FirstOrDefault(x => x.Id == DbId);
             if (entry != null)
             {
                 dbContext.InventoryItems.Remove(entry);
             }
             DbId = -1;
         }
         else
         {
             InventoryItem dbActionItem = null;
             if (DbId != -1)
             {
                 dbActionItem = dbContext.InventoryItems.FirstOrDefault(x => x.Id == DbId);
             }
             if (dbActionItem == null)
             {
                 dbActionItem = new InventoryItem();
                 dbContext.InventoryItems.Add(dbActionItem);
                 dbContext.SaveChanges();
                 DbId = dbActionItem.Id;
             }
             dbActionItem.CharacterId            = owner.Id;
             dbActionItem.ItemId                 = ItemId;
             dbActionItem.Position               = Position;
             dbActionItem.Quantity               = Quantity;
             dbActionItem.Source                 = Source;
             dbActionItem.Creator                = Creator;
             dbActionItem.Flags                  = (short)Flags;
             dbContext.Entry(dbActionItem).State = System.Data.Entity.EntityState.Modified;
         }
         dbContext.SaveChanges();
     }
 }
        public static void Handle(MapleClient c, PacketReader pr)
        {
            string enteredPic  = pr.ReadMapleString();
            int    characterId = pr.ReadInt();

            byte state = 20;

            if (c.Account.CheckPic(enteredPic) && c.Account.HasCharacter(characterId))
            {
                using (LeattyContext DBContext = new LeattyContext())
                {
                    //Do delete stuff
                    List <InventoryItem>  ItemsToDelete  = DBContext.InventoryItems.Where(x => x.CharacterId == characterId).ToList();
                    List <InventoryEquip> EquipsToDelete = new List <InventoryEquip>();
                    foreach (InventoryItem ItemToDelete in ItemsToDelete)
                    {
                        InventoryEquip EquipToDelete = DBContext.InventoryEquips.SingleOrDefault(x => x.InventoryItemId == ItemToDelete.Id);
                        if (EquipToDelete != null)
                        {
                            EquipsToDelete.Add(EquipToDelete);
                        }
                    }
                    DBContext.InventoryItems.RemoveRange(ItemsToDelete);
                    DBContext.InventoryEquips.RemoveRange(EquipsToDelete);
                    DBContext.InventorySlots.RemoveRange(DBContext.InventorySlots.Where(x => x.CharacterId == characterId));
                    DBContext.KeyMaps.RemoveRange(DBContext.KeyMaps.Where(x => x.CharacterId == characterId));
                    DBContext.QuickSlotKeyMaps.RemoveRange(DBContext.QuickSlotKeyMaps.Where(x => x.CharacterId == characterId));
                    DBContext.StolenSkills.RemoveRange(DBContext.StolenSkills.Where(x => x.CharacterId == characterId));

                    DBContext.Characters.Remove(DBContext.Characters.SingleOrDefault(x => x.Id == characterId));


                    DBContext.SaveChanges();
                }

                state = 0;
            }

            //Response
            PacketWriter pw = new PacketWriter();

            pw.WriteHeader(SendHeader.DeleteCharacter);
            pw.WriteInt(characterId);
            pw.WriteByte(state);
            c.SendPacket(pw);
        }
    public void AddArmor(Item item)
    {
        if (_armor.ID != "")
        {
            GameObject.FindGameObjectWithTag("Persistent").GetComponent <PersistentScript>().IncreaseItemCount(_armor.ID, 1);

            InventoryEquip button = GetButtonWithID(_armor.ID);
            if (button != null)
            {
                button.UpdateCount(GameObject.FindGameObjectWithTag("Persistent").GetComponent <PersistentScript>().CheckItemQuantity(_armor.ID));
            }
            else
            {
                GameObject.FindGameObjectWithTag("Persistent").GetComponent <PersistentScript>().AddItemBackToInventory(_armor.ID);
            }
        }
        _armor = item;
        UpdateInventory();
    }
        public static EntityComponentMessage AddItem(ProtoItem item, int Amount, bool isQuickSlot = false,
                                                     bool simulateCraft = false)
        {
            if (Player.Local == null && !Player.Local.IsConnected)
            {
                return(null);
            }
            var inventory = Player.Local.Inventory;
            var num       = ItemStack.MaxStackCountForProtoItem(item);
            var num2      = Amount >= num ? num : Amount;
            var itemStack = new ItemStack(item, num2);

            if (!ContainsItem(item, isQuickSlot))
            {
                var num3         = isQuickSlot ? inventory.FirstEmptyQuickSlot() : inventory.GetFirstEmptySlot();
                var inventoryAdd = new InventoryAdd(inventory, num3, itemStack, isQuickSlot);
                inventory.SendToServer(inventoryAdd);
                inventory.OnComponentMessage(inventoryAdd);
                if (simulateCraft)
                {
                    AudioController.Play(Player.Local.Crafting.SfxCraft);
                    NotificationCenter.Default.PostNotification(Player.CraftedSomethingEvent, getProtoCraft(item));
                }

                if (inventoryAdd.Item.ProtoItem is ProtoItemEquipment)
                {
                    var protoItemEquipment = (ProtoItemEquipment)inventoryAdd.Item.ProtoItem;
                    var inventoryEquip     = new InventoryEquip(inventory, true, inventoryAdd.Slot, protoItemEquipment.Slot,
                                                                inventoryAdd.SlotIsQuickSlot);
                    inventory.SendToServer(inventoryEquip);
                    inventory.OnComponentMessage(inventoryEquip);
                }

                return(inventoryAdd);
            }

            short num4;

            if (tryGetItemIndexEnough(itemStack.ProtoItem, inventory, out num4, isQuickSlot))
            {
                var inventoryModified = new InventoryModified(inventory, num4, (short)num2, isQuickSlot);
                inventory.SendToServer(inventoryModified);
                inventory.OnComponentMessage(inventoryModified);
                if (simulateCraft)
                {
                    AudioController.Play(Player.Local.Crafting.SfxCraft);
                    NotificationCenter.Default.PostNotification(Player.CraftedSomethingEvent,
                                                                getProtoCraft(itemStack.ProtoItem));
                }

                return(inventoryModified);
            }

            if (!tryGetItemIndexEnough(itemStack.ProtoItem, inventory, out num4, isQuickSlot))
            {
                var inventoryAdd2 = new InventoryAdd(inventory, num4, itemStack, isQuickSlot);
                inventory.OnComponentMessage(inventoryAdd2);
                inventory.SendToServer(inventoryAdd2);
                if (simulateCraft)
                {
                    AudioController.Play(Player.Local.Crafting.SfxCraft);
                    NotificationCenter.Default.PostNotification(Player.CraftedSomethingEvent,
                                                                getProtoCraft(itemStack.ProtoItem));
                }

                if (inventoryAdd2.Item.ProtoItem is ProtoItemEquipment)
                {
                    var protoItemEquipment2 = (ProtoItemEquipment)inventoryAdd2.Item.ProtoItem;
                    var inventoryEquip2     = new InventoryEquip(inventory, true, inventoryAdd2.Slot,
                                                                 protoItemEquipment2.Slot, inventoryAdd2.SlotIsQuickSlot);
                    inventory.SendToServer(inventoryEquip2);
                    inventory.OnComponentMessage(inventoryEquip2);
                }

                return(inventoryAdd2);
            }

            return(null);
        }