protected virtual float GetDamage(Character enemy, Damage damage) { LevelCheck(); // could happen that the player kills the enemy before he fully spawn (before Start "starts") enemy.LevelCheck(); var dmg = damage.Calculate(this, enemy); LastHitCharacter = enemy; Stats.Hp -= dmg; var floatingText = new FloatingText(this, "-" + (int) dmg, Color.White, 0.4f + dmg/300f); Engine.SpawnObject( floatingText.Name, floatingText ); // bounce back only if the damage is from a ranged enemy if (damage.KnockBack > 0f) BounceBack(damage); AudioSource.Volume = 0.65f; AudioSource.Play(((AudioAsset) Engine.GetAsset("sound_damage")).Clip); TookDamage(dmg); return Stats.Hp; }
private void BounceBack(Damage damage) { //var force = new Force //{ // Owner = this, // Direction = damage.Direction, // Step = BounceSpeed / BounceTime, // DestroyTimer = BounceTime * damage.Spell.KnockBack //}; //forces.Add(force); //Engine.SpawnObject($"{Name}_bouncebackforce_{forceCount++}", force); }
public virtual bool DoDamage(Character enemy, Damage damage = null) { if (damage == null) { // simple (closecombat usually) damage damage = new Damage(this, enemy) {DamageFunc = (ch0, ch1) => ch1.Stats.Attack}; } enemy.GetDamage(this, damage); if (!enemy.IsAlive) Stats.Xp += enemy.Stats.XpReward; return enemy.IsAlive; }