コード例 #1
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
        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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.CurrentCharacter.PrestigeChange(change);
 }
コード例 #3
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
 }
コード例 #5
0
ファイル: Event.cs プロジェクト: jenn0108/CourtIntrigue
        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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
        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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
        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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.PushScope(context.GetScopedObjectByName(scopeName));
     operation.Execute(result, game, context);
     context.PopScope();
 }
コード例 #9
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     result.GiveTargetTurn();
 }
コード例 #11
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     Debugger.Break();
 }
コード例 #12
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     game.CreateChild(context.CurrentCharacter, context.CurrentCharacter.Spouse);
 }
コード例 #13
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     result.Continue();
 }
コード例 #14
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
        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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     game.GiveJobTo(game.GetJobById(jobId), context.CurrentCharacter);
 }
コード例 #19
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 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
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.CurrentCharacter.SpendGold(gold);
 }
コード例 #22
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
 public void Execute(EventResults result, Game game, EventContext context)
 {
     context.CurrentCharacter.MultiplyObserveModifier(multiplier);
 }
コード例 #23
0
ファイル: Execute.cs プロジェクト: jenn0108/CourtIntrigue
        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
ファイル: Game.cs プロジェクト: jenn0108/CourtIntrigue
        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;
        }