示例#1
0
        private Inventory Update(Inventory entity, Inventory inventory)
        {

            var result = Inventory.SingleOrDefault(c => c.InventoryId == inventory.InventoryId);
            if (result != null)
            {
                Inventory.Remove(result);
                Inventory.Add(inventory);

            }


            return inventory;
        }
示例#2
0
        public void InsertOrUpdate(ref Inventory newInventory)
        {
            long inventoryId = newInventory.InventoryId;

            Inventory entity = Inventory.SingleOrDefault(c => c.InventoryId.Equals(inventoryId));

            if (entity == null) //new entity
            {
                newInventory = Insert(newInventory);
            }
            else //existing entity
            {
                newInventory = Update(entity, newInventory);
            }
        }
示例#3
0
        public Inventory CreateItem(InventoryItem newItem, Character character)
        {
            short Slot = -1;
            IEnumerable<InventoryItem> slotfree = null;
            Inventory inv = null;
            if (ServerManager.GetItem(newItem.ItemVNum).Type != 0)
            {
                slotfree = character.LoadBySlotAllowed(newItem.ItemVNum, newItem.Amount);
                inv = getFirstSlot(slotfree);
            }
            bool modified = false;
            Inventory newInventory = null;
            if (inv != null)
            {
                Slot = inv.Slot;
                newItem.Amount = (short)(newItem.Amount + inv.InventoryItem.Amount);
                modified = true;
            }
            else
                Slot = getFirstPlace(ServerManager.GetItem(newItem.ItemVNum).Type, character.BackPack, newItem);
            if (Slot != -1)
            {

                if (modified == false)
                    newInventory = new Inventory()
                    {
                        CharacterId = character.CharacterId,
                        InventoryItemId = newItem.InventoryItemId,
                        Slot = Slot,
                        Type = ServerManager.GetItem(newItem.ItemVNum).Type,
                        InventoryItem = newItem,
                        InventoryId = generateInventoryId(),
                    };
                else
                    newInventory = new Inventory()
                    {
                        CharacterId = character.CharacterId,
                        InventoryItemId = newItem.InventoryItemId,
                        Slot = Slot,
                        Type = ServerManager.GetItem(newItem.ItemVNum).Type,
                        InventoryItem = newItem,
                        InventoryId = inv.InventoryId,
                    };
                InsertOrUpdate(ref newInventory);

            }
            return newInventory;
        }
示例#4
0
 private Inventory Insert(Inventory inventory)
 {
     Inventory entity = inventory;
     Inventory.Add(entity);
     return entity;
 }
示例#5
0
        public MapItem PutItem(ClientSession Session, short type, short slot, short amount, out Inventory inv)
        {
            Random rnd = new Random();
            int random = 0;
            inv = Session.Character.InventoryList.LoadBySlotAndType(slot, type);
            MapItem DroppedItem = null;
            if (amount <= inv.InventoryItem.Amount)
            {
                DroppedItem = new MapItem((short)(rnd.Next(Session.Character.MapX - 2, Session.Character.MapX + 3)), (short)(rnd.Next(Session.Character.MapY - 2, Session.Character.MapY + 3)))
                {
                    Amount = amount,
                    Color = inv.InventoryItem.Color,
                    Concentrate = inv.InventoryItem.Concentrate,
                    CriticalLuckRate = inv.InventoryItem.CriticalLuckRate,
                    CriticalRate = inv.InventoryItem.CriticalRate,
                    DamageMaximum = inv.InventoryItem.DamageMaximum,
                    DamageMinimum = inv.InventoryItem.DamageMinimum,
                    DarkElement = inv.InventoryItem.DarkElement,
                    DistanceDefence = inv.InventoryItem.DistanceDefence,
                    DefenceDodge = inv.InventoryItem.DefenceDodge,
                    DistanceDefenceDodge = inv.InventoryItem.DistanceDefenceDodge,
                    ElementRate = inv.InventoryItem.ElementRate,
                    FireElement = inv.InventoryItem.FireElement,
                    HitRate = inv.InventoryItem.HitRate,
                    WaterElement = inv.InventoryItem.WaterElement,
                    SlHit = inv.InventoryItem.SlHit,
                    ItemVNum = inv.InventoryItem.ItemVNum,
                    LightElement = inv.InventoryItem.LightElement,
                    MagicDefence = inv.InventoryItem.MagicDefence,
                    RangeDefence = inv.InventoryItem.RangeDefence,
                    Rare = inv.InventoryItem.Rare,
                    SlDefence = inv.InventoryItem.SlDefence,
                    SlElement = inv.InventoryItem.SlElement,
                    SlHP = inv.InventoryItem.SlHP,
                    Upgrade = inv.InventoryItem.Upgrade
                };
                while (Session.CurrentMap.DroppedList.ContainsKey(random = rnd.Next(1, 999999)))
                { }
                DroppedItem.InventoryItemId = random;
                Session.CurrentMap.DroppedList.Add(random, DroppedItem);
                inv.InventoryItem.Amount = (short)(inv.InventoryItem.Amount - amount);
                Session.Character.InventoryList.InsertOrUpdate(ref inv);

            }
            return DroppedItem;
        }
