Beispiel #1
0
    public static List <Point> GetTiles(CombatMap map, RangeType rangeType, Point position, int maxRange, int minRange = 0)
    {
        List <Point> tiles = new List <Point>();

        // Gather valid tiles
        switch (rangeType)
        {
        case RangeType.distance:
            tiles = GetDistanceTiles(map, position, maxRange, minRange);
            break;

        case RangeType.circle:
            tiles = GetCircleTiles(map, position, maxRange, minRange);
            break;

        case RangeType.square:
            tiles = GetSquareTiles(map, position, maxRange, minRange);
            break;

        case RangeType.line:
            tiles = GetVectorTiles(map, position, lines, maxRange, minRange);
            break;

        case RangeType.diagonal:
            tiles = GetVectorTiles(map, position, diagonals, maxRange, minRange);
            break;
        }

        // Check valid targets

        return(tiles);
    }
Beispiel #2
0
    public void Load(CombatMap map, Unit[] army, Unit[] monsters)
    {
        mapManager = map;
        unitGrid   = new UnitPiece[map.width, map.height];

        for (int i = 0; i < army.Length; i++)
        {
            Unit  unit = Instantiate(army[i]);
            Point pos  = new Point(0, map.height / 2 - 3) + unit.position;
            AddUnit(pos, unit, Faction.Player, i);
        }

        // Create monster deploy area
        // Point monsterOffset = new Point(map.width - 1, map.height / 2 - monsters.Length / 2);
        List <Point> startingPoints = new List <Point>();

        for (int x = map.width - 4; x < map.width; x++)
        {
            for (int y = 1; y < map.height - 1; y++)
            {
                startingPoints.Add(new Point(x, y));
            }
        }

        // Create monsters
        for (int i = 0; i < monsters.Length; i++)
        {
            Unit  unit = Instantiate(monsters[i]);
            Point p    = startingPoints[Random.Range(0, startingPoints.Count)];
            startingPoints.Remove(p);
            // AddUnit(new Point(monsterOffset.x, monsterOffset.y + i), unit, Faction.Monster);
            AddUnit(p, unit, Faction.Monster);
        }
    }
Beispiel #3
0
    public override void Perform(CombatMap map, Point trigger)
    {
        owner.Energy(-cost);
        UnitPiece target = map.unitManager.GetUnit(trigger);

        target.Damage(owner, Random.Range(damage, maxDamage + 1));
    }
Beispiel #4
0
    TargetType IsValidTarget(CombatMap map, Point point)
    {
        switch (canTarget)
        {
        case Target.anything:
            return(TargetType.Valid);

        case Target.creature:
            if (map.unitManager.GetUnit(point) != null)
            {
                return(TargetType.Valid);
            }
            return(TargetType.NotValid);

        case Target.enemy:
            UnitPiece unit = map.unitManager.GetUnit(point);
            if (unit != null && unit.unit.IsEnemy(owner))
            {
                return(TargetType.Valid);
            }
            return(TargetType.NotValid);

        case Target.ally:
            unit = map.unitManager.GetUnit(point);
            if (unit != null && unit.unit.IsFriendly(owner))
            {
                return(TargetType.Valid);
            }
            return(TargetType.NotValid);
        }

        return(TargetType.NotValid);
    }
Beispiel #5
0
    /*==================================================================
    *  MOVES
    * ================================================================*/

    public List <Point> GetMoves(CombatMap map)
    {
        int energyMove  = energy > 0 ? 1 : 0;
        int baseRange   = move + bonusMove;
        int energyRange = baseRange + energyMove;

        // Get valid moves
        List <Point> moves  = PathFinding.GetTiles(map, moveType, position, energyRange, 1);
        List <Point> result = new List <Point>();

        foreach (Point p in moves)
        {
            if (map.unitManager.CanEnter(p))
            {
                result.Add(p);
            }
        }

        // Check energy tiles
        for (int i = 0; i < result.Count; i++)
        {
            Point p        = result[i];
            int   distance = PathFinding.GetDistance(moveType, position, p);
            p.z       = (byte)(distance > baseRange ? 1 : 0);
            result[i] = p;
        }

        return(result);
    }
