//-----------------------------------------------------------------------------
 // Constructor
 //-----------------------------------------------------------------------------
 public PlayerMinecartState()
 {
     minecartSpeed	= 1.0f;
     minecart		= null;
     trackTile		= null;
     minecartAnimationPlayer = new AnimationPlayer();
 }
예제 #2
0
        public Minecart spawnCart()
        {
            Minecart cart = new Minecart(this);

            cart.Move();
            return(cart);
        }
예제 #3
0
 //-----------------------------------------------------------------------------
 // Constructor
 //-----------------------------------------------------------------------------
 public PlayerMinecartState()
 {
     minecartSpeed	= 1.0f;
     minecart		= null;
     trackTile		= null;
     minecartAnimationPlayer = new AnimationPlayer();
 }
예제 #4
0
            public void RenderGameboard()
            {
                StringBuilder sb = new StringBuilder();

                sb.Append(Environment.NewLine);
                for (int y = 0; y < _maxY; y++)
                {
                    for (int x = 0; x < _maxX; x++)
                    {
                        int      tileIndex = GetTileIndex(x, y);
                        Minecart mc        = _cartLocations[tileIndex];
                        if (mc != null)
                        {
                            sb.Append(mc.Render());
                        }
                        else
                        {
                            MinecartTile tile = _tiles[tileIndex];
                            sb.Append(tile.Render());
                        }
                    }

                    sb.Append(Environment.NewLine);
                }

                Log.WriteLine(sb);
            }
예제 #5
0
 // Hop into a minecart.
 public void JumpIntoMinecart(Minecart minecart)
 {
     JumpToPosition(minecart.Center, 4.0f, 26, delegate(PlayerJumpToState state) {
         stateMinecart.Minecart = minecart;
         BeginSpecialState(stateMinecart);
     });
 }
예제 #6
0
파일: Day13.cs 프로젝트: RPScylla/AoC
        public AnswerModel Solve()
        {
            AnswerModel answer = new AnswerModel();

            char[,] track = GenerateTrack(_input, out List <Minecart> minecarts);

            while (minecarts.Count() > 1)
            {
                foreach (Minecart m in minecarts.OrderBy(m => m.Y).ThenBy(m => m.X))
                {
                    m.Tick(track);
                    Minecart crashedCar = minecarts.FirstOrDefault(mm => mm != m && mm.X == m.X && mm.Y == m.Y);
                    if (crashedCar != null)
                    {
                        crashedCar.Crashed = true;
                        m.Crashed          = true;
                        if (answer.PartA is null)
                        {
                            answer.PartA = $"{m.X},{m.Y}";
                        }
                    }
                }
                minecarts.RemoveAll(m => m.Crashed);
            }

            Minecart notCrashed = minecarts.First();

            answer.PartB = $"{notCrashed.X},{notCrashed.Y}";

            return(answer);
        }
예제 #7
0
 private void PoundTrack(Point spot)
 {
     if (Main.tile[spot.X, spot.Y].type == 314 && Minecart.FrameTrack(spot.X, spot.Y, pound: true) && Main.netMode == 1)
     {
         NetMessage.SendData(17, -1, -1, null, 15, spot.X, spot.Y, 1f);
     }
 }
예제 #8
0
        private static Rectangle GetTileRect(Tile tile, int halfIndex = 0)
        {
            Rectangle result;

            if (tile.halfBrick())
            {
                if (halfIndex == 0)
                {
                    result = new Rectangle(tile.frameX, tile.frameY, 16, 4);
                }
                else
                {
                    result = new Rectangle(tile.frameX, tile.frameY + 12, 16, 4);
                }
            }
            else if (tile.type == TileID.MinecartTrack)
            {
                result = Minecart.GetSourceRect(tile.frameX, Main.tileFrame[tile.type]);
            }
            else
            {
                result = new Rectangle(tile.frameX, tile.frameY, 16, 16);
            }

            if (result.X < 0)
            {
                result.X = 0;
            }
            if (result.Y < 0)
            {
                result.Y = 0;
            }

            return(result);
        }
예제 #9
0
 private void PoundTrack(Point spot)
 {
     if (Main.tile[spot.X, spot.Y].type != (ushort)314 || !Minecart.FrameTrack(spot.X, spot.Y, true, false) || Main.netMode != 1)
     {
         return;
     }
     NetMessage.SendData(17, -1, -1, (NetworkText)null, 15, (float)spot.X, (float)spot.Y, 1f, 0, 0, 0);
 }
예제 #10
0
    public bool Place(Minecart cart)
    {
        if (IsEmty())
        {
            Contains = cart;
            return true;
        }

        return false;
    }
예제 #11
0
            public MinecartSystem(string[] lines)
            {
                List <MinecartTile> tiles = new List <MinecartTile>();
                int          x            = 0;
                int          y            = 0;
                MinecartTile prevTile     = null;

                foreach (var line in lines)
                {
                    x = 0;
                    foreach (var character in line)
                    {
                        Minecart     m    = TryParseMineCart(character, x, y);
                        MinecartTile tile = null;
                        if (m != null)
                        {
                            _carts.Add(m);
                            tile = m.GenerateImpliedTile();
                        }
                        else
                        {
                            tile = ParseTile(character, x, y, prevTile);
                        }

                        prevTile = tile;
                        tiles.Add(tile);
                        x++;
                    }
                    _maxX = x;
                    y++;
                }

                _maxY = y;


                _tiles = new MinecartTile[tiles.Count];
                foreach (var tile in tiles)
                {
                    tile.TileIndex         = GetTileIndex(tile.X, tile.Y);
                    _tiles[tile.TileIndex] = tile;
                }


                _cartLocations = new Minecart[_tiles.Length];

                foreach (var cart in _carts)
                {
                    cart.TileIndex = GetTileIndex(cart.X, cart.Y);
                    _cartLocations[cart.TileIndex] = cart;
                }



                //RenderGameboard();
            }
예제 #12
0
            private int CompareCartsByLocation(Minecart a, Minecart b)
            {
                int rowCompare = a.Y.CompareTo(b.Y);

                if (rowCompare != 0)
                {
                    return(rowCompare);
                }

                return(a.X.CompareTo(b.X));
            }
예제 #13
0
    public virtual bool Place(Minecart mc)
    {
        if (IsEmpty())
        {
            Content = mc;
            Previous.Content = null;
            return true;
        }

        throw new JeMoederException();
    }
예제 #14
0
    public override bool Place(Minecart mc)
    {
        if (IsEmpty())
        {
            Content = mc;
            Previous.Content = null;
            return true;
        }

        return false;
    }
예제 #15
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override void OnInitialize()
        {
            trackIndex = Properties.GetInteger("track_index", 0);
            Graphics.PlaySpriteAnimation(SpriteList[trackIndex]);

            // Spawn a minecart entity.
            if (SpawnsMinecart)
            {
                Minecart minecart = new Minecart(this);
                RoomControl.SpawnEntity(minecart, Position);
            }
        }
예제 #16
0
    public override bool Place(Minecart mc)
    {
        if (Content == null)
        {
            Content = mc;
            Previous.Content = null;
            return true;
        }

        if (Previous.ToChar(true) == '#')
            throw new JeMoederException();

        return false;
    }
예제 #17
0
    public override bool Place(Minecart mc)
    {
        if (IsEmpty())
        {
            if (Previous.Content != null && Content == null)
            {
                Content = Previous.Content;
                Previous.Content = null;
                return true;
            }
        }

        return false;
    }
예제 #18
0
            public Minecart TryParseMineCart(char tile, int x, int y)
            {
                Minecart res = null;

                if (tile != Minecart.FacingEast && tile != Minecart.FacingWest && tile != Minecart.FacingNorth &&
                    tile != Minecart.FacingSouth)
                {
                    return(null);
                }
                res             = new Minecart();
                res.Orientation = Minecart.CharacterToOrientation(tile);
                res.X           = x;
                res.Y           = y;
                return(res);
            }
예제 #19
0
        private void CorrectTrackConnections(Point startCoords, Point endCoords)
        {
            GetExpectedDirections(startCoords, endCoords, out var expectedStartLeft, out var expectedStartRight, out var expectedEndLeft, out var expectedEndRight);
            Tile tileSafely  = Framing.GetTileSafely(startCoords);
            Tile tileSafely2 = Framing.GetTileSafely(endCoords);

            if (tileSafely.active() && tileSafely.type == 314)
            {
                Minecart.TryFittingTileOrientation(startCoords, expectedStartLeft, expectedStartRight);
            }
            if (tileSafely2.active() && tileSafely2.type == 314)
            {
                Minecart.TryFittingTileOrientation(endCoords, expectedEndLeft, expectedEndRight);
            }
        }
예제 #20
0
        ////////////////

        public static int ComputeImpendingFallDamage(Player player)
        {
            if (player.mount.CanFly)
            {
                return(0);
            }
            if (player.mount.Cart && Minecart.OnTrack(player.position, player.width, player.height))
            {
                return(0);
            }
            if (player.mount.Type == 1)
            {
                return(0);
            }

            int safetyMin = 25 + player.extraFall;
            int damage    = (int)(player.position.Y / 16f) - player.fallStart;

            if (player.stoned)
            {
                return((int)(((float)damage * player.gravDir - 2f) * 20f));
            }

            if ((player.gravDir == 1f && damage > safetyMin) || (player.gravDir == -1f && damage < -safetyMin))
            {
                if (player.noFallDmg)
                {
                    return(0);
                }
                for (int n = 3; n < 10; n++)
                {
                    if (player.armor[n].stack > 0 && player.armor[n].wingSlot > -1)
                    {
                        return(0);
                    }
                }

                int finalDamage = (int)((float)damage * player.gravDir - (float)safetyMin) * 10;
                if (player.mount.Active)
                {
                    finalDamage = (int)((float)finalDamage * player.mount.FallDamage);
                }
                return(finalDamage);
            }

            return(0);
        }
예제 #21
0
        //-----------------------------------------------------------------------------
        // Navigation methods
        //-----------------------------------------------------------------------------
        // Exit the minecart, dropping the player off in the given direction.
        private void ExitMinecart(int direction)
        {
            // Spawn another minecart entity.
            if (minecart == null || minecart.IsDestroyed) {
                minecart = new Minecart(trackTile);
                player.RoomControl.SpawnEntity(minecart, tileLocation * GameSettings.TILE_SIZE);
                minecart = null;
            }

            // Make the current track tile remember it has a minecart on it.
            if (trackTile != null)
                trackTile.SpawnsMinecart = true;

            // Hop out of the minecart.
            Point2I landingTile = tileLocation + Directions.ToPoint(direction);
            player.JumpOutOfMinecart(landingTile);
        }
예제 #22
0
    private void Update()
    {
        timer += Time.deltaTime;
        if (timer > 1f / spawnSpeed)
        {
            timer -= 1f / spawnSpeed;
            Vector3[] minecartPositions = board.RandomBorderPositions();
            Minecart  minecart          = Instantiate(minecartPrefab, minecartPositions[0] + new Vector3(0, 1.52f, 0), Quaternion.identity, transform);
            minecart.target = minecartPositions[1] + new Vector3(0, 1.52f, 0);
            minecart.transform.LookAt(minecartPositions[1] + new Vector3(0, 1.52f, 0));
            minecart.transform.position += 50f * Vector3.up;

            for (int i = 0; i <= (minecartPositions[1] - minecartPositions[0]).magnitude + 2; i++)
            {
                Plank plank1 = Instantiate(plankPrefab, minecartPositions[0] - 1f * (minecartPositions[1] - minecartPositions[0]).normalized + (minecartPositions[1] - minecartPositions[0]).normalized * i, Quaternion.identity);
                plank1.targetPos = minecartPositions[0] - 1f * (minecartPositions[1] - minecartPositions[0]).normalized + (minecartPositions[1] - minecartPositions[0]).normalized * i;
                plank1.transform.LookAt(minecartPositions[1]);
                plank1.transform.localScale = new Vector3(1.5f, 2f, 2.7f);
                plank1.transform.position  += baseHeight * Vector3.up + i * offsetHeight * Vector3.up;
                plank1.transform.SetParent(transform);
                minecart.listPlank.Add(plank1);

                Plank plank2 = Instantiate(plankPrefab, minecartPositions[0] - 0.5f * (minecartPositions[1] - minecartPositions[0]).normalized + (minecartPositions[1] - minecartPositions[0]).normalized * i, Quaternion.identity);
                plank2.targetPos = minecartPositions[0] - 0.5f * (minecartPositions[1] - minecartPositions[0]).normalized + (minecartPositions[1] - minecartPositions[0]).normalized * i;
                plank2.transform.LookAt(minecartPositions[1]);
                plank2.transform.localScale = new Vector3(1.5f, 2f, 2.7f);
                plank2.transform.position  += baseHeight * Vector3.up + (i + 0.5f) * offsetHeight * Vector3.up;
                plank2.transform.SetParent(transform);
                minecart.listPlank.Add(plank2);
            }

            Rail rail1 = Instantiate(railPrefab, minecartPositions[0] - 0.46f * (Vector3.Cross((minecartPositions[1] - minecartPositions[0]).normalized, Vector3.up)) - 1.5f * (minecartPositions[1] - minecartPositions[0]).normalized, Quaternion.identity);
            rail1.transform.LookAt(minecartPositions[1] - 0.46f * (Vector3.Cross((minecartPositions[1] - minecartPositions[0]).normalized, Vector3.up)));
            rail1.transform.localScale = new Vector3(1, 1, 0.1f);
            rail1.targetScale          = new Vector3(1, 1, 1.5f * (minecartPositions[1] - minecartPositions[0]).magnitude + 4.5f);
            rail1.transform.SetParent(transform);
            minecart.rail1 = rail1;

            Rail rail2 = Instantiate(railPrefab, minecartPositions[0] + 0.46f * (Vector3.Cross((minecartPositions[1] - minecartPositions[0]).normalized, Vector3.up)) - 1.5f * (minecartPositions[1] - minecartPositions[0]).normalized, Quaternion.identity);
            rail2.transform.LookAt(minecartPositions[1] + 0.46f * (Vector3.Cross((minecartPositions[1] - minecartPositions[0]).normalized, Vector3.up)));
            rail2.transform.localScale = new Vector3(1, 1, 0.1f);
            rail2.targetScale          = new Vector3(1, 1, 1.5f * (minecartPositions[1] - minecartPositions[0]).magnitude + 4.5f);
            rail2.transform.SetParent(transform);
            minecart.rail2 = rail2;
        }
    }
예제 #23
0
 public void Init()
 {
     if (init)
     {
         return;
     }
     init = true;
     if (GameManager.isLocalGame)
     {
         Destroy(this);
         return;
     }
     info     = new Info();
     info.key = gameObject.name;
     allObjs.Add(this);
     objsDict.Add(info.key, this);
     minecart = GetComponent <Minecart>();
 }
예제 #24
0
        private bool AlreadyLeadsIntoWantedTrack(
            Point tileCoordsOfFrontWheel,
            Point tileCoordsWeWantToReach)
        {
            Tile tileSafely1 = Framing.GetTileSafely(tileCoordsOfFrontWheel);
            Tile tileSafely2 = Framing.GetTileSafely(tileCoordsWeWantToReach);

            if (!tileSafely1.active() || tileSafely1.type != (ushort)314 || (!tileSafely2.active() || tileSafely2.type != (ushort)314))
            {
                return(false);
            }
            int?expectedStartLeft;
            int?expectedStartRight;
            int?expectedEndLeft;
            int?expectedEndRight;

            MinecartDiggerHelper.GetExpectedDirections(tileCoordsOfFrontWheel, tileCoordsWeWantToReach, out expectedStartLeft, out expectedStartRight, out expectedEndLeft, out expectedEndRight);
            return(Minecart.GetAreExpectationsForSidesMet(tileCoordsOfFrontWheel, expectedStartLeft, expectedStartRight) && Minecart.GetAreExpectationsForSidesMet(tileCoordsWeWantToReach, expectedEndLeft, expectedEndRight));
        }
예제 #25
0
    // Start is called before the first frame update
    void Awake()
    {
        effects = new List <EffectType>();
        enem    = GetComponent <Enemy>();
        if (!enem)
        {
            mc           = GetComponent <Minecart>();
            originals    = new Material[1];
            originals[0] = new Material(Resources.Load <Material>("Wheel/minecart_wheel"));
            mcParts      = gameObject.GetComponentsInChildren <Transform>();

            /*int j = 0;
             * for(int i=0; i< mcParts.Length; i++)
             * {
             *      if(mcParts[i].name.Contains("minecartwheel"))
             *      {
             *              originals[j] = new Material(mcParts[i].GetChild(0).gameObject.GetComponent<MeshRenderer>().material);
             *              j++;
             *      }
             * }*/
            frost = Resources.Load <Material>("GolemMats/GolemFrost");
        }
        else
        {
            string name = "Golem";
            if (enem.gameObject.name.Contains("Blaster"))
            {
                name = "Blaster";
            }

            originals = new Material[enem.BodyParts.Length];
            var i = 0;
            if (!name.Contains("Balloon"))
            {
                foreach (GameObject bodyPart in enem.BodyParts)
                {
                    originals[i] = new Material(bodyPart.GetComponent <SkinnedMeshRenderer>().material);
                    i++;
                }
            }
        }
    }
