예제 #1
0
        private void RefreshSquareTypeSelector()
        {
            var selectedPositions = mapEditor.SelectedPositions;

            if (selectedPositions.Count == 1)
            {
                SquareType sqType = Map.GetSquareTypeAt(selectedPositions.FirstOrDefault());
                squareTypeSelector.SelectBySquareType(sqType);
            }
            else
            {
                bool       wasFirst  = false;
                SquareType firstType = null;

                foreach (var pos in selectedPositions)
                {
                    SquareType type = Map.GetSquareTypeAt(pos);
                    if (!wasFirst)
                    {
                        firstType = type;
                        wasFirst  = true;
                    }
                    else if (firstType != type)
                    {
                        squareTypeSelector.DeselectAll();
                        return;
                    }
                }

                squareTypeSelector.SelectBySquareType(firstType);
            }
        }
예제 #2
0
        // returns whether this character could step to given position (ignoring available action points)
        public bool CanStepToPosition(Position position, Game game)
        {
            if (!game.GetMap().IsPositionWithin(position))
            {
                return(false);
            }
            if (Position.GetDistance(position) != 1)
            {
                return(false);
            }

            if (!game.GetMap().IsPositionPermeable(position))
            {
                return(false);
            }

            SquareType squareType = game.GetMap().GetSquareTypeAt(position);

            if (squareType != null)
            {
                if (!squareType.AllowsCharacter(this))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        private void RefreshInfo()
        {
            if (list.SelectedItem != null)
            {
                visualSelector.Visibility = Visibility.Hidden;

                tbID.IsEnabled = true;
                tbAllowedAttributes.IsEnabled   = true;
                tbForbiddenAttributes.IsEnabled = true;

                cbActionName.IsEnabled = true;

                bDelete.IsEnabled = true;

                SquareType squareType = (SquareType)((ListBoxItem)list.SelectedItem).Tag;

                tbID.Text = squareType.Name;
                tbAllowedAttributes.Text   = string.Join(" ", squareType.AllowedAttributes.ToArray());
                tbForbiddenAttributes.Text = string.Join(" ", squareType.ForbiddenAttributes.ToArray());
                RefreshActions(squareType.ActionName);

                iVisualImage.Source = (squareType.Visual?.BitmapFrame == null) ? DefaultResources.VisualPlaceholder : squareType.Visual.BitmapFrame;
                lVisualID.Content   = (squareType.Visual == null) ? "" : squareType.Visual.ID;
            }
            else
            {
                ClearInfo();
            }
        }
예제 #4
0
        private void squareTypeSelector_OnSquareTypeSelected(SquareType selectedSquareType)
        {
            SquareTypeSetEnum setType = SquareTypeSetEnum.None;

            var selectedPositions = mapEditor.SelectedPositions;

            foreach (var pos in selectedPositions)
            {
                // based on the first selected pos, if it already has given square type, we remove any type from each pos. else we set type for each.
                if (setType == SquareTypeSetEnum.None)
                {
                    if (Map.GetSquareTypeAt(pos) == selectedSquareType)
                    {
                        setType = SquareTypeSetEnum.Remove;
                    }
                    else
                    {
                        setType = SquareTypeSetEnum.Set;
                    }
                }
                if (setType == SquareTypeSetEnum.Set)
                {
                    Map.SetSquareTypeAt(pos, selectedSquareType);
                }
                else
                {
                    Map.RemoveSquareTypeAt(pos);
                }
            }

            RefreshSquareTypeSelector();
            mapEditor.Redraw();
        }
예제 #5
0
        private void bDelete_Click(object sender, RoutedEventArgs e)
        {
            ListBoxItem item       = (ListBoxItem)list.SelectedItem;
            SquareType  squareType = (SquareType)item.Tag;

            Project.Current.Config.Map.RemoveSquareType(squareType);
            list.SelectedItem = null;
            list.Items.Remove(item);
        }
예제 #6
0
 public void DeselectAll()
 {
     if (SelectedRow != null)
     {
         SelectedRow.Selected = false;
     }
     SelectedRow        = null;
     SelectedSquareType = null;
 }
예제 #7
0
        public int GetMovementCost(Position position, Config config)
        {
            SquareType squareType = GetSquareTypeAt(position);

            if (squareType != null)
            {
                return(GetMovementCost(squareType, config));
            }
            return(config.CharacterConfig.MovementActionPoints);
        }
예제 #8
0
 public void SetOrRemoveSquareTypeAt(Position position, SquareType squareType)
 {
     if (GetSquareTypeAt(position) == squareType)
     {
         Squares.Remove(position);
     }
     else
     {
         Squares[position] = squareType;
     }
 }
예제 #9
0
        private void tbForbiddenAttributes_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (list.SelectedItem == null || ((ListBoxItem)list.SelectedItem).Tag == null)
            {
                return;
            }

            ListBoxItem item       = (ListBoxItem)list.SelectedItem;
            SquareType  squareType = (SquareType)item.Tag;

            squareType.ForbiddenAttributes = tbForbiddenAttributes.Text.Split(' ').ToList();
        }
예제 #10
0
        private void cbActionName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (list.SelectedItem == null || ((ListBoxItem)list.SelectedItem).Tag == null || cbActionName.SelectedItem == null)
            {
                return;
            }

            ListBoxItem item       = (ListBoxItem)list.SelectedItem;
            SquareType  squareType = (SquareType)item.Tag;

            squareType.ActionName = (string)((ComboBoxItem)cbActionName.SelectedItem).Tag;
        }
