From: <ke...@us...> - 2007-10-19 22:34:33
|
Revision: 37 http://planeshift.svn.sourceforge.net/planeshift/?rev=37&view=rev Author: kemedes Date: 2007-10-19 15:33:50 -0700 (Fri, 19 Oct 2007) Log Message: ----------- Added dynamic item price calculation. Now it uses math script to include quality of the item in the price calculation. Modified Paths: -------------- trunk/docs/history.txt trunk/src/server/bulkobjects/psitem.cpp trunk/src/server/bulkobjects/psitem.h trunk/src/server/database/mysql/math_scripts.sql Modified: trunk/docs/history.txt =================================================================== --- trunk/docs/history.txt 2007-10-19 22:24:50 UTC (rev 36) +++ trunk/docs/history.txt 2007-10-19 22:33:50 UTC (rev 37) @@ -1,3 +1,7 @@ +*** 2007-10-20 by Sasha Levin +- Added dynamic item price calculation. Now it uses math script to include quality of the + item in the calculation. + *** 2007-10-19 by Michael Gist - Wrote a new updater. Console only atm. Modified: trunk/src/server/bulkobjects/psitem.cpp =================================================================== --- trunk/src/server/bulkobjects/psitem.cpp 2007-10-19 22:24:50 UTC (rev 36) +++ trunk/src/server/bulkobjects/psitem.cpp 2007-10-19 22:33:50 UTC (rev 37) @@ -26,6 +26,7 @@ #include "util/log.h" #include "util/psstring.h" #include "util/serverconsole.h" +#include "util/mathscript.h" #include "psitem.h" #include "pscharacter.h" @@ -1465,9 +1466,34 @@ return decay_resistance; } -psMoney& psItem::GetPrice() +psMoney psItem::GetPrice() { - return current_stats->GetPrice(); + static MathScript *script; + if (!script) + script = psserver->GetMathScriptEngine()->FindScript("Calc Item Price"); + if (!script) + { + Error1("Cannot find mathscript: Calc Item Price"); + return current_stats->GetPrice(); + } + + static MathScriptVar *price; + static MathScriptVar *quality; + static MathScriptVar *maxquality; + static MathScriptVar *finalprice; + + price = script->GetOrCreateVar("Price"); + quality = script->GetOrCreateVar("Quality"); + maxquality = script->GetOrCreateVar("MaxQuality"); + finalprice = script->GetOrCreateVar("FinalPrice"); + + price->SetValue(current_stats->GetPrice().GetTotal()); + quality->SetValue(GetItemQuality()); + maxquality->SetValue(GetMaxItemQuality()); + + script->Execute(); + + return psMoney((int)(finalprice->GetValue())); } psMoney psItem::GetSellPrice() @@ -1475,7 +1501,7 @@ // Merchants like 20% profit. So we take the total price, // multiply with 0.8 and make a new money with that amount // as trias. - int price = int(current_stats->GetPrice().GetTotal() * 0.8); + int price = int(GetPrice().GetTotal() * 0.8); if (price == 0) price = 1; return psMoney(price); Modified: trunk/src/server/bulkobjects/psitem.h =================================================================== --- trunk/src/server/bulkobjects/psitem.h 2007-10-19 22:24:50 UTC (rev 36) +++ trunk/src/server/bulkobjects/psitem.h 2007-10-19 22:33:50 UTC (rev 37) @@ -630,7 +630,7 @@ bool FitsInSlots(PSITEMSTATS_SLOTLIST slotmask); bool FitsInSlot(INVENTORY_SLOT_NUMBER slot); float GetDecayResistance(); - psMoney& GetPrice(); + psMoney GetPrice(); psMoney GetSellPrice(); ///< Merchants want a percentage psItemCategory* GetCategory(); Modified: trunk/src/server/database/mysql/math_scripts.sql =================================================================== --- trunk/src/server/database/mysql/math_scripts.sql 2007-10-19 22:24:50 UTC (rev 36) +++ trunk/src/server/database/mysql/math_scripts.sql 2007-10-19 22:33:50 UTC (rev 37) @@ -225,4 +225,5 @@ PrimCount = Actor:getSkillValue(64) + 20; "); +INSERT INTO math_scripts VALUES( "Calc Item Price", "FinalPrice = Price + Quality + MaxQuality;"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |