From: <wel...@us...> - 2012-02-25 17:02:13
|
Revision: 8088 http://planeshift.svn.sourceforge.net/planeshift/?rev=8088&view=rev Author: weltall2 Date: 2012-02-25 17:02:05 +0000 (Sat, 25 Feb 2012) Log Message: ----------- -Added psitem:GetItemModifier(position) (0 = prefix 1 = suffix 2= adjective) returns 0 on fail, the id on success -Added psitem:SetItemModifier(position, modifierid) returns 1 on success 0 on fail -added pscharacter:DeleteItem(slot, amount); amount: -1 for the whole stock or a number. Returns 1 on success 0 on fail -added psitemstats:id gets the UID of the itemstats -added psitemstats:IsNamed("name") returns 1 if the name corresponds, 0 otherwise -implemented support for running a script based on process during the generation of a new item but before the destruction of the previous one Modified Paths: -------------- trunk/src/server/bulkobjects/pscharacter.cpp trunk/src/server/bulkobjects/psitem.cpp trunk/src/server/bulkobjects/psitemstats.cpp trunk/src/server/bulkobjects/pstrade.cpp trunk/src/server/bulkobjects/pstrade.h trunk/src/server/database/mysql/math_scripts.sql trunk/src/server/database/mysql/trade_processes.sql trunk/src/server/database/mysql/upgrade_schema.sql trunk/src/server/workmanager.cpp trunk/src/server/workmanager.h Modified: trunk/src/server/bulkobjects/pscharacter.cpp =================================================================== --- trunk/src/server/bulkobjects/pscharacter.cpp 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/bulkobjects/pscharacter.cpp 2012-02-25 17:02:05 UTC (rev 8088) @@ -2854,6 +2854,27 @@ return env->GetValue(item); } + + // deletes an item by its index in the inventory. DeleteItem(position, stackamount (-1 for whole stack)) + else if(function == "DeleteItem") + { + psItem *item = inventory.RemoveItemIndex((INVENTORY_SLOT_NUMBER)int(params[0]), int(params[1])); + + //Item not found + if(!item) + { + return 0.0f; + } + + //Delete the item + if(!item->Destroy()) + { + Error2("Could not remove old item ID #%u from database", item->GetUID()); + return 0.0f; + } + + return 1.0f; + } /** * Seems not to be used and could be replaced by a correct GetSkillValue in scripts instead. */ Modified: trunk/src/server/bulkobjects/psitem.cpp =================================================================== --- trunk/src/server/bulkobjects/psitem.cpp 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/bulkobjects/psitem.cpp 2012-02-25 17:02:05 UTC (rev 8088) @@ -2267,6 +2267,30 @@ return env->GetValue(GetBaseStats()); } + //Sets a modifier on the item. SetItemModifier(position, modifierId) + //The position reference is available in psItem::Load() + if(function == "SetItemModifier") + { + if(modifierIds.GetSize() <= int(params[0])) + { + return (double) 0.0f; + } + modifierIds[int(params[0])] = params[1]; + UpdateModifiers(); + return (double) 1.0f; + } + + //Gets a modifier on the item. SetItemModifier(position, modifierId) + //The position reference is available in psItem::Load() + if(function == "GetItemModifier") + { + if(modifierIds.GetSize() <= int(params[0])) + { + return (double) 0.0f; + } + return (double) modifierIds[int(params[0])]; + } + CPrintf(CON_ERROR, "psItem::CalcFunction(%s) failed\n", functionName); return 0; } Modified: trunk/src/server/bulkobjects/psitemstats.cpp =================================================================== --- trunk/src/server/bulkobjects/psitemstats.cpp 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/bulkobjects/psitemstats.cpp 2012-02-25 17:02:05 UTC (rev 8088) @@ -1707,13 +1707,26 @@ return (double) GetQuality(); } + //returns the id of the item + if(property == "Id") + { + return (double) GetUID(); + } + CPrintf(CON_ERROR, "psItemStats::GetProperty(%s) failed\n",ptr); return 0; } double psItemStats::CalcFunction(MathEnvironment* env, const char * functionName, const double * params) { - //we have no functions here yet. + csString function(functionName); + + //Checks if the name of the item is the given one. + if(function == "IsNamed") + { + return (double) (GetName() == env->GetString(params[0]))? 1.0f : 0.0f; + } + CPrintf(CON_ERROR, "psItemStats::CalcFunction(%s) failed\n", functionName); return 0; } Modified: trunk/src/server/bulkobjects/pstrade.cpp =================================================================== --- trunk/src/server/bulkobjects/pstrade.cpp 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/bulkobjects/pstrade.cpp 2012-02-25 17:02:05 UTC (rev 8088) @@ -186,7 +186,8 @@ maxSecSkill = 0; secPracticePts = 0; secQualFactor = 0; - renderEffect.Clear(); + renderEffect .Clear(); + scriptName .Clear(); } psTradeProcesses::~psTradeProcesses() @@ -275,6 +276,7 @@ secPracticePts = row.GetInt("secondary_practice_points"); secQualFactor = row.GetInt("secondary_quality_factor"); renderEffect = row["render_effect"]; + scriptName = row["script"]; return true; } Modified: trunk/src/server/bulkobjects/pstrade.h =================================================================== --- trunk/src/server/bulkobjects/pstrade.h 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/bulkobjects/pstrade.h 2012-02-25 17:02:05 UTC (rev 8088) @@ -172,6 +172,24 @@ int GetSecondaryQualFactor() const { return secQualFactor; } csString& GetRenderEffect() { return renderEffect; } + /** + * Gets the script associated to this process. This can be set from + * the users of the class and it's a cache for the mathscript. + * + * @return A weak reference to the associated mathscript, if any. + */ + csWeakRef<MathScript> &GetScript() { return script; } + + /** + * Gets the name of the script associated to this process. + * It will be run after the process is done during the generation of + * the new item. + * + * @return A csString with the name of the script as taken from the + * database. + */ + csString GetScriptName() const { return scriptName; } + /** Returns the name of the current process. * @note Needed for iScriptableVar. * @return the name of the process. @@ -208,7 +226,9 @@ int maxSecSkill; int secPracticePts; int secQualFactor; - csString renderEffect; + csString renderEffect; + csString scriptName; + csWeakRef<MathScript> script; }; /** Modified: trunk/src/server/database/mysql/math_scripts.sql =================================================================== --- trunk/src/server/database/mysql/math_scripts.sql 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/database/mysql/math_scripts.sql 2012-02-25 17:02:05 UTC (rev 8088) @@ -687,3 +687,9 @@ { Actor:InterruptSpellCasting() }" ); + +INSERT INTO math_scripts VALUES( "Apply Post Trade Process", +"NewItem:SetItemModifier(0, OldItem:GetItemModifier(0)); +NewItem:SetItemModifier(1, OldItem:GetItemModifier(1)); +NewItem:SetItemModifier(2, OldItem:GetItemModifier(2)); +" ); Modified: trunk/src/server/database/mysql/trade_processes.sql =================================================================== --- trunk/src/server/database/mysql/trade_processes.sql 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/database/mysql/trade_processes.sql 2012-02-25 17:02:05 UTC (rev 8088) @@ -10,25 +10,26 @@ DROP TABLE IF EXISTS `trade_processes`; CREATE TABLE trade_processes ( process_id int(10) unsigned NOT NULL, - subprocess_number int(4) unsigned NOT NULL COMMENT 'subprocess number', - name varchar(40) default NULL COMMENT 'process name', - animation varchar(30) COMMENT 'transformation animation', - render_effect CHAR(32) default NULL COMMENT 'transformation render effect', - workitem_id int(10) unsigned NOT NULL COMMENT 'target item to complete transformation', - equipment_id int(10) unsigned COMMENT 'required equipted item', - constraints varchar(64) NOT NULL DEFAULT '' COMMENT 'constraints that apply to transformation', - garbage_id int(10) unsigned COMMENT 'garbage item for flubbed transformations', - garbage_qty int(8) unsigned COMMENT 'garbage quantity for flubbed transformations', - primary_skill_id int(10) COMMENT 'primary skill for transformation', - primary_min_skill int(8) unsigned COMMENT 'minimum primary skill level required to perform transformation, 0 is no minimum', - primary_max_skill int(8) unsigned COMMENT 'maximum primary skill level at which practice and quality are effected, 0 is no maximum', - primary_practice_points int(4) COMMENT 'number of practice primary skill points gained for performing transformation', - primary_quality_factor int(3) unsigned DEFAULT '0' COMMENT 'percentage of the primary skill range that applies to quality', - secondary_skill_id int(10) COMMENT 'secondary skill foriegn key', - secondary_min_skill int(8) unsigned COMMENT 'minimum secondary skill level required to perform transformation, 0 is no minimum', - secondary_max_skill int(8) unsigned COMMENT 'maximum secondary skill level at which practice and quality are effected, 0 is no maximum', - secondary_practice_points int(4) COMMENT 'number of practice secondary skill points gained for performing transformation', - secondary_quality_factor int(3) unsigned COMMENT 'percentage of the secondary skill range that applies to quality', + subprocess_number int(4) unsigned NOT NULL COMMENT 'subprocess number', + name varchar(40) default NULL COMMENT 'process name', + animation varchar(30) COMMENT 'transformation animation', + render_effect CHAR(32) default NULL COMMENT 'transformation render effect', + workitem_id int(10) unsigned NOT NULL COMMENT 'target item to complete transformation', + equipment_id int(10) unsigned COMMENT 'required equipted item', + constraints varchar(64) NOT NULL DEFAULT '' COMMENT 'constraints that apply to transformation', + garbage_id int(10) unsigned COMMENT 'garbage item for flubbed transformations', + garbage_qty int(8) unsigned COMMENT 'garbage quantity for flubbed transformations', + primary_skill_id int(10) COMMENT 'primary skill for transformation', + primary_min_skill int(8) unsigned COMMENT 'minimum primary skill level required to perform transformation, 0 is no minimum', + primary_max_skill int(8) unsigned COMMENT 'maximum primary skill level at which practice and quality are effected, 0 is no maximum', + primary_practice_points int(4) COMMENT 'number of practice primary skill points gained for performing transformation', + primary_quality_factor int(3) unsigned DEFAULT '0' COMMENT 'percentage of the primary skill range that applies to quality', + secondary_skill_id int(10) COMMENT 'secondary skill foriegn key', + secondary_min_skill int(8) unsigned COMMENT 'minimum secondary skill level required to perform transformation, 0 is no minimum', + secondary_max_skill int(8) unsigned COMMENT 'maximum secondary skill level at which practice and quality are effected, 0 is no maximum', + secondary_practice_points int(4) COMMENT 'number of practice secondary skill points gained for performing transformation', + secondary_quality_factor int(3) unsigned COMMENT 'percentage of the secondary skill range that applies to quality', + script varchar(255) NOT NULL DEFAULT 'Apply Post Trade Process' COMMENT 'A script to run after a process has completed. In order to apply custom effects to the result.', description varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (process_id,subprocess_number) ); @@ -38,17 +39,17 @@ # Dumping data for table 'trade_processes' # -INSERT INTO trade_processes VALUES(1,0,"Mix","greet","",70,65,'',75,1,39,0,10,4,15,38,0,20,2,30,'Mix in mixing bowl.'); -INSERT INTO trade_processes VALUES(1,1,"Mix","greet","",70,90,'',75,1,39,0,10,4,15,38,0,20,2,30,'Mix in mixing bowl.'); -INSERT INTO trade_processes VALUES(2,0,"Mix at 1AM","greet","",70,65,"TIME(13:00:00)",75,1,39,0,10,4,15,38,0,20,2,30,'Mix in mixing bowl at 13:00.'); -INSERT INTO trade_processes VALUES(3,0,"Mix with mixer","greet","",70,90,'',75,1,39,10,60,4,15,38,10,15,2,30,'Mix in mixing bowl with mixer.'); -INSERT INTO trade_processes VALUES(4,0,"Bake with skill","greet","",74,0,'',75,1,39,5,20,6,50,38,10,40,3,50,'Bake in oven with skill.'); -INSERT INTO trade_processes VALUES(5,0,"Kneed","greet","",138,0,'',75,1,0,0,0,0,0,0,0,0,0,0,'Kneed on table.'); -INSERT INTO trade_processes VALUES(6,0,"Bake","greet","",74,0,'',75,1,0,0,0,0,0,0,0,0,0,0,'Bake in oven.'); -INSERT INTO trade_processes VALUES(7,0,"Blast","greet","",4815,0,'',0,0,0,0,0,0,0,0,0,0,0,0,'Blast in forge.'); -INSERT INTO trade_processes VALUES(8,0,"Hammer","greet","",4811,4816,'',0,0,0,0,0,0,0,0,0,0,0,0,'Hammer on anvil.'); -INSERT INTO trade_processes VALUES(9,0,"Mold cast","greet","",119,0,'',0,0,0,0,0,0,0,0,0,0,0,0,'Use a casting mold.'); -INSERT INTO trade_processes VALUES(10,0,"Wayout Mix","greet","",70,65,'',75,1,39,0,10,4,15,38,0,20,2,30,'Do wayout mixing in mixing bowl.'); -INSERT INTO trade_processes VALUES(11,0,"Wayout Baking","","",0,0,'',75,1,39,0,10,4,15,38,0,20,2,30,'Do wayout baking.'); -INSERT INTO trade_processes VALUES(12,0,"Flaming weapon","","",0,0,'',75,1,0,0,0,0,0,0,0,0,0,0,'Flame on.'); +INSERT INTO trade_processes VALUES(1,0,"Mix","greet","",70,65,'',75,1,39,0,10,4,15,38,0,20,2,30,'Apply Post Trade Process','Mix in mixing bowl.'); +INSERT INTO trade_processes VALUES(1,1,"Mix","greet","",70,90,'',75,1,39,0,10,4,15,38,0,20,2,30,'Apply Post Trade Process','Mix in mixing bowl.'); +INSERT INTO trade_processes VALUES(2,0,"Mix at 1AM","greet","",70,65,"TIME(13:00:00)",75,1,39,0,10,4,15,38,0,20,2,30,'Apply Post Trade Process','Mix in mixing bowl at 13:00.'); +INSERT INTO trade_processes VALUES(3,0,"Mix with mixer","greet","",70,90,'',75,1,39,10,60,4,15,38,10,15,2,30,'Apply Post Trade Process','Mix in mixing bowl with mixer.'); +INSERT INTO trade_processes VALUES(4,0,"Bake with skill","greet","",74,0,'',75,1,39,5,20,6,50,38,10,40,3,50,'Apply Post Trade Process','Bake in oven with skill.'); +INSERT INTO trade_processes VALUES(5,0,"Kneed","greet","",138,0,'',75,1,0,0,0,0,0,0,0,0,0,0,'Apply Post Trade Process','Kneed on table.'); +INSERT INTO trade_processes VALUES(6,0,"Bake","greet","",74,0,'',75,1,0,0,0,0,0,0,0,0,0,0,'Apply Post Trade Process','Bake in oven.'); +INSERT INTO trade_processes VALUES(7,0,"Blast","greet","",4815,0,'',0,0,0,0,0,0,0,0,0,0,0,0,'Apply Post Trade Process','Blast in forge.'); +INSERT INTO trade_processes VALUES(8,0,"Hammer","greet","",4811,4816,'',0,0,0,0,0,0,0,0,0,0,0,0,'Apply Post Trade Process','Hammer on anvil.'); +INSERT INTO trade_processes VALUES(9,0,"Mold cast","greet","",119,0,'',0,0,0,0,0,0,0,0,0,0,0,0,'Apply Post Trade Process','Use a casting mold.'); +INSERT INTO trade_processes VALUES(10,0,"Wayout Mix","greet","",70,65,'',75,1,39,0,10,4,15,38,0,20,2,30,'Apply Post Trade Process','Do wayout mixing in mixing bowl.'); +INSERT INTO trade_processes VALUES(11,0,"Wayout Baking","","",0,0,'',75,1,39,0,10,4,15,38,0,20,2,30,'Apply Post Trade Process','Do wayout baking.'); +INSERT INTO trade_processes VALUES(12,0,"Flaming weapon","","",0,0,'',75,1,0,0,0,0,0,0,0,0,0,0,'Apply Post Trade Process','Flame on.'); Modified: trunk/src/server/database/mysql/upgrade_schema.sql =================================================================== --- trunk/src/server/database/mysql/upgrade_schema.sql 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/database/mysql/upgrade_schema.sql 2012-02-25 17:02:05 UTC (rev 8088) @@ -1688,6 +1688,14 @@ ALTER TABLE `spells` MODIFY COLUMN `max_power` FLOAT(4,2) DEFAULT 1; +INSERT INTO math_scripts VALUES( "Apply Post Trade Process", +"NewItem:SetItemModifier(0, OldItem:GetItemModifier(0)); +NewItem:SetItemModifier(1, OldItem:GetItemModifier(1)); +NewItem:SetItemModifier(2, OldItem:GetItemModifier(2)); +" ); + +ALTER TABLE `planeshift`.`trade_processes` ADD COLUMN `script` VARCHAR(255) NOT NULL DEFAULT 'Apply Post Trade Process' COMMENT 'A script to run after a process has completed. In order to apply custom effects to the result.' AFTER `secondary_quality_factor`; + # Insert your upgrade before this line. Remember when you set a new db_version # to update the server_options.sql file and update psserver.cpp as well. # This to ensure that everything is working if you use the create_all.sql to Modified: trunk/src/server/workmanager.cpp =================================================================== --- trunk/src/server/workmanager.cpp 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/workmanager.cpp 2012-02-25 17:02:05 UTC (rev 8088) @@ -2614,6 +2614,27 @@ return time; } +void WorkManager::ApplyProcessScript(psItem* oldItem, psItem* newItem, gemActor* worker, psTradeProcesses* process) +{ + //Check if the process is valid (not null) and that the scriptname contains something and + //it's not an empty string + if(process && process->GetScriptName().Length()) + { + //Checks if there is need to load the script + psserver->GetMathScriptEngine()->CheckAndUpdateScript(process->GetScript(), process->GetScriptName()); + //If it could be loaded run it. + if(process->GetScript().IsValid()) + { + MathEnvironment env; + env.Define("OldItem", oldItem); + env.Define("NewItem", newItem); + env.Define("Worker", worker); + env.Define("Process", process); + process->GetScript()->Evaluate(&env); + } + } +} + ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Combine transform all items in container into a new item psItem* WorkManager::CombineContainedItem(uint32 newId, int newQty, float itemQuality, psItem* containerItem) @@ -2708,14 +2729,14 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transform the container into a new item -psItem* WorkManager::TransformSelfContainerItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality) +psItem* WorkManager::TransformSelfContainerItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process) { return NULL; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transform the one items in container into a new item -psItem* WorkManager::TransformContainedItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality) +psItem* WorkManager::TransformContainedItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process) { if (!oldItem) { @@ -2736,24 +2757,37 @@ INVENTORY_SLOT_NUMBER oldslot = oldItem->GetLocInParent(false); - // Remove items from container and destroy it + // Remove items from container container->RemoveFromContainer(oldItem, owner->GetClient()); + + //Destroy the old item if (!oldItem->Destroy()) { Error2("TransformContainedItem() could not remove old item ID #%u from database", oldItem->GetUID()); return NULL; } + + psItem* newItem = NULL; + if(newId > 0) + { + //Create item and save it to item instances + psItem* newItem = CreateTradeItem(newId, newQty, itemQuality); + //As the item wasn't consumed apply the process script on it + if(newItem) //just a slight integrity check. + { + ApplyProcessScript(oldItem, newItem, owner, process); + } + } + delete oldItem; - // Check for consumed item - if (newId <= 0) - return NULL; - - // Create item and save it to item instances - psItem* newItem = CreateTradeItem(newId, newQty, itemQuality); if(!newItem) { - Error2("CreateTradeItem() could not create new item ID #%u", newId); + // Check for consumed item + if(newId > 0) + { + Error2("CreateTradeItem() could not create new item ID #%u", newId); + } return NULL; } @@ -2797,7 +2831,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transform all items in equipment into a new item -psItem* WorkManager::TransformSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality) +psItem* WorkManager::TransformSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process) { // Remove items from slot and destroy it psItem *oldItem = owner->GetCharacterData()->Inventory().RemoveItem(NULL,slot); @@ -2813,17 +2847,28 @@ Error2("TransformSlotItem() could not remove old item ID #%u from database", oldItem->GetUID()); return NULL; } - delete oldItem; - // Check for consumed item - if (newId <= 0) - return NULL; + psItem* newItem = NULL; + if(newId > 0) + { + //Create item and save it to item instances + newItem = CreateTradeItem(newId, newQty, itemQuality); + //As the item wasn't consumed apply the process script on it + if(newItem) //just a slight integrity check. + { + ApplyProcessScript(oldItem, newItem, owner, process); + } + } - // Create item - psItem* newItem = CreateTradeItem(newId, newQty, itemQuality); + delete oldItem; + if(!newItem) { - Error2("CreateTradeItem() could not create new item ID #%u", newId); + // Check for consumed item + if(newId > 0) + { + Error2("CreateTradeItem() could not create new item ID #%u", newId); + } return NULL; } @@ -2867,7 +2912,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transform all items in equipment into a new item -psItem* WorkManager::TransformTargetSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality) +psItem* WorkManager::TransformTargetSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process) { // Remove items from targeted slot and destroy it psItem *oldItem = gemTarget->GetCharacterData()->Inventory().RemoveItem(NULL,slot); @@ -2883,17 +2928,28 @@ Error2("TransformSlotItem() could not remove old item ID #%u from database", oldItem->GetUID()); return NULL; } + + psItem* newItem = NULL; + if(newId > 0) + { + //Create item and save it to item instances + newItem = CreateTradeItem(newId, newQty, itemQuality); + //As the item wasn't consumed apply the process script on it + if(newItem) //just a slight integrity check. + { + ApplyProcessScript(oldItem, newItem, owner, process); + } + } + delete oldItem; - // Check for consumed item - if (newId <= 0) - return NULL; - - // Create item - psItem* newItem = CreateTradeItem(newId, newQty, itemQuality); if(!newItem) { - Error2("CreateTradeItem() could not create new item ID #%u", newId); + // Check for consumed item + if(newId > 0) + { + Error2("CreateTradeItem() could not create new item ID #%u", newId); + } return NULL; } @@ -2948,7 +3004,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transforms the targeted item into a new item -psItem* WorkManager::TransformTargetItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality) +psItem* WorkManager::TransformTargetItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process) { if (!oldItem) { @@ -2973,19 +3029,28 @@ Error2("TransformTargetItem() could not destroy old item ID #%u from database", oldItem->GetUID()); return NULL; } - delete oldItem; + psItem* newItem = NULL; + if(newId > 0) + { + //Create item and save it to item instances + newItem = CreateTradeItem(newId, newQty, itemQuality, true); + //As the item wasn't consumed apply the process script on it + if(newItem) //just a slight integrity check. + { + ApplyProcessScript(oldItem, newItem, owner, process); + } + } + delete oldItem; - // Check for consumed item - if (newId <= 0) - return NULL; - - // Create item - psItem* newItem = CreateTradeItem(newId, newQty, itemQuality, true); if(!newItem) { - Error2("CreateTradeItem() could not create new item ID #%u", newId); + // Check for consumed item + if(newId > 0) + { + Error2("CreateTradeItem() could not create new item ID #%u", newId); + } return NULL; } @@ -3443,7 +3508,7 @@ case TRANSFORMTYPE_SLOT: { INVENTORY_SLOT_NUMBER slot = workEvent->GetTransformationSlot(); - psItem* newItem = TransformSlotItem(slot, result, resultQty, currentQuality ); + psItem* newItem = TransformSlotItem(slot, result, resultQty, currentQuality, workEvent->GetProcess()); if (!newItem && (result != 0)) { Error1("TransformSlotItem did not create new item in HandleWorkEvent().\n"); @@ -3459,7 +3524,7 @@ case TRANSFORMTYPE_TARGETSLOT: { INVENTORY_SLOT_NUMBER slot = workEvent->GetTransformationSlot(); - psItem* newItem = TransformTargetSlotItem(slot, result, resultQty, currentQuality ); + psItem* newItem = TransformTargetSlotItem(slot, result, resultQty, currentQuality, workEvent->GetProcess()); if (!newItem && (result != 0)) { Error1("TransformTargetSlotItem did not create new item in HandleWorkEvent().\n"); @@ -3474,7 +3539,7 @@ case TRANSFORMTYPE_TARGET: { - psItem* newItem = TransformTargetItem(workEvent->GetTranformationItem(), result, resultQty, currentQuality ); + psItem* newItem = TransformTargetItem(workEvent->GetTranformationItem(), result, resultQty, currentQuality, workEvent->GetProcess()); if (!newItem && (result != 0)) { Error1("TransformTargetItem did not create new item in HandleWorkEvent().\n"); @@ -3504,7 +3569,7 @@ case TRANSFORMTYPE_SELF_CONTAINER: { - psItem* newItem = TransformSelfContainerItem(workEvent->GetTranformationItem(), result, resultQty, currentQuality ); + psItem* newItem = TransformSelfContainerItem(workEvent->GetTranformationItem(), result, resultQty, currentQuality, workEvent->GetProcess()); if (!newItem && (result != 0)) { Error1("TransformSelfContainerItem did not create new item in HandleWorkEvent().\n"); @@ -3521,7 +3586,7 @@ case TRANSFORMTYPE_SLOT_CONTAINER: case TRANSFORMTYPE_CONTAINER: { - psItem* newItem = TransformContainedItem(workEvent->GetTranformationItem(), result, resultQty, currentQuality ); + psItem* newItem = TransformContainedItem(workEvent->GetTranformationItem(), result, resultQty, currentQuality, workEvent->GetProcess()); if (!newItem && (result != 0)) { Error1("TransformContainedItem did not create new item in HandleWorkEvent().\n"); Modified: trunk/src/server/workmanager.h =================================================================== --- trunk/src/server/workmanager.h 2012-02-21 23:35:01 UTC (rev 8087) +++ trunk/src/server/workmanager.h 2012-02-25 17:02:05 UTC (rev 8088) @@ -456,13 +456,48 @@ bool CombineWork(); bool IsIngredient(uint32 patternId, uint32 targetId); - psItem* TransformSelfContainerItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality); - psItem* TransformContainedItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality); + /** + * @param process The process which was applied in order to generate this item, if any, else NULL. + */ + psItem* TransformSelfContainerItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process); + + /** + * @param process The process which was applied in order to generate this item, if any, else NULL. + */ + psItem* TransformContainedItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process); psItem* CombineContainedItem(uint32 newId, int newQty, float itemQuality, psItem* containerItem); - psItem* TransformSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality); - psItem* TransformTargetSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality); - psItem* TransformTargetItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality); + + /** + * @param process The process which was applied in order to generate this item, if any, else NULL. + */ + psItem* TransformSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process); + + /** + * @param process The process which was applied in order to generate this item, if any, else NULL. + */ + psItem* TransformTargetSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process); + + /** + * @param process The process which was applied in order to generate this item, if any, else NULL. + */ + psItem* TransformTargetItem(psItem* oldItem, uint32 newId, int newQty, float itemQuality, psTradeProcesses* process); void TransformTargetItemToNpc(psItem* workItem, Client* client); + + /** + * Applies the mathscript defined for the process over items being produced. + * + * It checks if there is a mathscript defined (empty string to disable), + * if it's defined it will try to recover the mathscript if available, + * if it succeeds it sets NewItem OldItem Worker and Process in the math environment + * and runs the script. The function has no return as the mathscript is supposed to apply the effects + * directly on the targets passed in the environmnent. + * + * @param oldItem The item which is going to be destructed (the old item). + * @param newItem The newly created item. + * @param worker The actor which is working on the item. + * @param process The process applied to create the new item by the worker. + */ + void ApplyProcessScript(psItem* oldItem, psItem* newItem, gemActor* worker, psTradeProcesses* process); // bool TransformHandItem(uint32 newId, int newQty, float itemQuality); //bool SendItemUpdate( INVENTORY_SLOT_NUMBER slotID, psItem *newItem ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |