-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfortrecruiting.js
144 lines (135 loc) · 4.38 KB
/
fortrecruiting.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// vim: tabstop=2 shiftwidth=2 expandtab
//
TWDS.fbmisc.updateRecruitlist = function (arg) {
FortBattleWindow.backup_updateRecruitlist.call(this, arg)
if (!TWDS.settings.fbmisc_recruiting) return
const that = this
const iae = this.infoareaEl[0]
const rcl = TWDS.q1('.fort_battle_recruitlist_list', iae)
if (!rcl) return
rcl.classList.add('TWDS_enhanced')
const trows = TWDS.q1('.trows', rcl)
const head = TWDS.q1('.thead .row_head', trows)
const ev = TWDS.q1('.evaluated', head)
const body = TWDS.q1('.tbody', trows)
TWDS.createEle('div.cell.cell_7.hp', {
textContent: 'HP',
before: ev,
onclick: function (ev) {
const title = 'Sort by health'
const sorting = TWDS.createEle('div')
TWDS.createEle('div.linklike', {
textContent: '0 1 ... 8 9',
last: sorting,
onclick: function () {
that.preBattle.setSort('>hp')
that.updateRecruitlist(true)
mb.hide()
}
})
TWDS.createEle('div.linklike', {
textContent: '9 8 ... 1 0',
last: sorting,
onclick: function () {
that.preBattle.setSort('<hp')
that.updateRecruitlist(true)
mb.hide()
}
})
const mb = new west.gui.Dialog(title, sorting).addButton('cancel').show()
}
})
TWDS.createEle('div.cell.cell_7.dist', {
textContent: 'Dist.',
before: ev,
onclick: function (ev) {
const title = 'Sort by distance'
const sorting = TWDS.createEle('div')
TWDS.createEle('div.linklike', {
textContent: '0 1 ... 8 9',
last: sorting,
onclick: function () {
that.preBattle.setSort('>dist')
that.updateRecruitlist(true)
mb.hide()
}
})
TWDS.createEle('div.linklike', {
textContent: '9 8 ... 1 0',
last: sorting,
onclick: function () {
that.preBattle.setSort('<dist')
that.updateRecruitlist(true)
mb.hide()
}
})
const mb = new west.gui.Dialog(title, sorting).addButton('cancel').show()
}
})
const st = TWDS.q1('.cell_5 .sort-status', head)
st.innerHTML = ''
TWDS.createEle('img.sort.sort-status', {
src: '/images/chat/servicegrade_general.png',
last: st
})
const list = this.preBattle.battleData.playerlist
for (let i = 0; i < list.length; i++) {
const p = list[i]
p.dist = 0
const pid = p.player_id
const a = TWDS.q1('.player-' + pid, body)
if (!a) continue
const r = a.closest('.row')
if (!r) continue
if (Game.gameURL.includes('/en15.') && p.town_id === 510 && p.townname.includes(' Thicc ')) {
const townele = TWDS.q1('.town', r)
if (townele && p.town_id === 510) {
townele.textContent = 'Thicc'
}
}
const ev = TWDS.q1('.evaluated', r)
if (!ev) continue
let str = p.currhealth
let cladd = ''
if (p.currhealth !== p.maxhealth) {
str += '/' + p.maxhealth
cladd = 'notfull'
}
TWDS.createEle('div.cell.cell_7.hp', {
before: ev,
textContent: str,
className: cladd
})
let dist = (this.preBattle.battleData.fortCoords.x - p.coords.x) *
(this.preBattle.battleData.fortCoords.x - p.coords.x) +
(this.preBattle.battleData.fortCoords.y - p.coords.y) *
(this.preBattle.battleData.fortCoords.y - p.coords.y)
p.dist = dist
dist = (Math.round(Math.sqrt(dist)) / 1000).toFixed(1)
cladd = ''
if (dist > 0.0) {
cladd = 'away'
}
TWDS.createEle('div.cell.cell_7.dist', {
before: ev,
textContent: dist,
className: cladd
})
}
}
TWDS.fbmisc.recruitingstartfunc = function () {
TWDS.registerSetting('bool', 'fbmisc_recruiting',
TWDS._('FBMISC_SETTING_RECRUITING', 'Enhance the recruiting window.'),
true, null, 'fortbattles')
FortBattleWindow.backup_updateRecruitlist = FortBattleWindow.backup_updateRecruitlist ||
FortBattleWindow.updateRecruitlist
FortBattleWindow.updateRecruitlist = TWDS.fbmisc.updateRecruitlist
window.PreBattle.recruitSorting.hp = function (a, b, eq) {
return eq ? a.currhealth === b.currhealth : a.currhealth < b.currhealth
}
window.PreBattle.recruitSorting.dist = function (a, b, eq) {
return eq ? a.dist === b.dist : a.dist < b.dist
}
window.PreBattle.recruitSorting.order = ['>town', '>name', '<level', '>class', '<rank', '<grader', '<hp', '<dist']
}
TWDS.registerStartFunc(TWDS.fbmisc.recruitingstartfunc)