@@ -10,7 +10,7 @@ namespace BridgeBuilder
1010 public class BridgeBuilder : TerrariaPlugin
1111 {
1212 public override string Name => "BridgeBuilder" ;
13- public override Version Version => new Version ( 1 , 0 , 5 ) ;
13+ public override Version Version => new Version ( 1 , 0 , 6 ) ;
1414 public override string Author => "Soofa,肝帝熙恩汉化1449" ;
1515 public override string Description => "铺桥!" ;
1616 public static Configuration Config ;
@@ -46,10 +46,23 @@ private async void BridgeCmd(CommandArgs args)
4646 await Task . Run ( ( ) =>
4747 {
4848 TSPlayer plr = args . Player ;
49- int direction = plr . TPlayer . direction ;
50- int startX = direction == - 1 ? plr . TileX - 1 : plr . TileX + 2 ;
49+ int directionX = plr . TPlayer . direction ;
50+ int directionY = 0 ;
51+
52+ if ( args . Parameters . Count > 0 )
53+ {
54+ string direction = args . Parameters [ 0 ] . ToLower ( ) ;
55+ if ( direction == "up" || direction == "down" )
56+ {
57+ directionY = direction == "up" ? - 1 : 1 ; // 确保正确的垂直方向
58+ directionX = 0 ; // 在垂直建造时,水平方向不移动
59+ }
60+ }
61+
62+ int startX = directionX == 0 ? plr . TileX : ( directionX == - 1 ? plr . TileX - 1 : plr . TileX + 2 ) ;
5163 int i = 0 ;
52- int j = plr . TileY + 3 ;
64+ int j = plr . TileY + ( directionY == - 1 ? - 1 : ( directionY == 1 ? 3 : 3 ) ) ;
65+
5366 Item selectedItem = plr . SelectedItem ;
5467
5568 if ( selectedItem . createTile < 0 && selectedItem . createWall < 0 )
@@ -61,72 +74,68 @@ await Task.Run(() =>
6174 bool isTile = selectedItem . createTile >= 0 ;
6275 int styleId = selectedItem . placeStyle ;
6376
64- if ( j > Main . maxTilesY || j < 0 )
77+ if ( j < 0 || j >= Main . maxTilesY )
6578 {
6679 plr . SendErrorMessage ( "无法在这里建造桥梁。" ) ;
6780 return ;
6881 }
6982
70- if ( isTile )
83+ int placedCount = 0 ;
84+
85+ while ( CheckTileAvailability ( startX + i * directionX , j , plr ) && selectedItem . stack > 0 )
7186 {
72- if ( ! Config . AllowedTileIDs . Contains ( selectedItem . createTile ) )
87+ if ( isTile )
88+ {
89+ WorldGen . PlaceTile ( startX + i * directionX , j , selectedItem . createTile , false , true , - 1 , styleId ) ;
90+ }
91+ else
7392 {
74- plr . SendErrorMessage ( "你手持的物块无法自动建造桥梁。(一般仅允许使用平台或团队块或种植盆。)" ) ;
75- return ;
93+ Main . tile [ startX + i * directionX , j ] . wall = ( ushort ) selectedItem . createWall ;
7694 }
7795
78- int tileCount = 0 ;
79- while ( CheckTileAvailability ( startX , startX + i , j , plr ) )
96+ TSPlayer . All . SendTileRect ( ( short ) ( startX + i * directionX ) , ( short ) j , 1 , 1 ) ;
97+ plr . SelectedItem . stack -- ;
98+ i ++ ;
99+ if ( directionY != 0 ) // 只有在垂直建造时改变Y坐标
80100 {
81- WorldGen . PlaceTile ( startX + i , j , selectedItem . createTile , false , true , - 1 , styleId ) ;
82- TSPlayer . All . SendTileRect ( ( short ) ( startX + i ) , ( short ) j , 1 , 1 ) ;
83- plr . SelectedItem . stack -- ;
84- i += direction ;
85- tileCount ++ ;
101+ j += directionY ;
86102 }
103+ placedCount ++ ;
104+ }
87105
88- plr . SendSuccessMessage ( $ "{ tileCount } 格桥梁建造完成!") ;
106+ if ( placedCount > 0 )
107+ {
108+ plr . SendSuccessMessage ( $ "{ placedCount } 格桥梁建造完成!") ;
89109 }
90110 else
91111 {
92- if ( ! Config . AllowedwallIDs . Contains ( selectedItem . createWall ) )
93- {
94- plr . SendErrorMessage ( "你手持的墙壁无法自动建造桥梁。(一般仅允许使用平台或团队块或种植盆。)" ) ;
95- return ;
96- }
97- int wallCount = 0 ;
98- while ( CheckTileAvailability ( startX , startX + i , j , plr ) )
99- {
100- Main . tile [ startX + i , j ] . wall = ( ushort ) selectedItem . createWall ;
101- TSPlayer . All . SendTileRect ( ( short ) ( startX + i ) , ( short ) j , 1 , 1 ) ;
102- plr . SelectedItem . stack -- ;
103- i += direction ;
104- wallCount ++ ;
105- }
106- plr . SendSuccessMessage ( $ "{ wallCount } 格桥梁建造完成!") ;
112+ plr . SendErrorMessage ( "没有足够的空间或物品来建造桥梁。" ) ;
107113 }
108114
109115 NetMessage . SendData ( ( int ) PacketTypes . PlayerSlot , - 1 , - 1 , NetworkText . FromLiteral ( plr . SelectedItem . Name ) , plr . Index , plr . TPlayer . selectedItem ) ;
110116 NetMessage . SendData ( ( int ) PacketTypes . PlayerSlot , plr . Index , - 1 , NetworkText . FromLiteral ( plr . SelectedItem . Name ) , plr . Index , plr . TPlayer . selectedItem ) ;
111117 } ) ;
112118 }
113119
114-
115- private static bool CheckTileAvailability ( int startX , int x , int y , TSPlayer plr )
120+ private static bool CheckTileAvailability ( int x , int y , TSPlayer plr , int directionX = 0 , int directionY = 0 )
116121 {
117- bool canPlace = x < Main . maxTilesX && x >= 0 &&
118- Math . Abs ( startX - x ) < Config . MaxPlaceLength &&
122+ bool canPlace = x < Main . maxTilesX && x >= 0 && y < Main . maxTilesY && y >= 0 &&
123+ Math . Abs ( directionX != 0 ? plr . TileX - x : plr . TileY - y ) < Config . MaxPlaceLength &&
119124 plr . SelectedItem . stack > 0 &&
120- ! TShock . Regions . InArea ( x , y ) &&
121- ! Main . tile [ x , y ] . active ( ) ;
125+ ! TShock . Regions . InArea ( x , y ) ;
122126
123- if ( plr . SelectedItem . createTile < 0 && plr . SelectedItem . createWall >= 0 )
127+ if ( plr . SelectedItem . createTile < 0 && plr . SelectedItem . createWall >= 0 ) // 检查墙壁
124128 {
125129 canPlace &= Main . tile [ x , y ] . wall == 0 ;
126130 }
131+ else if ( plr . SelectedItem . createTile >= 0 ) // 检查物块
132+ {
133+ canPlace &= ! Main . tile [ x , y ] . active ( ) ;
134+ }
127135
128136 return canPlace ;
129137 }
138+
130139 }
131140}
132141
0 commit comments