Example #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);
            }
        }
Example #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);
        }
Example #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();
            }
        }
Example #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();
        }
Example #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);
        }
Example #6
0
 public void DeselectAll()
 {
     if (SelectedRow != null)
     {
         SelectedRow.Selected = false;
     }
     SelectedRow        = null;
     SelectedSquareType = null;
 }
Example #7
0
        public int GetMovementCost(Position position, Config config)
        {
            SquareType squareType = GetSquareTypeAt(position);

            if (squareType != null)
            {
                return(GetMovementCost(squareType, config));
            }
            return(config.CharacterConfig.MovementActionPoints);
        }
Example #8
0
 public void SetOrRemoveSquareTypeAt(Position position, SquareType squareType)
 {
     if (GetSquareTypeAt(position) == squareType)
     {
         Squares.Remove(position);
     }
     else
     {
         Squares[position] = squareType;
     }
 }
Example #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();
        }
Example #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;
        }
Example #11
0
        private ListBoxItem AddListBoxItem(SquareType squareType)
        {
            ListBoxItem listBoxItem = new ListBoxItem();

            listBoxItem.Tag = squareType;

            listBoxItem.Content = squareType.Name;

            list.Items.Add(listBoxItem);

            return(listBoxItem);
        }
Example #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;
        }
Example #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);
        }
Example #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));
        }
Example #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);
        }
Example #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();
        }
Example #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;
        }
Example #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);
            }
        }
Example #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;
        }
Example #20
0
 public void SetSquareTypeAt(Position position, SquareType squareType)
 {
     Squares[position] = squareType;
 }
Example #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");
            }
        }
Example #22
0
 public Square(SquareType type, Position position)
 {
     Type     = type;
     Position = position;
 }