Exemplo n.º 1
0
        public SaveResult InsertOrUpdate(ref ShopItemDTO item)
        {
            try
            {
                using (var context = DataAccessHelper.CreateContext())
                {
                    long     ShopItemId = item.ShopItemId;
                    ShopItem entity     = context.shopitem.SingleOrDefault(c => c.ShopItemId.Equals(ShopItemId));

                    if (entity == null) //new entity
                    {
                        item = Insert(item, context);
                        return(SaveResult.Inserted);
                    }
                    else //existing entity
                    {
                        item = Update(entity, item, context);
                        return(SaveResult.Updated);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log.ErrorFormat(Language.Instance.GetMessageFromKey("UPDATE_ACCOUNT_ERROR"), item.ShopItemId, e.Message);
                return(SaveResult.Error);
            }
        }
Exemplo n.º 2
0
        private ShopItemDTO Insert(ShopItemDTO shopitem, OpenNosContainer context)
        {
            ShopItem entity = Mapper.Map <ShopItem>(shopitem);

            context.shopitem.Add(entity);
            context.SaveChanges();
            return(Mapper.Map <ShopItemDTO>(entity));
        }
Exemplo n.º 3
0
 private ShopItemDTO Update(ShopItem entity, ShopItemDTO shopItem, OpenNosContext context)
 {
     if (entity != null)
     {
         _mapper.Map(shopItem, entity);
         context.SaveChanges();
     }
     return(_mapper.Map <ShopItemDTO>(entity));
 }
Exemplo n.º 4
0
        public ShopItemDTO Map(ShopItem shopItem)
        {
            var shopItemDTO = new ShopItemDTO()
            {
                Name  = shopItem.Name,
                Price = shopItem.Price
            };

            return(shopItemDTO);
        }
Exemplo n.º 5
0
 public ShopItemDTO Insert(ShopItemDTO item)
 {
     using (var context = DataAccessHelper.CreateContext())
     {
         ShopItem entity = _mapper.Map <ShopItem>(item);
         context.ShopItem.Add(entity);
         context.SaveChanges();
         return(_mapper.Map <ShopItemDTO>(entity));
     }
 }
Exemplo n.º 6
0
        public void ImportShopItems()
        {
            List <PortalDTO> listPacket = new List <PortalDTO>();
            int  portalCounter          = 0;
            byte type = 0;

            foreach (string[] linesave in packetList.Where(o => o[0].Equals("n_inv") || o[0].Equals("shopping")))
            {
                if (linesave[0].Equals("n_inv"))
                {
                    if (DAOFactory.ShopDAO.LoadByNpc(short.Parse(linesave[2])) != null)
                    {
                        for (int i = 5; i < linesave.Count(); i++)
                        {
                            string[]    item  = linesave[i].Split('.');
                            ShopItemDTO sitem = null;
                            if (item.Count() == 5)
                            {
                                sitem          = new ShopItemDTO();
                                sitem.ShopId   = DAOFactory.ShopDAO.LoadByNpc(short.Parse(linesave[2])).ShopId;
                                sitem.Type     = type;
                                sitem.Slot     = short.Parse(item[1]);
                                sitem.ItemVNum = short.Parse(item[2]);
                            }
                            else if (item.Count() == 6)
                            {
                                sitem          = new ShopItemDTO();
                                sitem.ShopId   = DAOFactory.ShopDAO.LoadByNpc(short.Parse(linesave[2])).ShopId;
                                sitem.Type     = type;
                                sitem.Slot     = short.Parse(item[1]);
                                sitem.ItemVNum = short.Parse(item[2]);
                                sitem.Rare     = byte.Parse(item[3]);
                                sitem.Upgrade  = byte.Parse(item[4]);
                            }
                            if (sitem != null && DAOFactory.ShopItemDAO.LoadByShopId(sitem.ShopId).FirstOrDefault(s => s.ItemVNum.Equals(sitem.ItemVNum)) == null)
                            {
                                DAOFactory.ShopItemDAO.Insert(sitem);
                                portalCounter++;
                            }
                        }
                    }
                }
                else
                {
                    if (linesave.Count() > 3)
                    {
                        type = byte.Parse(linesave[1]);
                    }
                }
            }

            Logger.Log.Info(string.Format(Language.Instance.GetMessageFromKey("SHOPITEMS_PARSED"), portalCounter));
        }
Exemplo n.º 7
0
        private ShopItemDTO Update(ShopItem entity, ShopItemDTO shopitem, OpenNosContainer context)
        {
            using (context)
            {
                var result = context.shopitem.SingleOrDefault(c => c.ShopItemId.Equals(shopitem.ShopItemId));
                if (result != null)
                {
                    result = Mapper.Map <ShopItemDTO, ShopItem>(shopitem, entity);
                    context.SaveChanges();
                }
            }

            return(Mapper.Map <ShopItemDTO>(entity));
        }
Exemplo n.º 8
0
 public IEnumerable <ShopItemDTO> LoadByShopId(int shopId)
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         List <ShopItemDTO> result = new List <ShopItemDTO>();
         foreach (ShopItem shopItem in context.ShopItem.AsNoTracking().Where(i => i.ShopId.Equals(shopId)))
         {
             ShopItemDTO dto = new ShopItemDTO();
             Mapper.Mappers.ShopItemMapper.ToShopItemDTO(shopItem, dto);
             result.Add(dto);
         }
         return(result);
     }
 }
Exemplo n.º 9
0
 public IEnumerable <ShopItemDTO> LoadAll()
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         List <ShopItemDTO> result = new List <ShopItemDTO>();
         foreach (ShopItem entity in context.ShopItem.AsNoTracking())
         {
             ShopItemDTO dto = new ShopItemDTO();
             Mapper.Mappers.ShopItemMapper.ToShopItemDTO(entity, dto);
             result.Add(dto);
         }
         return(result);
     }
 }
 public static bool ToShopItemDTO(ShopItem input, ShopItemDTO output)
 {
     if (input == null)
     {
         return(false);
     }
     output.Color      = input.Color;
     output.ItemVNum   = input.ItemVNum;
     output.Rare       = (sbyte)input.Rare;
     output.ShopId     = input.ShopId;
     output.ShopItemId = input.ShopItemId;
     output.Slot       = input.Slot;
     output.Type       = input.Type;
     output.Upgrade    = input.Upgrade;
     return(true);
 }
