コード例 #1
0
        public void SaveMap()
        {
            if (!this.IsStashedBuildingListEmpty())
            {
                Service.Logger.Warn("BLT: We can't save the map as there are still stashed buildings");
                return;
            }
            PositionMap positionMap = new PositionMap();

            this.IsSavingBaseLayout = true;
            bool            flag      = false;
            List <Building> buildings = this.GetCurrentPlayerMap().Buildings;
            int             i         = 0;
            int             count     = buildings.Count;

            while (i < count)
            {
                string   key      = buildings[i].Key;
                Position position = this.lastSavedMap.GetPosition(key);
                if (!(Service.GameStateMachine.CurrentState is WarBaseEditorState) && position == null)
                {
                    Service.Logger.Error("BLT: Old Building position for " + key + " not found!");
                }
                else if (position == null || this.HasBuildingMoved(buildings[i], position))
                {
                    positionMap.AddPosition(key, new Position
                    {
                        X = buildings[i].X,
                        Z = buildings[i].Z
                    });
                    flag = true;
                }
                i++;
            }
            if (flag)
            {
                this.SaveBaseLayout(positionMap);
                this.UpdateLastSavedMap();
                this.ClearStashedBuildings();
            }
            this.ShouldRevertMap    = false;
            this.IsSavingBaseLayout = false;
        }
コード例 #2
0
        public void FindValidPositionsAndAddBuildings(List <Entity> entities)
        {
            PositionMap positionMap = new PositionMap();

            for (int i = 0; i < entities.Count; i++)
            {
                Entity            entity            = entities[i];
                BuildingComponent buildingComponent = entity.Get <BuildingComponent>();
                Building          buildingTO        = buildingComponent.BuildingTO;
                if (this.FindValidPositionAndUpdate(entity, buildingTO))
                {
                    positionMap.AddPosition(buildingTO.Key, new Position
                    {
                        X = buildingTO.X,
                        Z = buildingTO.Z
                    });
                }
            }
            Service.Get <ServerAPI>().Enqueue(new BuildingMultiMoveCommand(new BuildingMultiMoveRequest
            {
                PositionMap = positionMap
            }));
        }
コード例 #3
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            int x = e.X / blockSize, y = e.Y / blockSize;

            if (nodeToolStripButton.Checked)
            {
                if (x >= 0 && x < mapWidth && y >= 0 && y < mapHeight)
                {
                    if (!map.Exists(x, y))
                    {
                        map.AddPosition(x, y);
                        drawNode_refreshTags(x, y);
                    }
                }
                return;
            }
            if (connectionToolStripButton.Checked)
            {
                if (connecting)
                {
                    connecting = false;
                    if (map.Exists(x, y) && map.Exists(x1, y1) && (x != x1 || y != y1))
                    {
                        map.AddConnection(x1, y1, x, y, (float)Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
                        ClearPath();
                        drawMap();
                    }
                    else
                    {
                        refreshBlock(x1, y1);
                    }
                }
                else
                {
                    if (map.Exists(x, y))
                    {
                        x1         = x;
                        y1         = y;
                        connecting = true;
                    }
                }
                return;
            }
            if (doubleConnectionToolStripButton.Checked)
            {
                if (connecting)
                {
                    connecting = false;
                    if (map.Exists(x, y) && map.Exists(x1, y1) && (x != x1 || y != y1))
                    {
                        map.AddDoubleConnection(x1, y1, x, y, (float)Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
                        ClearPath();
                        drawMap();
                    }
                    else
                    {
                        refreshBlock(x1, y1);
                    }
                }
                else
                {
                    if (map.Exists(x, y))
                    {
                        x1         = x;
                        y1         = y;
                        connecting = true;
                    }
                }
                return;
            }
            if (eraserToolStripButton.Checked)
            {
                if (map.Exists(x, y))
                {
                    IPosition_Connected p = map.GetPosition(x, y);
                    if (p == map.GetStartPosition())
                    {
                        map.ClearStartPosition();
                    }
                    if (p == map.GetEndPosition())
                    {
                        map.ClearEndPosition();
                    }
                    map.RemovePosition(x, y);
                    ClearPath();
                    drawMap();
                }
                return;
            }
            if (startPositionToolStripButton.Checked)
            {
                if (map.Exists(x, y))
                {
                    map.SetStartPosition(x, y);
                    ClearPath();
                    refreshTags();
                }
                return;
            }
            if (endPositionToolStripButton.Checked)
            {
                if (map.Exists(x, y))
                {
                    map.SetEndPosition(x, y);
                    ClearPath();
                    refreshTags();
                }
                return;
            }
        }