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.
127 lines
3.5 KiB
127 lines
3.5 KiB
1 month ago
|
using ProtoCSStruct;
|
||
|
using Sog;
|
||
|
|
||
|
namespace Game
|
||
|
{
|
||
|
/**
|
||
|
* 提供一种玩家在线延迟任务的机制:
|
||
|
* 比如说点击调查问卷之后延迟多长时间发送奖励邮件
|
||
|
*/
|
||
|
public static class ActorSvc
|
||
|
{
|
||
|
public static void OnTick(PlayerOnGame player, long now)
|
||
|
{
|
||
|
ref var jobs = ref player.RoleData.ExtData.Job;
|
||
|
if (jobs.Count == 0)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var result = new RepeatedDBJobData_16();
|
||
|
for (var i = 0; i < jobs.Count; i++)
|
||
|
{
|
||
|
ref var job = ref jobs[i];
|
||
|
if (job.EndTime > now)
|
||
|
{
|
||
|
result.Add(job);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
var ret = JobSvc.OnTimeout(player, now, ref job);
|
||
|
if (!ret) //不删除
|
||
|
{
|
||
|
result.Add(job);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
player.RoleData.ExtData.Job = result;
|
||
|
player.MakeDirty();
|
||
|
}
|
||
|
|
||
|
public static bool Submit(PlayerOnGame player, long duration, JobType type, IDValue64[] args = null)
|
||
|
{
|
||
|
//注意job 的数量
|
||
|
if (player.RoleData.ExtData.Job.Count == player.RoleData.ExtData.Job.GetMaxCount())
|
||
|
{
|
||
|
TraceLog.Error("ActorSvc.Add add actor job count too maximum");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
var job = new DBJobData
|
||
|
{
|
||
|
Id = GameServerUtils.GetTimeMs(),
|
||
|
StartTime = GameServerUtils.GetTimeSecond(),
|
||
|
EndTime = GameServerUtils.GetTimeSecond() + duration,
|
||
|
Type = (int)type
|
||
|
};
|
||
|
if (args != null)
|
||
|
{
|
||
|
foreach (var t in args)
|
||
|
{
|
||
|
job.Args.Add(t);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
player.RoleData.ExtData.Job.Add(job);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static bool Remove(PlayerOnGame player, long jobId)
|
||
|
{
|
||
|
ref var jobs = ref player.RoleData.ExtData.Job;
|
||
|
var index = -1;
|
||
|
for (int i = 0; i < jobs.Count; i++)
|
||
|
{
|
||
|
if (jobs[i].Id == jobId)
|
||
|
{
|
||
|
index = i;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (index > -1)
|
||
|
{
|
||
|
jobs.RemoveAt(index);
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static bool Reboot(PlayerOnGame player, int jobId, int startTime, int endTime)
|
||
|
{
|
||
|
ref var jobs = ref player.RoleData.ExtData.Job;
|
||
|
var index = -1;
|
||
|
for (var i = 0; i < jobs.Count; i++)
|
||
|
{
|
||
|
if (jobs[i].Id == jobId)
|
||
|
{
|
||
|
index = i;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (index <= -1) return false;
|
||
|
|
||
|
ref var job = ref jobs[index];
|
||
|
job.StartTime = startTime;
|
||
|
job.EndTime = endTime;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static bool Delay(PlayerOnGame player, int jobId, int duration)
|
||
|
{
|
||
|
ref var jobs = ref player.RoleData.ExtData.Job;
|
||
|
var index = -1;
|
||
|
for (var i = 0; i < jobs.Count; i++)
|
||
|
{
|
||
|
if (jobs[i].Id == jobId)
|
||
|
{
|
||
|
index = i;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (index <= -1) return false;
|
||
|
ref var job = ref jobs[index];
|
||
|
job.EndTime += duration;
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|