예제 #26
0
파일: Day13.cs 프로젝트: RPScylla/AoC
        private char[,] GenerateTrack(string[] input, out List <Minecart> minecarts)
        {
            char[,] track = new char[input.Length, input[0].Length];
            minecarts     = new List <Minecart>();
            for (int y = 0; y < input.Length; y++)
            {
                for (int x = 0; x < input[y].Length; x++)
                {
                    char c = input[y][x];
                    track[y, x] = c;
                    Direction?createCartInDirection = null;

                    if (c.Equals('<'))
                    {
                        createCartInDirection = Direction.Left;
                        track[y, x]           = '-';
                    }
                    else if (c.Equals('>'))
                    {
                        createCartInDirection = Direction.Right;
                        track[y, x]           = '-';
                    }
                    else if (c.Equals('^'))
                    {
                        createCartInDirection = Direction.Up;
                        track[y, x]           = '|';
                    }
                    else if (c.Equals('v'))
                    {
                        createCartInDirection = Direction.Down;
                        track[y, x]           = '|';
                    }

                    if (createCartInDirection.HasValue)
                    {
                        Minecart minecart = new Minecart(createCartInDirection.Value, x, y);
                        minecarts.Add(minecart);
                    }
                }
            }
            return(track);
        }
예제 #27
0
 public override void OnNewFrameDraw3d(Game game, float deltaTime)
 {
     for (int i = 0; i < game.entitiesCount; i++)
     {
         if (game.entities[i] == null)
         {
             continue;
         }
         if (game.entities[i].minecart == null)
         {
             continue;
         }
         Minecart m = game.entities[i].minecart;
         if (!m.enabled)
         {
             continue;
         }
         Draw(game, m.positionX, m.positionY, m.positionZ, m.direction, m.lastdirection, m.progress);
     }
 }
예제 #28
0
    public override bool Place(Minecart mc)
    {
        Content = mc;
        Previous.Content = null;

        if (Ship.IsDocked)
        {
            Content.Loaded = false;
            Board.Score += 1;
            Ship.Cargo += 1;

            if (Ship.Cargo == 8)
            {
                Ship.Depart();
                Board.Score += 10;
            }
        }

        return true;
    }
예제 #29
0
 public void CreateMinecartWindow()
 {
     if (Minecart == null || !Minecart.Visible)
     {
         Cursor.Current = Cursors.WaitCursor;
         Minecart       = new Minecart.OwnerForm();
         if (DockEditors)
         {
             Do.AddControl(MainForm.PanelForms, Minecart);
         }
         else
         {
             Minecart.Show();
         }
         loadedForms.Add(Minecart);
         Cursor.Current = Cursors.Arrow;
     }
     Minecart.KeyDown += new KeyEventHandler(editor_KeyDown);
     Minecart.BringToFront();
 }
예제 #30
0
        private void CorrectTrackConnections(Point startCoords, Point endCoords)
        {
            int?expectedStartLeft;
            int?expectedStartRight;
            int?expectedEndLeft;
            int?expectedEndRight;

            MinecartDiggerHelper.GetExpectedDirections(startCoords, endCoords, out expectedStartLeft, out expectedStartRight, out expectedEndLeft, out expectedEndRight);
            Tile tileSafely1 = Framing.GetTileSafely(startCoords);
            Tile tileSafely2 = Framing.GetTileSafely(endCoords);

            if (tileSafely1.active() && tileSafely1.type == (ushort)314)
            {
                Minecart.TryFittingTileOrientation(startCoords, expectedStartLeft, expectedStartRight);
            }
            if (!tileSafely2.active() || tileSafely2.type != (ushort)314)
            {
                return;
            }
            Minecart.TryFittingTileOrientation(endCoords, expectedEndLeft, expectedEndRight);
        }
예제 #31
0
        public static void PrintMapConsole(int width, int height, char[,] map)
        {
            StringBuilder sb = new StringBuilder();

            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
                    Minecart prospectiveCart = lstCarts.SingleOrDefault(r => r.positionX == i && r.positionY == j);
                    if (prospectiveCart != null)
                    {
                        sb.Append((char)prospectiveCart.currentDirection);
                    }
                    else
                    {
                        sb.Append(map[i, j]);
                    }
                }
                sb.Append(Environment.NewLine);
            }
            Console.WriteLine(sb);
        }
예제 #32
0
        private bool AlreadyLeadsIntoWantedTrack(Point tileCoordsOfFrontWheel, Point tileCoordsWeWantToReach)
        {
            Tile tileSafely  = Framing.GetTileSafely(tileCoordsOfFrontWheel);
            Tile tileSafely2 = Framing.GetTileSafely(tileCoordsWeWantToReach);

            if (!tileSafely.active() || tileSafely.type != 314)
            {
                return(false);
            }
            if (!tileSafely2.active() || tileSafely2.type != 314)
            {
                return(false);
            }
            GetExpectedDirections(tileCoordsOfFrontWheel, tileCoordsWeWantToReach, out var expectedStartLeft, out var expectedStartRight, out var expectedEndLeft, out var expectedEndRight);
            if (!Minecart.GetAreExpectationsForSidesMet(tileCoordsOfFrontWheel, expectedStartLeft, expectedStartRight))
            {
                return(false);
            }
            if (!Minecart.GetAreExpectationsForSidesMet(tileCoordsWeWantToReach, expectedEndLeft, expectedEndRight))
            {
                return(false);
            }
            return(true);
        }
