User prompt
envanterdeki item konumlarının tamamını 8 pixel aşşağı taşı ve itemleri birbirlerinden biraz uzaklaştır
User prompt
alınabilen ve satılabilen yeni bir eşya modülü ekle.item adı sword texturesi sword. temel fiyatı 60 2000 adımda fiyatı %5 artabilir ya da azalabilir. yeni oran. %35 boş %25 apple modülü %15 salt modülü %15 speeditem modülü %10 sword modülü .
User prompt
alınabilen ve satılabilen yeni bir eşya modülü ekle temel fiyatı 20 2000 adımda fiyatı %5 artabilir ya da azalabilir. yeni oran. %45 boş %25 apple modülü %15 salt modülü %15 speeditem modülü. envanterimizdeki speeditem sayısı kadar %1 hızlı hareket ediyoruz. 5 tane carsa hızımız %105, 60 tane varsa hızımız %60 oluyor
User prompt
envanterimizdeki kapatma butonunu 30 pixel yukarı 30 pixel sağa al.envanterimizdeki itemlerin sayı textini itemlerin texturesinin önüne al ve boyutunu %60 artır
User prompt
envanterimizdeki kapatma butonunu 30 pixel yukarı 30 pixel sağa al
User prompt
sağ üste envanter açma butonu ekle bag texturesi ile . açılan ekrana playerinventory texturesini ekle ve bu texture a oyuncu envanter slotlarını koy. slotların konumunu detaylıca açıklarsak: 📐 Genel Yapı Görsel boyutu: 600x600 px Slot sayısı: 4 sütun x 4 satır = 16 slot Slotlar: Kare (genişlik = yükseklik) Slot aralarındaki çizgiler: İç gölgeli, net ayrımlı Slotların yerleşimi: Her biri eşit büyüklükte ve aralarında eşit boşluk var. 📏 Slot Boyutu ve Kenar Boşlukları Toplam slot sayısı: 4x4 = 16 slot Her slotun yaklaşık boyutu: Slot genişliği = Slot yüksekliği ≈ 120 px Aradaki çizgi kalınlıkları (slotlar arası boşluk): Yaklaşık 10 px Dış kenar boşlukları (çerçeveden ilk slot kutusuna kadar olan mesafe): Yaklaşık 30 px (üst, alt, sağ, sol eşit) 📊 Slot Pozisyonları (x, y, genişlik, yükseklik) Slotlar sol üstten başlayarak sırayla sağa doğru ilerler. Her slot 120x120 px’dir. Slotlar arası 10 px boşluk bırakılmıştır. İlk slot sol üstten 30 px içerdedir. Aşağıda ilk satırdaki 4 slotun pozisyonları örneklenmiştir: Slot No X (soldan) Y (üstten) Genişlik Yükseklik 1 30 30 120 120 2 160 30 120 120 3 290 30 120 120 4 420 30 120 120 Her sonraki satır için Y değeri 130 px artar (120 + 10). Aynı şekilde X değeri yatayda 130 px arayla ilerler. envanter eşya sayı miktarını minecraft mantığı ile göstericek eşyanın üzerinde sağ alt köşesinde. slot da eşyanın sayı sınırı yok ve eyşalarla etkileşime girilmeyecek satın alındığında eşya sıradaki boş slota ya da varsa aynı iteme steklenecek
User prompt
oyuncunun parasında da yuvarlama yap dediğim gibi
User prompt
paramızdaki 0.1 den yani tek ondalık basamaktan sonraki küsüratları yuvarla
User prompt
oyunun ortasına tıklandığında 10000 altın verecek bir buton ekle
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < sellSlots.length; i++) {' Line Number: 2162
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'if (currentMap < 0 || currentMap >= slotProbabilityPools.length || !slotProbabilityPools[currentMap]) {' Line Number: 2141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'if (currentMap < 0 || currentMap >= slotProbabilityPools.length || !slotProbabilityPools[currentMap]) {' Line Number: 2141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'if (currentMap < 0 || currentMap >= slotProbabilityPools.length || !slotProbabilityPools[currentMap]) {' Line Number: 2141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'if (currentMap < 0 || currentMap >= slotProbabilityPools.length || !slotProbabilityPools[currentMap]) {' Line Number: 2144
User prompt
market eşya yenileme sisteminde yürüme mesafesi olayını kaldır bölge değiştirdikçe buy ve sell envanterlerindeki eşyalar yenilensin
User prompt
şu anda sadece buy yani satın alma sistemini yaptık. şimdi aynı şekilde sell yani itemlerimizi satma sistemi kuralım. marketlere sell sistemi içinde envanter ekle satma modülleri oluştur. alma sistemi gibi satma sisteminde de module tikladığımızda eğer bizim envanterimizde o eşya varsa eşya satılır modul kaybolur ve paramız artar.sell modulleri envanterine de buy modulleri ile aynı şans sisteminde eşyalar koy. şehre girdiğimizde önce sellbuton ve buybuton texturleri ile mod seçme butonları gelsin. şehir envanteri yönetimini olası buglardan arındır
User prompt
şu anda sadece buy yani satın alma sistemini yaptık. şimdi aynı şekilde sell yani itemlerimizi satma sistemi kuralım. marketlere sell sistemi içinde envanter ekle satma modülleri oluştur. alma sistemi gibi satma sisteminde de module tikladığımızda eğer bizim envanterimizde o eşya varsa eşya satılır modul kaybolur ve paramız artar. markette sell buy modunu değiştirmek için market ekranında aşşağıya sellbuton ve buybuton texturleri ile butonları koy. başlangıçta buy modunda olduğundan aşşağıda sell butonu olmalı bastığımızda sell moduna geçiyoruz ve sell butonu yerine buy butonu geliyorr aynı yere
User prompt
envanter sistemini. slotlara modul oluşum sistemini. modül sistemini. alım modülü satım modülü ayrımını hangı modda hangi modullerin gözükeceğini ve envanter hafızasını bu yeni şehre girmeden önce alma ve satma modu seçme sistemine göre yeniden düzenle ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
buy ve sell butonları şehre girince çıksa karşımıza sonra ticaret ekranı açılsa
User prompt
sell modu için eşyalarımızı sattığımız modülleri daha iyi ayarla ve aynı buy modundaki gibi rasgele slota koyma sistemini 7-12 slotlarına yanı sell slotlarına ayarla modül mantığını iyi yap ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
geçici olarak market default modu sell modu olsun eşyalarımızı satalım
User prompt
olmadı sell butonuna bastığımızda eşyalar kayboluyor buy butonu gelmiyor
User prompt
olmadı şehirde 12 slotluk envanter var artık 6 slot buy modunda gözüküyor buy modu default. kalan 6 slot sell modunda gözüküyor . envanter hafıza altyapısını geliştir buy modunda sell butonu gözüksün sadece. tıklayıp sell moduna geçtiğimizde buy butonu göükmeli ve tıklayınca biri buy moduna geri döndürmeli ve tekrar sell butonu gelmeli ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
şu anda sadece buy yani satın alma sistemini yaptık. şimdi aynı şekilde sell yani itemlerimizi satma sistemi kuralım. marketlere sell sistemi içinde envanter ekle satma modülleri oluştur. alma sistemi gibi satma sisteminde de module tikladığımızda eğer bizim envanterimizde o eşya varsa eşya satılır modul kaybolur ve paramız artar. markette sell buy modunu değiştirmek için market ekranında aşşağıya sellbuton ve buybuton texturleri ile butonları koy. başlangıçta buy modunda olduğundan aşşağıda sell butonu olmalı bastığımızda sell moduna geçiyoruz ve sell butonu yerine buy butonu geliyorr aynı yere
User prompt
coin texturu ile fiyat sayısı arasındaki boşluğu 20 pixel daha arttır
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { playerInventory: { salt: 0, apple: 0, buySlot1: undefined, buySlot2: undefined, buySlot3: undefined, buySlot4: undefined, buySlot5: undefined, buySlot6: undefined, sellSlot7: undefined, sellSlot8: undefined, sellSlot9: undefined, sellSlot10: undefined, sellSlot11: undefined, sellSlot12: undefined }, playerGold: 100, currentMap: 0 }); /**** * Classes ****/ var CenterMarker = Container.expand(function () { var self = Container.call(this); var markerGraphics = self.attachAsset('centerMarker', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.isMoving = false; self.targetX = 0; self.targetY = 0; self.speed = 3; self.lastX = 0; // Track last X position for direction detection self.moveTo = function (x, y) { self.targetX = x; self.targetY = y; self.isMoving = true; }; self.update = function () { if (self.isMoving) { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < self.speed) { self.x = self.targetX; self.y = self.targetY; self.isMoving = false; } else { // Store current X before updating var currentX = self.x; self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; // Check direction change and flip character accordingly if (self.x > currentX) { // Moving right - face right (normal) characterGraphics.scale.x = Math.abs(characterGraphics.scale.x); } else if (self.x < currentX) { // Moving left - face left (flipped) characterGraphics.scale.x = -Math.abs(characterGraphics.scale.x); } } } }; return self; }); var City = Container.expand(function () { var self = Container.call(this); var cityGraphics = self.attachAsset('city', { anchorX: 0.5, anchorY: 0.5 }); cityGraphics.y = -60; // Move graphics up by 60 pixels return self; }); var Mountain = Container.expand(function () { var self = Container.call(this); var mountainGraphics = self.attachAsset('mountain', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Passage = Container.expand(function () { var self = Container.call(this); var passageGraphics = self.attachAsset('passage', { anchorX: 0.5, anchorY: 0.5 }); self.targetMap = 0; self.targetX = 0; self.targetY = 0; return self; }); var Road = Container.expand(function () { var self = Container.call(this); var roadGraphics = self.attachAsset('road', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var TradeSlot = Container.expand(function () { var self = Container.call(this); // Slot properties self.item = null; // 'salt', 'apple', or null for empty self.price = 0; self.slotIndex = 0; // Track which slot this is (1-6 for buy, 7-12 for sell) self.mode = 'buy'; // 'buy' or 'sell' // Create slot background (tradearea) var slotBg = self.attachAsset('tradearea', { anchorX: 0.5, anchorY: 0.5 }); // Item icon (initially invisible) var itemIcon = null; var coinIcon = null; // Item name text var itemNameText = new Text2('', { size: 38, fill: 0xFFFFFF }); itemNameText.anchor.set(0.5, 0.5); itemNameText.x = 0; itemNameText.y = 50; self.addChild(itemNameText); // Item price text var itemPriceText = new Text2('', { size: 40, fill: 0xFFD700 }); itemPriceText.anchor.set(0.5, 0.5); itemPriceText.x = 0; itemPriceText.y = 80; self.addChild(itemPriceText); // Method to set slot properties self.setSlotProperties = function (index, mode) { self.slotIndex = index; self.mode = mode; }; // Method to set item self.setItem = function (itemType) { // Clear existing item icon and coin icon if (itemIcon) { self.removeChild(itemIcon); itemIcon = null; } if (coinIcon) { self.removeChild(coinIcon); coinIcon = null; } self.item = itemType; if (itemType === 'salt') { itemIcon = LK.getAsset('salt', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); itemIcon.x = 0; itemIcon.y = -20; self.addChild(itemIcon); itemNameText.setText('Salt'); self.price = Math.round(saltCurrentPrice * 10) / 10; // Create coin icon and price display coinIcon = LK.getAsset('coin', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); coinIcon.x = -60; coinIcon.y = 80; self.addChild(coinIcon); itemPriceText.setText(self.price.toString()); itemPriceText.fill = 0xB8860B; // Darker gold color } else if (itemType === 'apple') { itemIcon = LK.getAsset('elma', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); itemIcon.x = 0; itemIcon.y = -20; self.addChild(itemIcon); itemNameText.setText('Apple'); self.price = Math.round(appleCurrentPrice * 10) / 10; // Create coin icon and price display coinIcon = LK.getAsset('coin', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); coinIcon.x = -60; coinIcon.y = 80; self.addChild(coinIcon); itemPriceText.setText(self.price.toString()); itemPriceText.fill = 0xB8860B; // Darker gold color } else { // Empty slot itemNameText.setText(''); itemPriceText.setText(''); self.price = 0; } }; // Handle slot click self.down = function (x, y, obj) { if (self.mode === 'sell') { // Sell mode - check if player has the item to sell if (self.item && playerInventory[self.item] > 0) { // Sell item playerInventory[self.item] -= 1; playerGold += self.price; updateGoldDisplay(); // Clear the slot from inventory var slotKey = 'sellSlot' + self.slotIndex; playerInventory[slotKey] = null; updateInventoryStorage(); // Flash effect on sale LK.effects.flashObject(self, 0x00FF00, 500); // Clear the slot after sale self.setItem(null); // Auto-reassign items to empty sell slots reassignSellSlots(); // Refresh market screen to show changes if (isMarketOpen) { closeMarketScreen(); createMarketScreen(); } } else if (self.item && playerInventory[self.item] <= 0) { // Don't have item to sell - flash red LK.effects.flashObject(self, 0xFF0000, 500); } } else { // Buy mode if (self.item && playerGold >= self.price) { // Purchase item playerGold -= self.price; playerInventory[self.item] += 1; // Auto-assign to a random sell slot assignItemToRandomSellSlot(self.item); updateGoldDisplay(); updateInventoryStorage(); // Flash effect on purchase LK.effects.flashObject(self, 0x00FF00, 500); // Clear the buy slot after purchase var buySlotKey = 'buySlot' + self.slotIndex; playerInventory[buySlotKey] = null; self.setItem(null); // Regenerate buy slots to get new random items generateBuySlots(); } else if (self.item && playerGold < self.price) { // Not enough gold - flash red LK.effects.flashObject(self, 0xFF0000, 500); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228b22 }); /**** * Game Code ****/ var currentMap = storage.currentMap || 0; var character = game.addChild(new Character()); var roads = []; var mountains = []; var passages = []; var centerMarker = null; var city = null; // Gold system variables var playerGold = storage.playerGold || 100; var goldIcon = null; var goldText = null; // Economy system variables - flattened for storage compatibility var saltBasePrice = 2000; var saltCurrentPrice = storage.saltCurrentPrice || 2000; var appleBasePrice = 10; var appleCurrentPrice = storage.appleCurrentPrice || 10; // Movement tracking for economy var lastPlayerX = 0; var lastPlayerY = 0; var totalMovementDistance = storage.totalMovementDistance || 0; var lastSaltPriceUpdate = storage.lastSaltPriceUpdate || 0; var lastApplePriceUpdate = storage.lastApplePriceUpdate || 0; // Map data - 12 interconnected maps var mapData = [ // Map 0 { roads: [{ x: 200, y: 400 }, { x: 300, y: 400 }, { x: 400, y: 400 }, { x: 500, y: 400 }, { x: 600, y: 400 }, { x: 700, y: 400 }, { x: 800, y: 500 }, { x: 900, y: 600 }, { x: 1000, y: 700 }, { x: 1100, y: 800 }, { x: 1200, y: 900 }, { x: 1300, y: 1000 }, { x: 1400, y: 1100 }, { x: 1500, y: 1200 }, { x: 1600, y: 1300 }, { x: 1700, y: 1400 }, { x: 1800, y: 1500 }, { x: 1900, y: 1500 }, { x: 2000, y: 1500 }, { x: 1800, y: 1600 }, { x: 1800, y: 1700 }, { x: 1800, y: 1800 }, { x: 1800, y: 1900 }, { x: 1800, y: 2000 }, { x: 1800, y: 2100 }, { x: 1800, y: 2200 }, { x: 1800, y: 2300 }, { x: 1800, y: 2400 }, { x: 1800, y: 2500 }, { x: 1800, y: 2600 }, { x: 1800, y: 2700 }], mountains: [{ x: 150, y: 200 }, { x: 250, y: 150 }, { x: 350, y: 180 }, { x: 450, y: 220 }, { x: 550, y: 180 }, { x: 650, y: 200 }, { x: 750, y: 250 }, { x: 850, y: 300 }, { x: 950, y: 350 }, { x: 1050, y: 400 }, { x: 1150, y: 450 }, { x: 1250, y: 500 }, { x: 1350, y: 550 }, { x: 1450, y: 600 }, { x: 1550, y: 650 }, { x: 1650, y: 700 }], passages: [{ x: 2000, y: 1500, targetMap: 1, targetX: 100, targetY: 1500 }, { x: 1800, y: 2700, targetMap: 3, targetX: 1800, targetY: 100 }], startX: 200, startY: 400 }, // Map 1 { roads: [{ x: 100, y: 1500 }, { x: 200, y: 1500 }, { x: 300, y: 1500 }, { x: 400, y: 1400 }, { x: 500, y: 1300 }, { x: 600, y: 1200 }, { x: 700, y: 1100 }, { x: 800, y: 1000 }, { x: 900, y: 900 }, { x: 1000, y: 800 }, { x: 1100, y: 700 }, { x: 1200, y: 600 }, { x: 1300, y: 500 }, { x: 1400, y: 400 }, { x: 1500, y: 300 }, { x: 1600, y: 200 }, { x: 48, y: 1500 }, { x: 1600, y: 150 }, { x: 1600, y: 100 }, { x: 1600, y: 48 }], mountains: [{ x: 200, y: 1700 }, { x: 300, y: 1800 }, { x: 400, y: 1700 }, { x: 500, y: 1600 }, { x: 600, y: 1500 }, { x: 700, y: 1400 }, { x: 800, y: 1300 }, { x: 900, y: 1200 }, { x: 1000, y: 1100 }, { x: 1100, y: 1000 }, { x: 1200, y: 900 }, { x: 1300, y: 800 }], passages: [{ x: 100, y: 1500, targetMap: 0, targetX: 2000, targetY: 1500 }, { x: 1600, y: 100, targetMap: 2, targetX: 1600, targetY: 2700 }], startX: 100, startY: 1500 }, // Map 2 { roads: [{ x: 1600, y: 2700 }, { x: 1600, y: 2600 }, { x: 1600, y: 2500 }, { x: 1600, y: 2400 }, { x: 1600, y: 2300 }, { x: 1600, y: 2200 }, { x: 1600, y: 2100 }, { x: 1600, y: 2000 }, { x: 1600, y: 1900 }, { x: 1600, y: 1800 }, { x: 1600, y: 1700 }, { x: 1600, y: 1600 }, { x: 1600, y: 1500 }, { x: 1600, y: 1400 }, { x: 1600, y: 1300 }, { x: 1600, y: 1200 }], mountains: [{ x: 1400, y: 2600 }, { x: 1500, y: 2500 }, { x: 1700, y: 2500 }, { x: 1800, y: 2600 }, { x: 1400, y: 2400 }, { x: 1800, y: 2400 }, { x: 1400, y: 2200 }, { x: 1800, y: 2200 }, { x: 1400, y: 2000 }, { x: 1800, y: 2000 }, { x: 1400, y: 1800 }, { x: 1800, y: 1800 }], passages: [{ x: 1600, y: 2700, targetMap: 1, targetX: 1600, targetY: 100 }, { x: 1600, y: 1200, targetMap: 4, targetX: 1600, targetY: 2350 }], startX: 1600, startY: 2700 }, // Map 3 { roads: [{ x: 1800, y: 100 }, { x: 1700, y: 200 }, { x: 1600, y: 300 }, { x: 1500, y: 400 }, { x: 1400, y: 500 }, { x: 1300, y: 600 }, { x: 1200, y: 700 }, { x: 1100, y: 800 }, { x: 1000, y: 900 }, { x: 900, y: 1000 }, { x: 800, y: 1100 }, { x: 700, y: 1200 }, { x: 600, y: 1300 }, { x: 500, y: 1400 }, { x: 400, y: 1500 }, { x: 300, y: 1600 }, { x: 1800, y: 48 }, { x: 250, y: 1600 }, { x: 200, y: 1600 }], mountains: [{ x: 1900, y: 200 }, { x: 1800, y: 300 }, { x: 1700, y: 400 }, { x: 1600, y: 500 }, { x: 1500, y: 600 }, { x: 1400, y: 700 }, { x: 1300, y: 800 }, { x: 1200, y: 900 }, { x: 1100, y: 1000 }, { x: 1000, y: 1100 }, { x: 900, y: 1200 }, { x: 800, y: 1300 }], passages: [{ x: 1800, y: 100, targetMap: 0, targetX: 1800, targetY: 2700 }, { x: 200, y: 1600, targetMap: 5, targetX: 1900, targetY: 1600 }], startX: 1800, startY: 100 }, // Map 4 { roads: [{ x: 1600, y: 2350 }, { x: 1500, y: 2250 }, { x: 1400, y: 2150 }, { x: 1300, y: 2050 }, { x: 1200, y: 1950 }, { x: 1100, y: 1850 }, { x: 1000, y: 1750 }, { x: 900, y: 1650 }, { x: 800, y: 1550 }, { x: 700, y: 1450 }, { x: 600, y: 1350 }, { x: 500, y: 1250 }], mountains: [{ x: 1700, y: 2700 }, { x: 1600, y: 2800 }, { x: 1500, y: 2700 }, { x: 1400, y: 2600 }, { x: 1300, y: 2500 }, { x: 1200, y: 2400 }, { x: 1100, y: 2300 }, { x: 1000, y: 2200 }], passages: [{ x: 1600, y: 2350, targetMap: 2, targetX: 1600, targetY: 1200 }, { x: 500, y: 1250, targetMap: 6, targetX: 1800, targetY: 1500 }], startX: 1600, startY: 2350 }, // Map 5 { roads: [{ x: 1900, y: 1600 }, { x: 1800, y: 1600 }, { x: 1700, y: 1600 }, { x: 1600, y: 1600 }, { x: 1500, y: 1600 }, { x: 1400, y: 1600 }, { x: 1300, y: 1600 }, { x: 1200, y: 1600 }, { x: 1100, y: 1600 }, { x: 1000, y: 1600 }, { x: 900, y: 1600 }, { x: 800, y: 1600 }, { x: 750, y: 1600 }, { x: 700, y: 1600 }, { x: 1950, y: 1600 }, { x: 2000, y: 1600 }], mountains: [{ x: 1900, y: 1400 }, { x: 1800, y: 1400 }, { x: 1900, y: 1800 }, { x: 1800, y: 1800 }, { x: 1700, y: 1400 }, { x: 1600, y: 1400 }, { x: 1700, y: 1800 }, { x: 1600, y: 1800 }], passages: [{ x: 2000, y: 1600, targetMap: 3, targetX: 200, targetY: 1600 }, { x: 700, y: 1600, targetMap: 7, targetX: 1400, targetY: 1600 }], startX: 1900, startY: 1600 }, // Map 6 { roads: [{ x: 1800, y: 1500 }, { x: 1700, y: 1400 }, { x: 1600, y: 1300 }, { x: 1500, y: 1200 }, { x: 1400, y: 1100 }, { x: 1300, y: 1000 }, { x: 1200, y: 900 }, { x: 1100, y: 800 }, { x: 1000, y: 700 }, { x: 900, y: 600 }, { x: 800, y: 500 }, { x: 700, y: 400 }, { x: 1850, y: 1500 }, { x: 1900, y: 1500 }, { x: 1950, y: 1500 }, { x: 2000, y: 1500 }, { x: 650, y: 400 }, { x: 600, y: 400 }], mountains: [{ x: 1900, y: 1600 }, { x: 1800, y: 1700 }, { x: 1700, y: 1600 }, { x: 1600, y: 1500 }, { x: 1500, y: 1400 }, { x: 1400, y: 1300 }, { x: 1300, y: 1200 }, { x: 1200, y: 1100 }], passages: [{ x: 2000, y: 1500, targetMap: 4, targetX: 500, targetY: 1250 }, { x: 600, y: 400, targetMap: 8, targetX: 1500, targetY: 2300 }], startX: 1800, startY: 1500 }, // Map 7 { roads: [{ x: 1400, y: 1600 }, { x: 1300, y: 1500 }, { x: 1200, y: 1400 }, { x: 1100, y: 1300 }, { x: 1000, y: 1200 }, { x: 900, y: 1100 }, { x: 800, y: 1000 }, { x: 700, y: 900 }, { x: 600, y: 800 }, { x: 500, y: 700 }, { x: 400, y: 600 }, { x: 300, y: 500 }, { x: 1450, y: 1600 }, { x: 1500, y: 1600 }, { x: 250, y: 500 }, { x: 200, y: 500 }], mountains: [{ x: 1500, y: 1700 }, { x: 1400, y: 1800 }, { x: 1300, y: 1700 }, { x: 1200, y: 1600 }, { x: 1100, y: 1500 }, { x: 1000, y: 1400 }, { x: 900, y: 1300 }, { x: 800, y: 1200 }], passages: [{ x: 1500, y: 1600, targetMap: 5, targetX: 700, targetY: 1600 }, { x: 200, y: 500, targetMap: 9, targetX: 1800, targetY: 500 }], startX: 1400, startY: 1600 }, // Map 8 { roads: [{ x: 1500, y: 2300 }, { x: 1400, y: 2200 }, { x: 1300, y: 2100 }, { x: 1200, y: 2000 }, { x: 1100, y: 1900 }, { x: 1000, y: 1800 }, { x: 900, y: 1700 }, { x: 800, y: 1600 }, { x: 700, y: 1500 }, { x: 600, y: 1400 }, { x: 500, y: 1300 }, { x: 400, y: 1200 }, { x: 1500, y: 2400 }, { x: 1500, y: 2500 }, { x: 1500, y: 2600 }, { x: 1500, y: 2700 }, { x: 1500, y: 2732 }, { x: 350, y: 1200 }, { x: 300, y: 1200 }], mountains: [{ x: 1600, y: 2400 }, { x: 1500, y: 2500 }, { x: 1400, y: 2400 }, { x: 1300, y: 2300 }, { x: 1200, y: 2200 }, { x: 1100, y: 2100 }, { x: 1000, y: 2000 }, { x: 900, y: 1900 }], passages: [{ x: 1500, y: 2700, targetMap: 6, targetX: 600, targetY: 400 }, { x: 300, y: 1200, targetMap: 10, targetX: 1700, targetY: 1200 }], startX: 1500, startY: 2300 }, // Map 9 { roads: [{ x: 1800, y: 500 }, { x: 1700, y: 600 }, { x: 1600, y: 700 }, { x: 1500, y: 800 }, { x: 1400, y: 900 }, { x: 1300, y: 1000 }, { x: 1200, y: 1100 }, { x: 1100, y: 1200 }, { x: 1000, y: 1300 }, { x: 900, y: 1400 }, { x: 800, y: 1500 }, { x: 700, y: 1600 }, { x: 1850, y: 500 }, { x: 1900, y: 500 }, { x: 1950, y: 500 }, { x: 2000, y: 500 }, { x: 900, y: 1300 }, { x: 800, y: 1300 }, { x: 700, y: 1300 }, { x: 600, y: 1300 }, { x: 550, y: 1300 }, { x: 500, y: 1300 }], mountains: [{ x: 1900, y: 400 }, { x: 1800, y: 300 }, { x: 1700, y: 400 }, { x: 1600, y: 500 }, { x: 1500, y: 600 }, { x: 1400, y: 700 }, { x: 1300, y: 800 }, { x: 1200, y: 900 }], passages: [{ x: 2000, y: 500, targetMap: 7, targetX: 200, targetY: 500 }, { x: 500, y: 1300, targetMap: 11, targetX: 1500, targetY: 800 }], startX: 1800, startY: 500 }, // Map 10 { roads: [{ x: 1700, y: 1200 }, { x: 1600, y: 1100 }, { x: 1500, y: 1000 }, { x: 1400, y: 900 }, { x: 1300, y: 800 }, { x: 1200, y: 700 }, { x: 1100, y: 600 }, { x: 1000, y: 500 }, { x: 900, y: 400 }, { x: 800, y: 300 }, { x: 700, y: 200 }, { x: 600, y: 100 }, { x: 1750, y: 1200 }, { x: 1800, y: 1200 }, { x: 600, y: 75 }, { x: 600, y: 48 }], mountains: [{ x: 1800, y: 1300 }, { x: 1700, y: 1400 }, { x: 1600, y: 1300 }, { x: 1500, y: 1200 }, { x: 1400, y: 1100 }, { x: 1300, y: 1000 }, { x: 1200, y: 900 }, { x: 1100, y: 800 }], passages: [{ x: 1795, y: 1260, targetMap: 8, targetX: 300, targetY: 1200 }, { x: 600, y: 100, targetMap: 11, targetX: 600, targetY: 2700 }], startX: 1700, startY: 1200 }, // Map 11 { roads: [{ x: 1500, y: 800 }, { x: 1400, y: 900 }, { x: 1300, y: 1000 }, { x: 1200, y: 1100 }, { x: 1100, y: 1200 }, { x: 1000, y: 1300 }, { x: 900, y: 1400 }, { x: 800, y: 1500 }, { x: 700, y: 1600 }, { x: 600, y: 1700 }, { x: 600, y: 1800 }, { x: 600, y: 1900 }, { x: 600, y: 2000 }, { x: 600, y: 2100 }, { x: 600, y: 2200 }, { x: 600, y: 2300 }, { x: 600, y: 2400 }, { x: 600, y: 2500 }, { x: 600, y: 2600 }, { x: 1500, y: 750 }, { x: 1500, y: 700 }, { x: 600, y: 2650 }, { x: 600, y: 2700 }, { x: 600, y: 2732 }], mountains: [{ x: 1600, y: 700 }, { x: 1500, y: 600 }, { x: 1400, y: 700 }, { x: 1300, y: 800 }, { x: 1200, y: 900 }, { x: 1100, y: 1000 }, { x: 1000, y: 1100 }, { x: 900, y: 1200 }, { x: 500, y: 1700 }, { x: 700, y: 1700 }, { x: 500, y: 1900 }, { x: 700, y: 1900 }], passages: [{ x: 1500, y: 700, targetMap: 9, targetX: 600, targetY: 1600 }, { x: 600, y: 2700, targetMap: 10, targetX: 600, targetY: 100 }], startX: 1500, startY: 800 }]; var arBackground = null; function loadMap(mapIndex) { // Clear existing elements for (var i = 0; i < roads.length; i++) { roads[i].destroy(); } // Mountain cleanup removed for (var i = 0; i < passages.length; i++) { passages[i].destroy(); } // Clean up existing center marker if (centerMarker) { centerMarker.destroy(); centerMarker = null; } // Clean up existing city marker if (city) { city.destroy(); city = null; } // Clean up existing AR background if (arBackground) { arBackground.destroy(); arBackground = null; } roads = []; mountains = []; passages = []; var map = mapData[mapIndex]; // Add AR background only for Ancient Ruins (map 6) if (mapIndex === 6) { arBackground = game.addChild(LK.getAsset('AR', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1, x: 1024, y: 1366 })); } // Add CP background only for Central Plains (map 4) if (mapIndex === 4) { arBackground = game.addChild(LK.getAsset('CP', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2, x: 1024, y: 1366 })); } // Add SR background only for Southern Ridge (map 2) if (mapIndex === 2) { arBackground = game.addChild(LK.getAsset('Sr', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2, x: 1024, y: 1366 })); } // Add EV background only for Eastern Valleys (map 1) if (mapIndex === 1) { arBackground = game.addChild(LK.getAsset('Ev', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 7, x: 1024, y: 1366 })); } // Add NH background only for Northern Highlands (map 0) if (mapIndex === 0) { arBackground = game.addChild(LK.getAsset('Nh', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 7, x: 1024, y: 1366 })); } // Add WP background only for Western Peaks (map 3) if (mapIndex === 3) { arBackground = game.addChild(LK.getAsset('wp', { anchorX: 0.5, anchorY: 0.5, scaleX: 7, scaleY: 9, x: 1024, y: 1366 })); } // Add MW background only for Mystic Woods (map 5) if (mapIndex === 5) { arBackground = game.addChild(LK.getAsset('mw', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 7, x: 1024, y: 1366 })); } // Add DS background only for Desert Sands (map 7) if (mapIndex === 7) { arBackground = game.addChild(LK.getAsset('ds', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 7, x: 1024, y: 1366 })); } // Add CC background only for Coastal Cliffs (map 9) if (mapIndex === 9) { arBackground = game.addChild(LK.getAsset('cc', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 5, x: 1024, y: 1366 })); } // Add SG background only for Sacred Grove (map 11) if (mapIndex === 11) { arBackground = game.addChild(LK.getAsset('sg', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 7, x: 1024, y: 1366 })); } // Add MP background only for Mountain Pass (map 10) if (mapIndex === 10) { arBackground = game.addChild(LK.getAsset('mp', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 5, x: 1024, y: 1366 })); } // Add FW background only for Frozen Wastes (map 8) if (mapIndex === 8) { arBackground = game.addChild(LK.getAsset('fw', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 5, x: 1024, y: 1366 })); } // Create roads for (var i = 0; i < map.roads.length; i++) { var road = game.addChild(new Road()); road.x = map.roads[i].x; road.y = map.roads[i].y; roads.push(road); } // Mountains removed from display // Create passages for (var i = 0; i < map.passages.length; i++) { var passage = game.addChild(new Passage()); passage.x = map.passages[i].x; passage.y = map.passages[i].y; passage.targetMap = map.passages[i].targetMap; passage.targetX = map.passages[i].targetX; passage.targetY = map.passages[i].targetY; passages.push(passage); } // Set character position if (character.x === 0 && character.y === 0) { character.x = map.startX; character.y = map.startY; } // Find and mark the center road point var centerRoad = findCenterRoad(); if (centerRoad) { centerMarker = game.addChild(new CenterMarker()); centerMarker.x = centerRoad.x; centerMarker.y = centerRoad.y; } // Add city marker at calculated position var cityPosition = findCityPosition(); city = game.addChild(new City()); city.x = cityPosition.x; city.y = cityPosition.y; // Create connecting road between center marker and city if (centerMarker && city) { var connectionRoads = createConnectionRoad(centerMarker.x, centerMarker.y, city.x, city.y); for (var i = 0; i < connectionRoads.length; i++) { roads.push(connectionRoads[i]); } } // Bring city to front so it appears above roads if (city) { game.removeChild(city); game.addChild(city); } // Bring character to front so it appears above roads game.removeChild(character); game.addChild(character); // Reset city visit tracking for new map hasVisitedCity = false; lastCityDistance = Infinity; if (isCityMenuOpen) { closeCityMenu(); } if (isMarketOpen) { closeMarketScreen(); } // Generate new market slots for this map if (!marketSlots) { marketSlots = []; } } function findNearestRoad(x, y) { var nearestRoad = null; var minDistance = Infinity; for (var i = 0; i < roads.length; i++) { var road = roads[i]; var dx = x - road.x; var dy = y - road.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < minDistance) { minDistance = distance; nearestRoad = road; } } return nearestRoad; } function findCityPosition() { var centerX = 1024; // Screen center X var centerY = 1366; // Screen center Y var mirrorPoints = []; var map = mapData[currentMap]; // Calculate mirror coordinates for each passage for (var i = 0; i < map.passages.length; i++) { var passage = map.passages[i]; var mirrorX = 2 * centerX - passage.x; var mirrorY = 2 * centerY - passage.y; mirrorPoints.push({ x: mirrorX, y: mirrorY }); } // Find the center of all mirror points if (mirrorPoints.length === 0) { return { x: centerX, y: centerY }; // Default to screen center if no passages } var totalX = 0; var totalY = 0; for (var i = 0; i < mirrorPoints.length; i++) { totalX += mirrorPoints[i].x; totalY += mirrorPoints[i].y; } return { x: totalX / mirrorPoints.length, y: totalY / mirrorPoints.length }; } function createConnectionRoad(startX, startY, endX, endY) { var connectionRoads = []; var dx = endX - startX; var dy = endY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var steps = Math.floor(distance / 100); // Create road points every 100 pixels for (var i = 1; i <= steps; i++) { var progress = i / (steps + 1); var roadX = startX + dx * progress; var roadY = startY + dy * progress; var road = game.addChild(new Road()); road.x = roadX; road.y = roadY; connectionRoads.push(road); } return connectionRoads; } function findCenterRoad() { var centerX = 1024; // Screen center X var centerY = 1366; // Screen center Y var centerRoad = null; var minDistance = Infinity; for (var i = 0; i < roads.length; i++) { var road = roads[i]; var dx = centerX - road.x; var dy = centerY - road.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < minDistance) { minDistance = distance; centerRoad = road; } } return centerRoad; } function checkPassageCollision() { for (var i = 0; i < passages.length; i++) { var passage = passages[i]; var dx = character.x - passage.x; var dy = character.y - passage.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 80) { currentMap = passage.targetMap; storage.currentMap = currentMap; loadMap(currentMap); // Find the 4th nearest road point to the target passage var targetPassageX = passage.targetX; var targetPassageY = passage.targetY; var roadDistances = []; // Calculate distances from target passage to all roads for (var j = 0; j < roads.length; j++) { var road = roads[j]; var rdx = targetPassageX - road.x; var rdy = targetPassageY - road.y; var roadDistance = Math.sqrt(rdx * rdx + rdy * rdy); roadDistances.push({ road: road, distance: roadDistance }); } // Sort roads by distance roadDistances.sort(function (a, b) { return a.distance - b.distance; }); // Get the 4th nearest road (index 3), or closest available if less than 4 roads var targetRoadIndex = Math.min(3, roadDistances.length - 1); // Special case for Western Peaks left passage teleportation - use 5th nearest road for better positioning if (currentMap === 5 && passage.targetX === 1900 && passage.targetY === 1600) { targetRoadIndex = Math.min(4, roadDistances.length - 1); } // Special case for Sacred Grove to Coastal Cliffs teleportation - use 3rd nearest road if (currentMap === 9 && passage.targetX === 600 && passage.targetY === 1600) { targetRoadIndex = Math.min(2, roadDistances.length - 1); } var targetRoad = roadDistances[targetRoadIndex].road; character.x = targetRoad.x; character.y = targetRoad.y; character.isMoving = false; break; } } } // Initialize first map loadMap(currentMap); // Bring character to front so it appears above roads game.removeChild(character); game.addChild(character); // Initialize economy system tracking lastPlayerX = character.x; lastPlayerY = character.y; // Initialize market slots array to prevent undefined errors var marketSlots = []; // Region names for each map var regionNames = ['Northern Highlands', 'Eastern Valleys', 'Southern Ridge', 'Western Peaks', 'Central Plains', 'Mystic Woods', 'Ancient Ruins', 'Desert Sands', 'Frozen Wastes', 'Coastal Cliffs', 'Mountain Pass', 'Sacred Grove']; // Slot probability pools for each city var slotProbabilityPools = [ // Map 0 - Northern Highlands [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // 60% empty, 25% apple, 15% salt // Map 1 - Eastern Valleys [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 2 - Southern Ridge [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 3 - Western Peaks [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 4 - Central Plains [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 5 - Mystic Woods [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 6 - Ancient Ruins [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 7 - Desert Sands [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 8 - Frozen Wastes [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 9 - Coastal Cliffs [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 10 - Mountain Pass [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt'], // Map 11 - Sacred Grove [null, null, null, null, null, null, 'apple', 'apple', 'apple', 'salt']]; // Map info display var mapText = new Text2(regionNames[currentMap], { size: 60, fill: 0xFFFFFF }); mapText.anchor.set(1, 1); LK.gui.bottomRight.addChild(mapText); // Gold display setup goldIcon = LK.getAsset('gold', { anchorX: 0, anchorY: 0, scaleX: 1.6, scaleY: 1.6 }); goldIcon.x = 120; goldIcon.y = 20; LK.gui.topLeft.addChild(goldIcon); goldText = new Text2(playerGold.toString(), { size: 96, fill: 0xFFD700 }); goldText.anchor.set(0, 0); goldText.x = 280; goldText.y = 50; LK.gui.topLeft.addChild(goldText); // City market UI variables var marketScreen = null; var marketTitle = null; var closeButton = null; var isMarketOpen = false; var lastCityDistance = Infinity; var hasVisitedCity = false; // Market mode variables var isSellMode = false; var sellButton = null; var buyButton = null; // City menu UI variables var cityMenuScreen = null; var isCityMenuOpen = false; // Enhanced player inventory with proper separation of buy/sell systems var playerInventory = storage.playerInventory; // Market slot system variables var lastSlotRefreshDistance = storage.lastSlotRefreshDistance || 0; // Generate initial market slots after everything is initialized generateMarketSlots(); function generateMarketSlots() { // Clear existing slots for (var i = 0; i < marketSlots.length; i++) { if (marketSlots[i] && marketSlots[i].parent) { marketSlots[i].parent.removeChild(marketSlots[i]); } } marketSlots = []; // Generate slots based on current mode if (isSellMode) { generateSellSlots(); } else { generateBuySlots(); } } function generateBuySlots() { // Safety check for currentMap and slotProbabilityPools if (currentMap < 0 || currentMap >= slotProbabilityPools.length || !slotProbabilityPools[currentMap]) { return; } // Get probability pool for current map var probabilityPool = slotProbabilityPools[currentMap]; // Generate 6 slots for buy mode (buySlot1-6) for (var i = 1; i <= 6; i++) { var slot = new TradeSlot(); slot.setSlotProperties(i, 'buy'); // Check if slot already has an item from storage var buySlotKey = 'buySlot' + i; var existingItem = playerInventory[buySlotKey]; if (existingItem) { slot.setItem(existingItem); } else { // Generate new random item var randomIndex = Math.floor(Math.random() * probabilityPool.length); var itemType = probabilityPool[randomIndex]; playerInventory[buySlotKey] = itemType; slot.setItem(itemType); } marketSlots.push(slot); } updateInventoryStorage(); } function refreshMarketSlots() { // Safety check for marketSlots array if (!marketSlots) { marketSlots = []; generateMarketSlots(); return; } // Additional safety check for marketSlots length if (marketSlots.length === 0) { generateMarketSlots(); return; } // Safety check for currentMap and slotProbabilityPools if (currentMap < 0 || currentMap >= slotProbabilityPools.length || !slotProbabilityPools[currentMap]) { return; } // 10% chance to refresh each slot var probabilityPool = slotProbabilityPools[currentMap]; for (var i = 0; i < marketSlots.length; i++) { if (Math.random() < 0.1) { var randomIndex = Math.floor(Math.random() * probabilityPool.length); var itemType = probabilityPool[randomIndex]; marketSlots[i].setItem(itemType); } } } function createCityMenu() { // Create city menu background container cityMenuScreen = new Container(); cityMenuScreen.x = 0; cityMenuScreen.y = 0; // Create semi-transparent background var menuBg = LK.getAsset('citytrade', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.8 }); menuBg.x = 24; menuBg.y = -34; menuBg.alpha = 0.9; cityMenuScreen.addChild(menuBg); // Create welcome title var welcomeTitle = new Text2('Welcome to ' + regionNames[currentMap], { size: 60, fill: 0xFFFFFF }); welcomeTitle.anchor.set(0.5, 0.5); welcomeTitle.x = 24; welcomeTitle.y = -200; cityMenuScreen.addChild(welcomeTitle); // Create buy button var cityBuyButton = LK.getAsset('buybuton', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, scaleY: 4 }); cityBuyButton.x = -100; cityBuyButton.y = 0; cityMenuScreen.addChild(cityBuyButton); cityBuyButton.down = function () { // Close city menu and open market in buy mode closeCityMenu(); isSellMode = false; createMarketScreen(); }; // Create sell button var citySellButton = LK.getAsset('sellbuton', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, scaleY: 4 }); citySellButton.x = 150; citySellButton.y = 0; cityMenuScreen.addChild(citySellButton); citySellButton.down = function () { // Close city menu and open market in sell mode closeCityMenu(); isSellMode = true; createMarketScreen(); }; // Create close button var cityCloseButton = LK.getAsset('xbutton', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); cityCloseButton.x = 400; cityCloseButton.y = -300; cityMenuScreen.addChild(cityCloseButton); cityCloseButton.down = function () { closeCityMenu(); }; LK.gui.center.addChild(cityMenuScreen); isCityMenuOpen = true; } function closeCityMenu() { if (cityMenuScreen) { LK.gui.center.removeChild(cityMenuScreen); cityMenuScreen = null; isCityMenuOpen = false; } } function createMarketScreen() { // Create market background container marketScreen = new Container(); marketScreen.x = 0; marketScreen.y = 0; // Create market background using citytrade texture var marketBg = LK.getAsset('citytrade', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); marketBg.x = 24; marketBg.y = -34; marketScreen.addChild(marketBg); // Generate market slots if they don't exist if (marketSlots.length === 0) { generateMarketSlots(); } // Position and add slots to market screen (2 rows, 3 columns) var slotStartX = -190; var slotStartY = -180; var slotSpacingX = 220; var slotSpacingY = 210; for (var i = 0; i < marketSlots.length; i++) { var slot = marketSlots[i]; var row = Math.floor(i / 3); var col = i % 3; slot.x = slotStartX + col * slotSpacingX; slot.y = slotStartY + row * slotSpacingY; // Move top 3 slots (first row) 70 pixels up if (row === 0) { slot.y -= 70; } marketScreen.addChild(slot); } // Create market title marketTitle = new Text2(regionNames[currentMap] + ' Market', { size: 77, fill: 0xFFFFFF }); marketTitle.anchor.set(0.5, 0); marketTitle.x = 24; marketTitle.y = -490; marketScreen.addChild(marketTitle); // Create close button using xbutton texture closeButton = LK.getAsset('xbutton', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); closeButton.x = 556; closeButton.y = -680; marketScreen.addChild(closeButton); // Add close button functionality closeButton.down = function () { closeMarketScreen(); }; // Create sell/buy mode toggle buttons - only show sell button in buy mode if (!isSellMode) { // Show sell button when in buy mode (default) sellButton = LK.getAsset('sellbuton', { anchorX: 0.5, anchorY: 0.5, scaleX: 3, scaleY: 3 }); sellButton.x = 0; sellButton.y = 320; marketScreen.addChild(sellButton); sellButton.down = function () { // Switch to sell mode isSellMode = true; // Close current screen first closeMarketScreen(); // Create new market screen with sell mode createMarketScreen(); }; } else { // Show buy button when in sell mode buyButton = LK.getAsset('buybuton', { anchorX: 0.5, anchorY: 0.5, scaleX: 3, scaleY: 3 }); buyButton.x = 0; buyButton.y = 320; marketScreen.addChild(buyButton); buyButton.down = function () { // Switch to buy mode isSellMode = false; // Close current screen first closeMarketScreen(); // Create new market screen with buy mode createMarketScreen(); }; } LK.gui.center.addChild(marketScreen); isMarketOpen = true; } function closeMarketScreen() { if (marketScreen) { LK.gui.center.removeChild(marketScreen); marketScreen = null; marketTitle = null; closeButton = null; sellButton = null; buyButton = null; isMarketOpen = false; // Keep current mode when closing market } } function checkCityProximity() { if (!city) { return; } var dx = character.x - city.x; var dy = character.y - city.y; var currentDistance = Math.sqrt(dx * dx + dy * dy); // Check if entering city range (distance < 100) if (lastCityDistance >= 100 && currentDistance < 100) { // Just entered city - show city menu if not already visited if (!hasVisitedCity && !isCityMenuOpen && !isMarketOpen) { createCityMenu(); hasVisitedCity = true; } } // Check if leaving city range (distance > 150) if (lastCityDistance <= 150 && currentDistance > 150) { // Left city area - reset visit flag for next entry hasVisitedCity = false; if (isCityMenuOpen) { closeCityMenu(); } if (isMarketOpen) { closeMarketScreen(); } } lastCityDistance = currentDistance; } game.down = function (x, y, obj) { // Prevent movement when market or city menu is open if (isMarketOpen || isCityMenuOpen) { return; } var nearestRoad = findNearestRoad(x, y); if (nearestRoad) { character.moveTo(nearestRoad.x, nearestRoad.y); } }; function updateGoldDisplay() { if (goldText) { goldText.setText(playerGold.toString()); storage.playerGold = playerGold; } } function updateInventoryStorage() { storage.playerInventory = playerInventory; } function assignItemToRandomSellSlot(itemType) { // Find available sell slots (7-12) var availableSlots = []; for (var i = 7; i <= 12; i++) { var slotKey = 'sellSlot' + i; if (!playerInventory[slotKey]) { availableSlots.push(slotKey); } } // If there are available slots, assign to random one if (availableSlots.length > 0) { var randomIndex = Math.floor(Math.random() * availableSlots.length); var selectedSlot = availableSlots[randomIndex]; playerInventory[selectedSlot] = itemType; updateInventoryStorage(); return true; } return false; // No available slots } function reassignSellSlots() { // Clear all sell slots first for (var i = 7; i <= 12; i++) { var slotKey = 'sellSlot' + i; playerInventory[slotKey] = null; } // Reassign items from general inventory to sell slots randomly var itemsToAssign = []; // Add salt items to assignment list for (var s = 0; s < playerInventory.salt; s++) { itemsToAssign.push('salt'); } // Add apple items to assignment list for (var a = 0; a < playerInventory.apple; a++) { itemsToAssign.push('apple'); } // Randomly assign items to sell slots (max 6 items) var maxAssignments = Math.min(itemsToAssign.length, 6); for (var assign = 0; assign < maxAssignments; assign++) { var randomItemIndex = Math.floor(Math.random() * itemsToAssign.length); var selectedItem = itemsToAssign[randomItemIndex]; itemsToAssign.splice(randomItemIndex, 1); // Remove from list // Find empty sell slot for (var slot = 7; slot <= 12; slot++) { var sellSlotKey = 'sellSlot' + slot; if (!playerInventory[sellSlotKey]) { playerInventory[sellSlotKey] = selectedItem; break; } } } updateInventoryStorage(); } function generateSellSlots() { // Auto-populate sell slots with available inventory before displaying reassignSellSlots(); // Generate 6 slots for sell mode (sellSlot7-12 from inventory) for (var i = 7; i <= 12; i++) { var slot = new TradeSlot(); slot.setSlotProperties(i, 'sell'); var sellSlotKey = 'sellSlot' + i; var itemType = playerInventory[sellSlotKey]; // Show items from inventory if they exist and player has them in general inventory if (itemType && playerInventory[itemType] > 0) { slot.setItem(itemType); } else { slot.setItem(null); // Clear the slot if item no longer available playerInventory[sellSlotKey] = null; } marketSlots.push(slot); } updateInventoryStorage(); } function updateEconomySystem() { // Track movement distance var dx = character.x - lastPlayerX; var dy = character.y - lastPlayerY; var movementThisFrame = Math.sqrt(dx * dx + dy * dy); if (movementThisFrame > 0) { totalMovementDistance += movementThisFrame; // Salt price update every 5000 pixels var saltDistanceThreshold = lastSaltPriceUpdate + 5000; if (totalMovementDistance >= saltDistanceThreshold) { // 50% chance for price change if (Math.random() < 0.5) { // 50% chance for increase (7%) or decrease (6%) if (Math.random() < 0.5) { saltCurrentPrice *= 1.07; // 7% increase } else { saltCurrentPrice *= 0.94; // 6% decrease } } lastSaltPriceUpdate = totalMovementDistance; } // Apple price update every 500 pixels var appleDistanceThreshold = lastApplePriceUpdate + 500; if (totalMovementDistance >= appleDistanceThreshold) { // 50% chance for price change if (Math.random() < 0.5) { // 50% chance for increase (+1) or decrease (-1) if (Math.random() < 0.5) { appleCurrentPrice += 1; } else { appleCurrentPrice -= 1; } // Apply price limits for apple (5-25) if (appleCurrentPrice < 5) { appleCurrentPrice = 5; } if (appleCurrentPrice > 25) { appleCurrentPrice = 25; } } lastApplePriceUpdate = totalMovementDistance; } // Check for slot refresh every 3000 pixels var slotRefreshThreshold = lastSlotRefreshDistance + 3000; if (totalMovementDistance >= slotRefreshThreshold) { if (marketSlots && marketSlots.length > 0) { refreshMarketSlots(); } lastSlotRefreshDistance = totalMovementDistance; storage.lastSlotRefreshDistance = lastSlotRefreshDistance; } // Save economy data to storage storage.saltCurrentPrice = saltCurrentPrice; storage.appleCurrentPrice = appleCurrentPrice; storage.totalMovementDistance = totalMovementDistance; storage.lastSaltPriceUpdate = lastSaltPriceUpdate; storage.lastApplePriceUpdate = lastApplePriceUpdate; } // Update last position lastPlayerX = character.x; lastPlayerY = character.y; } game.update = function () { checkPassageCollision(); mapText.setText(regionNames[currentMap]); checkCityProximity(); updateGoldDisplay(); updateEconomySystem(); };
===================================================================
--- original.js
+++ change.js
@@ -1,9 +1,28 @@
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
-var storage = LK.import("@upit/storage.v1");
+var storage = LK.import("@upit/storage.v1", {
+ playerInventory: {
+ salt: 0,
+ apple: 0,
+ buySlot1: undefined,
+ buySlot2: undefined,
+ buySlot3: undefined,
+ buySlot4: undefined,
+ buySlot5: undefined,
+ buySlot6: undefined,
+ sellSlot7: undefined,
+ sellSlot8: undefined,
+ sellSlot9: undefined,
+ sellSlot10: undefined,
+ sellSlot11: undefined,
+ sellSlot12: undefined
+ },
+ playerGold: 100,
+ currentMap: 0
+});
/****
* Classes
****/
@@ -98,15 +117,18 @@
var self = Container.call(this);
// Slot properties
self.item = null; // 'salt', 'apple', or null for empty
self.price = 0;
+ self.slotIndex = 0; // Track which slot this is (1-6 for buy, 7-12 for sell)
+ self.mode = 'buy'; // 'buy' or 'sell'
// Create slot background (tradearea)
var slotBg = self.attachAsset('tradearea', {
anchorX: 0.5,
anchorY: 0.5
});
// Item icon (initially invisible)
var itemIcon = null;
+ var coinIcon = null;
// Item name text
var itemNameText = new Text2('', {
size: 38,
fill: 0xFFFFFF
@@ -123,15 +145,24 @@
itemPriceText.anchor.set(0.5, 0.5);
itemPriceText.x = 0;
itemPriceText.y = 80;
self.addChild(itemPriceText);
+ // Method to set slot properties
+ self.setSlotProperties = function (index, mode) {
+ self.slotIndex = index;
+ self.mode = mode;
+ };
// Method to set item
self.setItem = function (itemType) {
- // Clear existing item icon
+ // Clear existing item icon and coin icon
if (itemIcon) {
self.removeChild(itemIcon);
itemIcon = null;
}
+ if (coinIcon) {
+ self.removeChild(coinIcon);
+ coinIcon = null;
+ }
self.item = itemType;
if (itemType === 'salt') {
itemIcon = LK.getAsset('salt', {
anchorX: 0.5,
@@ -144,9 +175,9 @@
self.addChild(itemIcon);
itemNameText.setText('Salt');
self.price = Math.round(saltCurrentPrice * 10) / 10;
// Create coin icon and price display
- var coinIcon = LK.getAsset('coin', {
+ coinIcon = LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
@@ -168,9 +199,9 @@
self.addChild(itemIcon);
itemNameText.setText('Apple');
self.price = Math.round(appleCurrentPrice * 10) / 10;
// Create coin icon and price display
- var coinIcon = LK.getAsset('coin', {
+ coinIcon = LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
@@ -188,32 +219,27 @@
}
};
// Handle slot click
self.down = function (x, y, obj) {
- if (isSellMode) {
+ if (self.mode === 'sell') {
// Sell mode - check if player has the item to sell
if (self.item && playerInventory[self.item] > 0) {
// Sell item
playerInventory[self.item] -= 1;
playerGold += self.price;
updateGoldDisplay();
+ // Clear the slot from inventory
+ var slotKey = 'sellSlot' + self.slotIndex;
+ playerInventory[slotKey] = null;
updateInventoryStorage();
// Flash effect on sale
LK.effects.flashObject(self, 0x00FF00, 500);
- // Clear the sold item from sell slots (7-12) and regenerate sell slots
- var sellSlotKeys = ['slot7', 'slot8', 'slot9', 'slot10', 'slot11', 'slot12'];
- for (var i = 0; i < sellSlotKeys.length; i++) {
- if (playerInventory[sellSlotKeys[i]] === self.item) {
- playerInventory[sellSlotKeys[i]] = null;
- break;
- }
- }
// Clear the slot after sale
self.setItem(null);
- // Regenerate sell slots to reflect inventory changes
+ // Auto-reassign items to empty sell slots
+ reassignSellSlots();
+ // Refresh market screen to show changes
if (isMarketOpen) {
- generateSellSlots();
- // Refresh market screen
closeMarketScreen();
createMarketScreen();
}
} else if (self.item && playerInventory[self.item] <= 0) {
@@ -225,22 +251,20 @@
if (self.item && playerGold >= self.price) {
// Purchase item
playerGold -= self.price;
playerInventory[self.item] += 1;
- // Find first empty inventory slot (7-12 for sell slots)
- for (var i = 7; i <= 12; i++) {
- var slotKey = 'slot' + i;
- if (!playerInventory[slotKey]) {
- playerInventory[slotKey] = self.item;
- break;
- }
- }
+ // Auto-assign to a random sell slot
+ assignItemToRandomSellSlot(self.item);
updateGoldDisplay();
updateInventoryStorage();
// Flash effect on purchase
LK.effects.flashObject(self, 0x00FF00, 500);
- // Clear the slot after purchase
+ // Clear the buy slot after purchase
+ var buySlotKey = 'buySlot' + self.slotIndex;
+ playerInventory[buySlotKey] = null;
self.setItem(null);
+ // Regenerate buy slots to get new random items
+ generateBuySlots();
} else if (self.item && playerGold < self.price) {
// Not enough gold - flash red
LK.effects.flashObject(self, 0xFF0000, 500);
}
@@ -1995,32 +2019,16 @@
var isMarketOpen = false;
var lastCityDistance = Infinity;
var hasVisitedCity = false;
// Market mode variables
-var isSellMode = true;
+var isSellMode = false;
var sellButton = null;
var buyButton = null;
// City menu UI variables
var cityMenuScreen = null;
var isCityMenuOpen = false;
-// Player inventory - enhanced with 12-slot system
-var playerInventory = storage.playerInventory || {
- salt: 0,
- apple: 0,
- slot1: null,
- // 12 individual inventory slots
- slot2: null,
- slot3: null,
- slot4: null,
- slot5: null,
- slot6: null,
- slot7: null,
- slot8: null,
- slot9: null,
- slot10: null,
- slot11: null,
- slot12: null
-};
+// Enhanced player inventory with proper separation of buy/sell systems
+var playerInventory = storage.playerInventory;
// Market slot system variables
var lastSlotRefreshDistance = storage.lastSlotRefreshDistance || 0;
// Generate initial market slots after everything is initialized
generateMarketSlots();
@@ -2031,28 +2039,41 @@
marketSlots[i].parent.removeChild(marketSlots[i]);
}
}
marketSlots = [];
- // If in sell mode, generate sell slots instead
+ // Generate slots based on current mode
if (isSellMode) {
generateSellSlots();
- return;
+ } else {
+ generateBuySlots();
}
+}
+function generateBuySlots() {
// Safety check for currentMap and slotProbabilityPools
if (currentMap < 0 || currentMap >= slotProbabilityPools.length || !slotProbabilityPools[currentMap]) {
return;
}
// Get probability pool for current map
var probabilityPool = slotProbabilityPools[currentMap];
- // Generate 6 slots for buy mode (slots 1-6)
- for (var i = 0; i < 6; i++) {
+ // Generate 6 slots for buy mode (buySlot1-6)
+ for (var i = 1; i <= 6; i++) {
var slot = new TradeSlot();
- // Random item from probability pool
- var randomIndex = Math.floor(Math.random() * probabilityPool.length);
- var itemType = probabilityPool[randomIndex];
- slot.setItem(itemType);
+ slot.setSlotProperties(i, 'buy');
+ // Check if slot already has an item from storage
+ var buySlotKey = 'buySlot' + i;
+ var existingItem = playerInventory[buySlotKey];
+ if (existingItem) {
+ slot.setItem(existingItem);
+ } else {
+ // Generate new random item
+ var randomIndex = Math.floor(Math.random() * probabilityPool.length);
+ var itemType = probabilityPool[randomIndex];
+ playerInventory[buySlotKey] = itemType;
+ slot.setItem(itemType);
+ }
marketSlots.push(slot);
}
+ updateInventoryStorage();
}
function refreshMarketSlots() {
// Safety check for marketSlots array
if (!marketSlots) {
@@ -2269,10 +2290,9 @@
closeButton = null;
sellButton = null;
buyButton = null;
isMarketOpen = false;
- // Reset to buy mode when closing
- isSellMode = false;
+ // Keep current mode when closing market
}
}
function checkCityProximity() {
if (!city) {
@@ -2324,9 +2344,9 @@
function assignItemToRandomSellSlot(itemType) {
// Find available sell slots (7-12)
var availableSlots = [];
for (var i = 7; i <= 12; i++) {
- var slotKey = 'slot' + i;
+ var slotKey = 'sellSlot' + i;
if (!playerInventory[slotKey]) {
availableSlots.push(slotKey);
}
}
@@ -2339,32 +2359,61 @@
return true;
}
return false; // No available slots
}
-function generateSellSlots() {
- // Clear existing slots
- for (var i = 0; i < marketSlots.length; i++) {
- if (marketSlots[i] && marketSlots[i].parent) {
- marketSlots[i].parent.removeChild(marketSlots[i]);
+function reassignSellSlots() {
+ // Clear all sell slots first
+ for (var i = 7; i <= 12; i++) {
+ var slotKey = 'sellSlot' + i;
+ playerInventory[slotKey] = null;
+ }
+ // Reassign items from general inventory to sell slots randomly
+ var itemsToAssign = [];
+ // Add salt items to assignment list
+ for (var s = 0; s < playerInventory.salt; s++) {
+ itemsToAssign.push('salt');
+ }
+ // Add apple items to assignment list
+ for (var a = 0; a < playerInventory.apple; a++) {
+ itemsToAssign.push('apple');
+ }
+ // Randomly assign items to sell slots (max 6 items)
+ var maxAssignments = Math.min(itemsToAssign.length, 6);
+ for (var assign = 0; assign < maxAssignments; assign++) {
+ var randomItemIndex = Math.floor(Math.random() * itemsToAssign.length);
+ var selectedItem = itemsToAssign[randomItemIndex];
+ itemsToAssign.splice(randomItemIndex, 1); // Remove from list
+ // Find empty sell slot
+ for (var slot = 7; slot <= 12; slot++) {
+ var sellSlotKey = 'sellSlot' + slot;
+ if (!playerInventory[sellSlotKey]) {
+ playerInventory[sellSlotKey] = selectedItem;
+ break;
+ }
}
}
- marketSlots = [];
- // Generate 6 slots for sell mode (slots 7-12 from inventory)
- var sellSlotKeys = ['slot7', 'slot8', 'slot9', 'slot10', 'slot11', 'slot12'];
- for (var i = 0; i < 6; i++) {
+ updateInventoryStorage();
+}
+function generateSellSlots() {
+ // Auto-populate sell slots with available inventory before displaying
+ reassignSellSlots();
+ // Generate 6 slots for sell mode (sellSlot7-12 from inventory)
+ for (var i = 7; i <= 12; i++) {
var slot = new TradeSlot();
- var slotKey = sellSlotKeys[i];
- var itemType = playerInventory[slotKey];
+ slot.setSlotProperties(i, 'sell');
+ var sellSlotKey = 'sellSlot' + i;
+ var itemType = playerInventory[sellSlotKey];
// Show items from inventory if they exist and player has them in general inventory
- if (itemType && (itemType === 'salt' && playerInventory.salt > 0 || itemType === 'apple' && playerInventory.apple > 0)) {
+ if (itemType && playerInventory[itemType] > 0) {
slot.setItem(itemType);
} else {
slot.setItem(null);
// Clear the slot if item no longer available
- playerInventory[slotKey] = null;
+ playerInventory[sellSlotKey] = null;
}
marketSlots.push(slot);
}
+ updateInventoryStorage();
}
function updateEconomySystem() {
// Track movement distance
var dx = character.x - lastPlayerX;
mağara girişi. In-Game asset. 2d. High contrast. No shadows
ortaçağ atlı araba ve tüccar . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
aynısı arkaplansız
medieval X close button. In-Game asset. 2d. High contrast. No shadows
altın kesesi. In-Game asset. 2d. High contrast. No shadows
elma. In-Game asset. 2d. High contrast. No shadows
ortaçağ ticari tuz. In-Game asset. 2d. High contrast. No shadows
çivi ile duvara asılı hafif yıpranmış parşomen. In-Game asset. 2d. High contrast. No shadows
medieval envanter bag. In-Game asset. 2d. High contrast. No shadows
minecraft envaneri gibi kutucuklar sadece kutucuklar başka uı elementi yok. ortaçağ temasında bir çanta içi hissi vermeli dokusu . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
bir ortaçağ eşyası bize hız veriyor ne olur bilmiyorum. In-Game asset. 2d. High contrast. No shadows
medieval sword. In-Game asset. 2d. High contrast. No shadows