예제 #11
0
        private ListBoxItem AddListBoxItem(SquareType squareType)
        {
            ListBoxItem listBoxItem = new ListBoxItem();

            listBoxItem.Tag = squareType;

            listBoxItem.Content = squareType.Name;

            list.Items.Add(listBoxItem);

            return(listBoxItem);
        }
예제 #12
0
        private void tbID_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (list.SelectedItem == null || ((ListBoxItem)list.SelectedItem).Tag == null)
            {
                return;
            }

            ListBoxItem item       = (ListBoxItem)list.SelectedItem;
            SquareType  squareType = (SquareType)item.Tag;

            squareType.Name = tbID.Text;

            item.Content = tbID.Text;
        }
예제 #13
0
        public int GetMovementCost(SquareType squareType, Config config)
        {
            if (Scheme == null || squareType.ActionName == null || squareType.ActionName == "")
            {
                return(config.CharacterConfig.MovementActionPoints);
            }

            SchemeFunction action = Scheme.GetFunctionByName(squareType.ActionName);

            if (action == null)
            {
                return(config.CharacterConfig.MovementActionPoints);
            }

            return(action.ActionPoints);
        }
예제 #14
0
        // removes squaretype and all its references/occurences
        public void RemoveSquareType(SquareType squareType)
        {
            SquareTypes.Remove(squareType);

            List <Position> keysToRemove = new List <Position>();

            foreach (var square in Squares)
            {
                if (square.Value == squareType)
                {
                    keysToRemove.Add(square.Key);
                }
            }

            keysToRemove.ForEach(pos => Squares.Remove(pos));
        }
예제 #15
0
        public void ExecuteSquareAction(SquareType squareType, Character actor, Game game)
        {
            if (squareType == null || Scheme == null || squareType.ActionName == null || squareType.ActionName == "")
            {
                return;
            }

            SchemeFunction action = Scheme.GetFunctionByName(squareType.ActionName);

            if (action == null)
            {
                throw new GameException($"No such action in map: {squareType.ActionName}");
            }

            action.Execute(SchemeObject, actor, game);
        }
예제 #16
0
        private void visualSelector_OnVisualSelected(Visual selectedVisual)
        {
            visualSelector.Visibility = Visibility.Hidden;

            if (list.SelectedItem == null || ((ListBoxItem)list.SelectedItem).Tag == null)
            {
                return;
            }

            ListBoxItem item       = (ListBoxItem)list.SelectedItem;
            SquareType  squareType = (SquareType)item.Tag;

            squareType.Visual = selectedVisual;

            RefreshInfo();
        }
예제 #17
0
        private void bAdd_Click(object sender, RoutedEventArgs e)
        {
            string newId = IdGenerator.Generate("squaretype");

            while (Project.Current.Config.Map.GetSquareTypeByName(newId) != null)
            {
                newId = IdGenerator.Generate("squaretype");
            }

            SquareType squareType = new SquareType(newId);

            Project.Current.Config.Map.SquareTypes.Add(squareType);
            var item = AddListBoxItem(squareType);

            list.SelectedItem = item;
        }
