protected override void Enter() { PerformingActionStateData performingActionStateData = data as PerformingActionStateData; m_Action = performingActionStateData.action; m_Source = performingActionStateData.source; m_TargetCoordinate = performingActionStateData.targetCoordinate; m_Target = performingActionStateData.target; if (m_TargetCoordinate != null) { PerformAction(); } else if (m_Action is ISelectableTargetAction) { Coordinate currentCoordinate = mapController.GetPositionOfEntity(m_Source.Id); m_Paths = ShowPaths(currentCoordinate, m_Action); foreach (Coordinate coord in m_Paths.Keys) { mapController.GetMapTileAtCoordinate(coord).isHighlighted = true; } } }
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); } }