Exemple #1
0
        // ------------------ Methods

        override protected void Awake()
        {
            base.Awake();
            Debug.Log("GameController.Awake()");


            AudioController.Instantiate();
            InputController.Instantiate();
            ResourceController.Instantiate();
            TickController.Instantiate();
            ViewController.Instantiate();
            GameController.OnDestroying += GameController_OnDestroying;


            Application.targetFrameRate = 30;

            SetupPools();
            SetupPoolObserver();

            //order matters
            //1 - Systems that depend on entities will internally listen for entity creation before reacting - nice!
            SetupSystems();

            //2
            SetupEntities();
        }
Exemple #2
0
        // ------------------ Methods

        override protected void Awake()
        {
            base.Awake();
            Debug.Log("GameController.Awake()");


            GameController.OnDestroying += GameController_OnDestroying;
            TickController.Instantiate();
            AudioController.Instantiate();
            InputController.Instantiate();
            ViewController.Instantiate();
            ResourceController.Instantiate();

            Application.targetFrameRate = 30;
            _screenBounds = UnityEngineReplacementUtility.Convert(GameUtility.GetOrthographicBounds(Camera.main));


            SetupPools();
            SetupPoolObserver();

            //order matters
            //1 - Systems that depend on entities will internally listen for entity creation before reacting - nice!
            SetupSystems();

            //2
            SetupEntities();

            //place a ball in the middle of the screen w/ velocity
            _pool.CreateEntity().willStartNextRound = true;
        }
        ///<summary>
        /// Creates Input, View and Interaction components:
        /// Creates different move processors
        /// for each character on board, registers them in controllers.
        /// Creates interactors and passes created level and view to them.
        /// </summary>
        public void InvokeState()
        {
            var level     = levelFactory.CreateLevel();
            var inputLoop = new InputLoop();
            var playView  = new ConsolePlayView();

            var playerMoveInteractor = new PlayerMoveInteractor(level, playView);
            var mobMoveInteractor    = new MobMoveInteractor(level, playView);
            var saveGameInteractor   = new SaveGameInteractor(level);
            var exitGameInteractor   = new ExitGameInteractor(level);
            var inventoryInteractor  = new InventoryInteractor(level, playView);

            var moveProcessor            = new MoveProcessor(playerMoveInteractor);
            var saveAndExitGameProcessor = new SaveAndExitGameProcessor(exitGameInteractor, saveGameInteractor);
            var inventoryProcessor       = new InventoryProcessor(inventoryInteractor);

            var keyboardController = new KeyboardController(level, OfflinePlayerLogin);
            var tickController     = new TickController();

            keyboardController.AddInputProcessor(moveProcessor);
            keyboardController.AddInputProcessor(saveAndExitGameProcessor);
            keyboardController.AddInputProcessor(inventoryProcessor);

            inputLoop.AddUpdatable(keyboardController);
            inputLoop.AddFixedUpdatable(tickController);

            if (!level.ContainsPlayer(OfflinePlayerLogin))
            {
                level.AddPlayerAtEmpty(OfflinePlayerLogin);
            }

            level.CurrentPlayer = level.GetPlayer(OfflinePlayerLogin);

            var mobs = level.Mobs;

            foreach (var mob in mobs)
            {
                var mobMoveProcessor = new MobMoveProcessor(mob, mobMoveInteractor);
                tickController.AddTickProcessor(mobMoveProcessor);
                mob.OnDie += (sender, args) =>
                {
                    level.Mobs.Remove(mob);
                    tickController.RemoveTickProcessor(mobMoveProcessor);
                };
            }

            level.CurrentPlayer.OnDie += (sender, args) =>
            {
                inputLoop.Stop();
                saveGameInteractor.DeleteSaving();
            };

            exitGameInteractor.OnExit += (sender, player) =>
            {
                inputLoop.Stop();
            };

            playView.Draw(level);
            inputLoop.Start();
        }
