-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculateFormulas.js
188 lines (153 loc) · 8.26 KB
/
calculateFormulas.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Функция для добавления новых элементов
function addNewItem(formulaNumber) {
const additionalInputs = document.getElementById(`additional-inputs-${formulaNumber}`);
// Новый HTML код для добавления уровня и количества предметов 📙
const inputFields = `
<div class="input-group">
<label>Уровень 📙:</label>
<select class="level-item">
<option value="70">70</option>
<option value="5">1 - 5</option>
<option value="10">6 - 10</option>
<option value="15">11 - 15</option>
<option value="20">16 - 20</option>
<option value="25">21 - 25</option>
<option value="30">26 - 30</option>
<option value="35">31 - 35</option>
<option value="40">36 - 40</option>
<option value="45">41 - 45</option>
<option value="50">46 - 50</option>
<option value="55">51 - 55</option>
<option value="60">56 - 60</option>
<option value="65">61 - 65</option>
<option value="66">66 - 69</option>
</select>
</div>
<div class="input-group">
<label>Количество 📙:</label>
<input type="number" class="quantity-item" min="1">
</div>`;
// Вставляем новый блок
additionalInputs.insertAdjacentHTML('beforeend', inputFields);
// После добавления новых полей пересчитываем результаты
calculateTotal(formulaNumber);
}
// Функция для добавления полей "Количество 🧪"
function addPotionInputFields(containerId) {
const container = document.getElementById(containerId);
// Новый HTML код для добавления поля "Количество 🧪"
const inputField = `
<div class="input-group">
<label>Количество 🧪:</label>
<input type="number" class="potion-quantity" min="1">
</div>`;
// Добавление нового блока
container.insertAdjacentHTML('beforeend', inputField);
}
// Модифицированная функция удаления полей
function removeInputFields(containerId) {
const container = document.getElementById(containerId);
if (container.lastElementChild) {
container.lastElementChild.remove();
}
}
// Функция для перерасчёта итогов для добавленных элементов
function calculateAdditionalTotal(formulaNumber) {
const itemQuantities = document.querySelectorAll(`#formula-${formulaNumber} .quantity-item`);
const itemLevels = document.querySelectorAll(`#formula-${formulaNumber} .level-item`);
console.log("Количество элементов:", itemQuantities.length, itemLevels.length);
let totalValue = 0;
const levelTotals = {};
for (let i = 0; i < itemQuantities.length; i++) {
const quantity = parseInt(itemQuantities[i].value) || 0;
const level = parseInt(itemLevels[i].value) || 0;
console.log(`Обработка элемента ${i + 1}: Количество = ${quantity}, Уровень = ${level}`);
// Применяем priceTable1 или priceTable2 в зависимости от формулы
const adjustedLevel = formulaNumber === 1 ? (priceTable1[level] || 0) : (priceTable2[level] || 0);
// Применяем формулу: (уровень / 3) * 4 * количество
const pricePerItem = (adjustedLevel / 3) * 4;
const levelTotal = pricePerItem * quantity;
totalValue += levelTotal;
if (level in levelTotals) {
levelTotals[level] += levelTotal;
} else {
levelTotals[level] = levelTotal;
}
}
return { totalValue, levelTotals };
}
function calculateTotal(formulaNumber) {
const quantities = document.querySelectorAll(`#formula-${formulaNumber} .quantity`);
const levels = document.querySelectorAll(`#formula-${formulaNumber} .level`);
// Получаем множители
const multiplier = parseFloat(document.getElementById(`guild-multiplier-${formulaNumber}`).value) || 1;
const portalmultiplier = parseFloat(document.getElementById(`portal-multiplier-${formulaNumber}`).value) || 1.0;
const difficultymultiplier = parseFloat(document.getElementById(`difficulty-multiplier-${formulaNumber}`).value) || 1.5;
let totalValue = 0;
const levelTotals = {};
// Обработка полей 💍
for (let i = 0; i < quantities.length; i++) {
const quantity = parseInt(quantities[i].value) || 0;
const level = parseInt(levels[i].value) || 0;
const price = formulaNumber === 1 ? priceTable1[level] || 0 : priceTable2[level] || 0;
const levelTotal = quantity * price;
if (quantity > 0) {
totalValue += levelTotal;
if (level in levelTotals) {
levelTotals[level] += levelTotal;
} else {
levelTotals[level] = levelTotal;
}
}
}
// Обработка "+📙" блоков
const itemQuantities = document.querySelectorAll(`#formula-${formulaNumber} .quantity-item`);
const itemLevels = document.querySelectorAll(`#formula-${formulaNumber} .level-item`);
const levelTotalsExtra = {};
for (let i = 0; i < itemQuantities.length; i++) {
const quantity = parseInt(itemQuantities[i].value) || 0;
const level = parseInt(itemLevels[i].value) || 0;
if (quantity > 0) {
const adjustedLevel = formulaNumber === 1 ? (priceTable1[level] || 0) : (priceTable2[level] || 0);
const pricePerItem = (adjustedLevel / 3) * 4;
const levelTotal = pricePerItem * quantity;
if (level in levelTotalsExtra) {
levelTotalsExtra[level] += levelTotal;
} else {
levelTotalsExtra[level] = levelTotal;
}
}
}
// Обработка "+🧪" блоков
const potionQuantities = document.querySelectorAll(`#formula-${formulaNumber} .potion-quantity`);
let potionTotal = 0;
potionQuantities.forEach(potionQuantity => {
const quantity = parseInt(potionQuantity.value) || 0;
potionTotal += 500 * quantity;
});
// Итоговый расчёт с учётом всех множителей
let adjustedTotal = totalValue * multiplier * portalmultiplier * difficultymultiplier;
Object.keys(levelTotalsExtra).forEach(level => {
adjustedTotal += levelTotalsExtra[level] * multiplier * portalmultiplier * difficultymultiplier;
});
adjustedTotal += potionTotal * multiplier * portalmultiplier * difficultymultiplier;
// Отображение результата
const resultElement = document.getElementById(`result-${formulaNumber}`);
resultElement.innerHTML = `<strong>Результат:</strong> ${formatCurrency(adjustedTotal)} (${adjustedTotal.toFixed(2)})`;
// Отображаем результаты для обычных вещей 💍
Object.keys(levelTotals).forEach(level => {
if (levelTotals[level] > 0) {
resultElement.innerHTML += `<div class="result-small">📘📒 ${level} уровня: ${formatCurrency(levelTotals[level])} (${levelTotals[level].toFixed(2)})</div>`;
}
});
// Отображаем результаты для "+📙" блоков
Object.keys(levelTotalsExtra).forEach(level => {
if (levelTotalsExtra[level] > 0) {
resultElement.innerHTML += `<div class="result-small">📙 ${level} уровня: ${formatCurrency(levelTotalsExtra[level])} (${levelTotalsExtra[level].toFixed(2)})</div>`;
}
});
// Отображаем результаты для "+🧪" блоков
if (potionTotal > 0) {
resultElement.innerHTML += `<div class="result-small">Стоимость 🧪: ${formatCurrency(potionTotal)} (${(potionTotal).toFixed(2)})</div>`;
}
}