Exemplo n.º 1
0
    public static HealthBodyPartMessage SendToAll(GameObject entityToUpdate, BodyPartType bodyPartType,
                                                  float bruteDamage, float burnDamage)
    {
        HealthBodyPartMessage msg = new HealthBodyPartMessage
        {
            EntityToUpdate = entityToUpdate.GetComponent <NetworkIdentity>().netId,
            BodyPart       = bodyPartType,
            BruteDamage    = bruteDamage,
            BurnDamage     = burnDamage
        };

        msg.SendToAll();
        return(msg);
    }
Exemplo n.º 2
0
    public virtual void HealDamage(GameObject healingItem, int healAmt,
                                   DamageType damageTypeToHeal, BodyPartType bodyPartAim)
    {
        if (healAmt <= 0 || IsDead)
        {
            return;
        }
        if (bodyPartAim == BodyPartType.Groin)
        {
            bodyPartAim = BodyPartType.Chest;
        }

        if (bodyPartAim == BodyPartType.Eyes || bodyPartAim == BodyPartType.Mouth)
        {
            bodyPartAim = BodyPartType.Head;
        }

        if (BodyParts.Count == 0)
        {
            Logger.LogError($"There are no body parts to affect {gameObject.name}", Category.Health);
            return;
        }

        // See if any of the healing applied affects blood state
        bloodSystem.AffectBloodState(bodyPartAim, damageTypeToHeal, healAmt, true);

        if (damageTypeToHeal == DamageType.Brute || damageTypeToHeal == DamageType.Burn)
        {
            //Try to apply healing to the required body part
            bool appliedHealing = false;
            for (int i = 0; i < BodyParts.Count; i++)
            {
                if (BodyParts[i].Type == bodyPartAim)
                {
                    BodyParts[i].HealDamage(healAmt, damageTypeToHeal);
                    appliedHealing = true;
                    HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim,
                                                    BodyParts[i].BruteDamage, BodyParts[i].BurnDamage);
                    break;
                }
            }

            //If the body part does not exist then try to find the chest instead
            if (!appliedHealing)
            {
                var getChestIndex = BodyParts.FindIndex(x => x.Type == BodyPartType.Chest);
                if (getChestIndex != -1)
                {
                    BodyParts[getChestIndex].HealDamage(healAmt, damageTypeToHeal);
                    HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim,
                                                    BodyParts[getChestIndex].BruteDamage, BodyParts[getChestIndex].BurnDamage);
                }
                else
                {
                    //If there is no default chest body part then do nothing
                    Logger.LogError($"No chest body part found for {gameObject.name}", Category.Health);
                    return;
                }
            }
        }

        var prevHealth = OverallHealth;

        Logger.LogTraceFormat("{3} received {0} {4} healing from {6} aimed for {5}. Health: {1}->{2}", Category.Health,
                              healAmt, prevHealth, OverallHealth, gameObject.name, damageTypeToHeal, bodyPartAim, healingItem);
    }
Exemplo n.º 3
0
    public virtual void ApplyDamage(GameObject damagedBy, float damage,
                                    DamageType damageType, BodyPartType bodyPartAim = BodyPartType.Chest)
    {
        if (damage <= 0 || IsDead)
        {
            return;
        }
        if (bodyPartAim == BodyPartType.Groin)
        {
            bodyPartAim = BodyPartType.Chest;             //Temporary fix for groin, when we add surgery this might need some changing.
        }

        if (bodyPartAim == BodyPartType.Eyes || bodyPartAim == BodyPartType.Mouth)
        {
            bodyPartAim = BodyPartType.Head;
        }

        LastDamageType = damageType;
        LastDamagedBy  = damagedBy;

        if (BodyParts.Count == 0)
        {
            Logger.LogError($"There are no body parts to apply damage too for {gameObject.name}", Category.Health);
            return;
        }

        //See if damage affects the state of the blood:
        bloodSystem.AffectBloodState(bodyPartAim, damageType, damage);

        if (damageType == DamageType.Brute || damageType == DamageType.Burn)
        {
            //Try to apply damage to the required body part
            bool appliedDmg = false;
            for (int i = 0; i < BodyParts.Count; i++)
            {
                if (BodyParts[i].Type == bodyPartAim)
                {
                    BodyParts[i].ReceiveDamage(damageType, damage);
                    appliedDmg = true;
                    HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim,
                                                    BodyParts[i].BruteDamage, BodyParts[i].BurnDamage);
                    break;
                }
            }

            //If the body part does not exist then try to find the chest instead
            if (!appliedDmg)
            {
                var getChestIndex = BodyParts.FindIndex(x => x.Type == BodyPartType.Chest);
                if (getChestIndex != -1)
                {
                    BodyParts[getChestIndex].ReceiveDamage(damageType, damage);
                    HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim,
                                                    BodyParts[getChestIndex].BruteDamage, BodyParts[getChestIndex].BurnDamage);
                }
                else
                {
                    //If there is no default chest body part then do nothing
                    Logger.LogError($"No chest body part found for {gameObject.name}", Category.Health);
                    return;
                }
            }
        }

        //For special effects spawning like blood:
        DetermineDamageEffects(damageType);

        var prevHealth = OverallHealth;

        Logger.LogTraceFormat("{3} received {0} {4} damage from {6} aimed for {5}. Health: {1}->{2}", Category.Health,
                              damage, prevHealth, OverallHealth, gameObject.name, damageType, bodyPartAim, damagedBy);
    }