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 shipName = data["api_get_ship"]["api_ship_name"].string,
19 let winRank = data["api_win_rank"].string
21 guard let battle = TemporaryDataStore.default.battle()
22 else { return print("Can not get Battle") }
23 let mapAreaId = battle.mapArea
25 let store = ServerDataStore.default
26 guard let mapInfo = store.mapInfo(area: mapAreaId, no: battle.mapInfo)
27 else { return print("KCMasterMapInfo is not found") }
28 guard let mapArea = store.mapArea(byId: mapAreaId)
29 else { return print("KCMasterMapArea is not found") }
31 let localStore = LocalDataStore.oneTimeEditor()
32 guard let new = localStore.createHiddenDropShipHistory()
33 else { return print("Can not create HiddenDropShipHistory") }
34 new.shipName = shipName
35 new.mapArea = "\(mapAreaId)"
36 new.mapAreaName = mapArea.name
37 new.mapInfo = battle.mapInfo
38 new.mapInfoName = mapInfo.name
39 new.mapCell = battle.no
44 private func storeToVisible() {
45 let store = LocalDataStore.oneTimeEditor()
46 store.hiddenDropShipHistories()
48 guard let new = store.createDropShipHistory()
49 else { return print("Can not create DropShipHistory") }
50 new.shipName = $0.shipName
51 new.mapArea = $0.mapArea
52 new.mapAreaName = $0.mapAreaName
53 new.mapInfo = $0.mapInfo
54 new.mapInfoName = $0.mapInfoName
55 new.mapCell = $0.mapCell
56 new.winRank = $0.winRank