Ejemplo n.º 1
0
    protected override void Execute(State currentState, TilemapComponent tilemap)
    {
        if (skillToActivate is AttackSkill)
        {
            source.currentAttackSkill = (AttackSkill)skillToActivate;
            //dialog.PostToDialog("Activated " + skillToActivate.GetType().Name, dialogNoise, false);
        }
        else if (skillToActivate is SelectTilesSkill)
        {
            skillRange = ((SelectTilesSkill)skillToActivate).GetValidTiles(tilemap.grid, source.tile); //tilemap.ActivateSelectTilesSkill(source, (SelectTilesSkill) skillToActivate);
            if (skillRange.Count() != 0)
            {
                // dialog.PostToDialog("Activated " + skillToActivate.GetType().Name, dialogNoise, false);
            }
            else
            {
                // dialog.PostToDialog("Tried to activate " + skillToActivate.GetType().Name + " but there were no valid tiles", dialogNoise, false);
                // tilemap.DeactivateSelectTilesSkill(source);
                var stateData = (AllySelectedState)currentState;

                stateData.attackRange = TilemapComponent.GenerateAttackRange(tilemap.grid, source);
                stateData.moveRange   = TilemapComponent.GenerateMoveRange(tilemap.grid, source);

                TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.attackRange, Tile.HighlightTypes.Attack);
                TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.moveRange, Tile.HighlightTypes.Move);
            }
        }
        else if (skillToActivate is BuffSkill)
        {
            ((BuffSkill)skillToActivate).ResolveEffect(source);
            // dialog.PostToDialog("Activated " + skillToActivate.GetType().Name, dialogNoise, false);
        }
    }
Ejemplo n.º 2
0
 public override State Transition(State currentState, TilemapComponent tilemap, Dialog dialog)
 {
     Execute(currentState, tilemap);
     DisplayInGrid(currentState, tilemap);
     DisplayInDialog(currentState, dialog);
     return(new NoSelectionState());
 }
Ejemplo n.º 3
0
 public override State Transition(State currentState, TilemapComponent tilemap, Dialog dialog)
 {
     Execute(currentState, tilemap);
     DisplayInGrid(currentState, tilemap);
     DisplayInDialog(currentState, dialog);
     return(new TeleportActivatedState(source, validTiles));
 }
Ejemplo n.º 4
0
    protected override void Execute(State currentState, TilemapComponent tilemap)
    {
        var stateData = (AllySelectedState)currentState;

        stateData.attackRange = TilemapComponent.GenerateAttackRange(tilemap.grid, source);
        stateData.moveRange   = TilemapComponent.GenerateMoveRange(tilemap.grid, source);
    }
Ejemplo n.º 5
0
    protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
    {
        if (completed)
        {
            var stateData = (AllySelectedState)currentState;

            TilemapComponent.ClearAllHighlightsFromGrid(tilemap.grid);
            stateData.attackRange = TilemapComponent.GenerateAttackRange(tilemap.grid, source);
            stateData.moveRange   = TilemapComponent.GenerateMoveRange(tilemap.grid, source);
            TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.attackRange, Tile.HighlightTypes.Attack);
            TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.moveRange, Tile.HighlightTypes.Move);
        }
        else
        {
            // selecting a tile
            if (selectedTile.currentHighlights.Contains(Tile.HighlightTypes.Skill))
            {
                selectedTile.currentHighlights.Remove(Tile.HighlightTypes.Skill);
                selectedTile.currentHighlights.Add(Tile.HighlightTypes.SkillSelect);
            }
            // deselecting a tile
            else
            {
                selectedTile.currentHighlights.Remove(Tile.HighlightTypes.SkillSelect);
                selectedTile.currentHighlights.Add(Tile.HighlightTypes.Skill);
            }
        }
    }
