示例#1
0
        public bool Evaluate(EventContext context, Game game)
        {
            //No children means its never true.  Used in CHILDREN_WELLDRESS_PRESTIGE_MOD.
            if (context.CurrentCharacter.Children.Count == 0)
                return false;

            for (int i = 0; i < context.CurrentCharacter.Children.Count; ++i)
            {
                context.PushScope(context.CurrentCharacter.Children[i]);
                if (!requirements.Evaluate(context, game))
                {
                    //We've found a child that doesn't the requirements.  This is a failure
                    context.PopScope();
                    return false;
                }
                context.PopScope();
            }
            return true;
        }
示例#2
0
        public double Evaluate(Game game, EventContext context, Weights weights)
        {
            //TODO: Start with random index.
            // TODO: Should we be doing some average here instead of just stopping
            // at the first one that works?
            for (int i = 0; i < context.CurrentCharacter.Children.Count; ++i)
            {
                Character character = context.CurrentCharacter.Children[i];
                context.PushScope(character);
                if (requirements.Evaluate(context, game))
                {
                    double result = operation.Evaluate(game, context, weights);

                    //AnyChild stops after a single interation.
                    context.PopScope();
                    return result;
                }
                context.PopScope();
            }
            return 0.0;
        }
示例#3
0
 public bool Evaluate(EventContext context, Game game)
 {
     context.PushScope(context.GetScopedObjectByName(scopeName));
     bool result = logic.Evaluate(context, game);
     context.PopScope();
     return result;
 }
示例#4
0
        public bool Evaluate(EventContext context, Game game)
        {
            //No children means its never true.
            if (context.CurrentCharacter.Children.Count == 0)
                return false;

            //TODO: start with a random child index.
            for(int i = 0; i < context.CurrentCharacter.Children.Count; ++i)
            {
                context.PushScope(context.CurrentCharacter.Children[i]);
                if(requirements.Evaluate(context, game))
                {
                    //We've found a child that meets the requirements.
                    context.PopScope();
                    return true;
                }
                context.PopScope();
            }
            return false;
        }
示例#5
0
        public void Execute(EventResults result, Game game, EventContext context)
        {
            Character tellingCharacter = context.GetScopedObjectByName("ROOT") as Character;
            InformationInstance informationInstance = tellingCharacter.ChooseInformationAbout(type, context.GetScopedObjectByName(about) as Character);
            bool isNewInformation = context.CurrentCharacter.AddInformation(informationInstance);
            context.PushScope(informationInstance);
            operation.Execute(result, game, context);
            context.PopScope();

            result.AddObservableInfo(informationInstance, overhearChance, tellingCharacter);

            if (isNewInformation)
            {
                game.Log(context.CurrentCharacter.Name + " learned an information.");
                informationInstance.ExecuteOnTold(context.CurrentCharacter, game, context.CurrentCharacter.CurrentRoom);
            }
        }
示例#6
0
        public void Execute(EventResults result, Game game, EventContext context)
        {
            //TODO: Start with random index.
            for(int i = 0; i < context.CurrentCharacter.Children.Count; ++i)
            {
                Character character = context.CurrentCharacter.Children[i];
                context.PushScope(character);
                if (requirements.Evaluate(context, game))
                {
                    operation.Execute(result, game, context);

                    //AnyChild stops after a single interation.
                    context.PopScope();
                    return;
                }
                context.PopScope();
            }
        }
示例#7
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.PushScope(context.GetScopedObjectByName(scopeName));
     operation.Execute(result, game, context);
     context.PopScope();
 }
示例#8
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     context.PushScope(context.GetScopedObjectByName(scopeName));
     double result = operation.Evaluate(game, context, weights);
     context.PopScope();
     return result;
 }
示例#9
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     foreach (var character in context.CurrentCharacter.CurrentRoom.GetCharacters(context.CurrentCharacter))
     {
         context.PushScope(character);
         if (requirements.Evaluate(context, game))
         {
             operation.Execute(result, game, context);
         }
         context.PopScope();
     }
 }
