示例#1
0
 public UserImportChoice([NotNull] TriggerEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     Entity = entity;
 }
示例#2
0
        void ResolveUsing(
            ConflictResolution conflictResolution,
            TriggerManager triggerManager,
            TriggerEntity newTriggerEntity,
            [CanBeNull] ITrigger existingTrigger)
        {
            if (conflictResolution == ConflictResolution.Skip)
            {
                return;
            }
            else if (conflictResolution == ConflictResolution.Replace)
            {
                if (existingTrigger == null)
                {
                    throw new InvalidOperationException("existingTrigger is null");
                }

                var existingTriggerEntity = existingTrigger.GetTriggerEntityCopy(serializer);
                triggerManager.RemoveTrigger(existingTrigger);
                try
                {
                    triggerManager.CreateTriggerFromEntity(newTriggerEntity);
                }
                catch (Exception exception)
                {
                    logger.Error(exception, $"Error at trigger creation attempt (replace): {newTriggerEntity.GetDescription()}");

                    try
                    {
                        triggerManager.CreateTriggerFromEntity(existingTriggerEntity);
                    }
                    catch (Exception innerException)
                    {
                        logger.Error(innerException, $"Error at trigger recreate attempt: {existingTriggerEntity.GetDescription()}");
                    }

                    throw;
                }
            }
            else if (conflictResolution == ConflictResolution.ImportAsNew)
            {
                newTriggerEntity.TriggerId = Guid.NewGuid();
                if (existingTrigger != null && newTriggerEntity.Name == existingTrigger.Name)
                {
                    newTriggerEntity.Name = newTriggerEntity.Name + GetStampText();
                }
                try
                {
                    triggerManager.CreateTriggerFromEntity(newTriggerEntity);
                }
                catch (Exception exception)
                {
                    logger.Error(exception, $"Error at trigger creation attempt (import as new): {newTriggerEntity.GetDescription()}");

                    throw;
                }
            }
        }
示例#3
0
 //Default constructor
 public Collections()
 {
     map              = null;
     player           = null;
     monsters         = null;
     items            = null;
     triggers         = null;
     nextLevelTrigger = null;
     level            = 0;
 }
示例#4
0
 public SimpleTrigger(TriggerEntity triggerEntity, ISoundManager soundManager, ITrayPopups trayPopups, IWurmApi wurmApi,
                      ILogger logger)
     : base(triggerEntity, soundManager, trayPopups, wurmApi, logger)
 {
     ConditionHelp = "Text to match against log entry content, case insensitive";
     SourceHelp    =
         "Test to match against log entry source. " + Environment.NewLine +
         "Source is the text between < >, for example game character than sent a PM. " + Environment.NewLine +
         "Case insensitive. " + Environment.NewLine +
         "Leave empty to match everything.";
 }
示例#5
0
        public ITrigger CreateNewTriggerFromEntity(TriggerEntity entity)
        {
            if (triggers.ContainsKey(entity.TriggerId))
            {
                throw new InvalidOperationException(
                          $"Trigger with ID {entity.TriggerId} already exists for player {CharacterName}.");
            }

            var trigger = BuildTrigger(entity);

            triggers.Add(entity.TriggerId, trigger);
            triggersConfig.TriggerEntities.Add(entity.TriggerId, entity);
            return(trigger);
        }
示例#6
0
 public RegexTrigger(TriggerEntity triggerEntity, ISoundManager soundManager, ITrayPopups trayPopups, IWurmApi wurmApi,
                     ILogger logger, ITelemetry telemetry)
     : base(triggerEntity, soundManager, trayPopups, wurmApi, logger, telemetry)
 {
     if (logger == null)
     {
         throw new ArgumentNullException("logger");
     }
     this.logger   = logger;
     ConditionHelp = "C# regular expression pattern to match against log entry content.";
     SourceHelp    =
         "C# regular expression pattern to match against log entry source. " + Environment.NewLine +
         "Source is the text between < >, for example game character than sent a PM. " + Environment.NewLine +
         "Leave empty to match everything.";
 }
示例#7
0
        public TriggerBase([NotNull] TriggerEntity triggerEntity, [NotNull] ISoundManager soundManager, [NotNull] ITrayPopups trayPopups,
                           [NotNull] IWurmApi wurmApi, [NotNull] ILogger logger,
                           [NotNull] ITelemetry telemetry)
        {
            if (triggerEntity == null)
            {
                throw new ArgumentNullException("triggerEntity");
            }
            if (soundManager == null)
            {
                throw new ArgumentNullException("soundManager");
            }
            if (trayPopups == null)
            {
                throw new ArgumentNullException("trayPopups");
            }
            if (wurmApi == null)
            {
                throw new ArgumentNullException("wurmApi");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            this.TriggerEntity = triggerEntity;
            this.SoundManager  = soundManager;
            this.TrayPopups    = trayPopups;
            this.WurmApi       = wurmApi;
            this.Logger        = logger;
            this.telemetry     = telemetry ?? throw new ArgumentNullException(nameof(telemetry));

            MuteChecker = () => false;
            Active      = true;

            if (triggerEntity.HasSound)
            {
                Sound = new SoundNotifier(this, soundManager);
            }
            if (triggerEntity.HasPopup)
            {
                Popup = new PopupNotifier(this, trayPopups);
            }

            telemetry.TrackEvent($"Triggers: initialized trigger {this.GetType().Name}");
        }
示例#8
0
 public ActionQueueTrigger(TriggerEntity triggerEntity, ISoundManager soundManager, ITrayPopups trayPopups,
                           IWurmApi wurmApi, ILogger logger, [NotNull] IActionQueueConditions conditionsManager, ITelemetry telemetry)
     : base(triggerEntity, soundManager, trayPopups, wurmApi, logger, telemetry)
 {
     if (logger == null)
     {
         throw new ArgumentNullException("logger");
     }
     if (conditionsManager == null)
     {
         throw new ArgumentNullException("conditionsManager");
     }
     this.logger            = logger;
     this.conditionsManager = conditionsManager;
     LockedLogTypes         = new[] { LogType.Event };
     lastActionFinished     = DateTime.Now;
     lastActionStarted      = DateTime.Now;
     lastEventLine          = string.Empty;
 }
示例#9
0
        ITrigger BuildTrigger(TriggerEntity settings)
        {
            switch (settings.TriggerKind)
            {
            case TriggerKind.Simple:
                return(new SimpleTrigger(settings, soundManager, trayPopups, wurmApi, logger));

            case TriggerKind.Regex:
                return(new RegexTrigger(settings, soundManager, trayPopups, wurmApi, logger));

            case TriggerKind.ActionQueue:
                return(new ActionQueueTrigger(settings, soundManager, trayPopups, wurmApi, logger, actionQueueConditions));

            case TriggerKind.SkillLevel:
                return(new SkillLevelTrigger(CharacterName, settings, soundManager, trayPopups, wurmApi, logger));

            default:
                throw new ApplicationException("Unknown trigger kind: " + settings.TriggerKind);
            }
        }
示例#10
0
        public TriggerBase([NotNull] TriggerEntity triggerEntity, [NotNull] ISoundManager soundManager, [NotNull] ITrayPopups trayPopups,
                           [NotNull] IWurmApi wurmApi, [NotNull] ILogger logger)
        {
            if (triggerEntity == null)
            {
                throw new ArgumentNullException("triggerEntity");
            }
            if (soundManager == null)
            {
                throw new ArgumentNullException("soundManager");
            }
            if (trayPopups == null)
            {
                throw new ArgumentNullException("trayPopups");
            }
            if (wurmApi == null)
            {
                throw new ArgumentNullException("wurmApi");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            this.TriggerEntity = triggerEntity;
            this.SoundManager  = soundManager;
            this.TrayPopups    = trayPopups;
            this.WurmApi       = wurmApi;
            this.Logger        = logger;

            MuteChecker = () => false;
            Active      = true;

            if (triggerEntity.HasSound)
            {
                Sound = new SoundNotifier(this, soundManager);
            }
            if (triggerEntity.HasPopup)
            {
                Popup = new PopupNotifier(this, trayPopups);
            }
        }
示例#11
0
        public SkillLevelTrigger(string characterName, TriggerEntity triggerEntity, ISoundManager soundManager,
                                 ITrayPopups trayPopups, IWurmApi wurmApi, ILogger logger)
            : base(triggerEntity, soundManager, trayPopups, wurmApi, logger)
        {
            if (characterName == null)
            {
                throw new ArgumentNullException("characterName");
            }
            this.characterName = characterName;
            this.logger        = logger;
            skillEntryParser   = new SkillEntryParser(wurmApi);
            LockedLogTypes     = new[] { LogType.Skills };

            SkillFeedback = "(no data)";

            skillHistoricRefresher = new TriggerableAsyncOperation(RefreshSkill);

            character = wurmApi.Characters.Get(characterName);
            character.LogInOrCurrentServerPotentiallyChanged += CharacterOnLogInOrCurrentServerPotentiallyChanged;

            skillHistoricRefresher.Trigger();
        }
示例#12
0
        public ITrigger CreateNewTrigger(TriggerKind kind)
        {
            var entity = new TriggerEntity(Guid.NewGuid(), kind);

            return(CreateNewTriggerFromEntity(entity));
        }
示例#13
0
 protected SimpleConditionTriggerBase(TriggerEntity triggerEntity, ISoundManager soundManager, ITrayPopups trayPopups, IWurmApi wurmApi,
                                      ILogger logger, ITelemetry telemetry)
     : base(triggerEntity, soundManager, trayPopups, wurmApi, logger, telemetry)
 {
 }
示例#14
0
 public ITrigger CreateTriggerFromEntity(TriggerEntity triggerEntity)
 {
     return(activeTriggers.CreateNewTriggerFromEntity(triggerEntity));
 }