Exemplo n.º 11
0
 public ShopItemDTO Insert(ShopItemDTO item)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             ShopItem entity = _mapper.Map <ShopItem>(item);
             context.ShopItem.Add(entity);
             context.SaveChanges();
             return(_mapper.Map <ShopItemDTO>(entity));
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
         return(null);
     }
 }
Exemplo n.º 12
0
        public ShopItemDTO LoadById(int itemId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    ShopItemDTO dto = new ShopItemDTO();
                    if (Mapper.Mappers.ShopItemMapper.ToShopItemDTO(context.ShopItem.AsNoTracking().FirstOrDefault(i => i.ShopItemId.Equals(itemId)), dto))
                    {
                        return(dto);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
Exemplo n.º 13
0
        public ShopItemDTO Insert(ShopItemDTO item)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    ShopItem entity = new ShopItem();
                    Mapper.Mappers.ShopItemMapper.ToShopItem(item, entity);
                    context.ShopItem.Add(entity);
                    context.SaveChanges();
                    if (Mapper.Mappers.ShopItemMapper.ToShopItemDTO(entity, item))
                    {
                        return(item);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
        public void BuyShop(string packet)
        {
            if (Session.Character.InExchangeOrTrade)
            {
                return;
            }
            Logger.Debug(packet, Session.SessionId);
            string[] packetsplit = packet.Split(' ');
            long     owner;
            byte     type;
            short    slot;
            Random   random = new Random();

            if (packetsplit.Length < 5)
            {
                return;
            }
            byte amount = 0;

            long.TryParse(packetsplit[3], out owner);
            byte.TryParse(packetsplit[2], out type);
            short.TryParse(packetsplit[4], out slot);
            if (packetsplit.Length == 6)
            {
                byte.TryParse(packetsplit[5], out amount);
            }
            if (type == 1)
            {
                // User shop
                KeyValuePair <long, MapShop> shop = Session.CurrentMap.UserShops.FirstOrDefault(mapshop => mapshop.Value.OwnerId.Equals(owner));
                PersonalShopItem             item = shop.Value.Items.FirstOrDefault(i => i.Slot.Equals(slot));
                if (item == null || amount <= 0)
                {
                    return;
                }
                if (amount > item.Amount)
                {
                    amount = item.Amount;
                }
                if (item.Price * amount + ServerManager.Instance.GetProperty <long>(shop.Value.OwnerId, nameof(Character.Gold)) > 1000000000)
                {
                    Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("MAX_GOLD")));
                    return;
                }

                if (item.Price * amount >= Session.Character.Gold)
                {
                    Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                    return;
                }

                ItemInstance item2 = (item.ItemInstance as ItemInstance).DeepCopy();
                item2.Amount = amount;
                item2.Id     = Guid.NewGuid(); // this is necessary due the deepcopy would cause duplicate GUID
                Inventory inv = Session.Character.InventoryList.AddToInventory(item2);

                if (inv != null)
                {
                    Session.SendPacket(Session.Character.GenerateInventoryAdd(inv.ItemInstance.ItemVNum, inv.ItemInstance.Amount, inv.Type, inv.Slot, inv.ItemInstance.Rare, inv.ItemInstance.Design, inv.ItemInstance.Upgrade, 0));
                    Session.Character.Gold -= item.Price * amount;
                    Session.SendPacket(Session.Character.GenerateGold());
                    ServerManager.Instance.BuyValidate(Session, shop, slot, amount);
                    KeyValuePair <long, MapShop> shop2 = Session.CurrentMap.UserShops.FirstOrDefault(s => s.Value.OwnerId.Equals(owner));
                    LoadShopItem(owner, shop2);
                }
                else
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                }
            }
            else if (packetsplit.Length == 5)
            {
                // skill shop
                if (Session.Character.UseSp)
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("REMOVE_SP"), 0));
                    return;
                }
                Skill skillinfo = ServerManager.GetSkill(slot);
                if (Session.Character.Skills.Any(s => s.SkillVNum == slot))
                {
                    return;
                }
                if (skillinfo == null)
                {
                    return;
                }
                if (Session.Character.Gold < skillinfo.Price)
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 0));
                    return;
                }
                else if (Session.Character.GetCP() < skillinfo.CPCost)
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_CP"), 0));
                }
                else
                {
                    if (skillinfo.SkillVNum < 200)
                    {
                        int SkillMiniumLevel = 0;
                        if (skillinfo.MinimumSwordmanLevel == 0 && skillinfo.MinimumArcherLevel == 0 && skillinfo.MinimumMagicianLevel == 0)
                        {
                            SkillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                        }
                        else
                        {
                            switch (Session.Character.Class)
                            {
                            case (byte)ClassType.Adventurer:
                                SkillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                                break;

                            case (byte)ClassType.Swordman:
                                SkillMiniumLevel = skillinfo.MinimumSwordmanLevel;
                                break;

                            case (byte)ClassType.Archer:
                                SkillMiniumLevel = skillinfo.MinimumArcherLevel;
                                break;

                            case (byte)ClassType.Magician:
                                SkillMiniumLevel = skillinfo.MinimumMagicianLevel;
                                break;
                            }
                        }
                        if (SkillMiniumLevel == 0)
                        {
                            Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                            return;
                        }
                        else if (Session.Character.Level < SkillMiniumLevel)
                        {
                            Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("LOW_LVL"), 0));
                            return;
                        }
                        for (int i = Session.Character.Skills.Count - 1; i >= 0; i--)
                        {
                            if ((skillinfo.CastId == Session.Character.Skills[i].Skill.CastId) && (Session.Character.Skills[i].Skill.SkillVNum < 200))
                            {
                                Session.Character.Skills.Remove(Session.Character.Skills[i]);
                            }
                        }
                    }
                    else
                    {
                        if (Session.Character.Class != skillinfo.Class)
                        {
                            Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                            return;
                        }
                        else if (Session.Character.JobLevel < skillinfo.LevelMinimum)
                        {
                            Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("LOW_JOB_LVL"), 0));
                            return;
                        }
                        if (skillinfo.UpgradeSkill != 0)
                        {
                            CharacterSkill oldupgrade = Session.Character.Skills.FirstOrDefault(s => s.Skill.UpgradeSkill == skillinfo.UpgradeSkill && s.Skill.UpgradeType == skillinfo.UpgradeType && s.Skill.UpgradeSkill != 0);
                            if (oldupgrade != null)
                            {
                                Session.Character.Skills.Remove(oldupgrade);
                            }
                        }
                    }

                    Session.Character.Skills.Add(new CharacterSkill()
                    {
                        SkillVNum = slot, CharacterId = Session.Character.CharacterId
                    });

                    Session.Character.Gold -= skillinfo.Price;
                    Session.SendPacket(Session.Character.GenerateGold());
                    Session.SendPacket(Session.Character.GenerateSki());
                    Session.SendPackets(Session.Character.GenerateQuicklist());
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_LEARNED"), 0));
                    Session.SendPacket(Session.Character.GenerateLev());
                }
            }
            else
            {
                MapNpc npc = Session.CurrentMap.Npcs.FirstOrDefault(n => n.MapNpcId.Equals((short)owner));

                ShopItemDTO item = npc?.Shop.ShopItems.FirstOrDefault(it => it.Slot == slot);
                if (item == null)
                {
                    return;
                }
                Item   iteminfo   = ServerManager.GetItem(item.ItemVNum);
                long   price      = iteminfo.Price * amount;
                long   Reputprice = iteminfo.ReputPrice * amount;
                double percent    = 1;
                if (Session.Character.GetDignityIco() == 3)
                {
                    percent = 1.10;
                }
                else if (Session.Character.GetDignityIco() == 4)
                {
                    percent = 1.20;
                }
                else if (Session.Character.GetDignityIco() == 5 || Session.Character.GetDignityIco() == 6)
                {
                    percent = 1.5;
                }
                sbyte rare = item.Rare;
                if (iteminfo.Type == 0)
                {
                    amount = 1;
                }
                if (iteminfo.ReputPrice == 0)
                {
                    if (price < 0 || price * percent > Session.Character.Gold)
                    {
                        Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                        return;
                    }
                }
                else
                {
                    if (Reputprice <= 0 || Reputprice > Session.Character.Reput)
                    {
                        Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_REPUT")));
                        return;
                    }
                    byte ra = (byte)random.Next(0, 100);

                    int[] rareprob = { 100, 100, 70, 50, 30, 15, 5, 1 };
                    if (iteminfo.ReputPrice != 0)
                    {
                        for (int i = 0; i < rareprob.Length; i++)
                        {
                            if (ra <= rareprob[i])
                            {
                                rare = (sbyte)i;
                            }
                        }
                    }
                }

                Inventory newItem = Session.Character.InventoryList.AddNewItemToInventory(item.ItemVNum, amount);
                if (newItem == null)
                {
                    return;
                }

                newItem.ItemInstance.Rare    = rare;
                newItem.ItemInstance.Upgrade = item.Upgrade;
                newItem.ItemInstance.Design  = item.Color;

                if (newItem != null && newItem.Slot != -1)
                {
                    Session.SendPacket(Session.Character.GenerateInventoryAdd(newItem.ItemInstance.ItemVNum, newItem.ItemInstance.Amount, newItem.Type, newItem.Slot, newItem.ItemInstance.Rare, newItem.ItemInstance.Design, newItem.ItemInstance.Upgrade, 0));
                    if (iteminfo.ReputPrice == 0)
                    {
                        Session.SendPacket(Session.Character.GenerateShopMemo(1, string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"), iteminfo.Name, amount)));
                        Session.Character.Gold -= (long)(price * percent);
                        Session.SendPacket(Session.Character.GenerateGold());
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateShopMemo(1, string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"), iteminfo.Name, amount)));
                        Session.Character.Reput -= Reputprice;
                        Session.SendPacket(Session.Character.GenerateFd());
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("REPUT_DECREASED"), 11));
                    }
                }
                else
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                }
            }
        }
