entity changes, classes
This commit is contained in:
parent
bda2b88796
commit
8bd4aedcf9
20 changed files with 1917 additions and 27 deletions
|
|
@ -22,6 +22,7 @@ public class ActionUIHandler : MonoBehaviour
|
|||
#endregion
|
||||
private PlayerEntity selectedEntity;
|
||||
private RangedWeapon possibleRanged;
|
||||
public GameObject cursorObject;
|
||||
[Header("Main UI")]
|
||||
[SerializeField] private GameObject actionUI;
|
||||
[SerializeField] private TextMeshProUGUI actionText;
|
||||
|
|
@ -115,13 +116,14 @@ public class ActionUIHandler : MonoBehaviour
|
|||
public void ReloadGun()
|
||||
{
|
||||
possibleRanged.Reload();
|
||||
selectedEntity.actions -= 2;
|
||||
UpdateActions(possibleRanged.reloadActionUsage);
|
||||
HideUI();
|
||||
}
|
||||
|
||||
public void Attack()
|
||||
{
|
||||
selectedEntity.Attack();
|
||||
cursorObject.SetActive(true);
|
||||
HideUI();
|
||||
}
|
||||
|
||||
|
|
@ -167,12 +169,21 @@ public class ActionUIHandler : MonoBehaviour
|
|||
|
||||
public void SelectWeapon(Weapon weaponSelected)
|
||||
{
|
||||
selectedEntity.actions--;
|
||||
UpdateActions(1);
|
||||
selectedEntity.SwitchWeapon(weaponSelected);
|
||||
HideWeaponList();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void UpdateActions(int amount)
|
||||
{
|
||||
selectedEntity.actions -= amount;
|
||||
if (selectedEntity.actions == 0)
|
||||
{
|
||||
selectedEntity.debugDoneObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void HideWeaponList()
|
||||
{
|
||||
weaponUIPanel.gameObject.SetActive(false);
|
||||
|
|
|
|||
11
Assets/Scripts/AttachToCursor.cs
Normal file
11
Assets/Scripts/AttachToCursor.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class AttachToCursor : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Camera cam;
|
||||
private void Update()
|
||||
{
|
||||
transform.position = cam.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, cam.nearClipPlane);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AttachToCursor.cs.meta
Normal file
2
Assets/Scripts/AttachToCursor.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 548df8df9b2f95534b76729bc92e7bc9
|
||||
|
|
@ -1,10 +1,17 @@
|
|||
using System;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public float panSpeed;
|
||||
public bool canMoveCamera = true;
|
||||
[SerializeField] private CinemachineCamera cineCam;
|
||||
[Header("Zoom")]
|
||||
[SerializeField] private float zoomSpeed;
|
||||
[SerializeField] private float camMaxSize;
|
||||
[SerializeField] private float camMinSize;
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
|
@ -13,5 +20,12 @@ public class CameraController : MonoBehaviour
|
|||
Vector2 moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
|
||||
transform.Translate(moveDirection * (panSpeed * Time.deltaTime));
|
||||
}
|
||||
|
||||
if (Input.mouseScrollDelta.y != 0)
|
||||
{
|
||||
float scroll = Mathf.Clamp(cineCam.Lens.OrthographicSize - (Input.mouseScrollDelta.y * zoomSpeed),
|
||||
camMinSize, camMaxSize);
|
||||
cineCam.Lens.OrthographicSize = scroll;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Enemy : Entity
|
||||
{
|
||||
public static event Action<Entity> OnKill;
|
||||
[Header("Enemy Stats")]
|
||||
public int turnSpeed;
|
||||
public float minimumAttackRange;
|
||||
|
|
@ -19,7 +23,7 @@ public class Enemy : Entity
|
|||
closestPlayer = FindClosestPlayer();
|
||||
if (Vector3.Distance(transform.position, closestPlayer.transform.position) > minimumAttackRange)
|
||||
{
|
||||
EnemyMovement.instance.PathfindToTarget(closestPlayer.currentTile.neighbors[Random.Range(0, closestPlayer.currentTile.neighbors.Count)], this);
|
||||
EnemyMovement.instance.PathfindToTarget(GridManager.instance.FindClosestEmptyTile(closestPlayer.currentTile.neighbors[Random.Range(0, closestPlayer.currentTile.neighbors.Count)]), this);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -46,13 +50,14 @@ public class Enemy : Entity
|
|||
}
|
||||
return currentClosestPlayer;
|
||||
}
|
||||
protected override void OnKillEffects()
|
||||
protected override void OnKillEffects(Entity attacker)
|
||||
{
|
||||
TurnHandler.instance.enemyEntities.Remove(this);
|
||||
OnKill?.Invoke(attacker);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
public void Attack(PlayerEntity target)
|
||||
{
|
||||
target.TakeDamage(damage);
|
||||
target.TakeDamage(damage, this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ public class Entity : MonoBehaviour
|
|||
[SerializeField] private SpriteRenderer[] spriteRenderers;
|
||||
[SerializeField] private float damageColorChangeSpeed;
|
||||
|
||||
public virtual void TakeDamage(float damage)
|
||||
public virtual void TakeDamage(float damage, Entity attacker)
|
||||
{
|
||||
health -= damage;
|
||||
StartCoroutine(DamageAnimation());
|
||||
if (health <= 0)
|
||||
{
|
||||
OnKillEffects();
|
||||
OnKillEffects(attacker);
|
||||
}
|
||||
Debug.Log($"{name} took {damage} damage");
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ public class Entity : MonoBehaviour
|
|||
health = Mathf.Clamp(health, 0, maxHealth);
|
||||
}
|
||||
|
||||
protected virtual void OnKillEffects()
|
||||
protected virtual void OnKillEffects(Entity attacker)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class MeleeWeapon : Weapon
|
|||
{
|
||||
if (!enemy.transform.CompareTag(tag) && enemy.transform.TryGetComponent(out Entity isEntity))
|
||||
{
|
||||
isEntity.TakeDamage(damage);
|
||||
isEntity.TakeDamage(damage, thisEntity);
|
||||
}
|
||||
}
|
||||
isAiming = false;
|
||||
|
|
@ -32,11 +32,13 @@ public class MeleeWeapon : Weapon
|
|||
TurnHandler.instance.UpdateTurns();
|
||||
ActionUIHandler.instance.UpdateUI();
|
||||
debugColliderHitbox.gameObject.SetActive(false);
|
||||
ActionUIHandler.instance.cursorObject.SetActive(false);
|
||||
}
|
||||
else if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
isAiming = false;
|
||||
debugColliderHitbox.gameObject.SetActive(false);
|
||||
ActionUIHandler.instance.cursorObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
Assets/Scripts/OfficerAbilities.cs
Normal file
27
Assets/Scripts/OfficerAbilities.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class OfficerAbilities : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int killQuota;
|
||||
private int currentKills;
|
||||
public PlayerEntity thisEntity;
|
||||
private void Start()
|
||||
{
|
||||
Enemy.OnKill += UpdateKillQuota;
|
||||
}
|
||||
|
||||
private void UpdateKillQuota(Entity entity)
|
||||
{
|
||||
if (entity == thisEntity)
|
||||
{
|
||||
currentKills++;
|
||||
currentKills = Mathf.Clamp(currentKills, 0, killQuota);
|
||||
}
|
||||
}
|
||||
|
||||
public void ActivateAbility()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/OfficerAbilities.cs.meta
Normal file
2
Assets/Scripts/OfficerAbilities.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8bacba559d8b7025084e6a3b89c44a08
|
||||
|
|
@ -6,12 +6,18 @@ public class PlayerEntity : Entity
|
|||
[Header("Player Flags")]
|
||||
public int actions = 2;
|
||||
public int maxActions = 2;
|
||||
public enum PlayerClass {Ranker, Caster, Officer, Engineer, Medic}
|
||||
public PlayerClass selectedClass = PlayerClass.Ranker;
|
||||
[Header("Weaponry")]
|
||||
[SerializeField] private Weapon[] weapons;
|
||||
[HideInInspector] public List<Weapon> weaponInstances = new();
|
||||
public Weapon currentWeapon;
|
||||
[Header("OfficerAbilities")]
|
||||
[SerializeField] private OfficerAbilities officerAbility;
|
||||
[HideInInspector] public OfficerAbilities officerInstance;
|
||||
[Header("UI")]
|
||||
[SerializeField] private Transform hpBar;
|
||||
public GameObject debugDoneObject;
|
||||
void Start()
|
||||
{
|
||||
foreach (Weapon weapon in weapons)
|
||||
|
|
@ -21,6 +27,12 @@ public class PlayerEntity : Entity
|
|||
newWeapon.tag = tag;
|
||||
weaponInstances.Add(newWeapon);
|
||||
}
|
||||
|
||||
if (selectedClass == PlayerClass.Officer)
|
||||
{
|
||||
officerInstance = Instantiate(officerAbility, transform);
|
||||
officerInstance.thisEntity = this;
|
||||
}
|
||||
currentWeapon = weaponInstances[0];
|
||||
}
|
||||
|
||||
|
|
@ -30,9 +42,9 @@ public class PlayerEntity : Entity
|
|||
|
||||
}
|
||||
|
||||
public override void TakeDamage(float amount)
|
||||
public override void TakeDamage(float amount, Entity attacker)
|
||||
{
|
||||
base.TakeDamage(amount);
|
||||
base.TakeDamage(amount, attacker);
|
||||
UpdateHealthUI();
|
||||
}
|
||||
public void UpdateHealthUI()
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class PlayerEntityMovement : MonoBehaviour
|
|||
Deselect();
|
||||
}
|
||||
TileObject newTile = GridManager.instance.GetTileFromWorldPos(mouseGridPos);
|
||||
if (requestedTile != newTile)
|
||||
if (requestedTile != newTile && !newTile.blocked)
|
||||
{
|
||||
requestedTile = newTile;
|
||||
foreach (TileObject tile in pathRequested)
|
||||
|
|
@ -167,7 +167,7 @@ public class PlayerEntityMovement : MonoBehaviour
|
|||
StartCoroutine(selectedEntity.MoveToLocation(pathRequested.ToArray()));
|
||||
templateObject.SetActive(false);
|
||||
UncolorGrid();
|
||||
selectedEntity.actions--;
|
||||
ActionUIHandler.instance.UpdateActions(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ using UnityEngine;
|
|||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
[SerializeField] private LayerMask environmentLayer;
|
||||
public PlayerEntity fromEntity;
|
||||
[Header("Stats")]
|
||||
public float damage;
|
||||
public float speed;
|
||||
|
|
@ -31,13 +33,17 @@ public class Projectile : MonoBehaviour
|
|||
{
|
||||
if (!collision.CompareTag(tag) && collision.TryGetComponent(out Entity isEntity))
|
||||
{
|
||||
isEntity.TakeDamage(damage);
|
||||
isEntity.TakeDamage(damage, fromEntity);
|
||||
currentPierce++;
|
||||
if (currentPierce > pierceAmount)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
else if (collision.gameObject.layer == 3)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ public class RangedWeapon : Weapon
|
|||
private Camera cam;
|
||||
private Vector3 mousePos;
|
||||
[Header("Ranged Weapon Specifics")]
|
||||
public int reloadActionUsage;
|
||||
public bool fired;
|
||||
[SerializeField] private Projectile projectile;
|
||||
private void Start()
|
||||
|
|
@ -40,11 +41,13 @@ public class RangedWeapon : Weapon
|
|||
CreateProjectile(mousePos);
|
||||
fired = true;
|
||||
isAiming = false;
|
||||
thisEntity.actions--;
|
||||
ActionUIHandler.instance.UpdateActions(1);
|
||||
ActionUIHandler.instance.cursorObject.SetActive(false);
|
||||
}
|
||||
else if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
isAiming = false;
|
||||
ActionUIHandler.instance.cursorObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,6 +56,8 @@ public class RangedWeapon : Weapon
|
|||
{
|
||||
Projectile newProjectile = Instantiate(projectile, transform.position, Quaternion.identity);
|
||||
newProjectile.RotateToTarget(target);
|
||||
newProjectile.damage = damage;
|
||||
newProjectile.tag = tag;
|
||||
newProjectile.fromEntity = thisEntity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,13 @@ public class TurnHandler : MonoBehaviour
|
|||
[Header("Spawning")]
|
||||
[SerializeField] private int enemySpawnAmount;
|
||||
|
||||
[Header("Endless Mechanics")]
|
||||
[SerializeField] private bool isEndless = false;
|
||||
[SerializeField] private int baseSpawnAmount;
|
||||
[SerializeField] private int amountToSpawn;
|
||||
[SerializeField] private float exponentIncrease;
|
||||
private int currentWave = 1;
|
||||
|
||||
private void SortEnemies()
|
||||
{
|
||||
enemyEntities = enemyEntities.OrderBy(o=>o.turnSpeed).ToList();
|
||||
|
|
@ -83,12 +90,18 @@ public class TurnHandler : MonoBehaviour
|
|||
foreach (PlayerEntity player in playerEntities)
|
||||
{
|
||||
player.actions = player.maxActions;
|
||||
player.debugDoneObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void EnvironmentTurn()
|
||||
{
|
||||
EnemySpawner.instance.SpawnEnemy(enemySpawnAmount);
|
||||
if (isEndless && enemyEntities.Count == 0)
|
||||
{
|
||||
amountToSpawn = Mathf.FloorToInt(baseSpawnAmount * Mathf.Pow(currentWave, exponentIncrease));
|
||||
EnemySpawner.instance.SpawnEnemy(enemySpawnAmount);
|
||||
currentWave++;
|
||||
}
|
||||
}
|
||||
|
||||
public void SkipAll()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue