protected virtual void applyProjectileHit(Projectile p, PhysicalUnit unit) { unit.ApplyForce(p.Velocity / p.Velocity.Length() * _projectileForce); unit.ApplyDamage(_projectileDamage); if (_dissipateOnHit) p.Active = false; if (_splashRadius > 0) { p.ReadyToSplash = true; p.Velocity = Vector2.Zero; p.ProjectileSprite.PlayAnimation(1); } }
/// <summary> /// Check if target unit is in range. If so, apply force and damage /// </summary> /// <param name="effectPos">origin of effect</param> /// <param name="target">target unit</param> public void TryApply(Vector2 effectPos, PhysicalUnit target, TimeSpan time) { if (utility.XnaHelper.RectangleIntersectsCircle(target.HitRect, effectPos, _radius)) { tempVec.X = target.Position.X - effectPos.X; tempVec.Y = target.Position.Y - effectPos.Y; Vector2.Normalize(tempVec); float factor = Duration == TimeSpan.Zero ? 1 : (float)time.TotalSeconds / (float)Duration.TotalSeconds; target.ApplyForce(_force * factor * tempVec); target.ApplyDamage((_damage * factor)); target.ApplyStatus(_statEffects); } }