示例#6
0
        public void MoveItem(Character character, short type, short slot, short amount, short destslot, out Inventory inv, out Inventory invdest)
        {
            inv = LoadBySlotAndType(slot, type);
            invdest = LoadBySlotAndType(destslot, type);
            if (amount <= inv.InventoryItem.Amount)
            {
                if (invdest == null)
                {
                    if (inv.InventoryItem.Amount == amount)
                    {
                        inv.Slot = destslot;
                        InsertOrUpdate(ref inv);
                    }
                    else
                    {
                        inv.InventoryItem.Amount = (short)(inv.InventoryItem.Amount - amount);

                        InventoryItem itemDest = new InventoryItem
                        {
                            Amount = amount,
                            Color = inv.InventoryItem.Color,
                            Concentrate = inv.InventoryItem.Concentrate,
                            CriticalLuckRate = inv.InventoryItem.CriticalLuckRate,
                            CriticalRate = inv.InventoryItem.CriticalRate,
                            DamageMaximum = inv.InventoryItem.DamageMaximum,
                            DamageMinimum = inv.InventoryItem.DamageMinimum,
                            DarkElement = inv.InventoryItem.DarkElement,
                            DistanceDefence = inv.InventoryItem.DistanceDefence,
                            DistanceDefenceDodge = inv.InventoryItem.DistanceDefenceDodge,
                            DefenceDodge = inv.InventoryItem.DefenceDodge,
                            ElementRate = inv.InventoryItem.ElementRate,
                            FireElement = inv.InventoryItem.FireElement,
                            HitRate = inv.InventoryItem.HitRate,
                            ItemVNum = inv.InventoryItem.ItemVNum,
                            LightElement = inv.InventoryItem.LightElement,
                            MagicDefence = inv.InventoryItem.MagicDefence,
                            RangeDefence = inv.InventoryItem.RangeDefence,
                            Rare = inv.InventoryItem.Rare,
                            SlDefence = inv.InventoryItem.SlDefence,
                            SlElement = inv.InventoryItem.SlElement,
                            SlHit = inv.InventoryItem.SlHit,
                            SlHP = inv.InventoryItem.SlHP,
                            Upgrade = inv.InventoryItem.Upgrade,
                            WaterElement = inv.InventoryItem.WaterElement,
                            InventoryItemId = generateInventoryItemId(),

                        };

                        InsertOrUpdate(ref inv);

                        Inventory invDest = new Inventory
                        {
                            CharacterId = character.CharacterId,
                            InventoryItemId = itemDest.InventoryItemId,
                            Slot = destslot,
                            Type = inv.Type,
                            InventoryId = generateInventoryId(),
                            InventoryItem = itemDest,
                        };
                        InsertOrUpdate(ref invDest);
                        invdest = invDest;
                    }

                }
                else
                {

                    if (invdest.InventoryItem.ItemVNum == inv.InventoryItem.ItemVNum && inv.Type != 0)
                    {

                        if (invdest.InventoryItem.Amount + amount > 99)
                        {
                            short saveItemCount = invdest.InventoryItem.Amount;
                            invdest.InventoryItem.Amount = 99;
                            inv.InventoryItem.Amount = (short)(saveItemCount + inv.InventoryItem.Amount - 99);

                            InsertOrUpdate(ref inv);
                            InsertOrUpdate(ref invdest);

                        }
                        else
                        {
                            short saveItemCount = invdest.InventoryItem.Amount;
                            invdest.InventoryItem.Amount = (short)(saveItemCount + amount);
                            inv.InventoryItem.Amount = (short)(inv.InventoryItem.Amount - amount);
                            InsertOrUpdate(ref inv);
                            InsertOrUpdate(ref invdest);

                        }
                    }
                    else
                    {
                        invdest.Slot = inv.Slot;
                        inv.Slot = 99;
                        InsertOrUpdate(ref inv);
                        InsertOrUpdate(ref invdest);
                        inv.Slot = destslot;
                        InsertOrUpdate(ref inv);
                    }
                }
            }
            inv = LoadBySlotAndType(slot, type);
            invdest = LoadBySlotAndType(destslot, type);
        }
