Example #1
0
    public override IEnumerator Execute(Unit initiator, List <Unit> targets)
    {
        foreach (Unit target in targets)
        {
            bool stun = new Random().Next(1, 100) <= 99;

            var attackDamage = BattleManager.CalculatePhysicalDamage(0.8f * initiator.stats[StatString.PHYSICAL_DAMAGE].Value, target);
            target.stats[StatString.HP].AddModifier(new StatModifier(-attackDamage, StatModType.Flat));
            DamagePopUp.Create(target.transform.position, string.Format("- {0} HP", attackDamage), PopupType.DAMAGE);

            if (stun)
            {
                yield return(new WaitForSeconds(1f));

                Debug.Log("target stunned");
                target.Stun();
                yield return(target.StunAnimation());

                DamagePopUp.Create(target.transform.position, "Stunned!", PopupType.DAMAGE);
            }
        }
        UpdateStats(initiator, targets);

        yield break;
    }
Example #2
0
 public void HitNumber()
 {
     
    Transform damagePopUpTransform = Instantiate(_damagePopUpPreFab, Vector3.zero, Quaternion.identity);
    DamagePopUp damagePopUp = _damagePopUpPreFab.GetComponent<DamagePopUp>();
    damagePopUp.SetUp(300);
 }
    public void Hurt(int damage, float force, Transform obj)
    {
        // show healthbar
        canvas.enabled = true;
        // minus current health by damage
        mCurrentHealth -= damage;
        SetHealth();

        DamagePopUp.CreateEnemy(transform.position, damage);

        // animate hurt animation
        FindObjectOfType <AudioManager>().Play("Hurt");
        animator.SetTrigger("Hurt");
        StartCoroutine(Knockback(knockbackDuration, obj, force));
        // if current drop below 0, play die animation and set enable to boc collider and scripts to
        // false
        if (mCurrentHealth <= 0)
        {
            Die();
            if (enemySpawner != null)                                     // if was spawned by an enemySpawner
            {
                enemySpawner.GetComponent <EnemySpawner>().ifEnemyDied(); // run ifEnemyDied
            }
        }
    }
Example #4
0
    //For when the enemy object takes damage
    public void takeDamage(int damage, bool crit, GameObject source)
    {
        //Debug.Log (gameObject + " takes " + damage + " damage.");

        if (Random.value < chanceSpawnOnHit)
        {
            ObjectPooler.Instance.GetObject(enemy.ObjectPoolIndex, true, spawnpoint.gameObject.transform.position,
                                            Quaternion.Euler(new Vector3(0f, Random.Range(0, 360), 0f)));
        }

        if (healthBar == null)
        {
            InstantiateHealthBar();
        }

        health -= damage;
        healthBarImage.fillAmount = (float)health / startingHealth;
        float lerp = (float)health / (float)startingHealth;

        healthBarImage.color = Color.Lerp(Color.red, Color.magenta, lerp);

        DamagePopUp.CreateDamagePopUp(damage, gameObject, crit);

        if (clip_takeDamage != null)
        {
            ObjectPooler.Instance.PlayAudioSource(clip_takeDamage, mixerGroup, pitchMin, pitchMax, transform);
        }

        if (health <= 0)
        {
            //			Debug.Log ("dead");
            StartCoroutine(spawn());
            Die();
        }
    }
Example #5
0
 void Shoot()
 {
     muzzleFlash.Play();
     //hitEffect.instance.spawnDefaultHitEffect(barrelEnd.position, barrelEnd.transform);
     Debug.DrawRay(barrelEnd.transform.position, barrelEnd.transform.forward * 200f, Color.black);
     if (Physics.Raycast(barrelEnd.transform.position, barrelEnd.transform.forward, out hit, Range) && hit.transform.tag == "Enemy")
     {
         Debug.Log(hit.transform.name);
         Enemies enemy = hit.transform.GetComponent <Enemies>();
         //Enemies enemy = hit.collider.gameObject.GetComponent<Enemies>();
         bool isCritical = UnityEngine.Random.Range(0, 100) < 25;
         if (isCritical)
         {
             bulletDamage *= 2;
         }
         if (explosiveBullets)
         {
             Instantiate(bullet, hit.point, hit.transform.rotation);
         }
         if (enemy != null)
         {
             enemy.TakeDamage(bulletDamage);
         }
         if (hit.rigidbody != null)
         {
             hit.rigidbody.AddForce(-hit.normal * impactForce);
         }
         DamagePopUp.Create(hit.point, bulletDamage, isCritical);
     }
 }
Example #6
0
 public void TakeDamage(int playerDamage)
 {
     mCurrentHP -= playerDamage;
     DeathCheck();
     // DamagePop up as new feature
     DamagePopUp.Create(transform.position, playerDamage);
 }
Example #7
0
    public static void Create(Vector3 position, float damageAmount, Color customColor)
    {
        Transform   damagePopUpTransform = Instantiate(GameAssets.i.pfDamagePopUp, position, Quaternion.identity);
        DamagePopUp damagePopup          = damagePopUpTransform.GetComponent <DamagePopUp>();

        damagePopup.Setup(damageAmount, customColor);
    }
Example #8
0
    //For when the torch takes damage
    public void takeDamage(int damage, bool crit, GameObject source)
    {
        if (isDamagable)
        {
//		Debug.Log (gameObject + " takes " + damage + " damage.");
            health -= damage;
            DamagePopUp.CreateTorchHealthPopUp(damage, ui, true);
            updateHealth();
            TorchFOV.SetTrigger("TakeDamage");

            if (health <= 0)
            {
                health = 0;
                updateHealth();

                string sourceString = source.name;
                if (sourceString.EndsWith("(Clone)"))
                {
                    sourceString = sourceString.Remove(sourceString.Length - 7);
                }
                Debug.Log("Player dies by taking " + damage + " from " + sourceString);
                gameManager.deathCanvas.SetCauseText("by taking " + damage + " damage from " + sourceString + ".");

                Die();
            }
        }
    }
Example #9
0
    public void TakeDamage(int damage, float knockbackForce, Transform obj)
    {
        if (isDead)
        {
            return;
        }

        if (isGod is false)
        {
            if (halfDamage)
            {
                damage = damage / 2;
            }
            health -= damage;
            SetHealth();
            DamagePopUp.CreatePlayer(transform.position, damage);
        }

        heroMovement.Knockback(obj, knockbackForce);
        animator.SetBool("IsJumping", false);

        FindObjectOfType <AudioManager>().Play("Hurt");

        animator.SetTrigger("Hurt");

        if (health < 1)
        {
            Death();
        }
    }
Example #10
0
    //Create a damage popup
    public static DamagePopUp Create(Vector3 position, string effect, bool isWounding)
    {
        Transform   damagePopUpTransform = Instantiate(GameAssets.i.damagePopUp, position + new Vector3(0, 0.5f), Camera.main.transform.rotation);
        DamagePopUp damagePopUp          = damagePopUpTransform.GetComponent <DamagePopUp>();

        damagePopUp.Setup(effect, isWounding);
        return(damagePopUp);
    }
Example #11
0
    public static DamagePopUp Create(Vector3 position, string popupText, PopupType popupType, bool isCriticalHit = false)
    {
        Transform   damagePopUpTransform = Instantiate(GameAssets.MyInstance.pfDamagePopUp, position, Quaternion.identity);
        DamagePopUp damagePopUp          = damagePopUpTransform.GetComponent <DamagePopUp>();

        damagePopUp.SetUp(popupText, popupType, isCriticalHit);
        return(damagePopUp);
    }
Example #12
0
 public void Burn(float burnDamage)
 {
     health -= burnDamage;
     SpawnBlood();
     DamagePopUp.Create(transform.position, burnDamage, Color.red);
     image.fillAmount = health / maxHealth;
     CheckDeath();
 }
