/// <summary> /// Loops through all the Options of the minion. The action has 4 useful parameters to use. /// The first parameter refers to the Option/Multiple itself. It is a GameObject. /// The second parameter refers to the OptionBehavior component in the Option/Multiple. /// The third parameter refers to the target of the Option/Multiple owner. It is also a GameObject. /// The last parameter refers to the direction from the option to the target. It is a normalized Vector3. /// </summary> /// <param name="optionOwner">The owner of the option.</param> /// <param name="actionToRun">An action to execute for each Option. The inputs are as follows: /// GameObject option, OptionBehavior behavior, GameObject target, Vector3 direction.</param> public void FireForAllOptions(CharacterBody optionOwner, Action <GameObject, OptionBehavior, GameObject, Vector3> actionToRun) { if (!optionOwner) { return; } OptionTracker optionTracker = optionOwner.GetComponent <OptionTracker>(); if (!optionTracker) { return; } GameObject target = null; GameObject masterObject = optionOwner.masterObject; if (masterObject) { BaseAI ai = masterObject.GetComponent <BaseAI>(); BaseAI.Target mainTarget = ai.currentEnemy; if (mainTarget != null && mainTarget.gameObject) { target = mainTarget.gameObject; } } foreach (GameObject option in optionTracker.existingOptions) { OptionBehavior behavior = option.GetComponent <OptionBehavior>(); if (behavior) { Vector3 direction; if (target) { direction = (target.transform.position - option.transform.position).normalized; if (includeModelInsideOrb) { behavior.target = target; NetworkIdentity targetNetworkIdentity = target.GetComponent <NetworkIdentity>(); if (targetNetworkIdentity) { OptionSync(optionOwner, (networkIdentity, nullTracker) => { optionTracker.targetIds.Add(Tuple.Create( GameObjectType.Body, networkIdentity.netId, (short)behavior.numbering, targetNetworkIdentity.netId )); }, false); } } } else { direction = optionOwner.inputBank.GetAimRay().direction.normalized; } actionToRun(option, behavior, target, direction); } } }
private void SetTarget(OptionTracker tracker, GameObject target) { GameObject option = tracker.existingOptions[numbering - 1]; OptionBehavior behavior = option.GetComponent <OptionBehavior>(); if (!behavior) { return; } behavior.target = target; }
public void OnReceived() { if (NetworkServer.active) { return; } GameObject ownerObject = Util.FindNetworkObject(ownerId); if (!ownerObject) { Log.Warning("SyncOptionTargetForClients: ownerObject is null."); return; } GameObject targetObject = Util.FindNetworkObject(targetId); if (!targetObject) { Log.Warning("SyncOptionTargetForClients: targetObject is null."); return; } OptionTracker tracker = null; switch (bodyOrMaster) { case GameObjectType.Body: tracker = ownerObject.GetComponent <OptionTracker>(); break; case GameObjectType.Master: CharacterMaster ownerMaster = ownerObject.GetComponent <CharacterMaster>(); if (!ownerMaster) { Log.Warning("SpawnOptionsForClients: ownerMaster is null."); return; } GameObject bodyObject = ownerMaster.GetBodyObject(); if (!bodyObject) { Log.Warning("SpawnOptionsForClients: bodyObject is null."); return; } tracker = bodyObject.GetComponent <OptionTracker>(); break; } if (!tracker) { return; } SetTarget(tracker, targetObject); }
/// <summary> /// Method that provides the Network Identity and Option Tracker for easier syncing. Sync logic should be provided in actionToRun. /// </summary> /// <param name="optionOwner">The owner of the option.</param> /// <param name="actionToRun">The sync action to perform. Inputs are as follows: NetworkIdentity optionIdentity, OptionTracker tracker.</param> /// <param name="queryTracker">If true, the Option tracker is automatically queried. If false, the Option tracker will not be queried.</param> public void OptionSync(CharacterBody optionOwner, Action <NetworkIdentity, OptionTracker> actionToRun, bool queryTracker = true) { if (!NetworkServer.active) { return; } NetworkIdentity networkIdentity = optionOwner.gameObject.GetComponent <NetworkIdentity>(); if (!networkIdentity) { return; } OptionTracker tracker = null; if (queryTracker) { tracker = optionOwner.gameObject.GetComponent <OptionTracker>(); } if (!queryTracker || tracker) { actionToRun(networkIdentity, tracker); } }