public bool can_take_active_item(Game_Actor actor) { if (!this.can_take) { return(false); } var item_data = this.active_item.get_item(); return(actor.can_take(item_data)); }
internal void optimize_inventory(Game_Actor actor) { // Store all items; if after getting an inventory the convoy is overfull, // readd old items to make space List <Item_Data> given_items = new List <Item_Data>(); for (int i = actor.num_items - 1; i >= 0; i--) { // Don't give items that can't be given var item = actor.whole_inventory[i]; if (!item.blank_item && actor.can_give(item)) { Data.Add(item); given_items.Insert(0, item); actor.discard_item(i); } } var weapon_types = Global.weapon_types .OrderByDescending(x => actor.weapon_levels(x)) .ToList(); var valid_items = Data.Where(x => actor.can_take(x)); var weapons = valid_items .Where(x => x.is_weapon && !x.to_weapon.is_staff()) .GroupBy(x => x.Id) .SelectMany(x => x.OrderByDescending(y => y.Uses)) .Where(x => actor.is_equippable(x.to_weapon)) .ToList(); var staves = valid_items .Where(x => x.is_weapon && x.to_weapon.is_staff()) .GroupBy(x => x.Id) .SelectMany(x => x.OrderByDescending(y => y.Uses)) .Where(x => actor.is_equippable(x.to_weapon)) .ToList(); var items = valid_items .Where(x => x.is_item) .GroupBy(x => x.Id) .SelectMany(x => x.OrderByDescending(y => y.Uses)) .Where(x => actor.is_useable(x.to_item)) .ToList(); // Vanilla weapon optimize_weapon(InventoryOptimizePasses.VanillaWeapon, actor, weapon_types, weapons); // Healing Items if (actor.can_dance_skill()) { optimize_item(InventoryOptimizePasses.DanceRing, actor, items); } bool staff = false; if (actor.can_staff()) { if (optimize_staff(InventoryOptimizePasses.HealingStaff, actor, weapon_types, staves)) { staff = true; } if (optimize_staff(InventoryOptimizePasses.StatusStaff, actor, weapon_types, staves)) { staff = true; } if (optimize_staff(InventoryOptimizePasses.UtilityStaff, actor, weapon_types, staves)) { staff = true; } } if (!staff) { // Ranged weapon optimize_weapon(InventoryOptimizePasses.RangedWeapon, actor, weapon_types, weapons); // Effect weapon optimize_weapon(InventoryOptimizePasses.EffectWeapon, actor, weapon_types, weapons); // Backup weapon if (actor.weapon_types().Count > 1 && actor.items.Any(x => x.is_weapon)) { WeaponType equipped = actor.items.First(x => x.is_weapon).to_weapon.main_type(); if (actor.items.Where(x => x.is_weapon).All(x => x.to_weapon.main_type() == equipped)) { optimize_weapon(InventoryOptimizePasses.BackupWeapon, actor, weapon_types, weapons); } } } else { if (!optimize_weapon(InventoryOptimizePasses.EffectWeapon, actor, weapon_types, weapons)) { optimize_weapon(InventoryOptimizePasses.RangedWeapon, actor, weapon_types, weapons); } } // Accessories optimize_item(InventoryOptimizePasses.Accessory, actor, items); // Healing Items optimize_item(InventoryOptimizePasses.HealingItem, actor, items); // If the convoy is overfull while (Data.Count > this.convoy_size && !actor.is_full_items && given_items.Any()) { var item = given_items[0]; given_items.RemoveAt(0); int index = Data.IndexOf(item); if (index != -1) { actor.gain_item(Data[index]); Data.RemoveAt(index); } } }