public override float getAmmoPercentage()
    {
        if (primaryReloadTimer != null)
        {
            if (primaryReloadTimer.isTimeout())
            {
                int ammoRequired = maxActiveAmmo - activeAmmo;
                if (reserveAmmo >= ammoRequired)
                {
                    activeAmmo  += ammoRequired;
                    reserveAmmo -= ammoRequired;
                }
                else
                {
                    activeAmmo += reserveAmmo;
                    reserveAmmo = 0;
                }
                primaryReloadTimer = null;
            }
            else
            {
                return(primaryReloadTimer.getDisplayResetPercent());
            }
        }
        if (maxActiveAmmo == 0)
        {
            return(primaryReloadTimer?.getDisplayResetPercent() ?? 1);
        }

        return(activeAmmo / (maxActiveAmmo * 1.0f));
    }
 /**
  * Used to set up and start effect once attached
  *     lifeTime determines how long(in seconds) the effect will last
  */
 public virtual void startEffect(float lifeTime)
 {
     if (lifeTime > -1.0f)
     {
         lifeTimer = new GenericTimer(lifeTime, false);
     }
     startEffect();
 }
 void Start()
 {
     primaryResetTimer   = new GenericTimer(primaryResetTime, true);
     secondaryResetTimer = new GenericTimer(secondaryResetTime, true);
     spell  = GetComponent <AbstractWeaponEffect>();
     recoil = GetComponent <Recoil>();
     if (recoil == null)
     {
         recoil = gameObject.AddComponent <Recoil>();
     }
 }
    private void Start()
    {
        timer = new GenericTimer(10, false);
        if (isMultiplayer())
        {
            player1.GetComponentInChildren <Camera>().rect = new Rect(0, 0, 0.5f, 1);
            player2.GetComponentInChildren <Camera>().rect = new Rect(0.5f, 0, 0.5f, 1);
            AudioListener listener = player2.GetComponentInChildren <Camera>().GetComponent <AudioListener>();
            if (listener != null)
            {
                listener.enabled = false;
            }
            player2.transform.parent = null;
        }

        player1.transform.parent = null;
    }
 public void primaryFire()
 {
     if (primarySound != null)
     {
         primarySound.Play();
     }
     recoil.fire();
     playParticleEffect(primaryMuzzleFlash);
     spell.primaryFire(this);
     if (!infiniteAmmo)
     {
         activeAmmo--;
     }
     if (activeAmmo <= 0 && reserveAmmo > 0)
     {
         primaryReloadTimer = new GenericTimer(primaryReloadTime, false);
     }
 }
Exemple #6
0
    public void fire(Vector3 position, Vector3 direction, bool useGravity, float speed, float timeout)
    {
        transform.position = position + direction.normalized;

        timer = new GenericTimer(timeout, false);

        Rigidbody rig = GetComponent <Rigidbody>();

        if (rig != null)
        {
            rig.useGravity = useGravity;
            rig.AddForce(direction.normalized * speed, ForceMode.VelocityChange);
        }

        if (particles != null)
        {
            ParticleSystem effect = Instantiate(particles, gameObject.transform);
            effect.transform.position = transform.position;
            effect.Play();
        }
    }
    private void FixedUpdate()
    {
        if (timer == null)
        {
            return;
        }
        waveText.text = "Next wave: " + (int)(timer.getTimeLeft());
        if (timer.isTimeout())
        {
            waveText.text = "Wave: " + waveNo;
            noDeaths      = 0;
            timer         = null;

            numberSpawned += waveNo + waveNo / 2;
            numberSpawned  = (numberSpawned / spawners.Length);
            numberSpawned *= spawners.Length;
            foreach (var spawner in spawners)
            {
                spawner.spawnObjects(numberSpawned / spawners.Length, objects);
            }
        }
    }
 private void endWave()
 {
     waveNo++;
     timer = new GenericTimer(timeBetweenWaves, false);
 }
Exemple #9
0
 // Start is called before the first frame update
 void Start()
 {
     killTimer = new GenericTimer(timeToKill, false);
 }
 /**
  * Used to set up and start effect once attached
  *      lifeTime determines how long(in seconds) the effect will last
  *      tickTime determines how often affectObject() is called
  */
 public virtual void startEffect(GameObject obj, float tickTime, float lifeTime)
 {
     tickTimer = new GenericTimer(tickTime, true);
     startEffect(lifeTime);
 }
 protected void setLifeTimer(GenericTimer timer)
 {
     lifeTimer = timer;
 }
Exemple #12
0
    public override void Activate(MonsterCharacter character, int index)
    {
        //would result in illegal normalization, need a direction to dash into
        if (character.physicsBody.velocity == Vector2.zero)
        {
            return;
        }

        //need 65% of full power at minimum
        if (character.ChargePoints < (ChargeCost * .65f))
        {
            Sounds.CreateSound(FailSound);
            Messaging.GUI.ScreenMessage.Invoke("NOT ENOUGH CHARGE", Color.red);
            return;
        }

        if (character.SkillCooldowns[index] > 0)
        {
            Sounds.CreateSound(FailSound);
            return;
        }

        Sounds.CreateSound(ActivationSound);

        character.SkillCooldowns[index] = Cooldown;

        float strength = Strength;

        if (character.ChargePoints < ChargeCost)
        {
            strength *= (float)character.ChargePoints / ChargeCost;
            character.ChargePoints = 0;
        }
        else
        {
            character.ChargePoints -= ChargeCost;
        }

        DashSkill d = Instantiate(this, LevelLoader.DynamicObjects);

        d.Strength        = strength;
        d.direction       = character.physicsBody.velocity.normalized;
        d.targetCharacter = character;
        d.timer           = ActiveTime;

        if (AttachmentEffect != null)
        {
            foreach (string attachPoint in AttachmentPoints)
            {
                GameObject effect = Instantiate(AttachmentEffect);

                GenericTimer e = effect.AddComponent <GenericTimer>();
                e.LifeTime = ActiveTime * 5;
                e.OnTimer.AddListener(() =>
                {
                    TrailRenderer tr = effect.GetComponentInChildren <TrailRenderer>();
                    if (tr != null)
                    {
                        tr.emitting = false;
                    }
                });

                DestroyAfterTime t = effect.AddComponent <DestroyAfterTime>();
                t.LifeTime = ActiveTime * 10;

                effect.transform.SetParent(character.GetAttachmentPoint(attachPoint), false);
            }
        }
    }
Exemple #13
0
 private void Start()
 {
     timer       = new GenericTimer(2, true);
     weapon.user = this;
 }