Beispiel #6
0
        public void InitNodeSet(CombatMap map)
        {
            Width = map.Width;
            Height = map.Height;

            Nodes = new Node[Height, Width];

            BuildNodeSet(map);
        }
Beispiel #7
0
    public override void Perform(CombatMap map, Point trigger)
    {
        owner.Energy(-cost);
        //owner.Armor(value);
        UnitPiece target = map.unitManager.GetUnit(trigger);

        if (target != null)
        {
            target.Effect(attribute, Random.Range(value, maxValue + 1));
        }
    }
Beispiel #8
0
    /*==================================================================
    *  TIME
    * ================================================================*/

    public bool NewRound(CombatMap map, bool firstRound)
    {
        bool triggered = false;

        foreach (Passive passive in passives)
        {
            if (passive != null)
            {
                passive.Tick(firstRound ? Trigger.CombatStart : Trigger.NewRound);
                triggered = true;
            }
        }
        hasActionLeft = true;
        return(triggered);
    }
Beispiel #9
0
    public static List <Point> GetVectorTiles(CombatMap map, Point position, Point[] vectors, int maxRange, int minRange = 0)
    {
        List <Point> tiles = new List <Point>();

        foreach (Point vector in vectors)
        {
            for (int i = minRange; i <= maxRange; i++)
            {
                Point tile = position + vector * i;
                if (map.IsWithinBounds(tile))
                {
                    tiles.Add(tile);
                }
            }
        }

        return(tiles);
    }
Beispiel #10
0
    public List <TargetTile> GetTargets(CombatMap map, bool allTiles = true)
    {
        // Get all tiles
        List <Point> tiles = PathFinding.GetTiles(map, rangeType, owner.position, maxRange, minRange);

        // Filter to valid targets
        List <TargetTile> targetTiles = new List <TargetTile>();

        foreach (Point point in tiles)
        {
            if (allTiles || IsValidTarget(map, point) == TargetType.Valid)
            {
                targetTiles.Add(new TargetTile(point, IsValidTarget(map, point)));
            }
        }

        return(targetTiles);
    }
Beispiel #11
0
    public IEnumerator NewRound(CombatMap map, bool firstRound = false)
    {
        Debug.Log(unit.position + " start");
        isActive = true;

        spriteRenderer.material.color = Color.yellow;
        map.RemoveMarkings();

        if (!firstRound)
        {
            if (unit.hasActionLeft)
            {
                Action            action  = unit.actions[0];
                List <TargetTile> targets = action?.GetTargets(map, false);
                if (targets != null && action.CanUse() && action.GetTargets(map, false).Count > 0)
                {
                    map.Mark(unit.position, Marking.Orange);
                    map.Mark(targets[0].point, Marking.Red);
                    yield return(new WaitForSeconds(.25f));

                    map.unitManager.PerformAction(this, action, targets[0].point);
                    yield return(new WaitForSeconds(.75f));

                    map.RemoveMarkings();
                }
                else if (unit.energy < unit.maxEnergy)
                {
                    Effect(Attribute.Energy, 1);
                    yield return(new WaitForSeconds(.5f));
                }
            }
        }
        spriteRenderer.material.color = Color.white;
        bool triggered = unit.NewRound(map, firstRound);

        if (triggered)
        {
            yield return(new WaitForSeconds(.5f));
        }
        Debug.Log(unit.position + " done");
        isActive = false;
    }
Beispiel #12
0
    public void Load(CombatMap map, string data, string fallen)
    {
        string[] armies      = data.Split(':');
        string[] armyData    = armies[0].Split(',');
        string[] monsterData = armies[1].Split(',');

        mapManager = map;
        unitGrid   = new UnitPiece[map.width, map.height];

        for (int i = 0; i < armyData.Length; i++)
        {
            string[] parts    = armyData[i].Split();
            Unit     baseUnit = Config.GetUnit(parts[0]);
            Unit     unit     = Instantiate(baseUnit);
            unit.name = baseUnit.name;
            unit.Load(parts);
            AddUnit(new Point(unit.position.x, unit.position.y), unit, Faction.Player);
        }

        for (int i = 0; i < monsterData.Length; i++)
        {
            if (monsterData[i].Length < 2)
            {
                continue;
            }
            string[] parts    = monsterData[i].Split();
            Unit     baseUnit = Config.GetUnit(parts[0]);
            Unit     unit     = Instantiate(baseUnit);
            unit.name = baseUnit.name;
            unit.Load(parts);
            AddUnit(new Point(unit.position.x, unit.position.y), unit, Faction.Monster);
        }
        if (fallen.Length > 0)
        {
            foreach (string s in fallen.Split())
            {
                fallenUnits.Add(int.Parse(s));
            }
        }
    }
