fast72 commited on
Commit
45e026b
·
verified ·
1 Parent(s): df034c8

Create index.js

Browse files
Files changed (1) hide show
  1. index.js +159 -0
index.js ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require("express")
2
+ const app = express()
3
+ const port = 7860
4
+ const path = require("path")
5
+
6
+ app.use(express.static("public"))
7
+ app.use(express.urlencoded({ extended: true }))
8
+ app.use(express.json())
9
+
10
+ const fruits = [
11
+ ["Carrot", 0.275, 20, 100], ["Strawberry", 0.3, 15, 100], ["Blueberry", 0.2, 20, 100], ["Orange Tulip", 0.05, 850, 55],
12
+ ["Tomato", 0.5, 30, 100], ["Corn", 2, 40, 100], ["Daffodil", 0.2, 1000, 45], ["Watermelon", 7, 3000, 70],
13
+ ["Pumpkin", 8, 3400, 80], ["Apple", 3, 275, 50], ["Bamboo", 4, 4000, 35], ["Coconut", 14, 400, 70],
14
+ ["Cactus", 7, 3400, 100], ["Dragon Fruit", 12, 4750, 100], ["Mango", 15, 6500, 200], ["Grape", 3, 7850, 200],
15
+ ["Mushroom", 25, 151000, 220], ["Pepper", 5, 8000, 200], ["Cacao", 8, 12000, 250], ["Beanstalk", 10, 28000, 300],
16
+ ["Ember Lily", 12, 66666, 450], ["Sugar Apple", 9, 48000, 200], ["Pineapple", 3, 2000, 70], ["Cauliflower", 5, 40, 150],
17
+ ["Green Apple", 3, 300, 200], ["Banana", 1.5, 2000, 100], ["Avocado", 6.5, 350, 300], ["Kiwi", 5, 2750, 300],
18
+ ["Bell Pepper", 8, 5500, 325], ["Prickly Pear", 7, 7000, 375], ["Feijoa", 10, 13000, 400], ["Loquat", 6.5, 8000, 200],
19
+ ["Wild Carrot", 0.3, 25000, 100], ["Pear", 3, 20000, 120], ["Cantaloupe", 5.5, 34000, 250], ["Parasol Flower", 6, 200000, 350],
20
+ ["Rosy Delight", 10, 69000, 450], ["Elephant Ears", 18, 77000, 500], ["Chocolate Carrot", 0.275, 11000, 100],
21
+ ["Red Lollipop", 4, 50000, 65], ["Blue Lollipop", 1, 50000, 65], ["Candy Sunflower", 1.5, 80000, 85],
22
+ ["Easter Egg", 3, 2500, 20], ["Candy Blossom", 3, 100000, 40], ["Peach", 2, 300, 70], ["Raspberry", 0.75, 100, 70],
23
+ ["Papaya", 3, 1000, 60], ["Banana", 1.5, 1750, 100], ["Passionfruit", 3, 3550, 40], ["Soul Fruit", 25, 7750, 200],
24
+ ["Cursed Fruit", 30, 25750, 200], ["Mega Mushroom", 70, 500, 2000000], ["Cherry Blossom", 3, 500, 400],
25
+ ["Purple Cabbage", 5, 500, 70], ["Lemon", 1, 350, 50], ["Pink Tulip", 0.05, 850, 55], ["Cranberry", 1, 3500, 50],
26
+ ["Durian", 8, 7500, 200], ["Eggplant", 5, 12000, 220], ["Lotus", 20, 35000, 650], ["Venus Fly Trap", 10, 85000, 650],
27
+ ["Nightshade", 0.5, 3500, 100], ["Glowshroom", 0.75, 300, 100], ["Mint", 1, 5250, 150], ["Moonflower", 2, 9500, 200],
28
+ ["Starfruit", 3, 15000, 250], ["Moonglow", 7, 25000, 400], ["Moon Blossom", 3, 66666, 400], ["Crimson Vine", 1, 1250, 100],
29
+ ["Moon Melon", 8, 18000, 300], ["Blood Banana", 1.5, 6000, 200], ["Celestiberry", 2, 10000, 200],
30
+ ["Moon Mango", 15, 50000, 300], ["Rose", 1, 5000, 100], ["Foxglove", 2, 20000, 250], ["Lilac", 3, 35000, 250],
31
+ ["Pink Lily", 6, 65000, 400], ["Purple Dahlia", 12, 75000, 400], ["Sunflower", 16.5, 160000, 600],
32
+ ["Lavender", 0.275, 25000, 90], ["Nectarshade", 0.8, 50000, 100], ["Nectarine", 3, 48000, 200],
33
+ ["Hive Fruit", 8, 62000, 300], ["Manuka Flower", 0.3, 25000, 200], ["Dandelion", 4, 50000, 300],
34
+ ["Lumira", 6, 85000, 350], ["Honeysuckle", 12, 100000, 400], ["Crocus", 0.275, 30000, 150], ["Succulent", 5, 25000, 175],
35
+ ["Violet Corn", 3, 50000, 250], ["Bendboo", 18, 155000, 275], ["Cocovine", 14, 66666, 275],
36
+ ["Dragon Pepper", 6, 88888, 300], ["Bee Balm", 1, 18000, 200], ["Nectar Thorn", 7, 44444, 350],
37
+ ["Suncoil", 10, 80000, 400], ["Noble Flower", 5, 20000, 250], ["Traveler's Fruit", 2, 20000, 250],
38
+ ["Ice Cream Bean", 4, 4500, 200], ["Lime", 1, 1000, 125]
39
+ ]
40
+
41
+ const mutationMultiplier = {
42
+ Dawnbound: 150, Voidtouched: 135, Disco: 125, Meteoric: 125, Galactic: 120,
43
+ Celestial: 120, Shocked: 100, Alienlike: 100, Sundried: 85, Molten: 25,
44
+ Zombified: 25, Paradisal: 18, Frozen: 10, Cooked: 10, Plasma: 5,
45
+ Heavenly: 5, HoneyGlazed: 5, Twisted: 5, Burnt: 4, Bloodlit: 4,
46
+ Verdant: 4, Pollinated: 3, Windstruck: 2, Wet: 2, Chilled: 2,
47
+ Choc: 2, Moonlit: 2
48
+ }
49
+
50
+ const rarityMultiplier = { Normal: 1, Gold: 20, Rainbow: 50 }
51
+
52
+ function clamp(v, min, max) { return Math.min(Math.max(v, min), max) }
53
+ function format(n) { return n.toLocaleString("en-US") + "¢" }
54
+ function calcValue(name, weight, rarity = "Normal", mutations = []) {
55
+ const item = fruits.find(f => f[0] === name)
56
+ if (!item) return "0¢"
57
+ const totalMutation = mutations.reduce((t, m) => t * (mutationMultiplier[m] || 1), 1)
58
+ const clamped = clamp(weight / item[1], 0.95, 1e8)
59
+ const value = Math.round((item[2] * totalMutation * (rarityMultiplier[rarity] || 1)) * (clamped * clamped))
60
+ return format(value)
61
+ }
62
+
63
+ function clamp(v, min, max) { return Math.min(Math.max(v, min), max) }
64
+ function format(n) { return n.toLocaleString("en-US") + "¢" }
65
+ function calcValue(name, weight, rarity = "Normal", mutations = []) {
66
+ const item = fruits.find(f => f[0] === name)
67
+ if (mutations.includes("Dawnbound") && name !== "Sunflower") {
68
+ mutations = mutations.filter(m => m !== "Dawnbound")
69
+ }
70
+ if (!item) return "0¢"
71
+ const totalMutation = mutations.reduce((t, m) => t * (mutationMultiplier[m] || 1), 1)
72
+ const clamped = clamp(weight / item[1], 0.95, 1e8)
73
+ const base = item[2] * totalMutation * (rarityMultiplier[rarity] || 1)
74
+ const value = Math.round(base * (clamped * clamped))
75
+ return { value: format(value), base: format(item[2]) }
76
+ }
77
+
78
+ app.get("/", (req, res) => {
79
+ const fruitOptions = fruits.map(f => f[0]).sort().map(name => `<option>${name}</option>`).join("")
80
+ const mutationOptions = Object.keys(mutationMultiplier).map(m => `<option>${m}</option>`).join("")
81
+ res.send(`
82
+ <!DOCTYPE html>
83
+ <html lang='en'>
84
+ <head>
85
+ <meta charset='UTF-8'>
86
+ <meta name='viewport' content='width=device-width, initial-scale=1.0'>
87
+ <title>Price Calculator</title>
88
+ <script src="https://cdn.tailwindcss.com"></script>
89
+ <style>
90
+ .fade-in { animation: fadeIn 0.6s ease-in-out; }
91
+ @keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
92
+ </style>
93
+ </head>
94
+ <body class="bg-gradient-to-br from-[#0f0f1a] to-[#0c1b2a] text-white flex items-center justify-center min-h-screen">
95
+ <form id="form" class="bg-[#1a1d2c] p-6 rounded-2xl shadow-xl w-full max-w-md space-y-4 fade-in">
96
+ <select name="fruit" required class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">
97
+ <option disabled selected>Select Fruit</option>${fruitOptions}
98
+ </select>
99
+ <input name="weight" type="number" step="0.01" placeholder="Weight (kg)" required class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">
100
+ <select name="rarity" class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">
101
+ <option>Normal</option><option>Gold</option><option>Rainbow</option>
102
+ </select>
103
+ <select name="mutations" multiple size="6" class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">${mutationOptions}</select>
104
+ <button type="submit" class="w-full bg-blue-500 hover:bg-blue-600 p-3 rounded font-bold transition-all">Calculate</button>
105
+ <div id="result" class="text-center text-blue-300 font-semibold"></div>
106
+ </form>
107
+ <script>
108
+ document.getElementById("form").onsubmit = async e => {
109
+ e.preventDefault()
110
+ const form = e.target
111
+ const data = new URLSearchParams()
112
+ const fruit = form.fruit.value
113
+ data.append("fruit", fruit)
114
+ data.append("weight", form.weight.value)
115
+ data.append("rarity", form.rarity.value)
116
+ let selected = Array.from(form.mutations.selectedOptions).map(o => o.value)
117
+
118
+ if (selected.includes("Frozen") || (selected.includes("Wet") && selected.includes("Chilled"))) {
119
+ selected = selected.filter(m => !["Wet", "Chilled"].includes(m))
120
+ if (!selected.includes("Frozen")) selected.push("Frozen")
121
+ }
122
+ if (selected.includes("Sundried") && selected.includes("Verdant")) {
123
+ selected = selected.filter(m => !["Sundried", "Verdant"].includes(m))
124
+ selected.push("Paradisal")
125
+ }
126
+ if (selected.includes("Cooked")) {
127
+ selected = selected.filter(m => m !== "Burnt")
128
+ }
129
+ if (selected.includes("Burnt")) {
130
+ selected = selected.filter(m => m !== "Cooked")
131
+ }
132
+
133
+ selected.forEach(m => data.append("mutations", m))
134
+
135
+ const res = await fetch("/calc", {
136
+ method: "POST",
137
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
138
+ body: data
139
+ })
140
+ const json = await res.json()
141
+ document.getElementById("result").innerHTML = \`
142
+ <p>Total: <span class='text-blue-400'>\${json.value}</span></p>
143
+ \${fruit === "\${fruits[2][0]}" ? \`<p class='text-sm text-zinc-400'>Base: \${json.base}</p>\` : ""}\`
144
+ }
145
+ </script>
146
+ </body>
147
+ </html>
148
+ `)
149
+ })
150
+
151
+ app.post("/calc", (req, res) => {
152
+ const { fruit, weight, rarity } = req.body
153
+ let mutations = req.body.mutations || []
154
+ if (!Array.isArray(mutations)) mutations = [mutations]
155
+ const result = calcValue(fruit, parseFloat(weight), rarity, mutations)
156
+ res.json(result)
157
+ })
158
+
159
+ app.listen(port)