Example #1
0
        /// <summary>
        /// Setups the buff caster from save.
        /// </summary>
        /// <param name="bs">The bs.</param>
        /// <param name="partyMembers">The party members.</param>
        /// <returns></returns>
        public static Buff SetupBuffCasterFromSave(BuffSave bs, List<Character> partyMembers) {
            Buff b = bs.CreateObjectFromID();
            b.InitFromSaveObject(bs);

            Characters.Stats caster = null;
            int id = 0;
            switch (bs.Type) {
                case BuffSave.SaveType.CASTER_IN_PARTY:
                    Util.Assert(bs.PartyIndex >= 0, "Party index is negative.");
                    Character character = partyMembers[bs.PartyIndex];
                    caster = character.Stats;
                    id = character.Id;
                    break;

                // Spoof their stats, and equipment too!
                case BuffSave.SaveType.CASTER_NOT_IN_PARTY:
                    Util.Assert(bs.StatCopy != null, "Statcopy is null.");
                    caster = new Characters.Stats();
                    caster.SetupTemporarySaveFields(true);
                    caster.InitFromSaveObject(bs.StatCopy);
                    id = Character.UNKNOWN_ID;
                    break;
                default:
                    Util.Assert(false, "Unknown SaveType");
                    break;
            }
            b.Caster = new BuffParams(caster, id);

            return b;
        }
Example #2
0
 /// <summary>
 /// Effects that occur at the end of a turn.
 /// </summary>
 /// <param name="owner"></param>
 public void OnEndOfTurn(Characters.Stats owner)
 {
     PerformSpellEffects(OnEndOfTurnHelper(owner));
     if (isDefinite)
     {
         turnsRemaining--;
     }
 }
Example #3
0
 private static bool LearnerHasResourcesNeededToCastSpell(Characters.Stats learner, SpellBook book)
 {
     foreach (StatType type in book.Costs.Keys)
     {
         if (!learner.HasStat(type))
         {
             return(false);
         }
     }
     return(true);
 }
Example #4
0
 /// <summary>
 /// Casters the has resources.
 /// </summary>
 /// <param name="caster">The caster.</param>
 /// <returns></returns>
 public bool CasterHasResources(Characters.Stats caster)
 {
     foreach (KeyValuePair <StatType, int> stat in Costs)
     {
         if (caster.GetStatCount(Characters.Stats.Get.MOD, stat.Key) < stat.Value)
         {
             return(false);
         }
     }
     return(true);
 }
Example #5
0
 /// <summary>
 /// Effects that occur at the end of a turn.
 /// </summary>
 /// <param name="owner"></param>
 public void OnEndOfTurn(Characters.Stats owner)
 {
     // TODO use an overridable condition instead
     if (owner.State == Characters.State.ALIVE)
     {
         PerformSpellEffects(OnEndOfTurnHelper(owner));
     }
     if (isDefinite)
     {
         turnsRemaining--;
     }
 }
Example #6
0
        /// <summary>
        /// Gets the comma separated costs.
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <returns></returns>
        private string GetCommaSeparatedCosts(Characters.Stats caster = null)
        {
            string[] arr = new string[Costs.Count];

            int index = 0;

            foreach (KeyValuePair <StatType, int> pair in Costs)
            {
                arr[index++] = string.Format("{0} {1}",
                                             Util.ColorString(pair.Value.ToString(), caster != null && CasterHasResource(pair.Key, caster)),
                                             Util.ColorString(pair.Key.Name, pair.Key.Color));
            }
            return(string.Join(", ", arr));
        }
Example #7
0
 /// <see cref="OnDispell(Characters.Stats)"/>
 protected virtual IList <SpellEffect> OnDispellHelper(Characters.Stats owner)
 {
     return(OnTimeOutHelper(owner));
 }
Example #8
0
 /// <summary>
 /// Cast when the buff expires.
 /// </summary>
 /// <param name="ownerOfThisBuff">Stats of the character who is the target of the spell</param>
 public void OnTimeOut(Characters.Stats ownerOfThisBuff)
 {
     PerformSpellEffects(OnTimeOutHelper(ownerOfThisBuff));
 }
Example #9
0
 /// <see cref="React(Spell, Characters.Stats)"/>
 protected virtual void ReactHelper(Spell s, Characters.Stats owner)
 {
 }
Example #10
0
 /// <see cref="OnTimeOut(Characters.Stats)"/>
 protected virtual IList <SpellEffect> OnTimeOutHelper(Characters.Stats owner)
 {
     return(new SpellEffect[0]);
 }
Example #11
0
 /// <see cref="React(Spell, Characters.Stats)"/>
 protected virtual void ReactHelper(SingleSpell spellCast, Characters.Stats ownerOfThisBuff)
 {
 }
Example #12
0
 /// <summary>
 /// Cast when the buff is dispelled.
 /// </summary>
 /// <param name="statsOfTheCharacterTheBuffIsOn">Stats of the character who is the target of the spell</param>
 public void OnDispell(Characters.Stats statsOfTheCharacterTheBuffIsOn)
 {
     PerformSpellEffects(OnDispellHelper(statsOfTheCharacterTheBuffIsOn));
 }
