mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-11 12:27:40 +01:00
Merge branch 'SpartaqS-AddingSoldiersToSquad' into Development
This commit is contained in:
commit
a0564ec377
8
theProject/Assets/Prefabs/Managers.meta
Normal file
8
theProject/Assets/Prefabs/Managers.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 06da55108ff6ac84984842ede70a6019
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
48
theProject/Assets/Prefabs/Managers/SquadManager.prefab
Normal file
48
theProject/Assets/Prefabs/Managers/SquadManager.prefab
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &1831389151964757021
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1831389151964757027}
|
||||||
|
- component: {fileID: 1831389151964757020}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: SquadManager
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1831389151964757027
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1831389151964757021}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 2.9636345, y: 6.377094, z: 3.499856}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &1831389151964757020
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1831389151964757021}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 3a470f948c2458f4994fe0cf5f226c52, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
squadPrefab: {fileID: 6141901885681798073, guid: e79038bbfa9535f45be1d0f0ae0626ce,
|
||||||
|
type: 3}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3f72f88ef966ae34288fa03b7fff7884
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -78,22 +78,22 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: d34caf35d0ce610f8bc87cf815ba1915, type: 3}
|
m_Script: {fileID: 11500000, guid: d34caf35d0ce610f8bc87cf815ba1915, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
myTeam: 0
|
||||||
maxHealthPoints: 100
|
maxHealthPoints: 100
|
||||||
healthPoints: 100
|
healthPoints: 100
|
||||||
rangeAttack: 3
|
|
||||||
rangeView: 1
|
|
||||||
damageAttack: 1
|
|
||||||
speedAttack: 2
|
|
||||||
lastAttackTick: -1
|
|
||||||
nameText: {fileID: 6838251604148675782}
|
nameText: {fileID: 6838251604148675782}
|
||||||
healthPointsText: {fileID: 8012357605284019061}
|
healthPointsText: {fileID: 8012357605284019061}
|
||||||
target: {fileID: 0}
|
OnDeath:
|
||||||
enemyType: 0
|
|
||||||
ourType: 0
|
|
||||||
movementDestination: {x: 0, y: 0}
|
|
||||||
onDeath:
|
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
|
rangeAttack: 3
|
||||||
|
rangeView: 1
|
||||||
|
damageAttack: 25
|
||||||
|
speedAttack: 2
|
||||||
|
lastAttackTick: -1
|
||||||
|
target: {fileID: 0}
|
||||||
|
enemyType: 0
|
||||||
|
movementDestination: {x: 0, y: 0}
|
||||||
--- !u!1 &1997457243244158843
|
--- !u!1 &1997457243244158843
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -358,12 +358,12 @@ MonoBehaviour:
|
|||||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||||
m_isUsingLegacyAnimationComponent: 0
|
m_isUsingLegacyAnimationComponent: 0
|
||||||
m_isVolumetricText: 0
|
m_isVolumetricText: 0
|
||||||
m_hasFontAssetChanged: 0
|
|
||||||
m_renderer: {fileID: 1498494949006888735}
|
|
||||||
m_maskType: 0
|
|
||||||
_SortingLayer: 0
|
_SortingLayer: 0
|
||||||
_SortingLayerID: 0
|
_SortingLayerID: 0
|
||||||
_SortingOrder: 0
|
_SortingOrder: 0
|
||||||
|
m_hasFontAssetChanged: 0
|
||||||
|
m_renderer: {fileID: 1498494949006888735}
|
||||||
|
m_maskType: 0
|
||||||
--- !u!1 &2062275012809416088
|
--- !u!1 &2062275012809416088
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -530,9 +530,9 @@ MonoBehaviour:
|
|||||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||||
m_isUsingLegacyAnimationComponent: 0
|
m_isUsingLegacyAnimationComponent: 0
|
||||||
m_isVolumetricText: 0
|
m_isVolumetricText: 0
|
||||||
m_hasFontAssetChanged: 0
|
|
||||||
m_renderer: {fileID: 4083783489867894370}
|
|
||||||
m_maskType: 0
|
|
||||||
_SortingLayer: 0
|
_SortingLayer: 0
|
||||||
_SortingLayerID: 0
|
_SortingLayerID: 0
|
||||||
_SortingOrder: 0
|
_SortingOrder: 0
|
||||||
|
m_hasFontAssetChanged: 0
|
||||||
|
m_renderer: {fileID: 4083783489867894370}
|
||||||
|
m_maskType: 0
|
||||||
|
|||||||
47
theProject/Assets/Prefabs/Squad.prefab
Normal file
47
theProject/Assets/Prefabs/Squad.prefab
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &6141901885681798073
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 6141901885681798079}
|
||||||
|
- component: {fileID: 6141901885681798078}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Squad
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &6141901885681798079
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6141901885681798073}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 4.4048395, y: -4.749419, z: 13.353434}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &6141901885681798078
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6141901885681798073}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: eeef7310a48872043b4089979ec88b42, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
soldiers: []
|
||||||
7
theProject/Assets/Prefabs/Squad.prefab.meta
Normal file
7
theProject/Assets/Prefabs/Squad.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e79038bbfa9535f45be1d0f0ae0626ce
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: c8976c4733dc9814ca33c36b50beadf4
|
guid: ab3f3b9b28d59aa48a9da7d926f1e0cd
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
|
|||||||
@ -1,73 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using TMPro;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class Base : MonoBehaviour
|
|
||||||
{
|
|
||||||
public enum SoldierType
|
|
||||||
{
|
|
||||||
Ally,
|
|
||||||
Enemy
|
|
||||||
}
|
|
||||||
[SerializeField] protected SoldierType ourType;
|
|
||||||
[SerializeField] private float maxHealthPoints = 100;
|
|
||||||
[SerializeField] private float healthPoints = 100;
|
|
||||||
|
|
||||||
[SerializeField] private TMP_Text nameText = null;
|
|
||||||
[SerializeField] private TMP_Text healthPointsText = null;
|
|
||||||
|
|
||||||
public SoldierType TempGetOwnType()
|
|
||||||
{
|
|
||||||
return ourType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start is called before the first frame update
|
|
||||||
protected void Start(){
|
|
||||||
healthPoints = maxHealthPoints; // initialize health
|
|
||||||
UpdateHPDisplay();
|
|
||||||
|
|
||||||
Debug.Log("Base: " + ourType.ToString() + " has appeared", gameObject);
|
|
||||||
|
|
||||||
switch (ourType)
|
|
||||||
{
|
|
||||||
case SoldierType.Ally:
|
|
||||||
nameText.text = "Ally";
|
|
||||||
nameText.color = Color.blue;
|
|
||||||
break;
|
|
||||||
case SoldierType.Enemy:
|
|
||||||
nameText.text = "Enemy";
|
|
||||||
nameText.color = Color.red;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
nameText.text = "how did we get here (forever)";
|
|
||||||
nameText.color = new Color(255, 192, 203);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwnTag(SoldierType type)
|
|
||||||
{
|
|
||||||
ourType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnDestroy()
|
|
||||||
{
|
|
||||||
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
|
||||||
}
|
|
||||||
protected void ReduceHP(float damage)
|
|
||||||
{
|
|
||||||
healthPoints -= damage;
|
|
||||||
|
|
||||||
if (healthPoints <= 0)
|
|
||||||
Destroy(gameObject);
|
|
||||||
|
|
||||||
UpdateHPDisplay();
|
|
||||||
Debug.Log("I took damage, my HP is now: " + healthPoints + " noooo!!!!", gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateHPDisplay()
|
|
||||||
{
|
|
||||||
healthPointsText.text = healthPoints.ToString() + "/" + maxHealthPoints.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8
theProject/Assets/Scripts/Entities.meta
Normal file
8
theProject/Assets/Scripts/Entities.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2e5f405b6facc6e47a0297f2be93eae4
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
theProject/Assets/Scripts/Entities/Base.cs
Normal file
9
theProject/Assets/Scripts/Entities/Base.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Base : Entity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
96
theProject/Assets/Scripts/Entities/Entity.cs
Normal file
96
theProject/Assets/Scripts/Entities/Entity.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
public class Entity : MonoBehaviour
|
||||||
|
{
|
||||||
|
public enum Team
|
||||||
|
{
|
||||||
|
Ally,
|
||||||
|
Enemy
|
||||||
|
}
|
||||||
|
[Header("Values")]
|
||||||
|
[SerializeField] protected Team myTeam;
|
||||||
|
[SerializeField] protected float maxHealthPoints = 100;
|
||||||
|
[SerializeField] protected float healthPoints = 100;
|
||||||
|
|
||||||
|
[SerializeField] protected TMP_Text nameText = null;
|
||||||
|
[SerializeField] protected TMP_Text healthPointsText = null;
|
||||||
|
|
||||||
|
[HideInInspector] public UnityEvent<Entity> OnDeath = new UnityEvent<Entity>();
|
||||||
|
|
||||||
|
public Team GetOwnTeam()
|
||||||
|
{
|
||||||
|
return myTeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start is called before the first frame update
|
||||||
|
protected virtual void Start(){
|
||||||
|
healthPoints = maxHealthPoints; // initialize health
|
||||||
|
UpdateHPDisplay();
|
||||||
|
|
||||||
|
Debug.Log("Entity: " + myTeam.ToString() + " has appeared", gameObject);
|
||||||
|
|
||||||
|
switch (myTeam)
|
||||||
|
{
|
||||||
|
case Team.Ally:
|
||||||
|
nameText.text = "Ally";
|
||||||
|
nameText.color = Color.blue;
|
||||||
|
break;
|
||||||
|
case Team.Enemy:
|
||||||
|
nameText.text = "Enemy";
|
||||||
|
nameText.color = Color.red;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nameText.text = "how did we get here (forever)";
|
||||||
|
nameText.color = new Color(255, 192, 203);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Awake()
|
||||||
|
{
|
||||||
|
TickSystem.OnTick += HandleTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Die()
|
||||||
|
{
|
||||||
|
TickSystem.OnTick -= HandleTick;
|
||||||
|
OnDeath.Invoke(this);
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetOwnTeam(Team type)
|
||||||
|
{
|
||||||
|
myTeam = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReduceHP(float damage)
|
||||||
|
{
|
||||||
|
healthPoints -= damage;
|
||||||
|
|
||||||
|
if (healthPoints <= 0)
|
||||||
|
Die();
|
||||||
|
|
||||||
|
UpdateHPDisplay();
|
||||||
|
Debug.Log("I took damage, my HP is now: " + healthPoints + " noooo!!!!", gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
Debug.Log("Soldier: " + myTeam.ToString() + " has died", gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void UpdateHPDisplay()
|
||||||
|
{
|
||||||
|
healthPointsText.text = healthPoints.ToString() + "/" + maxHealthPoints.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
theProject/Assets/Scripts/Entities/Entity.cs.meta
Normal file
11
theProject/Assets/Scripts/Entities/Entity.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d77d5669fae0f57499970c2aed5af02b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -1,165 +1,148 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
public class Soldier : Base
|
public class Soldier : Entity
|
||||||
{
|
{
|
||||||
private Queue<Action> actions = new Queue<Action>();
|
private Queue<Action> actions = new Queue<Action>();
|
||||||
private Queue<Action> interrupts = new Queue<Action>();
|
private Queue<Action> interrupts = new Queue<Action>();
|
||||||
#region Action Queue Items
|
#region Action Queue Items
|
||||||
abstract class Action // action "template"
|
abstract class Action // action "template"
|
||||||
{
|
{
|
||||||
public virtual void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs) { } // called by Soldier when action is supposed to be done
|
public virtual void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs) { } // called by Soldier when action is supposed to be done
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Movement : Action
|
private class Movement : Action
|
||||||
{
|
{
|
||||||
public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs)
|
public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs)
|
||||||
{
|
{//TO DO: CALL PROPER FUNCTION TO MOVE
|
||||||
// move solider to previously set destination
|
throw new System.NotImplementedException($"(tick: {tickEventArgs.tickNumber}) Trying to teleport to {soldier.movementDestination}");
|
||||||
TilemapManager.MoveSoldierS(soldier.tileCoord.x, soldier.tileCoord.y, soldier.movementDestination.x, soldier.movementDestination.y);
|
//??tileMap.Teleport(movementDestination)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class TryAttack : Action
|
private class TryAttack : Action
|
||||||
{
|
{
|
||||||
public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs)
|
public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs)
|
||||||
{
|
{
|
||||||
//Debug.LogWarning($"(tick: {tickEventArgs.tickNumber}) Looking for enemy in range");
|
//Debug.LogWarning($"(tick: {tickEventArgs.tickNumber}) Looking for enemy in range");
|
||||||
if(soldier.TryAttackEnemy())
|
if(soldier.TryAttackEnemy())
|
||||||
soldier.lastAttackTick = tickEventArgs.tickNumber;
|
soldier.lastAttackTick = tickEventArgs.tickNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Handling Incoming Orders (Interrupts)
|
#region Handling Incoming Orders (Interrupts)
|
||||||
public void HandleMovementOrder(Vector2Int destination)
|
public void HandleMovementOrder(Vector2Int destination)
|
||||||
{
|
{
|
||||||
movementDestination = destination;
|
movementDestination = destination;
|
||||||
interrupts.Enqueue(new Movement()); // force soldier to find path to the new destination
|
interrupts.Enqueue(new Movement()); // force soldier to find path to the new destination
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[Header("Values")]
|
[Header("Soldier Values")]
|
||||||
[SerializeField] private float rangeAttack = 100;
|
[SerializeField] private float rangeAttack = 100;
|
||||||
[SerializeField] private float rangeView = 1;
|
[SerializeField] private float rangeView = 1;
|
||||||
[SerializeField] private float damageAttack = 1;
|
[SerializeField] private float damageAttack = 1;
|
||||||
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
||||||
[SerializeField] private int lastAttackTick = -1;
|
[SerializeField] private int lastAttackTick = -1;
|
||||||
[Header("References")]
|
[Header("References")]
|
||||||
[Header("Do-not-change-in-game values")]
|
[Header("Do-not-change-in-game values")]
|
||||||
[SerializeField] private Soldier target;
|
[SerializeField] private Entity target;
|
||||||
[SerializeField] private SoldierType enemyType;
|
[SerializeField] private Team enemyType;
|
||||||
[SerializeField] private SoldierType ourType;
|
|
||||||
[SerializeField] private Vector2Int tileCoord = Vector2Int.zero;
|
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
||||||
|
|
||||||
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
// Start is called before the first frame update
|
||||||
|
protected override void Start(){
|
||||||
// variables not visible in inspector
|
base.Start();
|
||||||
|
SetEnemyTag();
|
||||||
[HideInInspector] public UnityEvent onDeath = new UnityEvent();
|
}
|
||||||
|
|
||||||
|
public void SetEnemyTag()
|
||||||
void Start(){
|
{
|
||||||
base.Start();
|
if(myTeam == Team.Ally) enemyType = Team.Enemy;
|
||||||
setEnemyTag();
|
else enemyType = Team.Ally;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTileCoords(Vector2Int tileCoordinates)
|
protected override void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
|
||||||
{
|
{
|
||||||
tileCoord = tileCoordinates;
|
// base.HandleTick(tickEventArgs);
|
||||||
}
|
|
||||||
|
ref Queue<Action> queueToHandle = ref interrupts;
|
||||||
public void setEnemyTag()
|
if (interrupts.Count < 1) // if no interrupt actions to do, handle regular queue
|
||||||
{
|
queueToHandle = actions;
|
||||||
if(ourType == SoldierType.Ally) enemyType = SoldierType.Enemy;
|
|
||||||
else enemyType = SoldierType.Ally;
|
if(queueToHandle.Count > 0)
|
||||||
}
|
queueToHandle.Dequeue().Execute(this, tickEventArgs);
|
||||||
|
else
|
||||||
void Awake()
|
{
|
||||||
{
|
if(lastAttackTick + speedAttack <= tickEventArgs.tickNumber)
|
||||||
TickSystem.OnTick += HandleTick;
|
{
|
||||||
}
|
queueToHandle.Enqueue(new TryAttack());
|
||||||
|
queueToHandle.Dequeue().Execute(this, tickEventArgs);
|
||||||
private void OnDestroy()
|
}
|
||||||
{
|
}
|
||||||
base.OnDestroy();
|
}
|
||||||
TickSystem.OnTick -= HandleTick;
|
|
||||||
onDeath.Invoke();
|
bool TryAttackEnemy () //returns true if an enemy was attacked
|
||||||
}
|
{
|
||||||
|
// Enemies are the game objects tagged with the "Enemy"
|
||||||
private void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
|
//GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyType);
|
||||||
{
|
Entity[] soldiers = GameObject.FindObjectsOfType<Entity>();
|
||||||
ref Queue<Action> queueToHandle = ref interrupts;
|
|
||||||
if (interrupts.Count < 1) // if no interrupt actions to do, handle regular queue
|
List<Entity> enemiesList = new List<Entity>();
|
||||||
queueToHandle = actions;
|
|
||||||
|
foreach (Entity obj in soldiers)
|
||||||
if(queueToHandle.Count > 0)
|
{
|
||||||
queueToHandle.Dequeue().Execute(this, tickEventArgs);
|
if (obj.GetOwnTeam() == enemyType)
|
||||||
else
|
enemiesList.Add(obj);
|
||||||
{
|
}
|
||||||
if(lastAttackTick + speedAttack <= tickEventArgs.tickNumber)
|
|
||||||
{
|
Debug.Log(soldiers.Length);
|
||||||
queueToHandle.Enqueue(new TryAttack());
|
Debug.Log(enemiesList.Count);
|
||||||
queueToHandle.Dequeue().Execute(this, tickEventArgs);
|
Entity[] enemies = enemiesList.ToArray();
|
||||||
}
|
|
||||||
}
|
// We have not found enemy yet so the distance to enemy is "infinite"
|
||||||
}
|
float shortestDistance = Mathf.Infinity;
|
||||||
|
Entity nearestEnemy = null;
|
||||||
bool TryAttackEnemy () //returns true if an enemy was attacked
|
foreach (Entity enemy in enemies)
|
||||||
{
|
{
|
||||||
// Enemies are the game objects tagged with the "Enemy"
|
// Go through each enemy existing
|
||||||
//GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyType);
|
// Calculate distance to this enemy
|
||||||
Soldier[] soldiers = GameObject.FindObjectsOfType<Soldier>();
|
float distanceToEnemy = Vector3.Distance(transform.position,
|
||||||
|
enemy.transform.position);
|
||||||
List<Soldier> enemiesList = new List<Soldier>();
|
if (distanceToEnemy < shortestDistance)
|
||||||
|
{
|
||||||
foreach (Soldier obj in soldiers)
|
shortestDistance = distanceToEnemy;
|
||||||
{
|
nearestEnemy = enemy;
|
||||||
if (obj.ourType == enemyType)
|
}
|
||||||
enemiesList.Add(obj);
|
}
|
||||||
}
|
|
||||||
|
if (nearestEnemy != null && shortestDistance <= rangeAttack)
|
||||||
Soldier[] enemies = enemiesList.ToArray();
|
{
|
||||||
|
target = nearestEnemy;
|
||||||
// We have not found enemy yet so the distance to enemy is "infinite"
|
}
|
||||||
float shortestDistance = Mathf.Infinity;
|
else
|
||||||
Soldier nearestEnemy = null;
|
target = null;
|
||||||
foreach ( Soldier enemy in enemies)
|
|
||||||
{
|
if (target != null)
|
||||||
// Go through each enemy existing
|
target.ReduceHP(damageAttack);
|
||||||
// Calculate distance to this enemy
|
|
||||||
float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
|
return target != null;
|
||||||
if (distanceToEnemy < shortestDistance)
|
}
|
||||||
{
|
|
||||||
shortestDistance = distanceToEnemy;
|
// Update is called once per frame
|
||||||
nearestEnemy = enemy;
|
void Update()
|
||||||
}
|
{
|
||||||
}
|
//if (target == null) return;
|
||||||
|
}
|
||||||
if (nearestEnemy != null && shortestDistance <= rangeAttack)
|
|
||||||
{
|
/* https://www.youtube.com/watch?v=QKhn2kl9_8I 08:54 Soldier attack
|
||||||
target = nearestEnemy;
|
void OnDrawGizmosSelected ()
|
||||||
}
|
{
|
||||||
else
|
|
||||||
target = null;
|
}
|
||||||
|
*/
|
||||||
if (target != null)
|
}
|
||||||
target.ReduceHP(damageAttack);
|
|
||||||
|
|
||||||
return target != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
//if (target == null) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* https://www.youtube.com/watch?v=QKhn2kl9_8I 08:54 Soldier attack
|
|
||||||
void OnDrawGizmosSelected ()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
38
theProject/Assets/Scripts/Managers/SquadManager.cs
Normal file
38
theProject/Assets/Scripts/Managers/SquadManager.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// TEMP CODE JUST FOR SHOWCASE PURPOSES
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class SquadManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] GameObject squadPrefab;
|
||||||
|
Squad playerSquad;
|
||||||
|
Squad enemySquad;
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
playerSquad = Instantiate(squadPrefab).GetComponent<Squad>();
|
||||||
|
playerSquad.gameObject.name = "Player Squad";
|
||||||
|
playerSquad.transform.SetParent(transform);
|
||||||
|
|
||||||
|
enemySquad = Instantiate(squadPrefab).GetComponent<Squad>();
|
||||||
|
enemySquad.gameObject.name = "Enemy Squad";
|
||||||
|
enemySquad.transform.SetParent(transform);
|
||||||
|
|
||||||
|
}
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
Debug.Log("Added initial soldiers to squad");
|
||||||
|
// add all ally soldiers to squad
|
||||||
|
var soldiers = FindObjectsOfType<Soldier>();
|
||||||
|
foreach(var soldier in soldiers)
|
||||||
|
{
|
||||||
|
if(soldier.GetOwnTeam() == Soldier.Team.Ally)
|
||||||
|
{
|
||||||
|
playerSquad.TempAddSoldierToSquad(soldier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,29 +0,0 @@
|
|||||||
// TEMP CODE JUST FOR SHOWCASE PURPOSES
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class TempSquadManager : MonoBehaviour
|
|
||||||
{
|
|
||||||
Squad playerSquad;
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
playerSquad = FindObjectOfType<Squad>();
|
|
||||||
}
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
Debug.Log("Added initial soldeirs to squad");
|
|
||||||
// add all ally soldiers to squad
|
|
||||||
var soldiers = FindObjectsOfType<Soldier>();
|
|
||||||
foreach(var soldier in soldiers)
|
|
||||||
{
|
|
||||||
if(soldier.TempGetOwnType() == Soldier.SoldierType.Ally)
|
|
||||||
{
|
|
||||||
playerSquad.TempAddSoldierToSquad(soldier);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -14,7 +14,7 @@ public class TilemapManager : MonoBehaviour
|
|||||||
|
|
||||||
public struct Tile
|
public struct Tile
|
||||||
{
|
{
|
||||||
public Soldier standingSoldier;
|
public Entity standingEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Header("Common Values")]
|
[Header("Common Values")]
|
||||||
@ -101,19 +101,19 @@ public class TilemapManager : MonoBehaviour
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isBase)
|
if (isBase)
|
||||||
tiles[x, y].standingSoldier = Instantiate(basePrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
tiles[x, y].standingEntity = Instantiate(basePrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Base>();
|
||||||
else
|
else
|
||||||
tiles[x, y].standingSoldier = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
tiles[x, y].standingEntity = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
||||||
|
|
||||||
if (tiles[x, y].standingSoldier == null)
|
if (tiles[x, y].standingSoldier == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isAlly)
|
if (isAlly)
|
||||||
tiles[x, y].standingSoldier.setOwnTag(Soldier.SoldierType.Ally);
|
tiles[x, y].standingEntity.SetOwnTeam(Base.Team.Ally);
|
||||||
else
|
else
|
||||||
tiles[x, y].standingSoldier.setOwnTag(Soldier.SoldierType.Enemy);
|
tiles[x, y].standingEntity.SetOwnTeam(Base.Team.Enemy);
|
||||||
|
|
||||||
tiles[x, y].standingSoldier.SetTileCoords(new Vector2Int(x, y));
|
tiles[x, y].standingEntity.SetTileCoords(new Vector2Int(x, y));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -123,46 +123,32 @@ public class TilemapManager : MonoBehaviour
|
|||||||
if (GetTileState(x, y) != TileState.taken)
|
if (GetTileState(x, y) != TileState.taken)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Destroy(tiles[x, y].standingSoldier.gameObject);
|
Destroy(tiles[x, y].standingEntity.gameObject);
|
||||||
tiles[x, y].standingSoldier = null;
|
tiles[x, y].standingEntity = null;
|
||||||
Debug.Log("Despaned a soldier");
|
Debug.Log("Despaned a soldier");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Soldier GetSoldier(int x, int y)
|
public Entity GetSoldier(int x, int y)
|
||||||
{
|
{
|
||||||
if (GetTileState(x, y) != TileState.taken)
|
if (GetTileState(x, y) != TileState.taken)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return tiles[x,y].standingSoldier;
|
return tiles[x,y].standingEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Soldier[] GetAllSoldiers()
|
public bool MoveEntity(int x1, int y1, int x2, int y2) // old MoveSoldier
|
||||||
{
|
|
||||||
List<Soldier> list = new List<Soldier>();
|
|
||||||
|
|
||||||
foreach (Tile obj in tiles)
|
|
||||||
{
|
|
||||||
if (obj.standingSoldier != null)
|
|
||||||
list.Add(obj.standingSoldier);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool MoveSoldier(int x1, int y1, int x2, int y2)
|
|
||||||
{
|
{
|
||||||
if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free)
|
if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free)
|
||||||
{
|
{
|
||||||
// change proper values
|
// change proper values
|
||||||
tiles[x2, y2].standingSoldier = tiles[x1, y1].standingSoldier;
|
tiles[x2, y2].standingEntity = tiles[x1, y1].standingEntity;
|
||||||
tiles[x1, y1].standingSoldier = null;
|
tiles[x1, y1].standingEntity = null;
|
||||||
tiles[x2, y2].standingSoldier.SetTileCoords(new Vector2Int(x2, y2));
|
tiles[x2, y2].standingEntity.SetTileCoords(new Vector2Int(x2, y2));
|
||||||
|
|
||||||
// change Soldier world position
|
// change Soldier world position
|
||||||
tiles[x2, y2].standingSoldier.transform.position = tilemap.CellToWorld(new Vector3Int(x2, y2, 0));
|
tiles[x2, y2].standingEntity.transform.position = tilemap.CellToWorld(new Vector3Int(x2, y2, 0)) + WORLD_SPACE_OFFSET;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +169,7 @@ public class TilemapManager : MonoBehaviour
|
|||||||
if (x < 0 || y < 0 || x >= mapSize.x || y >= mapSize.y)
|
if (x < 0 || y < 0 || x >= mapSize.x || y >= mapSize.y)
|
||||||
return TileState.outOfBounds;
|
return TileState.outOfBounds;
|
||||||
|
|
||||||
if (tiles[x, y].standingSoldier == null)
|
if (tiles[x, y].standingEntity == null)
|
||||||
return TileState.free;
|
return TileState.free;
|
||||||
|
|
||||||
return TileState.taken;
|
return TileState.taken;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user