Example #1
0
 /// <summary>
 /// Sets the target as the given waypoint.
 /// </summary>
 /// <param name="position">The transform position of the waypoint destination.</param>
 /// <param name="distance">The current distance the AI Entity is from the waypoint.</param>
 public void SetWayPoint(Vector3 position, float distance)
 {
     this.type     = AiTargetType.Waypoint;
     this.collider = null;
     this.position = position;
     this.distance = distance;
     this.timeSeen = Time.time;
 }
Example #2
0
 /// <summary>
 /// Clears all the target values and reset them to a non-tracking state.
 /// </summary>
 public void Clear()
 {
     this.type     = AiTargetType.None;
     this.collider = null;
     this.position = Vector3.zero;
     this.distance = 0.0f;
     this.timeSeen = Mathf.Infinity;
 }
Example #3
0
 /// <summary>
 /// Updates the visual threat.  Because these are private, I learned it passes by value when using getter
 /// and I'll either have to make it public or have this method to set it.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="collider"></param>
 /// <param name="distance"></param>
 public void TrackVisualThreat(AiTargetType type, Collider collider, float distance)
 {
     this.visualThreat.SetTarget(
         type,
         collider,
         collider.transform.position,
         distance
         );
 }
 public static EntityInfo GetHearstTargetHelper(EntityInfo srcObj,float range,CharacterRelation relation, AiTargetType type)
 {
     EntityInfo nearstTarget = null;
     float minPowDist = 999999;
     srcObj.SceneContext.KdTree.Query(srcObj, range, (float distSqr, KdTreeObject kdTreeObj) => {
         StepCalcNearstTarget(srcObj, relation, type, distSqr, kdTreeObj.Object, ref minPowDist, ref nearstTarget);
     });
     return nearstTarget;
 }
Example #5
0
 /// <summary>
 /// Sets the target the given target type..
 /// </summary>
 /// <param name="type">Any type but None</param>
 /// <param name="collider">The collider for the target.</param>
 /// <param name="position">The position of the target.</param>
 /// <param name="distance"></param>
 public void SetTarget(AiTargetType type, Collider collider, Vector3 position, float distance)
 {
     if (type == AiTargetType.None)
     {
         throw new System.ArgumentException("Invalid type; use Clear() to set target type back to None!");
     }
     if (collider == null)
     {
         throw new System.ArgumentException("Invalid collider; it must exist!");
     }
     this.type     = type;
     this.collider = collider;
     this.position = position;
     this.distance = distance;
     this.timeSeen = Time.time;
 }
Example #6
0
 public static EntityInfo GetNearstTargetHelper(EntityInfo srcObj, CharacterRelation relation, AiTargetType type)
 {
     return(GetNearstTargetHelper(srcObj, srcObj.ViewRange, relation, type));
 }
 public static EntityInfo GetNearstTargetHelper(EntityInfo srcObj, CharacterRelation relation, AiTargetType type)
 {
     return GetHearstTargetHelper(srcObj,srcObj.ViewRange,relation,type);
 }
