Fixes? and side channels.

This commit is contained in:
2022-05-17 19:09:50 +07:00
parent b5aff44f79
commit e976a3fbff
18 changed files with 454 additions and 90 deletions

View File

@ -1,21 +1,31 @@
using System;
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class Shooting : MonoBehaviour
{
public GameObject raycast;
public GameObject firePoint;
//[SerializeField] private ParticleSystem projectilePrefab;
public ParticleSystem projectilePrefab;
private float hSliderValue = 0.1f;
private float _fireCountdown = 0.1f;
public GameObject gun;
public AudioSource audioSource;
private NPC _myNpc;
private MovementController _moveCtrl;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
TryGetComponent(out _moveCtrl);
TryGetComponent(out _myNpc);
}
private void Update()
{
@ -30,6 +40,7 @@ public class Shooting : MonoBehaviour
_fireCountdown += hSliderValue;
PlayerShoot();
}
_fireCountdown -= Time.deltaTime;
}
@ -37,7 +48,7 @@ public class Shooting : MonoBehaviour
{
audioSource.Play();
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
if (Physics.Raycast(raycast.transform.position,
if (Physics.Raycast(raycast.transform.position,
raycast.transform.forward, out var hit,
SettingsReader.Instance.GetSettings.ViewDistance))
{
@ -47,18 +58,33 @@ public class Shooting : MonoBehaviour
}
}
}
public void Shoot()
public void BotShoot()
{
if (Physics.Raycast(raycast.transform.position,
if (Physics.Raycast(raycast.transform.position,
raycast.transform.forward, out var hit,
SettingsReader.Instance.GetSettings.ViewDistance))
{
if (hit.transform.TryGetComponent<NPC>(out var target))
if (hit.transform.TryGetComponent<ICharacter>(out var target))
{
audioSource.Play();
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
var mySpeed = _moveCtrl.Velocity.magnitude;
var enemySpeed = 0f;
var inCover = false;
if (target.GetCharacter.TypeAi == TypeAI.HumanAI)
enemySpeed = hit.rigidbody.velocity.magnitude;
else
{
enemySpeed = hit.collider.GetComponent<MovementController>().Velocity.magnitude;
inCover = hit.collider.GetComponent<NPC>().NpcState.InCover;
}
var hitChance = (1 - 0.5 * mySpeed) * (1 - 0.5 * enemySpeed + 0.5*inCover.ToInt()) / 1.5f;
if (!(UnityEngine.Random.Range(0f, 1f) < hitChance)) return;
_myNpc.AddReward(0.05f);
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
}
}
}
}
}