Ejemplo n.º 6
0
    protected override void Execute(State currentState, TilemapComponent tilemap)
    {
        var stateData = (SelectSkillActivatedState)currentState;

        // selecting a tile
        if (stateData.validTiles.Contains(selectedTile))
        {
            stateData.selectedTiles.Add(selectedTile);
            stateData.validTiles.Remove(selectedTile);
        }
        // deselecting a tile
        else
        {
            stateData.validTiles.Add(selectedTile);
            stateData.selectedTiles.Remove(selectedTile);
        }

        completed = stateData.selectedTiles.Count == stateData.activeSkill.targets;

        if (completed)
        {
            source.UseSkill(stateData.activeSkill);
            stateData.selectedTiles.ForEach(x => stateData.activeSkill.ResolveEffect(source, x));
        }
    }
Ejemplo n.º 7
0
    protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
    {
        var stateData = (AllySelectedState)currentState;

        source.tile.HighlightAs(Tile.HighlightTypes.SelectedEntity);
        stateData.attackRange.ForEach(x => x.HighlightAs(Tile.HighlightTypes.Attack));
        stateData.moveRange.ForEach(x => x.HighlightAs(Tile.HighlightTypes.Move));
    }
Ejemplo n.º 8
0
 protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
 {
     if (skillToActivate is SelectTilesSkill)
     {
         TilemapComponent.ClearHighlightFromGrid(tilemap.grid, Tile.HighlightTypes.Attack);
         TilemapComponent.ClearHighlightFromGrid(tilemap.grid, Tile.HighlightTypes.Move);
         TilemapComponent.RefreshGridHighlights(tilemap.grid, skillRange, Tile.HighlightTypes.Skill);
     }
 }
Ejemplo n.º 9
0
    protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
    {
        var stateData      = (EnemySelectedState)currentState;
        var normalizedData = Utils.NormalizeDict(stateData.tileScoreMap);

        source.tile.HighlightAs(Tile.HighlightTypes.SelectedEntity);
        normalizedData.Keys.ToList().ForEach(x => x.tile.HighlightAs(Tile.HighlightTypes.Test, (float)normalizedData[x]));
        normalizedData.Keys.OrderBy(x => normalizedData[x]).First().tile.HighlightAs(Tile.HighlightTypes.Move);
    }
Ejemplo n.º 10
0
    public override State Transition(State currentState, TilemapComponent tilemap, Dialog dialog)
    {
        var nextState = new AllySelectedState(source);

        Execute(nextState, tilemap);
        DisplayInGrid(nextState, tilemap);
        DisplayInDialog(nextState, dialog);
        return(nextState);
    }
Ejemplo n.º 11
0
    protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
    {
        var stateData = (AllySelectedState)currentState;

        stateData.attackRange = TilemapComponent.GenerateAttackRange(tilemap.grid, source);
        stateData.moveRange   = TilemapComponent.GenerateMoveRange(tilemap.grid, source);

        TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.attackRange, Tile.HighlightTypes.Attack);
        TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.moveRange, Tile.HighlightTypes.Move);
    }
Ejemplo n.º 12
0
 protected override void Execute(State currentState, TilemapComponent tilemap)
 {
     if (source.currentTeleports >= 0)
     {
         validTiles = GridUtils.FlattenGridTiles(tilemap.grid, true).Where(tile => tile.occupier == null).ToList();
     }
     else
     {
         // dialog.PostToDialog("Tried to teleport but " + source.entityName + " has already teleported this encounter", dialogNoise, false);
     }
 }
Ejemplo n.º 13
0
 protected override void Execute(State currentState, TilemapComponent tilemap)
 {
     if (source.currentAttackSkill != null)
     {
         source.currentAttackSkill.BeforeAttack(source, target);
         source.MakeAttack(target);
         source.currentAttackSkill.AfterAttack(source, target);
     }
     else
     {
         source.MakeAttack(target);
     }
 }
Ejemplo n.º 14
0
 public override State Transition(State currentState, TilemapComponent tilemap, Dialog dialog)
 {
     Execute(currentState, tilemap);
     DisplayInGrid(currentState, tilemap);
     DisplayInDialog(currentState, dialog);
     if (skillToActivate is SelectTilesSkill)
     {
         return(new SelectSkillActivatedState(source, (SelectTilesSkill)skillToActivate, skillRange));
     }
     else
     {
         return(currentState);
     }
 }
