コード例 #1
0
ファイル: RadialTargeter.cs プロジェクト: psywombats/7drl2019
    protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result)
    {
        Func <Vector2Int, bool> rangeRule = (Vector2Int loc) => {
            return(Vector2Int.Distance(loc, actor.location) <= radius);
        };

        Vector2Int origin = new Vector2Int(
            (int)actorEvent.positionPx.x - Mathf.CeilToInt(radius),
            (int)actorEvent.positionPx.z - Mathf.CeilToInt(radius));

        SelectionGrid grid = battle.SpawnSelectionGrid();

        grid.ConfigureNewGrid(actor.location, Mathf.CeilToInt(radius), map.terrain, rangeRule, rangeRule);

        Result <Vector2Int> locResult = new Result <Vector2Int>();

        battle.SpawnCursor(actor.location);
        yield return(battle.cursor.AwaitSelectionRoutine(locResult, _ => true, null, loc => {
            return loc == actor.location;
        }));

        battle.DespawnCursor();
        Destroy(grid.gameObject);

        if (locResult.canceled)
        {
            result.Cancel();
        }
        else
        {
            List <Vector2Int> cells = new List <Vector2Int>();
            int r = Mathf.CeilToInt(radius);
            for (int y = locResult.value.y - r; y <= locResult.value.y + r; y += 1)
            {
                for (int x = locResult.value.x - r; x <= locResult.value.x + r; x += 1)
                {
                    Vector2Int cell = new Vector2Int(x, y);
                    if (DefaultSelectRule(effect)(cell))
                    {
                        cells.Add(cell);
                    }
                }
            }
            yield return(effect.ExecuteCellsRoutine(cells));

            result.value = true;
        }
    }
コード例 #2
0
 public override IEnumerator TryAIUse(AIController ai, Effector effect)
 {
     // 7drl hack
     if (Vector2Int.Distance(actor.location, ai.pc.location) < range &&
         battler.CanSeeLocation(map.terrain, ai.pc.location))
     {
         battle.Log(actor + " cast " + skill.skillName + "!");
         return(effect.ExecuteCellsRoutine(new List <Vector2Int>()
         {
             ai.pc.location
         }));
     }
     else
     {
         return(null);
     }
 }
コード例 #3
0
ファイル: RayTargeter.cs プロジェクト: psywombats/7drl2019
 public override IEnumerator TryAIUse(AIController ai, Effector effect)
 {
     if (Vector2Int.Distance(actor.location, ai.pc.location) < range)
     {
         foreach (Vector2Int v2 in map.PointsAlongPath(actor.location, ai.pc.location))
         {
             BattleEvent ev2 = map.GetEventAt <BattleEvent>(v2);
             if (ev2 != actor.battler && ev2 != null && ev2 != ai.pc.battler)
             {
                 return(null);
             }
         }
         return(effect.ExecuteCellsRoutine(new List <Vector2Int>()
         {
             ai.pc.location
         }));
     }
     else
     {
         return(null);
     }
 }
