Old Aetheria Code
Imported and massively refactored a bunch of code from the old Aetheria project
This commit is contained in:
parent
c58ba0b1da
commit
d64d5ab729
69 changed files with 6197 additions and 2458 deletions
101
Assets/Scripts/Targetable.cs
Normal file
101
Assets/Scripts/Targetable.cs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class Targetable : MonoBehaviour
|
||||
{
|
||||
public float Points = 100;
|
||||
public float Visibility;
|
||||
public Transform ReplaceWithPrefab;
|
||||
public Ship Ship;
|
||||
|
||||
public IsFriendlyFoeStatus DefaultIsFriendlyFoeStatus = IsFriendlyFoeStatus.None;
|
||||
|
||||
public readonly Dictionary<Targetable, IsFriendlyFoeStatus> IFF = new Dictionary<Targetable, IsFriendlyFoeStatus>();
|
||||
private Vector3 _lastPosition;
|
||||
|
||||
public IsFriendlyFoeStatus IsFriendlyFoe(Targetable target)
|
||||
{
|
||||
if (!IFF.ContainsKey(target))
|
||||
IFF[target] = DefaultIsFriendlyFoeStatus;
|
||||
|
||||
return IFF[target];
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Ship = GetComponent<Ship>();
|
||||
}
|
||||
|
||||
void Health(float health)
|
||||
{
|
||||
Points = health;
|
||||
}
|
||||
|
||||
public void Damage(float points)
|
||||
{
|
||||
if (Ship != null)
|
||||
{
|
||||
var shield = Ship.GetEquipped(HardpointType.Shield);
|
||||
if (shield != null)
|
||||
{
|
||||
var shieldData = shield.ItemData as Shield;
|
||||
var shieldedDamage = points * saturate(shieldData.Shielding.Evaluate(shield, Ship));
|
||||
Ship.AddHeat(shieldedDamage / shieldData.Efficiency.Evaluate(shield, Ship));
|
||||
Ship.Hull.Durability -= points - shieldedDamage;
|
||||
}
|
||||
else Ship.Hull.Durability -= points;
|
||||
}
|
||||
else
|
||||
{
|
||||
Points -= points;
|
||||
|
||||
if (Points > 0) return;
|
||||
|
||||
KillLocal();
|
||||
}
|
||||
/*
|
||||
var ent = GameManager.Instance.Entities.FirstOrDefault(kv => kv.Value == transform).Key;
|
||||
if(ent>0)
|
||||
GameManager.Instance.Send("Destroy", ent);*/
|
||||
|
||||
}
|
||||
|
||||
public void KillLocal()
|
||||
{
|
||||
//GameManager.Instance.Kill(this);
|
||||
// if (GetComponent<PlayerShip>())
|
||||
// {
|
||||
// GameManager.Instance.KillPlayer();
|
||||
// }
|
||||
|
||||
Destroy(gameObject);
|
||||
|
||||
if (ReplaceWithPrefab != null)
|
||||
Instantiate(ReplaceWithPrefab, transform.position, transform.rotation);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
_lastPosition = transform.position;
|
||||
}
|
||||
|
||||
void kill(string[] args)
|
||||
{
|
||||
if(args[0]==gameObject.name)
|
||||
KillLocal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum IsFriendlyFoeStatus
|
||||
{
|
||||
None,
|
||||
Friendly,
|
||||
Hostile,
|
||||
Mayday,
|
||||
Body,
|
||||
Wormhole
|
||||
}
|
||||
Loading…
Reference in a new issue