Repository reorganisation

Unified kotlin and java into just src/main
Unified the rs09 and core packages
Took all content out of the core package, and placed it into the new content package
Reorganised all source code relating to content to be easier to find and explore
This commit is contained in:
Ceikry
2023-01-26 13:59:28 +00:00
committed by Ryan
parent e4b799c44a
commit a100affda2
3156 changed files with 24205 additions and 30585 deletions
@@ -0,0 +1,16 @@
package core.game.consumable;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
public class BarbarianMix extends Potion {
public BarbarianMix(int[] ids, ConsumableEffect effect, String... messages) {
super(ids, effect, messages);
}
@Override
protected void sendDefaultMessages(Player player, Item item) {
player.getPacketDispatch().sendMessage("You drink the lumpy potion.");
}
}
@@ -0,0 +1,47 @@
package core.game.consumable;
import content.data.consumables.Consumables;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
/**
* Represents any cake item that is made of three even slices.
*/
public class Cake extends Food {
public Cake(int[] ids, ConsumableEffect effect, String... messages) {
super(ids, effect, messages);
}
@Override
public void consume(Item item, Player player) {
executeConsumptionActions(player);
final int nextItemId = getNextItemId(item.getId());
if (nextItemId != -1) {
player.getInventory().replace(new Item(nextItemId), item.getSlot());
} else {
player.getInventory().remove(item);
}
final int initialLifePoints = player.getSkills().getLifepoints();
Consumables.getConsumableById(item.getId()).effect.activate(player);
sendMessages(player, initialLifePoints, item, messages);
}
@Override
protected void sendMessages(Player player, int initialLifePoints, Item item, String[] messages) {
if (messages.length == 0) {
sendDefaultMessages(player, item);
} else {
sendCustomMessages(player, messages, item.getId());
}
sendHealingMessage(player, initialLifePoints);
}
private void sendCustomMessages(final Player player, final String[] messages, int itemId) {
int i = 0;
while (ids[i] != itemId) {
i++;
}
player.getPacketDispatch().sendMessage(messages[i]);
}
}
@@ -0,0 +1,125 @@
package core.game.consumable;
import content.data.consumables.Consumables;
import core.api.Container;
import static core.api.ContentAPIKt.*;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.game.world.update.flag.context.Animation;
import core.plugin.Plugin;
/**
* Represents any item that has a consumption option such as 'Eat' or 'Drink'.
*/
public abstract class Consumable implements Plugin<Object> {
/**
* Represents the item IDs of all the variants of a consumable where the last one is often the empty container, if it has any.
*/
protected final int[] ids;
/**
* Represents the effect to apply on the player once the item is consumed.
*/
protected final ConsumableEffect effect;
/**
* Represents the messages to send to the player when it consumes the item.
*/
protected final String[] messages;
/**
* Represents the animation that the player will execute when consuming the item.
*/
protected Animation animation = null;
public Consumable(final int[] ids, final ConsumableEffect effect, final String... messages) {
this.ids = ids;
this.effect = effect;
this.messages = messages;
}
public Consumable(final int[] ids, final ConsumableEffect effect, final Animation animation, final String... messages) {
this.ids = ids;
this.effect = effect;
this.animation = animation;
this.messages = messages;
}
public void consume(final Item item, final Player player) {
executeConsumptionActions(player);
final int nextItemId = getNextItemId(item.getId());
if(item.getAmount() > 1){
removeItem(player, item.getId(), Container.INVENTORY);
} else removeItem(player, item, Container.INVENTORY);
if (nextItemId != -1) {
addItem(player, nextItemId, 1, Container.INVENTORY);
}
final int initialLifePoints = player.getSkills().getLifepoints();
Consumables.getConsumableById(item.getId()).effect.activate(player);
sendMessages(player, initialLifePoints, item, messages);
}
protected void sendMessages(final Player player, final int initialLifePoints, final Item item, String[] messages) {
if (messages.length == 0) {
sendDefaultMessages(player, item);
sendHealingMessage(player, initialLifePoints);
} else {
sendCustomMessages(player, messages);
}
}
protected void sendHealingMessage(final Player player, final int initialLifePoints) {
if (player.getSkills().getLifepoints() > initialLifePoints) {
player.getPacketDispatch().sendMessage("It heals some health.");
}
}
protected void sendCustomMessages(final Player player, final String[] messages) {
for (String message : messages) {
player.getPacketDispatch().sendMessage(message);
}
}
protected abstract void sendDefaultMessages(final Player player, final Item item);
protected abstract void executeConsumptionActions(Player player);
protected int getNextItemId(final int currentConsumableId) {
for (int i = 0; i < ids.length; i++) {
if (ids[i] == currentConsumableId && i != ids.length - 1) {
return ids[i + 1];
}
}
return -1;
}
public String getFormattedName(Item item) {
return item.getName().replace("(4)", "").replace("(3)", "").replace("(2)", "").replace("(1)", "").trim().toLowerCase();
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
Consumables.add(this);
return this;
}
@Override
public Object fireEvent(String identifier, Object... args) {
return null;
}
public int getHealthEffectValue(Player player) {
return effect.getHealthEffectValue(player);
}
public ConsumableEffect getEffect() {
return effect;
}
public int[] getIds() {
return ids;
}
}
@@ -0,0 +1,12 @@
package core.game.consumable;
import core.game.node.entity.player.Player;
public abstract class ConsumableEffect {
public abstract void activate(Player p);
public int getHealthEffectValue(Player player) {
return 0;
}
}
@@ -0,0 +1,36 @@
package core.game.consumable;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.audio.Audio;
import core.game.node.item.Item;
import core.game.world.update.flag.context.Animation;
public class Drink extends Consumable {
public static final Audio SOUND = new Audio(4580, 1, 1);
public Drink(int[] ids, ConsumableEffect effect, String... messages) {
super(ids, effect, messages);
animation = new Animation(1327);
}
public Drink(int[] ids, ConsumableEffect effect, Animation animation, String... messages) {
super(ids, effect, animation, messages);
}
@Override
protected void sendDefaultMessages(Player player, Item item) {
player.getPacketDispatch().sendMessage("You drink the " + getFormattedName(item) + ".");
}
@Override
protected void executeConsumptionActions(Player player) {
player.animate(animation);
player.getAudioManager().send(SOUND);
}
@Override
public String getFormattedName(Item item) {
return item.getName().replace("(4)", "").replace("(3)", "").replace("(2)", "").replace("(1)", "").replace("(m4)", "").replace("(m3)", "").replace("(m2)", "").replace("(m1)", "").replace("(m)", "").trim().toLowerCase();
}
}
@@ -0,0 +1,31 @@
package core.game.consumable;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
/**
* Represents a special type of consumable that cannot be consumed unless it is transformed into another item.
* During its 'consumption', only a message is sent to the player.
*/
public class FakeConsumable extends Consumable {
public FakeConsumable(final int id, final String[] messages) {
super(new int[] {id}, null, messages);
}
@Override
public void consume(Item item, Player player) {
sendDefaultMessages(player, item);
}
@Override
protected void sendDefaultMessages(Player player, Item item) {
for (String message : messages) {
player.getPacketDispatch().sendMessage(message);
}
}
@Override
protected void executeConsumptionActions(Player player) {
}
}
@@ -0,0 +1,35 @@
package core.game.consumable;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.audio.Audio;
import core.game.node.item.Item;
import core.game.world.update.flag.context.Animation;
public class Food extends Consumable {
public static final Audio SOUND = new Audio(2393, 1, 1);
public Food(final int[] ids, final ConsumableEffect effect, final String... messages) {
super(ids, effect, messages);
animation = new Animation(829);
}
public Food(int[] ids, ConsumableEffect effect, Animation animation, String... messages) {
super(ids, effect, animation, messages);
}
@Override
protected void sendDefaultMessages(Player player, Item item) {
player.getPacketDispatch().sendMessage("You eat the " + getFormattedName(item) + ".");
}
@Override
protected void executeConsumptionActions(Player player) {
player.animate(animation);
playEatingSound(player);
}
private void playEatingSound(Player player) {
player.getAudioManager().send(SOUND);
}
}
@@ -0,0 +1,30 @@
package core.game.consumable;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
/**
* Represents any food that is consumed in two parts such as pies and pizzas.
*/
public class HalfableFood extends Food {
public HalfableFood(int[] ids, ConsumableEffect effect, String... messages) {
super(ids, effect, messages);
}
@Override
protected void sendDefaultMessages(Player player, Item item) {
if (item.getId() == ids[0]) {
player.getPacketDispatch().sendMessage("You eat half the "+ getFormattedName(item) + ".");
} else if (item.getId() == ids[1]) {
player.getPacketDispatch().sendMessage("You eat the remaining " + getFormattedName(item) + ".");
} else {
super.sendDefaultMessages(player, item);
}
}
@Override
public String getFormattedName(Item item) {
return item.getName().replace("1/2", "").replace("Half an", "").replace("Half a", "").trim().toLowerCase();
}
}
@@ -0,0 +1,78 @@
package core.game.consumable;
import content.data.consumables.Consumables;
import content.region.kandarin.barcrawl.BarcrawlManager;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.audio.Audio;
import core.game.node.item.Item;
public class Potion extends Drink {
private static final int VIAL = 229;
private static final Audio SOUND = new Audio(2401, 1, 1);
public Potion(final int[] ids, final ConsumableEffect effect, final String... messages) {
super(ids, effect, messages);
}
@Override
public void consume(Item item, Player player) {
executeConsumptionActions(player);
final int nextItemId = getNextItemId(item.getId());
if (nextItemId != -1) {
player.getInventory().replace(new Item(nextItemId), item.getSlot());
} else {
if (BarcrawlManager.getInstance(player).isFinished()) {
player.getInventory().remove(item);
} else {
player.getInventory().replace(new Item(VIAL), item.getSlot());
}
}
final int initialLifePoints = player.getSkills().getLifepoints();
Consumables.getConsumableById(item.getId()).effect.activate(player);
if (messages.length == 0) {
sendDefaultMessages(player, item);
} else {
sendCustomMessages(player, messages);
}
sendHealingMessage(player, initialLifePoints);
}
@Override
protected void executeConsumptionActions(Player player) {
player.animate(animation);
player.getAudioManager().send(SOUND);
}
@Override
protected void sendDefaultMessages(Player player, Item item) {
int consumedDoses = 1;
int i = 0;
while (ids[i] != item.getId()) {
consumedDoses++;
i++;
}
final int dosesLeft = ids.length - consumedDoses;
player.getPacketDispatch().sendMessage("You drink some of your " + getFormattedName(item) + ".");
if (dosesLeft > 1) {
player.getPacketDispatch().sendMessage("You have " + dosesLeft + " doses of your potion left.");
} else if (dosesLeft == 1) {
player.getPacketDispatch().sendMessage("You have 1 dose of your potion left.");
} else {
player.getPacketDispatch().sendMessage("You have finished your potion.");
}
}
public static int getDose(Item potion){
return Integer.parseInt(potion.getName().replaceAll("[^\\d.]",""));
}
public int[] getIds() {
return ids;
}
public ConsumableEffect getEffect() {
return effect;
}
}