2 // DestroyItem2Command.swift
5 // Created by Hori,Masaki on 2017/01/10.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class DestroyItem2Command: JSONCommand {
13 override class func canExecuteAPI(_ api: String) -> Bool {
15 if api == "/kcsapi/api_req_kousyou/destroyitem2" { return true }
20 override func execute() {
22 guard let itemIds = parameter["api_slotitem_ids"]
24 .components(separatedBy: ",")
26 else { return print("api_slotitem_ids is wrong") }
28 let store = ServerDataStore.oneTimeEditor()
30 store.slotItems(in: itemIds)
31 .forEach { store.delete($0) }
33 guard let material = store.material()
34 else { return print("Material is not found") }
36 guard let gm = data["api_get_material"].arrayObject as? [Int]
37 else { return print("api_get_material is wrong") }
39 let resouces = ["fuel", "bull", "steel", "bauxite"]
41 zip(gm, resouces).forEach {
43 if let current = material.value(forKey: $0.1) as? Int {
45 material.setValue((current + $0.0) as NSNumber, forKey: $0.1)