-- не настраивать
require( "scripts/game/deftasks.lua" );
require( "scripts/game/deftime.lua" );
GameObject = {
    Params = {
        ID="trash";
        width=1;
        height=1;
        --health=3200;
        timerTask=-1;       -- do not change this parameter (для расчетов)
        group=4; --мусорка
        --RandomTasks=0;
        GridData= { 
            1
        };
        delay_selection = 0; -- сколько сек ждать перед вкл.подсветки
    };
    ActivePoints = { 
        trashing = { 
                       { {}, 1,0,0,  0,  0,0,0 };
                       { {}, -1,0,0,  0,  0,0,0 };
                       { {}, 0,1,0,  0,  0,0,0 };
                       { {}, 0,-1,0,  0,  0,0,0 };
                   }; 
    };
    Objects = {};
    -- list of all tasks for an object
    Tasks = {
        trashing = { FuncName="TrashTaskExecute", sleeping={0}, not_need_action=0, timer=1, time_tick=1000, skill_up = 0 };
    };
    -- list of all triggers for an object
    Triggers = { 
        Selection = {FuncName="SelectTriger", NotRunWhen={"trashing"}, time_tick=100 };
    };
    --tasks to be performed after an object is created
    InitActiveTasks = {};
    --tasks an object is waiting ofr after it is created
    InitExpectedTasks = {};
};
function GameObject:Get()
    return self;
end


-- вся инициализация должа проходить только в этой функции
function OnInit()
    aObj = GameObject:Get();   
    if( not aObj.Params.MaxHealth )then
        aObj.Params.MaxHealth = aObj.Params.health;
    end;
    aObj.Params.selection = 0;
end
    

function GetParams()
    aObj = GameObject:Get();   
    return aObj.Params;
end

-- perform Task EATING over external object and return true if task is completed
function TrashTaskExecute()
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then tTask = aObject.Tasks.trashing.timer; end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        AddStatParamI("RecycleBin",1);
        return 0;
    end
    return 1;
end
--для включения - выключения служит переменная .Params.selection
function SelectTriger()
    aObject = GameObject:Get();
    if (aObject.Params.selection <= 0) then return; end
    local aTrigger = aObject.Triggers.Selection;
    aObject.Params.selection = aObject.Params.selection - 1;
    if (aObject.Params.selection <= 0) then
        CPP_WantSelect(1);
    end
end

