예제 #1
0
    /// <summary>
    /// 查找最远的目标列表
    /// </summary>
    /// <param name="sourceType">源的类型</param>
    /// <param name="sourceGrid">源的格子数据</param>
    /// <param name="count">查找数量</param>
    /// <param name="effectTarget">查找阵营</param>
    /// <returns>找到的目标列表</returns>
    public List <ActorBevBase> FindFar(ActorType sourceType, GridData sourceGrid, byte count, EffectTargetType effectTarget)
    {
        List <ActorBevBase> findList = this.GetFindList(sourceType, effectTarget);

        if (findList == null || findList.Count == 0)
        {
            return(null);
        }
        if (findList.Count <= count)
        {
            return(findList);
        }
        List <ActorBevBase> targetList = new List <ActorBevBase>();

        if (effectTarget == EffectTargetType.Rival)
        {
            for (byte i = 0; i < count; i++)
            {
                ActorBevBase target = null;
                foreach (var tmpTarget in findList)
                {
                    if (target == null)
                    {
                        target = tmpTarget;
                    }
                    else
                    {
                        if (tmpTarget.GridData.ZGrid > target.GridData.ZGrid)
                        {
                            target = tmpTarget;
                        }
                        else if (tmpTarget.GridData.ZGrid == target.GridData.ZGrid &&
                                 Mathf.Abs(tmpTarget.GridData.XGrid - sourceGrid.XGrid) <= Mathf.Abs(tmpTarget.GridData.XGrid - sourceGrid.XGrid) &&
                                 tmpTarget.GridData.XGrid < target.GridData.XGrid)
                        {
                            target = tmpTarget;
                        }
                    }
                }
                findList.Remove(target);
                targetList.Add(target);
            }
        }
        else if (effectTarget == EffectTargetType.Friend)
        {
            for (byte i = 0; i < count; i++)
            {
                ActorBevBase target      = null;
                byte         maxDistance = byte.MaxValue;
                for (byte j = 0; j < findList.Count; j++)
                {
                    ActorBevBase tmpTarget = findList[j];
                    byte         distance  = sourceGrid.CalculateDistanceMagnitude(tmpTarget.GridData);
                    if (target == null)
                    {
                        target      = tmpTarget;
                        maxDistance = distance;
                    }
                    else
                    {
                        if (distance > maxDistance)
                        {
                            target      = tmpTarget;
                            maxDistance = distance;
                        }
                        else if (distance == maxDistance && tmpTarget.Index > target.Index)
                        {
                            target      = tmpTarget;
                            maxDistance = distance;
                        }
                    }
                }
                findList.Remove(target);
                targetList.Add(target);
            }
        }
        return(targetList);
    }