/// <summary>
        /// Applies trauma damage to the body part, checks if it has enough protective armor to cancel the trauma damage
        /// </summary>
        public void ApplyTraumaDamage(TraumaticDamageTypes damageType = TraumaticDamageTypes.SLASH, bool ignoreSeverityCheck = false)
        {
            if (Severity < DamageSeverity.Bad && ignoreSeverityCheck == false)
            {
                return;
            }
            //We use dismember protection chance because it's the most logical value.
            if (DMMath.Prob(SelfArmor.DismembermentProtectionChance) == false)
            {
                if (damageType == TraumaticDamageTypes.SLASH)
                {
                    currentSlashDamageLevel += 1;
                }
                if (damageType == TraumaticDamageTypes.PIERCE)
                {
                    currentPierceDamageLevel += 1;
                }
            }
            //Burn and blunt damage checks for it's own armor damage type.
            if (damageType == TraumaticDamageTypes.BURN)
            {
                TakeBurnDamage();
            }

            if (damageType == TraumaticDamageTypes.BLUNT && DMMath.Prob(SelfArmor.Melee * 100) == false)
            {
                TakeBluntDamage();
            }
        }
예제 #2
0
        /// <summary>
        /// Applies trauma damage to the body part, checks if it has enough protective armor to cancel the trauma damage
        /// and automatically checks how big is the body part's cut size.
        /// </summary>
        public void ApplyTraumaDamage(float tramuaDamage, TraumaticDamageTypes damageType = TraumaticDamageTypes.SLASH)
        {
            //We use dismember protection chance because it's the most logical value.
            if (DMMath.Prob(SelfArmor.DismembermentProtectionChance * 100) == false)
            {
                if (damageType == TraumaticDamageTypes.SLASH)
                {
                    currentSlashCutDamage += MultiplyTraumaDamage(tramuaDamage);
                }
                if (damageType == TraumaticDamageTypes.PIERCE)
                {
                    currentPierceDamage += MultiplyTraumaDamage(tramuaDamage);
                }
                CheckCutSize();
            }
            //Burn and blunt damage checks for it's own armor damage type.
            if (damageType == TraumaticDamageTypes.BURN)
            {
                TakeBurnDamage(MultiplyTraumaDamage(tramuaDamage));
            }

            if (damageType == TraumaticDamageTypes.BLUNT)
            {
                if (DMMath.Prob(SelfArmor.Melee * 100) == false)
                {
                    TakeBluntDamage(tramuaDamage);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Applies damage to this body part. Damage will be divided among it and sub organs depending on their
        /// armor values.
        /// </summary>
        /// <param name="damagedBy">The player or object that caused the damage. Null if there is none</param>
        /// <param name="damage">Damage amount</param>
        /// <param name="attackType">Type of attack that is causing the damage</param>
        /// <param name="damageType">The type of damage</param>
        /// <param name="organDamageSplit">Should the damage be divided amongst the contained organs or applied to a random one</param>
        public void TakeDamage(GameObject damagedBy, float damage, AttackType attackType, DamageType damageType,
                               bool organDamageSplit     = false, bool DamageSubOrgans = true, float armorPenetration = 0,
                               double traumaDamageChance = 100, TraumaticDamageTypes tramuticDamageType = TraumaticDamageTypes.NONE)
        {
            float damageToLimb = Armor.GetTotalDamage(
                SelfArmor.GetDamage(damage, attackType, armorPenetration),
                attackType,
                ClothingArmors,
                armorPenetration
                );

            AffectDamage(damageToLimb, (int)damageType);

            // May be changed to individual damage
            // May also want it so it can miss sub organs
            if (DamageSubOrgans && containBodyParts.Count > 0)
            {
                DamageOrgans(damage, attackType, damageType, organDamageSplit, armorPenetration);
            }

            if (damage < damageThreshold)
            {
                return;                                    //Do not apply traumas if the damage is not serious.
            }
            if (damageType == DamageType.Brute)            //Check damage type to avoid bugs where you can blow someone's head off with a shoe.
            {
                if (attackType == AttackType.Melee || attackType == AttackType.Laser || attackType == AttackType.Energy)
                {
                    if (tramuticDamageType != TraumaticDamageTypes.NONE && DMMath.Prob(traumaDamageChance))
                    {
                        //TODO: move this to an utility, its hard to read! - picks a random enum from the ones already flagged
                        Random random = new Random();
                        TraumaticDamageTypes[] typeToSelectFrom = Enum.GetValues(typeof(TraumaticDamageTypes)).Cast <TraumaticDamageTypes>().Where(x => tramuticDamageType.HasFlag(x)).ToArray();
                        TraumaticDamageTypes   selectedType     = typeToSelectFrom[random.Next(1, typeToSelectFrom.Length)];
                        ApplyTraumaDamage(selectedType);
                    }
                    CheckBodyPartIntegrity();
                }
            }

            if (attackType == AttackType.Bomb)
            {
                TakeBluntDamage();
                DismemberBodyPartWithChance();
            }

            if (damageType == DamageType.Burn || attackType == AttackType.Fire ||
                attackType == AttackType.Laser || attackType == AttackType.Energy)
            {
                ApplyTraumaDamage(TraumaticDamageTypes.BURN);
            }
        }
예제 #4
0
 public void HealTraumaticDamage(TraumaticDamageTypes damageTypeToHeal)
 {
     if (damageTypeToHeal == TraumaticDamageTypes.BURN)
     {
         currentBurnDamageLevel -= 1;
     }
     if (damageTypeToHeal == TraumaticDamageTypes.SLASH)
     {
         currentSlashDamageLevel -= 1;
     }
     if (damageTypeToHeal == TraumaticDamageTypes.PIERCE)
     {
         currentPierceDamageLevel -= 1;
     }
 }
예제 #5
0
        public void HealTraumaticDamage(float healAmount, TraumaticDamageTypes damageTypeToHeal)
        {
            if (damageTypeToHeal == TraumaticDamageTypes.BURN)
            {
                currentBurnDamage -= healAmount;
            }
            if (damageTypeToHeal == TraumaticDamageTypes.SLASH)
            {
                currentSlashCutDamage -= healAmount;
            }
            if (damageTypeToHeal == TraumaticDamageTypes.PIERCE)
            {
                currentPierceDamage -= healAmount;
            }

            CheckCutSize();
        }
예제 #6
0
 /// <summary>
 /// Applies Trauma damage to a body part.
 /// </summary>
 public void TakeTraumaDamage(float damage, TraumaticDamageTypes damageType)
 {
     foreach (BodyPart limb in ContainsLimbs)
     {
         if (damageType.HasFlag(TraumaticDamageTypes.BURN))
         {
             limb.ApplyTraumaDamage(damage, TraumaticDamageTypes.BURN);
         }
         if (damageType.HasFlag(TraumaticDamageTypes.SLASH))
         {
             limb.ApplyTraumaDamage(damage);
         }
         if (damageType.HasFlag(TraumaticDamageTypes.PIERCE))
         {
             limb.ApplyTraumaDamage(damage, TraumaticDamageTypes.PIERCE);
         }
     }
 }
예제 #7
0
 public void HealTraumaDamage(float healAmt, TraumaticDamageTypes typeToHeal)
 {
 }
예제 #8
0
    public void ServerPerformMeleeAttack(GameObject victim, Vector2 attackDirection, BodyPartType damageZone, LayerType layerType)
    {
        if (victim == null)
        {
            return;
        }
        if (Cooldowns.IsOnServer(playerScript, CommonCooldowns.Instance.Melee))
        {
            return;
        }
        if (playerMove.allowInput == false)
        {
            return;
        }
        if (playerScript.IsGhost)
        {
            return;
        }
        if (playerScript.playerHealth.serverPlayerConscious == false)
        {
            return;
        }

        if (victim.TryGetComponent <InteractableTiles>(out var tiles))
        {
            // validate based on position of target vector
            if (Validations.CanApply(playerScript, victim, NetworkSide.Server, targetVector: attackDirection) == false)
            {
                return;
            }
        }
        else
        {
            // validate based on position of target object
            if (Validations.CanApply(playerScript, victim, NetworkSide.Server) == false)
            {
                return;
            }
        }

        float                  damage           = fistDamage;
        DamageType             damageType       = DamageType.Brute;
        AddressableAudioSource weaponSound      = meleeSounds.PickRandom();
        GameObject             weapon           = playerScript.playerNetworkActions.GetActiveHandItem();
        ItemAttributesV2       weaponAttributes = weapon == null ? null : weapon.GetComponent <ItemAttributesV2>();

        if (weaponAttributes != null)
        {
            damage             = weaponAttributes.ServerHitDamage;
            damageType         = weaponAttributes.ServerDamageType;
            weaponSound        = weaponAttributes.hitSoundSettings == SoundItemSettings.OnlyObject ? null : weaponAttributes.ServerHitSound;
            tramuticDamageType = weaponAttributes.TraumaticDamageType;
            traumaDamageChance = weaponAttributes.TraumaDamageChance;
        }

        LayerTile attackedTile = null;
        bool      didHit       = false;

        // If Tilemap LayerType is not None then it is a tilemap being attacked
        if (layerType != LayerType.None)
        {
            var tileChangeManager = victim.GetComponent <TileChangeManager>();
            if (tileChangeManager == null)
            {
                return;                                        // Make sure its on a matrix that is destructable
            }
            // Tilemap stuff:
            var tileMapDamage = victim.GetComponentInChildren <MetaTileMap>().Layers[layerType].gameObject.GetComponent <TilemapDamage>();
            if (tileMapDamage == null)
            {
                return;
            }

            var worldPos = (Vector2)transform.position + attackDirection;
            attackedTile = tileChangeManager.InteractableTiles.LayerTileAt(worldPos, true);

            // Tile itself is responsible for playing victim damage sound
            tileMapDamage.ApplyDamage(damage, AttackType.Melee, worldPos);
            didHit = true;
        }
        // Damaging an object
        else if (victim.TryGetComponent <Integrity>(out var integrity) &&
                 victim.TryGetComponent <Meleeable>(out var meleeable) && meleeable.IsMeleeable)
        {
            if (weaponAttributes != null && weaponAttributes.hitSoundSettings != SoundItemSettings.OnlyItem)
            {
                AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: Random.Range(0.9f, 1.1f));
                SoundManager.PlayNetworkedAtPos(integrity.soundOnHit, gameObject.WorldPosServer(), audioSourceParameters, sourceObj: gameObject);
            }

            integrity.ApplyDamage(damage, AttackType.Melee, damageType);
            didHit = true;
        }