示例#1
0
 public ActivityResolver(IUtilityAi utilityAi, IConditionContext conditionContext,
                         IActivityCreationContext activityCreationContext)
 {
     _utilityAi               = utilityAi;
     _conditionContext        = conditionContext;
     _activityCreationContext = activityCreationContext;
 }
示例#2
0
 public UtilityAi(IActivityCreationContext activityCreationContext, ISkillEvaluationContext skillEvaluationContext,
                  IConditionContext conditionContext)
 {
     _activityCreationContext = activityCreationContext;
     _skillEvaluationContext  = skillEvaluationContext;
     _conditionContext        = conditionContext;
 }
示例#3
0
        /// <summary>
        /// Sends a notification synchronously.
        /// </summary>
        /// <param name="context">A reference to the condition context.</param>
        /// <param name="notification">The notification to send.</param>
        protected void SendNotification(IConditionContext context, INotification notification)
        {
            context.ThrowIfNull(nameof(context));
            notification.ThrowIfNull(nameof(notification));

            notification.Send(new NotificationContext(context.Logger, context.MapDescriptor, context.CreatureFinder));
        }
示例#4
0
        /// <summary>
        /// Sends a notification asynchronously.
        /// </summary>
        /// <param name="context">A reference to the condition context.</param>
        /// <param name="notification">The notification to send.</param>
        /// <param name="delayTime">Optional. The time delay after which the notification should be sent. If left null, the notificaion is scheduled to be sent ASAP.</param>
        protected void SendNotificationAsync(IConditionContext context, INotification notification, TimeSpan?delayTime = null)
        {
            context.ThrowIfNull(nameof(context));
            notification.ThrowIfNull(nameof(notification));

            context.Scheduler.ScheduleEvent(notification, delayTime);
        }
示例#5
0
        public void Load(IConditionContext context, string scriptFile)
        {
            mConditionContext = context;
            string[] lines = File.ReadAllLines(scriptFile);

            bool startBlockFounded = false;

            foreach (var line in lines)
            {
                if (IsBeginStartLine(line))
                {
                    startBlockFounded = true;
                    continue;
                }
                if (startBlockFounded)
                {
                    if (IsEndLine(line))
                    {
                        startBlockFounded = false;
                        continue;
                    }
                    var condition = ParseCondition(line);
                    if (condition != null)
                    {
                        mStartConditions.Add(condition);
                    }
                }
            }
        }
示例#6
0
        public override bool Evaluate(GameEntity entity, IConditionContext conditionContext)
        {
            IEnumerable <GameEntity> entitiesSeen = entity.vision.EntitiesNoticed
                                                    .Select(guid => conditionContext.Context.GetEntityWithId(guid))
                                                    .Where(e => e != null) // SAME AS IN PostHeartbeatSystem. will ignore removed entites, but they will remain in EntitiesNoticed. todo: is it fine?
            ;

            return(entitiesSeen.Any(e => !conditionContext.FriendshipResolver.AreFriends(entity, e)));
        }
示例#7
0
        public override bool Evaluate(GameEntity entity, IConditionContext conditionContext)
        {
            IEnumerable <GameEntity> selectedItemsInVicinity = conditionContext.EntityDetector.DetectEntities(entity.position.Position,
                                                                                                              entity.vision.PerceptionRange)
                                                               .Where(e => e.isCarryable)
                                                               .Where(e => e.recipee.RecipeeName == ItemRecipee.Id);

            return(selectedItemsInVicinity.Any());
        }