示例#7
0
        public void UpgradeItem(Inventory item, InventoryItem.UpgradeMode mode, InventoryItem.UpgradeProtection protection)
        {
            if (item.InventoryItem.Upgrade < 10)
            {
                short[] upsuccess = { 100, 100, 90, 80, 60, 40, 20, 10, 5, 1 };
                short[] upfix = { 0, 0, 10, 15, 20, 20, 20, 20, 15, 10 };

                //short itempricevnum1 = 0;
                //short itempricevnum2 = 0;
                short goldprice = 500;
                double reducedpricefactor = 0.5;

                switch (mode)
                {
                    case InventoryItem.UpgradeMode.Free:
                        break;

                    case InventoryItem.UpgradeMode.Reduced:
                        //TODO: Reduced Item Amount
                        Session.Character.Gold = Session.Character.Gold - (long)(goldprice * reducedpricefactor);
                        break;

                    case InventoryItem.UpgradeMode.Normal:
                        //TODO: Normal Item Amount
                        Session.Character.Gold = Session.Character.Gold - goldprice;
                        break;
                }

                Random r = new Random();
                int rnd = r.Next(100);
                if (rnd <= upsuccess[item.InventoryItem.Upgrade])
                {
                    Session.Client.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_SUCCESS"), 12));
                    Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_SUCCESS"), 0));
                    Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                    Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Upgrade++;
                    Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
                }
                else if (rnd <= upfix[item.InventoryItem.Upgrade])
                {
                    Session.Client.SendPacket(Session.Character.GenerateEff(3004));
                    Session.Client.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_FIXED"), 11));
                    Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FIXED"), 0));
                }
                else
                {
                    if (protection == InventoryItem.UpgradeProtection.None)
                    {
                        Session.Client.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_FAILED"), 11));
                        Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FAILED"), 0));
                        DeleteItem(item.Type, item.Slot);
                    }
                    else
                    {
                        Session.Client.SendPacket(Session.Character.GenerateEff(3004));
                        Session.Client.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_FAILED_ITEM_SAVED"), 11));
                        Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FAILED_ITEM_SAVED"), 0));
                    }
                }
            }
            else
            {
                Session.Client.SendPacket(Session.Character.GenerateEff(3004));
                Session.Client.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_FAILED_ITEM_SAVED"), 11));
                Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FAILED_ITEM_SAVED"), 0));
            }
        }
示例#8
0
        public void sortopen(string packet)
        {
            Boolean gravity = true;
            short type;
            while (gravity)
            {
                gravity = false;
                for (short x = 0; x < 44; x++)
                {
                    for (short i = 0; i < 2; i++)
                    {
                        type = (i == 0) ? (short)InventoryType.Sp : (short)InventoryType.Costume;
                        if (Session.Character.InventoryList.LoadBySlotAndType(x, type) == null)
                        {
                            if (Session.Character.InventoryList.LoadBySlotAndType((short)(x + 1), type) != null)
                            {
                                Inventory invdest = new Inventory();
                                Inventory inv = new Inventory();
                                Session.Character.InventoryList.MoveItem(Session.Character, type, (short)(x + 1), 1, x, out inv, out invdest);
                                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(invdest.InventoryItem.ItemVNum, invdest.InventoryItem.Amount, type, invdest.Slot, invdest.InventoryItem.Rare, invdest.InventoryItem.Color, invdest.InventoryItem.Upgrade));
                                DeleteItem(type, (short)(x + 1));

                                gravity = true;
                            }
                        }
                    }
                }
            }
        }
示例#9
0
        public void RarifyItem(Inventory item, InventoryItem.RarifyMode mode, InventoryItem.RarifyProtection protection)
        {
            double rare1 = 50;
            double rare2 = 35;
            double rare3 = 25;
            double rare4 = 10;
            double rare5 = 10;
            double rare6 = 5;
            double rare7 = 1;
            double reducedchancefactor = 1.1;

            //short itempricevnum = 0;
            short goldprice = 500;
            double reducedpricefactor = 0.5;

            if (protection == InventoryItem.RarifyProtection.RedAmulet)
            {
                rare1 = rare1 * reducedchancefactor;
                rare2 = rare2 * reducedchancefactor;
                rare3 = rare3 * reducedchancefactor;
                rare4 = rare4 * reducedchancefactor;
                rare5 = rare5 * reducedchancefactor;
                rare6 = rare6 * reducedchancefactor;
                rare7 = rare7 * reducedchancefactor;
            }
            switch (mode)
            {
                case InventoryItem.RarifyMode.Free:
                    break;

                case InventoryItem.RarifyMode.Reduced:
                    //TODO: Reduced Item Amount
                    Session.Character.Gold = Session.Character.Gold - (long)(goldprice * reducedpricefactor);
                    break;

                case InventoryItem.RarifyMode.Normal:
                    //TODO: Normal Item Amount
                    Session.Character.Gold = Session.Character.Gold - goldprice;
                    break;
            }

            Random r = new Random();
            int rnd = r.Next(100);
            if (rnd <= rare7 && !(protection == InventoryItem.RarifyProtection.Scroll && item.InventoryItem.Rare >= 7))
            {
                Session.Client.SendPacket(Session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 7), 12));
                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 7), 0));
                Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Rare = 7;
                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
            }
            else if (rnd <= rare6 && !(protection == InventoryItem.RarifyProtection.Scroll && item.InventoryItem.Rare >= 6))
            {
                Session.Client.SendPacket(Session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 6), 12));
                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 6), 0));
                Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Rare = 6;
                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
            }
            else if (rnd <= rare5 && !(protection == InventoryItem.RarifyProtection.Scroll && item.InventoryItem.Rare >= 5))
            {
                Session.Client.SendPacket(Session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 5), 12));
                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 5), 0));
                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
                Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Rare = 5;
            }
            else if (rnd <= rare4 && !(protection == InventoryItem.RarifyProtection.Scroll && item.InventoryItem.Rare >= 4))
            {
                Session.Client.SendPacket(Session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 4), 12));
                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 4), 0));
                Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Rare = 4;
                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
            }
            else if (rnd <= rare3 && !(protection == InventoryItem.RarifyProtection.Scroll && item.InventoryItem.Rare >= 3))
            {
                Session.Client.SendPacket(Session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 3), 12));
                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 3), 0));
                Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Rare = 3;
                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
            }
            else if (rnd <= rare2 && !(protection == InventoryItem.RarifyProtection.Scroll && item.InventoryItem.Rare >= 2))
            {
                Session.Client.SendPacket(Session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 2), 12));
                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 2), 0));
                Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Rare = 2;
                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
            }
            else if (rnd <= rare1 && !(protection == InventoryItem.RarifyProtection.Scroll && item.InventoryItem.Rare >= 1))
            {
                Session.Client.SendPacket(Session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 1), 12));
                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("RARIFY_SUCCESS"), 1), 0));
                Session.Client.SendPacket(Session.Character.GenerateEff(3005));
                Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.Rare = 1;
                Session.Client.SendPacket(Session.Character.GenerateInventoryAdd(item.InventoryItem.ItemVNum, item.InventoryItem.Amount, item.Type, item.Slot, item.InventoryItem.Rare, item.InventoryItem.Color, item.InventoryItem.Upgrade));
            }
            else
            {
                if (protection == InventoryItem.RarifyProtection.None)
                {
                    DeleteItem(item.Type, item.Slot);
                    Session.Client.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("RARIFY_FAILED"), 11));
                    Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("RARIFY_FAILED"), 0));
                }
                else
                {
                    Session.Client.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("RARIFY_FAILED_ITEM_SAVED"), 11));
                    Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("RARIFY_FAILED_ITEM_SAVED"), 0));
                    Session.Client.SendPacket(Session.Character.GenerateEff(3004));
                    Session.Character.InventoryList.LoadByInventoryItem(item.InventoryItemId).InventoryItem.IsFixed = true;

                }
            }
        }
示例#10
0
        public void LoadInventory()
        {
            IEnumerable<ItemInstanceDTO> inventories = DAOFactory.ItemInstanceDAO.LoadByCharacterId(CharacterId).ToList();

            Inventory = new Inventory(this);
            Inventory = new Inventory(this);
            foreach (ItemInstanceDTO inventory in inventories)
            {
                inventory.CharacterId = CharacterId;

                if (inventory.Type != InventoryType.Wear)
                {
                    Inventory[inventory.Id] = (ItemInstance)inventory;
                }
                else
                {
                    Inventory[inventory.Id] = (ItemInstance)inventory;
                }
            }
        }