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++; }
/* 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); }