You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using SiegeSong;
namespace SiegeSong
{
public class HitReceiver : MonoBehaviour
{
public string HitReceiverName = "Body Location";
public ActorStatistics ActorStats;
public InventoryItem[] ArmorOnSlot;
public AparrelSlot Slot;
public PhysicalMaterial Material;
public AudioClip[] HitSounds;
void Start()
{
}
void Update()
{
}
public void ApplyHit(int baseDamage, float momentum, PhysicalMaterial material, DamageType damageType, DamageWeight damageWeight, int skillValue, UnityEvent weaponHitEvent = null, UnityEvent gripHitEvent = null)
{
Debug.Log($"{baseDamage} Damage Taken.");
var soundIndex = Random.Range(0, HitSounds.Length);
ActorStats.AudioSource.clip = HitSounds[soundIndex];
ActorStats.AudioSource.Play();
var protection = ProtectionLevel.Unprotected;
foreach (var armor in ArmorOnSlot)
{
if (armor.FullProtection.ContainsKey(damageWeight))
if (armor.FullProtection[damageWeight].ContainsKey(damageType) && armor.FullProtection[damageWeight][damageType])
protection = ProtectionLevel.Full;
if (armor.PartialProtection.ContainsKey(damageWeight))
if (armor.PartialProtection[damageWeight].ContainsKey(damageType) && armor.PartialProtection[damageWeight][damageType])
protection = ProtectionLevel.Partial;
armor.Degrade(material, Material, baseDamage, momentum);
}
if (ActorStats != null)
ActorStats.ReceiveHit(baseDamage, momentum, skillValue, protection, damageType, Slot, weaponHitEvent, gripHitEvent);
}
}
}