Started implementing Castle Wars (not ready to enable yet)

This commit is contained in:
Dan Ginovker
2023-04-10 07:13:54 +00:00
committed by Ryan
parent dd3c957f8b
commit 034cc75a61
32 changed files with 1166 additions and 75 deletions
@@ -372,6 +372,50 @@ public class Container {
return true;
}
/**
* Removes all items from the container that have the passed in IDs
*
* @param ids Array of IDs to remove
* @return {@code True} if all the items got removed, <br> {@code false} if some of the
* found items were null
*/
public boolean removeAll(int[] ids) {
boolean removedAll = true;
for (int id : ids) {
if (!removeAll(id)) {
removedAll = false;
}
}
update();
return removedAll;
}
/**
* Removes all items from the container that have the passed in ID
*
* @param id Item ID to remove all instances of
* @return {@code True} if all the items got removed, <br> {@code false} if some of the
* found items were null
*/
public boolean removeAll(int id) {
ArrayList<Item> matchingIdItems = new ArrayList<>();
for (Item item : this.items) {
// If the item is not null and the item ID matches the ID we're looking for
if (item != null && item.getId() == id) {
// Add the item to the list
matchingIdItems.add(item);
}
}
boolean res = true;
// Remove all the items from the container
for (Item item : matchingIdItems) {
if (!remove(item, false)) {
res = false;
}
}
return res;
}
/**
* Replaces the item on the given slot with the argued item.
*
@@ -463,6 +463,7 @@ public final class DialogueInterpreter {
*/
public Component sendDialogues(int npcId, int expression, String... messages) {
if (messages.length < 1 || messages.length > 4) {
System.err.println("Invalid amount of messages: " + messages.length);
return null;
}
boolean npc = npcId > -1;
@@ -341,6 +341,7 @@ public final class WalkingQueue {
* {@code false} if not.
*/
public boolean isRunningBoth() {
if (isRunDisabled()) return false;
if (entity instanceof Player && ((Player) entity).getSettings().isRunToggled()) {
return true;
}
+7 -4
View File
@@ -17,6 +17,7 @@ import org.rs09.consts.Components
import org.rs09.consts.Items
import core.ServerConstants
import core.game.shops.Shops.Companion.logShop
import core.game.system.config.ItemConfigParser
import core.game.world.GameWorld
import java.lang.Integer.max
import java.lang.Integer.min
@@ -159,8 +160,9 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
val item = cont[slot]
val price = when(currency)
{
Items.TOKKUL_6529 -> item.definition.getConfiguration("tokkul_price", 1)
Items.ARCHERY_TICKET_1464 -> item.definition.getConfiguration("archery_ticket_price", 1)
Items.TOKKUL_6529 -> item.definition.getConfiguration(ItemConfigParser.TOKKUL_PRICE, 1)
Items.ARCHERY_TICKET_1464 -> item.definition.getConfiguration(ItemConfigParser.ARCHERY_TICKET_PRICE, 1)
Items.CASTLE_WARS_TICKET_4067 -> item.definition.getConfiguration(ItemConfigParser.CASTLE_WARS_TICKET_PRICE, 1)
else -> getGPCost(Item(item.id, 1), if (isMainStock) stock[item.slot].amount else playerStock[slot].amount, if (isMainStock) item.amount else playerStock[slot].amount)
}
@@ -199,8 +201,9 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
val price = when(currency)
{
Items.TOKKUL_6529 -> (item.definition.getConfiguration("tokkul_price", 1) / 10.0).toInt() // selling items authentically return 10x less tokkul (floored/truncated) than the item's shop price
Items.ARCHERY_TICKET_1464 -> item.definition.getConfiguration("archery_ticket_price", 1)
Items.TOKKUL_6529 -> (item.definition.getConfiguration(ItemConfigParser.TOKKUL_PRICE, 1) / 10.0).toInt() // selling items authentically return 10x less tokkul (floored/truncated) than the item's shop price
Items.ARCHERY_TICKET_1464 -> item.definition.getConfiguration(ItemConfigParser.ARCHERY_TICKET_PRICE, 1)
Items.CASTLE_WARS_TICKET_4067 -> item.definition.getConfiguration(ItemConfigParser.CASTLE_WARS_TICKET_PRICE, 1)
else -> getGPSell(Item(shopItemId, 1), stockAmt, currentAmt)
}
+22 -17
View File
@@ -52,20 +52,25 @@ class Shops : StartupListener, TickListener, InteractionListener, InterfaceListe
return items
}
stock.split('-').map {
val tokens = it.replace("{", "").replace("}", "").split(",".toRegex()).toTypedArray()
var amount = tokens[1].trim()
if(amount == "inf")
amount = "-1"
val item = tokens[0].toInt()
if(idsInStock[item] != null) {
log(this::class.java, Log.WARN, "[SHOPS] MALFORMED STOCK IN SHOP ID $id FOR ITEM $item")
items.forEach { if(it.itemId == item) {
it.amount += amount.toInt()
return@map
}}
} else {
items.add(ShopItem(item, amount.toInt(), tokens.getOrNull(2)?.toIntOrNull() ?: 100))
idsInStock[item] = true
try {
val tokens = it.replace("{", "").replace("}", "").split(",".toRegex()).toTypedArray()
var amount = tokens[1].trim()
if(amount == "inf")
amount = "-1"
val item = tokens[0].toInt()
if(idsInStock[item] != null) {
log(this::class.java, Log.WARN, "[SHOPS] MALFORMED STOCK IN SHOP ID $id FOR ITEM $item")
items.forEach { if(it.itemId == item) {
it.amount += amount.toInt()
return@map
}}
} else {
items.add(ShopItem(item, amount.toInt(), tokens.getOrNull(2)?.toIntOrNull() ?: 100))
idsInStock[item] = true
}
} catch (e: Exception) {
log(this::class.java, Log.WARN, "[SHOPS] MALFORMED STOCK IN SHOP ID $id FOR ITEM $it")
throw e
}
}
return items
@@ -215,9 +220,9 @@ class Shops : StartupListener, TickListener, InteractionListener, InterfaceListe
val valueMsg = when {
(price.amount == -1)
|| !def.isTradeable
|| def.id in intArrayOf(Items.COINS_995, Items.TOKKUL_6529, Items.ARCHERY_TICKET_1464)
|| def.hasDestroyAction() -> "This shop will not buy that item."
|| !def.hasShopCurrencyValue(price.id)
|| def.id in intArrayOf(Items.COINS_995, Items.TOKKUL_6529, Items.ARCHERY_TICKET_1464, Items.CASTLE_WARS_TICKET_4067)
-> "This shop will not buy that item."
else -> "${player.inventory[slot].name}: This shop will buy this item for ${price.amount} ${price.name.lowercase()}."
}
@@ -7,8 +7,10 @@ import core.plugin.Initializable
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import core.ServerConstants
import core.api.log
import core.game.system.command.Privilege
import core.game.world.repository.Repository
import core.tools.Log
@Initializable
class TeleportCommandSet : CommandSet(Privilege.ADMIN){
@@ -217,6 +217,11 @@ class ItemConfigParser {
*/
const val ARCHERY_TICKET_PRICE = "archery_ticket_price"
/**
* The Castle Wars Ticket price of items (in Lanthas' shop).
*/
const val CASTLE_WARS_TICKET_PRICE = "castle_wars_ticket_price"
}
val parser = JSONParser()
@@ -270,8 +275,9 @@ class ItemConfigParser {
//ints
"equip_audio",
"point_price",
"tokkul_price",
"archery_ticket_price",
TOKKUL_PRICE,
ARCHERY_TICKET_PRICE,
CASTLE_WARS_TICKET_PRICE,
"ge_buy_limit",
"weapon_interface",
"attack_speed",
@@ -92,6 +92,7 @@ object ServerConfigParser {
jad_practice_enabled = data.getBoolean("world.jad_practice_enabled"),
ge_announcement_limit = data.getLong("world.ge_announcement_limit", 500L).toInt(),
smartpathfinder_bfs = data.getBoolean("world.smartpathfinder_bfs", false),
enable_castle_wars = data.getBoolean("world.enable_castle_wars", false),
message_model = data.getString("world.motw_identifier").toInt(),
message_string = data.getString("world.motw_text").replace("@name", ServerConstants.SERVER_NAME)
)
@@ -84,6 +84,7 @@ class GameSettings
var jad_practice_enabled: Boolean,
var ge_announcement_limit: Int,
var smartpathfinder_bfs: Boolean,
var enable_castle_wars: Boolean,
/**"Lobby" interface
* The message of the week models to display
@@ -140,6 +141,7 @@ class GameSettings
val jad_practice_enabled = if(data.containsKey("jad_practice_enabled")) data["jad_practice_enabled"] as Boolean else true
val ge_announcement_limit = data["ge_announcement_limit"].toString().toInt()
val smartpathfinder_bfs = if(data.containsKey("smartpathfinder_bfs")) data["smartpathfinder_bfs"] as Boolean else false
val enable_castle_wars = if(data.containsKey("enable_castle_wars")) data["enable_castle_wars"] as Boolean else false
val allow_token_purchase = data["allow_token_purchase"] as Boolean
val message_of_the_week_identifier = data["message_of_the_week_identifier"].toString().toInt()
val message_of_the_week_text = data["message_of_the_week_text"].toString()
@@ -171,6 +173,7 @@ class GameSettings
jad_practice_enabled,
ge_announcement_limit,
smartpathfinder_bfs,
enable_castle_wars,
message_of_the_week_identifier,
message_of_the_week_text
)
@@ -2,6 +2,7 @@ package core.game.world.map.zone;
import core.game.node.Node;
import core.game.world.map.Location;
import core.game.world.map.RegionManager;
import core.tools.RandomFunction;
import java.util.ArrayList;
@@ -97,6 +98,10 @@ public final class ZoneBorders {
this.zeroPlaneCheck = zeroPlaneCheck;
}
public ZoneBorders(Location l1, Location l2) {
this(l1.getX(), l1.getY(), l2.getX(), l2.getY(), l1.getZ());
}
/**
* Creates zone borders for the given region id.
* @param regionId The region id.
@@ -234,6 +239,16 @@ public final class ZoneBorders {
return new Location(x, y, plane);
}
public Location getRandomWalkableLoc() {
Location loc = getRandomLoc();
int tries = 0; // prevent bad code from DOSing server
while (!RegionManager.isTeleportPermitted(loc) && tries < 20) {
loc = getRandomLoc();
tries += 1;
}
return loc;
}
/**
* Adds an exception.
* @param exception The exception to add.