/// <summary> /// Called when the loc has reached the given to-block of the current route. /// </summary> public void BlockReached(ILocState loc, IBlockState block) { if (block == targetBlock) { TargetReached(loc); } }
public void Execute(InputState state, IBlockState BlockState, Vector2 BlockLocation) { if (BlockState != null) { /* * switch (state) * { * case InputState.ChangeToUsed: * BlockState.ChangeToUsedBlock(); * break; * case InputState.BumpUp: * BlockState.BlockBumpUp(BlockLocation); * break; * case InputState.ChangeToVisible: * BlockState.ChangeToBrickBlock(); * break; * case InputState.BreakBrick: * BlockState.BreakBrickBlock(); * break; * default: * break; * } */ } }
public void Explode() { state = new ExplodingBlockState(); isExploding = true; Game1.GetInstance().gameHUD.Score += ValueHolder.brickBreakPoints; SoundManager.brickBreak.Play(); }
/// <summary> /// Choose an available route from the given block. /// </summary> /// <param name="loc">The loc a route should be choosen for</param> /// <param name="fromBlock">The starting block of the route</param> /// <param name="locDirection">The direction the loc is facing in the <see cref="fromBlock"/>.</param> /// <param name="avoidDirectionChanges">If true, routes requiring a direction change will not be considered, unless there is no alternative.</param> /// <returns>Null if not route is available.</returns> private IRouteState ChooseRoute(ILocState loc, IBlockState fromBlock, BlockSide locDirection, bool avoidDirectionChanges, int generationDelta) { // Gather possible routes. var routeFromFromBlock = railwayState.GetAllPossibleNonClosedRoutesFromBlock(fromBlock).ToList(); var routeOptions = routeFromFromBlock.Select(x => routeAvailabilityTester.IsAvailableFor(x, loc, locDirection, avoidDirectionChanges, generationDelta)).ToList(); var possibleRoutes = routeOptions.Where(x => x.IsPossible).Select(x => x.Route).ToList(); loc.LastRouteOptions.Actual = routeOptions.ToArray(); if (possibleRoutes.Any()) { // Use the route selector to choose a next route var selector = loc.RouteSelector; var selected = selector.SelectRoute(possibleRoutes, loc, fromBlock, locDirection); if (selected == null) { log.Info("No route selected for {0} [from {1} {2}]. Available routes: {3}", loc, fromBlock, locDirection, string.Join(", ", possibleRoutes.Select(x => x.ToString()).ToArray())); } else { log.Info("Selected route {0} for {1} [from {2} {3}]", selected, loc, fromBlock, locDirection); } return(selected); } log.Info("No possible routes for {0} [from {1} {2}]", loc, fromBlock, locDirection); // No available routes return(null); }
public MoveableBlock(IDictionary <string, IDoor> doors) { this.doors = doors; sprite = RoomSpriteFactory.Instance.CreateBlock(); State = new MoveableBlockState(this, doors); Hitbox = new Rectangle(0, 0, RoomParser.TILE_SIZE, RoomParser.TILE_SIZE); }
public bool TryResolve(BlockState source, string property, string value, bool prioritize, out IBlockState result, params string[] requiredMatches) { var copiedProperties = source.ToDictionary(); copiedProperties[property] = value.ToString(); int highestMatch = 0; IBlockState highest = null; foreach (var variant in Variants.ToArray().Where(x => (x.TryGetValue(property, out string xVal) && xVal.Equals(value, StringComparison.InvariantCultureIgnoreCase)))) { bool valid = true; foreach (var requiredMatch in requiredMatches) { if (!(copiedProperties.TryGetValue(requiredMatch, out string copyValue) && variant.TryGetValue(requiredMatch, out string variantValue) && copyValue == variantValue)) { valid = false; break; } } if (!valid) { continue; } int matches = 0; foreach (var copy in copiedProperties.Where(x => x.Key != property)) { //Check if variant value matches copy value. if (variant.TryGetValue(copy.Key, out string val) && copy.Value.Equals(val, StringComparison.InvariantCultureIgnoreCase)) { matches++; } } foreach (var variantProp in variant.ToDictionary()) { if (!copiedProperties.ContainsKey(variantProp.Key)) { matches--; } } if (matches > highestMatch) { highestMatch = matches; highest = variant; } } if (highest != null) { result = highest; return(true); } result = null; return(false); }
public static BlockStateModel[] GetModels(IBlockState blockState, BlockStateResource resource) { List <BlockStateModel> resultingModels = new List <BlockStateModel>(resource.Parts.Length); foreach (var s in resource.Parts) { if (s.When == null) { resultingModels.AddRange(s.Apply); } else if (s.When.Length > 0) { bool passes = true; foreach (var rule in s.When) { if (!PassesMultiPartRule(rule, blockState)) { passes = false; break; } } if (passes) { resultingModels.AddRange(s.Apply); } } } return(resultingModels.ToArray()); }
public byte GetMetaFromState(IBlockState state) { byte i = 0; if (state.GetTypedValue(UPPER)) { i = (byte) (i | 8); if (state.GetTypedValue(RIGHTHINCHED)) { i |= 1; } if (state.GetTypedValue(POWERED)) { i |= 2; } } else { var facingValue = Correct(state.GetTypedValue(FACING)); i = (byte) ((i & 245) + facingValue); if (state.GetTypedValue(OPEN)) { i |= 4; } } return i; }
public IChunkColumn GenerateChunkColumn(ChunkCoordinates chunkCoordinates) { int cc = 0; ChunkColumn chunk = new ChunkColumn(); chunk.X = chunkCoordinates.X; chunk.Z = chunkCoordinates.Z; for (int x = 0; x < 16; ++x) { for (int z = 0; z < 16; ++z) { int rx = chunkCoordinates.X * 16 + x; int rz = chunkCoordinates.Z * 16 + z; IBlockState iblockstate = GetBlockStateFor(rx, rz); if (iblockstate != null) { chunk.SetBlockState(x, 70, z, iblockstate); chunk.Height[((z << 4) + (x))] = 70; } chunk.SetSkyLight(x, 70, z, 15); chunk.SetSkyLight(x, 71, z, 15); chunk.SetSkyLight(x, 69, z, 15); } } chunk.CalculateHeight(); return(chunk); }
/// <summary> /// Is there are traffic in the opposite direction of the given to-block of a route? /// </summary> protected override bool HasTrafficInOppositeDirection(IBlockState toBlock, BlockSide toBlockSide, ILocState currentLoc) { var loc = GetLockedBy(toBlock); if ((loc != null) && (loc != currentLoc)) { // Check direction var locEnterSide = GetCurrentBlockEnterSide(loc); if (locEnterSide != toBlockSide) { // loc is in opposing direction if (!loc.CanChangeDirectionIn(toBlock)) { // The loc cannot change direction in to block, so there is absolutely opposite traffic. return(true); } } else { // Loc is in same direction, we're ok return(false); } } return(false); }
private static List <IBlockState> ReadBlockState(NbtCompound tag) { //Log.Debug($"Palette nbt:\n{tag}"); var states = new List <IBlockState>(); var nbtStates = (NbtCompound)tag["states"]; foreach (NbtTag stateTag in nbtStates) { IBlockState state = stateTag.TagType switch { NbtTagType.Byte => (IBlockState) new BlockStateByte() { Name = stateTag.Name, Value = stateTag.ByteValue }, NbtTagType.Int => new BlockStateInt() { Name = stateTag.Name, Value = stateTag.IntValue }, NbtTagType.String => new BlockStateString() { Name = stateTag.Name, Value = stateTag.StringValue }, _ => throw new ArgumentOutOfRangeException() }; states.Add(state); } return(states); }
private IBlockState FixFacingTrapdoor(IBlockState state, int meta) { switch (meta) { case 4: case 0: state = state.WithProperty(facing, "east"); break; case 5: case 1: state = state.WithProperty(facing, "west"); break; case 6: case 2: state = state.WithProperty(facing, "south"); break; case 7: case 3: state = state.WithProperty(facing, "north"); break; } return(state); }
public BrickBlock(Vector2 position) { State = new BrickShowedState(); Location = position; BlockPhysics = new BlocksPhysicalProperty(this); HaveCollision = true; }
public Block(Vector2 location, ICollectable prize, IBlockState state, Game1 game) { this.game = game; this.prize = prize; this.state = state; position = location; }
public BlockType FindType(IBlockState bState) { BlockType type = BlockType.used; if (bState is BrickBlockState || bState is BrickBlockBumpState) { type = BlockType.brick; } else if (bState is ExplodingBlockState) { type = BlockType.exploded; } else if (bState is HiddenBlockState) { type = BlockType.hidden; } else if (bState is QuestionBlockState || bState is QuestionBlockBumpState) { type = BlockType.question; } else if (bState is PipeBlockState) { type = BlockType.pipe; } else if (bState is BridgeBlockState) { type = BlockType.bridge; } return(type); }
/// <summary> /// Default ctor /// </summary> public BlockItem(IBlock entity, IBlockState state, ItemContext context) : base(entity, false, context) { this.state = state; DragDropHandler = new SetLocTargetDragDropHandler(this, DragDropHandler); MouseHandler = new SelectLocHandler(this, MouseHandler); }
public QuestionBlock(Vector2 position) { State = new QuestionBlockStates(); Location = position; hasBeUsed = false; BlockPhysics = new BlocksPhysicalProperty(this); }
public async Task <INode?> MoveAsync(IBlock block, IBlockState blockState, INavigationContext context, bool forward) { context.State.CurrentBlockId = block.Id; for (; ;) { if (forward) { var node = await MoveNextAsync(block, context, blockState.GetCurrentIteration()); if (node is not null || block.While is null || !block.While.Evaluate(context.Variables)) { return(node); } blockState.MoveToNextIteration(); } else { var node = await MovePreviousAsync(block, context, blockState.GetCurrentIteration()); if (node is not null || block.While is null || !blockState.MoveToPreviousIteration()) { return(node); } } } }
public StoryboardParserTests() { blockFactory = new FakeBlockFactory(); dismissNodes = new(); parsingContext = A.Fake<IParsingContext>(i => i.Strict()); A.CallTo(() => parsingContext.RegisterDismissNode(A<INode>.Ignored)) .Invokes(i => dismissNodes.Add(i.Arguments.Get<INode>(0))); A.CallTo(() => parsingContext.BlockFactory).Returns(blockFactory); rootBlockParser = A.Fake<IRootBlockParser>(i => i.Strict()); sceneNavigator = A.Fake<ISceneNavigator>(i => i.Strict()); eventManager = A.Fake<IEventManager>(i => i.Strict()); randomizer = A.Fake<IRandomizer>(i => i.Strict()); navigationState = A.Fake<INavigationState>(i => i.Strict()); variableDictionary = A.Fake<IVariableDictionary>(i => i.Strict()); blockState = A.Fake<IBlockState>(i => i.Strict()); var serviceProvider = A.Fake<IServiceProvider>(i => i.Strict()); A.CallTo(() => serviceProvider.GetService(typeof(IParsingContext))).Returns(parsingContext); A.CallTo(() => serviceProvider.GetService(typeof(IRootBlockParser))).Returns(rootBlockParser); A.CallTo(() => serviceProvider.GetService(typeof(ISceneNavigator))).Returns(sceneNavigator); A.CallTo(() => serviceProvider.GetService(typeof(IEventManager))).Returns(eventManager); A.CallTo(() => serviceProvider.GetService(typeof(IRandomizer))).Returns(randomizer); A.CallTo(() => serviceProvider.GetService(typeof(INavigationState))).Returns(navigationState); A.CallTo(() => serviceProvider.GetService(typeof(IVariableDictionary))).Returns(variableDictionary); A.CallTo(() => serviceProvider.GetService(typeof(IBlockState))).Returns(blockState); sut = new StoryboardParser(serviceProvider); }
/// <summary> /// Save the open/closed state of the given block. /// </summary> public void SetBlockState(IRailwayState railwayState, IBlockState block, bool closed) { // Write assignment using (var key = Registry.CurrentUser.CreateSubKey(GetBlockStateKey(block))) { key.SetValue(ClosedKey, closed ? 1 : 0); } }
public static void SetBlockAtPos(BlockPos pos, IBlockState state) { Chunk chunk = Chunks[GetChunkIndex(Mathf.FloorToInt((float)pos.x / ChunkX), Mathf.FloorToInt((float)pos.z / ChunkZ))]; chunk.Blocks[(pos.x + ChunkX) % ChunkX, pos.y, (pos.z + ChunkZ) % ChunkZ] = state; GameObject.Find($"Chunk {chunk.ChunkPos.Item1} {chunk.ChunkPos.Item2}").GetComponent <ChunkScript>().UpdateMesh(); Debug.Log($"Chunk {chunk.ChunkPos.Item1} {chunk.ChunkPos.Item2} At {(pos.x + ChunkX) % ChunkX} {pos.y} {(pos.z + ChunkZ) % ChunkZ}"); }
protected static string GetShape(IBlockState state) { if (state.TryGetValue("shape", out string facingValue)) { return(facingValue); } return(string.Empty); }
public Block(Vector2 location, IBlockState initState) { Location = location; State = initState; State.SetBlock(this); setSpriteFromState(); Physics = new BlockPhysics(this); BeRemoved = false; }
public static BlockState GetState(BlockState type, IBlockState state) { if (state is BlockBreakingState) { type = (BlockState)((int)type | (int)BlockState.Breaking); } return type; }
protected static string GetHalf(IBlockState state) { if (state.TryGetValue("half", out string facingValue)) { return(facingValue); } return(string.Empty); }
////============================================================================= //// コンストラクタ //// ////============================================================================= /// <summary> /// 基本的なコンストラクタ /// </summary> /// <param name="state">初期ステート</param> /// <param name="parentLayer">親レイヤーへの参照</param> /// <param name="x">ブロックのX座標</param> /// <param name="y">ブロックのY座標</param> /// <param name="blockSize">ブロックのサイズ</param> /// <param name="aroundMineNum">周りの地雷の数</param> /// <param name="hasMine">地雷を保持すべきかどうか</param> public BlockBase(IBlockState state, int x, int y, int blockSize, int aroundMineNum, bool hasMine = false) { XPosition = x; YPosition = y; BlockSize = blockSize; HasMine = hasMine; AroundMinesNum = aroundMineNum; ChangeState(state); }
/// <summary> /// Find all route sequences that lead from the given side of the given "from" block to the given "to" block. /// </summary> public static IEnumerable <IRouteSequence> FindRouteSequences(IBlockState fromBlock, BlockSide fromBlockEnterSide, IBlockState toBlock) { var railway = fromBlock.RailwayState; var fromBlockLeaveSide = fromBlockEnterSide.Invert(); var startRoutes = railway.RouteStates.Where(x => (x.From == fromBlock) && (x.FromBlockSide == fromBlockLeaveSide)).ToList(); var initialSequences = startRoutes.Select(x => new RouteSequence(x)); return(FindRouteSequences(initialSequences, railway, toBlock, railway.RouteStates.Count)); }
private void SetInitialState(Type blockType, bool isUnderground) { switch (blockType) { case Type.BrickBlock: blockState = new BrickBlockState(this, isUnderground); break; case Type.HiddenBlock: blockState = new HiddenBlockState(this); break; case Type.QuestionBlock: blockState = new QuestionBlockState(this); break; case Type.SolidBlock: blockState = new SolidBlockState(this); break; case Type.BreakingBlock: blockState = new BreakingBlockState(this, isUnderground); break; case Type.NullBlock: blockState = new NullBlockState(this); break; case Type.EnemyUpBlock: blockState = new DirectEnemyUpBlockState(this); break; case Type.EnemyDownBlock: blockState = new DirectEnemyDownBlockState(this); break; case Type.EnemyRightBlock: blockState = new DirectEnemyRightBlockState(this); break; case Type.EnemyLeftBlock: blockState = new DirectEnemyLeftBlockState(this); break; case Type.TeleportBlock: blockState = new TeleportBlockState(this); break; case Type.VerticalBlockWall: blockState = new VerticalBlockWallState(this); break; case Type.HorizontalBlockWall: blockState = new HorizontalBlockWallState(this); break; } }
protected static BlockFace GetFacing(IBlockState state) { if (state.TryGetValue("facing", out string facingValue) && Enum.TryParse <BlockFace>(facingValue, true, out BlockFace face)) { return(face); } return(BlockFace.None); }
public void SetBlock(int x, int y, int z, IBlockState blockState) { var index = SectionIndex(y); var section = CreateSection(index); var blockStorage = section.BlockStorage; blockStorage.SetBlock( x, y % Minecraft.Units.Chunk.SectionHeight, z, blockState ); }
/// <summary> /// Save the current block state of the given loc. /// </summary> public void SetLocState(IRailwayState railwayState, ILocState loc, IBlockState currentBlock, BlockSide currentBlockEnterSide, LocDirection currentDirection) { // Write assignment using (var key = Registry.CurrentUser.CreateSubKey(GetKey(loc))) { key.SetValue(CurrentBlock, (currentBlock != null) ? currentBlock.EntityId : string.Empty); key.SetValue(CurrentBlockEnterSide, (currentBlockEnterSide == BlockSide.Back) ? 0 : 1); key.SetValue(CurrentDirection, (currentDirection == LocDirection.Forward) ? 0 : 1); } }
public Block(Vector2 position, BlockState initialType, Megaman megaman, ContentManager content) { spriteFactory = new BlockSpriteFactory(content); stateMachine = new BlockStateMachine(this, megaman); currentState = stateMachine.GetState(BlockState.Normal); currentType = initialType; currentSprite = spriteFactory.GetSprite(BlockStateHelper.GetState(currentType, currentState)); currentSprite.Position = position; initialPosition = position; this.initialType = initialType; }
public void Reset() { currentState = stateMachine.GetState(BlockState.Normal); currentType = initialType; StateChanged(); currentSprite.Position = initialPosition; itemIndex = 0; }