Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ public override bool Start()
bool wasAnticipated = Anticipated;
base.Start();
m_Target = GetTarget();
if (HasTarget() && m_Target == null)
{
// target has disappeared! Abort.
return false;
}

if (Description.Projectiles.Length < 1 || Description.Projectiles[0].ProjectilePrefab == null)
throw new System.Exception($"Action {Description.ActionTypeEnum} has no valid ProjectileInfo!");

// animate shooting the projectile
if( !wasAnticipated )
if (!wasAnticipated)
{
PlayFireAnim();
}
Expand All @@ -56,7 +51,7 @@ public override bool Update()
if (TimeRunning >= Description.ExecTimeSeconds && m_Projectile == null)
{
// figure out how long the pretend-projectile will be flying to the target
Vector3 targetPos = HasTarget() ? m_Target.transform.position : m_Data.Position;
Vector3 targetPos = m_Target ? m_Target.transform.position : m_Data.Position;
float initialDistance = Vector3.Distance(targetPos, m_Parent.transform.position);
m_ProjectileDuration = initialDistance / Description.Projectiles[0].Speed_m_s;

Expand Down Expand Up @@ -100,25 +95,23 @@ private void PlayHitReact()
}
}

/// <summary>
/// Do we even have a target? (If false, it means player clicked on nothing, and we're rendering a "missed" fake bolt.)
/// </summary>
private bool HasTarget()
{
return Data.TargetIds != null && Data.TargetIds.Length > 0;
}

private NetworkObject GetTarget()
{
if (Data.TargetIds == null || Data.TargetIds.Length == 0)
{
return null;
}

NetworkObject obj;
if (NetworkSpawnManager.SpawnedObjects.TryGetValue(Data.TargetIds[0], out obj) && obj != null)
if (NetworkSpawnManager.SpawnedObjects.TryGetValue(Data.TargetIds[0], out NetworkObject targetObject) && targetObject != null)
{
return obj;
// make sure this isn't a friend (or if it is, make sure this is a friendly-fire action)
var targetable = targetObject.GetComponent<ITargetable>();
if (targetable != null && targetable.IsNpc == (Description.IsFriendly ^ IsParentAnNPC()))
{
// not a valid target
return null;
}
return targetObject;
}
else
{
Expand All @@ -128,6 +121,16 @@ private NetworkObject GetTarget()
}
}

/// <summary>
/// Determines if the character playing this Action is an NPC (as opposed to a player)
/// </summary>
private bool IsParentAnNPC()
{
var targetable = m_Parent.Parent.GetComponent<ITargetable>();
return targetable.IsNpc;
}


private FXProjectile SpawnAndInitializeProjectile()
{
GameObject projectileGO = Object.Instantiate(Description.Projectiles[0].ProjectilePrefab, m_Parent.transform.position, m_Parent.transform.rotation, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private void PopulateSkillRequest(Vector3 hitPoint, ActionType action, ref Actio
resultData.CancelMovement = true;
return;
case ActionLogic.RangedFXTargeted:
if (resultData.TargetIds == null) { resultData.Position = hitPoint; }
resultData.Position = hitPoint;
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ public FXProjectileTargetedAction(ServerCharacter parent, ref ActionRequestData
public override bool Start()
{
m_Target = GetTarget();
if (m_Target == null && HasTarget())
{
// target has disappeared! Abort.
return false;
}

// figure out where the player wants us to aim at...
Vector3 targetPos = HasTarget() ? m_Target.transform.position : m_Data.Position;
Vector3 targetPos = m_Target != null ? m_Target.transform.position : m_Data.Position;

// then make sure we can actually see that point!
if (!ActionUtils.HasLineOfSight(m_Parent.transform.position, targetPos, out Vector3 collidePos))
Expand Down Expand Up @@ -76,14 +71,6 @@ public override void Cancel()
}
}

/// <summary>
/// Are we even supposed to have a target? (If not, we're representing a "missed" bolt that just hits nothing.)
/// </summary>
private bool HasTarget()
{
return Data.TargetIds != null && Data.TargetIds.Length > 0;
}

/// <summary>
/// Returns our intended target, or null if not found/no target.
/// </summary>
Expand All @@ -97,6 +84,13 @@ private IDamageable GetTarget()
NetworkObject obj;
if (NetworkSpawnManager.SpawnedObjects.TryGetValue(Data.TargetIds[0], out obj) && obj != null)
{
// make sure this isn't a friend (or if it is, make sure this is a friendly-fire action)
var serverChar = obj.GetComponent<ServerCharacter>();
if (serverChar && serverChar.IsNpc == (Description.IsFriendly ^ m_Parent.IsNpc))
{
// not a valid target
return null;
}
return obj.GetComponent<IDamageable>();
}
else
Expand Down