Example #13
0
 public static void Initialize()
 {
     canvas = GameObject.Find("BattleUI");
     if (!popUpText)
     {
         popUpText = Resources.Load <DamagePopUp>("Logics/PopUp_Text_Parent");
     }
 }
Example #14
0
    public static DamagePopUp Create(Vector3 position, int damageAmount, bool isCriticalHit)
    {
        Transform   damagePopUpTransform = Instantiate(GameAssets.instance.DamagePopUp, position, Quaternion.identity);
        DamagePopUp damagePopUp          = damagePopUpTransform.GetComponent <DamagePopUp>();

        damagePopUp.Setup(damageAmount, isCriticalHit);
        return(damagePopUp);
    }
Example #15
0
    public static DamagePopUp CreateEnemy(Vector3 position, int damage)
    {
        Transform   damagePopUpTransform = Instantiate(GameAssets.i.pfDamagePopUpEnemy, position, Quaternion.identity);
        DamagePopUp damagePopUp          = damagePopUpTransform.GetComponent <DamagePopUp>();

        damagePopUp.Setup(damage);

        return(damagePopUp);
    }
Example #16
0
    IEnumerator delyayedAction(DamagePopUp textItem, string ValueasString, bool isCrit, int delay)
    {
        for (int i = 0; i < delay; i++)
        {
            yield return(null);
        }

        textItem.setText(ValueasString, isCrit);
    }
Example #17
0
    public IEnumerator Execute(Unit initiator, Tile target, Map map)
    {
        {
            map.RemoveAllObstaclesFromTile(target);
            DamagePopUp.Create(target.transform.position, "Wall Break", PopupType.DEBUFF);
        }
        initiator.UpdateUI();

        yield break;
    }
Example #18
0
    // Start is called before the first frame update
    public static DamagePopUp Create(Transform copy, Vector3 offset, int damage, Transform parent)
    {
        Transform   damageposition = Instantiate(copy, Vector3.zero, Quaternion.identity);
        DamagePopUp damagePopUp    = damageposition.GetComponent <DamagePopUp>();

        damageposition.transform.SetParent(parent);
        damageposition.transform.position = parent.transform.position + offset;
        damagePopUp.Setup(damage);
        return(damagePopUp);
    }
Example #19
0
    public static void CreateDamagePopUp_Text(string text, Transform location)
    {
        Initialize();
        DamagePopUp instance       = Instantiate(popUpText);
        Vector2     screenPosition = Camera.main.WorldToScreenPoint(new Vector3(location.position.x, location.position.y + 3, location.position.z));

        instance.transform.SetParent(canvas.transform, false);
        instance.transform.position = screenPosition;
        instance.SetText(text);
    }
    void Shoot()
    {
        if (timeBtwShots > 0)
        {
            return;
        }

        RaycastHit2D info   = Physics2D.Raycast(muzzle.position, transform.right, Distance, shootWut);
        GameObject   obj    = Instantiate(projectile, muzzle.position, Quaternion.identity);
        Bullet       bullet = obj.GetComponent <Bullet>();

        CS.Shake();
        if (offset == 0)
        {
            bullet.offset = -90f;
        }
        else
        {
            bullet.offset = 90f;
        }

        audioSource.Play();
        if (info.collider != null)
        {
            if (!info.collider.CompareTag("Environment"))
            {
                Enemy enemy = info.collider.GetComponent <Enemy>();
                if (enemy != null)
                {
                    Vector3 popUp = info.collider.gameObject.transform.position;
                    if (!isCritical)
                    {
                        enemy.TakeDamage(Damage);
                        DamagePopUp.DamagePop(pfDamagePopup, "Hit", popUp);
                    }
                    if (isCritical)
                    {
                        enemy.TakeDamage(Critical);
                        DamagePopUp.DamagePop(pfDamagePopup, "Critical", popUp);
                    }
                }
            }
        }
        if (isCritical)
        {
            Fired        = 0;
            TillCritical = Random.Range(4, 6);
        }
        if (RecoilIsActive)
        {
            playerController.KnockBack(10f, new Vector2(1f, 0f), RecoilForce);
        }
        Fired++;
        timeBtwShots = totalTimeBtwShots;
    }