示例#8
0
        /// <summary>
        /// Executes the condition's logic.
        /// </summary>
        /// <param name="context">The execution context for this condition.</param>
        protected override void Execute(IConditionContext context)
        {
            var inThingContainer = this.Item.ParentContainer;

            if (!(this.Item is IThing existingThing) || !this.Item.HasExpiration || inThingContainer == null)
            {
                // Silent fail.
                return;
            }

            if (this.Item.ExpirationTarget == 0)
            {
                // We will delete this item.
                context.Scheduler.ScheduleEvent(new DeleteItemOperation(requestorId: 0, this.Item));

                return;
            }

            var creationArguments = ItemCreationArguments.WithTypeId(this.Item.ExpirationTarget);

            if (this.Item.IsLiquidPool)
            {
                creationArguments.Attributes = new[]
示例#9
0
        /// <summary>
        /// Executes the condition's logic.
        /// </summary>
        /// <param name="context">The execution context for this condition.</param>
        protected override void Execute(IConditionContext context)
        {
            var currentTimeSnapshot = context.CurrentTime;

            // Clear out any exhaustion that has passed.
            foreach (var exhaustionType in this.ExhaustionTimesPerType.Keys)
            {
                if (this.ExhaustionTimesPerType[exhaustionType] > currentTimeSnapshot)
                {
                    continue;
                }

                this.ExhaustionTimesPerType.Remove(exhaustionType);
            }

            if (this.ExhaustionTimesPerType.Count == 0)
            {
                return;
            }

            var nextExpiry = this.ExhaustionTimesPerType.Min(kvp => kvp.Value - currentTimeSnapshot);

            this.RepeatAfter = nextExpiry < TimeSpan.Zero ? TimeSpan.Zero : nextExpiry;
        }
示例#10
0
 /// <summary>
 /// Executes the condition's logic.
 /// </summary>
 /// <param name="context">The execution context for this condition.</param>
 protected override void Execute(IConditionContext context)
 {
     // For InFight, we just send the updated flags.
     this.SendNotificationAsync(context, new GenericNotification(() => this.Player.YieldSingleItem(), new PlayerConditionsPacket(this.Player)));
 }
示例#11
0
 public abstract bool Evaluate(GameEntity entity, IConditionContext conditionContext);
示例#12
0
 public EqualCondition(IConditionContext context, string name, T val)
     : base(context, name)
 {
     mValue = val;
 }
示例#13
0
 /// <summary>
 /// Executes the condition's logic.
 /// </summary>
 /// <param name="context">The execution context for this condition.</param>
 protected override void Execute(IConditionContext context)
 {
     // For InFight, we just send the updated flags.
     this.SendNotification(context, new PlayerConditionsUpdateNotification(this.Player));
 }
示例#14
0
 public NotEqualCondition(IConditionContext context, string varName, T val)
     : base(context, varName)
 {
     mValue = val;
 }
示例#15
0
 /// <summary>
 /// Executes the condition's logic.
 /// </summary>
 /// <param name="context">The execution context for this condition.</param>
 protected abstract void Execute(IConditionContext context);
示例#16
0
 public Condition(IConditionContext context, string variableName)
 {
     this.context       = context;
     this.mVariableName = variableName;
 }
示例#17
0
 public RaceEqualCondition(IConditionContext context, string name, Race race)
     : base(context, name, race)
 {
 }
示例#18
0
 public override bool Evaluate(GameEntity entity, IConditionContext conditionContext)
 {
     return(entity.vision.EntitiesNoticed
            .Select(id => conditionContext.Context.GetEntityWithId(id))
            .Any(e => conditionContext.FriendshipResolver.AreFriends(entity, e)));
 }
示例#19
0
文件: Attitude.cs 项目: bmjoy/Osnowa
 public override bool Evaluate(GameEntity entity, IConditionContext conditionContext)
 {
     return(entity.isAggressive == Aggressive);
 }
示例#20
0
        /// <summary>
        /// Sends a notification synchronously.
        /// </summary>
        /// <param name="context">A reference to the condition's context.</param>
        /// <param name="notification">The notification to send.</param>
        protected void SendNotification(IConditionContext context, INotification notification)
        {
            notification.ThrowIfNull(nameof(notification));

            context.GameApi.SendNotification(notification);
        }