Пример #1
0
        public void Heal(string service, string channel, string username)
        {
            User   user   = context.GetModule <UserModule>().GetExistingUser(service, username);
            Player player = context.GetModule <PlayerModule>().GetExistingPlayer(service, username);
            int    toheal = player.MaximumHP - player.CurrentHP;

            if (toheal == 0 && !string.IsNullOrEmpty(channel))
            {
                context.GetModule <StreamModule>().SendMessage(service, channel, username, "No need to heal yourself.");
                return;
            }

            FullInventoryItem[] items = context.GetModule <InventoryModule>().GetInventoryItems(player.UserID, ItemType.Consumable);

            SkillConsumption skill = context.GetModule <SkillModule>().GetSkill(player.UserID, SkillType.Heal);

            if (skill != null)
            {
                if (context.GetModule <SkillModule>().GetSkillCost(SkillType.Heal, skill.Level) <= player.CurrentMP)
                {
                    context.GetModule <SkillModule>().Cast(channel, user, player, SkillType.Heal);
                    return;
                }
            }

            FullInventoryItem bestitem = items.OrderBy(i => Math.Abs(toheal - i.HP)).FirstOrDefault();

            if (bestitem == null)
            {
                context.GetModule <StreamModule>().SendMessage(service, channel, username, "No healing item available.");
                return;
            }

            context.GetModule <SkillModule>().ModifyPlayerStats(player);
            context.GetModule <EffectModule>().ModifyPlayerStats(player);

            context.GetModule <InventoryModule>().UseItem(channel, user, player, context.GetModule <ItemModule>().GetItem(bestitem.ID));
        }
Пример #2
0
        void OnItemFound(long playerid, long itemid, int quantity)
        {
            AwarenessContext playercontext;

            if (!afkdetection.TryGetValue(playerid, out playercontext))
            {
                return;
            }

            // automatic item selling is done by level 1
            if (playercontext.Level < 1)
            {
                return;
            }

            Item item = context.GetModule <ItemModule>().GetItem(itemid);

            if (item.Type == ItemType.Gold)
            {
                return;
            }

            if (context.GetModule <ItemModule>().IsIngredient(itemid))
            {
                // automatic crafting is done by level 3
                if (playercontext.Level >= 3)
                {
                    ItemRecipe[] recipes = context.GetModule <ItemModule>().GetRecipes(itemid).OrderByDescending(r => r.Ingredients.Length).ToArray();
                    foreach (ItemRecipe recipe in recipes)
                    {
                        if (context.GetModule <InventoryModule>().HasItems(playerid, recipe.Ingredients.Select(i => i.Item).ToArray()))
                        {
                            context.GetModule <InventoryModule>().CraftItem(playerid, context.GetModule <ItemModule>().GetItems(recipe.Ingredients.Select(i => i.Item)).ToArray());
                            return;
                        }
                    }
                }
            }

            if (item.Type == ItemType.Consumable)
            {
                Player player = context.GetModule <PlayerModule>().GetExistingPlayer(playerid);
                if (item.HP < player.MaximumHP * 0.35)
                {
                    context.GetModule <ShopModule>().SellItem(playerid, item, quantity, context.GetModule <ShopModule>().IsInsultNecessaryToSell(playerid, itemid) ? 0.2 : 0.0);
                    return;
                }
            }
            else if (item.Type == ItemType.Weapon || item.Type == ItemType.Armor)
            {
                if (item.LevelRequirement > context.GetModule <PlayerModule>().GetLevel(playerid))
                {
                    return;
                }

                EquipmentBonus bonus = context.GetModule <EquipmentModule>().GetEquipmentBonus(playerid, item.GetTargetSlot());
                if ((item.Type == ItemType.Weapon && bonus.Damage >= item.Damage) || (item.Type == ItemType.Armor && bonus.Armor >= item.Armor))
                {
                    context.GetModule <ShopModule>().SellItem(playerid, item, quantity, context.GetModule <ShopModule>().IsInsultNecessaryToSell(playerid, itemid) ? 0.2 : 0.0);
                }
                else
                {
                    EquipmentItem olditem = context.GetModule <EquipmentModule>().Equip(playerid, item, item.GetTargetSlot());
                    if (quantity > 1)
                    {
                        context.GetModule <ShopModule>().SellItem(playerid, item, quantity - 1, context.GetModule <ShopModule>().IsInsultNecessaryToSell(playerid, itemid) ? 0.2 : 0.0);
                    }
                    context.GetModule <ShopModule>().SellItem(playerid, olditem.ItemID, 1, context.GetModule <ShopModule>().IsInsultNecessaryToSell(playerid, olditem.ItemID) ? 0.2 : 0.0);
                }
                return;
            }

            context.GetModule <ShopModule>().SellItem(playerid, item, quantity, context.GetModule <ShopModule>().IsInsultNecessaryToSell(playerid, itemid) ? 0.2 : 0.0);

            if (playercontext.Level >= 3)
            {
                int sizethreshold = (int)(context.GetModule <InventoryModule>().GetMaximumInventorySize(playerid) * 0.8);

                if (context.GetModule <InventoryModule>().GetInventorySize(playerid) > sizethreshold)
                {
                    List <FullInventoryItem> inventory = new List <FullInventoryItem>(context.GetModule <InventoryModule>().GetInventoryItems(playerid));

                    while (inventory.Count > sizethreshold)
                    {
                        FullInventoryItem sellitem = inventory.Where(i => i.Type == ItemType.Misc && i.Name != "Pee" && i.Name != "Poo").OrderBy(i => i.Value).FirstOrDefault();
                        if (sellitem == null)
                        {
                            sellitem = inventory.FirstOrDefault(i => i.Type == ItemType.Potion && i.HP == 0);
                        }
                        if (sellitem == null)
                        {
                            sellitem = inventory.Where(i => i.Type == ItemType.Consumable).OrderBy(i => i.Value).FirstOrDefault();
                        }
                        if (sellitem == null)
                        {
                            break;
                        }

                        context.GetModule <ShopModule>().SellItem(playerid, sellitem.ID, sellitem.Quantity, context.GetModule <ShopModule>().IsInsultNecessaryToSell(playerid, sellitem.ID) ? 0.2 : 0.0);
                        inventory.Remove(sellitem);
                    }
                }
            }
        }