Exemplo n.º 15
0
        private void ExecuteHandler(ClientSession session)
        {
            if (session.Character.InExchangeOrTrade)
            {
                return;
            }

            switch (Type)
            {
            case BuyShopType.CharacterShop:
                if (!session.HasCurrentMapInstance)
                {
                    return;
                }

                KeyValuePair <long, MapShop> shop =
                    session.CurrentMapInstance.UserShops.FirstOrDefault(mapshop =>
                                                                        mapshop.Value.OwnerId.Equals(OwnerId));
                PersonalShopItem item = shop.Value?.Items.Find(i => i.ShopSlot.Equals(Slot));
                ClientSession    sess = ServerManager.Instance.GetSessionByCharacterId(shop.Value?.OwnerId ?? 0);
                if (sess == null || item == null || Amount <= 0 || Amount > 999)
                {
                    return;
                }

                GameLogger.Instance.LogItemBuyPlayerShop(ServerManager.Instance.ChannelId, session.Character.Name,
                                                         session.Character.CharacterId, sess.Character.Name, OwnerId, item.ItemInstance, Amount,
                                                         item.Price, session.CurrentMapInstance.Map.MapId, session.Character.PositionX,
                                                         session.Character.PositionY);

                if (Amount > item.SellAmount)
                {
                    Amount = item.SellAmount;
                }

                if ((item.Price * Amount)
                    + sess.Character.Gold
                    > ServerManager.Instance.Configuration.MaxGold)
                {
                    session.SendPacket(UserInterfaceHelper.GenerateShopMemo(3,
                                                                            Language.Instance.GetMessageFromKey("MAX_GOLD")));
                    return;
                }

                if (item.Price * Amount >= session.Character.Gold)
                {
                    session.SendPacket(UserInterfaceHelper.GenerateShopMemo(3,
                                                                            Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                    return;
                }

                // check if the item has been removed successfully from previous owner and remove it
                if (session.BuyValidate(shop, Slot, Amount))
                {
                    session.Character.Gold -= item.Price * Amount;
                    session.SendPacket(session.Character.GenerateGold());

                    KeyValuePair <long, MapShop> shop2 =
                        session.CurrentMapInstance.UserShops.FirstOrDefault(s =>
                                                                            s.Value.OwnerId.Equals(OwnerId));
                    session.LoadShopItem(OwnerId, shop2);
                }
                else
                {
                    session.SendPacket(
                        UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"),
                                                        0));
                }

                break;

            case BuyShopType.ItemShop:
                if (!session.HasCurrentMapInstance)
                {
                    return;
                }

                MapNpc npc =
                    session.CurrentMapInstance.Npcs.Find(n => n.MapNpcId.Equals((short)OwnerId));
                if (npc != null)
                {
                    int dist = Map.GetDistance(
                        new MapCell {
                        X = session.Character.PositionX, Y = session.Character.PositionY
                    },
                        new MapCell {
                        X = npc.MapX, Y = npc.MapY
                    });
                    if (npc.Shop == null || dist > 5)
                    {
                        return;
                    }

                    if (npc.Shop.ShopSkills.Count > 0)
                    {
                        if (!npc.Shop.ShopSkills.Exists(s => s.SkillVNum == Slot))
                        {
                            return;
                        }

                        // skill shop
                        if (session.Character.UseSp)
                        {
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("REMOVE_SP"),
                                                                0));
                            return;
                        }

                        if (session.Character.Skills.Any(s =>
                                                         s.LastUse.AddMilliseconds(s.Skill.Cooldown * 100) > DateTime.UtcNow))
                        {
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(
                                    Language.Instance.GetMessageFromKey("SKILL_NEED_COOLDOWN"), 0));
                            return;
                        }

                        Skill skillinfo = ServerManager.GetSkill(Slot);
                        if (session.Character.Skills.Any(s => s.SkillVNum == Slot) || skillinfo == null)
                        {
                            return;
                        }

                        GameLogger.Instance.LogSkillBuy(ServerManager.Instance.ChannelId, session.Character.Name,
                                                        session.Character.CharacterId, npc.MapNpcId, skillinfo.SkillVNum, skillinfo.Price,
                                                        session.CurrentMapInstance.Map.MapId, session.Character.PositionX,
                                                        session.Character.PositionY);

                        if (session.Character.Gold < skillinfo.Price)
                        {
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(
                                    Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 0));
                        }
                        else if (session.Character.GetCP() < skillinfo.CPCost)
                        {
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(
                                    Language.Instance.GetMessageFromKey("NOT_ENOUGH_CP"), 0));
                        }
                        else
                        {
                            if (skillinfo.SkillVNum < 200)
                            {
                                int skillMiniumLevel = 0;
                                if (skillinfo.MinimumSwordmanLevel == 0 && skillinfo.MinimumArcherLevel == 0 &&
                                    skillinfo.MinimumMagicianLevel == 0)
                                {
                                    skillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                                }
                                else
                                {
                                    switch (session.Character.Class)
                                    {
                                    case ClassType.Adventurer:
                                        skillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                                        break;

                                    case ClassType.Swordman:
                                        skillMiniumLevel = skillinfo.MinimumSwordmanLevel;
                                        break;

                                    case ClassType.Archer:
                                        skillMiniumLevel = skillinfo.MinimumArcherLevel;
                                        break;

                                    case ClassType.Magician:
                                        skillMiniumLevel = skillinfo.MinimumMagicianLevel;
                                        break;
                                    }
                                }

                                if (skillMiniumLevel == 0)
                                {
                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(
                                                           Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                                    return;
                                }

                                if (session.Character.Level < skillMiniumLevel)
                                {
                                    session.SendPacket(
                                        UserInterfaceHelper.GenerateMsg(
                                            Language.Instance.GetMessageFromKey("LOW_LVL"), 0));
                                    return;
                                }

                                foreach (CharacterSkill skill in session.Character.Skills.GetAllItems())
                                {
                                    if (skillinfo.CastId == skill.Skill.CastId && skill.Skill.SkillVNum < 200)
                                    {
                                        session.Character.Skills.Remove(skill.SkillVNum);
                                    }
                                }
                            }
                            else
                            {
                                if ((byte)session.Character.Class != skillinfo.Class)
                                {
                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(
                                                           Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                                    return;
                                }

                                if (session.Character.JobLevel < skillinfo.LevelMinimum)
                                {
                                    session.SendPacket(
                                        UserInterfaceHelper.GenerateMsg(
                                            Language.Instance.GetMessageFromKey("LOW_JOB_LVL"), 0));
                                    return;
                                }

                                if (skillinfo.UpgradeSkill != 0)
                                {
                                    CharacterSkill oldupgrade = session.Character.Skills.FirstOrDefault(s =>
                                                                                                        s.Skill.UpgradeSkill == skillinfo.UpgradeSkill &&
                                                                                                        s.Skill.UpgradeType == skillinfo.UpgradeType &&
                                                                                                        s.Skill.UpgradeSkill != 0);
                                    if (oldupgrade != null)
                                    {
                                        session.Character.Skills.Remove(oldupgrade.SkillVNum);
                                    }
                                }
                            }

                            session.Character.Skills[Slot] = new CharacterSkill
                            {
                                SkillVNum   = Slot,
                                CharacterId = session.Character.CharacterId
                            };

                            session.Character.Gold -= skillinfo.Price;
                            session.SendPacket(session.Character.GenerateGold());
                            session.SendPacket(session.Character.GenerateSki());
                            session.SendPackets(session.Character.GenerateQuicklist());
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(
                                    Language.Instance.GetMessageFromKey("SKILL_LEARNED"), 0));
                            session.Character.LoadPassiveSkills();
                            session.SendPacket(session.Character.GenerateLev());
                        }
                    }
                    else if (npc.Shop.ShopItems.Count > 0)
                    {
                        // npc shop
                        ShopItemDTO shopItem = npc.Shop.ShopItems.Find(it => it.Slot == Slot);
                        if (shopItem == null || Amount <= 0 || Amount > 999)
                        {
                            return;
                        }

                        Item   iteminfo   = ServerManager.GetItem(shopItem.ItemVNum);
                        long   price      = iteminfo.Price * Amount;
                        long   reputprice = iteminfo.ReputPrice * Amount;
                        double percent;
                        switch (session.Character.GetDignityIco())
                        {
                        case 3:
                            percent = 1.10;
                            break;

                        case 4:
                            percent = 1.20;
                            break;

                        case 5:
                        case 6:
                            percent = 1.5;
                            break;

                        default:
                            percent = 1;
                            break;
                        }

                        GameLogger.Instance.LogItemBuyNpcShop(ServerManager.Instance.ChannelId,
                                                              session.Character.Name, session.Character.CharacterId, npc.MapNpcId, iteminfo.VNum,
                                                              Amount, (long)(price * percent), session.CurrentMapInstance.Map.MapId,
                                                              session.Character.PositionX, session.Character.PositionY);

                        sbyte rare = shopItem.Rare;
                        if (iteminfo.Type == 0)
                        {
                            Amount = 1;
                        }

                        if (iteminfo.ReputPrice == 0)
                        {
                            if (price < 0 || price * percent > session.Character.Gold)
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateShopMemo(3,
                                                                                        Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                                return;
                            }
                        }
                        else
                        {
                            if (reputprice <= 0 || reputprice > session.Character.Reputation)
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateShopMemo(3,
                                                                                        Language.Instance.GetMessageFromKey("NOT_ENOUGH_REPUT")));
                                return;
                            }

                            byte ra = (byte)ServerManager.RandomNumber();

                            int[] rareprob = { 100, 100, 70, 50, 30, 15, 5, 1 };
                            if (iteminfo.ReputPrice != 0)
                            {
                                for (int i = 0; i < rareprob.Length; i++)
                                {
                                    if (ra <= rareprob[i])
                                    {
                                        rare = (sbyte)i;
                                    }
                                }
                            }
                        }

                        List <ItemInstance> newItems = session.Character.Inventory.AddNewToInventory(
                            shopItem.ItemVNum, Amount, rare: rare, upgrade: shopItem.Upgrade,
                            design: shopItem.Color);
                        if (newItems.Count == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateShopMemo(3,
                                                                                    Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE")));
                            return;
                        }

                        if (newItems.Count > 0)
                        {
                            foreach (ItemInstance itemInst in newItems)
                            {
                                switch (itemInst.Item.EquipmentSlot)
                                {
                                case EquipmentType.Armor:
                                case EquipmentType.MainWeapon:
                                case EquipmentType.SecondaryWeapon:
                                    bool isPartner = (itemInst.ItemVNum >= 990 && itemInst.ItemVNum <= 992) || (itemInst.ItemVNum >= 995 && itemInst.ItemVNum <= 997);
                                    itemInst.SetRarityPoint(isPartner);
                                    break;

                                case EquipmentType.Boots:
                                case EquipmentType.Gloves:
                                    itemInst.FireResistance =
                                        (short)(itemInst.Item.FireResistance * shopItem.Upgrade);
                                    itemInst.DarkResistance =
                                        (short)(itemInst.Item.DarkResistance * shopItem.Upgrade);
                                    itemInst.LightResistance =
                                        (short)(itemInst.Item.LightResistance * shopItem.Upgrade);
                                    itemInst.WaterResistance =
                                        (short)(itemInst.Item.WaterResistance * shopItem.Upgrade);
                                    break;
                                }
                            }

                            if (iteminfo.ReputPrice == 0)
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateShopMemo(1,
                                                                                        string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"),
                                                                                                      iteminfo.Name, Amount)));
                                session.Character.Gold -= (long)(price * percent);
                                session.SendPacket(session.Character.GenerateGold());
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateShopMemo(1,
                                                                                        string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"),
                                                                                                      iteminfo.Name, Amount)));
                                session.Character.Reputation -= reputprice;
                                session.SendPacket(session.Character.GenerateFd());
                                session.SendPacket(
                                    session.Character.GenerateSay(
                                        Language.Instance.GetMessageFromKey("REPUT_DECREASED"), 11));
                            }
                        }
                        else
                        {
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(
                                    Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                        }
                    }
                }

                break;
            }
        }