Ejemplo n.º 15
0
    protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
    {
        if (skillToDeactivate is SelectTilesSkill)
        {
            var stateData = (AllySelectedState)currentState;

            TilemapComponent.ClearAllHighlightsFromGrid(tilemap.grid);
            stateData.attackRange = TilemapComponent.GenerateAttackRange(tilemap.grid, source);
            stateData.moveRange   = TilemapComponent.GenerateMoveRange(tilemap.grid, source);

            TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.attackRange, Tile.HighlightTypes.Attack);
            TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.moveRange, Tile.HighlightTypes.Move);
        }
    }
Ejemplo n.º 16
0
 protected override void Execute(State currentState, TilemapComponent tilemap)
 {
     if (currentState is EnemyTurnState)
     {
         var stateData = (EnemyTurnState)currentState;
         var nextStep  = stateData.aiSteps.First();
         if (nextStep != null)
         {
             stateData.aiSteps.RemoveAt(0);
             nextStep.ToList().ForEach(behavior => behavior.DoBestAction(tilemap, currentState));
             stateData.stepTaken = nextStep;
         }
     }
 }
Ejemplo n.º 17
0
    public override bool DoBestAction(TilemapComponent tilemap, State currentState)
    {
        var stateData = (EnemyTurnState)currentState;

        Debug.Log(String.Format("{0} chose to do {1} with score of {2}", entity, "Flee", bestAction.Value));

        tilemap.MoveEntity(entity.tile, bestAction.Key.tile);

        if (GridUtils.GetEdgesOfEnabledGrid(tilemap.grid).Contains(bestAction.Key.tile))
        {
            this.entity.RemoveFromGrid();
            stateData.enemies.Remove(this.entity);
        }

        return(true);
    }
Ejemplo n.º 18
0
    public override State Transition(State currentState, TilemapComponent tilemap, Dialog dialog)
    {
        Execute(currentState, tilemap);
        DisplayInGrid(currentState, tilemap);
        DisplayInDialog(currentState, dialog);

        var stateData = (EnemyTurnState)currentState;

        if (stateData.aiSteps.Count == 0)
        {
            // can add new reinforcement / summoning state
            return(new NoSelectionState());
        }
        else
        {
            return(currentState);
        }
    }
Ejemplo n.º 19
0
    public override bool DoBestAction(TilemapComponent tilemap, State currentState)
    {
        var stateData = (EnemyTurnState)currentState;

        if (!(entity.lastSelectedBehavior is EvasiveTeleport))
        {
            Debug.Log(String.Format("{0} chose to do {1} turn 1 with score of {2}", entity, "EvasiveTeleport", bestAction.Value));
            entity.lastSelectedBehavior = this;
            // turn 1 of evasive teleport
        }
        else
        {
            // turn 2 of evasive teleport
            Debug.Log(String.Format("{0} chose to do {1} turn 2 with score of {2}", entity, "EvasiveTeleport", bestAction.Value));
            tilemap.TeleportEntity(entity.tile, bestAction.Key.tile);
            entity.lastSelectedBehavior = null;
        }
        return(true);
    }
Ejemplo n.º 20
0
    public override bool DoBestAction(TilemapComponent tilemap, State currentState)
    {
        Debug.Log(String.Format("{0} chose to do {1} with score of {2}", entity, "RangedAttackV1", bestAction.Value));

        if (bestAction.Key.tile != entity.tile)
        {
            tilemap.MoveEntity(entity.tile, bestAction.Key.tile);
        }

        var attackRange = GridUtils.GenerateTileCircle(tilemap.grid, entity.range, entity.tile).ToList();

        if (attackRange.Contains(bestTarget.tile))
        {
            entity.MakeAttack(bestTarget);
            Debug.Log(String.Format("{0} chose to do {1} with score of {2} against {3}", entity, "RangedAttackV1", bestAction.Value, bestTarget));
        }

        return(true);
    }
