if isServer() then
    return
end

ISArtSupportCursor = ISBuildingObject:derive("ISArtSupportCursor")
local this = ISArtSupportCursor
function ISArtSupportCursor:create(x, y, z, north, sprite)
    local vehicle = self.character:getVehicle()
    if not FakeISArtSupportUI.instance then
        local maxY = getCore():getScreenHeight()
        local maxX = getCore():getScreenWidth()
        local sq = getWorld():getCell():getGridSquare(x, y, z)
        local ISAimStatusBox = FakeISArtSupportUI:new(0, 0, 0, 0, self.character, self.square, vehicle);
        ISAimStatusBox:initialise();
        ISAimStatusBox:addToUIManager();
        local Drag = getCell():getDrag(0)
        if Drag and Drag.instance then
            Drag.instance = nil
        end
        getCell():setDrag(nil, 0)
        local Type = GetPanzerType(vehicle)
        local CrewLaungage = PanzerList[Type].CrewLaungage
        if self.character:getModData().CrewLaungage then
            CrewLaungage = self.character:getModData().CrewLaungage
        end
        self.character:playSound(CrewLaungage .. "Need_Art")
        local modData = vehicle:getModData()
        if modData.ArtSupportTimes and modData.ArtSupportTimes > 0 then
            modData.ArtSupportTimes = modData.ArtSupportTimes - 1
        end
    end
end

function ISArtSupportCursor:isValid(square) -- local distan = 10
    local distan = ((square:getX() - self.character:getX()) ^ 2 + (square:getY() - self.character:getY()) ^ 2) ^ 0.5
    if distan > 5 then
        return true
    else
        return false
    end
end

function ISArtSupportCursor:render(x, y, z, square)

    if not self.floorSprite then
        self.floorSprite = IsoSprite.new()
        self.floorSprite:LoadFramesNoDirPageSimple('media/ui/FloorTileCursor.png')
    end
    local r, g, b, a = 0.0, 1.0, 0.0, 0.8
    if not self:isValid(square) then
        r = 1.0
        g = 0.0
    end
    for i = -5, 5, 10 do
        for j = -5, 5, 10 do
            self.floorSprite:RenderGhostTileColor(x + i, y + j, z, 1, 1, 0, a)
        end
    end

    self.floorSprite:RenderGhostTileColor(x, y, z, r, g, b, a)
    -- self.floorSprite:RenderGhostTileColor(x, y, z, r, g, b, a)
    self.square = square
    self.Vaild = self:isValid(square)
end

function ISArtSupportCursor:new(sprite, northSprite, character)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    this.instance = o
    o:init()
    o:setSprite(sprite)
    o:setNorthSprite(northSprite)
    o.player = 0
    o.character = character
    o.FireTick = 10
    o.type = "ArtSupport"
    o.noNeedHammer = true
    o.skipBuildAction = true
    o.maxrange = 20
    o.square = nil
    o.Vaild = false
    o.skipWalk2 = true
    o.canBeAlwaysPlaced = true
    return o
end
