Exemple #1
0
        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 List <TimedTaskItem> GetTimedTasks()
 {
     return(mImpl.GetTimedTasks(this));
 }
Exemple #3
0
        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();
                }
            }
        }