public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
 {
     _ = componentMiner.Inventory;
     if (Terrain.ExtractContents(componentMiner.ActiveBlockValue) == 178)
     {
         TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging);
         if (terrainRaycastResult.HasValue)
         {
             Vector3 position = terrainRaycastResult.Value.HitPoint();
             DynamicArray <ComponentBody> dynamicArray = new DynamicArray <ComponentBody>();
             m_subsystemBodies.FindBodiesInArea(new Vector2(position.X, position.Z) - new Vector2(8f), new Vector2(position.X, position.Z) + new Vector2(8f), dynamicArray);
             if (dynamicArray.Count((ComponentBody b) => b.Entity.ValuesDictionary.DatabaseObject.Name == "Boat") < 6)
             {
                 Entity entity = DatabaseManager.CreateEntity(base.Project, "Boat", throwIfNotFound: true);
                 entity.FindComponent <ComponentFrame>(throwOnError: true).Position      = position;
                 entity.FindComponent <ComponentFrame>(throwOnError: true).Rotation      = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.Float(0f, (float)Math.PI * 2f));
                 entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0f;
                 base.Project.AddEntity(entity);
                 componentMiner.RemoveActiveTool(1);
                 m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, autoDelay: true);
             }
             else
             {
                 componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: false);
             }
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        public override bool CheckMove(Coordinate endCoordinate)
        {
            DynamicArray <Coordinate> Coordinates = Moves();

            for (int i = 0; i < Coordinates.Count(); i++)
            {
                if (Coordinates[i].ToString() == endCoordinate.ToString())
                {
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
        /// <summary>
        /// Проверка пути переданной фигуры на "пригодность" к передвижению
        /// </summary>
        /// <param name="figurePath">Путь фигуры, который нужно проверить</param>
        /// <param name="movingPiece">Передвигаемая фигура</param>
        private void CheckWithOtherPieces(DynamicArray <Coordinate> figurePath, ChessPiece movingPiece)
        {
            for (int i = 0; i < figurePath.Count(); i++)
            {
                Cell cell = FindCell(figurePath[i]);

                if (i == figurePath.Count() - 1)
                {
                    if (cell.ContentPiece != null && cell.ContentPiece.Color == movingPiece.Color)
                    {
                        throw new Exception("Фигуры одного и того же цвета");
                    }
                }
                if (i < figurePath.Count() - 1)
                {
                    if (cell.Contains())
                    {
                        throw new Exception("На пути фигуры находится другая фигура");
                    }
                }
            }
        }
示例#4
0
        public void VerifyIndexScore_MapReduce_JsProjection_StaticIndex()
        {
            using (var store = GetDocumentStore())
            {
                new Users_ByAge().Execute(store);

                using (var session = store.OpenSession())
                {
                    session.Store(new User
                    {
                        Name = "Jerry",
                        Age  = 75
                    });
                    session.Store(new User
                    {
                        Name = "Bob",
                        Age  = 67
                    });
                    session.Store(new User
                    {
                        Name = "Bill",
                        Age  = 75
                    });
                    session.SaveChanges();
                }

                Indexes.WaitForIndexing(store);

                using (var commands = store.Commands())
                {
                    var command = new QueryCommand(commands.Session, new IndexQuery
                    {
                        Query = "from index 'Users/ByAge' as i where i.Count < 10 select { Age : i.Age }"
                    });

                    commands.RequestExecutor.Execute(command, commands.Context);

                    var results = new DynamicArray(command.Result.Results);
                    Assert.Equal(2, results.Count());

                    foreach (dynamic r in results)
                    {
                        var indexScoreAsString = r[Constants.Documents.Metadata.Key][Constants.Documents.Metadata.IndexScore];
                        Assert.NotNull(indexScoreAsString);
                        var indexScore = float.Parse(indexScoreAsString.ToString(), CultureInfo.InvariantCulture);
                        Assert.True(indexScore > 0);
                    }
                }
            }
        }
示例#5
0
        public void VerifyIndexScore_MapReduce_SimpleProjection_AutoIndex()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User
                    {
                        Name = "Jerry",
                        Age  = 75
                    });
                    session.Store(new User
                    {
                        Name = "Bob",
                        Age  = 67
                    });
                    session.Store(new User
                    {
                        Name = "Bill",
                        Age  = 75
                    });
                    session.SaveChanges();
                }

                using (var commands = store.Commands())
                {
                    var command = new QueryCommand(commands.Session, new IndexQuery
                    {
                        Query = "from Users group by Age select key()"
                    });

                    commands.RequestExecutor.Execute(command, commands.Context);

                    var results = new DynamicArray(command.Result.Results);
                    Assert.Equal(2, results.Count());

                    foreach (dynamic r in results)
                    {
                        var indexScoreAsString = r[Constants.Documents.Metadata.Key][Constants.Documents.Metadata.IndexScore];
                        Assert.NotNull(indexScoreAsString);
                        var indexScore = float.Parse(indexScoreAsString.ToString(), CultureInfo.InvariantCulture);
                        Assert.True(indexScore > 0);
                    }
                }
            }
        }
