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