The Fortress Datapack (Patreon)
Downloads
Content
Welcome back! To another installment of "Owen tries his best to explain his own code but he's forgotten how most of it works cause he never comments his own code"
Today: Fortresses, some of the cast loved em, some of the cast weren't good at em. Either way, they were surprisingly easy to code, but a real task to fine tune!
Where it all started:
In the lead up to Pirates SMP, I ran a stream with Smajor, SoupForEloise, and Bekyamon on "Sea Of Thieves". Was this a sneaky ploy to get the community interested in Pirate content? You bet your Cruppy butt it was! During that stream, we ran a raid on something called a "Fortress". Ghosts would spawn from the floor every minute or so, we'd fight them off, while running around and looting the fortress getting gold and gems and cash galore. Eventually there'd be a final big boss that we'd kill and that would be that!
..... Sound familiar?... It doesn't take a detective to see I was "inspired" by (read: Completely ripped 1-1) the formula of the mini-event. If pirates was going to have all the great parts of pirate games, it was going to have fortresses.
The Builds:
Knowing we wanted to do something like this, we asked noName to start developing us various "fortress" builds, and who ended up being given that task than none other than our wonderful castle builder SMP cast member Roscumber!
At this point in the projects development, Ros wasn't actually a member of the cast yet. It was from her work with noName that we discovered her. But that's a story for another day (hint hint go listen to our PowCast episode 2!).
The Setup:
Once we had our builds, we went around and used a special function to create a bunch of invisible armour stands at notable parts of the build. In the tunnels, on the bridges, in the attics. These would later be used as not only the location for mobs to spawn, but for LOOT too!
The Code:
Alright then lets get started with how the entire system works. It all starts with spawning an armour stand in the centre of the fortress with the tag "FortressCentre" (Good name huh?) Every tick (20 times a second) this fortress tag looks around in a 50 block radius, and if there is a player within that range (Who has not played that fortress that day), the fortress starts to get angry >:(
That's what you're seeing when the players start getting sPoOkY NoIsEs around them, the fortress is giving them time to leave with they wish to. If they stay for long enough, a raid begins!
The Raid:
As soon as the raid starts, all players within that 50 block zone get a special tag that corresponds to the fortress they're raiding, this means the code knows later on if they return to the same fortress, and doesn't let them start a new raid.
Either way, the raid has begun, and they better get a move on!
Every 13 seconds a new "Wave" spawned. The FortressCentre armour stand would pick a random spawner tagged armour stand from the ones nearby, and spawn a mob and chest there. Depending on the round number, the chest would be called something different, such as "Round 2 Chest" or "Round 4 Chest". This is important for later.
The mob that spawned depended on the round the players were on, with harder mobs having stronger gear and effects. We asked our beta testers to create 16 different types of armoured mobs per round, with different combos of swords, armour, bows, etc. They really delivered and saved us a lot of time!
We wanted to avoid the scenario where players are having to kill a bunch of mobs again and again, so we actually made that part optional. If they want to ignore all the mobs and just grab loot, they absolutely can! But if they ignore the ever growing number of mobs, they may get overwhelmed!
The FortressCentre armour stand kept track of everything in the game, the wave number (12 per round), the round number (5 per raid) how long before the next wave, and super importantly: How many players are around it. Going into this project, we knew it was gonna be tricky to balance the mobs. Too hard and it's frustrating, too easy and it's a cake walk. So the amount of mobs that spawn at the start of every wave increases the more players there are around. Not to short change the players either, we also increase the number of chests that spawn too!
Dying in a raid wasn't a huge deal, as long as you had another player nearby. This is because the fortress is constantly making sure at least someone is within that 50 block zone. If everyone leaves that zone (or if they all die) then the raid is immediately ended, all the mobs are killed, and all the chests are despawned. That last bit is super important, because we wanted players to remain inside the fortress at all times, attempting to get a breather away from the carnage is not part of the game loop after all!
The Loot:
Not everything had to be done with datapacks thankfully, MrMadSpy had already coded a "loot plugin" for players finding chests out in the world, and it didn't take much to tweak it to work for fortresses too! When a player opened a chest called "Round # Chest", the plugin would fetch a random number of items from a tower of chests in our control room depending on what round number the chest was from. After a chest had been opened, it wouldn't spawn more loot on further openings.
We even managed to add a little flare of flames to the bottom of unopened chests for the cast to know what had been opened and not!
if you wanted to do this entirely with datapacks however, there are loot table commands you can use, but they're a bit complicated, we'll save that for another post someday!
The Boss:
No raid is complete without a big bad boss at the end. Thankfully, the "Rotten Creatures" mod we used had a perfect trident wielding self-healing lightning casting drowned zombie mob to use! We just had to create a bossbar for his health, and let him loose.
For an added bonus, I also added some functionality that while he was alive, if he called down lightning (Which he does whenever he hits the player), he would actually spawn another mob called a "zap", a weaker variant of him. Sometimes he was very tricky to beat (As he would heal randomly if he got struck by lightning) but other times he was a cake walk. We'd loved to have made a grander more nuanced fight, but we think he served the purpose well.
The Ending + Easter Egg:
And finally, once you bested the boss, there was a 20% chance for him to drop a special "relic" item that we used at a later date in the SMP.
(Also, there was actually a secret "Ice Edition" fortress far far in the north, but due to time constraints, no one managed to get a boat good enough fast enough to explore the snowy biomes to find it. It was a harder variant of the standard fortress, spawning icey version of the mobs and giving more loot!
Closing Thoughts:
Overall, the fortresses were great fun to make, great fun to test, and added as a nice influx of cash for the players. We were really happy with how receptive they were to the minigame!
I know it sounds like a lot, but the code is surprisingly simple for what it does. A few timers and counters to keep track of the wave number, round number, and time left till next wave, a few lines of code to check that players are within range, a few functions to spawn some chests and zombies when the wave number increases, and a final boss with a healthbar that runs a win function if you kill him!
If you want to take a poke through the code yourself, it's attached in all it's messy form below. Warning: as always, it ain't commented, and it won't work "out the box", as there's a few dependencies on things like MrMadSpy's plugin. But if you want to use it as inspo or just straight up steal bits of code for yourself, go right ahead!