コード例 #1
0
        public void DamageNotification(DamageNotificationArgs args)
        {
            var changed   = args.m_FinalHealth - args.m_InitialHealth;
            var intAmount = Mathf.FloorToInt(args.m_Args.m_FinalAmount);

            if (args.m_Args.m_Type == DamageType.Radiation)
            {
                if (intAmount > 0)
                {
                    TwoDee.EasySound.Play("poweron", gameObject);
                }
                return;
            }

            var prefix    = (intAmount < 0) ? "+" : "";
            var absAmount = Math.Abs(intAmount);

            FloatingTextManager.Instance.AddEntry(prefix + absAmount, args.m_Args.m_Location);
            if (intAmount > 0)
            {
                TwoDee.EasySound.Play("hit1", gameObject);
            }
            else if (intAmount < 0)
            {
                TwoDee.EasySound.Play("heal", transform.position);
            }
        }
コード例 #2
0
        public void RawDamageUnchecked(DamageArgs args)
        {
            var baseAmount = args.m_Amount;

            List <ResistanceData> listRd = new List <ResistanceData>();

            foreach (var comp in m_ResistanceComponents)
            {
                ResistanceData rd = new ResistanceData();
                comp.GetResistances(rd);
                listRd.Add(rd);
            }
            listRd.Sort((x, y) => x.m_Priority.CompareTo(y.m_Priority));

            float finalPercent = 1.0f;
            float finalBlock   = 0.0f;

            foreach (var rd in listRd)
            {
                foreach (var resist in rd.m_Resistances)
                {
                    if (resist.m_Type == args.m_Type || resist.m_Type == DamageType.Any)
                    {
                        finalPercent = resist.m_Percent;
                        finalBlock   = resist.m_Block;
                        if (resist.m_Type != DamageType.Any)
                        {
                            break;
                        }
                    }
                }
            }

            float oldHealth = m_Health;

            if (baseAmount > 0.0f)
            {
                args.m_FinalAmount = Mathf.Clamp(finalPercent * baseAmount - finalBlock, 0.0f, 99999.0f);
                if (args.m_Type == DamageType.Radiation)
                {
                    if (m_RadiationVulnerable)
                    {
                        m_LastRadiationTime = 0.9f;
                        m_Radiation        -= args.m_FinalAmount;
                    }
                }
                else
                {
                    m_Health -= args.m_FinalAmount;
                }
            }
            else
            {
                args.m_FinalAmount = Mathf.Clamp(finalPercent * baseAmount - finalBlock, -99999.0f, 0.0f);
                if (args.m_Type == DamageType.Radiation)
                {
                    if (m_RadiationVulnerable)
                    {
                        m_Radiation -= args.m_FinalAmount;
                    }
                }
                else
                {
                    m_Health -= args.m_FinalAmount;
                }
            }

            DamageNotificationArgs notificationArgs = new DamageNotificationArgs()
            {
                m_Args = args, m_InitialHealth = oldHealth, m_FinalHealth = Mathf.Clamp(m_Health, 0.0f, m_MaxHealth)
            };

            foreach (var notification in GetComponents <IDamageNotification>())
            {
                notification.DamageNotification(notificationArgs);
            }

            if (m_Health <= 0)
            {
                m_Health = 0;
                m_Dead   = true;
                TwoDee.EasySound.Play("die1", gameObject);

                foreach (var killable in GetComponents <IKillable>())
                {
                    if (isServer)
                    {
                        killable.Kill();
                    }
                }
            }
            if (m_Health > m_MaxHealth)
            {
                m_Health = m_MaxHealth;
            }
            if (m_Radiation < 0.0f && m_RadiationVulnerable)
            {
                float excess = -m_Radiation;
                m_Radiation = 0.0f;;
                RawDamageUnchecked(new DamageArgs(excess, DamageType.Pure, args.m_Hitter, args.m_Location));
            }
        }