Exemple #4
0
        public Guid InitTimer(ETimerType timerType, TickController controller, int interval, Guid guid)
        {
            switch (timerType)
            {
            case ETimerType.System:
            {
                System.Timers.Timer wTimer = new System.Timers.Timer();
                wTimer.Interval = interval * 1000;
                wTimer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);

                TickTimers.Add(guid, new TTimer {
                        Guid = guid, Type = timerType, Timer = wTimer, Controller = controller
                    });

                wTimer.Start();
            }
            break;

            case ETimerType.Form:
            {
                System.Windows.Forms.Timer wTimer = new System.Windows.Forms.Timer();
                wTimer.Interval = interval * 1000;
                wTimer.Tick    += new EventHandler(Timer_Tick);

                TickTimers.Add(guid, new TTimer {
                        Guid = guid, Type = timerType, Timer = wTimer, Controller = controller
                    });

                wTimer.Start();
            }
            break;
            }

            return(guid);
        }
 void Awake()
 {
     tickController      = GetComponent <TickController>();
     selectionController = GetComponent <SelectionController>();
     spawningMode        = GetComponent <SpawningMode>();
     workersController   = GetComponent <WorkersController>();
     shopBooster         = GetComponent <ShopBooster>();
 }
 private void Start()
 {
     tickController = GetComponent <TickController>();
     if (trackCurCmndUI)
     {
         TickController.TicksEvent += CommandUIsTracker;
     }
     CurCommandsList = mainCommandsList;
 }
Exemple #7
0
        public void InitTickTimer(ETickTimer eTimer, TickController tickController, double interval)
        {
            System.Windows.Forms.Timer wTimer = new System.Windows.Forms.Timer();
            wTimer.Tick    += new System.EventHandler(Timer_Tick);
            wTimer.Interval = (int)(interval * 1000);

            TickTimers.Add(eTimer, new TTickTimer {
                Timer = wTimer, Controller = tickController
            });

            wTimer.Enabled = true;
            wTimer.Start();
        }
Exemple #8
0
        public void InvokeState()
        {
            var level     = levelFactory.CreateLevel();
            var inputLoop = new InputLoop();
            var playView  = new VoidView();

            var inputController = new ServerInputController(level, newSessionId, inputService);

            var exitGameInteractor   = new ExitGameInteractor(level, inputController);
            var playerMoveInteractor = new PlayerMoveInteractor(level, playView, inputController);
            var mobMoveInteractor    = new MobMoveInteractor(level, playView, inputController);
            var inventoryInteractor  = new InventoryInteractor(level, playView);

            levelFactory.SetPlayerFactory(new NetworkPlayerFactory(exitGameInteractor));

            var moveProcessor      = new MoveProcessor(playerMoveInteractor);
            var exitGameProcessor  = new ExitGameProcessor(exitGameInteractor);
            var inventoryProcessor = new InventoryProcessor(inventoryInteractor, inputController);

            var tickController = new TickController();

            inputController.AddInputProcessor(moveProcessor);
            inputController.AddInputProcessor(inventoryProcessor);
            inputController.AddInputProcessor(exitGameProcessor);

            inputLoop.AddFixedUpdatable(tickController);
            inputLoop.AddUpdatable(inputController);

            level.CurrentPlayer = new Player(DummyLogin, level, new Position(-1, -1));

            var mobs = level.Mobs;

            foreach (var mob in mobs)
            {
                var mobMoveProcessor = new MobMoveProcessor(mob, mobMoveInteractor);
                tickController.AddTickProcessor(mobMoveProcessor);
                mob.OnDie += (sender, args) =>
                {
                    level.Mobs.Remove(mob);
                    tickController.RemoveTickProcessor(mobMoveProcessor);
                };
            }

            inputLoop.Start();
        }
