Esempio n. 1
0
 public UnitSelectionController(InputController inputController,
                                RaycastController raycastController, CoordFinder coordFinder)
 {
     this.inputController   = inputController;
     this.raycastController = raycastController;
     this.coordFinder       = coordFinder;
 }
 public UnitViewFactory(Dictionary <string, UnitInfo> unitInfos, UnitView unitPrefab,
                        CoordFinder coordFinder, Camera mainCamera)
 {
     this.unitInfos   = unitInfos;
     this.unitPrefab  = unitPrefab;
     this.coordFinder = coordFinder;
     this.mainCamera  = mainCamera;
 }
Esempio n. 3
0
    // spawn an animal in the
    void Spawn()
    {
        Vector2 position = CoordFinder.SearchCoord(transform, topCorner, bottomCorner, rightCorner, leftCorner);

        // spawn animal
        Instantiate(animals[Random.Range(0, 3)], new Vector3(position.x, 0.5f, position.y), Quaternion.identity, transform);
        currentTime = spawnTime + Time.time;
    }
Esempio n. 4
0
 public BattleSimulationPresenter(CoordFinder tile, BoardPresenter board,
                                  ISimulationTick tickables, IReset resettables)
 {
     this.tile        = tile;
     this.board       = board;
     this.tickables   = tickables;
     this.resettables = resettables;
 }
Esempio n. 5
0
    protected IEnumerator MovementRoutine()
    {
        while (true)
        {
            //animal just spawned or stopped. Wait some times
            yield return(new WaitForSeconds(idleTime));

            //choose destination
            bool    isDistant = false;
            Vector2 coords    = Vector2.zero;
            while (!isDistant)
            {
                coords = CoordFinder.SearchCoord(transform.parent, spawner.topCorner, spawner.bottomCorner, spawner.rightCorner, spawner.leftCorner);
                if (Vector2.Distance(coords, new Vector2(transform.position.x, transform.position.z)) >= minimumDistance)
                {
                    isDistant = true;
                }
                yield return(new WaitForSeconds(thinkingTime));
            }
            destination = new Vector3(coords.x + transform.parent.position.x, transform.position.y, coords.y + transform.parent.position.z);
            //start moving to destination
            animator.SetBool("Move", true);
            navigator.enabled = true;
            yield return(new WaitForSeconds(0f));

            navigator.SetDestination(destination);
            //Debug.Log("Destination: "+destination);
            yield return(new WaitForSeconds(thinkingTime));

            //check when we arrive at the destination
            bool arrived = false;
            while (!arrived)
            {
                if (System.Math.Abs(destination.x - transform.position.x) < EPSILON && System.Math.Abs(destination.z - transform.position.z) < EPSILON)
                {
                    arrived = true;
                }
                yield return(new WaitForSeconds(thinkingTime));
            }
            //Debug.Log("Arrived");
            //destination reached. Stop animation
            animator.SetBool("Move", false);
            //stop moving because i'm arrived
            navigator.enabled = false;
        }
    }
Esempio n. 6
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);
        }
 public MovementController(BoardPresenter board, CoordFinder finder)
 {
     this.board  = board;
     this.finder = finder;
 }
 public CoordFinderBySelectedPlayer(CoordFinder coordFinder, BattleSetupUI battleSetupUI)
 {
     this.coordFinder   = coordFinder;
     this.battleSetupUI = battleSetupUI;
 }
 public UnitViewCoordChangedHandler(CoordFinder coordFinder) =>
 this.coordFinder = coordFinder;
 public TargetDebugController(Board board, CoordFinder coordFinder, DebugInfo debugInfo)
 {
     this.board       = board;
     this.coordFinder = coordFinder;
     this.debugInfo   = debugInfo;
 }