示例#6
0
        public override DynamicArray <Coordinate> Moves()
        {
            Queen  queen = this;
            Bishop bishop = new Bishop(queen.Coordinate, queen.Color); Rock rock = new Rock(queen.Coordinate, queen.Color);
            DynamicArray <Coordinate> Bishop = bishop.Moves(), Rock = rock.Moves();
            DynamicArray <Coordinate> queenMoves = new DynamicArray <Coordinate>(); // rock always have maximum 14 moves, they do not depend on the piece color

            for (int i = 0; i < Bishop.Count(); i++)
            {
                queenMoves.Add(Bishop[i]);
            }
            for (int i = 0; i < Rock.Count(); i++)
            {
                queenMoves.Add(Rock[i]);
            }
            return(queenMoves);
        }
示例#7
0
        public void VerifyIndexScore_Map_JsProjection_AutoIndex()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User
                    {
                        Name     = "Jerry",
                        LastName = "Garcia"
                    });
                    session.Store(new User
                    {
                        Name     = "Bob",
                        LastName = "Weir"
                    });
                    session.SaveChanges();
                }

                using (var commands = store.Commands())
                {
                    var command = new QueryCommand(commands.Session, new IndexQuery
                    {
                        Query = "from Users as u where u.LastName != null " +
                                "select { Name : u.Name }"
                    });

                    commands.RequestExecutor.Execute(command, commands.Context);

                    var results = new DynamicArray(command.Result.Results);
                    Assert.Equal(2, results.Count());

                    foreach (dynamic r in results)
                    {
                        var indexScoreAsString = r[Constants.Documents.Metadata.Key][Constants.Documents.Metadata.IndexScore];
                        Assert.NotNull(indexScoreAsString);
                        var indexScore = float.Parse(indexScoreAsString.ToString(), CultureInfo.InvariantCulture);
                        Assert.True(indexScore > 0);
                    }
                }
            }
        }
        public async Task Can_project_in_map_reduce()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(new Address()
                    {
                        City = "Torun"
                    });

                    await session.StoreAsync(new Address()
                    {
                        City = "Torun"
                    });

                    await session.StoreAsync(new Address()
                    {
                        City = "Hadera"
                    });

                    await session.SaveChangesAsync();
                }

                using (var commands = store.Commands())
                {
                    // create auto map reduce index
                    var command = new QueryCommand(commands.Session, new IndexQuery
                    {
                        Query = "FROM Addresses GROUP BY City SELECT count() as TotalCount ",
                        WaitForNonStaleResults = true
                    });

                    commands.RequestExecutor.Execute(command, commands.Context);

                    // retrieve only City field
                    command = new QueryCommand(commands.Session, new IndexQuery
                    {
                        Query = "FROM Addresses GROUP BY City SELECT City ",
                        WaitForNonStaleResults = true
                    });

                    commands.RequestExecutor.Execute(command, commands.Context);

                    var indexDefinitions = store.Maintenance.Send(new GetIndexesOperation(0, 10));

                    Assert.Equal(1, indexDefinitions.Length); // the above queries should be handled by the same auto index

                    var result  = command.Result;
                    var results = new DynamicArray(result.Results);

                    var cities = new List <string> {
                        "Torun", "Hadera"
                    };
                    Assert.Equal(2, results.Count());
                    foreach (dynamic r in results)
                    {
                        var json = (DynamicBlittableJson)r;
                        Assert.Equal(2, json.BlittableJson.Count);
                        Assert.True(json.ContainsKey("City"));
                        Assert.True(json.ContainsKey(Constants.Documents.Metadata.Key));

                        var city = r.City;
                        Assert.True(cities.Remove(city));
                    }
                }
            }
        }