/// <summary> /// We check through the AI's Memory and get a list /// of all the targets that were in it. The one /// who is closest to this AI will become the new target. /// </summary> public void UpdateTarget() { if (canTarget) { //TODO: Finalize Attacking Multiple People this.attackTargets.Clear(); float closestTarget = float.MaxValue; //Needs tweeking, initial value doesnt matter //myCurrentTarget = null; // List<Transform> percievedTargets = new List<Transform>(); if (myOwner.GetMyPerception().GetRecentPercievedTargets() != null) { percievedTargets = myOwner.GetMyPerception().GetRecentPercievedTargets(); if (percievedTargets.Count == 0) { this.myCurrentTarget = null; this.myOwner.MyTarget = null; //this.myOwner.MyTarget = myCurrentTarget.gameObj; } if (percievedTargets.Count == 1) { this.myCurrentTarget = percievedTargets[0]; this.myOwner.MyTarget = myCurrentTarget.myGameObject; } else { for (int i = 0; i <= percievedTargets.Count - 1; i++) { if (percievedTargets[i].myTransform != this.myTransform) { //Getting the distnace between the target and the AI float distance = Vector3.Distance(percievedTargets[i].myTransform.position, myTransform.position); //If the distance between the two is below the previously closest target //then set that as the newest target if (distance < closestTarget) { closestTarget = distance; myCurrentTarget = percievedTargets[i]; this.myOwner.MyTarget = myCurrentTarget.myGameObject; //TODO: Finalize Attacking Multiple People if (attackTargets.Count - 1 <= targetCap && !attackTargets.Contains(percievedTargets[i].myGameObject)) attackTargets.Add(percievedTargets[i].myGameObject); } } } } } } }
public override void ApplyEffect() { // get the base stat value of the user of this effect int baseValue = 0; if (StatBase != "") // prevents people forgetting to give a stat base name { IHasStats owner = Source.GetOwner().GetComponent <IHasStats>(); if (owner != null) { owner.TryGetStatValue(StatBase, out baseValue); // prevents the case where the statname doesn't exist } } // get source as a targettable source IHasTargetEffects targetSource = Source as IHasTargetEffects; if (targetSource == null) { return; } // get source owner IHasPerception perceptionOwner = Source.GetOwner().GetComponent <IHasPerception>(); if (perceptionOwner == null) { return; } // for each found percept, if the tag is inside the target type mask, process foreach (var percept in perceptionOwner.Perception.Percepts.Values) { IPerceivable perceivable = percept.Entity.GetComponent <IPerceivable>(); if (perceivable != null && ((perceivable.Tag & TargetType) != 0) && (Vector3.Magnitude(percept.Entity.transform.position - targetSource.GetTarget().transform.position) <= Radius)) { if (percept.Entity != targetSource.GetTarget() || IncludeTarget) { IHasStats target = percept.Entity.GetComponent <IHasStats> (); if (target != null) { target.ModifyStat(TargetStat, Modifier, FlatValue, baseValue); } } } } }
public override void ApplyEffect() { Debug.Log("applying room wide stat effect"); // get the base stat value of the user of this effect int baseValue = 0; if (StatBase != "") // prevents people forgetting to give a stat base name { IHasStats owner = Source.GetOwner().GetComponent <IHasStats>(); if (owner != null) { owner.TryGetStatValue(StatBase, out baseValue); // prevents the case where the statname doesn't exist } } // if the owner doesn't have a perception component, it sees nothing basically, nothing can be affected IHasPerception perceptionOwner = Source.GetOwner().GetComponent <IHasPerception>(); if (perceptionOwner == null) { return; } // for each found percept, if the tag is inside the target type mask, process foreach (var percept in perceptionOwner.Perception.Percepts.Values) { IPerceivable perceivable = percept.Entity.GetComponent <IPerceivable>(); if (perceivable != null && ((perceivable.Tag & TargetType) != 0)) { if (percept.Entity != Source.GetOwner() || IncludeSelf) { // this effect should only apply to perceivable that has stats component IHasStats target = percept.Entity.GetComponent <IHasStats> (); if (target != null) { target.ModifyStat(TargetStat, Modifier, FlatValue, baseValue); } } } } }
/// <summary> /// the function called when a perception event is received /// </summary> void Perceived(Hashtable param) { if (!param.ContainsKey("OBJECT")) { return; } GameObject perceivedObject = (GameObject)(param ["OBJECT"]); Percept percept; if (Percepts.TryGetValue(perceivedObject.GetInstanceID(), out percept)) { Percepts [perceivedObject.GetInstanceID()].Entity = perceivedObject; } else { IPerceivable perceivable = perceivedObject.GetComponent <IPerceivable> (); if (perceivable != null) { Percepts.Add(perceivedObject.GetInstanceID(), new Percept(perceivedObject, 0)); } } }
void Awake() { this.myTransform = this.GetComponentInParent<Living>().transform; this.myOwner = this.myTransform.GetComponent<IPerceivable>(); }
void LeftRadius(IPerceivable perceivable) { if (occlusionType == OcclusionType.Computational && perceivable.canUpdateAI) { if (perceivable.myGameObject.activeSelf && perceivable.myGameInstance == myGameInstance) { perceivable.UpdateValues(-1, -1, -1, -1); } } else if (occlusionType == OcclusionType.Visual && perceivable.cullable) { perceivable.StartCulling(); } }
void EnterRadius(IPerceivable perceivable) { if (occlusionType == OcclusionType.Computational && perceivable.canUpdateAI) { if (perceivable.myGameObject.activeSelf && perceivable.myGameInstance == myGameInstance) { perceivable.UpdateValues(aiUpdates.thinkTime, aiUpdates.targetTime, aiUpdates.perceptionTime, aiUpdates.attackTime); } } else if (occlusionType == OcclusionType.Visual && perceivable.cullable) { perceivable.StopCulling(); } }