TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

151 lines
4.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.VFX;
using DG.Tweening;
public class NPCAssistant
{
private NPC n;
public NPCAssistant(NPC n)
{
this.n = n;
}
//random functions
public void FireProjectile(int targetPlayerId, string projectile)
{
if (projectile == null)
return;
if (n.projectileOrigin == null)
return;
if (PlayerManager.Instance.GetPlayer(targetPlayerId) == null)
return;
Vector3 playerPos = PlayerManager.Instance.GetPlayer(targetPlayerId).gameObject.transform.position;
playerPos += new Vector3(Random.Range(-2.0f, 2.0f), Random.Range(-0.6f, -0.2f), Random.Range(-2.0f, 2.0f));
Vector3 a = playerPos - n.gameObject.transform.position;
a.Normalize();
Projectile projectilePrefab = OnDemandLoader.Load<Projectile>("projectiles/" + projectile);
if (projectilePrefab != null)
{
Projectile projectileClone = n.Instantiate2(projectilePrefab);
projectileClone.name = projectile;
if (projectileClone != null)
{
projectileClone.transform.position = n.projectileOrigin.transform.position;
projectileClone.transform.rotation = n.projectileOrigin.transform.rotation;
projectileClone.ApplyForce(a, 1);
}
}
//Debug.DrawRay(projectileOrigin.transform.position, new Vector3(direction.x, direction.y, direction.z) * 50f, Color.red, 100f);
}
/**
* Used to Offset an NPC to put it in the center of a tile..
* Perhaps in the future this could be based on transform.scale?
*/
public float getSize(int npcType)
{
switch (npcType)
{
case 1:
return 2.0f;
default:
return 1.0f;
}
}
public Vector3 GetHeadPosition() => n.headTransform.position;
public void AnimationMovement(float moveSpeed)
{
//float diff = Vector3.Distance(transform.position, previousPosition);
//float currentMoveSpeed = animator.GetFloat(MOVE_SPEED);
//float targetMoveSpeed = Mathf.Abs(diff) < 0.01f ? 0 : moveSpeed;
//float interpolateMoveSpeed = Mathf.MoveTowards(currentMoveSpeed, targetMoveSpeed, 0.2f * Time.deltaTime);
n.animator.SetFloat("Speed", moveSpeed);
}
public void InterpolateEntity()
{
float distance = Vector3.Distance(n.transform.position, n.targetPosition);
float moveSpeed = n.deltaMultiplier * Time.deltaTime;
//NPC Interpolation
if (distance >= 10f || n.forcePositionUpdate)
{
n.transform.position = n.targetPosition;
n.forcePositionUpdate = false;
}
else if (distance > 0.0f)
{
n.transform.position = Vector3.MoveTowards(n.transform.position, n.targetPosition, distance * moveSpeed);
}
AnimationMovement(moveSpeed);
n.previousPosition = n.transform.position;
}
public void BindEntityToTerrain()
{
Terrain terrain = Misc.GetClosestCurrentTerrain(n.transform.position);
float height = terrain.SampleHeight(n.transform.position);
Vector3 setNPCHeight = n.transform.position;
setNPCHeight.y = height;
n.transform.position = setNPCHeight;
//n.transform.position = new Vector3(n.transform.position.x, 22.5f, n.transform.position.z);
}
public void ToggleColliders(bool isEnabled)
{
foreach (Collider collider in n.npcColliders)
{
collider.enabled = isEnabled;
}
}
public void InitializeVisuals(int weaponId, float scale, float h, float s, float v)
{
if (n.weaponRandomizer != null) n.weaponRandomizer.SetWeapon(weaponId);
n.transform.localScale = new Vector3(scale, scale, scale);
n.skinnedMesh.material.color = Color.HSVToRGB(h, s, v);
}
public void FadeHealthCanvas()
{
n.healthBarComponent.healthBar.SetHealth(0);
n.healthBarComponent.healthBar.GetCanvasGroup().DOFade(0, 1.0f);
}
public IEnumerator WaitToSpawnDeathSoul()
{
yield return new WaitForSeconds(1.75f);
NetworkPooler.Instance.PooledPlayEffect("Death_Soul", n.transform.position, n.transform.rotation, 5.0f);
}
public IEnumerator DeathFadePosition()
{
yield return new WaitForSeconds(5.0f);
Vector3 pos = n.transform.position;
float heightToMoveTo = pos.y -= 1.5f;
n.transform.DOMoveY(heightToMoveTo, 2.0f).SetEase(Ease.OutQuad);
}
}