Gewehr sollte jetzt vollständig Funktionieren mitsamt Schusseffekten und Bugfixing. Es fehlen noch anpassungen an Balancingwerten. Als nächstes sollte Gegner Hit-Registrierung und Combat dessen Seite anstehen, dann weitere Türme zur Verteidigung.
This commit is contained in:
1 parent
e8c81646c4
commit
9367275e8d
17 files changed
+591
-418
No files matched your search
+159
-12
@@ -1,3 +1,5 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DepthsOfGreed.HandbookUI;
|
||||
|
||||
@@ -24,6 +26,13 @@ public class Turret : MonoBehaviour
|
||||
[SerializeField]
|
||||
private float bulletSpeed = 8f;
|
||||
|
||||
[Min(1)]
|
||||
public int pierce = 3;
|
||||
|
||||
[Header("Shooting Effect")]
|
||||
[SerializeField]
|
||||
private GameObject effectPrefab;
|
||||
|
||||
private CombatDefinition combatStats;
|
||||
|
||||
private float nextAttackTime;
|
||||
@@ -62,7 +71,6 @@ public class Turret : MonoBehaviour
|
||||
if (combatStats == null)
|
||||
return;
|
||||
|
||||
// Ziel innerhalb der Reichweite suchen.
|
||||
currentTarget = FindTarget();
|
||||
|
||||
if (currentTarget != null)
|
||||
@@ -72,7 +80,6 @@ public class Turret : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// Zur ursprünglichen Ausrichtung zurückkehren.
|
||||
RotateTowardsOrigin();
|
||||
}
|
||||
}
|
||||
@@ -119,7 +126,6 @@ public class Turret : MonoBehaviour
|
||||
Vector3 worldDirection =
|
||||
currentTarget.transform.position - turret.position;
|
||||
|
||||
// Richtung in den lokalen Raum der Turmbasis umwandeln.
|
||||
Vector3 localDirection =
|
||||
turret.parent != null
|
||||
? turret.parent.InverseTransformDirection(worldDirection)
|
||||
@@ -166,6 +172,95 @@ public class Turret : MonoBehaviour
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
// Feuer-Effekt an der Geschützspitze erzeugen.
|
||||
if (effectPrefab != null)
|
||||
{
|
||||
Instantiate(
|
||||
effectPrefab,
|
||||
tip.position,
|
||||
tip.rotation
|
||||
);
|
||||
}
|
||||
|
||||
// Neue Trefferliste für diesen Angriff.
|
||||
HashSet<Enemy> hitEnemies = new HashSet<Enemy>();
|
||||
|
||||
int remainingPierce = Mathf.Max(1, pierce);
|
||||
|
||||
// Kreisradius entspricht dem Abstand zur Geschützspitze.
|
||||
Vector2 attackCenter = turret.position;
|
||||
|
||||
float attackRadius = Vector2.Distance(
|
||||
turret.position,
|
||||
tip.position
|
||||
);
|
||||
|
||||
// Alle Collider im Nahbereich ermitteln.
|
||||
Collider2D[] nearbyColliders =
|
||||
Physics2D.OverlapCircleAll(
|
||||
attackCenter,
|
||||
attackRadius
|
||||
);
|
||||
|
||||
// Gegner und ihre Entfernung speichern.
|
||||
Dictionary<Enemy, float> nearbyEnemies =
|
||||
new Dictionary<Enemy, float>();
|
||||
|
||||
foreach (Collider2D col in nearbyColliders)
|
||||
{
|
||||
if (col == null)
|
||||
continue;
|
||||
|
||||
Enemy enemy =
|
||||
col.GetComponentInParent<Enemy>();
|
||||
|
||||
if (enemy == null || enemy.IsDead)
|
||||
continue;
|
||||
|
||||
// Mehrere Collider desselben Gegners vermeiden.
|
||||
if (nearbyEnemies.ContainsKey(enemy))
|
||||
continue;
|
||||
|
||||
float distance =
|
||||
Vector2.Distance(
|
||||
attackCenter,
|
||||
enemy.transform.position
|
||||
);
|
||||
|
||||
nearbyEnemies.Add(enemy, distance);
|
||||
}
|
||||
|
||||
// Gegner nach Entfernung sortieren.
|
||||
List<Enemy> sortedEnemies =
|
||||
new List<Enemy>(nearbyEnemies.Keys);
|
||||
|
||||
sortedEnemies.Sort((a, b) =>
|
||||
nearbyEnemies[a].CompareTo(nearbyEnemies[b])
|
||||
);
|
||||
|
||||
// Phase 1: Sofortiger Nahbereichsschaden.
|
||||
foreach (Enemy enemy in sortedEnemies)
|
||||
{
|
||||
if (remainingPierce <= 0)
|
||||
break;
|
||||
|
||||
if (enemy == null || enemy.IsDead)
|
||||
continue;
|
||||
|
||||
if (!hitEnemies.Add(enemy))
|
||||
continue;
|
||||
|
||||
enemy.TakeDamage(combatStats.damagePerHit);
|
||||
|
||||
remainingPierce--;
|
||||
}
|
||||
|
||||
// Kein Pierce mehr übrig:
|
||||
// Der Angriff endet ohne Projektil.
|
||||
if (remainingPierce <= 0)
|
||||
return;
|
||||
|
||||
// Phase 2: Normales Projektil direkt an der Spitze.
|
||||
GameObject bulletObject = Instantiate(
|
||||
bulletPrefab,
|
||||
tip.position,
|
||||
@@ -178,7 +273,7 @@ public class Turret : MonoBehaviour
|
||||
if (bullet == null)
|
||||
{
|
||||
Debug.LogError(
|
||||
"TowerShooting: Bullet Prefab besitzt kein TowerBullet-Skript!",
|
||||
"Turret: Bullet Prefab besitzt kein Bullet-Skript!",
|
||||
bulletObject
|
||||
);
|
||||
|
||||
@@ -186,24 +281,76 @@ public class Turret : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
// Abstand zwischen Drehpunkt und Geschützspitze berechnen.
|
||||
float muzzleOffset = Vector2.Distance(
|
||||
turret.position,
|
||||
tip.position
|
||||
);
|
||||
|
||||
// Verbleibende Flugreichweite berechnen.
|
||||
float bulletRange = Mathf.Max(
|
||||
0f,
|
||||
combatStats.range - muzzleOffset
|
||||
);
|
||||
|
||||
bullet.Initialize(
|
||||
tip.up,
|
||||
bulletSpeed,
|
||||
combatStats.damagePerHit,
|
||||
combatStats.range
|
||||
bulletRange,
|
||||
remainingPierce,
|
||||
hitEnemies
|
||||
);
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (towerData == null)
|
||||
return;
|
||||
// Reguläre Angriffsreichweite.
|
||||
if (towerData != null)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(
|
||||
transform.position,
|
||||
towerData.combat.range
|
||||
);
|
||||
}
|
||||
|
||||
Gizmos.DrawWireSphere(
|
||||
transform.position,
|
||||
towerData.combat.range
|
||||
);
|
||||
// Nahbereich und Geschützpositionen.
|
||||
if (turret != null && tip != null)
|
||||
{
|
||||
float radius = Vector2.Distance(
|
||||
turret.position,
|
||||
tip.position
|
||||
);
|
||||
|
||||
// Nahbereichskreis.
|
||||
Gizmos.color = Color.yellow;
|
||||
|
||||
Gizmos.DrawWireSphere(
|
||||
turret.position,
|
||||
radius
|
||||
);
|
||||
|
||||
// Verbindung zwischen Drehpunkt und Spitze.
|
||||
Gizmos.DrawLine(
|
||||
turret.position,
|
||||
tip.position
|
||||
);
|
||||
|
||||
// Drehpunkt markieren.
|
||||
Gizmos.DrawSphere(
|
||||
turret.position,
|
||||
0.07f
|
||||
);
|
||||
|
||||
// Geschützspitze markieren.
|
||||
Gizmos.color = Color.cyan;
|
||||
|
||||
Gizmos.DrawSphere(
|
||||
tip.position,
|
||||
0.09f
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user