public void AddMaxHealthAlteration(IHasHealth hasHealth, IMaxHealthAlteration maxHealthAlteration)
        {
            if (!MaxHealthAlterationDict.ContainsKey(hasHealth))
            {
                MaxHealthAlterationDict[hasHealth] = new List <IMaxHealthAlteration>();
            }

            MaxHealthAlterationDict[hasHealth].Add(maxHealthAlteration);
        }
        public int GetTempHP(IHasHealth hasHealth)
        {
            if (TempHitPointsDict.ContainsKey(hasHealth))
            {
                return(TempHitPointsDict[hasHealth]);
            }

            return(0);
        }
    private void OnTriggerEnter(Collider other)
    {
        IHasHealth otherHealth = other.GetComponent <IHasHealth>();

        //! will this cause a bug? I dont think so but if something doesnt collide check here if the GO Tags are not set up correctly.
        if (otherHealth != null && other.tag != gameObject.tag)
        {
            otherHealth.TakeDamage(dmgAmount);
        }
    }
        public int CheckHeal(IHasHealth hasHealth, int health)
        {
            int maxHealth = GetMaxHealth(hasHealth);

            if (health > maxHealth)
            {
                return(maxHealth);
            }
            return(health);
        }
        public int GetMaxHealth(IHasHealth hasHealth)
        {
            int health = 0;

            foreach (IMaxHealthAlteration maxHealthAlteration in MaxHealthAlterationDict[hasHealth])
            {
                health = maxHealthAlteration.Alter(health);
            }
            return(health);
        }
Exemple #6
0
    private void OnTriggerStay(Collider other)
    {
        IHasHealth otherHealth = other.GetComponent <IHasHealth>();

        if (otherHealth != null && other.tag != gameObject.tag)
        {
            otherHealth.TakeDamage(dmgAmount);
            //print($"{this.name} hits {other.name} and causes damage");
        }
    }
Exemple #7
0
 public override void OnStart(GameObject target)
 {
     characterHealth = target.GetComponent <IHasHealth>();
     characterState  = target.GetComponent <CharacterState>();
     spriteRenderer  = target.GetComponent <SpriteRenderer>();
     blinkOnHit      = target.GetComponent <BlinkOnHit>();
     blinkOnHit.SetRegularColor((Config as PoisonConfig).PoisonedEnemyColor);
     spriteRenderer.color = (Config as PoisonConfig).PoisonedEnemyColor;
     characterState.AddStatusEffect(this);
 }
Exemple #8
0
        public override bool ReceiveDamage(float damage, IHasHealth target)
        {
            bool isDead = base.ReceiveDamage(damage, target);

            if (isDead)
            {
                this.controller.OnDeath();
            }
            return(isDead);
        }
Exemple #9
0
        public void Heal(IHasHealth target)
        {
            this.LookAt(target.position);

            this._animator.Play("Cast");

            this.InternalHeal(target);

            ((UI.ClericUI) this._uiComponent).FinishHeal();
            this._canHeal = false;
        }
Exemple #10
0
        public virtual void Attack(IHasHealth target)
        {
            this._lastAttack = Time.timeSinceLevelLoad;
            this.LookAt(target.position);
            this.StopMoving();

            // NOTE: Need to do a blocking check to see when the animation is finished playing then continue to do the attack logic.
            this._animator.Play("Attack");

            this.InternalAttack(GetDamage(), target);

            ((UI.UnitUI) this._uiComponent).FinishAttack();
            this._canAttack = false;
        }
Exemple #11
0
        protected override void InternalAttack(float damage, IHasHealth target)
        {
            var hits = Utils.hitsBuffers;
            var pos  = target.position;

            Physics.SphereCastNonAlloc(pos, this.unitRadius * 2.0f, this.transform.forward, hits, this._splashRadius, GlobalSettings.LayerValues.unitLayer | GlobalSettings.LayerValues.structureLayer);

            this._hitComparer.position = pos;
            Array.Sort(hits, this._hitComparer);

            for (int i = 0; i < hits.Length; i++)
            {
                var hit = hits[i];

                if (hit.transform == null)
                {
                    continue;
                }

                var hasHealth = hit.collider.GetEntity <IHasHealth>();
                if (hasHealth == null || hasHealth.isDead)
                {
                    continue;
                }

                if (this.IsAlly(hasHealth))
                {
                    continue;
                }

                Debug.Log(hasHealth.gameObject.name + " - " + hasHealth.controller.name);

                if (hasHealth.Equals(target))
                {
                    hasHealth.lastAttacker = this;
                    hasHealth.ReceiveDamage(damage, this as IHasHealth);
                    continue;
                }

                float distance = Vector3.Distance(target.position, hasHealth.position);
                Debug.Log(distance.ToString());
                double roundTo       = Math.Round(((double)(distance / this._splashRadius)), 1);
                float  splashDamange = damage * (1.0f - (float)roundTo);
                Debug.Log("Splash: " + damage);

                hasHealth.lastAttacker = this;
                hasHealth.ReceiveDamage(splashDamange, this as IHasHealth);
            }
        }
    private void OnTriggerEnter(Collider other)
    {
        IHasHealth otherHealth = other.GetComponent <IHasHealth>();

        if (otherHealth != null && other.tag != gameObject.tag)
        {
            otherHealth.TakeDamage(dmgAmount);
            //print($"{this.name} hits {other.name} and causes damage");
            Destroy(gameObject);
        }
        else
        {
            //print($"No damage from {this.name} hits {other.name}");
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        IHasHealth otherHealth = other.GetComponent <IHasHealth>();

        if (otherHealth != null && other.tag != gameObject.tag)
        {
            otherHealth.TakeDamage(dmgAmount);

            //! use this if we dont have durability Destroy(gameObject);
            //Destroy(gameObject);

            durability--;
            if (durability <= 0)
            {
                Destroy(gameObject);
            }
        }
    }
        public int TakeDamage(IHasHealth hasHealth, int damage)
        {
            if (TempHitPointsDict.ContainsKey(hasHealth))
            {
                if (damage > TempHitPointsDict[hasHealth])
                {
                    damage -= TempHitPointsDict[hasHealth];
                    TempHitPointsDict[hasHealth] = 0;
                }
                else
                {
                    TempHitPointsDict[hasHealth] -= damage;
                    damage = 0;
                }
            }

            return(damage);
        }
Exemple #15
0
        public override bool ReceiveDamage(float damage, IHasHealth target)
        {
            if (this.isDead)
            {
                return(true);
            }

            ICanAttack unit        = target as ICanAttack;
            float      finalDamage = damage;

            if (unit.attackType == this.resistanceType)
            {
                finalDamage *= (this.resistancePercentage / 100.0f);
            }
            else if (unit.attackType == this.weaknessType)
            {
                finalDamage += (damage * (this.weaknessPercentage / 100.0f));
            }

            this.currentHealth -= finalDamage;
            this.uiComponent.UpdateUI();

            if (this.currentHealth <= 0.0f)
            {
                if (this.controller != null)
                {
                    this.controller.units.Remove(this);
                }

                UnitPoolManager.instance.Return(this);
                // NOTE: play any death animations, or add in any death effects onto the scene.

                return(true);
            }
            else
            {
                // NOTE: play hit anbimation.
            }
            return(false);
        }
Exemple #16
0
        protected virtual void InternalAttack(float damage, IHasHealth target)
        {
            var hits = Utils.hitsBuffers;
            //var pos = this.position + this.transform.forward * this._unitRadius;
            var pos = target.position;

            Physics.SphereCastNonAlloc(pos, this._unitRadius * 2.0f, this.transform.forward, hits, this._attackRadius, GlobalSettings.LayerValues.unitLayer | GlobalSettings.LayerValues.structureLayer);

            this._hitComparer.position = this.position;
            Array.Sort(hits, this._hitComparer);

            for (int i = 0; i < hits.Length; i++)
            {
                var hit = hits[i];

                if (hit.transform == null)
                {
                    continue;
                }

                if (hit.transform == this.transform)
                {
                    continue; // jgnore hits with itself;
                }
                var hasHealth = hit.collider.GetEntity <IHasHealth>();
                if (hasHealth == null || hasHealth.isDead)
                {
                    continue; // ignore anything that doesn't contain health or is dead.
                }
                if (this.IsAlly(hasHealth))
                {
                    continue; // ignore allies.
                }
                hasHealth.lastAttacker = this;
                hasHealth.ReceiveDamage(damage, this as IHasHealth); // only attack the original target chosen.
                break;
            }
        }
Exemple #17
0
        public override bool ReceiveDamage(float damage, IHasHealth target)
        {
            if (this.isDead)
            {
                return(true);
            }

            //var lookUp = Quaternion.LookRotation(Vector3.up);

            this.currentHealth -= damage;
            if (this.currentHealth <= 0.0f)
            {
                if (this.controller != null && this.controller.structures != null)
                {
                    this.controller.structures.Remove(this);
                }

                // NOTE: spawn in particle effects.
                this.ReturnStructure();
                return(true);
            }
            return(false);
        }
Exemple #18
0
        public void InternalHeal(IHasHealth target)
        {
            var hits = Utils.hitsBuffers;
            //var pos = this.position + this.transform.forward * this._unitRadius;
            var pos = target.position;

            Physics.SphereCastNonAlloc(pos, this._unitRadius * 2.0f, this.transform.forward, hits, this._healingRadius, GlobalSettings.LayerValues.unitLayer | GlobalSettings.LayerValues.structureLayer);

            this._hitComparer.position = this.position;
            Array.Sort(hits, this._hitComparer);

            for (int i = 0; i < hits.Length; i++)
            {
                var hit = hits[i];

                if (hit.transform == null)
                {
                    continue;
                }

                //if(hit.transform == this.transform)
                //continue; // jgnore hits with itself;

                var hasHealth = hit.collider.GetEntity <IHasHealth>();
                if (hasHealth == null || hasHealth.isDead)
                {
                    continue; // ignore anything that doesn't contain health or is dead.
                }
                if (this.IsEnemy(hasHealth))
                {
                    continue; // ignore enemies.
                }
                // only attack the original target chosen.
                hasHealth.AddHealth(this._healingAmount);
                break;
            }
        }
Exemple #19
0
 public abstract bool ReceiveDamage(float damage, IHasHealth target);
Exemple #20
0
        protected override void InternalAttack(float damage, IHasHealth target)
        {
            base.InternalAttack(damage, target);

            //NOTE: emit a particle at the end of the attack.
        }
Exemple #21
0
 public bool IsAlly(IHasHealth other)
 {
     return(ReferenceEquals(other.controller, this));
 }
Exemple #22
0
 public bool IsEnemy(IHasHealth other)
 {
     return(!this.IsAlly(other));
 }
 public void AddTempHP(IHasHealth hasHealth, int tempHP)
 {
     TempHitPointsDict[hasHealth] = tempHP;
 }
Exemple #24
0
 public virtual bool IsAlly(IHasHealth other)
 {
     return(ReferenceEquals(this.controller, other.controller));
 }
 private void Awake()
 {
     _hasHealth  = GetComponent <IHasHealth>();
     _moveOnPath = GetComponent <IMoveOnPath>();
 }
Exemple #26
0
        protected override void InternalAttack(float damage, IHasHealth target)
        {
            base.InternalAttack(damage, target);

            // NOTE: Find units within the splashRadius and calculate damage on the distance from the main attack source.
        }