Exemplo n.º 1
0
        public static SoldierModel CreateSoldier(GameView parentView)
        {
            var model = new SoldierModel();
            var view  = ViewFactory.CreateViewForModel <SoldierView>(model);

            parentView.AddToMap(view);

            model.Name         = "Soldier";
            model.MovementRate = 0.5f;

            return(model);
        }
Exemplo n.º 2
0
        private void OnArrivedToWaypoint(SoldierView sender, int coordX, int coordY)
        {
            SoldierModel model = (SoldierModel)_viewToModel[sender];

            GridManager.Instance.UpdateMap(model.CoordX, model.CoordY, 1, 1, 0);

            model.CoordX = coordX;
            model.CoordY = coordY;

            GridManager.Instance.UpdateMap(coordX, coordY, 1, 1, GridLayers.Units);

            model.RemovePath(new Vector2(coordX, coordY));
        }
Exemplo n.º 3
0
        private void OnBoardClickRegistered(GameView sender, int coordX, int coordY, UnityEngine.EventSystems.PointerEventData.InputButton btn)
        {
            var model = (GameModel)this._viewToModel[sender];

            if (btn == PointerEventData.InputButton.Left)
            {
                // There is an undergoing placement.
                // This will not select units.
                if (_buildingPlacement != null)
                {
                    var available = !GridManager.Instance.CheckOverlap(coordX, coordY, _buildingPlacement.Width,
                                                                       _buildingPlacement.Height,
                                                                       GridLayers.Buildings | GridLayers.Units);

                    if (available)
                    {
                        model.AddBuilding(_buildingPlacement);
                        _buildingPlacement.Placed    = true;
                        _buildingPlacement           = null;
                        sender.BoardHoverRegistered -= OnBoardHoverRegistered;
                    }
                }
                else
                {
                    bool hit = false;
                    foreach (var selectable in model.Selectables)
                    {
                        // Check given coords with Rectangles of selectables.
                        if (selectable.CheckOverlap(coordX, coordY))
                        {
                            hit = true;
                            if (_currentSelection != null)
                            {
                                _currentSelection.OnDeSelection();
                            }

                            selectable.OnSelection();
                            _currentSelection    = selectable;
                            model.SelectedEntity = selectable;
                            break;
                        }
                    }

                    if (_currentSelection != null && !hit)
                    {
                        _currentSelection.OnDeSelection();
                        _currentSelection    = null;
                        model.SelectedEntity = null;
                    }
                }
            }
            else if (btn == PointerEventData.InputButton.Right)
            {
                if (_currentSelection != null)
                {
                    // Too tired to think something anything near engineering at this point.
                    // Just getting things done.
                    // We have only to entities that get right click commands.
                    if (_currentSelection is SoldierModel)
                    {
                        SoldierModel soldier = (SoldierModel)_currentSelection;
                        var          path    = GridManager.Instance.FindPath(soldier.CoordX, soldier.CoordY, coordX, coordY);

                        if (path != null)
                        {
                            soldier.Path = path;
                        }
                        else
                        {
                            Debug.LogError("Could not find a path.");
                        }
                    }
                    else if (_currentSelection is ProductionBuildingModel)
                    {
                        if (!GridManager.Instance.CheckOverlap(coordX, coordY, 1, 1, GridLayers.Buildings))
                        {
                            ((ProductionBuildingModel)_currentSelection).RallyPoint = new Vector2(coordX, coordY);
                        }
                    }
                }
            }
        }