OSDN Git Service

staticプロパティをインスタンスプロパティに変更
[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: API) -> Bool {
14         
15         return api.endpoint == .destroyItem2
16     }
17     
18     override func execute() {
19         
20         let store = ServerDataStore.oneTimeEditor()
21         
22         store.sync { store.slotItems(in: self.parameter["api_slotitem_ids"].integerArray).forEach(store.delete) }
23         
24         guard let material = store.sync(execute: { store.material() }) else {
25             
26             Logger.shared.log("Material is not found")
27             
28             return
29         }
30         guard let getMaterials = data["api_get_material"].arrayObject as? [Int],
31             getMaterials.count >= 4 else {
32                 
33                 Logger.shared.log("api_get_material is wrong")
34                 
35                 return
36         }
37         
38         store.sync {
39             
40             material.fuel += getMaterials[0]
41             material.bull += getMaterials[1]
42             material.steel += getMaterials[2]
43             material.bauxite += getMaterials[3]
44         }
45     }
46 }