battle_ai.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. -- helper function for ai
  2. Battle.in_front_row = function( self )
  3. return self.row == Battle.Row.FRONT
  4. end
  5. Battle.get_random_enemy_as_target = function( self )
  6. local target = {}
  7. local enemy = Battle.Type.ENEMY
  8. local number = EntityContainer.BattleLogic.enemy_number
  9. if self.unit_type == Battle.Type.ENEMY then
  10. enemy = Battle.Type.ALLY
  11. number = EntityContainer.BattleLogic.ally_number
  12. end
  13. local random_id = math.random( 1, number )
  14. local current_id = 1;
  15. for key, value in pairs( EntityContainer ) do
  16. if value.unit_type == enemy then
  17. if random_id == current_id then
  18. target[ 1 ] = value
  19. end
  20. current_id = current_id + 1
  21. end
  22. end
  23. return target
  24. end;
  25. Battle.add_command = function( self, target, action, attack )
  26. local command = {
  27. self = self,
  28. target = target,
  29. action = action,
  30. attack = attack,
  31. }
  32. -- temporary hack
  33. local priority = 0
  34. if EntityContainer.BattleLogic.command_queue[ priority ] == nil then
  35. EntityContainer.BattleLogic.command_queue[ priority ] = {}
  36. end
  37. table.insert( EntityContainer.BattleLogic.command_queue[ priority ], command )
  38. end;
  39. --[[
  40. function is_all_enemy_in_front_row()
  41. if table.getn(fighters_enemy) ~= 0 then
  42. for i, fighter in pairs(fighters_enemy) do
  43. if fighter.data.row > 0 then
  44. return false;
  45. end;
  46. end;
  47. return true;
  48. end;
  49. return false;
  50. end;
  51. function is_all_enemy_in_back_row()
  52. if table.getn(fighters_enemy) ~= 0 then
  53. for i, fighter in pairs(fighters_enemy) do
  54. if fighter.data.row == 0 then
  55. return false;
  56. end;
  57. end;
  58. return true;
  59. end;
  60. return false;
  61. end;
  62. function is_all_ally_in_front_row()
  63. if table.getn(fighters_ally) ~= 0 then
  64. for i, fighter in pairs(fighters_ally) do
  65. if fighter.data.row > 0 then
  66. return false;
  67. end;
  68. end;
  69. return true;
  70. end;
  71. return false;
  72. end;
  73. function is_all_ally_in_back_row()
  74. if table.getn(fighters_ally) ~= 0 then
  75. for i, fighter in pairs(fighters_ally) do
  76. if fighter.data.row == 0 then
  77. return false;
  78. end;
  79. end;
  80. return true;
  81. end;
  82. return false;
  83. end;
  84. function set_self_as_target()
  85. -- clear targer
  86. fighters_target = {};
  87. fighters_target[1] = fighter_self;
  88. end;
  89. function set_random_ally_as_target()
  90. -- clear targer
  91. fighters_target = {};
  92. if table.getn(fighters_ally) ~= 0 then
  93. fighters_target[1] = fighters_ally[math.random(1, table.getn(fighters_ally))];
  94. end;
  95. end;
  96. ]]