コード例 #1
0
ファイル: Unit.cs プロジェクト: crafics/globetrotter2
        //for apply damage directly, not in used
        public void ApplyDamage(float damage)
        {
            if (immunityCounter > 0)
            {
                return;
            }

            //show the overlay (for UI)
            Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);

            new TextOverlay(thisT.position + offsetPos, damage.ToString("f0"));

            //if the unit is player, fire event to inform UI
            if (thisObj.layer == TDS.GetLayerPlayer())
            {
                TDS.PlayerDamaged(damage);
            }

            //register the stagger
            hpRegenStaggerCounter = hpRegenStagger;

            hitPoint -= damage;                 //damage the hitpoint
            if (hitPoint <= 0)
            {
                Destroyed();
            }

            if (hitPoint > 0 && uAnimation != null)
            {
                uAnimation.Hit();
            }
        }
コード例 #2
0
ファイル: Unit.cs プロジェクト: crafics/globetrotter2
        //function call when the unit instance gain/lost hitpoint from external source
        public virtual float GainHitPoint(float value)
        {
            float limit = GetFullHitPoint() - hitPoint;

            hitPoint += Mathf.Min(value, limit);

            //if the unit lost hitpoint instead of gaining it
            if (value < 0)
            {
                hpRegenStaggerCounter = hpRegenStagger;

                //if this is the player, call the damage event (inform UI)
                if (thisObj.layer == TDS.GetLayerPlayer())
                {
                    TDS.PlayerDamaged(value);
                }
            }

            //if hitpoint reach 0, destroy the unit
            if (hitPoint <= 0)
            {
                Destroyed();
            }

            return(limit);
        }
コード例 #3
0
ファイル: Unit.cs プロジェクト: crafics/globetrotter2
        //applies the effect of an attack
        public void ApplyAttack(AttackInstance attInstance)
        {
            if (immunityCounter > 0)
            {
                return;
            }

            //if unit is invincible, do nothing
            if (IsInvincible())
            {
                Debug.Log("Immuned");
                Vector3 osPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(thisT.position + osPos, "Immuned");
                return;
            }

            AttackStats aStats = attInstance.aStats;

            //check if the attack is an aoe and modify the damage value is dimishingAOE is enabled
            float damage = Random.Range(aStats.damageMin, aStats.damageMax);

            if (attInstance.isAOE && aStats.diminishingAOE)
            {
                damage *= Mathf.Clamp(1 - attInstance.aoeDistance / aStats.aoeRadius, 0, 1);
            }


            //check for cirtical and modify the damage based on critical multiplier
            bool critical = Random.value < aStats.critChance;

            if (critical)
            {
                damage *= aStats.critMultiplier;
            }

            //modify the damage based on damage and armor type
            damage *= DamageTable.GetModifier(armorType, aStats.damageType);

            //if damage is valid, modify the hit point
            if (damage > 0)
            {
                //show the overlay (for UI)
                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                if (!critical)
                {
                    new TextOverlay(thisT.position + offsetPos, damage.ToString("f0"));
                }
                else
                {
                    new TextOverlay(thisT.position + offsetPos, damage.ToString("f0"), new Color(1f, 0.9f, 0.9f, 1f), 1.5f);
                }

                //if the unit is player, fire event to inform UI
                if (thisObj.layer == TDS.GetLayerPlayer())
                {
                    TDS.PlayerDamaged(damage);
                }

                //register the stagger
                hpRegenStaggerCounter = hpRegenStagger;

                hitPoint -= damage;                     //damage the hitpoint
                if (hitPoint <= 0)
                {
                    Destroyed(attInstance.GetSrcPlayer());
                }

                if (hitPoint > 0 && uAnimation != null)
                {
                    uAnimation.Hit();
                }
            }

            //apply effect if there's any
            //if(aStats.effect!=null) ApplyEffect(aStats.effect);
            if (hitPoint > 0 && aStats.effectIdx >= 0)
            {
                ApplyEffect(Effect_DB.CloneItem(aStats.effectIdx));
            }
        }