#region File Description //----------------------------------------------------------------------------- // CombatantMonster.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #endregion #region Using Statements using System; using RolePlayingGameData; using Microsoft.Xna.Framework; #endregion namespace RolePlaying { /// /// Encapsulates all of the combat-runtime data for a particular monster combatant. /// /// /// There may be many of a particular Monster in combat. This class adds the /// statistics and AI data that are particular to this particular combatant. /// class CombatantMonster : Combatant { /// /// The monster content object that this combatant uses. /// private Monster monster; /// /// The monster content object that this combatant uses. /// public Monster Monster { get { return monster; } } /// /// The character encapsulated by this combatant. /// public override FightingCharacter Character { get { return monster as FightingCharacter; } } #region State /// /// The current state of this combatant. /// private Character.CharacterState state; /// /// The current state of this combatant. /// public override Character.CharacterState State { get { return state; } set { if (value == state) { return; } state = value; switch (state) { case RolePlayingGameData.Character.CharacterState.Idle: CombatSprite.PlayAnimation("Idle"); break; case RolePlayingGameData.Character.CharacterState.Hit: CombatSprite.PlayAnimation("Hit"); break; case RolePlayingGameData.Character.CharacterState.Dying: statistics.HealthPoints = 0; CombatSprite.PlayAnimation("Die"); break; } } } #endregion #region Graphics Data /// /// The combat sprite for this combatant, copied from the monster. /// private AnimatingSprite combatSprite; /// /// Accessor for the combat sprite for this combatant. /// public override AnimatingSprite CombatSprite { get { return combatSprite; } } #endregion #region Current Statistics /// /// The statistics for this particular combatant. /// private StatisticsValue statistics = new StatisticsValue(); /// /// The current statistics of this combatant. /// public override StatisticsValue Statistics { get { return statistics + CombatEffects.TotalStatistics; } } /// /// Heals the combatant by the given amount. /// public override void Heal(StatisticsValue healingStatistics, int duration) { if (duration > 0) { CombatEffects.AddStatistics(healingStatistics, duration); } else { statistics += healingStatistics; statistics.ApplyMaximum(monster.CharacterStatistics); } base.Heal(healingStatistics, duration); } /// /// Damages the combatant by the given amount. /// public override void Damage(StatisticsValue damageStatistics, int duration) { if (duration > 0) { CombatEffects.AddStatistics(new StatisticsValue() - damageStatistics, duration); } else { statistics -= damageStatistics; statistics.ApplyMaximum(monster.CharacterStatistics); } base.Damage(damageStatistics, duration); } /// /// Pay the cost for the given spell. /// /// True if the cost could be paid (and therefore was paid). public override bool PayCostForSpell(Spell spell) { // check the parameter. if (spell == null) { throw new ArgumentNullException("spell"); } // check the requirements if (Statistics.MagicPoints < spell.MagicPointCost) { return false; } // reduce the player's magic points by the spell's cost statistics.MagicPoints -= spell.MagicPointCost; return true; } #endregion #region Artificial Intelligence /// /// The artificial intelligence data for this particular combatant. /// private ArtificialIntelligence artificialIntelligence; /// /// The artificial intelligence data for this particular combatant. /// public ArtificialIntelligence ArtificialIntelligence { get { return artificialIntelligence; } } #endregion #region Initialization /// /// Create a new CombatMonster object containing the given monster. /// /// public CombatantMonster(Monster monster) : base() { // check the parameter if (monster == null) { throw new ArgumentNullException("monster"); } // assign the parameters this.monster = monster; this.statistics += monster.CharacterStatistics; this.combatSprite = monster.CombatSprite.Clone() as AnimatingSprite; this.State = RolePlayingGameData.Character.CharacterState.Idle; this.CombatSprite.PlayAnimation("Idle"); // create the AI data this.artificialIntelligence = new ArtificialIntelligence(this); } #endregion #region Updating /// /// Update the monster for this frame. /// public override void Update(GameTime gameTime) { // start any waiting action immediately if ((CombatAction != null) && (CombatAction.Stage == CombatAction.CombatActionStage.NotStarted)) { CombatAction.Start(); } base.Update(gameTime); } #endregion } }