2 // DropShipHistoryCommand.swift
5 // Created by Hori,Masaki on 2017/01/14.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 class DropShipHistoryCommand: JSONCommand {
12 override func execute() {
13 if api == "/kcsapi/api_port/port" || api == "/kcsapi/api_get_member/ship_deck" {
16 if !api.hasSuffix("battleresult") { return }
18 guard let data = json[dataKey] as? [String: Any],
19 let getShip = data["api_get_ship"] as? [String: Any],
20 let shipName = getShip["api_ship_name"] as? String,
21 let winRank = data["api_win_rank"] as? String
23 guard let battle = TemporaryDataStore.default.battle()
24 else { return print("Can not get Battle") }
25 let mapAreaId = battle.mapArea
27 let store = ServerDataStore.default
28 guard let mapInfo = store.mapInfo(area: mapAreaId, no: battle.mapInfo)
29 else { return print("KCMasterMapInfo is not found") }
30 guard let mapArea = store.mapArea(byId: mapAreaId)
31 else { return print("KCMasterMapArea is not found") }
33 let localStore = LocalDataStore.oneTimeEditor()
34 guard let new = localStore.createHiddenDropShipHistory()
35 else { return print("Can not create HiddenDropShipHistory") }
36 new.shipName = shipName
37 new.mapArea = "\(mapAreaId)"
38 new.mapAreaName = mapArea.name
39 new.mapInfo = battle.mapInfo
40 new.mapInfoName = mapInfo.name
41 new.mapCell = battle.no
46 private func storeToVisible() {
47 let store = LocalDataStore.oneTimeEditor()
48 store.hiddenDropShipHistories()
50 guard let new = store.createDropShipHistory()
51 else { return print("Can not create DropShipHistory") }
52 new.shipName = $0.shipName
53 new.mapArea = $0.mapArea
54 new.mapAreaName = $0.mapAreaName
55 new.mapInfo = $0.mapInfo
56 new.mapInfoName = $0.mapInfoName
57 new.mapCell = $0.mapCell
58 new.winRank = $0.winRank