예제 #33
0
    internal void RailOnNewFrame(Game game, float dt)
    {
        if (localMinecart == null)
        {
            localMinecart          = new Entity();
            localMinecart.minecart = new Minecart();
            game.EntityAddLocal(localMinecart);
        }
        localMinecart.minecart.enabled = railriding;
        if (railriding)
        {
            Minecart m = localMinecart.minecart;
            m.positionX     = game.player.position.x;
            m.positionY     = game.player.position.y;
            m.positionZ     = game.player.position.z;
            m.direction     = currentdirection;
            m.lastdirection = lastdirection;
            m.progress      = currentrailblockprogress;
        }

        game.localplayeranimationhint.InVehicle = railriding;
        game.localplayeranimationhint.DrawFixX  = 0;
        game.localplayeranimationhint.DrawFixY  = railriding ? (-one * 7 / 10) : 0;
        game.localplayeranimationhint.DrawFixZ  = 0;

        bool turnright = game.keyboardState[game.GetKey(GlKeys.D)];
        bool turnleft  = game.keyboardState[game.GetKey(GlKeys.A)];

        RailSound(game);
        if (railriding)
        {
            game.controls.SetFreemove(FreemoveLevelEnum.Freemove);
            game.enable_move = false;
            Vector3Ref railPos = CurrentRailPos(game);
            game.player.position.x    = railPos.X;
            game.player.position.y    = railPos.Y;
            game.player.position.z    = railPos.Z;
            currentrailblockprogress += currentvehiclespeed * dt;
            if (currentrailblockprogress >= 1)
            {
                lastdirection            = currentdirection;
                currentrailblockprogress = 0;
                TileEnterData newenter = new TileEnterData();
                Vector3IntRef nexttile = NextTile(currentdirection, currentrailblockX, currentrailblockY, currentrailblockZ);
                newenter.BlockPositionX = nexttile.X;
                newenter.BlockPositionY = nexttile.Y;
                newenter.BlockPositionZ = nexttile.Z;
                //slope
                if (GetUpDownMove(game, currentrailblockX, currentrailblockY, currentrailblockZ,
                                  DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Up)
                {
                    newenter.BlockPositionZ++;
                }
                if (GetUpDownMove(game, newenter.BlockPositionX,
                                  newenter.BlockPositionY,
                                  newenter.BlockPositionZ - 1,
                                  DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Down)
                {
                    newenter.BlockPositionZ--;
                }

                newenter.EnterDirection = DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection));
                BoolRef            newdirFound = new BoolRef();
                VehicleDirection12 newdir      = BestNewDirection(PossibleRails(game, newenter), turnleft, turnright, newdirFound);
                if (!newdirFound.value)
                {
                    //end of rail
                    currentdirection = DirectionUtils.Reverse(currentdirection);
                }
                else
                {
                    currentdirection  = newdir;
                    currentrailblockX = game.platform.FloatToInt(newenter.BlockPositionX);
                    currentrailblockY = game.platform.FloatToInt(newenter.BlockPositionY);
                    currentrailblockZ = game.platform.FloatToInt(newenter.BlockPositionZ);
                }
            }
        }
        if (game.keyboardState[game.GetKey(GlKeys.W)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed += 1 * dt;
        }
        if (game.keyboardState[game.GetKey(GlKeys.S)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed -= 5 * dt;
        }
        if (currentvehiclespeed < 0)
        {
            currentvehiclespeed = 0;
        }
        //todo fix
        //if (viewport.keypressed != null && viewport.keypressed.Key == GlKeys.Q)
        if (!wasqpressed && game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing)
        {
            Reverse();
        }
        if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && !railriding && (game.controls.GetFreemove() == FreemoveLevelEnum.None) && game.GuiTyping != TypingState.Typing)
        {
            currentrailblockX = game.platform.FloatToInt(game.player.position.x);
            currentrailblockY = game.platform.FloatToInt(game.player.position.z);
            currentrailblockZ = game.platform.FloatToInt(game.player.position.y) - 1;
            if (!game.map.IsValidPos(currentrailblockX, currentrailblockY, currentrailblockZ))
            {
                ExitVehicle(game);
            }
            else
            {
                int railunderplayer = game.d_Data.Rail()[game.map.GetBlock(currentrailblockX, currentrailblockY, currentrailblockZ)];
                railriding          = true;
                originalmodelheight = game.GetCharacterEyesHeight();
                game.SetCharacterEyesHeight(minecartheight());
                currentvehiclespeed = 0;
                if ((railunderplayer & RailDirectionFlags.Horizontal) != 0)
                {
                    currentdirection = VehicleDirection12.HorizontalRight;
                }
                else if ((railunderplayer & RailDirectionFlags.Vertical) != 0)
                {
                    currentdirection = VehicleDirection12.VerticalUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpLeft) != 0)
                {
                    currentdirection = VehicleDirection12.UpLeftUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpRight) != 0)
                {
                    currentdirection = VehicleDirection12.UpRightUp;
                }
                else if ((railunderplayer & RailDirectionFlags.DownLeft) != 0)
                {
                    currentdirection = VehicleDirection12.DownLeftLeft;
                }
                else if ((railunderplayer & RailDirectionFlags.DownRight) != 0)
                {
                    currentdirection = VehicleDirection12.DownRightRight;
                }
                else
                {
                    ExitVehicle(game);
                }
                lastdirection = currentdirection;
            }
        }
        else if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && railriding && game.GuiTyping != TypingState.Typing)
        {
            ExitVehicle(game);
            game.player.position.y += one * 7 / 10;
        }
        wasqpressed = game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing;
        wasepressed = game.keyboardState[game.GetKey(GlKeys.E)] && game.GuiTyping != TypingState.Typing;
    }