예제 #18
0
        private void Row_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                UCEVisualSelectorRow row = (UCEVisualSelectorRow)sender;

                if (SelectedRow != null)
                {
                    SelectedRow.Selected = false;
                }
                SelectedRow          = row;
                SelectedRow.Selected = true;

                SelectedSquareType = (SquareType)row.Tag;
                OnSquareTypeSelected?.Invoke(SelectedSquareType);
            }
        }
예제 #19
0
        public void SelectBySquareType(SquareType squareType)
        {
            if (SelectedRow != null)
            {
                SelectedRow.Selected = false;
            }

            foreach (var row_obj in spContainer.Children)
            {
                var row = (UCEVisualSelectorRow)row_obj;
                if (row.Tag == squareType)
                {
                    SelectedRow          = row;
                    SelectedRow.Selected = true;
                    SelectedSquareType   = squareType;
                    row.BringIntoView();
                    return;
                }
            }

            SelectedRow        = null;
            SelectedSquareType = null;
        }
예제 #20
0
 public void SetSquareTypeAt(Position position, SquareType squareType)
 {
     Squares[position] = squareType;
 }
예제 #21
0
        //After an object is selected, the current player can do some action with it (or they can do basic actions)
        public void DoAction(string actionName, params string[] actionParameters)
        {
            if (SelectedObject != null)
            {
                Log.Write($"Player [{CurrentPlayerNo}]: do '{actionName}' with object '{SelectedObject.Id}'");
            }
            else
            {
                Log.Write($"Player [{CurrentPlayerNo}]: do '{actionName}({string.Join(", ",actionParameters)})'");
            }



            if (actionName == BasicActions.Movement)
            {
                Character character = CurrentPlayer.Character;

                Position newPosition = new Position(character.Position.X, character.Position.Y);

                if (actionParameters[0] == MovementParameters.Norht)
                {
                    newPosition.Y -= 1;
                }
                else if (actionParameters[0] == MovementParameters.East)
                {
                    newPosition.X += 1;
                }
                else if (actionParameters[0] == MovementParameters.South)
                {
                    newPosition.Y += 1;
                }
                else if (actionParameters[0] == MovementParameters.West)
                {
                    newPosition.X -= 1;
                }

                // check if new position is within map borders
                if (!Map.IsPositionWithin(newPosition))
                {
                    throw new GameException("Invalid movement");
                }

                // if no special square at target position, or it has no associated action, the movement cost is the basic movement cost
                int MovementCost = Config.CharacterConfig.MovementActionPoints;

                // check square restrictions at new position
                SquareType squareType = Map.GetSquareTypeAt(newPosition);
                if (squareType != null)
                {
                    if (!squareType.AllowsCharacter(character))
                    {
                        throw new GameException("This character is not allowed to step on this square");
                    }
                    MovementCost = Map.GetMovementCost(squareType, Config);
                }

                if (MovementCost > CurrentPlayer.AvailableActionPoints)
                {
                    throw new GameException("Too few action points for movement");
                }

                character.Position = newPosition;
                CurrentPlayer.AvailableActionPoints -= MovementCost;

                // if character stepped on a square, we may have to call an action
                Map.ExecuteSquareAction(squareType, character, this);
            }
            else if (actionName == BasicActions.EndTurn)
            {
                NextPlayer();
            }
            else if (SelectedObject != null)
            {
                //Get action points to be removed on a successful action
                int actionPointsToRemove = SelectedObject.Scheme.GetFunctionByName(actionName).ActionPoints;

                if (actionPointsToRemove > CurrentPlayer.AvailableActionPoints)
                {
                    throw new GameException("Too few action points");
                }

                actionPointsToRemove = SelectedObject.ExecuteAction(actionName, CurrentPlayer.Character, this);

                CurrentPlayer.AvailableActionPoints -= actionPointsToRemove;
            }
            else
            {
                throw new GameException("Non-basic actions can only be applied to objects");
            }
        }
예제 #22
0
 public Square(SquareType type, Position position)
 {
     Type     = type;
     Position = position;
 }