Пример #1
0
        protected override void Enter()
        {
            SelectedStateData selectedStateData = data as SelectedStateData;

            m_CurrentlySelectedCoordinate = selectedStateData.coordinate;
            MapTile mapTile = mapController.GetMapTileAtCoordinate(m_CurrentlySelectedCoordinate);

            m_CurrentlySelectedEntity = mapTile.entities.Count > 0 ? mapTile.entities[0] : null;

            if (m_CurrentlySelectedEntity != null)
            {
                mapTile.isHighlighted = true;
                MoveAction moveAction = m_CurrentlySelectedEntity.GetAction <MoveAction>();

                if (moveAction != null && moveAction.actionPoints <= m_CurrentlySelectedEntity.ActionPoints)
                {
                    m_Paths = ShowPaths(m_CurrentlySelectedCoordinate, moveAction);

                    foreach (Coordinate coord in m_Paths.Keys)
                    {
                        mapController.GetMapTileAtCoordinate(coord).isHighlighted = true;
                    }
                }
            }
        }
Пример #2
0
        public override void HandleInput(InputEvent inputEvent)
        {
            if (inputEvent is MapTileClickedInput)
            {
                MapTileClickedInput mapTileClickedInput = inputEvent as MapTileClickedInput;

                MapTile mapTile = mapController.GetMapTileAtCoordinate(mapTileClickedInput.coordinate);

                if (mapTile.entities.Count > 0 && player.GetEntity(mapTile.entities[0].Id) != null)
                {
                    SelectedStateData selectedStateData = ScriptableObject.CreateInstance <SelectedStateData>();
                    selectedStateData.coordinate = mapTileClickedInput.coordinate;

                    dispatcher.Dispatch <SelectedState>(selectedStateData);
                }
            }

            if (inputEvent is CycleSelectionInput)
            {
                Entity availableEntity = player.entities.Find(entity => entity.ActionPoints > 0);
                if (availableEntity != null)
                {
                    Coordinate        coordinate        = mapController.GetPositionOfEntity(availableEntity.Id);
                    SelectedStateData selectedStateData = ScriptableObject.CreateInstance <SelectedStateData>();
                    selectedStateData.coordinate = coordinate;

                    dispatcher.Dispatch <SelectedState>(selectedStateData);
                }
            }

            if (inputEvent is OpenResearchInput)
            {
                dispatcher.Dispatch <ResearchState>();
            }

            if (inputEvent is EndOfTurnInput)
            {
                dispatcher.Dispatch <WaitingState>();
            }
        }
Пример #3
0
        public override void HandleInput(InputEvent inputEvent)
        {
            if (inputEvent is MapTileClickedInput)
            {
                MapTileClickedInput mapTileClickedInput = inputEvent as MapTileClickedInput;
                MoveAction          moveAction          = m_CurrentlySelectedEntity.GetAction <MoveAction>();

                if (m_Paths.ContainsKey(mapTileClickedInput.coordinate) && moveAction.CanExecute(player, m_CurrentlySelectedEntity, mapTileClickedInput.coordinate, null))
                {
                    PerformingActionStateData stateData = ScriptableObject.CreateInstance <PerformingActionStateData>();
                    stateData.action           = moveAction;
                    stateData.source           = m_CurrentlySelectedEntity;
                    stateData.targetCoordinate = mapTileClickedInput.coordinate;

                    dispatcher.Dispatch <PerformingActionState>(stateData);
                }
                else if (mapTileClickedInput.mapTile.entities.Count > 0 && player.GetEntity(mapTileClickedInput.mapTile.entities[0].Id) != null)
                {
                    SelectedStateData selectedStateData = ScriptableObject.CreateInstance <SelectedStateData>();
                    selectedStateData.coordinate = mapTileClickedInput.coordinate;

                    dispatcher.Dispatch <SelectedState>(selectedStateData);
                }
                else
                {
                    dispatcher.Dispatch <IdleState>();
                }
            }

            if (inputEvent is CycleSelectionInput)
            {
                int    currentIndex    = player.entities.FindIndex(entity => entity.Id == CurrentlySelectedEntity.Id);
                Entity availableEntity = player.entities
                                         .GetRange(currentIndex + 1, player.entities.Count - currentIndex - 1)
                                         .Find(entity => entity.ActionPoints > 0);

                if (availableEntity != null)
                {
                    Coordinate        coordinate        = mapController.GetPositionOfEntity(availableEntity.Id);
                    SelectedStateData selectedStateData = ScriptableObject.CreateInstance <SelectedStateData>();
                    selectedStateData.coordinate = coordinate;

                    dispatcher.Dispatch <SelectedState>(selectedStateData);
                }
                else
                {
                    dispatcher.Dispatch <IdleState>();
                }
            }

            if (inputEvent is ActionButtonClickedInput)
            {
                ActionButtonClickedInput  actionButtonClickedInput = inputEvent as ActionButtonClickedInput;
                PerformingActionStateData stateData = ScriptableObject.CreateInstance <PerformingActionStateData>();
                stateData.action = m_CurrentlySelectedEntity.GetAction(actionButtonClickedInput.actionType);
                stateData.source = m_CurrentlySelectedEntity;
                stateData.target = actionButtonClickedInput.target;

                dispatcher.Dispatch <PerformingActionState>(stateData);
            }
        }