Example #13
0
 /// <summary>
 /// Respond to a spell cast in battle.
 /// </summary>
 /// <param name="incomingSpell">Spell cast on character</param>
 /// <param name="statsOfTheCharacterTheBuffIsOn">Stats of the character who is the target of the spell</param>
 public void React(Spell incomingSpell, Characters.Stats statsOfTheCharacterTheBuffIsOn)
 {
     ReactHelper(incomingSpell, statsOfTheCharacterTheBuffIsOn);
 }
Example #14
0
 /// <summary>
 /// Cast when the buff is dispelled.
 /// </summary>
 /// <param name="ownerOfThisBuff">Stats of the character who is the target of the spell</param>
 public void OnDispell(Characters.Stats ownerOfThisBuff)
 {
     PerformSpellEffects(OnDispellHelper(ownerOfThisBuff));
 }
Example #15
0
 /// <summary>
 /// Respond to a spell cast in battle.
 /// </summary>
 /// <param name="incomingSpell">Spell cast on character</param>
 /// <param name="ownerOfThisBuff">Stats of the character who is the target of the spell</param>
 private void React(SingleSpell incomingSpell, Characters.Stats ownerOfThisBuff)
 {
     ReactHelper(incomingSpell, ownerOfThisBuff);
 }
Example #16
0
 /// <summary>
 /// If true, buff will react to the spells being cast in battle. This can be any spell.
 /// The one who has the buff doesn't have to be targeted.
 /// </summary>
 /// <param name="incomingSpell">Spell cast on character</param>
 /// <param name="ownerOfThisBuff">Stats of the character who is the target of the spell</param>
 /// <returns>True if the buff will react.</returns>
 public virtual bool IsReact(SingleSpell incomingSpell, Characters.Stats ownerOfThisBuff)
 {
     return(false);
 }
Example #17
0
 /// <summary>
 /// Effects that occur when the buff is added to a character.
 /// </summary>
 /// <param name="owner"></param>
 public void OnApply(Characters.Stats owner)
 {
     PerformSpellEffects(OnApplyHelper(owner));
 }
Example #18
0
 /// <summary>
 /// Exp earned = Defeated.Level - Earner.Level
 /// </summary>
 /// <param name="earner">Whoever is earning the experience</param>
 /// <param name="defeated">Defeated character to do calculation for</param>
 /// <returns>Calculated experience earner should recieve</returns>
 private int CalculateExperience(Characters.Stats earner, Characters.Stats defeated)
 {
     return(Mathf.Max(0, defeated.Level - earner.Level));
 }
Example #19
0
 public static int GetDifference(StatType type, Characters.Stats a, Characters.Stats b)
 {
     return(a.GetStatCount(Characters.Stats.Get.TOTAL, type) - b.GetStatCount(Characters.Stats.Get.TOTAL, type));
 }
Example #20
0
 /// <summary>
 /// Determines whether [is meet pre target requirements] [the specified caster].
 /// </summary>
 /// <param name="caster">The caster.</param>
 /// <returns>
 ///   <c>true</c> if [is meet pre target requirements] [the specified caster]; otherwise, <c>false</c>.
 /// </returns>
 public bool IsMeetPreTargetRequirements(Characters.Stats caster)
 {
     return(CasterHasResources(caster) && IsMeetOtherPreTargetRequirements());
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuffParams"/> struct.
 /// </summary>
 /// <param name="caster">The caster's stats.</param>
 /// <param name="casterId">A unique id number associated with a character.</param>
 public BuffParams(Characters.Stats caster, int casterId)
 {
     this.Caster   = caster;
     this.CasterId = casterId;
 }
Example #22
0
 /// <summary>
 /// Casters the has resource.
 /// </summary>
 /// <param name="stat">The stat.</param>
 /// <param name="caster">The caster.</param>
 /// <returns></returns>
 public bool CasterHasResource(StatType stat, Characters.Stats caster)
 {
     return(caster.GetStatCount(Characters.Stats.Get.MOD, stat) >= Costs[stat]);
 }
Example #23
0
 /// <summary>
 /// Cast when the buff expires.
 /// </summary>
 /// <param name="statsOfTheCharacterTheBuffIsOn">Stats of the character who is the target of the spell</param>
 public void OnTimeOut(Characters.Stats statsOfTheCharacterTheBuffIsOn)
 {
     PerformSpellEffects(OnTimeOutHelper(statsOfTheCharacterTheBuffIsOn));
 }
Example #24
0
 /// <summary>
 /// If true, buff will react to the spells being cast in battle. This can be any spell.
 /// The one who has the buff doesn't have to be targeted.
 /// </summary>
 /// <param name="incomingSpell">Spell cast on character</param>
 /// <param name="statsOfTheCharacterTheBuffIsOn">Stats of the character who is the target of the spell</param>
 /// <returns></returns>
 public virtual bool IsReact(Spell incomingSpell, Characters.Stats statsOfTheCharacterTheBuffIsOn)
 {
     return(false);
 }
Example #25
0
 /// <see cref="OnEndOfTurn(Characters.Stats)"/>
 protected virtual IList <SpellEffect> OnEndOfTurnHelper(Characters.Stats ownerOfThisBuff)
 {
     return(new SpellEffect[0]);
 }