Example #1
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);
            }
        }
Example #2
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);
                }
            }
        }