예제 #34
0
 public virtual void Spawn()
 {
     Minecart mineCart = new Minecart();
     Random randomPath = new Random();
     int random = randomPath.Next(2);
     if (random == 0)
     {
         boardInjector.DockPath.First.Next.Value.Place(mineCart);
         UsedTracks.Add(boardInjector.DockPath.First.Next.Value);
     }
     else if (random == 1)
     {
         boardInjector.SecondPath.First.Next.Value.Place(mineCart);
         UsedTracks.Add(boardInjector.SecondPath.First.Next.Value);
     }
     else if (random == 2)
     {
         boardInjector.SavePath.First.Next.Value.Place(mineCart);
         UsedTracks.Add(boardInjector.SavePath.First.Next.Value);
     }
 }
예제 #35
0
 // Hop into a minecart.
 public void JumpIntoMinecart(Minecart minecart)
 {
     JumpToPosition(minecart.Center, 4.0f, 26, delegate(PlayerJumpToState state) {
         stateMinecart.Minecart = minecart;
         BeginSpecialState(stateMinecart);
     });
 }
        //-----------------------------------------------------------------------------
        // Navigation methods
        //-----------------------------------------------------------------------------
        // Exit the minecart, dropping the player off in the given direction.
        private void ExitMinecart(int direction)
        {
            // Spawn another minecart entity.
            if (minecart == null || minecart.IsDestroyed) {
                minecart = new Minecart(trackTile);
                player.RoomControl.SpawnEntity(minecart, tileLocation * GameSettings.TILE_SIZE);
                minecart = null;
            }

            // Make the current track tile remember it has a minecart on it.
            if (trackTile != null)
                trackTile.SpawnsMinecart = true;

            // Hop out of the minecart.
            Point2I landingTile = tileLocation + Directions.ToPoint(direction);
            player.JumpOutOfMinecart(landingTile);
        }
예제 #37
0
 public override bool Place(Minecart mc)
 {
     throw new System.NotImplementedException();
 }
