<commit_before>﻿using Scripts.Model.Items;
using System;
using System.Collections.Generic;
using UnityEngine;
using Scripts.Model.Characters;
using Scripts.Model.Interfaces;

namespace Scripts.Model.Spells {

    /// <summary>
    /// Unserialized Spellbooks associated with item usage.
    /// </summary>
    /// <seealso cref="Scripts.Model.Spells.SpellBook" />
    public abstract class ItemSpellBook : SpellBook {
        protected Item item;

        /// <summary>
        /// Initializes a new instance of the <see cref="ItemSpellBook"/> class.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="name">The item name.</param>
        /// <param name="verb">The verb. Caster [Verb] ItemName on Target!</param>
        public ItemSpellBook(Item item, TargetType target, string name, string verb) : base(name, item.Icon, target, SpellType.ITEM, PriorityType.ITEM, verb) {
            this.item = item;
            flags.Remove(Flag.CASTER_REQUIRES_SPELL);
        }

        /// <summary>
        /// Gets a detailed name.
        /// Detailed names show the count of the item, and are colored differently based on castability.
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <returns></returns>
        public override string GetDetailedName(Character caster) {
            int count = caster.Inventory.GetCount(item);

            Color color = Color.white;
            if (!IsMeetPreTargetRequirements(caster)) {
                color = Color.grey;
            }

            return caster.Inventory.CountedItemName(item);
        }

        protected override string CreateDescriptionHelper() {
            return item.Description;
        }

        /// <summary>
        /// Determines whether is meet other cast requirements
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <param name="target">The target.</param>
        /// <returns>
        ///   <c>true</c> if [is meet other cast requirements] [the specified caster]; otherwise, <c>false</c>.
        /// </returns>
        protected override sealed bool IsMeetOtherCastRequirements(IPage current, Character caster, Character target) {
            return
                (item.IsUsable(caster, target)
                && IsMeetItemCastRequirements(caster, target))
                || IsOverride();
        }

        /// <summary>
        /// Determines whether is meet other cast requirements, other requirements.
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <param name="target">The target.</param>
        /// <returns>
        ///   <c>true</c> if [is meet other cast requirements2] [the specified caster]; otherwise, <c>false</c>.
        /// </returns>
        protected virtual bool IsMeetItemCastRequirements(Character caster, Character target) {
            return true;
        }

        protected virtual bool IsOverride() {
            return false;
        }
    }
}<commit_msg>fix issue where having both party members toss an item with only 1 count would throw an error instead of having the 2nd attempt fail<commit_after>﻿using Scripts.Model.Items;
using System;
using System.Collections.Generic;
using UnityEngine;
using Scripts.Model.Characters;
using Scripts.Model.Interfaces;

namespace Scripts.Model.Spells {

    /// <summary>
    /// Unserialized Spellbooks associated with item usage.
    /// </summary>
    /// <seealso cref="Scripts.Model.Spells.SpellBook" />
    public abstract class ItemSpellBook : SpellBook {
        protected Item item;

        /// <summary>
        /// Initializes a new instance of the <see cref="ItemSpellBook"/> class.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="name">The item name.</param>
        /// <param name="verb">The verb. Caster [Verb] ItemName on Target!</param>
        public ItemSpellBook(Item item, TargetType target, string name, string verb) : base(name, item.Icon, target, SpellType.ITEM, PriorityType.ITEM, verb) {
            this.item = item;
            flags.Remove(Flag.CASTER_REQUIRES_SPELL);
        }

        /// <summary>
        /// Gets a detailed name.
        /// Detailed names show the count of the item, and are colored differently based on castability.
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <returns></returns>
        public override string GetDetailedName(Character caster) {
            int count = caster.Inventory.GetCount(item);

            Color color = Color.white;
            if (!IsMeetPreTargetRequirements(caster)) {
                color = Color.grey;
            }

            return caster.Inventory.CountedItemName(item);
        }

        protected override string CreateDescriptionHelper() {
            return item.Description;
        }

        /// <summary>
        /// Determines whether is meet other cast requirements
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <param name="target">The target.</param>
        /// <returns>
        ///   <c>true</c> if [is meet other cast requirements] [the specified caster]; otherwise, <c>false</c>.
        /// </returns>
        protected override sealed bool IsMeetOtherCastRequirements(IPage current, Character caster, Character target) {
            return
                (item.IsUsable(caster, target) || IsOverride())
                && IsMeetItemCastRequirements(caster, target);
        }

        /// <summary>
        /// Determines whether is meet other cast requirements, other requirements.
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <param name="target">The target.</param>
        /// <returns>
        ///   <c>true</c> if [is meet other cast requirements2] [the specified caster]; otherwise, <c>false</c>.
        /// </returns>
        protected virtual bool IsMeetItemCastRequirements(Character caster, Character target) {
            return true;
        }

        protected virtual bool IsOverride() {
            return false;
        }
    }
}
{'fraction_non_alphanumeric': 0.12546725174711523, 'fraction_numerical': 0.0006500893872907525, 'mean_word_length': 2.0785392696348173, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3510277', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1580, 'n_words': 454}