コード例 #4
0
ファイル: RayTargeter.cs プロジェクト: psywombats/7drl2019
    protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result)
    {
        Cursor        cursor = battle.SpawnCursor(actor.location);
        SelectionGrid grid   = battle.SpawnSelectionGrid();

        Func <Vector2Int, bool> selectRule = (Vector2Int v) => { return(IsSelected(effect, v)); };
        Func <Vector2Int, bool> rangeRule  = (Vector2Int v) => {
            Vector2Int otherLoc = battle.cursor.GetComponent <MapEvent>().location;
            return(map.PointsAlongPath(actor.location, otherLoc).Contains(v));
        };
        Func <Vector2Int, IEnumerator> scanner = (Vector2Int loc) => {
            grid.ConfigureNewGrid(actor.location, range, map.terrain, rangeRule, selectRule);
            return(null);
        };

        if (effect.TargetsHostiles())
        {
            float      minDist  = float.MaxValue;
            BattleUnit bestUnit = null;
            foreach (BattleUnit unit in battle.units)
            {
                float dist = Vector2Int.Distance(unit.location, actor.location);
                cursor.GetComponent <MapEvent>().SetLocation(unit.location);
                if (unit.align != actor.align && dist < minDist && selectRule(unit.location))
                {
                    bestUnit = unit;
                    minDist  = dist;
                }
            }
            if (bestUnit != null)
            {
                cursor.GetComponent <MapEvent>().SetLocation(bestUnit.location);
            }
        }

        Func <Vector2Int, bool> constrainer = loc => Vector2.Distance(loc, actor.location) <= range;

        grid.ConfigureNewGrid(actor.location, range, map.terrain, rangeRule, selectRule);

        Result <Vector2Int> locResult = new Result <Vector2Int>();

        yield return(battle.cursor.AwaitSelectionRoutine(locResult, selectRule, scanner, constrainer));

        battle.DespawnCursor();
        Destroy(grid.gameObject);

        if (locResult.canceled)
        {
            result.Cancel();
        }
        else
        {
            List <Vector2Int> cells = new List <Vector2Int>();
            if (penetrates)
            {
                foreach (Vector2Int v in map.PointsAlongPath(actor.location, locResult.value))
                {
                    if (map.terrain.HeightAt(v) == map.terrain.HeightAt(actor.location))
                    {
                        cells.Add(v);
                    }
                }
            }
            else
            {
                cells.Add(locResult.value);
            }

            yield return(effect.ExecuteCellsRoutine(cells));

            result.value = true;
        }
    }
コード例 #5
0
    protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result)
    {
        Cursor        cursor = battle.SpawnCursor(actor.location);
        SelectionGrid grid   = battle.SpawnSelectionGrid();

        Func <Vector2Int, bool>        selectRule;
        Func <Vector2Int, IEnumerator> scanner   = null;
        Func <Vector2Int, bool>        rangeRule = (Vector2Int loc) => {
            return(Vector2Int.Distance(loc, actor.location) <= range);
        };

        if (radius > 0)
        {
            selectRule = (Vector2Int loc) => {
                return(Vector2Int.Distance(cursor.GetComponent <MapEvent>().location, loc) <= radius);
            };
        }
        else
        {
            selectRule = DefaultSelectRule(effect);
        }
        scanner = (Vector2Int loc) => {
            grid.ConfigureNewGrid(actor.location, range + Mathf.CeilToInt(radius),
                                  map.terrain, rangeRule, selectRule);
            return(null);
        };

        if (effect.TargetsHostiles())
        {
            float      minDist  = float.MaxValue;
            BattleUnit bestUnit = null;
            foreach (BattleUnit unit in battle.units)
            {
                float dist = Vector2Int.Distance(unit.location, actor.location);
                if (unit.align != actor.align && dist < minDist && selectRule(unit.location))
                {
                    bestUnit = unit;
                    minDist  = dist;
                }
            }
            if (bestUnit != null)
            {
                cursor.GetComponent <MapEvent>().SetLocation(bestUnit.location);
            }
        }

        Vector2Int origin = new Vector2Int(
            (int)actorEvent.positionPx.x - (range + Mathf.CeilToInt(radius) - 1),
            (int)actorEvent.positionPx.z - (range + Mathf.CeilToInt(radius) - 1));

        Func <Vector2Int, bool> constrainer = loc => Vector2.Distance(loc, actor.location) <= range;

        grid.ConfigureNewGrid(actor.location, range, map.terrain, rangeRule, selectRule);

        Result <Vector2Int> locResult = new Result <Vector2Int>();

        yield return(battle.cursor.AwaitSelectionRoutine(locResult, _ => true, scanner, constrainer));

        battle.DespawnCursor();
        Destroy(grid.gameObject);

        if (locResult.canceled)
        {
            result.Cancel();
        }
        else
        {
            List <Vector2Int> cells = new List <Vector2Int>();
            int r = Mathf.CeilToInt(radius);
            for (int y = locResult.value.y - r; y <= locResult.value.y + r; y += 1)
            {
                for (int x = locResult.value.x - r; x <= locResult.value.x + r; x += 1)
                {
                    Vector2Int cell = new Vector2Int(x, y);
                    if (Vector2Int.Distance(cell, locResult.value) <= radius)
                    {
                        cells.Add(cell);
                    }
                }
            }
            yield return(effect.ExecuteCellsRoutine(cells));

            result.value = true;
        }
    }