Exemple #9
0
        //Called during GameController.Destroy();
        private void GameController_OnDestroying(GameController instance)
        {
            Debug.Log("GameController.Destroy()");

            GameController.OnDestroying -= GameController_OnDestroying;

            AudioController.Destroy();
            InputController.Destroy();
            ResourceController.Destroy();
            TickController.Destroy();
            ViewController.Destroy();
            _unpausableUpdateSystems.DeactivateReactiveSystems();

            Pools.pool.Reset();
            DestroyPoolObserver();

            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
Exemple #10
0
        //Called during GameController.Destroy();
        private void GameController_OnDestroying(GameController instance)
        {
            Debug.Log("GameController.Destroy()");

            GameController.OnDestroying -= GameController_OnDestroying;

            if (AudioController.IsInstantiated())
            {
                AudioController.Destroy();
            }
            if (InputController.IsInstantiated())
            {
                InputController.Destroy();
            }
            if (ViewController.IsInstantiated())
            {
                ViewController.Destroy();
            }
            if (TickController.IsInstantiated())
            {
                TickController.Destroy();
            }
            if (ResourceController.IsInstantiated())
            {
                ResourceController.Destroy();
            }


            _pausableUpdateSystems.DeactivateReactiveSystems();
            _unpausableUpdateSystems.DeactivateReactiveSystems();

            Pools.pool.Reset();
            DestroyPoolObserver();

            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
Exemple #11
0
        IEnumerator Start()
        {
            #region Config

            log.Info("\n\nStart");
            var units                 = new UnitInfoLoader().Load();
            var saveDataLoader        = new SaveInfoLoader();
            var saves                 = saveDataLoader.Load();
            var decisionTreeLoader    = new DecisionTreeLoader();
            var decisionTreeComponent = decisionTreeLoader.Load();

            #endregion
            #region Infrastructure

            var tickController  = new TickController();
            var inputController = new InputController(tickController);
            //TODO: implement event bus that won't allocate(no delegates)
            var eventBus = new EventBus();            //TODO: stop using eventbus Ievent interface to remove reference on that library from model
            EventBus.Log     = m => log.Info($"{m}"); //TODO: remove that lmao
            EventBus.IsLogOn = () => DebugController.Info.IsDebugOn;

            #endregion
            #region View

            var mainCamera                  = Camera.main;
            var tileSpawner                 = new TilePresenter(TileStartPoints, new TileViewFactory(TileViewPrefab));
            var coordFinder                 = new CoordFinder(TileStartPoints);
            var unitViewFactory             = new UnitViewFactory(units, UnitViewPrefab, coordFinder, mainCamera);
            var unitViewCoordChangedHandler = new UnitViewCoordChangedHandler(coordFinder);
            var boardPresenter              = new BoardPresenter(unitViewCoordChangedHandler);

            var playerPresenterContext = new PlayerPresenterContext(
                new PlayerPresenter(unitViewFactory, unitViewCoordChangedHandler),
                new PlayerPresenter(unitViewFactory, unitViewCoordChangedHandler));

            #endregion
            #region Model
            var decisionTreeLookup = new DecisionTreeLookup();

            var decisionTreeCreatorVisitor = new DecisionTreeCreatorVisitor(eventBus,
                                                                            d => new LoggingDecorator(d, DebugController.Info), decisionTreeLookup);

            var unitFactory = new UnitFactory(units, new DecisionFactory(
                                                  decisionTreeCreatorVisitor, decisionTreeComponent));

            //TODO: replace board/bench dictionaries with array?
            var playerContext = new PlayerContext(new Player(unitFactory), new Player(unitFactory));
            var board         = new Board();
            var aiHeap        = new AiHeap();
            var aiContext     = new AiContext(board, aiHeap);

            #endregion
            #region Shared

            var worldContext = new PlayerSharedContext(playerContext, playerPresenterContext, BattleSetupUI);

            #endregion
            #region Controller

            var raycastController = new RaycastController(mainCamera,
                                                          LayerMask.GetMask("Terrain", "GlobalCollider"), LayerMask.GetMask("Unit"));

            var unitSelectionController = new UnitSelectionController(inputController,
                                                                      raycastController, coordFinder);

            var unitTooltipController = new UnitTooltipController(UnitTooltipUI,
                                                                  unitSelectionController);

            #endregion
            #region Unit drag

            var battleStateController = new BattleStateController(BattleSimulationUI);
            var unitDragController    = new UnitDragController(raycastController,
                                                               new CoordFinderBySelectedPlayer(coordFinder, BattleSetupUI),
                                                               inputController, unitSelectionController,
                                                               new CanStartDrag(battleStateController, BattleSetupUI));

            var tileHighlightController = new TileHighlighterController(tileSpawner,
                                                                        unitDragController);

            var unitMoveController = new UnitMoveController(worldContext, unitDragController);

            #endregion
            #region Battle simulation

            var movementController  = new MovementController(boardPresenter, coordFinder);
            var attackController    = new AttackController(boardPresenter, unitTooltipController);
            var animationController = new AnimationController(boardPresenter);
            eventBus.Register <StartMoveEvent>(movementController, animationController); //TODO: register implicitly?
            eventBus.Register <FinishMoveEvent>(movementController);
            eventBus.Register <RotateEvent>(movementController);
            eventBus.Register <UpdateHealthEvent>(attackController);
            eventBus.Register <DeathEvent>(attackController);
            eventBus.Register <IdleEvent>(animationController);
            eventBus.Register <StartAttackEvent>(animationController);

            var battleSimulationPresenter = new BattleSimulationPresenter(coordFinder,
                                                                          boardPresenter, movementController, movementController);

            var battleSimulation = new BattleSimulation(aiContext, board, aiHeap);

            var realtimeBattleSimulationController = new RealtimeBattleSimulationController(
                movementController, battleSimulation);

            #endregion
            #region Debug

            var battleSimulationDebugController = new BattleSimulationDebugController(
                battleSimulation, BattleSimulationUI,
                aiContext, playerContext, playerPresenterContext, realtimeBattleSimulationController,
                battleSimulationPresenter);

            var battleSaveController = new BattleSaveController(playerContext,
                                                                playerPresenterContext, BattleSaveUI, saveDataLoader, saves,
                                                                battleSimulationDebugController);

            var battleSetupController = new BattleSetupController(playerContext,
                                                                  playerPresenterContext, BattleSetupUI);

            var unitModelDebugController = new UnitModelDebugController(playerContext, board, ModelUI,
                                                                        DebugController.Info, unitSelectionController);

            var takenCoordDebugController = new TakenCoordDebugController(board, DebugController,
                                                                          tileSpawner);

            var targetDebugController = new TargetDebugController(
                board, coordFinder, DebugController.Info);

            var uiDebugController = new UIDebugController(
                BattleSetupUI, BattleSaveUI, BattleSimulationUI,
                unitModelDebugController);

            #endregion

            yield return(null);

            #region Infrastructure

            tickController.InitObservable(takenCoordDebugController, targetDebugController,
                                          uiDebugController, unitModelDebugController, realtimeBattleSimulationController,
                                          DebugController); //TODO: register implicitly?
            inputController.InitObservables();

            #endregion
            #region View

            BattleSetupUI.SetDropdownOptions(units.Keys.ToList());
            BattleSaveUI.SubToUI(saves.Keys.ToList());
            tileSpawner.SpawnTiles();

            #endregion
            decisionTreeCreatorVisitor.Init();
            #region Controller

            unitSelectionController.SubToInput(disposable);
            battleStateController.SubToUI();
            unitDragController.SubToUnitSelection(disposable);
            tileHighlightController.SubToDrag(disposable);
            unitMoveController.SubToDrag(disposable);
            unitTooltipController.SubToUnitSelection(disposable);

            #endregion
            #region Debug

            battleSaveController.SubToUI();
            battleSetupController.SubToUI();
            unitModelDebugController.SubToUnitSelection(disposable);
            battleSimulationDebugController.SubToUI();
            DebugController.Init(UnitTooltipUI);

            #endregion

            MonoBehaviourCallBackController.StartUpdating(tickController);
        }
Exemple #12
0
 public Guid InitTimer(ETimerType timerType, TickController controller, int interval)
 {
     return(InitTimer(timerType, controller, interval, Guid.NewGuid()));
 }