From 82653d92f48ae05037e8b8a64737b460db099dc6 Mon Sep 17 00:00:00 2001
From: Ny Bruker <robinhs@stud.ntnu.no>
Date: Sun, 2 Oct 2022 16:25:24 +0200
Subject: [PATCH] Reworked projectiles. - Uses AttackStats passed from the
 attack. - Takes target from attack instead of mouse pos. - Implemented range.

---
 .../Assets/Code/attack/AttackMovement.cs      | 80 ++++++++++++-------
 1 file changed, 52 insertions(+), 28 deletions(-)

diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs
index 37b53fa9..aa7795a3 100644
--- a/MrBigsock/Assets/Code/attack/AttackMovement.cs
+++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs
@@ -4,29 +4,44 @@ using UnityEngine;
 using UnityEngine.InputSystem;
 using static UnityEngine.GraphicsBuffer;
 
+using BigSock.Service;
+
+
 namespace BigSock {
 
 	public class AttackMovement : MonoBehaviour
 	{
 		public float speed = 10.0f;
 		bool moved = false;
-		Vector3 direction;
+		//Vector3 direction;
+		Vector3 startingPos;
 
 		/*
 			Damage of the character.
 		*/
-		public float Damage => baseDamage;
-		public float baseDamage = 1;
+		//public float Damage => baseDamage;
+		//public float baseDamage = 1;
 
-		public float KnockbackForce => knockbackForce;
-		public float knockbackForce = 1;
+		//public float KnockbackForce => knockbackForce;
+		//public float knockbackForce = 1;
 
 		/*
 			The character that activated the attack.
 		*/
-		public Character Actor { get; set; }
+		//public Character Actor { get; set; }
+		
+		/*
+			The attack stats of the attack.
+		*/
+		public AttackStats Stats { get; set; }
+
+		/*
+			The direction of the attack.
+		*/
+		public Vector3 Direction { get; set; }
+
 
-		// Start is called before the first frame update
+		// Start is called before the first frame update 
 		void Start()
 		{
 		}
@@ -36,18 +51,26 @@ namespace BigSock {
 		{
 			if (!moved)
 			{
-				var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
-				var pos = transform.position;
-				var temp = (mouse - pos);
-				temp.z = 0;
-				direction = temp.normalized;
+				//var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
+				//var pos = transform.position;
+				//var temp = (mouse - pos);
+				//temp.z = 0;
+				//direction = temp.normalized;
 				//print($"[AttackMovement.Update()] {mouse} - {pos} = {direction}");
+				startingPos = transform.position;
 				moved = true;
 			}
 
 			//transform.Translate(new Vector3(1 * horizontalInput, 1 * verticalInput, 0) * speed * Time.deltaTime);
-			transform.Translate(direction * speed * Time.deltaTime);
-				
+			transform.Translate(Direction * Stats.ProjectileSpeed * Time.deltaTime);
+
+			var traveled = Vector2.Distance(transform.position, startingPos);
+
+			// If we traveled passed our range: destroy this obj.
+			if(traveled > Stats.Range) {
+				PrefabService.SINGLETON.Destroy(gameObject);
+			}
+
 		}
 		
 		
@@ -58,23 +81,24 @@ namespace BigSock {
 
 			if(target != null) {
 
-				var attack = new AttackStats{
-					Damage = Damage,
-					Knockback = KnockbackForce,
-					//Range = 0,
-					//AttackSpeed = AttackSpeed,
-					Source = transform.position,
-					Actor = Actor,
-				};
+				//var attack = new AttackStats{
+				//	Damage = Damage,
+				//	Knockback = KnockbackForce,
+				//	//Range = 0,
+				//	//AttackSpeed = AttackSpeed,
+				//	Source = transform.position,
+				//	Actor = Actor,
+				//};
+				Stats.Source = transform.position;
 
 				// If we have an actor: Apply their stat mods & trigger their OnHit.
-				if(Actor != null) {
-					attack.Damage *= Actor.Damage;
-					attack.Knockback *= Actor.KnockbackForce;
-					//Actor.TargetHit(target, attack);
-				}
+				//if(Actor != null) {
+				//	attack.Damage *= Actor.Damage;
+				//	attack.Knockback *= Actor.KnockbackForce;
+				//	//Actor.TargetHit(target, attack);
+				//}
 
-				if(target.TakeDamage(attack)) {
+				if(target.TakeDamage(Stats)) {
 					
 				}
 			} 
-- 
GitLab