Adventure Land — торговец

Автор: | 15 января, 2022
Поделиться...

Тут набросок кодов для торговца:

//show_json(character)
//show_json(G.monsters.squig)
//show_json(G.maps["main"].monsters)
//show_json(G.maps["main"].npcs)
//show_json(get_target())

/* eslint-disable no-undef */
const ITEM_TO_BUY_AND_UPGRADE = "helmet"
const NUM_TO_KEEP = 4
const NUM_TO_BUY = 5 // If this is less than NUM_TO_KEEP, we won't buy anything.
const LEVEL_TO_UPGRADE_TO = 8

// список для продажи через запятую
const itemsToSell = [
	"cclaw",
	"whiteegg",
	"ringsj","hpamulet","hpbelt",
    "wshoes", "wgloves","helmet"
]

// автопокупка вещей с ценой меньше рыночной
setInterval(function(){
	buyCheapStuff()
	sellAll()
	loot()
},1000/4);

function sellAll()
{
	// продажа не нужного
	let tmp=find_npc("newupgrade")
	//log(tmp)
	if(distance(character,tmp) < 500) 
	{
		for (let i = 0; i < character.isize; i++)
		{
			const item = character.items[i]
			if (!item) continue // There is no item in this slot
			if (!itemsToSell.includes(item.name)) continue // This item is not on our to-sell list
			sell(i);
		}
	}	
}

function buyCheapStuff(){
  for (i in parent.entities){
    let otherPlayer = parent.entities[i];
    if(otherPlayer.player
      && otherPlayer.ctype === "merchant"
      && otherPlayer.slots
      && distance(character, otherPlayer) < G.skills.mluck.range){
      let tradeSlots = Object.keys(otherPlayer.slots).filter(tradeSlot => tradeSlot.includes("trade"));
      tradeSlots.forEach(tradeSlot => {
        if(otherPlayer.slots[tradeSlot]
           && otherPlayer.slots[tradeSlot].price < item_value(otherPlayer.slots[tradeSlot])
           && character.gold > otherPlayer.slots[tradeSlot].price){
          trade_buy(otherPlayer, tradeSlot);
          log("Bought " + otherPlayer.slots[tradeSlot].name + " from player: " + otherPlayer.name)
        }        
      });          
    }
  }
}


/*
async function buyAndUpgradeLoop() {
    try {
        //** Buy items if we need 
        let numItems = 0
        for (let i = 0; i < character.isize; i++) {
            const item = character.items[i]
            if (!item) continue // No item in this slot
            if (item.name !== ITEM_TO_BUY_AND_UPGRADE) continue // Not the item we're looking for
            numItems += 1
        }
        if (numItems < NUM_TO_BUY) {
            await buy(ITEM_TO_BUY_AND_UPGRADE)
            buyAndUpgradeLoop()
            return
        }
        if (numItems <= NUM_TO_KEEP) return // No more to upgrade

        //** Find the lowest level item, we'll upgrade that one 
        let lowestLevel = Number.MAX_SAFE_INTEGER
        let lowestLevelPosition
        for (let i = 0; i < character.isize; i++) {
            const item = character.items[i]
            if (!item) continue // No item in this slot

            if (item.name == ITEM_TO_BUY_AND_UPGRADE) {
                // This is an item we want to upgrade!
                if (item.level < lowestLevel) {
                    lowestLevel = item.level
                    lowestLevelPosition = i
                }
            }
        }

        // Don't upgrade if it's already the level we want, or there's no items to upgrade 
        if (lowestLevel < LEVEL_TO_UPGRADE_TO) {
            //** Find the scroll that corresponds with the grade of the item 
            const grade = item_grade(character.items[lowestLevelPosition])
            const scroll = `scroll${grade}`

            //** Buy a scroll if we don't have one 
            let scrollPosition = locate_item(scroll)
            if (scrollPosition == -1) scrollPosition = (await buy(scroll)).num

            //** Speed up the upgrade if we can 
            if (can_use("massproduction")) use_skill("massproduction")

            //** Upgrade! 
            await upgrade(lowestLevelPosition, scrollPosition)
        }
    } catch (e) {
        console.error(e)
    }
    buyAndUpgradeLoop()
}
buyAndUpgradeLoop()

// Move to a spot where we can buy scrolls and equipment, and upgrade.
smart_move({ map: "main", x: -225, y: -125 })
*/

Поделиться...

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *