You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.5 KiB

using System;
using System.Collections.Generic;
using ProtoCSStruct;
using Sog;
namespace Game
{
public class JobSvc
{
private static readonly SortedList<JobType, Func<PlayerOnGame, DBJobData, DBJobData>> m_Job_Event = new();
public static void Register()
{
m_Job_Event[JobType.JOB_TEST] = TestJob;
}
public static bool OnTimeout(PlayerOnGame player, long now,ref DBJobData job)
{
var action = m_Job_Event[(JobType)job.Type];
if (action == null)
{
TraceLog.Trace("JobSvc.OnTimeout not found action method for event type={0}", job.Type);
return true;
}
var retJob = action(player, job);
var ret = retJob.EndTime <= job.EndTime;
job.CopyFrom(ref retJob);
if (!ret && job.EndTime < now)
{
job.EndTime = now + 1;
}
return ret;
}
private static DBJobData TestJob(PlayerOnGame player, DBJobData job)
{
var args = job.Args;
TraceLog.Trace("JobSvc.TestJob job do something id={0}", job.Id);
job.TryRet++;
if (job.TryRet == 10) //模拟执行10此结束job
{
TraceLog.Trace("JobSvc.TestJob delete job id={0}", job.Id);
return job;
}
job.EndTime += 10; //循环延迟10秒执行
return job;
}
}
}