예제 #38
0
            private bool AdvanceCart(Minecart a)
            {
                int nextTileX = a.X;
                int nextTileY = a.Y;

                switch (a.Orientation)
                {
                case MinecartOrientation.FacingEast:
                    nextTileX++;
                    break;

                case MinecartOrientation.FacingWest:
                    nextTileX--;
                    break;

                case MinecartOrientation.FacingNorth:
                    nextTileY--;
                    break;

                case MinecartOrientation.FacingSouth:
                    nextTileY++;
                    break;
                }


                int oldTileIndex = a.TileIndex;
                int newTileIndex = GetTileIndex(nextTileX, nextTileY);

                a.X         = nextTileX;
                a.Y         = nextTileY;
                a.TileIndex = newTileIndex;

                Minecart newLocation = _cartLocations[newTileIndex];

                if (newLocation != null)
                {
                    Log.WriteLine("Mine cart collided at " + a.X + "," + a.Y);
                    return(true);
                }

                _cartLocations[oldTileIndex] = null;
                _cartLocations[newTileIndex] = a;



                // Adjust orientation for next step
                MinecartTile tile = _tiles[newTileIndex];

                switch (tile.TileType)
                {
                case MinecartTileType.CurveEastToSouth:
                    if (a.Orientation == MinecartOrientation.FacingEast)
                    {
                        a.Orientation = MinecartOrientation.FacingSouth;
                    }
                    else
                    {
                        a.Orientation = MinecartOrientation.FacingWest;
                    }
                    break;

                case MinecartTileType.CurveNorthToEast:
                    if (a.Orientation == MinecartOrientation.FacingNorth)
                    {
                        a.Orientation = MinecartOrientation.FacingEast;
                    }
                    else
                    {
                        a.Orientation = MinecartOrientation.FacingSouth;
                    }
                    break;

                case MinecartTileType.CurveSouthToWest:
                    if (a.Orientation == MinecartOrientation.FacingSouth)
                    {
                        a.Orientation = MinecartOrientation.FacingWest;
                    }
                    else
                    {
                        a.Orientation = MinecartOrientation.FacingNorth;
                    }
                    break;

                case MinecartTileType.CurveWestToNorth:
                    if (a.Orientation == MinecartOrientation.FacingWest)
                    {
                        a.Orientation = MinecartOrientation.FacingNorth;
                    }
                    else
                    {
                        a.Orientation = MinecartOrientation.FacingEast;
                    }
                    break;

                case MinecartTileType.Intersection:

                    int turnCount = a.TurnCount;
                    if (turnCount == 0)                             // Left turn
                    {
                        switch (a.Orientation)
                        {
                        case MinecartOrientation.FacingNorth:
                            a.Orientation = MinecartOrientation.FacingWest;
                            break;

                        case MinecartOrientation.FacingWest:
                            a.Orientation = MinecartOrientation.FacingSouth;
                            break;

                        case MinecartOrientation.FacingEast:
                            a.Orientation = MinecartOrientation.FacingNorth;
                            break;

                        case MinecartOrientation.FacingSouth:
                            a.Orientation = MinecartOrientation.FacingEast;
                            break;
                        }
                    }
                    else if (turnCount == 1)                               // Straight
                    {
                    }
                    else if (turnCount == 2)                               // Right turn
                    {
                        switch (a.Orientation)
                        {
                        case MinecartOrientation.FacingNorth:
                            a.Orientation = MinecartOrientation.FacingEast;
                            break;

                        case MinecartOrientation.FacingWest:
                            a.Orientation = MinecartOrientation.FacingNorth;
                            break;

                        case MinecartOrientation.FacingEast:
                            a.Orientation = MinecartOrientation.FacingSouth;
                            break;

                        case MinecartOrientation.FacingSouth:
                            a.Orientation = MinecartOrientation.FacingWest;
                            break;
                        }
                    }
                    turnCount++;
                    a.TurnCount = turnCount % 3;
                    break;
                }

                return(false);
            }
        private static void ProcessTileBreak(int bufferId)
        {
            var buffer = NetMessage.buffer[bufferId];

            byte  action = buffer.reader.ReadByte();
            int   x      = (int)buffer.reader.ReadInt16();
            int   y      = (int)buffer.reader.ReadInt16();
            short type   = buffer.reader.ReadInt16();
            int   style  = (int)buffer.reader.ReadByte();
            bool  fail   = type == 1;

            if (!WorldGen.InWorld(x, y, 3))
            {
                return;
            }

            var player = Main.player[bufferId];

            //TODO implement the old methods
            var ctx = new HookContext
            {
                Connection = player.Connection,
                Sender     = player,
                Player     = player,
            };

            var args = new HookArgs.PlayerWorldAlteration
            {
                X      = x,
                Y      = y,
                Action = action,
                Type   = type,
                Style  = style
            };

            HookPoints.PlayerWorldAlteration.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                //Terraria.WorldGen.SquareTileFrame (x, y, true);
                NetMessage.SendTileSquare(bufferId, x, y, 1);
                return;
            }

            if (Main.tile[x, y] == null)
            {
                Main.tile[x, y] = new Tile();
            }

            if (Main.netMode == 2)
            {
                if (!fail)
                {
                    if (action == 0 || action == 2 || action == 4)
                    {
                        Netplay.Clients[bufferId].SpamDeleteBlock += 1;
                    }
                    if (action == 1 || action == 3)
                    {
                        Netplay.Clients[bufferId].SpamAddBlock += 1;
                    }
                }
                if (!Netplay.Clients[bufferId].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
                {
                    fail = true;
                }
            }
            if (action == 0)
            {
                WorldGen.KillTile(x, y, fail, false, false);
            }
            if (action == 1)
            {
                WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style);
            }
            if (action == 2)
            {
                WorldGen.KillWall(x, y, fail);
            }
            if (action == 3)
            {
                WorldGen.PlaceWall(x, y, (int)type, false);
            }
            if (action == 4)
            {
                WorldGen.KillTile(x, y, fail, false, true);
            }
            if (action == 5)
            {
                WorldGen.PlaceWire(x, y);
            }
            if (action == 6)
            {
                WorldGen.KillWire(x, y);
            }
            if (action == 7)
            {
                WorldGen.PoundTile(x, y);
            }
            if (action == 8)
            {
                WorldGen.PlaceActuator(x, y);
            }
            if (action == 9)
            {
                WorldGen.KillActuator(x, y);
            }
            if (action == 10)
            {
                WorldGen.PlaceWire2(x, y);
            }
            if (action == 11)
            {
                WorldGen.KillWire2(x, y);
            }
            if (action == 12)
            {
                WorldGen.PlaceWire3(x, y);
            }
            if (action == 13)
            {
                WorldGen.KillWire3(x, y);
            }
            if (action == 14)
            {
                WorldGen.SlopeTile(x, y, (int)type);
            }
            if (action == 15)
            {
                Minecart.FrameTrack(x, y, true, false);
            }
            if (Main.netMode != 2)
            {
                return;
            }
            NetMessage.SendData(17, -1, bufferId, "", (int)action, (float)x, (float)y, (float)type, style, 0, 0);
            if (action == 1 && type == 53)
            {
                NetMessage.SendTileSquare(-1, x, y, 1);
            }
        }
        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            byte  action = ReadByte(readBuffer);
            int   x      = (int)ReadInt16(readBuffer);
            int   y      = (int)ReadInt16(readBuffer);
            short type   = ReadInt16(readBuffer);
            int   style  = (int)ReadByte(readBuffer);
            bool  fail   = type == 1;

            var player = Main.player[whoAmI];

            if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY)
            {
                player.Kick("Out of range tile received from client.");
                return;
            }

            if (!Terraria.Netplay.Clients[whoAmI].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
            {
                Tools.WriteLine("{0} @ {1}: {2} attempted to alter world in unloaded tile.");
                return;
            }

            //TODO implement the old methods
            var ctx = new HookContext
            {
                Connection = (Terraria.Netplay.Clients[whoAmI] as ServerSlot).conn,
                Sender     = player,
                Player     = player,
            };

            var args = new HookArgs.PlayerWorldAlteration
            {
                X      = x,
                Y      = y,
                Action = action,
                Type   = type,
                Style  = style
            };

            HookPoints.PlayerWorldAlteration.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                //Terraria.WorldGen.SquareTileFrame (x, y, true);

                NewNetMessage.SendTileSquare(whoAmI, x, y, 1);
                return;
            }

            if (Main.tile[x, y] == null)
            {
                Main.tile[x, y] = new Tile();
            }
            if (Main.netMode == 2)
            {
                if (!fail)
                {
                    if (action == 0 || action == 2 || action == 4)
                    {
                        Terraria.Netplay.Clients[whoAmI].SpamDeleteBlock += 1f;
                    }
                    if (action == 1 || action == 3)
                    {
                        Terraria.Netplay.Clients[whoAmI].SpamAddBlock += 1f;
                    }
                }
                if (!Terraria.Netplay.Clients[whoAmI].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
                {
                    fail = true;
                }
            }

            if (action == 0)
            {
                WorldGen.KillTile(x, y, fail, false, false);
            }
            if (action == 1)
            {
                WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style);
            }
            if (action == 2)
            {
                WorldGen.KillWall(x, y, fail);
            }
            if (action == 3)
            {
                WorldGen.PlaceWall(x, y, (int)type, false);
            }
            if (action == 4)
            {
                WorldGen.KillTile(x, y, fail, false, true);
            }
            if (action == 5)
            {
                WorldGen.PlaceWire(x, y);
            }
            if (action == 6)
            {
                WorldGen.KillWire(x, y);
            }
            if (action == 7)
            {
                WorldGen.PoundTile(x, y);
            }
            if (action == 8)
            {
                WorldGen.PlaceActuator(x, y);
            }
            if (action == 9)
            {
                WorldGen.KillActuator(x, y);
            }
            if (action == 10)
            {
                WorldGen.PlaceWire2(x, y);
            }
            if (action == 11)
            {
                WorldGen.KillWire2(x, y);
            }
            if (action == 12)
            {
                WorldGen.PlaceWire3(x, y);
            }
            if (action == 13)
            {
                WorldGen.KillWire3(x, y);
            }
            if (action == 14)
            {
                WorldGen.SlopeTile(x, y, (int)type);
            }
            if (action == 15)
            {
                Minecart.FrameTrack(x, y, true, false);
            }
            if (Main.netMode != 2)
            {
                return;
            }
            NewNetMessage.SendData(17, -1, whoAmI, String.Empty, (int)action, (float)x, (float)y, (float)type, style);
            if (action == 1 && type == 53)
            {
                NewNetMessage.SendTileSquare(-1, x, y, 1);
                return;
            }
        }
