Jump to content

OTClient Adicionando barra de carregamento nas criaturas


Recommended Posts

 

Descrição: Com estas alterações nas sources do servidor e do OTC você conseguirá adicionar ao jogo uma barra de carregamento nas criaturas do jogo. Esta barra é personalizável e pode ser utilizada de diversas formas em diferentes scripts.

separador.png

Server sources.

No arquivo game.h

Abaixo de:

Spoiler

bool reload(ReloadTypes_t reloadType);

 

Adicione:

Spoiler

void startProgressbar(Creature* creature, uint32_t duration, bool ltr = true);

 

 

No arquivo game.cpp

Adicione:

Spoiler


void Game::startProgressbar(Creature* creature, uint32_t duration, bool ltr)
{
    SpectatorVec spectators;
    map.getSpectators(spectators, creature->getPosition(), false, true);
    for (Creature* spectator : spectators) {
        if (Player* tmpPlayer = spectator->getPlayer()) {
            tmpPlayer->sendProgressbar(creature->getID(), duration, ltr);
        }
    }
}

 

 

No arquivo luascript.h

Abaixo de:

Spoiler

static int luaCreatureGetZone(lua_State* L);

 

Adicione:

Spoiler

static int luaCreatureSetProgressbar(lua_State* L);

 

 

No arquivo luascript.cpp

Abaixo de:

Spoiler

	registerMethod("Creature", "getZone", LuaScriptInterface::luaCreatureGetZone)

 

Adicione:

Spoiler

 


	registerMethod("Creature", "sendProgressbar", LuaScriptInterface::luaCreatureSetProgressbar);

Abaixo de:

Spoiler

 



int LuaScriptInterface::luaCreatureGetZone(lua_State* L)
{
	// creature:getZone()
	Creature* creature = getUserdata<Creature>(L, 1);
	if (creature) {
		lua_pushnumber(L, creature->getZone());
	} else {
		lua_pushnil(L);
	}
	return 1;
}

Adicione:

Spoiler


int LuaScriptInterface::luaCreatureSetProgressbar(lua_State* L)
{
    // creature:sendProgressbar(duration, leftToRight)
    Creature* creature = getUserdata<Creature>(L, 1);
    uint32_t duration = getNumber<uint32_t>(L, 2);
    bool ltr = getBoolean(L, 3);
    if (creature) {
        g_game.startProgressbar(creature, duration, ltr);
        pushBoolean(L, true);
    }
    else {
        lua_pushnil(L);
    }

    return 1;
}

 

 

No arquivo player.h

Abaixo de:

Spoiler


		void sendNetworkMessage(const NetworkMessage& message) {
			if (client) {
				client->writeToOutputBuffer(message);
			}
		}

 

Adicione:

Spoiler


		void sendProgressbar(uint32_t id, uint32_t duration, bool ltr = true) {
            if (client) {
                client->sendProgressbar(id, duration, ltr);
            }
        }

 

 

No arquivo protocolgame.h

Abaixo de:

Spoiler

void sendModalWindow(const ModalWindow& modalWindow);

 

Adicione:

Spoiler

void sendProgressbar(uint32_t id, uint32_t duration, bool ltr = true);

 

 

No arquivo protocolgame.cpp

No final do arquivo adicione:

Spoiler


void ProtocolGame::sendProgressbar(uint32_t id, uint32_t duration, bool ltr)
{
    NetworkMessage msg;
    msg.addByte(0x3b);
    msg.add<uint32_t>(id);
    msg.add<uint32_t>(duration);
    msg.addByte(ltr);
    writeToOutputBuffer(msg);
}

 

 

Client sources.

No arquivo protocolcodes.cpp

Abaixo de:

Spoiler

        GameServerExtendedOpcode            = 50,

 

Adicione:

Spoiler

		GameServerProgressBar               = 59,

 

 

No arquivo protocolgame.h

Abaixo de:

Spoiler

    void parseChangeMapAwareRange(const InputMessagePtr& msg);

 

Adicione:

Spoiler

	void parseProgressBar(const InputMessagePtr& msg);

 

 

No arquivo protocolgameparse.cpp

Abaixo de:

Spoiler

            case Proto::GameServerChangeMapAwareRange:
                parseChangeMapAwareRange(msg);
                break;

 

Adicione:

Spoiler


			case Proto::GameServerProgressBar:
                parseProgressBar(msg);
                break;

 

Abaixo de:

Spoiler


void ProtocolGame::parseChangeMapAwareRange(const InputMessagePtr& msg)
{
    int xrange = msg->getU8();
    int yrange = msg->getU8();

    AwareRange range;
    range.left = xrange/2 - ((xrange+1) % 2);
    range.right = xrange/2;
    range.top = yrange/2 - ((yrange+1) % 2);
    range.bottom = yrange/2;

    g_map.setAwareRange(range);
    g_lua.callGlobalField("g_game", "onMapChangeAwareRange", xrange, yrange);
}

 

Adicione:

Spoiler

 



void ProtocolGame::parseProgressBar(const InputMessagePtr& msg)
{
    uint32 id = msg->getU32();
    uint32 duration = msg->getU32();
    bool ltr = msg->getU8();
    CreaturePtr creature = g_map.getCreatureById(id);
    if (creature)
        creature->setProgressBar(duration, ltr);
    else
        g_logger.traceError(stdext::format("could not get creature with id %d", id));
}

 

No arquivo creature.h

Abaixo de:

Spoiler


    virtual void onPositionChange(const Position& newPos, const Position& oldPos);
    virtual void onAppear();
    virtual void onDisappear();
    virtual void onDeath();

 

Adicione:

Spoiler


    // progress bar
    uint8 getProgressBarPercent() { return m_progressBarPercent; }
    void setProgressBar(uint32 duration, bool ltr);
    void updateProgressBar(uint32 duration, bool ltr);

 

Abaixo de:

Spoiler

 



    // jump related
    float m_jumpHeight;
    float m_jumpDuration;
    PointF m_jumpOffset;
    Timer m_jumpTimer;

Adicione:

Spoiler

 



    // progress bar
    uint8 m_progressBarPercent;
    ScheduledEventPtr m_progressBarUpdateEvent;
    Timer m_progressBarTimer;

 

No arquivo creature.cpp

Abaixo de:

Spoiler

 



    m_outfitColor = Color::white;

Adicione:

Spoiler


	m_progressBarPercent = 0;
    m_progressBarUpdateEvent = nullptr;

 

Substitua o código abaixo:

 

Spoiler


    // draw
    if(g_game.getFeature(Otc::GameBlueNpcNameColor) && isNpc() && m_healthPercent == 100 && !useGray)
        fillColor = Color(0x66, 0xcc, 0xff);

    if(drawFlags & Otc::DrawBars && (!isNpc() || !g_game.getFeature(Otc::GameHideNpcNames))) {
        g_painter->setColor(Color::black);
        g_painter->drawFilledRect(backgroundRect);

        g_painter->setColor(fillColor);
        g_painter->drawFilledRect(healthRect);

        if(drawFlags & Otc::DrawManaBar && isLocalPlayer()) {
            LocalPlayerPtr player = g_game.getLocalPlayer();
            if(player) {
                backgroundRect.moveTop(backgroundRect.bottom());

                g_painter->setColor(Color::black);
                g_painter->drawFilledRect(backgroundRect);

                Rect manaRect = backgroundRect.expanded(-1);
                double maxMana = player->getMaxMana();
                if(maxMana == 0) {
                    manaRect.setWidth(25);
                } else {
                    manaRect.setWidth(player->getMana() / (maxMana * 1.0) * 25);
                }

                g_painter->setColor(Color::blue);
                g_painter->drawFilledRect(manaRect);
            }
        }
    }

 

Por este código:

Spoiler


    // draw
    if(g_game.getFeature(Otc::GameBlueNpcNameColor) && isNpc() && m_healthPercent == 100 && !useGray)
        fillColor = Color(0x66, 0xcc, 0xff);

    if(drawFlags & Otc::DrawBars && (!isNpc() || !g_game.getFeature(Otc::GameHideNpcNames))) {
        g_painter->setColor(Color::black);
        g_painter->drawFilledRect(backgroundRect);

        g_painter->setColor(fillColor);
        g_painter->drawFilledRect(healthRect);

        if(drawFlags & Otc::DrawManaBar && isLocalPlayer()) {
            LocalPlayerPtr player = g_game.getLocalPlayer();
            if(player) {
                backgroundRect.moveTop(backgroundRect.bottom());

                g_painter->setColor(Color::black);
                g_painter->drawFilledRect(backgroundRect);

                Rect manaRect = backgroundRect.expanded(-1);
                double maxMana = player->getMaxMana();
                if(maxMana == 0) {
                    manaRect.setWidth(25);
                } else {
                    manaRect.setWidth(player->getMana() / (maxMana * 1.0) * 25);
                }

                g_painter->setColor(Color::blue);
                g_painter->drawFilledRect(manaRect);
            }
        }
		
		if (getProgressBarPercent()) {
            backgroundRect.moveTop(backgroundRect.bottom());

			g_painter->setColor(Color::black);
            g_painter->drawFilledRect(backgroundRect);
            //g_drawQueue->addFilledRect(backgroundRect, Color::black);

            Rect progressBarRect = backgroundRect.expanded(-1);
            double maxBar = 100;
            progressBarRect.setWidth(getProgressBarPercent() / (maxBar * 1.0) * 25);

			g_painter->setColor(Color::white);
            g_painter->drawFilledRect(progressBarRect);
            //g_drawQueue->addFilledRect(progressBarRect, Color::white);
		}
    }

 

 

E ainda no arquivo creature.cpp no final da página adicione:

Spoiler


void Creature::setProgressBar(uint32 duration, bool ltr)
{
    if (m_progressBarUpdateEvent) {
        m_progressBarUpdateEvent->cancel();
        m_progressBarUpdateEvent = nullptr;
    }

    if (duration > 0) {
        m_progressBarTimer.restart();
        updateProgressBar(duration, ltr);
    } else
        m_progressBarPercent = 0;

    callLuaField("onProgressBarStart", duration, ltr);
}

void Creature::updateProgressBar(uint32 duration, bool ltr)
{
    if (m_progressBarTimer.ticksElapsed() < duration) {
        if (ltr)
            m_progressBarPercent = abs(m_progressBarTimer.ticksElapsed() / static_cast<double>(duration) * 100);
        else
            m_progressBarPercent = abs((m_progressBarTimer.ticksElapsed() / static_cast<double>(duration) * 100) - 100);

        auto self = static_self_cast<Creature>();
        m_progressBarUpdateEvent = g_dispatcher.scheduleEvent([=] {
            self->updateProgressBar(duration, ltr);
        }, 50);
    } else {
        m_progressBarPercent = 0;
    }
    callLuaField("onProgressBarUpdate", m_progressBarPercent, duration, ltr);
}

 

 

 

Fim! Estas são todas as alterações! 

separador.png

Créditos:

EddyHavoc

Flatlander

Kondrah

 

Edited by EddyHavoc (see edit history)
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By WorkedBox
      Bom pessoal, estou tentando compilar a source de um servidor de nto 8.54 que foi disponibilizado aqui no fórum, mas sempre que tento pelo dev C++, encontro o seguinte erro
      Eu já mexo nessa base a uns bons anos, mas nunca tive muito conhecimento e sempre enrolei pra vir atrás da source, mas quero focar mais no servidor e ela é essencial agora, alguém poderia me ajudar ?  
       
       
      o servidor da qual estou falando é o 
       
       
    • By Sydion
      Alguém poderia me ajuda ?
      Bom , fui adicionar algumas sprites em meu old client .. mas ele ja chegou no maximo , e como não tem como extende-ló gostaria de saber , como posso o deixar em OTCLIENT
    • By vini464
      Falae galera blz ? bom eu to precisando que alguem descompile o client do wodbo wars , eu tentei aki mas ele ta protegido , mas nunca um client ta 100% protegido neh entao , se alguem ai manjar em descompilar o client "protegido" eu agradeço mtttt , eu to criando um server de wodbo e to precisando de algumas sprites pra voc nova entao é isso,Obrigado !!
       
      REP++++
    • By chavoz
      Oi galera!
       
      Primero que nada me disculpo mi portugués (traductor)
       
       
      Eu to creando isso:
       

       
      Mas eu nao consigo fazer que o "Health Bars" tenha funcao...
      eu ja crei um comando pra ver % de vida no pokemon do jogador
       

       
      Eu não tenho conhecimento suficiente da OTC para fazer isso.
       
      Me Pregunto sí alguien me entendio, y si es asi, por favor ayudeme.
       
    • By marvadon
      Bom Dia pessoal do TK
       
      estou com problemas com o npc xodet.
      ele não entrega e nem vende a wand of dragonbreath, aparece na lista de compra mas não ocorre nehuma ação referente a entrega e cobrança de gold.
       
      todos os outros itens ele entrega normalmente.
       
      alguém poderia me ajudar.
       
       
      Obrigado
      local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end local shopModule = ShopModule:new() npcHandler:addModule(shopModule) shopModule:addBuyableItem({'spellbook'}, 2175, 150, 1, 'spellbook') shopModule:addBuyableItem({'small health'}, 8704, 20, 1, 'small health potion') shopModule:addBuyableItem({'health potion'}, 7618, 45, 1, 'health potion') shopModule:addBuyableItem({'mana potion'}, 7620, 50, 1, 'mana potion') shopModule:addBuyableItem({'strong health'}, 7588, 100, 1, 'strong health potion') shopModule:addBuyableItem({'strong mana'}, 7589, 80, 1, 'strong mana potion') shopModule:addBuyableItem({'great health'}, 7591, 190, 1, 'great health potion') shopModule:addBuyableItem({'great mana'}, 7590, 120, 1, 'great mana potion') shopModule:addBuyableItem({'great spirit'}, 8472, 190, 1, 'great spirit potion') shopModule:addBuyableItem({'ultimate health'}, 8473, 310, 1, 'ultimate health potion') shopModule:addSellableItem({'normal potion flask', 'normal flask'}, 7636, 5, 'empty small potion flask') shopModule:addSellableItem({'strong potion flask', 'strong flask'}, 7634, 10, 'empty strong potion flask') shopModule:addSellableItem({'great potion flask', 'great flask'}, 7635, 15, 'empty great potion flask') shopModule:addBuyableItem({'instense healing'}, 2265, 95, 1, 'intense healing rune') shopModule:addBuyableItem({'ultimate healing'}, 2273, 100, 1, 'ultimate healing rune') shopModule:addBuyableItem({'fire bomb'}, 2305, 117, 1, 'fire bomb') shopModule:addBuyableItem({'destroy field'}, 2261, 15, 1, 'destroy field rune') shopModule:addBuyableItem({'light magic missile'}, 2287, 4, 1, 'light magic missile rune') shopModule:addBuyableItem({'heavy magic missile'}, 2311, 12, 1, 'heavy magic missile rune') shopModule:addBuyableItem({'great fireball'}, 2304, 45, 1, 'great fireball rune') shopModule:addBuyableItem({'explosion'}, 2313, 31, 1, 'explosion rune') shopModule:addBuyableItem({'sudden death'}, 2268, 40, 1, 'sudden death rune') shopModule:addBuyableItem({'convince creature'}, 2290, 80, 1, 'convince creature rune') shopModule:addBuyableItem({'chameleon'}, 2291, 210, 1, 'chameleon rune') shopModule:addBuyableItem({'desintegrate'}, 2310, 80, 1, 'desintegreate rune') shopModule:addBuyableItem({'fire field'}, 2301, 28, 1, 'fire field rune') shopModule:addBuyableItem({'energy field'}, 2301, 38, 1, 'energy field rune') shopModule:addBuyableItem({'avalanche rune'}, 2274, 45, 1, 'avalanche rune') shopModule:addBuyableItem({'antidote rune'}, 2266, 65, 1, 'antidote rune') shopModule:addBuyableItem({'energy wall'}, 2279, 85, 1, 'energy wall rune') shopModule:addBuyableItem({'icicle'}, 2271, 30, 1, 'icicle rune') shopModule:addBuyableItem({'magic wall rune'}, 2293, 30, 1, 'magic wall rune') shopModule:addBuyableItem({'wild growth rune'}, 2269, 15, 1, 'wild growth rune') shopModule:addBuyableItem({'poison field'}, 2285, 21, 1, 'poison field rune') shopModule:addBuyableItem({'poison wall'}, 2289, 52, 1, 'poison wall rune') shopModule:addBuyableItem({'blank'}, 2260, 10, 1, 'blank rune') shopModule:addBuyableItem({'paralyze rune'}, 2278, 5, 1, 'paralyze rune') shopModule:addBuyableItem({'fire ball'}, 2302, 30, 1, 'fire ball rune') shopModule:addBuyableItem({'wand of vortex', 'vortex'}, 2190, 500, 'wand of vortex') shopModule:addBuyableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 1000, 1, 'wand of dragonbreath') shopModule:addBuyableItem({'wand of decay', 'decay'}, 2188, 5000, 'wand of decay') shopModule:addBuyableItem({'wand of draconia', 'draconia'}, 8921, 7500, 'wand of draconia') shopModule:addBuyableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 10000, 'wand of cosmic energy') shopModule:addBuyableItem({'wand of inferno', 'inferno'}, 2187, 15000, 'wand of inferno') shopModule:addBuyableItem({'wand of starstorm', 'starstorm'}, 8920, 18000, 'wand of starstorm') shopModule:addBuyableItem({'wand of voodoo', 'voodoo'}, 8922, 22000, 'wand of voodoo') shopModule:addSellableItem({'normal potion flask', 'normal flask'}, 7636, 5, 'empty small potion flask') shopModule:addSellableItem({'strong potion flask', 'strong flask'}, 7634, 10, 'empty strong potion flask') shopModule:addSellableItem({'great potion flask', 'great flask'}, 7635, 15, 'empty great potion flask') shopModule:addSellableItem({'wand of vortex', 'vortex'}, 2190, 250, 'wand of vortex') shopModule:addSellableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 500, 'wand of dragonbreath') shopModule:addSellableItem({'wand of decay', 'decay'}, 2188, 2500, 'wand of decay') shopModule:addSellableItem({'wand of draconia', 'draconia'}, 8921, 3750, 'wand of draconia') shopModule:addSellableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 5000, 'wand of cosmic energy') shopModule:addSellableItem({'wand of inferno', 'inferno'},2187, 7500, 'wand of inferno') shopModule:addSellableItem({'wand of starstorm', 'starstorm'}, 8920, 9000, 'wand of starstorm') shopModule:addSellableItem({'wand of voodoo', 'voodoo'}, 8922, 11000, 'wand of voodoo') shopModule:addSellableItem({'snakebite rod', 'snakebite'}, 2182, 250, 1, 'snakebite rod') shopModule:addSellableItem({'moonlight rod', 'moonlight'}, 2186, 500, 1, 'moonlight rod') shopModule:addSellableItem({'necrotic rod', 'necrotic'}, 2185, 2500, 1, 'necrotic rod') shopModule:addSellableItem({'northwind rod', 'northwind'}, 8911, 3750, 1, 'northwind rod') shopModule:addSellableItem({'terra rod', 'terra'}, 2181, 5000, 1, 'terra rod') shopModule:addSellableItem({'hailstorm rod', 'hailstorm'}, 2183, 7500, 1, 'hailstorm rod') shopModule:addSellableItem({'springsprout rod', 'springsprout'}, 8912, 9000, 1, 'springsprout rod') shopModule:addSellableItem({'underworld rod', 'underworld'}, 8910, 11000, 1, 'underworld rod') shopModule:addBuyableItem({'snakebite rod', 'snakebite'}, 2182, 500, 'snakebite rod') shopModule:addBuyableItem({'moonlight rod', 'moonlight'}, 2186, 1000, 'moonlight rod') shopModule:addBuyableItem({'necrotic rod', 'necrotic'}, 2185, 5000, 'necrotic rod') shopModule:addBuyableItem({'northwind rod', 'northwind'}, 8911, 7500, 'northwind rod') shopModule:addBuyableItem({'terra rod', 'terra'}, 2181, 10000, 'terra rod') shopModule:addBuyableItem({'hailstorm rod', 'hailstorm'}, 2183, 15000, 'hailstorm rod') shopModule:addBuyableItem({'springsprout rod', 'springsprout'}, 8912, 18000, 'springsprout rod') shopModule:addBuyableItem({'underworld rod', 'underworld'}, 8910, 22000, 'underworld rod') npcHandler:addModule(FocusModule:new())
  • Recently Browsing   0 members

    No registered users viewing this page.


×
×
  • Create New...

Important Information

Confirmação de Termo