Skip to content

Instantly share code, notes, and snippets.

@ShikiSuen
Last active March 31, 2024 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShikiSuen/c1b3e3bbf3e1d9c36f5a977c42d12e71 to your computer and use it in GitHub Desktop.
Save ShikiSuen/c1b3e3bbf3e1d9c36f5a977c42d12e71 to your computer and use it in GitHub Desktop.
// (c) 2024 Shiki Suen. (MIT-License).
// 用於《崩壞:星穹鐵道》2.1 版的調酒活動。
struct Nomimono {
let name: String
let amami: Int // 甜度
let yawarakasa: Int // 柔和度
let sawayakasa: Int // 清爽度
public init(_ name: String?, _ params: (Int, Int, Int)) {
self.name = name ?? ""
amami = params.0
yawarakasa = params.1
sawayakasa = params.2
}
func hasSameParamsWith(_ target: Nomimono) -> Bool{
amami == target.amami && yawarakasa == target.yawarakasa && sawayakasa == target.sawayakasa
}
func hasSameParamsWith(_ target: [Nomimono]) -> Bool{
let summed = target.summedProperties
return amami == summed.0 && yawarakasa == summed.1 && sawayakasa == summed.2
}
}
extension Array where Element == Nomimono {
var summedProperties: (Int, Int, Int) {
var (x, y, z) = (0, 0, 0)
self.forEach { nomimono in
x += nomimono.amami
y += nomimono.yawarakasa
z += nomimono.sawayakasa
}
return (x, y, z)
}
}
let AllNomimonos: [Nomimono] = [
.init("羊奶", (2, 0, 2)),
.init("博士", (1, 0, -1)),
.init("冰点", (1, 0, -2)),
.init("安神", (-1, 0, -1)),
.init("怪味", (-2, 0, 1)),
.init("激梦", (0, 2, 1)),
.init("糖浆", (0, 1, 2)),
.init("清露", (0, 1, -1)),
.init("夕红", (0, -1, 1)),
.init("能量", (0, -1, 0)),
.init("豆汁", (0, -2, 2)),
]
func combos<T>(elements: ArraySlice<T>, k: Int) -> [[T]] {
guard k != 0, let first = elements.first else { return [[]] }
let head = [first]
let subcombos = combos(elements: elements, k: k - 1)
return subcombos.map { head + $0 } + combos(elements: elements.dropFirst(), k: k)
}
func combos<T>(elements: Array<T>, k: Int) -> [[T]] {
return combos(elements: ArraySlice(elements), k: k)
}
enum CupSize: Int {
case S = 3
case L = 4
case XL = 5
}
// Expected 填写期望的饮料特征;sourceAmount 根据杯子的大小填写要倒几次成分饮料。
func plan(_ expected: Nomimono, cupSize: CupSize) -> [Nomimono]? {
let sourceAmount = cupSize.rawValue
let allCombinations = combos(elements: AllNomimonos, k: sourceAmount)
var results = [[Nomimono]]()
for combination in allCombinations {
guard expected.hasSameParamsWith(combination) else { continue }
results.append(combination)
}
return results.randomElement()
}
// ---------------
// 開始測試。
if let result = plan(Nomimono(nil, (1, 0, 0)), cupSize: .XL) {
result.forEach { component in
print(component)
}
}
@ShikiSuen
Copy link
Author

ShikiSuen commented Mar 31, 2024

這腳本是在 iPad 與 macOS 系統下運作的,使用時只需要提供杯子大小、以及要調酒的各種口味參數即可。
哪裡有巨集?哪裡會修改到遊戲數據?

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment