public void Refresh() { Player player = context.GetModule <PlayerModule>().GetExistingPlayer(PlayerID); context.GetModule <SkillModule>().ModifyPlayerStats(player); context.GetModule <EffectModule>().ModifyPlayerStats(player); EquipmentBonus bonus = context.GetModule <EquipmentModule>().GetEquipmentBonus(PlayerID); Level = player.Level; HP = player.CurrentHP; MP = player.CurrentMP; MaxHP = player.MaximumHP; Power = player.Strength + bonus.Damage; Defense = player.Fitness + bonus.Armor; Luck = player.Luck; Dexterity = player.Dexterity; WeaponOptimum = bonus.WeaponCritical; ArmorOptimum = bonus.ArmorCritical; Effects = context.GetModule <EffectModule>().GetActivePlayerEffects(player.UserID).Where(e => e is IBattleEffect).ToArray(); }
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); } } } }