예제 #1
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();
            }
        }
예제 #2
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.CurrentCharacter.PrestigeChange(change);
 }
예제 #3
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     Dictionary<string, object> computedParameters = new Dictionary<string, object>();
     foreach (var pair in parameters)
     {
         computedParameters.Add(pair.Key, context.GetScopedObjectByName(pair.Value));
     }
     result.AddObservableInfo(new InformationInstance(game.GetInformationById(informationId), computedParameters, game.CurrentTime), chance, null);
 }
예제 #4
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
 }
예제 #5
0
        public void Execute(EventResults result, Game game, EventContext context)
        {
            game.Log(context.CurrentCharacter.Fullname + ": Event:" + this.CreateActionDescription(context));

            //DirectExecute always happens if it is present.
            if (DirectExecute != null)
                DirectExecute.Execute(result, game, context);

            EventOption[] options = GetAvailableOptions(context, game);
            if (options.Length > 0)
            {
                int[] willpowerCost = new int[options.Length];
                for(int i = 0; i < options.Length; ++i)
                {
                    int maxCost = options[i].GetCostToTake(context.CurrentCharacter) - options[i].GetCostToAvoid(context.CurrentCharacter);
                    for(int j = 0; j < options.Length; ++j)
                    {
                        if (i == j)
                            continue;

                        maxCost = Math.Max(maxCost, options[j].GetCostToAvoid(context.CurrentCharacter));
                    }
                    willpowerCost[i] = maxCost;
                }
                //If there are options, the character must choose one.
                int chosenIndex = context.CurrentCharacter.ChooseOption(options, willpowerCost, context, this);
                EventOption chosen = options[chosenIndex];
                if(chosen != null && chosen.DirectExecute != null)
                {
                    context.CurrentCharacter.SpendWillpower(willpowerCost[chosenIndex]);
                    //Execute the option activity.
                    chosen.DirectExecute.Execute(result, game, context);
                }
            }
        }
예제 #6
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);
            }
        }
예제 #7
0
        public void Execute(EventResults result, Game game, EventContext context)
        {
            if (XmlHelper.IsSpecialName(varName))
                throw new InvalidOperationException("Cannot assign to special properties: " + varName);

            context.SetVariable(context.CurrentCharacter, varName, newValue.Calculate(context, game));
        }
예제 #8
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.PushScope(context.GetScopedObjectByName(scopeName));
     operation.Execute(result, game, context);
     context.PopScope();
 }
예제 #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 void Execute(EventResults result, Game game, EventContext context)
 {
     result.GiveTargetTurn();
 }
예제 #11
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     Debugger.Break();
 }
예제 #12
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     game.CreateChild(context.CurrentCharacter, context.CurrentCharacter.Spouse);
 }
예제 #13
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     result.Continue();
 }
예제 #14
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();
 }
예제 #15
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     OpinionModifierInstance mod = game.CreateOpinionModifier(identifier, context.GetScopedObjectByName(character) as Character);
     context.CurrentCharacter.AddOpinionModifier(mod);
 }
예제 #16
0
        public void Execute(EventResults result, Game game, EventContext context)
        {
            const int RandomPrecision = 1000000;

            int val = game.GetRandom(RandomPrecision);
            for(int i = 0; i < outcomes.Length; ++i)
            {
                int myCutoff = (int)(chances[i] * RandomPrecision);
                if (val < myCutoff)
                {
                    outcomes[i].Execute(result, game, context);
                    return;
                }

                val -= myCutoff;
            }
        }
예제 #17
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     for(int i = 0; i < instructions.Length; ++i)
     {
         instructions[i].Execute(result, game, context);
     }
 }
예제 #18
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     game.GiveJobTo(game.GetJobById(jobId), context.CurrentCharacter);
 }
예제 #19
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     if(requirements.Evaluate(context, game))
     {
         thenExecute.Execute(result, game, context);
     }
     else
     {
         elseExecute.Execute(result, game, context);
     }
 }
예제 #20
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     Room targetRoom = game.GetRoomById(roomId);
     if (context.CurrentCharacter.CurrentRoom.Priority < targetRoom.Priority)
         throw new Exception("Can only move from a higher priority room to a lower one.");
     context.CurrentCharacter.CurrentRoom = targetRoom;
 }
예제 #21
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.CurrentCharacter.SpendGold(gold);
 }
예제 #22
0
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.CurrentCharacter.MultiplyObserveModifier(multiplier);
 }
예제 #23
0
        public void Execute(EventResults result, Game game, EventContext context)
        {
            Dictionary<string, object> computedParameters = new Dictionary<string, object>();
            foreach (var pair in parameters)
            {
                computedParameters.Add(pair.Key, context.GetScopedObjectByName(pair.Value));
            }
            EventContext newContext = new EventContext(context.CurrentCharacter, computedParameters);
            game.GetEventById(eventid).Execute(result, game, newContext);

            //We need to commit any changes that were performed on the new context to our old one.
            newContext.CommitTo(context);
        }
예제 #24
0
        private bool ExecuteAction(Character character, ActionDescriptor actionDescriptor, ISet<Character> finishedCharacters, Dictionary<Room, List<ObservableInformation>> informations)
        {
            //Find a matching event to execute.
            Event eventToPlay = eventManager.FindEventForAction(actionDescriptor, this);

            if (eventToPlay != null)
            {
                //We pass in an event results instead of accepting a return value because we want all
                //the event logic along the way to touch the same instance instead of having to worry
                //about merging a number of different instances.
                EventResults results = new EventResults();
                EventContext context = new EventContext(actionDescriptor);
                eventToPlay.Execute(results, this, context);

                //We need to commit any changes that occurred.
                context.Commit();

                //Did the target get their turn consumed?
                if (!results.TargetGetsTurn && actionDescriptor.Target != null)
                {
                    //Remove the target from the room (since they are busy) and make sure they don't
                    //get their normal action.
                    finishedCharacters.Add(actionDescriptor.Target);
                    actionDescriptor.Target.MarkBusy();
                }

                if(results.HasInformation)
                {
                    //Add any information to the list of things that characters in the room might observe.
                    List<ObservableInformation> infos = null;
                    if (!informations.TryGetValue(character.CurrentRoom, out infos))
                    {
                        infos = new List<ObservableInformation>();
                        informations.Add(character.CurrentRoom, infos);
                    }
                    infos.AddRange(results.ObservableInformation);
                }

                if (results.ContinueTurn)
                {
                    //The turn is incomplete.  The character isn't busy or finished yet.
                    return false;
                }
            }

            //This character is now done.
            finishedCharacters.Add(character);

            // The initiator always gets their turn consumed so remove them from the room.
            character.MarkBusy();

            //The turn completed successfully.
            return true;
        }