public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            byte doorAction    = ReadByte(readBuffer);
            int  x             = (int)ReadInt16(readBuffer);
            int  y             = (int)ReadInt16(readBuffer);
            int  doorDirection = (ReadByte(readBuffer) == 0) ? -1 : 1;

            if (doorAction == 0)
            {
                WorldGen.OpenDoor(x, y, doorDirection);
            }
            else if (doorAction == 1)
            {
                WorldGen.CloseDoor(x, y, true);
            }

            NewNetMessage.SendData(19, -1, whoAmI, String.Empty, (int)doorAction, (float)x, (float)y, (float)((doorDirection == 1) ? 1 : 0), 0);
        }
Esempio n. 2
0
            public DoorOpeningHelper.DoorCloseAttemptResult TryCloseDoor(
                DoorOpeningHelper.DoorOpenCloseTogglingInfo info,
                DoorOpeningHelper.PlayerInfoForClosingDoors playerInfo)
            {
                Point coordsForToggling = info.tileCoordsForToggling;
                Tile  tile = Main.tile[coordsForToggling.X, coordsForToggling.Y];

                if (!tile.active() || tile.type != (ushort)11)
                {
                    return(DoorOpeningHelper.DoorCloseAttemptResult.DoorIsInvalidated);
                }
                int       num        = (int)tile.frameX % 72 / 18;
                Rectangle rectangle1 = new Rectangle(coordsForToggling.X * 16, coordsForToggling.Y * 16, 16, 48);

                switch (num)
                {
                case 1:
                    rectangle1.X -= 16;
                    break;

                case 2:
                    rectangle1.X += 16;
                    break;
                }
                rectangle1.Inflate(1, 0);
                Rectangle rectangle2 = Rectangle.Intersect(rectangle1, playerInfo.hitboxToNotCloseDoor);

                if (rectangle2.Width > 0 || rectangle2.Height > 0)
                {
                    return(DoorOpeningHelper.DoorCloseAttemptResult.StillInDoorArea);
                }
                if (!WorldGen.CloseDoor(coordsForToggling.X, coordsForToggling.Y, false))
                {
                    return(DoorOpeningHelper.DoorCloseAttemptResult.FailedToCloseDoor);
                }
                NetMessage.SendData(13, -1, -1, (NetworkText)null, Main.myPlayer, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                NetMessage.SendData(19, -1, -1, (NetworkText)null, 1, (float)coordsForToggling.X, (float)coordsForToggling.Y, 1f, 0, 0, 0);
                return(DoorOpeningHelper.DoorCloseAttemptResult.ClosedDoor);
            }
            public DoorCloseAttemptResult TryCloseDoor(DoorOpenCloseTogglingInfo info, PlayerInfoForClosingDoors playerInfo)
            {
                Point tileCoordsForToggling = info.tileCoordsForToggling;
                Tile  tile = Main.tile[tileCoordsForToggling.X, tileCoordsForToggling.Y];

                if (!tile.active() || tile.type != 11)
                {
                    return(DoorCloseAttemptResult.DoorIsInvalidated);
                }
                int       num   = tile.frameX % 72 / 18;
                Rectangle value = new Rectangle(tileCoordsForToggling.X * 16, tileCoordsForToggling.Y * 16, 16, 48);

                switch (num)
                {
                case 1:
                    value.X -= 16;
                    break;

                case 2:
                    value.X += 16;
                    break;
                }
                value.Inflate(1, 0);
                Rectangle rectangle = Rectangle.Intersect(value, playerInfo.hitboxToNotCloseDoor);

                if (rectangle.Width > 0 || rectangle.Height > 0)
                {
                    return(DoorCloseAttemptResult.StillInDoorArea);
                }
                if (WorldGen.CloseDoor(tileCoordsForToggling.X, tileCoordsForToggling.Y))
                {
                    NetMessage.SendData(13, -1, -1, null, Main.myPlayer);
                    NetMessage.SendData(19, -1, -1, null, 1, tileCoordsForToggling.X, tileCoordsForToggling.Y, 1f);
                    return(DoorCloseAttemptResult.ClosedDoor);
                }
                return(DoorCloseAttemptResult.FailedToCloseDoor);
            }
Esempio n. 4
0
        public bool Read(int bufferId, int start, int length)
        {
            var  buffer = NetMessage.buffer[bufferId];
            byte kind   = buffer.reader.ReadByte();
            int  x      = (int)buffer.reader.ReadInt16();
            int  y      = (int)buffer.reader.ReadInt16();

            if (!WorldGen.InWorld(x, y, 3))
            {
                return(true);
            }
            int direction = (buffer.reader.ReadByte() == 0) ? -1 : 1;

            var args = new TDSMHookArgs.BarrierStateChange()
            {
                X         = x,
                Y         = y,
                Direction = direction,
                Kind      = kind
            };
            var ctx = new HookContext()
            {
                Sender = Main.player[bufferId],
                Player = Main.player[bufferId]
            };

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

            if (ctx.Result == HookResult.DEFAULT)
            {
                if (kind == 0)
                {
                    WorldGen.OpenDoor(x, y, direction);
                }
                else if (kind == 1)
                {
                    WorldGen.CloseDoor(x, y, true);
                }
                else if (kind == 2)
                {
                    WorldGen.ShiftTrapdoor(x, y, direction == 1, 1);
                }
                else if (kind == 3)
                {
                    WorldGen.ShiftTrapdoor(x, y, direction == 1, 0);
                }
                else if (kind == 4)
                {
                    WorldGen.ShiftTallGate(x, y, false);
                }
                else if (kind == 5)
                {
                    WorldGen.ShiftTallGate(x, y, true);
                }

                if (Main.netMode == 2)
                {
                    NetMessage.SendData((int)Packet.BARRIER_STATE_CHANGE, -1, bufferId, "", (int)kind, (float)x, (float)y, (float)((direction == 1) ? 1 : 0));
                }
            }
            else if (ctx.Result == HookResult.RECTIFY)
            {
                if (Main.netMode == 2)
                {
                    //Teleport
                    ctx.Player.Teleport(args.Position);

                    //I would think to send the real door state
                    if (kind == 0)
                    {
                        kind = 1;
                    }
                    else if (kind == 1)
                    {
                        kind = 0;
                    }
                    else if (kind == 2)
                    {
                        kind = 3;
                    }
                    else if (kind == 3)
                    {
                        kind = 2;
                    }
                    else if (kind == 4)
                    {
                        kind = 5;
                    }
                    else if (kind == 5)
                    {
                        kind = 4;
                    }

                    if (Main.netMode == 2)
                    {
                        NetMessage.SendData((int)Packet.BARRIER_STATE_CHANGE, -1, bufferId, "", (int)kind, (float)x, (float)y, (float)((direction == 1) ? 1 : 0));
                    }
                }
            }

            return(true);
        }
Esempio n. 5
0
 public override void PreUpdate()
 {
     if (logoTimer == 80)
     {
         Revolutions.bluePrintManager = new BluePrintManager(mod);
     }
     if (Main.playerInventory && Revolutions.bluePrintManager != null)
     {
         Revolutions.bluePrintManager.Update();
     }
     if (!starFlareStatus)
     {
         starFlareColor = new Color(126, 171, 243);
     }
     else
     {
         starFlareColor = Helper.SFCtypeToColor(starFlareColorType);
     }
     if (Revolutions.Settings.spcolor)
     {
         spname = Helper.Name2Specialname(player.name);
     }
     else
     {
         spname = "none";
     }
     //过去的属性
     for (int j = 600; j > 0; j--)
     {
         pastPosition[j] = pastPosition[j - 1];
         pastCenter[j]   = pastCenter[j - 1];
         pastSpeed[j]    = pastSpeed[j - 1];
         pastLife[j]     = pastLife[j - 1];
         pastMana[j]     = pastMana[j - 1];
         starFlare[j]    = starFlare[j - 1];
         corePower[j]    = corePower[j - 1];
     }
     for (int i = 0; i < npctalk.Count; i++)
     {
         if (npctalk[i].timer > 0)
         {
             npctalk[i].timer--;
         }
         else
         {
             npctalk.RemoveAt(i);
         }
     }
     pastPosition[0] = player.position;
     pastCenter[0]   = player.Center;
     pastSpeed[0]    = player.velocity;
     pastLife[0]     = player.statLife;
     pastMana[0]     = player.statMana;
     if (talkActive > 0)
     {
         talkActive--;
     }
     //周期性事件
     if (timer == 60)
     {
         timer             = 0;
         justDmgcounter    = 0;
         sLifeStealcounter = 0;
     }
     else
     {
         timer++;
     }
     //周期性事件
     if (timer % 20 == 0 && timer != 0)
     {
         if (starFlare[0] + 1 > maxStarFlare)
         {
             starFlare[0] = maxStarFlare;
         }
         else
         {
             starFlare[0] += 1;
         }
     }
     if (timer == 30 || timer == 60)
     {
         if (hitcounter == 0 && nowBoss != null && difficulty < 100)
         {
             difficulty++;
         }
     }
     if (nowBoss == null)
     {
         difficulty = 50;
     }
     //自动开关门
     if (Revolutions.Settings.autodoor)
     {
         for (int i = 0; i < justOpenDoors.Count; i++)
         {
             var door = justOpenDoors.ToArray()[i];
             if (Vector2.Distance(door.ToVector2(), Helper.ToTilesPos(player.Center).ToVector2()) >= 3)
             {
                 WorldGen.CloseDoor(door.X, door.Y);
                 justOpenDoors.RemoveAt(i);
             }
         }
         if (Main.tile[Helper.ToTilesPos(player.Center).X + 1, Helper.ToTilesPos(player.Center).Y].type == TileID.ClosedDoor)
         {
             if (!WorldGen.OpenDoor(Helper.ToTilesPos(player.Center).X + 1, Helper.ToTilesPos(player.Center).Y, player.direction))
             {
                 WorldGen.OpenDoor(Helper.ToTilesPos(player.Center).X + 1, Helper.ToTilesPos(player.Center).Y, -player.direction);
             }
             justOpenDoors.Add(new Point(Helper.ToTilesPos(player.Center).X + 1, Helper.ToTilesPos(player.Center).Y));
         }
         if (Main.tile[Helper.ToTilesPos(player.Center).X - 1, Helper.ToTilesPos(player.Center).Y].type == TileID.ClosedDoor)
         {
             if (!WorldGen.OpenDoor(Helper.ToTilesPos(player.Center).X - 1, Helper.ToTilesPos(player.Center).Y, player.direction))
             {
                 WorldGen.OpenDoor(Helper.ToTilesPos(player.Center).X - 1, Helper.ToTilesPos(player.Center).Y, -player.direction);
             }
             justOpenDoors.Add(new Point(Helper.ToTilesPos(player.Center).X - 1, Helper.ToTilesPos(player.Center).Y));
         }
     }
 }