-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_improvement.js
127 lines (116 loc) · 4.87 KB
/
item_improvement.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Ver:3.0.3
// Author:Nishisonic
// script読み込み
load("script/utils.js")
load("script/ScriptData.js")
// import部分
IOUtils = Java.type("org.apache.commons.io.IOUtils")
BufferedReader = Java.type("java.io.BufferedReader")
InputStreamReader = Java.type("java.io.InputStreamReader")
HttpURLConnection = Java.type("java.net.HttpURLConnection")
StandardCharsets = Java.type("java.nio.charset.StandardCharsets")
Files = Java.type("java.nio.file.Files")
Paths = Java.type("java.nio.file.Paths")
StandardOpenOption = Java.type("java.nio.file.StandardOpenOption")
URI = Java.type("java.net.URI")
URL = Java.type("java.net.URL")
Calendar = Java.type("java.util.Calendar")
HashMap = Java.type("java.util.HashMap")
TimeZone = Java.type("java.util.TimeZone")
Collectors = Java.type("java.util.stream.Collectors")
HttpsURLConnection = Java.type("javax.net.ssl.HttpsURLConnection")
Ship = Java.type("logbook.internal.Ship")
data_prefix = "improvement_"
var VERSION = 3.02
var LOAD_FILE_URL = "https://raw.githubusercontent.com/TeamFleet/WhoCallsTheFleet-DB/master/db/items.nedb"
var UPDATE_CHECK_URL = "https://raw.githubusercontent.com/Nishisonic/RemodelItem/master/update3.txt"
var FILE_URL_LIST = [
"https://raw.githubusercontent.com/Nishisonic/RemodelItem/master/item_improvement.js",
"https://raw.githubusercontent.com/Nishisonic/RemodelItem/master/itemstyle.js",
]
/** 保存場所 */
var EXECUTABLE_FILE_LIST = [
"script/item_improvement.js",
"script/itemstyle.js",
]
function header() {
return ["二番艦"]
}
function begin() {
if (!getData("items") || getData("items").size() === 0) {
try {
if (VERSION < Number(IOUtils.toString(URI.create(UPDATE_CHECK_URL), StandardCharsets.UTF_8))) {
FILE_URL_LIST.forEach(function (file, i) {
IOUtils.write(IOUtils.toString(URI.create(file), StandardCharsets.UTF_8),
Files.newOutputStream(Paths.get(EXECUTABLE_FILE_LIST[i]),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING),
StandardCharsets.UTF_8)
})
}
} catch (e) {}
var url = new URL(LOAD_FILE_URL)
var connection = HttpsURLConnection.class.cast(url.openConnection())
connection.setRequestMethod("HEAD")
connection.connect()
if (connection.getResponseCode() === HttpURLConnection.HTTP_OK) {
var reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"))
var items = reader.lines().map(function (line) {
return JSON.parse(line)
}).filter(function (data) {
return data.improvable
}).collect(Collectors.groupingBy(function (data) {
return data.id
}))
setTmpData("items", items)
} else {
setTmpData("items", new HashMap())
}
}
}
function body(data) {
var dayOfWeek = Calendar.getInstance(TimeZone.getTimeZone("Asia/Tokyo")).get(Calendar.DAY_OF_WEEK) - 1
var items = getData("items")
if (items.containsKey(data.info.id)) {
var item = items.get(data.info.id)[0]
var flatten = function (array) {
return array.reduce(function (a, c) {
return Array.isArray(c) ? a.concat(flatten(c)) : a.concat(c)
}, [])
}
var shipNames = flatten(item.improvement.map(function (improvement) {
return Array.prototype.concat.apply([], improvement.req.filter(function (data) {
return data[0][dayOfWeek]
}).map(function (data) {
return data[1]
}))
})).map(function (id) {
return id === false ? "任意二番艦" : Ship.get(id).fullName
}).join(" / ")
if (shipNames) {
return toComparable([shipNames])
}
var nextDayOfWeek = Array.apply(null, new Array(7)).map(function (_, i) {
return (i + dayOfWeek + 1) % 7
}).filter(function (d) {
return item.improvement.some(function (improvement) {
return improvement.req.some(function (data) {
return data[0][d]
})
})
})[0]
var nextShipNames = flatten(item.improvement.map(function (improvement) {
return Array.prototype.concat.apply([], improvement.req.filter(function (data) {
return data[0][nextDayOfWeek]
}).map(function (data) {
return data[1]
}))
})).map(function (id) {
return id === false ? "任意二番艦" : Ship.get(id).fullName
}).join(" / ")
var dayOfWeekString = ["日", "月", "火", "水", "木", "金", "土"]
return toComparable([String("次回(" + dayOfWeekString[nextDayOfWeek] + "):" + nextShipNames)])
}
return toComparable([""])
}
function end() {}