Ejemplo n.º 21
0
    protected override void Execute(State currentState, TilemapComponent tilemap)
    {
        if (skillToDeactivate is AttackSkill)
        {
            source.currentAttackSkill = null;
            //dialog.PostToDialog("Activated " + skillToActivate.GetType().Name, dialogNoise, false);
        }
        else if (skillToDeactivate is SelectTilesSkill)
        {
            var stateData = (AllySelectedState)currentState;

            TilemapComponent.ClearHighlightFromGrid(tilemap.grid, Tile.HighlightTypes.Skill);
            stateData.attackRange = TilemapComponent.GenerateAttackRange(tilemap.grid, source);
            stateData.moveRange   = TilemapComponent.GenerateMoveRange(tilemap.grid, source);
            TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.attackRange, Tile.HighlightTypes.Attack);
            TilemapComponent.RefreshGridHighlights(tilemap.grid, stateData.moveRange, Tile.HighlightTypes.Move);
        }
        else if (skillToDeactivate is BuffSkill)
        {
            // do nothing for now
        }
    }
Ejemplo n.º 22
0
    public override bool DoBestAction(TilemapComponent tilemap, State currentState)
    {
        Debug.Log(String.Format("{0} chose to do {1} with score of {2}", entity, "MeleeAttackV1", bestAction.Value));

        if (bestAction.Key.tile != entity.tile)
        {
            tilemap.MoveEntity(entity.tile, bestAction.Key.tile);
        }

        var tileWithTarget = GridUtils.GenerateTileCircle(tilemap.grid, 1, entity.tile)
                             .ToList()
                             .FirstOrDefault(tile =>
                                             tile.occupier != null &&
                                             (tile.occupier.isAllied || tile.occupier.isFriendly) &&
                                             !tile.occupier.outOfHP
                                             );

        if (tileWithTarget != null)
        {
            entity.MakeAttack(tileWithTarget.occupier);
        }
        return(true);
    }
Ejemplo n.º 23
0
    public void DeactivateGrid()
    {
        activated = false;
        waiting   = true;
        GridUtils.FlattenGridTiles(tilemap.grid)
        .Where(tile => !tile.disabled).ToList()
        .ForEach(tile => DeactivateTile(tile));

        TilemapComponent.ClearAllHighlightsFromGrid(tilemap.grid);

        factions.ToList()
        .Where(faction => faction.isHostileFaction).ToList()
        .ForEach(faction => {
            faction.entities
            .Where(entity => entity.outOfHP).ToList()
            .ForEach(entity => {
                var rand = new System.Random();
                GameObject onDeathPrefab = null;
                if (rand.Next(2) == 0)
                {
                    onDeathPrefab = entity.corpse;
                }
                else
                {
                    onDeathPrefab = threadPrefabs.OrderBy(_ => rand.Next()).First();
                }
                Instantiate(onDeathPrefab, entity.transform.position, Quaternion.identity);
            });
        });

        factions.ToList().ForEach(faction => {
            faction.entities.ForEach(entity => entity.RemoveFromGrid());
        });
        factions = new Queue <Faction>();

        skillMenu.SetActive(false);
    }
Ejemplo n.º 24
0
 protected override void Execute(State currentState, TilemapComponent tilemap)
 {
 }
Ejemplo n.º 25
0
 public abstract bool DoBestAction(TilemapComponent tilemap, State currentState);
Ejemplo n.º 26
0
 protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
 {
     TilemapComponent.ClearAllHighlightsFromGrid(tilemap.grid);
 }
Ejemplo n.º 27
0
 protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
 {
     TilemapComponent.ClearAllHighlightsFromGrid(tilemap.grid);
     TilemapComponent.RefreshGridHighlights(tilemap.grid, validTiles, Tile.HighlightTypes.Teleport);
 }
Ejemplo n.º 28
0
 // This is the "Model"
 protected abstract void Execute(State currentState, TilemapComponent tilemap);
Ejemplo n.º 29
0
 protected override void Execute(State currentState, TilemapComponent tilemap)
 {
     currentState.source.UseTeleport();
     tilemap.TeleportEntity(currentState.source.tile, selectedTile);
 }
Ejemplo n.º 30
0
 protected override void DisplayInGrid(State currentState, TilemapComponent tilemap)
 {
 }