ZombieActions = ZombieActions or {}

require("Bandits/Bandit");

ZombieActions.Forn = {}
ZombieActions.Forn.onStart = function(zombie, task)
    return true
end

ZombieActions.Forn.onWorking = function(zombie, task)
	--print("bandit time: " .. tostring(task.time));
	
	if task.time <= 1 then
		--zombie:getModData().activeScene = false;	---is handled outside of ZAForn
		--print("bAnim is finished"); 
		requestor = {}; 
		zombie:getModData().activeScene = false;
        return true
    else
		local bdir = zombie:getDirectionAngle();
		local bx = zombie:getX();
		local by = zombie:getY();
		local bz = zombie:getZ();
		local requestor = zombie:getModData().isRequestor;
		if requestor == nil then 
			--print("requestor is nil"); 
			zombie:getModData().activeScene = false;
			return true; 
		end
		if not requestor:getModData().ZomboWinSexScene then
			--print("requestor cancelled anim"); 
			requestor = {};
			zombie:getModData().activeScene = false;
			return true;
		end
		
		local rdir = requestor:getDirectionAngle();
		local rx = requestor:getX();
		local ry = requestor:getY();
		local rz = requestor:getZ();
		--[[
		if not rdir then print("requestor.dir is nil"); end
		if not rx then print("requestor.x is nil"); end
		if not ry then print("requestor.y is nil"); end
		if not rz then print("requestor.z is nil"); end
		print("bandit dir: " .. tostring(bdir) .. ", player dir: " .. tostring(rdir));
		print("bandit x: " .. tostring(bx) .. ", player x: " .. tostring(rx));
		print("bandit y: " .. tostring(by) .. ", player y: " .. tostring(ry));
		print("bandit z: " .. tostring(bz) .. ", player z: " .. tostring(rz));
		]]
		if not requestor:getModData().isOffering then
			requestor:setDirectionAngle(bdir);
			requestor:setX(bx); 
			requestor:setY(by); 
			requestor:setZ(bz); 
		else
			zombie:setDirectionAngle(rdir);
			zombie:setX(rx); 
			zombie:setY(ry); 
			zombie:setZ(rz); 
		end
			
		--[[
        local bumpType = zombie:getBumpType()
		print(tostring(bumpType));
        if bumpType ~= task.anim then 
            zombie:setBumpType(task.anim)
			print(tostring(task.anim));

            if task.sound then
                local emitter = zombie:getEmitter()
                if not emitter:isPlaying(task.sound) then
                    emitter:playSound(task.sound)
                end
            end

        end]]
		
		local function overrideAnim()	---is paired with forced animation override in ZWDZombieUpdate, works likes clockwork.
			if zombie:isBumped() then 
				local currentAnim = zombie:getBumpType();
				if currentAnim ~= zombie:getModData().sendAnim then
					--print("playing override is called");
					return true;
				end
			end
			--print("playing override is called but failed");
			return false;
		end
		
		if not zombie:isBumped() or overrideAnim() then
			--[[ How to animate Zombies
			... anims ".fbx;.x;" have animations names within the file, 'BumpType:STRING:Name;' MUST reference that animation name, NOT the filename.
			
			zombie:setBumpType("ConsentMaleSI"); Would reference... 
			
			"<m_Name>BumpType</m_Name>;
			<m_Type>STRING</m_Type>;
			<m_StringValue>ConsentMaleSI</m_StringValue>;" 
			
			in 'FOLDER:animSets:zombie:bumped' ... 'FILE:Vertical_MaleSI.xml' and play anim "<m_AnimName>Vertical_MaleSI</m_AnimName>;"
			
			Editor Note: Figuring just this one out took overall 30 HOURS of trial and error, decoding Bandits + WeekOne. You're welcome.
			
			How to make animation transitions for Bandits, A similar method could work for players too.
			{
				if not task.stage then task.stage = 1 end
		
				if not zombie:isBumped() then
					if task.stage == 1 then
						zombie:setBumpType("ANIM1");
					elseif task.stage < 20 then
						zombie:setBumpType("ANIM2")
					else
						zombie:setBumpType("ANIM3")
				end
				
				task.stage = task.stage + 1
				Bandit.UpdateTask(zombie, task)
				end

				if task.stage == 20 then
					return true;	--return true will end this code block in Bandits.
				end
			}
			]]
			zombie:setBumpType(tostring(zombie:getModData().sendAnim));
			
			Bandit.UpdateTask(zombie, task)
			--print(tostring("bandit anim: " .. zombie:getBumpType()));
		else
			--print(tostring(zombie:getBumpType()));
		end
    end
end

ZombieActions.Forn.onComplete = function(zombie, task)
    return true
end