示例#10
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     double result = 0.0;
     foreach (var character in context.CurrentCharacter.CurrentRoom.GetCharacters(context.CurrentCharacter))
     {
         context.PushScope(character);
         if (requirements.Evaluate(context, game))
         {
             result += operation.Evaluate(game, context, weights);
         }
         context.PopScope();
     }
     return result;
 }
示例#11
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     Character chosen = context.CurrentCharacter.ChooseCharacter(game.FilterCharacters(requirements, context), operation, context, scopeName);
     context.PushScope(chosen, scopeName);
     operation.Execute(result, game, context);
     context.PopScope();
 }
示例#12
0
        public double Evaluate(Game game, EventContext context, Weights weights)
        {
            //Get the weights for the character that will be choosing the character.
            Weights charWeights = context.CurrentCharacter.GetWeights(weights.Perspective);

            Character[] availableCharacters = game.FilterCharacters(requirements, context).ToArray();
            bool[] allowed = new bool[availableCharacters.Length];
            if (context.CurrentCharacter is AICharacter)
            {
                //AICharacter will only select characters from his important character's list.
                var important = (context.CurrentCharacter as AICharacter).GetImportantCharacters().Select(pair => pair.Key).ToList();
                for (int i = 0; i < availableCharacters.Length; ++i)
                {
                    allowed[i] = important.Contains(availableCharacters[i]);
                }
            }
            else
            {
                //The player could select anything.  We don't know anything about his preferences.
                for (int i = 0; i < availableCharacters.Length; ++i)
                {
                    allowed[i] = true;
                }
            }

            //Figure out which ones we think he will choose.
            int[] bestIndices = AIHelper.GetBest(availableCharacters, allowed, charWeights, (character, localWeights) =>
            {
                //We are only considering things theoretically: Don't make any changes to the context
                //we are given.  We want a new local context for each character so variable changes for
                //one character don't influence the others.
                EventContext localContext = new EventContext(context);
                localContext.PushScope(character, scopeName);
                double directResult = operation.Evaluate(game, localContext, localWeights);
                //We need to take into account any prestige modifiers because we are throwing away
                //the local context now.
                return directResult + localWeights.MeasureAfter(localContext, game);
            });
            //Evaluate each of those character using our weights
            double result = 0.0;
            foreach(var bestIndex in bestIndices)
            {
                Character best = availableCharacters[bestIndex];
                //We are only considering things theoretically: Don't make any changes to the context
                //we are given.  We want a new local context for each character so variable changes for
                //one character don't influence the others.
                EventContext localContext = new EventContext(context);
                localContext.PushScope(best, scopeName);
                result += operation.Evaluate(game, localContext, weights);
                //We need to take into account any prestige modifiers because we are throwing away
                //the local context now.
                result += weights.MeasureAfter(localContext, game);
            }
            return result / bestIndices.Length;
        }
示例#13
0
        private double EvaluateChangedModifiers(Character character, EventContext context, Game game)
        {
            context.PushScope(character);
            List<PrestigeModifier> addedModifiers = new List<PrestigeModifier>();
            List<PrestigeModifier> removedModifiers = new List<PrestigeModifier>();
            game.GetChangedModifiers(context, addedModifiers, removedModifiers);

            double result = 0.0;
            if (addedModifiers.Count > 0 || removedModifiers.Count > 0)
            {
                foreach (var added in addedModifiers)
                {
                    result += added.DailyChange;
                }
                foreach (var removed in removedModifiers)
                {
                    result -= removed.DailyChange;
                }

            }
            context.PopScope();
            return result * 100.0 * 10.0;
        }
示例#14
0
 public Character[] FilterCharacters(ILogic requirements, EventContext context)
 {
     List<Character> matchingCharacters = new List<Character>();
     foreach (Character character in this.AllCharacters)
     {
         context.PushScope(character);
         if (requirements.Evaluate(context, this))
         {
             matchingCharacters.Add(character);
         }
         context.PopScope();
     }
     return matchingCharacters.ToArray();
 }