예제 #41
0
        public bool Read(int bufferId, int start, int length)
        {
            var buffer = NetMessage.buffer[bufferId];

            ActionType action = (ActionType)buffer.reader.ReadByte();
            int        x      = (int)buffer.reader.ReadInt16();
            int        y      = (int)buffer.reader.ReadInt16();
            short      type   = buffer.reader.ReadInt16();
            int        style  = (int)buffer.reader.ReadByte();
            bool       fail   = type == 1;

            if (!WorldGen.InWorld(x, y, 3))
            {
                return(true);
            }

            var player = Main.player[bufferId];

            //TODO implement the old methods
            var ctx = new HookContext
            {
                Connection = player.Connection.Socket,
                Sender     = player,
                Player     = player,
            };

            var args = new TDSMHookArgs.PlayerWorldAlteration
            {
                X      = x,
                Y      = y,
                Action = action,
                Type   = type,
                Style  = style
            };

            TDSMHookPoints.PlayerWorldAlteration.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return(true);
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return(true);
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                //Terraria.WorldGen.SquareTileFrame (x, y, true);
                NetMessage.SendTileSquare(bufferId, x, y, 1);
                return(true);
            }

            if (Main.tile[x, y] == null)
            {
                Main.tile[x, y] = new OTA.Memory.MemTile();
            }

            if (Main.netMode == 2)
            {
                if (!fail)
                {
                    if (action == ActionType.KillTile || action == ActionType.KillWall || action == ActionType.KillTile1)
                    {
                        Netplay.Clients[bufferId].SpamDeleteBlock += 1;
                    }
                    if (action == ActionType.PlaceTile || action == ActionType.PlaceWall)
                    {
                        Netplay.Clients[bufferId].SpamAddBlock += 1;
                    }
                }
                if (!Netplay.Clients[bufferId].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)])
                {
                    fail = true;
                }
            }
            switch (action)
            {
            case ActionType.KillTile:
                WorldGen.KillTile(x, y, fail, false, false);
                break;

            case ActionType.PlaceTile:
                WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style);
                break;

            case ActionType.KillWall:
                WorldGen.KillWall(x, y, fail);
                break;

            case ActionType.PlaceWall:
                WorldGen.PlaceWall(x, y, (int)type, false);
                break;

            case ActionType.KillTile1:
                WorldGen.KillTile(x, y, fail, false, true);
                break;

            case ActionType.PlaceWire:
                WorldGen.PlaceWall(x, y, (int)type, false);
                break;

            case ActionType.KillWire:
                WorldGen.KillWire(x, y);
                break;

            case ActionType.PoundTile:
                WorldGen.PoundTile(x, y);
                break;

            case ActionType.PlaceActuator:
                WorldGen.PlaceActuator(x, y);
                break;

            case ActionType.KillActuator:
                WorldGen.KillActuator(x, y);
                break;

            case ActionType.PlaceWire2:
                WorldGen.PlaceWire2(x, y);
                break;

            case ActionType.KillWire2:
                WorldGen.KillWire2(x, y);
                break;

            case ActionType.PlaceWire3:
                WorldGen.PlaceWire3(x, y);
                break;

            case ActionType.KillWire3:
                WorldGen.KillWire3(x, y);
                break;

            case ActionType.SlopeTile:
                WorldGen.SlopeTile(x, y, (int)type);
                break;

            case ActionType.FrameTrack:
                Minecart.FrameTrack(x, y, true, false);
                break;

            case ActionType.PlaceWire4:
                WorldGen.PlaceWire4(x, y);
                break;

            case ActionType.KillWire4:
                WorldGen.KillWire4(x, y);
                break;

            case ActionType.PlaceLogicGate:
                Wiring.SetCurrentUser(bufferId);
                Wiring.PokeLogicGate(x, y);
                Wiring.SetCurrentUser(-1);
                return(true);

            case ActionType.Actuate:
                Wiring.SetCurrentUser(bufferId);
                Wiring.Actuate(x, y);
                Wiring.SetCurrentUser(-1);
                return(true);
            }
            if (Main.netMode != 2)
            {
                return(true);
            }
            NetMessage.SendData(17, -1, bufferId, "", (int)action, (float)x, (float)y, (float)type, style, 0, 0);
            if (action == ActionType.PlaceTile && type == 53)
            {
                NetMessage.SendTileSquare(-1, x, y, 1);
            }

            return(true);
        }