Example #8
0
        private static bool IsWantedTargetForRandomTarget(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type, ISpaceObject obj)
        {
            if (type == AiTargetType.USER && obj.GetObjType() != SpatialObjType.kUser)
            {
                return(false);
            }
            if (type == AiTargetType.NPC && obj.GetObjType() != SpatialObjType.kNPC)
            {
                return(false);
            }
            CharacterInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, (int)obj.GetID());

            if (null != target && !target.IsDead())
            {
                if (target.IsControlMecha)
                {
                    return(false);
                }
                NpcInfo npcTarget = target.CastNpcInfo();
                if (null != npcTarget && npcTarget.NpcType == (int)NpcTypeEnum.Skill)
                {
                    return(false);
                }
                if (relation == CharacterInfo.GetRelation(srcObj, target))
                {
                    if (CanSee(srcObj, target))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        private static void StepCalcNearstTarget(EntityInfo srcObj, CharacterRelation relation, AiTargetType type, float powDist, EntityInfo obj, ref float minPowDist, ref EntityInfo nearstTarget)
        {
            EntityInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, obj.GetId());

            if (null != target && !target.IsDead())
            {
                if (!target.IsTargetNpc())
                {
                    return;
                }
                if (type == AiTargetType.HERO && target.EntityType != (int)EntityTypeEnum.Hero)
                {
                    return;
                }
                if (type == AiTargetType.TOWER && target.EntityType != (int)EntityTypeEnum.Tower)
                {
                    return;
                }
                if (type == AiTargetType.BOSS && target.EntityType != (int)EntityTypeEnum.Boss)
                {
                    return;
                }
                if (type == AiTargetType.NPC && target.EntityType != (int)EntityTypeEnum.Normal)
                {
                    return;
                }
                if (relation == EntityInfo.GetRelation(srcObj, target))
                {
                    if (powDist < minPowDist)
                    {
                        if (powDist > c_MaxViewRangeSqr || CanSee(srcObj, target))
                        {
                            nearstTarget = target;
                            minPowDist   = powDist;
                        }
                    }
                }
            }
        }
Example #10
0
 /// <summary>
 /// Tracks the target using the given values.
 /// </summary>
 public void TrackTarget(AiTargetType type, Collider collider, Vector3 position, float distance, float stoppingDistance)
 {
     this.target.SetTarget(type, collider, position, distance);
     MoveTargetTriggerToTarget(stoppingDistance);
 }
Example #11
0
 /// <summary>
 /// Set the target using the given values, but use the state machine's stoppingDistance value.
 /// </summary>
 public void TrackTarget(AiTargetType type, Collider collider, Vector3 position, float distance)
 {
     this.TrackTarget(type, collider, position, distance, this.stateMachine.StoppingDistance);
 }
Example #12
0
 public bool IsTargeting(AiTargetType type)
 {
     return(this.target.Type == type);
 }
Example #13
0
        public static CharacterInfo GetRandomTargetHelper(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type)
        {
            CharacterInfo target = null;

            DashFireSpatial.ISpatialSystem spatialSys = srcObj.SpatialSystem;
            if (null != spatialSys)
            {
                List <DashFireSpatial.ISpaceObject> objs = spatialSys.GetObjectInCircle(srcObj.GetMovementStateInfo().GetPosition3D(), srcObj.ViewRange, (distSqr, obj) => IsWantedTargetForRandomTarget(srcObj, relation, type, obj));
                int index = Helper.Random.Next(objs.Count);
                if (index >= 0 && index < objs.Count)
                {
                    target = objs[index].RealObject as CharacterInfo;
                }
            }
            return(target);
        }
Example #14
0
        public static CharacterInfo GetInterestestTargetHelper(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type)
        {
            CharacterInfo interestestTarget = null;

            DashFireSpatial.ISpatialSystem spatialSys = srcObj.SpatialSystem;
            if (null != spatialSys)
            {
                ScriptRuntime.Vector3 srcPos = srcObj.GetMovementStateInfo().GetPosition3D();
                float minPowDist             = 999999;
                spatialSys.VisitObjectInCircle(srcPos, srcObj.ViewRange, (float distSqr, ISpaceObject obj) => {
                    GetInterestestTarget(srcObj, relation, type, distSqr, obj, ref minPowDist, ref interestestTarget);
                });
            }
            return(interestestTarget);
        }
Example #15
0
    public static EntityInfo GetNearstTargetHelper(EntityInfo srcObj, float range, CharacterRelation relation, AiTargetType type)
    {
        EntityInfo nearstTarget = null;
        float      minDistSqr   = 999999;

        srcObj.SceneContext.KdTree.QueryWithAction(srcObj, range, (float distSqr, KdTreeObject kdTreeObj) => {
            StepCalcNearstTarget(srcObj, relation, type, distSqr, kdTreeObj.Object, ref minDistSqr, ref nearstTarget);
        });
        return(nearstTarget);
    }
 private static void StepCalcNearstTarget(EntityInfo srcObj, CharacterRelation relation, AiTargetType type, float powDist, EntityInfo obj, ref float minPowDist, ref EntityInfo nearstTarget)
 {
     EntityInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, obj.GetId());
     if (null != target && !target.IsDead()) {
         if (!target.IsTargetNpc()) {
             return;
         }
         if (type == AiTargetType.HERO && target.EntityType != (int)EntityTypeEnum.Hero) {
             return;
         }
         if (type == AiTargetType.TOWER && target.EntityType != (int)EntityTypeEnum.Tower) {
             return;
         }
         if (type == AiTargetType.BOSS && target.EntityType != (int)EntityTypeEnum.Boss) {
             return;
         }
         if (type == AiTargetType.NPC && target.EntityType != (int)EntityTypeEnum.Normal) {
             return;
         }
         if (relation == EntityInfo.GetRelation(srcObj, target)) {
             if (powDist < minPowDist) {
                 if (powDist > c_MaxViewRangeSqr || CanSee(srcObj, target)) {
                     nearstTarget = target;
                     minPowDist = powDist;
                 }
             }
         }
     }
 }
Example #17
0
    private static void StepCalcNearstTarget(EntityInfo srcObj, CharacterRelation relation, AiTargetType type, float distSqr, EntityInfo obj, ref float minDistSqr, ref EntityInfo nearstTarget)
    {
        EntityInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, obj.GetId());

        if (null != target && !target.IsDead())
        {
            if (!target.IsTargetNpc())
            {
                return;
            }
            if (type == AiTargetType.HERO && target.EntityType != (int)EntityTypeEnum.Hero)
            {
                return;
            }
            if (type == AiTargetType.BOSS && target.EntityType != (int)EntityTypeEnum.Boss)
            {
                return;
            }
            if (type == AiTargetType.NPC && target.EntityType != (int)EntityTypeEnum.Normal)
            {
                return;
            }

            if (relation == EntityInfo.GetRelation(srcObj, target))
            {
                if (srcObj.EntityType == (int)EntityTypeEnum.Hero || !srcObj.IsPassive || srcObj.AttackerInfos.ContainsKey(target.GetId()))
                {
                    if (distSqr < minDistSqr)
                    {
                        nearstTarget = target;
                        minDistSqr   = distSqr;
                    }
                }
            }
        }
    }
Example #18
0
        private static void StepCalcNearstTarget(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type, float powDist, ISpaceObject obj, ref float minPowDist, ref CharacterInfo nearstTarget)
        {
            if (type == AiTargetType.USER && obj.GetObjType() != SpatialObjType.kUser)
            {
                return;
            }
            if (type == AiTargetType.NPC && obj.GetObjType() != SpatialObjType.kNPC)
            {
                return;
            }
            CharacterInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, (int)obj.GetID());

            if (null != target && !target.IsDead())
            {
                if (target.IsControlMecha)
                {
                    return;
                }
                NpcInfo npcTarget = target.CastNpcInfo();
                if (null != npcTarget && npcTarget.NpcType == (int)NpcTypeEnum.Skill)
                {
                    return;
                }
                if (relation == CharacterInfo.GetRelation(srcObj, target))
                {
                    if (powDist < minPowDist)
                    {
                        if (powDist > c_MaxViewRangeSqr || CanSee(srcObj, target))
                        {
                            nearstTarget = target;
                            minPowDist   = powDist;
                        }
                    }
                }
            }
        }