aboutsummaryrefslogtreecommitdiff
path: root/basetypes
diff options
context:
space:
mode:
Diffstat (limited to 'basetypes')
-rw-r--r--basetypes/build.gradle.kts12
-rw-r--r--basetypes/src/main/kotlin/moe/nea/ledger/ItemChange.kt43
-rw-r--r--basetypes/src/main/kotlin/moe/nea/ledger/ItemId.kt35
-rw-r--r--basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt42
-rw-r--r--basetypes/src/main/kotlin/moe/nea/ledger/utils/RemoveInRelease.kt4
-rw-r--r--basetypes/src/main/kotlin/moe/nea/ledger/utils/ULIDWrapper.kt35
-rw-r--r--basetypes/src/main/kotlin/moe/nea/ledger/utils/UUIDUtil.kt41
7 files changed, 212 insertions, 0 deletions
diff --git a/basetypes/build.gradle.kts b/basetypes/build.gradle.kts
new file mode 100644
index 0000000..f4b1a8b
--- /dev/null
+++ b/basetypes/build.gradle.kts
@@ -0,0 +1,12 @@
+plugins {
+ `java-library`
+ kotlin("jvm")
+}
+
+java {
+ toolchain.languageVersion.set(JavaLanguageVersion.of(8))
+}
+
+dependencies {
+ implementation("io.azam.ulidj:ulidj:1.0.4")
+}
diff --git a/basetypes/src/main/kotlin/moe/nea/ledger/ItemChange.kt b/basetypes/src/main/kotlin/moe/nea/ledger/ItemChange.kt
new file mode 100644
index 0000000..6cadf27
--- /dev/null
+++ b/basetypes/src/main/kotlin/moe/nea/ledger/ItemChange.kt
@@ -0,0 +1,43 @@
+package moe.nea.ledger
+
+data class ItemChange(
+ val itemId: ItemId,
+ val count: Double,
+ val direction: ChangeDirection,
+) {
+
+ enum class ChangeDirection {
+ GAINED,
+ TRANSFORM,
+ SYNC,
+ CATALYST,
+ LOST;
+
+ }
+
+ companion object {
+ fun gainCoins(number: Double): ItemChange {
+ return gain(ItemId.COINS, number)
+ }
+
+ fun unpair(direction: ChangeDirection, pair: Pair<ItemId, Double>): ItemChange {
+ return ItemChange(pair.first, pair.second, direction)
+ }
+
+ fun unpairGain(pair: Pair<ItemId, Double>) = unpair(ChangeDirection.GAINED, pair)
+ fun unpairLose(pair: Pair<ItemId, Double>) = unpair(ChangeDirection.LOST, pair)
+
+ fun gain(itemId: ItemId, amount: Number): ItemChange {
+ return ItemChange(itemId, amount.toDouble(), ChangeDirection.GAINED)
+ }
+
+ fun lose(itemId: ItemId, amount: Number): ItemChange {
+ return ItemChange(itemId, amount.toDouble(), ChangeDirection.LOST)
+ }
+
+ fun loseCoins(number: Double): ItemChange {
+ return lose(ItemId.COINS, number)
+ }
+
+ }
+} \ No newline at end of file
diff --git a/basetypes/src/main/kotlin/moe/nea/ledger/ItemId.kt b/basetypes/src/main/kotlin/moe/nea/ledger/ItemId.kt
new file mode 100644
index 0000000..8dcfa27
--- /dev/null
+++ b/basetypes/src/main/kotlin/moe/nea/ledger/ItemId.kt
@@ -0,0 +1,35 @@
+package moe.nea.ledger
+
+import moe.nea.ledger.utils.RemoveInRelease
+
+data class ItemId(
+ val string: String
+) {
+ @RemoveInRelease
+ fun singleItem(): Pair<ItemId, Double> {
+ return withStackSize(1)
+ }
+
+ @RemoveInRelease
+ fun withStackSize(size: Number): Pair<ItemId, Double> {
+ return Pair(this, size.toDouble())
+ }
+
+
+ companion object {
+
+ @JvmStatic
+ @RemoveInRelease
+ fun forName(string: String) = ItemId(string)
+ fun skill(skill: String) = ItemId("SKYBLOCK_SKILL_$skill")
+
+ val GARDEN = skill("GARDEN")
+ val FARMING = skill("FARMING")
+
+
+ val COINS = ItemId("SKYBLOCK_COIN")
+ val GEMSTONE_POWDER = ItemId("SKYBLOCK_POWDER_GEMSTONE")
+ val MITHRIL_POWDER = ItemId("SKYBLOCK_POWDER_MITHRIL")
+ val NIL = ItemId("SKYBLOCK_NIL")
+ }
+} \ No newline at end of file
diff --git a/basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt b/basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt
new file mode 100644
index 0000000..d4c15e5
--- /dev/null
+++ b/basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt
@@ -0,0 +1,42 @@
+package moe.nea.ledger
+
+enum class TransactionType {
+ ACCESSORIES_SWAPPING,
+ ALLOWANCE_GAIN,
+ AUCTION_BOUGHT,
+ AUCTION_LISTING_CHARGE,
+ AUCTION_SOLD,
+ AUTOMERCHANT_PROFIT_COLLECT,
+ BANK_DEPOSIT,
+ BANK_INTEREST,
+ BANK_WITHDRAW,
+ BASIC_REFORGE,
+ BAZAAR_BUY_INSTANT,
+ BAZAAR_BUY_ORDER,
+ BAZAAR_SELL_INSTANT,
+ BAZAAR_SELL_ORDER,
+ BITS_PURSE_STATUS,
+ BOOSTER_COOKIE_ATE,
+ CADUCOUS_FEEDER_USED,
+ CAPSAICIN_EYEDROPS_USED,
+ COMMUNITY_SHOP_BUY,
+ CORPSE_DESECRATED,
+ DIE_ROLLED,
+ DRACONIC_SACRIFICE,
+ DUNGEON_CHEST_OPEN,
+ FORGED,
+ GHOST_COIN_DROP,
+ GOD_POTION_DRANK,
+ GOD_POTION_MIXIN_DRANK,
+ GUMMY_POLAR_BEAR_ATE,
+ KAT_TIMESKIP,
+ KAT_UPGRADE,
+ KISMET_REROLL,
+ KUUDRA_CHEST_OPEN,
+ NPC_BUY,
+ NPC_SELL,
+ PEST_REPELLENT_USED,
+ STONKS_AUCTION,
+ VISITOR_BARGAIN,
+ WYRM_EVOKED,
+} \ No newline at end of file
diff --git a/basetypes/src/main/kotlin/moe/nea/ledger/utils/RemoveInRelease.kt b/basetypes/src/main/kotlin/moe/nea/ledger/utils/RemoveInRelease.kt
new file mode 100644
index 0000000..319fb63
--- /dev/null
+++ b/basetypes/src/main/kotlin/moe/nea/ledger/utils/RemoveInRelease.kt
@@ -0,0 +1,4 @@
+package moe.nea.ledger.utils
+
+@Retention(AnnotationRetention.BINARY)
+annotation class RemoveInRelease
diff --git a/basetypes/src/main/kotlin/moe/nea/ledger/utils/ULIDWrapper.kt b/basetypes/src/main/kotlin/moe/nea/ledger/utils/ULIDWrapper.kt
new file mode 100644
index 0000000..29d5e31
--- /dev/null
+++ b/basetypes/src/main/kotlin/moe/nea/ledger/utils/ULIDWrapper.kt
@@ -0,0 +1,35 @@
+package moe.nea.ledger.utils
+
+import io.azam.ulidj.ULID
+import java.time.Instant
+import kotlin.random.Random
+
+@JvmInline
+value class ULIDWrapper(
+ val wrapped: String
+) {
+ companion object {
+ fun lowerBound(timestamp: Instant): ULIDWrapper {
+ return ULIDWrapper(ULID.generate(timestamp.toEpochMilli(), ByteArray(10)))
+ }
+
+ fun upperBound(timestamp: Instant): ULIDWrapper {
+ return ULIDWrapper(ULID.generate(timestamp.toEpochMilli(), ByteArray(10) { -1 }))
+ }
+
+ fun createULIDAt(timestamp: Instant): ULIDWrapper {
+ return ULIDWrapper(ULID.generate(
+ timestamp.toEpochMilli(),
+ Random.nextBytes(10)
+ ))
+ }
+ }
+
+ fun getTimestamp(): Instant {
+ return Instant.ofEpochMilli(ULID.getTimestamp(wrapped))
+ }
+
+ init {
+ require(ULID.isValid(wrapped))
+ }
+} \ No newline at end of file
diff --git a/basetypes/src/main/kotlin/moe/nea/ledger/utils/UUIDUtil.kt b/basetypes/src/main/kotlin/moe/nea/ledger/utils/UUIDUtil.kt
new file mode 100644
index 0000000..92a29f7
--- /dev/null
+++ b/basetypes/src/main/kotlin/moe/nea/ledger/utils/UUIDUtil.kt
@@ -0,0 +1,41 @@
+package moe.nea.ledger.utils
+
+import java.util.UUID
+import kotlin.uuid.ExperimentalUuidApi
+import kotlin.uuid.Uuid
+import kotlin.uuid.toJavaUuid
+
+object UUIDUtil {
+ @OptIn(ExperimentalUuidApi::class)
+ fun parsePotentiallyDashlessUUID(str: String): UUID {
+ val bytes = ByteArray(16)
+ var i = -1
+ var bi = 0
+ while (++i < str.length) {
+ val char = str[i]
+ if (char == '-') {
+ if (bi != 4 && bi != 6 && bi != 8 && bi != 10) {
+ error("Unexpected dash in UUID: $str")
+ }
+ continue
+ }
+ val current = parseHexDigit(str, char)
+ ++i
+ if (i >= str.length)
+ error("Unexpectedly short UUID: $str")
+ val next = parseHexDigit(str, str[i])
+ bytes[bi++] = (current * 16 or next).toByte()
+ }
+ if (bi != 16)
+ error("Unexpectedly short UUID: $str")
+ return Uuid.fromByteArray(bytes).toJavaUuid()
+ }
+
+ private fun parseHexDigit(str: String, char: Char): Int {
+ val d = char - '0'
+ if (d < 10) return d
+ val h = char - 'a'
+ if (h < 6) return 10 + h
+ error("Unexpected hex digit $char in UUID: $str")
+ }
+} \ No newline at end of file