Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Random = UnityEngine.Random;
- public class Minion : Character
- {
- public MinionCard Card;
- public Mechanics Mechanics;
- public override int CurrentAttack
- {
- get
- {
- int modifiedAttack = BaseAttack;
- foreach (Func<int, int> modifier in AttackModifiers)
- {
- modifiedAttack = modifier.Invoke(modifiedAttack);
- if (modifiedAttack < 0)
- {
- modifiedAttack = 0;
- }
- }
- foreach (Func<int, int> modifier in AuraAttackModifiers)
- {
- modifiedAttack = modifier.Invoke(modifiedAttack);
- if (modifiedAttack < 0)
- {
- modifiedAttack = 0;
- }
- }
- return modifiedAttack;
- }
- }
- public override int MaxHealth
- {
- get
- {
- int modifiedHealth = BaseHealth;
- foreach (Func<int, int> modifier in HealthModifiers)
- {
- modifiedHealth = modifier.Invoke(modifiedHealth);
- if (modifiedHealth < 0)
- {
- modifiedHealth = 1;
- }
- }
- foreach (Func<int, int> modifier in AuraHealthModifiers)
- {
- modifiedHealth = modifier.Invoke(modifiedHealth);
- if (modifiedHealth < 0)
- {
- modifiedHealth = 1;
- }
- }
- return modifiedHealth;
- }
- }
- #region Constructor
- public Minion(MinionCard card)
- {
- Player = card.Player;
- Card = card;
- Card.Minion = this;
- BaseAttack = card.BaseAttack;
- CurrentHealth = card.CurrentHealth;
- BaseHealth = card.BaseHealth;
- HasTaunt = card.HasTaunt;
- HasCharge = card.HasCharge;
- HasPoison = card.HasPoison;
- HasWindfury = card.HasWindfury;
- HasDivineShield = card.HasDivineShield;
- IsElusive = card.IsElusive;
- IsForgetful = card.IsForgetful;
- IsStealth = card.IsStealth;
- SpellPower = card.SpellPower;
- CurrentArmor = 0;
- Mechanics = Card.Mechanics;
- }
- #endregion
- #region Methods
- public override void Attack(Character target)
- {
- Debugger.LogMinion(this, "starting attack to " + target.GetName());
- // Removing stealth of the Minion
- IsStealth = false;
- // Checking if minion is Forgetful
- if (IsForgetful)
- {
- // Checking if there's more than 1 enemy (hero + minions)
- if (Player.Enemy.Minions.Count > 0)
- {
- // Random 50% chance
- if (RNG.RandomBool())
- {
- // TODO : Forgetful animation/effect
- // Creating a list of possible targets
- List<Character> possibleTargets = new List<Character>();
- // Adding the enemy hero to the list
- possibleTargets.Add(Player.Enemy.Hero);
- // Adding all enemy minions to the list
- foreach (Minion enemyMinion in Player.Enemy.Minions)
- {
- possibleTargets.Add(enemyMinion);
- }
- // Removing the current target from the possible targets list
- possibleTargets.Remove(target);
- // Selecting a target by random
- int randomTarget = Random.Range(0, possibleTargets.Count);
- // Setting the current target as the random target
- target = possibleTargets[randomTarget];
- Debugger.LogMinion(this, "switched target to " + target.GetTypeName() + " (forgetful)");
- }
- }
- }
- // Firing OnPreAttack events
- MinionPreAttackEvent minionPreAttackEvent = EventManager.Instance.OnMinionPreAttack(this, target, CurrentAttack);
- Mechanics.OnPreAttack.OnNext(minionPreAttackEvent);
- // Redefining target in case it changed when firing events
- target = minionPreAttackEvent.Target;
- // Checking if the Attack was not cancelled
- if (minionPreAttackEvent.Status != PreStatus.Cancelled)
- {
- // Getting both characters current attack
- int attackerAttack = minionPreAttackEvent.DamageAmount;
- int targetAttack = target.CurrentAttack;
- // Queueing attack animation
- ActionQueue.Instance.Add(() => Controller.AnimateAttack(target, attackerAttack, targetAttack), 1f);
- if (target.IsHero())
- {
- // Damaging the enemy hero
- target.Damage(this, attackerAttack);
- // Checking the death of the enemy hero
- target.CheckDeath();
- }
- else if (target.IsMinion())
- {
- Minion targetMinion = target.As<Minion>();
- // Checking if both minions are still alive
- if (this.IsAlive() && target.IsAlive())
- {
- // Damaging both minions
- target.Damage(this, attackerAttack);
- this.Damage(target, targetAttack);
- // Checking the death of both characters
- target.CheckDeath();
- this.CheckDeath();
- // Checking for poison on both minions
- if (this.HasPoison)
- {
- if (attackerAttack > 0)
- {
- Debugger.LogMinion(this, "killed by posion of " + targetMinion.GetName());
- EventManager.Instance.OnMinionPoisoned(targetMinion, this);
- Destroy();
- }
- }
- if (targetMinion.HasPoison)
- {
- if (targetAttack > 0)
- {
- Debugger.LogMinion(targetMinion, "killed by posion of " + this.GetName());
- EventManager.Instance.OnMinionPoisoned(this, targetMinion);
- Destroy();
- }
- }
- }
- }
- // Adding 1 to the current turn attacks counter
- CurrentTurnAttacks++;
- // Firing OnAttacked events
- MinionAttackedEvent minionAttackedEvent = EventManager.Instance.OnMinionAttacked(this, target);
- Mechanics.OnAttacked.OnNext(minionAttackedEvent);
- }
- ActionQueue.Instance.Add(GameManager.Instance.GameUpdate, 0f);
- }
- public override void Heal(int healAmount)
- {
- Debugger.LogMinion(this, "healing for " + healAmount);
- // Firing OnMinionPreHeal events
- MinionPreHealEvent minionPreHealEvent = EventManager.Instance.OnMinionPreHeal(this, healAmount);
- // TODO : Check if heal is transformed to damage and if so, call Damage instead
- // Healing the minion
- CurrentHealth = Mathf.Min(CurrentHealth + minionPreHealEvent.HealAmount, MaxHealth);
- // Firing OnMinionHealed events
- EventManager.Instance.OnMinionHealed(this, minionPreHealEvent.HealAmount);
- // Showing Heal splat
- if (minionPreHealEvent.HealAmount > 0)
- {
- InterfaceManager.Instance.SpawnHealSplatOn(this.Controller, minionPreHealEvent.HealAmount);
- }
- CheckEnrage();
- ActionQueue.Instance.Add(GameManager.Instance.GameUpdate, 0f);
- }
- public override void Damage(Character attacker, int damageAmount)
- {
- // Firing OnMinionPreDamage events
- MinionPreDamageEvent minionPreDamageEvent = EventManager.Instance.OnMinionPreDamage(attacker, this, damageAmount);
- Mechanics.OnPreDamage.OnNext(minionPreDamageEvent);
- Debugger.LogMinion(this, "receiving " + minionPreDamageEvent.DamageAmount + " damage by " + attacker.GetName());
- // Checking for Divine Shield
- if (HasDivineShield)
- {
- // Setting off Divine Shield
- HasDivineShield = false;
- }
- else
- {
- // Substracting the damage to the current health of the Minion
- CurrentHealth -= minionPreDamageEvent.DamageAmount;
- }
- // TODO : Show health loss sprite + amount on token
- // Creating the MinionDamagedEvent
- MinionDamagedEvent minionDamagedEvent = EventManager.Instance.OnMinionDamaged(attacker, this, minionPreDamageEvent.DamageAmount);
- Mechanics.OnDamaged.OnNext(minionDamagedEvent);
- CheckEnrage();
- ActionQueue.Instance.Add(GameManager.Instance.GameUpdate, 0f);
- }
- public void CheckEnrage()
- {
- if (CurrentHealth != MaxHealth)
- {
- Mechanics.OnEnraged.OnNext(this);
- }
- else
- {
- Mechanics.OnDisenraged.OnNext(this);
- }
- ActionQueue.Instance.Add(() => GameManager.Instance.GameUpdate(), 0f);
- }
- public override void CheckDeath()
- {
- if (IsAlive() == false)
- {
- Debugger.LogMinion(this, "died (check)");
- ActionQueue.Instance.Add(Die, 0f);
- }
- }
- public void Die()
- {
- if (Player.DeadMinions.Contains(Card) == false)
- {
- Debugger.LogMinion(this, "died");
- // TODO : Custom animations, sounds, etc ?
- // Firing OnMinionDied events
- EventManager.Instance.OnMinionDied(this);
- Mechanics.Deathrattle.OnNext(this);
- // Removing the minion from the board
- Remove();
- // Adding the Minion to the list of dead Minions
- Player.DeadMinions.Add(Card);
- GameManager.Instance.CurrentTurnDeadMinions++;
- SoundManager.Instance.PlayMinionSound(Card, "Death", 0.25f);
- }
- else
- {
- Debugger.LogMinion(this, " is already in the dead minions list (ERROR)");
- }
- GameManager.Instance.GameUpdate();
- }
- public void Destroy()
- {
- Debugger.LogMinion(this, "destroyed");
- // TODO : Custom animations, sounds, etc ?
- // Firing OnMinionDied events
- EventManager.Instance.OnMinionDied(this);
- Mechanics.Deathrattle.OnNext(this);
- // Removing the minion from the board
- Remove();
- // Adding the Minion to the list of dead Minions
- Player.DeadMinions.Add(Card);
- GameManager.Instance.CurrentTurnDeadMinions++;
- SoundManager.Instance.PlayMinionSound(Card, "Death", 0.25f);
- GameManager.Instance.GameUpdate();
- }
- private void Remove()
- {
- Debugger.LogMinion(this, "removed");
- // Removing the minion from the player list of minions
- Player.Minions.Remove(this);
- // Removing the controller from the board and destroying it
- Player.BoardController.RemoveMinion(this);
- // Delaying controller destroy
- Controller.StartCoroutine(DelayedRemove());
- }
- private IEnumerator DelayedRemove()
- {
- yield return new WaitForSeconds(1);
- // Destroying the controller
- Controller.DestroyController();
- }
- // TODO : Animation
- public BaseCard ReturnToHand()
- {
- Debugger.LogMinion(this, "returns to Hand");
- // Removing the minion from the board
- Remove();
- // Creating a new copy of the card
- BaseCard returnedCard = Card.Copy();
- // Adding the card to the Hand
- Player.AddCardToHand(returnedCard);
- return returnedCard;
- }
- // TODO : Animation
- public BaseCard ReturnToEnemyHand()
- {
- Debugger.LogMinion(this, "returns to enemy Hand");
- // Removing the minion from the board
- Remove();
- // Creating a new copy of the card
- BaseCard returnedCard = Card.Copy();
- // Adding the card to the Hand
- Player.Enemy.AddCardToHand(returnedCard);
- return returnedCard;
- }
- // TODO : Animation
- public BaseCard ReturnToDeck()
- {
- Debugger.LogMinion(this, "returns to Deck");
- // Removing the minion from the board
- Remove();
- // Creating a new copy of the card
- BaseCard returnedCard = Card.Copy();
- // Adding the card to the Deck
- Player.AddCardToDeck(Card.Copy());
- return returnedCard;
- }
- public void Silence()
- {
- Debugger.LogMinion(this, "silenced");
- SoundManager.Instance.Play("Game_Mechanic_Silence");
- Mechanics.RemoveAll();
- AttackModifiers.Clear();
- HealthModifiers.Clear();
- if (CurrentHealth > MaxHealth)
- {
- CurrentHealth = MaxHealth;
- }
- HasTaunt = false;
- HasCharge = false;
- HasPoison = false;
- HasWindfury = false;
- HasDivineShield = false;
- IsImmune = false;
- IsElusive = false;
- IsStealth = false;
- IsNonAttack = false;
- SpellPower = 0;
- IsFrozen = false;
- UnfreezeNextTurn = false;
- IsForgetful = false;
- IsSilenced = true;
- if (Card.MinionAura != null)
- {
- AuraManager.Instance.RemoveMinionAura(Card.MinionAura);
- }
- if (Card.CardAura != null)
- {
- AuraManager.Instance.RemoveCardAura(Card.CardAura);
- }
- if (Card.HeroPowerAura != null)
- {
- AuraManager.Instance.RemoveHeroPowerAura(Card.HeroPowerAura);
- }
- if (Card.HeroAura != null)
- {
- AuraManager.Instance.RemoveHeroAura(Card.HeroAura);
- }
- GameManager.Instance.GameUpdate();
- }
- // TODO : Animation
- public void TransformInto(MinionCard minionCard)
- {
- Debugger.LogMinion(this, "transforming into " + minionCard.Name);
- // Setting the owner of the card
- minionCard.SetOwner(Player);
- MinionController adaptedController = (MinionController) Controller;
- // Creating a new Minion and adapting the current controller
- Minion newMinion = new Minion(minionCard);
- newMinion.Controller = adaptedController;
- adaptedController.Minion = newMinion;
- adaptedController.HoverController.Card = minionCard;
- // Updating visuals of the controller
- newMinion.Controller.UpdateSprites();
- newMinion.Controller.UpdateNumbers();
- adaptedController.HoverController.UpdateNumbers();
- adaptedController.HoverController.UpdateSprites();
- // Replacing the old minion in the player minion list
- int oldMinionIndex = Player.Minions.IndexOf(this);
- Player.Minions[oldMinionIndex] = newMinion;
- }
- #endregion
- #region Getter Methods
- public int GetPosition()
- {
- return Player.BoardController.GetPositionOf((MinionController) Controller);
- }
- #endregion
- #region Condition Checkers
- public override bool IsMinion()
- {
- return true;
- }
- public bool IsNextTo(Minion other)
- {
- if (this.IsFriendlyOf(other))
- {
- if (this.IsAlive() && other.IsAlive())
- {
- int positionDelta = this.Controller.As<MinionController>().BoardPosition - other.Controller.As<MinionController>().BoardPosition;
- if (Math.Abs(positionDelta) == 1)
- {
- return true;
- }
- }
- }
- return false;
- }
- public override bool CanAttack()
- {
- if (CurrentAttack > 0)
- {
- if (IsNonAttack == false)
- {
- if (IsFrozen == false)
- {
- if (IsSleeping == false || HasCharge)
- {
- if (HasWindfury)
- {
- return CurrentTurnAttacks < 2;
- }
- else
- {
- return CurrentTurnAttacks < 1;
- }
- }
- }
- }
- }
- return false;
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement