Skip to content

Commit

Permalink
feat: bugfixes & balance
Browse files Browse the repository at this point in the history
  • Loading branch information
Restioson committed Jun 21, 2024
1 parent 177d8a0 commit 4632b4d
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 174 deletions.
70 changes: 32 additions & 38 deletions src/main/java/io/github/restioson/siege/game/SiegeKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.github.restioson.siege.game.active.SiegePlayer;
import io.github.restioson.siege.item.SiegeHorn;
import net.minecraft.enchantment.EnchantmentLevelEntry;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
Expand Down Expand Up @@ -39,7 +38,14 @@ public final class SiegeKit {
new KitEquipment(Items.IRON_SWORD, EquipmentSlot.MAINHAND),
new KitEquipment(Items.STONE_AXE, EquipmentSlot.OFFHAND)
),
List.of(),
List.of(
new KitResource(
Items.GOLDEN_APPLE.getName(),
Items.GOLDEN_APPLE,
SiegePersonalResource.GAPPLE,
2
)
),
List.of()
);
public static final SiegeKit SHIELD_BEARER = new SiegeKit(
Expand All @@ -50,7 +56,8 @@ public final class SiegeKit {
new KitEquipment(Items.IRON_CHESTPLATE),
new KitEquipment(Items.IRON_LEGGINGS),
new KitEquipment(Items.LEATHER_BOOTS),
new KitEquipment(Items.STONE_SWORD, EquipmentSlot.MAINHAND),
new KitEquipment(Items.IRON_SWORD, EquipmentSlot.MAINHAND),
new KitEquipment(Items.WOODEN_AXE, EquipmentSlot.MAINHAND),
new KitEquipable() {
@Override
public EquipmentSlot getArmorStandSlot() {
Expand Down Expand Up @@ -80,57 +87,40 @@ public ItemStack buildItemStack(GameTeam team) {
new KitEquipment(Items.LEATHER_CHESTPLATE),
new KitEquipment(Items.LEATHER_LEGGINGS),
new KitEquipment(Items.LEATHER_BOOTS),
new KitEquipment(Items.WOODEN_SWORD, EquipmentSlot.OFFHAND),
new KitEquipment(
Items.BOW,
Items.BOW,
List.of(
new EnchantmentLevelEntry(Enchantments.POWER, 1)
),
EquipmentSlot.MAINHAND,
null
)
new KitEquipment(Items.STONE_SWORD, EquipmentSlot.OFFHAND),
new KitEquipment(Items.BOW, EquipmentSlot.MAINHAND),
new KitEquipment(Items.CROSSBOW)
),
List.of(new KitResource(
Text.translatable("game.siege.kit.items.arrows"),
Items.ARROW,
SiegePersonalResource.ARROWS,
24
32
)),
List.of(kitEffect(StatusEffects.SPEED))
);
public static final SiegeKit CONSTRUCTOR = new SiegeKit(
"constructor",
Items.OAK_PLANKS,
public static final SiegeKit ENGINEER = new SiegeKit(
"engineer",
Items.IRON_SHOVEL,
List.of(
new KitEquipment(Items.LEATHER_HELMET),
new KitEquipment(Items.IRON_CHESTPLATE),
new KitEquipment(Items.LEATHER_LEGGINGS),
new KitEquipment(Items.LEATHER_BOOTS),
new KitEquipment(Items.STONE_SWORD, EquipmentSlot.MAINHAND),
new KitEquipment(Items.STONE_SWORD),
new KitEquipment(Items.WOODEN_AXE)
),
List.of(KitResource.PLANKS),
List.of()
);
public static final SiegeKit DEMOLITIONER = new SiegeKit(
"demolitioner",
Items.TNT,
List.of(
new KitEquipment(Items.LEATHER_HELMET),
new KitEquipment(Items.LEATHER_CHESTPLATE),
new KitEquipment(Items.LEATHER_LEGGINGS),
new KitEquipment(Items.LEATHER_BOOTS),
new KitEquipment(Items.WOODEN_SWORD, EquipmentSlot.MAINHAND)
KitResource.PLANKS,
new KitResource(
Text.translatable("game.siege.kit.items.tnt"),
Items.TNT,
SiegePersonalResource.TNT,
EquipmentSlot.MAINHAND,
2
)
),
List.of(new KitResource(
Text.translatable("game.siege.kit.items.tnt"),
Items.TNT,
SiegePersonalResource.TNT,
EquipmentSlot.OFFHAND,
2
)),
List.of(kitEffect(StatusEffects.GLOWING))
List.of()
);
public static final SiegeKit CAPTAIN = new SiegeKit(
"captain",
Expand Down Expand Up @@ -230,6 +220,10 @@ private static Text restockMessage(List<RestockResult> restockResults, long time
return text;
}

public static ItemStack kitSelectItemStack() {
return KitEquipment.KIT_SELECT.buildItemStack(null);
}

public void equipArmourStand(SiegeKitStandEntity stand) {
var team = stand.getTeam();

Expand Down Expand Up @@ -406,7 +400,7 @@ private record KitEquipment(Item attackerItem, Item defenderItem, List<Enchantme
@SuppressWarnings("Convert2Lambda") // That would be hard to understand
public final static KitEquipable KIT_SELECT = new KitEquipable() {
@Override
public ItemStack buildItemStack(GameTeam team) {
public ItemStack buildItemStack(@Nullable GameTeam team) {
return ItemStackBuilder.of(KIT_SELECT_ITEM)
.setCount(1)
.setName(Text.literal("Kit Select").setStyle(NON_ITALIC_STYLE))
Expand Down
49 changes: 47 additions & 2 deletions src/main/java/io/github/restioson/siege/game/SiegeWaiting.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import eu.pb4.sgui.api.gui.SimpleGui;
import io.github.restioson.siege.game.active.SiegeActive;
import io.github.restioson.siege.game.active.WarpSelectionUi;
import io.github.restioson.siege.game.map.SiegeMap;
import io.github.restioson.siege.game.map.SiegeMapLoader;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.GameMode;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;
import xyz.nucleoid.plasmid.game.GameOpenContext;
Expand All @@ -22,14 +32,19 @@
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.util.PlayerRef;
import xyz.nucleoid.stimuli.event.item.ItemUseEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

import java.util.Map;

public class SiegeWaiting {
private final ServerWorld world;
private final GameSpace gameSpace;
private final SiegeMap map;
private final SiegeConfig config;

private final Map<PlayerRef, SiegeKit> kitSelections;
private final TeamSelectionLobby teamSelection;

private SiegeWaiting(ServerWorld world, GameSpace gameSpace, SiegeMap map, SiegeConfig config, TeamSelectionLobby teamSelection) {
Expand All @@ -38,6 +53,7 @@ private SiegeWaiting(ServerWorld world, GameSpace gameSpace, SiegeMap map, Siege
this.map = map;
this.config = config;
this.teamSelection = teamSelection;
this.kitSelections = new Object2ObjectOpenHashMap<>();
}

public static GameOpenProcedure open(GameOpenContext<SiegeConfig> context) {
Expand All @@ -58,20 +74,49 @@ public static GameOpenProcedure open(GameOpenContext<SiegeConfig> context) {
activity.listen(GameActivityEvents.REQUEST_START, waiting::requestStart);
activity.listen(GamePlayerEvents.OFFER, waiting::offerPlayer);
activity.listen(PlayerDeathEvent.EVENT, waiting::onPlayerDeath);
activity.listen(ItemUseEvent.EVENT, waiting::onUseItem);
activity.listen(GamePlayerEvents.ADD, waiting::onAddPlayer);
});
}

private void onAddPlayer(ServerPlayerEntity player) {
player.getInventory().offerOrDrop(SiegeKit.kitSelectItemStack());
}

private TypedActionResult<ItemStack> onUseItem(ServerPlayerEntity player, Hand hand) {
var stack = player.getStackInHand(hand);

if (stack.getItem() == SiegeKit.KIT_SELECT_ITEM) {
var ref = PlayerRef.of(player);
SimpleGui ui = WarpSelectionUi.createKitSelect(player, this.kitSelections.get(ref), selectedKit -> {
this.kitSelections.put(ref, selectedKit);
var msg = Text.translatable("game.siege.kit.selected")
.append(" ")
.append(selectedKit.getName())
.formatted(Formatting.GREEN);
player.sendMessage((msg), true);
player.playSound(SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, SoundCategory.NEUTRAL, 1.0F, 1.0F);
});

ui.open();
}

return TypedActionResult.fail(stack);
}

private GameResult requestStart() {
Multimap<GameTeamKey, ServerPlayerEntity> players = HashMultimap.create();
this.teamSelection.allocate(this.gameSpace.getPlayers(), players::put);

SiegeActive.open(this.world, this.gameSpace, this.map, this.config, players);
SiegeActive.open(this.world, this.gameSpace, this.map, this.config, players, this.kitSelections);

return GameResult.ok();
}

private PlayerOfferResult offerPlayer(PlayerOffer offer) {
return SiegeSpawnLogic.acceptPlayer(offer, this.world, this.map.waitingSpawn, GameMode.ADVENTURE);
var res = SiegeSpawnLogic.acceptPlayer(offer, this.world, this.map.waitingSpawn, GameMode.ADVENTURE);
offer.player().getInventory().offerOrDrop(SiegeKit.kitSelectItemStack());
return res;
}

private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
Expand Down
Loading

0 comments on commit 4632b4d

Please sign in to comment.