public void TakeDamage(Spell spell) { if (!spell.EnemyHit) { Vector2 damageTextPos = new Vector2(this.transform.position.x, this.transform.position.y + 2); if (spell.SpellDamageType == _weakness) { //if the damage type of the spell is the same as the weakness of the enemy, do double damage _currentHealth -= spell.SpellDamage * 2; ShowDamage.onShowDamage(damageTextPos, spell.SpellDamage * 2, true); ScreenShake.onScreenShake(4); } else { //IF the spells damage type is not the same as the weakness of the enemy, deal normal damage _currentHealth -= spell.SpellDamage; ShowDamage.onShowDamage(damageTextPos, spell.SpellDamage, false); ScreenShake.onScreenShake(1); } spell.EnemyHit = true; //This is to make sure spells dont hit multiple enemies StartCoroutine(TakeDamageRoutine(0.3f)); } _healthbar.ChangeHealth(_currentHealth, _maxHealth); if (_currentHealth <= 0) { Death(); } }
private void UpdateCommandState() { switch (commandState) { case CommandState.Idle: if (activeCommands.Count > 0) { // Is the acting character alive? if (activeCommands.Peek().owner.entity.isDisabled) { activeCommands.Dequeue(); } else { stateTimer = activationPauseTime; commandState = CommandState.HighlightActor; } } break; case CommandState.HighlightActor: silhouettes[activeCommands.Peek().owner].enabled = true; stateTimer -= Time.deltaTime; if (stateTimer <= 0) { stateTimer = marqueeTime; commandState = CommandState.ShowMarquee; } break; case CommandState.ShowMarquee: stateTimer -= Time.deltaTime; if (stateTimer <= 0) { stateTimer = hesitationTime; commandState = CommandState.Hesitation; } break; case CommandState.Hesitation: stateTimer -= Time.deltaTime; if (stateTimer <= 0) { stateTimer = effectsTime; commandState = CommandState.Effects; CommandBase activeCommand = activeCommands.Peek(); // Single-target retargeting - if the target actor // is already dead, retarget a different actor on // the target actor's team if (activeCommand.targetActors.Count == 1 && activeCommand.targetActors[0].entity.isDead && activeCommand.isRetargetable) { bool targetIsEnemy = (activeCommand.targetActors[0] as EnemyCombatController != null); if (targetIsEnemy) { activeCommand.targetActors[0] = enemyActors[0]; } else { activeCommand.targetActors[0] = playerActors[0]; // May need to refine this since player actors don't really go away. } } List <CombatEffectBase> effects = activeCommands.Peek().Execute(); foreach (CombatEffectBase effect in effects) { effect.Process(); if (effect as WeaponDamage != null) { ShowDamage show = effect.target.gameObject.AddComponent <ShowDamage>(); show.damage = effect.displayText; show.lifetime = effectsTime; show.displayStyle = effectsStyle; if (enemyActors.Contains(effect.target as EnemyCombatController)) { if (effect.target.entity.isDead) { enemyActors.Remove(effect.target as EnemyCombatController); } } } } } break; case CommandState.Effects: stateTimer -= Time.deltaTime; if (stateTimer <= 0) { stateTimer = postCommandCooldownTime; commandState = CommandState.Cooldown; activeCommands.Peek().owner.ProcessCommand(activeCommands.Peek()); } break; case CommandState.Cooldown: silhouettes[activeCommands.Peek().owner].enabled = false; stateTimer -= Time.deltaTime; if (stateTimer <= 0) { activeCommands.Dequeue(); commandState = CommandState.Idle; } break; } }
public void Awake() { GameManager.onBattlePhase.AddListener(Battle); showDamage = GetComponent <ShowDamage>(); }