mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-04-24 17:27:17 +00:00
fix: read itemcost correctly
This commit is contained in:
parent
0bcda3233e
commit
3c8e5f8da8
@ -15,6 +15,7 @@ import spray.json._
|
|||||||
import scala.concurrent.{ExecutionContext, Future}
|
import scala.concurrent.{ExecutionContext, Future}
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
import scala.util.Try
|
import scala.util.Try
|
||||||
|
import scala.util.matching.Regex
|
||||||
|
|
||||||
trait XivApi extends RequestExecutor {
|
trait XivApi extends RequestExecutor {
|
||||||
|
|
||||||
@ -77,6 +78,8 @@ object XivApi {
|
|||||||
|
|
||||||
private val defaultShop = JsObject("IsUnique" -> JsNumber(1), "StackSize" -> JsNumber(999))
|
private val defaultShop = JsObject("IsUnique" -> JsNumber(1), "StackSize" -> JsNumber(999))
|
||||||
|
|
||||||
|
private val itemRegexp = new Regex("""Item(Receive|Cost)(\d+)""", "type", "index")
|
||||||
|
|
||||||
private def parseXivapiJsonToShop(
|
private def parseXivapiJsonToShop(
|
||||||
js: JsObject
|
js: JsObject
|
||||||
)(implicit executionContext: ExecutionContext): Future[Map[Long, (String, Long)]] = {
|
)(implicit executionContext: ExecutionContext): Future[Map[Long, (String, Long)]] = {
|
||||||
@ -86,12 +89,12 @@ object XivApi {
|
|||||||
.map(_ => "crafted" -> -1L) // you can craft this item
|
.map(_ => "crafted" -> -1L) // you can craft this item
|
||||||
.orElse { // lets try shop items
|
.orElse { // lets try shop items
|
||||||
js.fields("SpecialShop").asJsObject.fields.collectFirst {
|
js.fields("SpecialShop").asJsObject.fields.collectFirst {
|
||||||
case (shopName, JsArray(array)) if shopName.startsWith("ItemReceive") =>
|
case (shopName, JsArray(array)) if itemRegexp.matches(shopName) =>
|
||||||
val shopId = array.head match {
|
val shopId = array.head match {
|
||||||
case JsNumber(id) => id.toLong
|
case JsNumber(id) => id.toLong
|
||||||
case other => throw deserializationError(s"Could not parse $other")
|
case other => throw deserializationError(s"Could not parse $other")
|
||||||
}
|
}
|
||||||
shopName.replace("ItemReceive", "") -> shopId
|
itemRegexp.findFirstMatchIn(shopName).get.group("index") -> shopId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.getOrElse(throw deserializationError(s"Could not parse $js"))
|
.getOrElse(throw deserializationError(s"Could not parse $js"))
|
||||||
|
Loading…
Reference in New Issue
Block a user