Exemplo n.º 16
0
        public void BuyShop(BuyPacket buyPacket)
        {
            if (Session.Character.InExchangeOrTrade)
            {
                return;
            }
            Logger.Debug(buyPacket.ToString(), Session.SessionId);

            Random random = new Random();
            byte   amount = buyPacket.Amount;

            switch (buyPacket.Type)
            {
            case BuyShopType.CharacterShop:
            {
                // User shop
                KeyValuePair <long, MapShop> shop = Session.CurrentMap.UserShops.FirstOrDefault(mapshop => mapshop.Value.OwnerId.Equals(buyPacket.OwnerId));

                PersonalShopItem item = shop.Value.Items.FirstOrDefault(i => i.ShopSlot.Equals(buyPacket.Slot));
                if (item == null || amount <= 0 || amount > 99)
                {
                    return;
                }
                if (amount > item.SellAmount)
                {
                    amount = item.SellAmount;
                }
                if (item.Price * amount + ServerManager.Instance.GetProperty <long>(shop.Value.OwnerId, nameof(Character.Gold)) > 1000000000)
                {
                    Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("MAX_GOLD")));
                    return;
                }

                if (item.Price * amount >= Session.Character.Gold)
                {
                    Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                    return;
                }

                // check if the item has been removed successfully from previous owner and remove it
                if (BuyValidate(Session, shop, buyPacket.Slot, amount))
                {
                    ItemInstance inv = item.ItemInstance.Type == InventoryType.Equipment
                                               ? Session.Character.Inventory.AddToInventory(item.ItemInstance)
                                               : Session.Character.Inventory.AddNewToInventory(item.ItemInstance.ItemVNum, amount, item.ItemInstance.Type);

                    if (inv != null)
                    {
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(inv.ItemVNum, inv.Amount, inv.Type, inv.Slot, inv.Rare, inv.Design, inv.Upgrade, 0));
                        Session.Character.Gold -= item.Price * amount;
                        Session.SendPacket(Session.Character.GenerateGold());

                        KeyValuePair <long, MapShop> shop2 = Session.CurrentMap.UserShops.FirstOrDefault(s => s.Value.OwnerId.Equals(buyPacket.OwnerId));
                        LoadShopItem(buyPacket.OwnerId, shop2);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                    }
                }

                break;
            }

            case BuyShopType.ItemShop:
            {
                // load shop
                MapNpc npc  = Session.CurrentMap.Npcs.FirstOrDefault(n => n.MapNpcId.Equals((short)buyPacket.OwnerId));
                int    dist = Map.GetDistance(new MapCell()
                    {
                        MapId = Session.CurrentMap.MapId, X = Session.Character.MapX, Y = Session.Character.MapY
                    }, new MapCell()
                    {
                        MapId = npc.MapId, X = npc.MapX, Y = npc.MapY
                    });
                if (npc == null || npc.Shop == null || dist > 5)
                {
                    return;
                }

                if (npc.Shop.ShopSkills.Any())
                {
                    // skill shop
                    if (Session.Character.UseSp)
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("REMOVE_SP"), 0));
                        return;
                    }
                    Skill skillinfo = ServerManager.GetSkill(buyPacket.Slot);
                    if (Session.Character.Skills.GetAllItems().Any(s => s.SkillVNum == buyPacket.Slot) || skillinfo == null)
                    {
                        return;
                    }

                    if (Session.Character.Gold < skillinfo.Price)
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 0));
                        return;
                    }
                    else if (Session.Character.GetCP() < skillinfo.CPCost)
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_CP"), 0));
                    }
                    else
                    {
                        if (skillinfo.SkillVNum < 200)
                        {
                            int SkillMiniumLevel = 0;
                            if (skillinfo.MinimumSwordmanLevel == 0 && skillinfo.MinimumArcherLevel == 0 && skillinfo.MinimumMagicianLevel == 0)
                            {
                                SkillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                            }
                            else
                            {
                                switch (Session.Character.Class)
                                {
                                case ClassType.Adventurer:
                                    SkillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                                    break;

                                case ClassType.Swordman:
                                    SkillMiniumLevel = skillinfo.MinimumSwordmanLevel;
                                    break;

                                case ClassType.Archer:
                                    SkillMiniumLevel = skillinfo.MinimumArcherLevel;
                                    break;

                                case ClassType.Magician:
                                    SkillMiniumLevel = skillinfo.MinimumMagicianLevel;
                                    break;
                                }
                            }
                            if (SkillMiniumLevel == 0)
                            {
                                Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                                return;
                            }
                            else if (Session.Character.Level < SkillMiniumLevel)
                            {
                                Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("LOW_LVL"), 0));
                                return;
                            }
                            foreach (var skill in Session.Character.Skills.GetAllItems())
                            {
                                if ((skillinfo.CastId == skill.Skill.CastId) && skill.Skill.SkillVNum < 200)
                                {
                                    Session.Character.Skills.Remove(skill.SkillVNum);
                                }
                            }
                        }
                        else
                        {
                            if ((byte)Session.Character.Class != skillinfo.Class)
                            {
                                Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                                return;
                            }
                            else if (Session.Character.JobLevel < skillinfo.LevelMinimum)
                            {
                                Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("LOW_JOB_LVL"), 0));
                                return;
                            }
                            if (skillinfo.UpgradeSkill != 0)
                            {
                                CharacterSkill oldupgrade = Session.Character.Skills.GetAllItems().FirstOrDefault(s => s.Skill.UpgradeSkill == skillinfo.UpgradeSkill && s.Skill.UpgradeType == skillinfo.UpgradeType && s.Skill.UpgradeSkill != 0);
                                if (oldupgrade != null)
                                {
                                    Session.Character.Skills.Remove(oldupgrade.SkillVNum);
                                }
                            }
                        }

                        Session.Character.Skills[buyPacket.Slot] = new CharacterSkill()
                        {
                            SkillVNum = buyPacket.Slot, CharacterId = Session.Character.CharacterId
                        };

                        Session.Character.Gold -= skillinfo.Price;
                        Session.SendPacket(Session.Character.GenerateGold());
                        Session.SendPacket(Session.Character.GenerateSki());
                        Session.SendPackets(Session.Character.GenerateQuicklist());
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_LEARNED"), 0));
                        Session.SendPacket(Session.Character.GenerateLev());
                    }
                }
                else if (npc.Shop.ShopItems.Any())
                {
                    // npc shop
                    ShopItemDTO item = npc?.Shop.ShopItems.FirstOrDefault(it => it.Slot == buyPacket.Slot);
                    if (item == null || amount <= 0 || amount > 99)
                    {
                        return;
                    }
                    Item   iteminfo   = ServerManager.GetItem(item.ItemVNum);
                    long   price      = iteminfo.Price * amount;
                    long   Reputprice = iteminfo.ReputPrice * amount;
                    double percent    = 1;
                    if (Session.Character.GetDignityIco() == 3)
                    {
                        percent = 1.10;
                    }
                    else if (Session.Character.GetDignityIco() == 4)
                    {
                        percent = 1.20;
                    }
                    else if (Session.Character.GetDignityIco() == 5 || Session.Character.GetDignityIco() == 6)
                    {
                        percent = 1.5;
                    }
                    sbyte rare = item.Rare;
                    if (iteminfo.Type == 0)
                    {
                        amount = 1;
                    }
                    if (iteminfo.ReputPrice == 0)
                    {
                        if (price < 0 || price * percent > Session.Character.Gold)
                        {
                            Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                            return;
                        }
                    }
                    else
                    {
                        if (Reputprice <= 0 || Reputprice > Session.Character.Reput)
                        {
                            Session.SendPacket(Session.Character.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_REPUT")));
                            return;
                        }
                        byte ra = (byte)random.Next(0, 100);

                        int[] rareprob = { 100, 100, 70, 50, 30, 15, 5, 1 };
                        if (iteminfo.ReputPrice != 0)
                        {
                            for (int i = 0; i < rareprob.Length; i++)
                            {
                                if (ra <= rareprob[i])
                                {
                                    rare = (sbyte)i;
                                }
                            }
                        }
                    }

                    ItemInstance newItem = Session.Character.Inventory.AddNewToInventory(item.ItemVNum, amount);
                    if (newItem == null)
                    {
                        return;
                    }

                    newItem.Rare    = rare;
                    newItem.Upgrade = item.Upgrade;
                    newItem.Design  = item.Color;

                    if (newItem != null && newItem.Slot != -1)
                    {
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(newItem.ItemVNum, newItem.Amount, newItem.Type, newItem.Slot, newItem.Rare, newItem.Design, newItem.Upgrade, 0));
                        if (iteminfo.ReputPrice == 0)
                        {
                            Session.SendPacket(Session.Character.GenerateShopMemo(1, String.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"), iteminfo.Name, amount)));
                            Session.Character.Gold -= (long)(price * percent);
                            Session.SendPacket(Session.Character.GenerateGold());
                        }
                        else
                        {
                            Session.SendPacket(Session.Character.GenerateShopMemo(1, String.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"), iteminfo.Name, amount)));
                            Session.Character.Reput -= Reputprice;
                            Session.SendPacket(Session.Character.GenerateFd());
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("REPUT_DECREASED"), 11));
                        }
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                    }
                }
                break;
            }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// buy packet
        /// </summary>
        /// <param name="buyPacket"></param>
        public void BuyShop(BuyPacket buyPacket)
        {
            if (Session.Character.InExchangeOrTrade)
            {
                return;
            }
            Logger.Debug(Session.Character.GenerateIdentity(), buyPacket.ToString());

            byte amount = buyPacket.Amount;

            switch (buyPacket.Type)
            {
            case BuyShopType.CharacterShop:
            {
                // User shop
                if (!Session.HasCurrentMapInstance)
                {
                    return;
                }
                KeyValuePair <long, MapShop> shop = Session.CurrentMapInstance.UserShops.FirstOrDefault(mapshop => mapshop.Value.OwnerId.Equals(buyPacket.OwnerId));
                PersonalShopItem             item = shop.Value?.Items.FirstOrDefault(i => i.ShopSlot.Equals(buyPacket.Slot));
                if (item == null || amount <= 0 || amount > 99)
                {
                    return;
                }
                if (amount > item.SellAmount)
                {
                    amount = item.SellAmount;
                }
                if (item.Price * amount + ServerManager.Instance.GetProperty <long>(shop.Value.OwnerId, nameof(Character.Gold)) > ServerManager.Instance.MaxGold)
                {
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("MAX_GOLD")));
                    return;
                }

                if (item.Price * amount >= Session.Character.Gold)
                {
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                    return;
                }

                // check if the item has been removed successfully from previous owner and
                // remove it
                if (BuyValidate(Session, shop, buyPacket.Slot, amount))
                {
                    Session.Character.Gold -= item.Price * amount;
                    Session.SendPacket(Session.Character.GenerateGold());

                    KeyValuePair <long, MapShop> shop2 = Session.CurrentMapInstance.UserShops.FirstOrDefault(s => s.Value.OwnerId.Equals(buyPacket.OwnerId));
                    LoadShopItem(buyPacket.OwnerId, shop2);
                }
                else
                {
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                }

                break;
            }

            case BuyShopType.ItemShop:
            {
                // load shop
                if (!Session.HasCurrentMapInstance)
                {
                    return;
                }
                MapNpc npc = Session.CurrentMapInstance.Npcs.FirstOrDefault(n => n.MapNpcId.Equals((short)buyPacket.OwnerId));
                if (npc != null)
                {
                    int dist = Map.GetDistance(new MapCell {
                            X = Session.Character.PositionX, Y = Session.Character.PositionY
                        }, new MapCell {
                            X = npc.MapX, Y = npc.MapY
                        });
                    if (npc.Shop == null || dist > 5)
                    {
                        return;
                    }
                    if (npc.Shop.ShopSkills.Any())
                    {
                        if (!npc.Shop.ShopSkills.Exists(s => s.SkillVNum == buyPacket.Slot))
                        {
                            return;
                        }

                        // skill shop
                        if (Session.Character.UseSp)
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("REMOVE_SP"), 0));
                            return;
                        }

                        if (Session.Character.Skills.GetAllItems().Any(s => s.LastUse.AddMilliseconds(s.Skill.Cooldown * 100) > DateTime.Now))
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_NEED_COOLDOWN"), 0));
                            return;
                        }

                        Skill skillinfo = ServerManager.Instance.GetSkill(buyPacket.Slot);
                        if (Session.Character.Skills.GetAllItems().Any(s => s.SkillVNum == buyPacket.Slot) || skillinfo == null)
                        {
                            return;
                        }

                        if (Session.Character.Gold < skillinfo.Price)
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 0));
                        }
                        else if (Session.Character.GetCP() < skillinfo.CPCost)
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_CP"), 0));
                        }
                        else
                        {
                            if (skillinfo.SkillVNum < 200)
                            {
                                int SkillMiniumLevel = 0;
                                if (skillinfo.MinimumSwordmanLevel == 0 && skillinfo.MinimumArcherLevel == 0 && skillinfo.MinimumMagicianLevel == 0)
                                {
                                    SkillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                                }
                                else
                                {
                                    switch (Session.Character.Class)
                                    {
                                    case ClassType.Adventurer:
                                        SkillMiniumLevel = skillinfo.MinimumAdventurerLevel;
                                        break;

                                    case ClassType.Swordman:
                                        SkillMiniumLevel = skillinfo.MinimumSwordmanLevel;
                                        break;

                                    case ClassType.Archer:
                                        SkillMiniumLevel = skillinfo.MinimumArcherLevel;
                                        break;

                                    case ClassType.Magician:
                                        SkillMiniumLevel = skillinfo.MinimumMagicianLevel;
                                        break;
                                    }
                                }
                                if (SkillMiniumLevel == 0)
                                {
                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                                    return;
                                }
                                if (Session.Character.Level < SkillMiniumLevel)
                                {
                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("LOW_LVL"), 0));
                                    return;
                                }
                                foreach (CharacterSkill skill in Session.Character.Skills.GetAllItems())
                                {
                                    if (skillinfo.CastId == skill.Skill.CastId && skill.Skill.SkillVNum < 200)
                                    {
                                        Session.Character.Skills.Remove(skill.SkillVNum);
                                    }
                                }
                            }
                            else
                            {
                                if ((byte)Session.Character.Class != skillinfo.Class)
                                {
                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_CANT_LEARN"), 0));
                                    return;
                                }
                                if (Session.Character.JobLevel < skillinfo.LevelMinimum)
                                {
                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("LOW_JOB_LVL"), 0));
                                    return;
                                }
                                if (skillinfo.UpgradeSkill != 0)
                                {
                                    CharacterSkill oldupgrade = Session.Character.Skills.GetAllItems().FirstOrDefault(s => s.Skill.UpgradeSkill == skillinfo.UpgradeSkill && s.Skill.UpgradeType == skillinfo.UpgradeType && s.Skill.UpgradeSkill != 0);
                                    if (oldupgrade != null)
                                    {
                                        Session.Character.Skills.Remove(oldupgrade.SkillVNum);
                                    }
                                }
                            }

                            Session.Character.Skills[buyPacket.Slot] = new CharacterSkill {
                                SkillVNum = buyPacket.Slot, CharacterId = Session.Character.CharacterId
                            };

                            Session.Character.Gold -= skillinfo.Price;
                            Session.SendPacket(Session.Character.GenerateGold());
                            Session.SendPacket(Session.Character.GenerateSki());
                            Session.SendPackets(Session.Character.GenerateQuicklist());
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SKILL_LEARNED"), 0));
                            Session.SendPacket(Session.Character.GenerateLev());
                        }
                    }
                    else if (npc.Shop.ShopItems.Any())
                    {
                        // npc shop
                        ShopItemDTO item = npc.Shop.ShopItems.FirstOrDefault(it => it.Slot == buyPacket.Slot);
                        if (item == null || amount <= 0 || amount > 99)
                        {
                            return;
                        }
                        Item   iteminfo   = ServerManager.Instance.GetItem(item.ItemVNum);
                        long   price      = iteminfo.Price * amount;
                        long   Reputprice = iteminfo.ReputPrice * amount;
                        double percent;
                        switch (Session.Character.GetDignityIco())
                        {
                        case 3:
                            percent = 1.10;
                            break;

                        case 4:
                            percent = 1.20;
                            break;

                        case 5:
                        case 6:
                            percent = 1.5;
                            break;

                        default:
                            percent = 1;
                            break;
                        }
                        sbyte rare = item.Rare;
                        if (iteminfo.Type == 0)
                        {
                            amount = 1;
                        }
                        if (iteminfo.ReputPrice == 0)
                        {
                            if (price < 0 || price * percent > Session.Character.Gold)
                            {
                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY")));
                                return;
                            }
                        }
                        else
                        {
                            if (Reputprice <= 0 || Reputprice > Session.Character.Reput)
                            {
                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_REPUT")));
                                return;
                            }
                            byte ra = (byte)ServerManager.Instance.RandomNumber();

                            int[] rareprob = { 100, 100, 70, 50, 30, 15, 5, 1 };
                            if (iteminfo.ReputPrice != 0)
                            {
                                for (int i = 0; i < rareprob.Length; i++)
                                {
                                    if (ra <= rareprob[i])
                                    {
                                        rare = (sbyte)i;
                                    }
                                }
                            }
                        }

                        List <ItemInstance> newItem = Session.Character.Inventory.AddNewToInventory(item.ItemVNum, amount, Rare: rare, Upgrade: item.Upgrade, Design: item.Color);
                        if (!newItem.Any())
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(3, Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE")));
                            return;
                        }

                        if (newItem.Any())
                        {
                            if (iteminfo.ReputPrice == 0)
                            {
                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(1, string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"), iteminfo.Name, amount)));
                                Session.Character.Gold -= (long)(price * percent);
                                Session.SendPacket(Session.Character.GenerateGold());
                            }
                            else
                            {
                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(1, string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM_VALID"), iteminfo.Name, amount)));
                                Session.Character.Reput -= Reputprice;
                                Session.SendPacket(Session.Character.GenerateFd());
                                Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("REPUT_DECREASED"), 11));
                            }
                        }
                        else
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                        }
                    }
                }
                break;
            }
            }
        }
Exemplo n.º 18
0
 public ShopItemDTO Insert(ShopItemDTO item)
 {
     throw new NotImplementedException();
 }