OSDN Git Service

integerArrayプロパティを使用するようにした
[kcd/KCD.git] / KCD / DestroyItem2Command.swift
index d3e5f53..4a0c3ad 100644 (file)
@@ -10,40 +10,27 @@ import Cocoa
 
 final class DestroyItem2Command: JSONCommand {
     
-    override class func canExecuteAPI(_ api: String) -> Bool {
+    override class func canExecuteAPI(_ api: API) -> Bool {
         
-        if api == "/kcsapi/api_req_kousyou/destroyitem2" { return true }
-        
-        return false
+        return api.endpoint == .destroyItem2
     }
     
     override func execute() {
         
-        guard let itemIds = parameter["api_slotitem_ids"]
-            .string?
-            .components(separatedBy: ",")
-            .flatMap({ Int($0) }) else {
-                
-                print("api_slotitem_ids is wrong")
-                return
-        }
-        
         let store = ServerDataStore.oneTimeEditor()
         
-        store.slotItems(in: itemIds).forEach { store.delete($0) }
+        store.slotItems(in: parameter["api_slotitem_ids"].integerArray).forEach(store.delete)
         
         guard let material = store.material() else {
             
-            print("Material is not found")
-            return
+            return Logger.shared.log("Material is not found")
         }
         guard let gm = data["api_get_material"].arrayObject as? [Int] else {
             
-            print("api_get_material is wrong")
-            return
+            return Logger.shared.log("api_get_material is wrong")
         }
         
-        let resouces = ["fuel", "bull", "steel", "bauxite"]
+        let resouces = [#keyPath(Material.fuel), #keyPath(Material.bull), #keyPath(Material.steel), #keyPath(Material.bauxite)]
         
         zip(gm, resouces).forEach {