EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development: Custom Code (https://www.eqemulator.org/forums/forumdisplay.php?f=665)
-   -   Alternate TakeMoneyFromPP() (https://www.eqemulator.org/forums/showthread.php?t=35904)

Uleat 10-23-2012 10:14 PM

Alternate TakeMoneyFromPP()
 
This is basically a polished version of the existing TakeMoneyFromPP() method that is referenced here: http://www.eqemulator.org/forums/showthread.php?t=35883

I integrated Lerxst's rework for AddMoneyToPP() into this in an attempt to speed up this procedure. (http://www.eqemulator.org/forums/sho...0&postcount=18)


There may be a minor increase of speed in certain operations, but the overall is still negligible and doesn't warrant the work and effort of testing and implementing it.

It's posted here for reference, so feel free to do whatever with it. I'll answer any questions as to why I did things a certain way.


BETA-LEVEL PROCEDURE

Code:

bool Client::TakeMoneyFromPP(uint64 copper, bool updateclient) {
       
        if (!HasMoney(copper)) { return false; }

        sint64 cur_copper = static_cast<sint64>(m_pp.copper) - copper;
        if (cur_copper < 0) {
                sint64 cur_silver = (static_cast<sint64>(m_pp.silver) * 10) + cur_copper;
                if (cur_silver < 0) {
                        sint64 cur_gold = (static_cast<sint64>(m_pp.gold) * 100 ) + cur_silver;       
                        if (cur_gold < 0) {
                                sint64 cur_platinum = (static_cast<sint64>(m_pp.platinum) * 1000) + cur_gold;       
                                if (cur_platinum < 0) {
#if (EQDEBUG>=5)
                                        LogFile->write(EQEMuLog::Debug, "Client::TakeMoneyFromPP() %s's transaction resulted in a deficit of %i copper",
                                                GetName(), (~cur_platinum + 1));
#endif
                                        m_pp.platinum = 0;
                                        m_pp.gold = 0;
                                        m_pp.silver = 0;
                                        m_pp.copper = 0;
                                }
                                else {
                                        m_pp.platinum = cur_platinum / 1000;
                                        m_pp.gold = (cur_platinum / 100) % 10;
                                        m_pp.silver = (cur_platinum / 10) % 10;
                                        m_pp.copper = cur_platinum % 10;
                                }
                        }
                        else {
                                m_pp.gold = cur_gold / 100;
                                m_pp.silver = (cur_gold / 10) % 10;
                                m_pp.copper = cur_gold % 10;
                        }
                }
                else {
                        m_pp.silver = cur_silver / 10;
                        m_pp.copper = cur_silver % 10;
                }
        }
        else {
                m_pp.copper = cur_copper;
        }
 
        if (updateclient) { SendMoneyUpdate(); }
       
        RecalcWeight();
        Save();
        return true;
}



All times are GMT -4. The time now is 11:14 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.