Last active
October 19, 2023 13:31
-
-
Save Novaras/12b558d5b76c8d52b74e9f85b5edc10f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---@class MoveAttacker : Ship | |
---@field attack_move_position? Position | |
---@field previous_ROE? ROE | |
---@field success_distance integer | |
moveattacker = { | |
success_distance = 100 | |
}; | |
function moveattacker:isMoveAttacking() | |
return self.attack_move_position ~= nil; | |
end | |
function moveattacker:moveAttack(position) | |
self.previous_ROE = self:ROE(); | |
self:ROE(ROE.OffensiveROE); | |
self.attack_move_position = position; -- remember this | |
self:move(position); | |
end | |
function moveattacker:endMoveAttack() | |
self.attack_move_position = nil; | |
self:ROE(self.previous_ROE); | |
self.previous_ROE = nil; | |
end | |
function moveattacker:update() | |
if (self:isMoveAttacking()) then | |
local current_command = self:currentCommand(); | |
-- in this case we somehow got distacted and went idle or something | |
if (current_command ~= COMMAND_Move and current_command ~= COMMAND_Attack) then | |
-- let's just re-issue the command | |
self:moveAttack(self.attack_move_position); | |
end | |
local distance_to_target = Vec3:distanceBetween(self:position(), self.attack_move_position); | |
local within_target_threshold = distance_to_target <= moveattacker.success_distance; | |
if (within_target_threshold) then | |
self:endMoveAttack(); | |
end | |
end | |
end | |
modkit.compose:addBaseProto(moveattacker); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment