USE [msdb]
GO

/****** Object:  Job [Jobs 1 minuto]    Script Date: 02/15/2017 00:45:59 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]]    Script Date: 02/15/2017 00:45:59 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'Jobs 1 minuto', 
		@enabled=1, 
		@notify_level_eventlog=0, 
		@notify_level_email=0, 
		@notify_level_netsend=0, 
		@notify_level_page=0, 
		@delete_level=0, 
		@description=N'No description available.', 
		@category_name=N'[Uncategorized (Local)]', 
		@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [null]    Script Date: 02/15/2017 00:45:59 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'null', 
		@step_id=1, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'UPDATE CashShopData
SET goblinPoint=goblinpoint+10
FROM CashShopData join Character on CashShopData.Accountid = Character.Accountid COLLATE database_default
WHERE character.tempo_exp>180

Update character set exp_war=exp_war+4,tempo_exp=0 
FROM Character join Memb_info on Character.Accountid = Memb_info.memb___id COLLATE database_default where tempo_exp > 180 and memb_info.accountlevel=1

Update character set exp_war=exp_war+2,tempo_exp=0 
FROM Character join Memb_info on Character.Accountid = Memb_info.memb___id COLLATE database_default where tempo_exp > 180 and memb_info.accountlevel=0

update character set data_reset = (getdate()) where resetcount > 299 and data_reset is null and nivel_gm<2
update character set data_mreset = (getdate()) where masterresetcount > 299 and data_mreset is null and nivel_gm<2

update MEMB_INFO set AccountLevel = 0 where AccountExpireDate < GETDATE()', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [tempo]    Script Date: 02/15/2017 00:45:59 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'tempo', 
		@step_id=2, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'Update character set character.tempo = character.tempo+1, character.tempo_mensal = character.tempo_mensal+1,
character.tempo_exp= character.tempo_exp+1
FROM Character join Memb_Stat on Character.Accountid = Memb_Stat.memb___id
join AccountCharacter on Character.Accountid = AccountCharacter.id
where Memb_Stat.ConnectStat=1 and character.Name=AccountCharacter.GameIDC', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [tempo conta on]    Script Date: 02/15/2017 00:45:59 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'tempo conta on', 
		@step_id=3, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'Update Memb_stat set tempo=tempo+1,tempo_vip=tempo_vip+1 where connectstat=1
', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [add vip x tempo]    Script Date: 02/15/2017 00:45:59 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'add vip x tempo', 
		@step_id=4, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'UPDATE MEMB_INFO
SET accountexpiredate = accountexpiredate+1
FROM MEMB_INFO join memb_stat on Memb_info.memb___id = Memb_stat.memb___id COLLATE database_default
WHERE memb_stat.tempo_vip>''719'' and accountlevel = 1

UPDATE MEMB_INFO
SET accountlevel = 1, accountexpiredate = (getdate())+1
FROM MEMB_INFO join memb_stat on Memb_info.memb___id = Memb_stat.memb___id COLLATE database_default
WHERE memb_stat.tempo_vip>''719'' and accountlevel = 0

update memb_stat set tempo_vip=0 where tempo_vip>''719'' 
', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [recorde]    Script Date: 02/15/2017 00:45:59 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'recorde', 
		@step_id=5, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'update mk_server set recorde_on = (select count(*) from Memb_stat where connectstat=1) 
where recorde_on < (select count(*) from Memb_stat where connectstat=1)', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Rei do MU]    Script Date: 02/15/2017 00:45:59 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Rei do MU', 
		@step_id=6, 
		@cmdexec_success_code=0, 
		@on_success_action=1, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'update guild set owner_time=owner_time+1 where owner=1 and (select rei_do_mk from mk_server)=1', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'a', 
		@enabled=1, 
		@freq_type=4, 
		@freq_interval=1, 
		@freq_subday_type=4, 
		@freq_subday_interval=1, 
		@freq_relative_interval=0, 
		@freq_recurrence_factor=0, 
		@active_start_date=20160730, 
		@active_end_date=99991231, 
		@active_start_time=0, 
		@active_end_time=235959, 
		@schedule_uid=N'24500868-d936-4fe6-a449-69b836f1098e'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:

GO