Beispiel #13
0
    public void MoveTo(CombatMap map, Point target, float moveSpeed = 3f)
    {
        lastMoveOrder  = target;
        this.target    = target.ToVector2();
        this.moveSpeed = moveSpeed;
        unit.MoveTo(map, target);

        if (target.z != 0)
        {
            unit.energy--;
        }

        if (moveSpeed > 0)
        {
            animator.SetBool("Walking", true);
            moving = true;
        }
        else
        {
            transform.localPosition = new Vector2(target.x, target.y);
        }
    }
Beispiel #14
0
    private void InstantiateMap(int mapIndex, double reference, int basicMapIndex, MapType specialMapType)
    {
        BasicMap newMap = Instantiate(possibleMaps[mapIndex], grid.transform) as BasicMap;

        newMap.Initialize(reference, this.OnLoadNextMap, this.OnDestroyMap, this.GoToNextMap, basicMapIndex);

        switch (specialMapType)
        {
        case MapType.COMBAT_BOSS:
            CombatMap combatMap = (CombatMap)newMap;
            combatMap.SetAsBossMap();
            break;

        case MapType.TALKING_TUTORIAL:
            TalkingMap talkingMap = (TalkingMap)newMap;
            talkingMap.SetAsTutorial(basicMapIndex);
            break;
        }

        newMap.gameObject.SetActive(false);
        nextMapsToAdd.Enqueue(newMap);
    }
Beispiel #15
0
    public static List <Point> GetDistanceTiles(CombatMap map, Point position, int maxRange, int minRange = 0)
    {
        List <Point> tiles = new List <Point>();

        for (int x = -maxRange; x <= maxRange; x++)
        {
            for (int y = -maxRange; y <= maxRange; y++)
            {
                int distance = Mathf.Abs(x) + Mathf.Abs(y);
                if (distance < minRange || distance > maxRange)
                {
                    continue;
                }

                Point tile = new Point(x + position.x, y + position.y);
                if (map.IsWithinBounds(tile))
                {
                    tiles.Add(tile);
                }
            }
        }

        return(tiles);
    }
Beispiel #16
0
    public static List <Point> GetSquareTiles(CombatMap map, Point position, int maxRange, int minRange = 0)
    {
        List <Point> tiles = new List <Point>();

        for (int x = -maxRange; x <= maxRange; x++)
        {
            for (int y = -maxRange; y <= maxRange; y++)
            {
                // Skip while inside minRange
                if (Mathf.Abs(x) + Mathf.Abs(y) < minRange)
                {
                    continue;
                }
                // Center on owner and check if tile is within bounds
                Point tile = position + new Point(x, y);
                if (map.IsWithinBounds(tile))
                {
                    tiles.Add(tile);
                }
            }
        }

        return(tiles);
    }
Beispiel #17
0
 public void MoveTo(CombatMap map, Point tile)
 {
     position = tile;
 }
Beispiel #18
0
 public abstract void Perform(CombatMap map, Point trigger);
Beispiel #19
0
 void BuildNodeSet(CombatMap map)
 {
     for (int y = 0; y < Height; ++y)
     {
         for (int x = 0; x < Width; ++x)
         {
             Node node = new Node(new Vector2I(x, y));
             node.SetWalkable(map.Combat.GetCell(x, y).IsUsable());
             SetNode(x, y, node);
         }
     }
 }
Beispiel #20
0
 public List <Point> GetMoves(CombatMap map)
 {
     return(unit.GetMoves(map));
 }
Beispiel #21
0
 // Use this for initialization
 void Start()
 {
     Invoke("ClosePanel", 1.5f);
     PlayerLogic = GameObject.Find("Player").GetComponent <PlayerLogic>();
     combatMap   = GameObject.Find("Forest").GetComponent <CombatMap>();
 }
Beispiel #22
0
 public void SetMap(CombatMap map)
 {
     this.map = map;
 }