diff --git a/src/main/kotlin/JAlchemyRecipeGenerator.kt b/src/main/kotlin/JAlchemyRecipeGenerator.kt index b0c7273..4c16bbe 100644 --- a/src/main/kotlin/JAlchemyRecipeGenerator.kt +++ b/src/main/kotlin/JAlchemyRecipeGenerator.kt @@ -1,5 +1,8 @@ package top.jie65535 +import Transmutation +import Silicon +import Silver import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin import net.mamoe.mirai.event.GlobalEventChannel @@ -38,6 +41,7 @@ object JAlchemyRecipeGenerator : KotlinPlugin( private fun gen(seed: Long): String { val random = Random(seed) val sb = StringBuilder() + val transmutation = Transmutation(seed) for (catalyst in catalysts) { sb.append(catalyst.name).append(" : ") for (i in 1..4) @@ -60,6 +64,9 @@ object JAlchemyRecipeGenerator : KotlinPlugin( // } // sb.appendLine(']') } + // 硅 + sb.append("硅反应物:混沌催化剂 + ${transmutation.transmuted(Silicon).name}反应物\n") + sb.append("银反应物:混沌催化剂 + ${transmutation.transmuted(Silver).name}反应物") return sb.toString() } @@ -72,4 +79,10 @@ object JAlchemyRecipeGenerator : KotlinPlugin( Catalyst("宝石催化剂", arrayOf("朱砂", "青金石", "蓝宝石", "绿宝石", "红宝石", "钻石")), Catalyst("混沌催化剂", arrayOf("火成催化剂", "草本催化剂", "不稳定催化剂", "晶化催化剂", "金属催化剂", "宝石催化剂")), ) -} \ No newline at end of file + + /** + * 反应物 + */ + val reagents = catalysts.filter { it.name != "混沌催化剂" } + .flatMap { it.materials.asIterable() } +} diff --git a/src/main/kotlin/Reagent.kt b/src/main/kotlin/Reagent.kt new file mode 100644 index 0000000..473c30b --- /dev/null +++ b/src/main/kotlin/Reagent.kt @@ -0,0 +1,54 @@ +import top.jie65535.JAlchemyRecipeGenerator.reagents + +/** + * 反应物种类量 + */ +const val REAGENT_COUNT = 38 + +/** + * 反应物 + */ +open class Reagent { + val index: Int + val name: String + + constructor(index: Int) { + this.index = index + this.name = if (index !in 0 until REAGENT_COUNT) + UndefineReagent.name + else when (index) { + Silicon.index -> Silicon.name + Silver.index -> Silver.name + else -> reagents[index] + } + } + + constructor(name: String) { + this.name = name + this.index = when (name) { + Silver.name -> Silver.index + Silicon.name -> Silicon.index + else -> reagents.indexOf(name) + } + } + + constructor(name: String, index: Int) { + this.name = name + this.index = index + } +} + +/** + * 未定义的反应物 + */ +object UndefineReagent : Reagent("", -1) + +/** + * 硅反应物 + */ +object Silicon : Reagent("硅", 36) + +/** + * 银反应物 + */ +object Silver : Reagent("银", 37) diff --git a/src/main/kotlin/Transmutation.kt b/src/main/kotlin/Transmutation.kt new file mode 100644 index 0000000..6c43a5d --- /dev/null +++ b/src/main/kotlin/Transmutation.kt @@ -0,0 +1,57 @@ +import java.util.* + +/** + * 反应物炼金 + */ +class Transmutation(seed: Long) { + private val chaosMap = IntArray(REAGENT_COUNT) { it } + + init { + var swap: Int + val ran = Random(seed) + val arr = IntArray(REAGENT_COUNT) { it } + // 根据 CAB 脚本代码消费几次 ran + repeat(7) { + repeat(4) { ran.nextInt(6) } + shuffle(IntArray(6), ran) + } + // 反应物洗牌(混沌 step 1) + shuffle(arr, ran) + for (i in 0 until REAGENT_COUNT step 2) { + if (arr[i] >= Silicon.index && arr[i + 1] >= Silicon.index) { + if (i == 0) { + swap = arr[2] + arr[2] = arr[1] + arr[1] = swap + } else { + swap = arr[i - 1] + arr[i - 1] = arr[i] + arr[i] = swap + } + } + } + // 混沌 step 2:置换 + for (x in 0 until REAGENT_COUNT step 2) { + chaosMap[arr[x]] = arr[x + 1] + chaosMap[arr[x + 1]] = arr[x] + } + } + + /** + * 根据产出查询混沌配方素材 + */ + fun transmuted(result: Reagent) = Reagent(chaosMap[result.index]) + + /** + * 洗牌 + */ + private fun shuffle(arr: IntArray, ran: Random) { + var tmp: Int + for (i in arr.lastIndex downTo 1) { + val j = ran.nextInt(i + 1) + tmp = arr[i] + arr[i] = arr[j] + arr[j] = tmp + } + } +}