Example #21
0
    // Creating DamagePopup

    public static DamagePopUp Create(Vector3 postion, int damageAmount)
    {
        var damagePopTransform = Instantiate(PlayerHealth.instance.damagePopUpText, postion,
                                             Quaternion.identity);

        DamagePopUp damagePop = damagePopTransform.GetComponent <DamagePopUp>();

        damagePop.Setup(damageAmount);

        return(damagePop);
    }
Example #22
0
    //For when the player e.g. picks up a healthPickUp.
    public void heal(int healingAmount)
    {
//		Debug.Log (gameObject + " heals " + healingAmount + "points");
        health += healingAmount;
        if (health > startingHealth)
        {
            health = startingHealth;
        }
        DamagePopUp.CreateTorchHealthPopUp(healingAmount, ui, false);
        updateHealth();
        StartCoroutine(ParticlesCoroutine());
    }
Example #23
0
 public void OnOpenButton()
 {
     // Debug.Log($"Chest empty: {isEmpty}");
     if (!isEmpty)
     {
         inventory.AddItem(Instantiate(item));
         openChestPanel.SetActive(false);
         Debug.Log($"Added {item.itemName} to inventory");
         DamagePopUp.Create(gameObject.transform.position, $"{item.itemName} added to convoy", PopupType.ITEM_COLLECT);
         isEmpty = true;
     }
 }
Example #24
0
    // Ranged AoE of 2-tile radius. Deals x1.5 physical damage to all targets in range
    public override IEnumerator Execute(Unit initiator, List <Unit> targets)
    {
        foreach (Unit target in targets)
        {
            int attackDamage = BattleManager.CalculateMagicDamage(1.5f * initiator.stats[StatString.PHYSICAL_DAMAGE].Value, target);
            target.stats[StatString.HP].AddModifier(new StatModifier(-attackDamage, StatModType.Flat));
            DamagePopUp.Create(target.transform.position, string.Format("- {0} HP", attackDamage), PopupType.DAMAGE);
        }
        UpdateStats(initiator, targets);

        yield break;
    }
Example #25
0
    public override IEnumerator Execute(Unit initiator, List <Unit> targets)
    {
        foreach (Unit target in targets)
        {
            int healingAmount = Mathf.CeilToInt(0.8f * initiator.stats[StatString.MAGIC_DAMAGE].Value);
            target.stats[StatString.HP].AddModifier(new StatModifier(healingAmount, StatModType.Flat));
            DamagePopUp.Create(target.transform.position, string.Format("+ {0} HP", healingAmount), PopupType.HEAL);
        }

        UpdateStats(initiator, targets);

        yield break;
    }
Example #26
0
    //For when the enemy object takes damage
    public void takeDamage(int damage, bool crit, GameObject source)
    {
        //Debug.Log (gameObject + " takes " + damage + " damage.");
        if (healthBar == null)
        {
            InstantiateHealthBar();
        }

        health -= damage;
        healthBarImage.fillAmount = (float)health / startingHealth;
        float lerp = (float)health / (float)startingHealth;

        if (lerp <= .5f)
        {
            lerp *= 2f;
            healthBarImage.color = Color.Lerp(Color.red, Color.yellow, lerp);
        }
        else if (lerp > .5f)
        {
            lerp -= .5f;
            lerp *= 2f;
            healthBarImage.color = Color.Lerp(Color.yellow, Color.green, lerp);
        }
        DamagePopUp.CreateDamagePopUp(damage, gameObject, crit);



        if (clip_takeDamage != null)
        {
            ObjectPooler.Instance.PlayAudioSource(clip_takeDamage, mixerGroup, pitchMin, pitchMax, transform);
        }

        if (health <= 0)
        {
            if (anim != null)
            {
//				Debug.Log ("animation time");
                anim.SetTrigger("Die");
//				Debug.Log (anim.GetCurrentAnimatorClipInfo (0).Length);
            }
//			Debug.Log ("dead");

            ReturnPlayerData(source);
            Die();
        }
        else if (clip_takeDamage != null)
        {
            ObjectPooler.Instance.PlayAudioSource(clip_takeDamage, mixerGroup, pitchMin, pitchMax, transform);
        }
    }
