Exemple #1
0
        /// <summary>
        /// Decorates an existing model with a given decorator that is produced by the given function
        /// </summary>
        /// <typeparam name="TDecoratee"><see cref="GameModel"/> derived type to decorate.</typeparam>
        /// <typeparam name="TDecorater"><see cref="GameModel"/> derived type that will decorate it.</typeparam>
        /// <param name="starter"><see cref="IGameStarter"/> Object.</param>
        /// <param name="decoraterCtor">Functions which creates the decorator from the given model</param>
        public static void Decorate <TDecoratee, TDecorater>(this IGameStarter starter, Func <TDecoratee, TDecorater> decoraterCtor)
            where TDecoratee : GameModel where TDecorater : TDecoratee
        {
            var baseType = typeof(TDecoratee);
            var model    = starter.Models
                           .OfType <TDecoratee>()
                           .SingleOrDefault();

            if (model == null)
            {
                throw new ArgumentException($"No model or multiple models registered with type '{baseType.Name}'. It must be exactly ONE model with this type to decorate it!");
            }
            var decorater = decoraterCtor(model);

            starter.Replace <TDecoratee, TDecorater>(decorater);
            m_ledger.Add(new GameModelLedgerEntry(typeof(TDecoratee), typeof(TDecorater)));
        }
Exemple #2
0
 protected override void OnGameStart(Game game, IGameStarter gameStarterObject)
 {
     if (!(game.GameType is Campaign))
     {
         return;
     }
     // Difficulty model
     gameStarterObject.Replace <DefaultDifficultyModel, CustomizableDifficultyModel>();
     // Xp Models
     gameStarterObject.Replace <DefaultGenericXpModel, CustomizableGenericXpModel>();
     gameStarterObject.Replace <StoryModeGenericXpModel, CustomizableStoryModeGenericXpModel>();
     // Wage Models
     gameStarterObject.Replace <DefaultPartyWageModel, CustomizablePartyWageModel>();
     gameStarterObject.Replace <StoryModePartyWageModel, CustomizableStoryModePartyWageModel>();
     // CombatXp Models
     gameStarterObject.Replace <DefaultCombatXpModel, CustomizableCombatXpModel>();
     gameStarterObject.Replace <StoryModeCombatXpModel, CustomizableStoryModeCombatXpModel>();
     ((CampaignGameStarter)gameStarterObject).AddBehavior(new CustomCampaignOptionsBehaviour());
 }