コード例 #1
0
        private void ApplyHeal(Entity healer, int healAmount, DamageType damType, BodyPart targetLocation)
        {
            if (isDead)
            {
                return;
            }
            float realHealAmount = healAmount;

            if (GetHealth() + healAmount > GetMaxHealth())
            {
                realHealAmount = GetMaxHealth() - GetHealth();
            }

            if (damageZones.Exists(x => x.location == targetLocation))
            {
                DamageLocation dmgLoc = damageZones.First(x => x.location == targetLocation);
                dmgLoc.HealDamage(damType, (int)realHealAmount);
            }

            currentHealth = GetHealth();
            maxHealth     = GetMaxHealth();

            if (damType == DamageType.Slashing)
            {
                var statuscomp = (StatusEffectComp)Owner.GetComponent(ComponentFamily.StatusEffects);
                if (statuscomp.HasEffect("Bleeding"))
                {
                    statuscomp.RemoveEffect("Bleeding");
                }
            }

            SendHealthUpdate();
        }
コード例 #2
0
        public override ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
                                                             params object[] list)
        {
            ComponentReplyMessage reply = ComponentReplyMessage.Empty;

            if (type != ComponentMessageType.Damage)
            {
                reply = base.RecieveMessage(sender, type, list);
            }

            if (sender == this)
            {
                return(ComponentReplyMessage.Empty);
            }

            switch (type)
            {
            case ComponentMessageType.GetCurrentLocationHealth:
                var location = (BodyPart)list[0];
                if (damageZones.Exists(x => x.location == location))
                {
                    DamageLocation dmgLoc = damageZones.First(x => x.location == location);
                    var            reply1 = new ComponentReplyMessage(ComponentMessageType.CurrentLocationHealth, location,
                                                                      dmgLoc.UpdateTotalHealth(), dmgLoc.maxHealth);
                    reply = reply1;
                }
                break;

            case ComponentMessageType.GetCurrentHealth:
                var reply2 = new ComponentReplyMessage(ComponentMessageType.CurrentHealth, GetHealth(),
                                                       GetMaxHealth());
                reply = reply2;
                break;

            case ComponentMessageType.Damage:
                if (list.Count() > 3)     //We also have a target location
                {
                    ApplyDamage((Entity)list[0], (int)list[1], (DamageType)list[2], (BodyPart)list[3]);
                }
                else     //We dont have a target location
                {
                    ApplyDamage((Entity)list[0], (int)list[1], (DamageType)list[2]);
                }
                break;

            case ComponentMessageType.Heal:
                if (list.Count() > 3)     // We also have a target location
                {
                    ApplyHeal((Entity)list[0], (int)list[1], (DamageType)list[2], (BodyPart)list[3]);
                }
                break;
            }

            return(reply);
        }
コード例 #3
0
        protected void ApplyDamage(Entity damager, int damageamount, DamageType damType, BodyPart targetLocation)
        {
            DamagedBy(damager, damageamount, damType);

            int actualDamage = Math.Max(damageamount - GetArmor(damType), 0);

            if (GetHealth() - actualDamage < 0) //No negative total health.
            {
                actualDamage = (int)GetHealth();
            }

            if (damageZones.Exists(x => x.location == targetLocation))
            {
                DamageLocation dmgLoc = damageZones.First(x => x.location == targetLocation);
                dmgLoc.AddDamage(damType, actualDamage);
            }

            if (targetLocation == BodyPart.Head && actualDamage > 5)
            {
                ComponentReplyMessage r = Owner.SendMessage(this, ComponentFamily.Actor,
                                                            ComponentMessageType.GetActorSession);
                if (r.MessageType == ComponentMessageType.ReturnActorSession)
                {
                    var s = (IPlayerSession)r.ParamsList[0];
                    s.AddPostProcessingEffect(PostProcessingEffectType.Blur, 5);
                }
            }

            TriggerBleeding(damageamount, damType, targetLocation);

            currentHealth = GetHealth();
            maxHealth     = GetMaxHealth();

            SendHealthUpdate();

            if (GetHealth() <= 0)
            {
                Die();
            }
        }