|
1 | 1 | package castle; |
2 | 2 |
|
| 3 | +import arc.math.geom.Point2; |
| 4 | +import arc.struct.Seq; |
3 | 5 | import arc.math.Mathf; |
4 | 6 | import arc.util.*; |
5 | 7 | import castle.CastleCosts.*; |
6 | 8 | import mindustry.Vars; |
7 | 9 | import mindustry.content.*; |
| 10 | +import mindustry.world.*; |
8 | 11 | import mindustry.game.Team; |
9 | 12 | import mindustry.gen.*; |
10 | 13 | import mindustry.type.*; |
11 | 14 | import mindustry.world.*; |
| 15 | +import mindustry.gen.Player; |
| 16 | +import mindustry.type.UnitType; |
12 | 17 | import mindustry.world.blocks.ConstructBlock; |
13 | 18 | import mindustry.world.blocks.storage.CoreBlock; |
14 | | -import useful.Bundle; |
| 19 | +import useful.Bundle; |
| 20 | +import mindustry.Vars; |
15 | 21 |
|
16 | 22 | import static castle.CastleUtils.boatSpawnX; |
17 | 23 | import static castle.CastleUtils.boatSpawnY; |
| 24 | +import static castle.CastleUtils.landSpawnX; |
| 25 | +import static castle.CastleUtils.landSpawnY; |
| 26 | +import static castle.CastleUtils.airSpawnX; |
| 27 | +import static castle.CastleUtils.airSpawnY; |
18 | 28 | import static castle.CastleUtils.generatePlatforms; |
19 | 29 | import static castle.CastleUtils.platformSource; |
| 30 | +import static castle.CastleUtils.defenseCap; |
| 31 | +import static castle.CastleUtils.attackCap; |
20 | 32 | import static castle.Main.*; |
21 | 33 |
|
22 | 34 | public class CastleRooms { |
@@ -180,44 +192,80 @@ public UnitRoom(UnitType type, UnitData data, boolean attack) { |
180 | 192 | this.income = attack ? data.income() : -data.income(); |
181 | 193 | } |
182 | 194 |
|
| 195 | + private boolean validFor(UnitType type, int x,int y) { |
| 196 | + |
| 197 | + var tile = Vars.world.tile(x, y); |
| 198 | + if (tile == null || |
| 199 | + (!type.flying && !tile.block().isAir()) || |
| 200 | + (type.naval && !tile.floor().isLiquid) ) |
| 201 | + return false; |
| 202 | + return true; |
| 203 | + } |
| 204 | + |
| 205 | + private void spawnUnit(PlayerData data, float x, float y, UnitType type, boolean core_spawn) { |
| 206 | + Unit unit = null; |
| 207 | + var i = 0; |
| 208 | + var y_coordinate = 0.0; |
| 209 | + if (core_spawn == true){ |
| 210 | + y_coordinate = Math.round((data.team().team == Team.blue ? Vars.world.height() - y : y) * 8 + Mathf.range(48f)); |
| 211 | + } |
| 212 | + else{ |
| 213 | + y_coordinate = y + Mathf.range(48f); |
| 214 | + } |
| 215 | + while(i < 10 && !validFor(type,Math.round((int)x),Math.round((int)y_coordinate/8))){ |
| 216 | + if (core_spawn == true){ |
| 217 | + y_coordinate = Math.round((data.team().team == Team.blue ? Vars.world.height() - y : y) * 8 + Mathf.range(48f)); |
| 218 | + } |
| 219 | + else{ |
| 220 | + y_coordinate = y + Mathf.range(48f); |
| 221 | + } |
| 222 | + i++; |
| 223 | + } |
| 224 | + unit = type.spawn( |
| 225 | + data.player.team(), |
| 226 | + x * 8 + 48f,Math.round(y_coordinate)); |
| 227 | + Bundle.label(1f, unit.getX(), unit.getY(), "rooms.unit.bought", data.player.coloredName()); |
| 228 | + } |
| 229 | + |
| 230 | + |
183 | 231 | @Override |
184 | 232 | public void buy(PlayerData data) { |
185 | 233 | super.buy(data); |
186 | 234 | data.income += income; |
187 | 235 |
|
188 | 236 | if (attack) spawns.spawn(data.player, data.player.team(), type); |
189 | 237 | else if ((boatSpawnX > 0 && boatSpawnY > 0) && type.naval) { |
190 | | - var prevLimit = Vars.state.rules.unitCap; |
191 | | - Vars.state.rules.unitCap = Integer.MAX_VALUE; |
192 | | - var unit = type.spawn( |
193 | | - data.player.team(), |
194 | | - boatSpawnX * 8f, |
195 | | - (data.team().team == Team.blue ? Vars.world.height() - boatSpawnY : boatSpawnY) * 8f + Mathf.range(48f)); |
196 | | - Bundle.label(1f, unit.getX(), unit.getY(), "rooms.unit.bought", data.player.coloredName()); |
197 | | - Vars.state.rules.unitCap = prevLimit; |
| 238 | + spawnUnit(data, boatSpawnX, boatSpawnY, type, true); |
| 239 | + } |
| 240 | + else if ((landSpawnX > 0 && landSpawnY > 0) && !type.naval && !type.flying) { |
| 241 | + spawnUnit(data, landSpawnX, landSpawnY, type, true); |
| 242 | + } |
| 243 | + else if ((airSpawnX > 0 && airSpawnY > 0) && type.flying) { |
| 244 | + spawnUnit(data, airSpawnX, airSpawnY, type, true); |
198 | 245 | } |
199 | 246 | else if (data.player.core() != null) { |
200 | 247 | var core = data.player.core(); |
201 | | - var prevLimit = Vars.state.rules.unitCap; |
202 | | - Vars.state.rules.unitCap = Integer.MAX_VALUE; |
203 | | - var unit = type.spawn(data.player.team(), core.x + 48f, core.y + Mathf.range(48f)); |
204 | | - Bundle.label(1f, unit.getX(), unit.getY(), "rooms.unit.bought", data.player.coloredName()); |
205 | | - Vars.state.rules.unitCap = prevLimit; |
206 | | - } |
| 248 | + spawnUnit(data, core.x/8, core.y, type, false); |
| 249 | + }; |
207 | 250 | } |
208 | 251 |
|
209 | 252 | @Override |
210 | 253 | public boolean canBuy(PlayerData data) { |
211 | 254 | if (!super.canBuy(data)) return false; |
212 | | - |
213 | | - if (data.team().getUnitCount() >= Vars.state.rules.unitCap) { |
214 | | - Bundle.announce(data.player, "rooms.unit.limit"); |
215 | | - return false; |
| 255 | + if (attack){ |
| 256 | + if(data.team().getUnitCountAttack()>=attackCap) { |
| 257 | + Bundle.announce(data.player, "rooms.unit.limit"); |
| 258 | + return false; |
| 259 | + } |
| 260 | + } |
| 261 | + else{ |
| 262 | + if(data.team().getUnitCountDefense()>=defenseCap){ |
| 263 | + Bundle.announce(data.player, "rooms.unit.limit"); |
| 264 | + return false; |
| 265 | + } |
216 | 266 | } |
217 | | - |
218 | 267 | return true; |
219 | 268 | } |
220 | | - |
221 | 269 | @Override |
222 | 270 | public String toString() { |
223 | 271 | return type.emoji() + " " + (attack ? "[accent]\uE865" : "[scarlet]\uE84D") + |
|
0 commit comments