//Does a bullet have a reference to an attack?
    //or does a bullet behave like an attack?

    public Projectile(ProjectilePrototype proto, RangedAttack attack, Vector2 direction) : base(proto, attack, direction)
    {
        frameDelay             = proto.frameDelay;
        this.collidesWithTiles = proto.collidesWithTiles;
        this.attack            = attack;
        isAngled = proto.angled;
        //Body.mState = ColliderState.Closed;
        SetOwner(attack.mEntity);
        hitbox        = new Hitbox(this, new CustomAABB(Position, proto.hitboxSize, new Vector2(0, 0)));
        hitbox.mState = ColliderState.Closed;
        Body          = new PhysicsBody(this, new CustomAABB(Position, proto.bodySize, new Vector2(0, 0)));

        Body.mIsKinematic = true;
        //mMovingSpeed = 100;
        Body.mIgnoresOneWay = true;
        pierce   = proto.pierce;
        isBouncy = proto.bouncy;

        Body.mIgnoresGravity = proto.ignoreGravity;

        mMovingSpeed = proto.speed;

        if (SoundManager.instance != null)
        {
            SoundManager.instance.PlaySingle(proto.spawnSFX);
        }
        //AudioSource.PlayClipAtPoint(sfx, Body.mPosition);
    }
 public override void Initialize()
 {
     base.Initialize();
     projProto  = Instantiate(projProto);
     attributes = new WeaponAttributes();
     attributes.SetStats(baseAttributes);
     ammunitionCount = (int)attributes.GetAttribute(WeaponAttributesType.AmmoCapacity).GetValue();
     projProto.speed = (int)attributes.GetAttribute(WeaponAttributesType.ProjectileSpeed).GetValue();
 }
示例#3
0
    public void Init(ProjectilePrototype iPrototype, Unit iOriginUnit, Vector3 iTargetPoint)
    {
        ApplyPrototype(iPrototype);
        _originUnit   = iOriginUnit;
        _targetEntity = null;
        _targetPoint  = iTargetPoint;

        SpriteRenderer Sprite = this.GetComponent <SpriteRenderer>();

        Sprite.sprite = _prototype._sprite;
    }
示例#4
0
    //
    // Guess is that it targeted a unit the same tick it was destroyed, so was created with a target,
    // But the target stopped existing.


    public void Init(ProjectilePrototype iPrototype, Unit iOriginUnit, Entity iTargetEntity)
    {
        ApplyPrototype(iPrototype);
        _originUnit   = iOriginUnit;
        _targetEntity = iTargetEntity;
        _targetPoint  = _targetEntity.transform.position;

        SpriteRenderer Sprite = this.GetComponent <SpriteRenderer>();

        Sprite.sprite = _prototype._sprite;
    }
示例#5
0
 public void ApplyPrototype(ProjectilePrototype iPrototype)
 {
     _prototype = iPrototype;
 }
    public override bool Attack()
    {
        bool outcome = false;

        /*
         * if(reloading && Time.time > reloadTimeStamp+reloadTime)
         * {
         *  reloading = false;
         *  ammunitionCount = ammunitionCapacity;
         *  Debug.Log("Reloading Complete");
         *
         * }
         */
        if (!reloading && ammunitionCount > 0)
        {
            if (Time.time > fireTimeStamp + (1 / attributes.GetAttribute(WeaponAttributesType.FireRate).GetValue()))
            {
                ammunitionCount--;

                //Debug.Log("Fire " + (ammunitionCapacity - ammunitionCount) + " (Last shot at: " + fireTimeStamp);

                fireTimeStamp = Time.time;

                float interval = attributes.GetAttribute(WeaponAttributesType.SpreadAngle).GetValue() / attributes.GetAttribute(WeaponAttributesType.NumProjectiles).GetValue();

                for (int i = 0; i < attributes.GetAttribute(WeaponAttributesType.NumProjectiles).GetValue(); i++)
                {
                    Vector2 tempDir = equipped.GetAimRight().normalized;

                    if (attributes.GetAttribute(WeaponAttributesType.NumProjectiles).GetValue() > 1)
                    {
                        tempDir = tempDir.Rotate(-attributes.GetAttribute(WeaponAttributesType.SpreadAngle).GetValue() / 2 + (interval * i));
                    }

                    tempDir.Normalize();
                    RangedAttackPrototype attackProto = Instantiate(attack);
                    attackProto.damage     = (int)attributes.GetAttribute(WeaponAttributesType.Damage).GetValue();
                    attackProto.damageType = damageType;
                    ProjectilePrototype tempProto = Instantiate(projProto);
                    tempProto.speed = (int)attributes.GetAttribute(WeaponAttributesType.ProjectileSpeed).GetValue();
                    Projectile shot = new Projectile(tempProto, new RangedAttack(equipped, attackProto), tempDir);
                    shot.Spawn(equipped.Position + new Vector2(0, attackProto.offset.y) + (attackProto.offset * tempDir.normalized));
                }

                foreach (Companion companion in equipped.companionManager.Companions)
                {
                    companion.Fire();
                }
                //Actually fire here
                outcome = true;
            }

            if (ammunitionCount <= 0)
            {
                reloadTimeStamp = Time.time;
                reloading       = true;
                Debug.Log("Reloading");
            }
        }

        return(outcome);
    }
示例#7
0
 public RangedAttack(Entity entity, RangedAttackPrototype prototype) : base(entity, prototype)
 {
     numberOfProjectiles = prototype.numberOfProjectiles;
     spreadAngle         = prototype.spreadAngle;
     projProto           = prototype.projectilePrototype;
 }
示例#8
0
    internal static GameObject CreateProjectile(Unit iOrigin, Vector3 iPosition, Entity iTarget, ProjectilePrototype iPrototype)
    {
        GameObject obj        = (GameObject)GameObject.Instantiate(Active.ProjectilePrefab, iPosition, Quaternion.identity);
        Projectile projectile = obj.GetComponent <Projectile>();

        obj.transform.parent = Active.TowerContainer.transform;

        projectile.Init(iPrototype, iOrigin, iTarget);

        return(obj);
    }
示例#9
0
    // Use this for initialization
    void Start()
    {
        Active = this;

        EffectDefault         = new Effect();
        AttackManagerDefault  = new AttackManagerPrototype(0.0f, 0.0f, 0, EffectDefault);
        AbilityManagerDefault = new AbilityManagerPrototype(0.0f, 0, AbilityManagerPrototype.TRIGGER.ON_ATTACK, EffectDefault);
        PowerManagerDefault   = new PowerManagerPrototype(0, 0);



        Wall = new TowerPrototype("Wall Tower", 2, null);
        Wall._powerManagerPrototype.SetCanRecieve(false);

        // Rock Launcher
        {
            int[] Damage        = { 31, 96, 224, 448, 960, 1680 };      // Would prefer using a function to generate.
            int   BasePrice     = 10;
            int   BasePower     = 50;
            int   BasePowerRate = 10;
            for (int z = 0; z < 6; z++)
            {
                // Create a Effectdamage, and a projectile to deliver it.
                ProjectilePrototype projectilePrototype = new ProjectilePrototype(9.0f, new EffectDamage(Damage [z], true), SpriteProjectileCannon);

                // Make an EffectProjectile to throw said projectile
                Effect effectCreateProjectile = new EffectProjectile(projectilePrototype, false);
                int    level = z + 1;
                // Make a TowerPrototype
                Cannon [z] = new TowerPrototype("Rock Launcher " + level, (int)LevelScale(level, BasePrice), SpriteTurretCannon);
                // Attach an AttackManagerPrototype to throw that effect, also display the damage.
                Cannon [z]._attackManagerPrototype = new AttackManagerPrototype(5.0f, 3.0f, Damage [z], effectCreateProjectile);

                // Attack a SpellManager.
                Effect effectOverclockAdd    = new EffectMutableStat(Tower.ATTACK_SPEED, "overclock", 4.0f, true);
                Effect effectOverclockRemove = new EffectMutableStat(Tower.ATTACK_SPEED, "overclock", false);
                Effect effectAddbuff         = new EffectBuff(new BuffPrototype(effectOverclockAdd, effectOverclockRemove, EffectDefault, 5.0f, 0f, true, "Overclock"), EffectBuff.TARGET.SELF, false);

                Cannon[z]._abilityManagerPrototype = new AbilityManagerPrototype(5.0f, (int)LevelScale(level, 25), AbilityManagerPrototype.TRIGGER.CONSTANT, effectAddbuff, "Overclock", "+300% Attack Speed");
                // (float iCooldown, int iEnergyCost, TRIGGER iTrigger, int iDamageDisplay, Effect iEffect)
                // (5.0f, 25, TRIGGER.ON_ATTACK, -1, new EFFECT(Apply Buff self -cooldown, 5 second, something),"Overclock");


                // Attach a PowerManagerPrototype as well, to supply power.
                Cannon [z]._powerManagerPrototype = new PowerManagerPrototype((int)LevelScale(level, BasePower), (int)LevelScale(level, BasePowerRate));
            }

            for (int z = 0; z < 5; z++)
            {
                Cannon [z].SetUpgradesTo(Cannon [z + 1]);
            }
        }


        {
            // Poison Tower
            int[] Damage        = { 20, 53, 107, 196, 341, 567 };
            int[] AbilityDamage = { 33, 156, 489, 1306, 3218, 7560 };
            int   BasePrice     = 20;
            int[] Power         = { 150, 400, 900, 1700, 3300, 6400 };
            int[] PowerCost     = { 40, 115, 250, 500, 980, 1890 };   //{ 40,113,248,500,979,1890 };
            int[] PowerRate     = { 28, 75, 165, 333, 653, 1260 };
            for (int z = 0; z < 6; z++)
            {
                // Create a Effectdamage, and a projectile to deliver it.
                ProjectilePrototype projectilePrototype = new ProjectilePrototype(5.0f, new EffectDamage(Damage[z], true), SpriteProjectilePoison);

                BuffPrototype       buff = new BuffPrototype(new EffectDamage(AbilityDamage[z], false), EffectDefault, new EffectDamage(AbilityDamage[z] / 10, false), 15.1f, 1.0f, true, "Poison");
                ProjectilePrototype abilityProjectilePrototype = new ProjectilePrototype(9.0f, new EffectBuff(buff, EffectBuff.TARGET.RUNNER, true), SpriteAbilityProjectilePoison);

                // Make an EffectProjectile to throw said projectile
                Effect effect        = new EffectProjectile(projectilePrototype, false);
                Effect effectAbility = new EffectProjectile(abilityProjectilePrototype, false);
                int    level         = z + 1;
                // Make a TowerPrototype
                Poison[z] = new TowerPrototype("Posion Tower " + level, (int)LevelScale(level, BasePrice), SpriteTurretPoison);

                // Attach an AttackManagerPrototype to throw that effect, also display the damage.
                Poison[z]._attackManagerPrototype = new AttackManagerPrototype(3.5f, 0.4f, Damage [z], effect);


                // Attach a SpellManager.
                Poison[z]._abilityManagerPrototype = new AbilityManagerPrototype(
                    3.0f, PowerCost[z],
                    AbilityManagerPrototype.TRIGGER.ON_ATTACK,
                    effectAbility,
                    "Poison",
                    AbilityDamage[z] + "damage + " + (AbilityDamage[z] / 10) + "dps for 15sec"
                    );



                // Attach a PowerManagerPrototype as well, to supply power.
                Poison [z]._powerManagerPrototype = new PowerManagerPrototype(Power[z], LevelScale(level, PowerRate[z]));
            }
            for (int z = 0; z < 5; z++)
            {
                Poison [z].SetUpgradesTo(Poison [z + 1]);
            }
        }


        {
            // Slow Tower
            int[]   Damage        = { 20, 53, 107, 196, 341, 567 };
            int[]   AbilityDamage = { 33, 156, 489, 1306, 3218, 7560 }; // Huh, Poison and Frost have same damage. Well, sort of.
            int     BasePrice     = 15;
            int[]   Power         = { 90, 225, 450, 843, 1551, 2835 };
            int[]   PowerCost     = { 18, 45, 105, 500, 979, 1890 };
            int[]   PowerRate     = { 30, 75, 150, 281, 517, 945 };
            float[] AbilityRange  = { 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f }; // A guess, Revamp later.
            float[] Duration      = { 2f, 4f, 7f, 11f, 16f, 21f };
            for (int z = 0; z < 6; z++)
            {
                // Create a Effectdamage, and a projectile to deliver it.
                ProjectilePrototype projectilePrototype = new ProjectilePrototype(5.0f, new EffectDamage(Damage[z], true), SpriteProjectileFrost);

                Effect effectBuffAdd       = new EffectMutableStat(Runner.MOVEMENT_SPEED, "slow", 0.5f, true);
                Effect effectBuffRemove    = new EffectMutableStat(Runner.MOVEMENT_SPEED, "slow", false);
                Effect effectAddBuff       = new EffectBuff(new BuffPrototype(effectBuffAdd, effectBuffRemove, EffectDefault, Duration[z], 0f, true, "slow"), EffectBuff.TARGET.RUNNER, false);
                Effect effectAOE           = new EffectSplash(effectAddBuff, AbilityRange[z], Effect.TARGET.RUNNER, false);
                Effect effectAbilityDamage = new EffectDamage(AbilityDamage[z], true);
                Effect effectFork          = new EffectFork(effectAOE, effectAbilityDamage, EffectDefault, EffectDefault);
                // Need splash effect and fork effect for this to work correctly.
                // On Impact, call Fork. Damage Target, and AOE on Target ->Apply Debuff
                ProjectilePrototype abilityProjectilePrototype = new ProjectilePrototype(9.0f, effectFork, SpriteAbilityProjectileFrost);

                // Make an EffectProjectile to throw said projectile
                Effect effect        = new EffectProjectile(projectilePrototype, false);
                Effect effectAbility = new EffectProjectile(abilityProjectilePrototype, false);
                int    level         = z + 1;
                // Make a TowerPrototype
                Frost[z] = new TowerPrototype("Frost Tower " + level, (int)LevelScale(level, BasePrice), SpriteTurretFrost);

                // Attach an AttackManagerPrototype to throw that effect, also display the damage.
                Frost[z]._attackManagerPrototype = new AttackManagerPrototype(3.5f, 1f, Damage[z], effect);


                // Attach a SpellManager.
                Frost[z]._abilityManagerPrototype = new AbilityManagerPrototype(
                    1.0f, PowerCost[z],
                    AbilityManagerPrototype.TRIGGER.ON_ATTACK,
                    effectAbility,
                    "Slow",
                    "50% Slow for " + Duration[z] + "sec"
                    );



                // Attach a PowerManagerPrototype as well, to supply power.
                Frost[z]._powerManagerPrototype = new PowerManagerPrototype(Power[z], LevelScale(level, PowerRate[z]));
            }
            for (int z = 0; z < 5; z++)
            {
                Frost[z].SetUpgradesTo(Frost[z + 1]);
            }
        }

        {
            // Pyro Trap -- NYA
            int   BasePrice     = 25;
            int[] Damage        = { 2, 5, 11, 24, 51, 105 };
            int[] AbilityDamage = { 450, 1443, 3594, 8220, 18135, 39375 };
            float Range         = 1.5f;
            float AbilityRange  = 1.75f;
            int[] Power         = { 200, 600, 2000, 4000, 8000, 20000 };
            int[] PowerCost     = { 113, 356, 875, 1968, 4360, 9450 };
            int[] PowerRate     = { 25, 80, 194, 441, 967, 2100 };
            for (int z = 0; z < 6; z++)
            {
                int level = z + 1;

                // Create a Splash effect that Applies a damage over time buff.
                EffectDamage initialDamage  = new EffectDamage(AbilityDamage[z], false);
                EffectDamage periodicDamage = new EffectDamage(AbilityDamage[z] / 20, false);

                BuffPrototype buff = new BuffPrototype(initialDamage, EffectDefault, periodicDamage, 10.1f, 1.0f, true, "Pyro", "On Fire");

                EffectBuff   dotEffect    = new EffectBuff(buff, Effect.TARGET.RUNNER, false);
                EffectSplash splashEffect = new EffectSplash(dotEffect, AbilityRange, Effect.TARGET.RUNNER, false);

                // Create a direct damage effect.
                EffectDamage attackDamage = new EffectDamage(Damage[z], false);


                // Make a TowerPrototype
                Pyro[z] = new TowerPrototype("Pyro Trap " + level, (int)LevelScale(level, BasePrice), null);

                // Attach an AttackManagerPrototype to throw that effect, also display the damage.
                Pyro[z]._attackManagerPrototype = new AttackManagerPrototype(Range, 1.0f, Damage [z], attackDamage);


                // Attack a SpellManager.
                Pyro[z]._abilityManagerPrototype = new AbilityManagerPrototype(
                    8.5f, PowerCost[z],
                    AbilityManagerPrototype.TRIGGER.ON_ATTACK,
                    splashEffect,
                    "Firestorm",
                    AbilityDamage[z] + "damage + " + (AbilityDamage[z] / 20) + "dps for 10sec in Range"
                    );



                // Attach a PowerManagerPrototype as well, to supply power.
                Pyro [z]._powerManagerPrototype = new PowerManagerPrototype(Power[z], LevelScale(level, PowerRate[z]));
            }

            for (int z = 0; z < 5; z++)
            {
                Pyro [z].SetUpgradesTo(Pyro [z + 1]);
            }
        }

        {
            // Flame Tower
            int   BaseDamage    = 36;//	  { 36, 108, 252,  540, 1116, 2268 };
            int[] AbilityDamage = { 48, 135, 294, 585, 1116, 2079 };
            int   BasePrice     = 20;
            int[] Power         = { 120, 300, 720, 1440, 3000, 6600 };
            int   BasePowerCost = 15;
            int   BasePowerRate = 40;
            for (int z = 0; z < 6; z++)
            {
                int level = z + 1;

                // Create a Effectdamage, and a projectile to deliver it.
                ProjectilePrototype projectilePrototype        = new ProjectilePrototype(5.0f, new EffectDamage(LevelScale(level, BaseDamage), true), SpriteProjectileFlame);
                ProjectilePrototype abilityProjectilePrototype = new ProjectilePrototype(5.0f, new EffectDamage(LevelScale(level, BaseDamage) + AbilityDamage[z], true), SpriteAbilityProjectileFlame);



                // Make an EffectProjectile to throw said projectile
                Effect effect        = new EffectProjectile(projectilePrototype, false);
                Effect effectAbility = new EffectProjectile(abilityProjectilePrototype, false);
                // Make a TowerPrototype
                Flame[z] = new TowerPrototype("Flame Tower " + level, LevelScale(level, BasePrice), SpriteTurretFlame);

                // Attach an AttackManagerPrototype to throw that effect, also display the damage.
                Flame[z]._attackManagerPrototype = new AttackManagerPrototype(3.0f, 0.75f, LevelScale(level, BaseDamage), effect);


                // Attack a SpellManager.
                Flame[z]._abilityManagerPrototype = new AbilityManagerPrototype(
                    0.75f, (int)LevelScale(level, BasePowerCost),
                    AbilityManagerPrototype.TRIGGER.ON_ATTACK_OVERRIDE,
                    effectAbility,
                    "Ignite",
                    AbilityDamage[z] + " bonus damage."
                    );



                // Attach a PowerManagerPrototype as well, to supply power.
                Flame [z]._powerManagerPrototype = new PowerManagerPrototype(Power[z], (int)LevelScale(level, BasePowerRate));
            }

            for (int z = 0; z < 5; z++)
            {
                Flame [z].SetUpgradesTo(Flame [z + 1]);
            }
        }

        {
            // Lightning Tower
            // Temperarlly a rapid-fire attack tower because no lightning effect yet.
            int BaseDamage        = 3;
            int BaseAbilityDamage = 9;            //90;
            int BasePrice         = 10;
            int BasePower         = 160;
            int BasePowerCost     = 2;        //20;
            int BasePowerRate     = 40;
            for (int z = 0; z < 6; z++)
            {
                int level = z + 1;

                // Create a Effectdamage, and a projectile to deliver it.
                ProjectilePrototype projectilePrototype        = new ProjectilePrototype(5.0f, new EffectDamage(LevelScale(level, BaseDamage), true), SpriteProjectileLightning);
                ProjectilePrototype abilityProjectilePrototype = new ProjectilePrototype(8.0f, new EffectDamage(LevelScale(level, BaseAbilityDamage), true), SpriteAbilityProjectileLightning);



                // Make an EffectProjectile to throw said projectile
                Effect effect        = new EffectProjectile(projectilePrototype, false);
                Effect effectAbility = new EffectProjectile(abilityProjectilePrototype, false);
                // Make a TowerPrototype
                Lightning[z] = new TowerPrototype("Lightning Tower " + level, LevelScale(level, BasePrice), SpriteTurretLightning);

                // Attach an AttackManagerPrototype to throw that effect, also display the damage.
                Lightning[z]._attackManagerPrototype = new AttackManagerPrototype(3.0f, 1f, LevelScale(level, BaseDamage), effect);


                // Attack a SpellManager.
                Lightning[z]._abilityManagerPrototype = new AbilityManagerPrototype(
                    0.1f, LevelScale(level, BasePowerCost),
                    AbilityManagerPrototype.TRIGGER.ON_ATTACK_OVERRIDE,
                    effectAbility,
                    "Lightning",
                    LevelScale(level, BaseAbilityDamage) + " damage."
                    );



                // Attach a PowerManagerPrototype as well, to supply power.
                Lightning [z]._powerManagerPrototype = new PowerManagerPrototype(LevelScale(level, BasePower), (int)LevelScale(level, BasePowerRate));
            }

            for (int z = 0; z < 5; z++)
            {
                Lightning [z].SetUpgradesTo(Lightning [z + 1]);
            }
        }

        {
            // Generator
            int BasePrice           = 5;
            int BasePowerGeneration = 5;
            int BasePowerRate       = 10;
            int BasePowerCap        = 250;

            for (int z = 0; z < 6; z++)
            {
                int level = z + 1;

                Generator [z] = new TowerPrototype("Generator " + level, (int)LevelScale(level, BasePrice), SpriteGenerator);

                // Attach a PowerManagerPrototype as well, to supply power.
                Generator [z]._powerManagerPrototype = new PowerManagerPrototype((int)LevelScale(level, BasePowerCap), (int)LevelScale(level, BasePowerRate));

                Generator[z]._powerManagerPrototype.SetPassiveProduction(LevelScale(level, BasePowerGeneration));
                Generator[z]._powerManagerPrototype.SetCanSend(true);
            }

            for (int z = 0; z < 5; z++)
            {
                Generator [z].SetUpgradesTo(Generator [z + 1]);
            }
        }

        {
            // Transfer Tower
            int BasePrice     = 3;
            int BasePowerRate = 30;
            int BasePowerCap  = 300;

            for (int z = 0; z < 6; z++)
            {
                int level = z + 1;

                Transfer [z] = new TowerPrototype("Transfer Tower " + level, (int)LevelScale(level, BasePrice), SpriteTransfer);

                // Attach a PowerManagerPrototype as well, to supply power.
                Transfer [z]._powerManagerPrototype = new PowerManagerPrototype(((int)Mathf.Pow(3, level - 1) * BasePowerCap), ((int)Mathf.Pow(3, level - 1) * BasePowerRate));

                Transfer[z]._powerManagerPrototype.SetCanSend(true);
                Transfer[z]._powerManagerPrototype.SetCanSendLong(true);
            }

            for (int z = 0; z < 5; z++)
            {
                Transfer [z].SetUpgradesTo(Transfer [z + 1]);
            }
        }
    }
 public EffectProjectile(ProjectilePrototype iProjectilePrototype, bool iDestroy = false)
 {
     _projectilePrototype = iProjectilePrototype;
     _destroySource       = iDestroy;
 }