forked from JaccaK/AlbionRecipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipetable.js
165 lines (153 loc) · 6.5 KB
/
recipetable.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
function createTableFromRecipes(recipes,itemmap){
var city = $("#locations").val()
var rrr = $("#rrr").val()
var nutri = $("#nutri").val()
var tax = FREE_TAX //6% tax + 1.5% setup fee
if($("#prem").is(":checked"))
tax = PREM_TAX //3% tax + 1.5% setup fee
var quality = $("#quality").val()
if(isNaN(quality))
quality = 1
$("#tablearea").empty().append("<table>")
$("#tablearea > table").append("<tr><th class=\"enchant\">En</th><th>Product</th><th class=\"nut\">Nutri</th><th>#</th><th style=\"width:5%\">Price</th><th>Profit</th><th>Material</th><th>#</th><th class=\"cost\" style=\"width:3%\">Cost</tr>")
var string = ""
for (let i = 0; i < recipes.length; i++) {
string = string + "<tr><td class=\"enchant\">"+getEnchantFromName(recipes[i].result)
+"</td><td>"+ITEM_NAMES.get(recipes[i].result)+"</td><td class=\"nut\">"
+recipes[i].nutrition+"</td><td>"
+ recipes[i].quantity+"</td><td><input type=\"number\" class=\"price\" style=\"width:80%\" min=0 value="
+itemmap.getPrice(recipes[i].result,quality,city)+"></td><td class=\"profit\">"
+Math.trunc(recipes[i].calcProfit(itemmap,quality,city,rrr,nutri,tax))+"</td>"
for (var key of recipes[i].ingredients.keys()){
string = string + "<td>"+ITEM_NAMES.get(key)+"</td><td>"+recipes[i].ingredients.get(key)+"</td><td><input type=\"number\" class=\"cost\" min=0 size=\"8\" value="+itemmap.getPrice(key,1,city)+">"
+"<td class=\"exclude\">"+recipes[i].isExcluded(key)+"</td>"
}
string = string + "</tr>"
}
$("#tablearea > table")
.append(string)
}
function createTableFromRecipesDifferentEnd(recipes,itemmap){
var city = $("#locations").val()
var endCity = $("#endLocations").val()
var rrr = $("#rrr").val()
var nutri = $("#nutri").val()
var tax = FREE_TAX //6% tax + 1.5% setup fee
if($("#prem").is(":checked"))
tax = PREM_TAX //3% tax + 1.5% setup fee
var quality = $("#quality").val()
if(isNaN(quality))
quality = 1
$("#tablearea").empty().append("<table>")
$("#tablearea > table").append("<tr><th class=\"enchant\">En</th><th>Product</th><th class=\"nut\">Nutri</th><th>#</th><th style=\"width:5%\">Price</th><th>Profit</th><th>Material</th><th>#</th><th class=\"cost\" style=\"width:3%\">Cost</tr>")
var string = ""
for (let i = 0; i < recipes.length; i++) {
string = string + "<tr><td class=\"enchant\">"+getEnchantFromName(recipes[i].result)
+"</td><td>"+ITEM_NAMES.get(recipes[i].result)+"</td><td class=\"nut\">"
+recipes[i].nutrition+"</td><td>"
+ recipes[i].quantity+"</td><td><input type=\"number\" class=\"price\" style=\"width:80%\" min=0 value="
+itemmap.getPrice(recipes[i].result,quality,endCity)+"></td><td class=\"profit\">"
+Math.trunc(recipes[i].calcProfit(itemmap,quality,city,rrr,nutri,tax))+"</td>"
for (var key of recipes[i].ingredients.keys()){
string = string + "<td>"+ITEM_NAMES.get(key)+"</td><td>"+recipes[i].ingredients.get(key)+"</td><td><input type=\"number\" class=\"cost\" min=0 size=\"8\" value="+itemmap.getPrice(key,1,city)+">"
+"<td class=\"exclude\">"+recipes[i].isExcluded(key)+"</td>"
}
string = string + "</tr>"
}
$("#tablearea > table")
.append(string)
}
function createNavBar(){
htmlstuff = "<ul><li><a href=\"index.html\">HOME</a></li>"
+"<ul><li><a href=\"cooking.html\">CHEF</a></li>"
+"<ul><li><a href=\"alchemy.html\">ALCHEMIST</a></li>"
+"<ul><li><a href=\"saddler.html\">SADDLER</a></li>"
+"<ul><li><a href=\"toolmaker.html\">TOOLMAKER</a></li>"
+"<ul><li><a href=\"magestower.html\">MAGE'S TOWER</a></li>"
+"<ul><li><a href=\"hunterslodge.html\">HUNTER'S LODGE</a></li>"
+"<ul><li><a href=\"warriorsforge.html\">WARRIOR'S FORGE</a></li>"
+"<ul><li><a href=\"refine.html\">REFINING</a></li>"
+"<ul><li><a href=\"farm.html\">FARM</a></li>"
+"<ul><li><a href=\"butcher.html\">BUTCHER</a></li>"
+"<ul><li><a href=\"artefact.html\">FOUNDRY</a></li>"
+"</ul><br>"
$("#navbararea").empty().append(htmlstuff)
}
function updateButtonTextUpdating(){
$("#updateButton").text("Updating . . .")
$("#updateButton").prop( "disabled", true );
$("#tablearea").empty();
}
function updateButtonTextUpdated(){
$("#updateButton").text("Update")
$("#updateButton").prop( "disabled", false )
}
function changeProfitColor() {
$(".profit").each( function() {
var profit = parseInt($(this).text().trim());
var color = 'red';
if (!isNaN(profit) && profit > 0)
color = 'green';
$(this).css('color', color);
})
}
function hideUnprofitable() {
$(".profit").each( function() {
var profit = parseInt($(this).text().trim());
if (!isNaN(profit) && profit < 1)
$(this).parent().remove()
})
}
function showOnlyEnchant(enchantlevel) {
$(".enchant").each( function () {
if (!$(this).html().includes("En") && ($(this).text() != enchantlevel))
$(this).parent().remove()
})
}
async function updateProfit(){
var city = $("#locations").val()
var rrr = $("#rrr").val()
var nutri = $("#nutri").val()
var tax = FREE_TAX //6% tax + 1.5% setup fee
if($("#prem").is(":checked"))
tax = PREM_TAX //3% tax + 1.5% setup fee
$(".profit").each(function () {
var price = $(this).parent().children().children(".price").val()
var quantity = $(this).parent().children().children(".price").parent().prev().text()
var nutricost = $(this).parent().children().children(".price").parent().prev().prev().text()
nutricost = nutricost * nutri
price = price * quantity
var cost = 0
$(this).parent().children().children(".cost").each(function (){
quantity = $(this).parent().prev().text()
exluded = $(this).parent().next().text()
if(exluded == "false"){
cost = cost + $(this).val() * quantity * (1 - rrr)
} else {
cost = cost + $(this).val() * quantity
}
})
var profit = price * (1 - tax) - cost - nutricost
$(this).parent().children(".profit").text(Math.trunc(profit))
})
changeProfitColor()
}
$("*").change(function() { updateProfit() })
function getEnchantFromName(enchant){
var enchantlevel = "0"
if(enchant.indexOf("@") != -1){
enchantlevel = enchant.at(-1)
}
return enchantlevel
}
async function bindSelectRow(){
$("#tablearea > table > tr").click(function() {
$(".selectedRow").removeClass()
$(this).addClass("selectedRow")
})
}
function appendItems(itemarray) { //Limit total item list to around 8000 characters.
string = ""
itemarray.forEach(item => string = string+item+",")
return string
}