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.

51 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 StatisticsManager Actor;
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)
{
var soundIndex = Random.Range(0, HitSounds.Length);
Actor.AudioSource.clip = HitSounds[soundIndex];
Actor.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 (Actor != null)
Actor.ReceiveHit(baseDamage, momentum, skillValue, protection, damageType, Slot, weaponHitEvent, gripHitEvent);
}
}
}