Esempio n. 1
0
    protected ProjectileHandler SpawnProjectile(
        BaseController sender, Vector2 direction,
        WeaponStats stats, float damage, float statsMod = 1)
    {
        GameObject projectile = Instantiate(projectilPrefab,
                                            GameModes.GetDebrisTransform(sender.team));

        projectile.name = $"{gameObject.name}_Projectile";

        projectile.transform.position =
            (Vector2)transform.position + direction;

        ProjectileHandler handler = projectile
                                    .GetComponent <ProjectileHandler>();

        handler.onUpdate = OnProjectileUpdate;
        handler.onHit    = OnProjectileHit;

        Collider2D collider = handler.body
                              .GetComponent <Collider2D>();

        Physics2D.IgnoreCollision(collider, sender.body.Collider);

        handler.SetStats(sender, damage * statsMod,
                         (life + stats.life) / statsMod,
                         ((speed + stats.speed) / statsMod) * direction.normalized,
                         ((force + stats.force) / 4) * statsMod);

        sender.perks.Activate <IProjectileFired>(1, perk =>
                                                 perk.OnFire(handler));

        return(handler);
    }
Esempio n. 2
0
        public bool OnHit(BaseController self, ProjectileHandler projectile)
        {
            cooldown = 5;

            if (!projectile || shield <= 0)
            {
                return(!Remaining);
            }

            Transform debrisParent = GameModes.GetDebrisTransform(self.team);

            if (shield >= projectile.damage)
            {
                ShieldHealth(-projectile.damage, self);
                Shielded(projectile.transform.position, debrisParent);
                projectile.active = false;

                return(!Remaining);
            }

            projectile.damage -= shield;
            ShieldHealth(-shield, self);
            Shielded(projectile.transform.position, debrisParent);

            return(!Remaining);
        }
Esempio n. 3
0
        public bool OnCollide(BaseController controller, Collision2D collision)
        {
            BaseController other = collision.collider.GetComponent <BaseController>();

            if (other && !controller.IsTeammate(other))
            {
                Vector3 point = collision.contacts[0].point;
                other.TakeDamage(Intensity, controller, point);
                point.z = -5;
                UnityEngine.Object.Destroy(SpawnPrefab(point, null,
                                                       GameModes.GetDebrisTransform(controller.team)), 1f);
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        public bool OnControllerUpdate(BaseController controller, float delta)
        {
            if (controller.stats.HPP >= 1)
            {
                return(false);
            }

            if ((time += delta) >= 5f)
            {
                time -= 5f;
                controller.HitHealth(Intensity);
                UnityEngine.Object.Destroy(SpawnPrefab(controller.transform.position,
                                                       null, GameModes.GetDebrisTransform(controller.team)), 1f);
            }
            return(true);
        }
Esempio n. 5
0
        public bool OnHit(BaseController self, Vector2?attackPosition, ref float damage)
        {
            cooldown = 5;

            if (damage <= 0 || shield <= 0)
            {
                return(!Remaining);
            }

            Transform debrisParent = GameModes.GetDebrisTransform(self.team);

            float reduction = Math.Min(damage, shield);

            damage -= reduction;
            ShieldHealth(-reduction, self);
            Shielded(attackPosition ?? self.transform.position, debrisParent);

            return(!Remaining);
        }