/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput() { int oldSelectedEntry = selectedEntry; foreach (MenuEntry entry in MenuEntries) { Rectangle entryRecg = new Rectangle((int)entry.Position.X, (int)entry.Position.Y, entry.Texture.Width, entry.Texture.Height); if (InputManager.IsButtonClicked(entryRecg)) { entry.OnSelectEntry(); return; } } if (InputManager.IsActionTriggered(InputManager.Action.Back) || InputManager.IsActionTriggered(InputManager.Action.ExitGame)) { OnCancel(); } else if (selectedEntry != oldSelectedEntry) { AudioManager.PlayCue("MenuMove"); } }
/// <summary> /// Start executing the combat action. /// </summary> public override void Start() { // play the creation sound effect AudioManager.PlayCue(spell.CreatingCueName); base.Start(); }
/// <summary> /// Handle user input. /// </summary> public override void HandleInput() { // exit the screen if (InputManager.IsActionTriggered(InputManager.Action.Back)) { ExitScreen(); return; } // move the cursor up else if (InputManager.IsActionTriggered(InputManager.Action.CursorUp)) { if (selectionMark == 2) { selectionMark = 1; } } // move the cursor down else if (InputManager.IsActionTriggered(InputManager.Action.CursorDown)) { if (selectionMark == 1) { selectionMark = 2; } } // select an option else if (InputManager.IsActionTriggered(InputManager.Action.Ok)) { if (selectionMark == 1) { int partyCharge = GetChargeForParty(Session.Party); if (Session.Party.PartyGold >= partyCharge) { AudioManager.PlayCue("Money"); Session.Party.PartyGold -= partyCharge; selectionMark = 2; ChangeDialogue(serviceRenderedMessage); HealParty(Session.Party); } else { selectionMark = 2; ChangeDialogue(noGoldMessage); } } else { ExitScreen(); return; } } }
/// <summary> /// Respond to the triggering of the Select action. /// </summary> protected override void SelectTriggered(ContentEntry <Gear> entry) { // if the quantity is zero, don't bother if (selectedQuantity <= 0) { return; } // check to see if gold is selected if (IsGoldSelected) { // play the "pick up gold" cue AudioManager.PlayCue("Money"); // add the gold to the party Session.Party.PartyGold += selectedQuantity; chestEntry.Content.Gold -= selectedQuantity; if (chestEntry.Content.Gold > 0) { selectedQuantity = Math.Min(selectedQuantity, chestEntry.Content.Gold); } else { ResetSelectedQuantity(); } } else { // remove the selected quantity of gear from the chest int quantity = selectedQuantity; if ((entry.Content != null) && (quantity > 0)) { Session.Party.AddToInventory(entry.Content, quantity); entry.Count -= quantity; } if (entry.Count > 0) { selectedQuantity = Math.Min(entry.Count, selectedQuantity); } else { // if the entry is now empty, remove it from the chest chestEntry.Content.Entries.RemoveAt(SelectedGearIndex); ResetSelectedQuantity(); } } }
/// <summary> /// Update the combatant for this frame. /// </summary> public virtual void Update(GameTime gameTime) { float elapsedSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds; // update the combat action if (combatAction != null) { // update the combat action combatAction.Update(gameTime); // remove the combat action if it is done and set the turn-taken flag if (combatAction.Stage == CombatAction.CombatActionStage.Complete) { combatAction = null; isTurnTaken = true; } } // update the combat sprite animation CombatSprite.UpdateAnimation(elapsedSeconds); // check for death if (!IsDeadOrDying && (Statistics.HealthPoints <= 0)) { AudioManager.PlayCue("Death"); State = RolePlayingGameData.Character.CharacterState.Dying; } // check for waking up else if (IsDeadOrDying && (Statistics.HealthPoints > 0)) { State = RolePlayingGameData.Character.CharacterState.Idle; } else if (CombatSprite.IsPlaybackComplete) { if (State == RolePlayingGameData.Character.CharacterState.Hit) { State = RolePlayingGameData.Character.CharacterState.Idle; } else if (State == RolePlayingGameData.Character.CharacterState.Dying) { State = RolePlayingGameData.Character.CharacterState.Dead; } } }
/// <summary> /// Respond to the triggering of the Y button (and related key). /// </summary> protected override void ButtonYPressed(ContentEntry <Gear> entry) { // add the entire amount of gold if (chestEntry.Content.Gold > 0) { AudioManager.PlayCue("Money"); Session.Party.PartyGold += chestEntry.Content.Gold; chestEntry.Content.Gold = 0; } // add all items at full quantity // -- there is no limit to the party's inventory ReadOnlyCollection <ContentEntry <Gear> > entries = GetDataList(); foreach (ContentEntry <Gear> gearEntry in entries) { Session.Party.AddToInventory(gearEntry.Content, gearEntry.Count); } // clear the entries, as they're all gone now chestEntry.Content.Entries.Clear(); selectedQuantity = 0; }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput() { int oldSelectedEntry = selectedEntry; // Move to the previous menu entry? if (InputManager.IsActionTriggered(InputManager.Action.CursorUp)) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } } // Move to the next menu entry? if (InputManager.IsActionTriggered(InputManager.Action.CursorDown)) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } } // Accept or cancel the menu? if (InputManager.IsActionTriggered(InputManager.Action.Ok)) { AudioManager.PlayCue("Continue"); OnSelectEntry(selectedEntry); } else if (InputManager.IsActionTriggered(InputManager.Action.Back) || InputManager.IsActionTriggered(InputManager.Action.ExitGame)) { OnCancel(); } else if (selectedEntry != oldSelectedEntry) { AudioManager.PlayCue("MenuMove"); } }
/// <summary> /// Starts a new combat stage. Called right after the stage changes. /// </summary> /// <remarks>The stage never changes into NotStarted.</remarks> protected override void StartStage() { switch (stage) { case CombatActionStage.Preparing: // called from Start() { // play the animations combatant.CombatSprite.PlayAnimation("SpellCast"); spellSpritePosition = Combatant.Position; spell.SpellSprite.PlayAnimation("Creation"); // remove the magic points Combatant.PayCostForSpell(spell); } break; case CombatActionStage.Advancing: { // play the animations spell.SpellSprite.PlayAnimation("Traveling"); // calculate the projectile destination projectileDirection = Target.Position - Combatant.OriginalPosition; totalProjectileDistance = projectileDirection.Length(); projectileDirection.Normalize(); projectileDistanceCovered = 0f; // determine if the projectile is flipped if (Target.Position.X > Combatant.Position.X) { projectileSpriteEffect = SpriteEffects.FlipHorizontally; } else { projectileSpriteEffect = SpriteEffects.None; } } break; case CombatActionStage.Executing: { // play the animation spell.SpellSprite.PlayAnimation("Impact"); // apply the spell effect to the primary target bool damagedAnyone = ApplySpell(Target); // apply the spell to the secondary targets foreach (Combatant targetCombatant in CombatEngine.SecondaryTargetedCombatants) { // skip dead or dying targets if (targetCombatant.IsDeadOrDying) { continue; } // apply the spell damagedAnyone |= ApplySpell(targetCombatant); } // play the impact sound effect if (damagedAnyone) { AudioManager.PlayCue(spell.ImpactCueName); if (spell.Overlay != null) { spell.Overlay.PlayAnimation(0); spell.Overlay.ResetAnimation(); } } } break; case CombatActionStage.Returning: // play the animation combatant.CombatSprite.PlayAnimation("Idle"); break; case CombatActionStage.Finishing: // play the animation combatant.CombatSprite.PlayAnimation("Idle"); break; case CombatActionStage.Complete: // play the animation combatant.CombatSprite.PlayAnimation("Idle"); // make sure that the overlay has stopped spell.Overlay.StopAnimation(); break; } }
/// <summary> /// Starts a new combat stage. Called right after the stage changes. /// </summary> /// <remarks>The stage never changes into NotStarted.</remarks> protected override void StartStage() { switch (stage) { case CombatActionStage.Preparing: // called from Start() { // play the animation combatant.CombatSprite.PlayAnimation("Idle"); } break; case CombatActionStage.Advancing: { // play the animation combatant.CombatSprite.PlayAnimation("Walk"); // calculate the advancing destination if (Target.Position.X > Combatant.Position.X) { advanceDirection = Target.Position - Combatant.OriginalPosition - advanceOffset; } else { advanceDirection = Target.Position - Combatant.OriginalPosition + advanceOffset; } totalAdvanceDistance = advanceDirection.Length(); advanceDirection.Normalize(); advanceDistanceCovered = 0f; } break; case CombatActionStage.Executing: { // play the animation combatant.CombatSprite.PlayAnimation("Attack"); // play the audio Weapon weapon = combatant.Character.GetEquippedWeapon(); if (weapon != null) { AudioManager.PlayCue(weapon.SwingCueName); } else { AudioManager.PlayCue("StaffSwing"); } } break; case CombatActionStage.Returning: { // play the animation combatant.CombatSprite.PlayAnimation("Walk"); // calculate the damage Int32Range damageRange = combatant.Character.TargetDamageRange + combatant.Statistics.PhysicalOffense; Int32Range defenseRange = Target.Character.HealthDefenseRange + Target.Statistics.PhysicalDefense; int damage = Math.Max(0, damageRange.GenerateValue(Session.Random) - defenseRange.GenerateValue(Session.Random)); // apply the damage if (damage > 0) { // play the audio Weapon weapon = combatant.Character.GetEquippedWeapon(); if (weapon != null) { AudioManager.PlayCue(weapon.HitCueName); } else { AudioManager.PlayCue("StaffHit"); } // damage the target Target.DamageHealth(damage, 0); if ((weapon != null) && (weapon.Overlay != null)) { weapon.Overlay.PlayAnimation(0); weapon.Overlay.ResetAnimation(); } } } break; case CombatActionStage.Finishing: { // play the animation combatant.CombatSprite.PlayAnimation("Idle"); } break; case CombatActionStage.Complete: { // play the animation combatant.CombatSprite.PlayAnimation("Idle"); } break; } }
/// <summary> /// Starts a new combat stage. Called right after the stage changes. /// </summary> /// <remarks>The stage never changes into NotStarted.</remarks> protected override void StartStage() { switch (stage) { case CombatActionStage.Preparing: // called from Start() { // play the animations combatant.CombatSprite.PlayAnimation("ItemCast"); itemSpritePosition = Combatant.Position; item.SpellSprite.PlayAnimation("Creation"); Session.Party.RemoveFromInventory(item, 1); } break; case CombatActionStage.Advancing: { // play the animations item.SpellSprite.PlayAnimation("Traveling"); // calculate the projectile destination projectileDirection = Target.Position - Combatant.OriginalPosition; totalProjectileDistance = projectileDirection.Length(); projectileDirection.Normalize(); projectileDistanceCovered = 0f; // determine if the projectile is flipped if (Target.Position.X > Combatant.Position.X) { projectileSpriteEffect = SpriteEffects.FlipHorizontally; } else { projectileSpriteEffect = SpriteEffects.None; } } break; case CombatActionStage.Executing: // play the animation item.SpellSprite.PlayAnimation("Impact"); // apply the item effect to the primary target bool damagedAnyone = ApplyItem(Target); // apply the item effect to the secondary targets foreach (Combatant targetCombatant in CombatEngine.SecondaryTargetedCombatants) { // skip any dead or dying combatants if (targetCombatant.IsDeadOrDying) { continue; } // apply the effect damagedAnyone |= ApplyItem(targetCombatant); } // play the impact sound effect if (damagedAnyone) { AudioManager.PlayCue(item.ImpactCueName); if (item.Overlay != null) { item.Overlay.PlayAnimation(0); item.Overlay.ResetAnimation(); } } break; case CombatActionStage.Returning: // play the animation combatant.CombatSprite.PlayAnimation("Idle"); break; case CombatActionStage.Finishing: // play the animation combatant.CombatSprite.PlayAnimation("Idle"); break; case CombatActionStage.Complete: // play the animation combatant.CombatSprite.PlayAnimation("Idle"); break; } }
/// <summary> /// Handle user input. /// </summary> public override void HandleInput() { bool stayClicked = false; bool leaveClicked = false; if (InputManager.IsButtonClicked(new Rectangle((int)stayPosition.X, (int)stayPosition.Y, 120, 40))) { int partyCharge = GetChargeForParty(Session.Party); if (Session.Party.PartyGold >= partyCharge) { AudioManager.PlayCue("Money"); Session.Party.PartyGold -= partyCharge; selectionMark = 2; ChangeDialogue(serviceRenderedMessage); HealParty(Session.Party); } else { selectionMark = 2; ChangeDialogue(noGoldMessage); } } if (InputManager.IsButtonClicked(new Rectangle((int)leavePosition.X, (int)leavePosition.Y, 120, 40))) { ExitScreen(); } // exit the screen if (InputManager.IsActionTriggered(InputManager.Action.Back)) { ExitScreen(); return; } // move the cursor up else if (InputManager.IsActionTriggered(InputManager.Action.CursorUp) || stayClicked) { if (selectionMark == 2) { selectionMark = 1; } } // move the cursor down else if (InputManager.IsActionTriggered(InputManager.Action.CursorDown) || leaveClicked) { if (selectionMark == 1) { selectionMark = 2; } } // select an option else if (InputManager.IsActionTriggered(InputManager.Action.Ok)) { if (selectionMark == 1) { int partyCharge = GetChargeForParty(Session.Party); if (Session.Party.PartyGold >= partyCharge) { AudioManager.PlayCue("Money"); Session.Party.PartyGold -= partyCharge; selectionMark = 2; ChangeDialogue(serviceRenderedMessage); HealParty(Session.Party); } else { selectionMark = 2; ChangeDialogue(noGoldMessage); } } else { ExitScreen(); return; } } }