Example #27
0
    private void HandleAttack()
    {
        foreach (Structure struc in enemyStructuresInRange)
        {
            if (struc != null)
            {
                if (behaviour == Behaviour.Win)
                {
                    if (struc.gameObject.GetComponent <Base>() != null)
                    {
                        state = State.Attacking;

                        DamagePopUp.Create(struc.transform.position, 20, false);
                        struc.TakeDamage(20);
                    }
                }

                if (behaviour == Behaviour.Destroy)
                {
                    state = State.Attacking;
                    if (attackTarget == null)
                    {
                        attackTarget = struc;
                    }
                    else
                    {
                        DamagePopUp.Create(attackTarget.transform.position, 20, false);
                        attackTarget.TakeDamage(20);
                    }

                    if (attackTarget != null)
                    {
                        speed = 0;
                        if (attackTarget.IsDead())
                        {
                            speed = MAX_SPEED;
                        }
                    }
                }

                if (behaviour == Behaviour.Rampage)
                {
                    state = State.Attacking;
                    speed = MAX_SPEED / 2;
                    DamagePopUp.Create(struc.transform.position, 20, false);
                    struc.TakeDamage(20);
                }
            }
        }
    }
Example #28
0
    // Does 110% magic damage to all units in range, and also reduces attack damage by 20%
    public override IEnumerator Execute(Unit initiator, List <Unit> targets)
    {
        foreach (Unit target in targets)
        {
            int   attackDamage = BattleManager.CalculateMagicDamage(1.2f * initiator.stats[StatString.MAGIC_DAMAGE].Value, target);
            float armorDebuff  = 0.2f;
            target.stats[StatString.HP].AddModifier(new StatModifier(-attackDamage, StatModType.Flat));
            target.stats[StatString.ARMOR].AddModifier(new StatModifier(-armorDebuff, duration, StatModType.PercentAdd));
            DamagePopUp.Create(target.transform.position, string.Format("- {0} HP", attackDamage), PopupType.DAMAGE);
            DamagePopUp.Create(target.transform.position, string.Format("\n\n- {0}% Attack", armorDebuff * 100), PopupType.DEBUFF);
        }
        UpdateStats(initiator, targets);

        yield break;
    }
Example #29
0
    public override IEnumerator Execute(Unit initiator, List <Unit> targets)
    {
        foreach (Unit target in targets)
        {
            int heuristicDistance =
                Mathf.CeilToInt(Vector3.Distance(initiator.transform.position, target.transform.position));

            var attackDamage = Mathf.CeilToInt((1 + (heuristicDistance - 1) * 0.2f) * BattleManager.CalculatePhysicalDamage(initiator.stats[StatString.PHYSICAL_DAMAGE].Value, target));

            target.stats[StatString.HP].AddModifier(new StatModifier(-attackDamage, StatModType.Flat));
            DamagePopUp.Create(target.transform.position, string.Format("- {0} HP", attackDamage), PopupType.DAMAGE);
        }

        UpdateStats(initiator, targets);

        yield break;
    }
Example #30
0
    public void TakeDamage(Vector3 attackPosition, float damageAmount, Transform source, Color customColor)
    {
        health -= damageAmount;

        CheckDeath();
        SetTarget(source);
        image.fillAmount = health / maxHealth;
        Vector3 dirFromAttacker = (transform.position - attackPosition).normalized;

        float knockbackDistance = 10f;

        transform.position += dirFromAttacker * knockbackDistance;
        SpawnBlood();
        DamagePopUp.Create(transform.position, damageAmount, customColor);

        Debug.Log("YOU HIT AN ENEMYYYYY");
    }