| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- -- helper function for ai
- Battle.in_front_row = function( self )
- return self.row == Battle.Row.FRONT
- end
- Battle.get_random_enemy_as_target = function( self )
- local target = {}
- local enemy = Battle.Type.ENEMY
- local number = EntityContainer.BattleLogic.enemy_number
- if self.unit_type == Battle.Type.ENEMY then
- enemy = Battle.Type.ALLY
- number = EntityContainer.BattleLogic.ally_number
- end
- local random_id = math.random( 1, number )
- local current_id = 1;
- for key, value in pairs( EntityContainer ) do
- if value.unit_type == enemy then
- if random_id == current_id then
- target[ 1 ] = value
- end
- current_id = current_id + 1
- end
- end
- return target
- end;
- Battle.add_command = function( self, target, action, attack )
- local command = {
- self = self,
- target = target,
- action = action,
- attack = attack,
- }
- -- temporary hack
- local priority = 0
- if EntityContainer.BattleLogic.command_queue[ priority ] == nil then
- EntityContainer.BattleLogic.command_queue[ priority ] = {}
- end
- table.insert( EntityContainer.BattleLogic.command_queue[ priority ], command )
- end;
- --[[
- function is_all_enemy_in_front_row()
- if table.getn(fighters_enemy) ~= 0 then
- for i, fighter in pairs(fighters_enemy) do
- if fighter.data.row > 0 then
- return false;
- end;
- end;
- return true;
- end;
- return false;
- end;
- function is_all_enemy_in_back_row()
- if table.getn(fighters_enemy) ~= 0 then
- for i, fighter in pairs(fighters_enemy) do
- if fighter.data.row == 0 then
- return false;
- end;
- end;
- return true;
- end;
- return false;
- end;
- function is_all_ally_in_front_row()
- if table.getn(fighters_ally) ~= 0 then
- for i, fighter in pairs(fighters_ally) do
- if fighter.data.row > 0 then
- return false;
- end;
- end;
- return true;
- end;
- return false;
- end;
- function is_all_ally_in_back_row()
- if table.getn(fighters_ally) ~= 0 then
- for i, fighter in pairs(fighters_ally) do
- if fighter.data.row == 0 then
- return false;
- end;
- end;
- return true;
- end;
- return false;
- end;
- function set_self_as_target()
- -- clear targer
- fighters_target = {};
- fighters_target[1] = fighter_self;
- end;
- function set_random_ally_as_target()
- -- clear targer
- fighters_target = {};
- if table.getn(fighters_ally) ~= 0 then
- fighters_target[1] = fighters_ally[math.random(1, table.getn(fighters_ally))];
- end;
- end;
- ]]
|