public void ApplyServerTaskes(TimedTaskItem item) { var index = mServerTaskData.Items.FindIndex(t => t.Id == item.Id); if (index != -1) { var data = mServerTaskData.Items[index]; var count = item.CacheCount; while (data.Stamp < item.Stamp && count > 0) { try { mServerAction(item.Id); } catch (Exception ex) { Logger.Error(ex, "execute 1 ApplyServerTaskes id {0} error.", item.Id); } data.Stamp++; count--; } data.Stamp = item.Stamp; } else { var data = new DataContract.TimedTaskItem { Id = item.Id, Stamp = 0 }; var count = item.CacheCount; while (data.Stamp < item.Stamp && count > 0) { try { mServerAction(item.Id); } catch (Exception ex) { Logger.Error(ex, "execute 2 ApplyServerTaskes id {0} error.", item.Id); } data.Stamp++; count--; } data.Stamp = item.Stamp; mServerTaskData.Items.Add(data); } }
internal void InitTasks(ICharacterController character) { foreach (var item in mEvents) { if (!item.Value.Enable) { continue; } var data = new DataContract.TimedTaskItem { Id = item.Value.Id, Stamp = item.Value.Stamp }; character.GetTimedTasks().Add(data); } }
public void ApplyTaskes(ICharacterController character, TimedTaskItem item) { if (character.GetTimedTasks() == null) { return; } var index = character.GetTimedTasks().FindIndex(t => t.Id == item.Id); if (index != -1) { var data = character.GetTimedTasks()[index]; var count = item.CacheCount; while (data.Stamp < item.Stamp && count > 0) { try { Logger.Info("ApplyTaskes {0} id:{1} stamp:{2} ss:{3}", character, data.Id, data.Stamp, item.Stamp); item.Action(character, item.Stamp - data.Stamp); } catch (Exception ex) { Logger.Error(ex, "execute 1 ApplyTasks id {0} error", item.Id); } data.Stamp++; count--; } data.Stamp = item.Stamp; var nodeBase = character as NodeBase; if (nodeBase != null) { nodeBase.MarkDbDirty(); } } else { var data = new DataContract.TimedTaskItem { Id = item.Id, Stamp = 0 }; var count = item.CacheCount; while (data.Stamp < item.Stamp && count > 0) { try { Logger.Info("ApplyTaskes {0} id:{1} stamp:{2} ss:{3}", character, data.Id, data.Stamp, item.Stamp); item.Action(character, item.Stamp - data.Stamp); } catch (Exception ex) { Logger.Error(ex, "execute 2 ApplyTasks id {0} error", item.Id); } data.Stamp++; count--; } data.Stamp = item.Stamp; character.GetTimedTasks().Add(data); var nodeBase = character as NodeBase; if (nodeBase != null) { nodeBase.MarkDbDirty(); } } }