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 = arguments["api_slotitem_ids"]?
19 .components(separatedBy: ",")
21 else { return print("api_slotitem_ids is wrong") }
22 let store = ServerDataStore.oneTimeEditor()
23 store.slotItems(in: itemIds)
24 .forEach { store.delete($0) }
26 guard let material = store.material()
27 else { return print("Material is not found") }
28 guard let gm = data["api_get_material"].arrayObject as? [Int]
29 else { return print("api_get_material is wrong") }
30 let resouces = ["fuel", "bull", "steel", "bauxite"]
31 zip(gm, resouces).forEach {
32 if let current = material.value(forKey: $0.1) as? Int {
33 material.setValue((current + $0.0) as NSNumber, forKey: $0.1)