public Unit(int x, int y, int level) : base(x, y)
    {
        brain          = new SimpleAI(this);
        Map_position_x = x;
        Map_position_y = y;

        if (level < 0)
        {
            level = 0;
        }

        Max_Health = level - ((float)level) / 1.2f + 1;
        if (Max_Health < 0)
        {
            Max_Health = 1;
        }
        Health = Max_Health;
        Money  = level / 2;
        if (Money < 1)
        {
            Money = 12;
        }
        name = MainColour.ToString() + " unit";

        MainSpell = SpellGenerator.GetInstance().GetClosestSingleSpell(level / 4);
        Debug.Log("enemy hp: " + Max_Health + MainSpell.ToString());
    }
    public void logic_tick()
    {
        //flush buffered spells
        BufferedSpells = new List <Spell>();
        int castRange = MainSpell.CastRange;

        if (RechargeTime >= MaxRechargeTime)
        {
            for (int i = -castRange; i <= castRange; i++)
            {
                for (int j = castRange - Mathf.Abs(i); j >= -(castRange - Mathf.Abs(i)); j--)
                {
                    if (!MapTools.IsOutOfBounds(Map_position_x + i, Map_position_y + j) && GameTools.Map.map_unit_occupy[Map_position_x + i, Map_position_y + j] != null)
                    {
                        MainSpell.loadInfo(new int[2] {
                            Map_position_x, Map_position_y
                        },
                                           new int[2] {
                            Map_position_x + i, Map_position_y + j
                        });
                        ProjectileManager.getInstance().queueProjectile(MainSpell, game_object.transform.position,
                                                                        GameTools.Map.map_unit_occupy[Map_position_x + i, Map_position_y + j].game_object.transform.position);
                        RechargeTime = 0;
                        i            = castRange + 1;
                        j            = castRange + 1;
                        break;
                    }
                }
            }
        }
        RechargeTime++;
    }
Exemplo n.º 3
0
 private new bool CastMainSpell()
 {
     base.CastMainSpell();
     MainSpell.cast(new int[2] {
         Map_position_x, Map_position_y
     },
                    new int[2] {
         GameTools.Mouse.Pos_x, GameTools.Mouse.Pos_z
     });
     playerAnimation.SetBool("Cast", true);
     castedSpell = true;
     deckManager.popTopSpell();
     ReloadSpell();
     return(true);
 }
    /* Maybe make the unit search for a valid target before shooting, as opposed to always shooting at the player */
    public override void CastMainSpell()
    {
        base.CastMainSpell();
        /* new animation */

        if (GraphSearch
            .fromPosition(Map_position_x, Map_position_y)
            .manhattanDistanceFromTarget(GameTools.Player.Map_position_x, GameTools.Player.Map_position_y) <= MainSpell.CastRange)
        {
            MainSpell.loadInfo(new int[2] {
                Map_position_x, Map_position_y
            },
                               new int[2] {
                GameTools.Player.Map_position_x, GameTools.Player.Map_position_y
            });
            ProjectileManager.getInstance().queueProjectile(MainSpell, game_object.transform.position, GameTools.Player.game_object.transform.position);
        }
        else if (GraphSearch
                 .fromPosition(Map_position_x, Map_position_y)
                 .manhattanDistanceFromTarget(GameTools.Base.Map_position_x, GameTools.Base.Map_position_y) <= MainSpell.CastRange)
        {
            MainSpell.loadInfo(new int[2] {
                Map_position_x, Map_position_y
            },
                               new int[2] {
                GameTools.Base.Map_position_x, GameTools.Base.Map_position_y
            });
            ProjectileManager.getInstance().queueProjectile(MainSpell, game_object.transform.position, GameTools.Base.game_object.transform.position);
        }
        else
        {
            Debug.LogError("Not in either range");
        }

        enemyAnimation.SetBool("Cast", true);
    }