123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #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
- {
- /// <summary>
- /// Encapsulates all of the combat-runtime data for a particular monster combatant.
- /// </summary>
- /// <remarks>
- /// 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.
- /// </remarks>
- class CombatantMonster : Combatant
- {
- /// <summary>
- /// The monster content object that this combatant uses.
- /// </summary>
- private Monster monster;
- /// <summary>
- /// The monster content object that this combatant uses.
- /// </summary>
- public Monster Monster
- {
- get { return monster; }
- }
- /// <summary>
- /// The character encapsulated by this combatant.
- /// </summary>
- public override FightingCharacter Character
- {
- get { return monster as FightingCharacter; }
- }
-
-
- #region State
- /// <summary>
- /// The current state of this combatant.
- /// </summary>
- private Character.CharacterState state;
- /// <summary>
- /// The current state of this combatant.
- /// </summary>
- 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
- /// <summary>
- /// The combat sprite for this combatant, copied from the monster.
- /// </summary>
- private AnimatingSprite combatSprite;
- /// <summary>
- /// Accessor for the combat sprite for this combatant.
- /// </summary>
- public override AnimatingSprite CombatSprite
- {
- get { return combatSprite; }
- }
- #endregion
- #region Current Statistics
- /// <summary>
- /// The statistics for this particular combatant.
- /// </summary>
- private StatisticsValue statistics = new StatisticsValue();
- /// <summary>
- /// The current statistics of this combatant.
- /// </summary>
- public override StatisticsValue Statistics
- {
- get { return statistics + CombatEffects.TotalStatistics; }
- }
- /// <summary>
- /// Heals the combatant by the given amount.
- /// </summary>
- 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);
- }
- /// <summary>
- /// Damages the combatant by the given amount.
- /// </summary>
- 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);
- }
-
- /// <summary>
- /// Pay the cost for the given spell.
- /// </summary>
- /// <returns>True if the cost could be paid (and therefore was paid).</returns>
- 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
- /// <summary>
- /// The artificial intelligence data for this particular combatant.
- /// </summary>
- private ArtificialIntelligence artificialIntelligence;
- /// <summary>
- /// The artificial intelligence data for this particular combatant.
- /// </summary>
- public ArtificialIntelligence ArtificialIntelligence
- {
- get { return artificialIntelligence; }
- }
- #endregion
- #region Initialization
- /// <summary>
- /// Create a new CombatMonster object containing the given monster.
- /// </summary>
- /// <param name="monster"></param>
- 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
- /// <summary>
- /// Update the monster for this frame.
- /// </summary>
- 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
- }
- }
|