Ir para conteúdo
  • 0
Entre para seguir isso  
ariest

Programação Accept new coin

Pergunta

ariest    0
ariest

Antes de fazer a sua pergunta, tenha certeza de ter lido as regras da seção e o guia abaixo:

https://forums.otserv.com.br/index.php?/forums/topic/168583-regras-da-seção/

https://forums.otserv.com.br/index.php?/forums/topic/165121-como-fazer-uma-pergunta-ou-o-grande-guia-do-usuário-com-dúvidas/

Obs: não delete esse formulário pré-definido, preencha-o corretamente para postar o seu tópico!

Descreva em algumas palavras a base utilizada. (Nome do servidor / Nome do cliente / Nome do website / etc.).

Base:

OTServBR-Global 12.x

Qual é a sua pergunta?

Estou procurando uma maneira de adicionar uma nova moeda ao jogo e fazer com que o npc aceite a nova moeda como dinheiro.

Tentei editar fontes de um guia que encontrei em outro fórum mas ao comprar algo o npc não detecta a nova moeda como dinheiro, espero e possam me ajudar, estou usando otbr 1.3 12.64

 

Você tem o código disponível? Se tiver poste-o na caixa de código que está dentro do spoiler abaixo:

Spoiler

Esse é o guia que me ajudou há um ano mas preciso dele para trabalhar com o otbr 12.64

Spoiler


 const.h

Change this lines:
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
To this lines: As you see there is "2151" its server gold ingot ID, change it for you server gold ingot ID or what you want.
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
    ITEM_GOLD_INGOT = 2151

 

 

Spoiler


game.cpp

After this line:
Code:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }
Add this line:
Code:
    uint32_t goldIngot = money / 1000000;
    money -= goldIngot * 1000000;
    while (goldIngot > 0) {
        const uint16_t count = std::min<uint32_t>(100, goldIngot);

        Item* remaindItem = Item::CreateItem(ITEM_GOLD_INGOT, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        goldIngot -= count;
    }

 

 

Spoiler


item.cpp

Change this:
Code:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        default:
            return 0;
    }
}

To this:

Code:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        case ITEM_GOLD_INGOT:
            return count * 1000000;

        default:
            return 0;
    }
}

 

 

Spoiler


luascript.cpp

After this:

Code:
    registerEnum(ITEM_CRYSTAL_COIN)

Add this:

Code:
    registerEnum(ITEM_GOLD_INGOT)

 

 

Spoiler


player.cpp

Change this:
Code:
bool Player::updateSaleShopList(const Item* item)
{
    uint16_t itemId = item->getID();
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN) {
        auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
        if (it == shopItemList.end()) {
            const Container* container = item->getContainer();
            if (!container) {
                return false;
            }

            const auto& items = container->getItemList();
            return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
                return updateSaleShopList(containerItem);
            });
        }
    }

    if (client) {
        client->sendSaleItemList(shopItemList);
    }
    return true;
}

To this:

Code:
bool Player::updateSaleShopList(const Item* item)
{
    uint16_t itemId = item->getID();
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_INGOT) {
        auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
        if (it == shopItemList.end()) {
            const Container* container = item->getContainer();
            if (!container) {
                return false;
            }

            const auto& items = container->getItemList();
            return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
                return updateSaleShopList(containerItem);
            });
        }
    }

    if (client) {
        client->sendSaleItemList(shopItemList);
    }
    return true;
}

 

Você tem alguma imagem que possa auxiliar no problema? Se sim, anexe-a dentro do spoiler abaixo:

Spoiler

 

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

1 resposta a esta questão

Recommended Posts

Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×