OSDN Git Service

テスト用表示を修正
[kcd/KCD.git] / KCD / DestroyItem2Command.swift
1 //
2 //  DestroyItem2Command.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/10.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class DestroyItem2Command: JSONCommand {
12     
13     override class func canExecuteAPI(_ api: String) -> Bool {
14         
15         if api == "/kcsapi/api_req_kousyou/destroyitem2" { return true }
16         
17         return false
18     }
19     
20     override func execute() {
21         
22         guard let itemIds = parameter["api_slotitem_ids"]
23             .string?
24             .components(separatedBy: ",")
25             .flatMap({ Int($0) }) else {
26                 
27                 return Logger.shared.log("api_slotitem_ids is wrong")
28         }
29         
30         let store = ServerDataStore.oneTimeEditor()
31         
32         store.slotItems(in: itemIds).forEach(store.delete)
33         
34         guard let material = store.material() else {
35             
36             return Logger.shared.log("Material is not found")
37         }
38         guard let gm = data["api_get_material"].arrayObject as? [Int] else {
39             
40             return Logger.shared.log("api_get_material is wrong")
41         }
42         
43         let resouces = [#keyPath(Material.fuel), #keyPath(Material.bull), #keyPath(Material.steel), #keyPath(Material.bauxite)]
44         
45         zip(gm, resouces).forEach {
46             
47             if let current = material.value(forKey: $0.1) as? Int {
48                 
49                 material.setValue((current + $0.0) as NSNumber, forKey: $0.1)
50             }
51         }
52         
53     }
54 }