OSDN Git Service

Doutakuを導入
[kcd/KCD.git] / KCD / NyukyoStartCommand.swift
1 //
2 //  NyukyoStartCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/08.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class NyukyoStartCommand: JSONCommand {
12     
13     override class func canExecuteAPI(_ api: API) -> Bool {
14         
15         return api.endpoint == .startNyukyo
16     }
17     
18     override func execute() {
19         
20         guard let hi = parameter["api_highspeed"].int, hi != 0 else { return }
21         
22         let store = ServerDataStore.oneTimeEditor()
23         store.sync {
24             self.parameter["api_ship_id"]
25                 .int
26                 .flatMap(store.ship(by:))
27                 .map { $0.nowhp = $0.maxhp }
28             
29             store.material()
30                 .map { $0.kousokushuhuku = $0.kousokushuhuku - 1 }
31         }
32     }
33 }