/////////////////////////////////////////////////////////////////////////////// // npcact_p_harvest - NPC ACTIVITIES 6.0 Profession "Harvester" // By Deva Bryson Winblood. 09/08/2004 Modified: 01/17/2006 //----------------------------------------------------------------------------- // PURPOSE: This profession handles harvesting natural resources. It is good // for Lumberjacks, farmers, miners, etc. //----------------------------------------------------------------------------- // sProfHarvestLoc - Location to Harvest // sProfHarvestPlace - Placeable or Waypoint to use for Harvesting // sProfHarvestTool - Tool Required when Harvesting // sProfHarvestToolRes - ResRef for Tool // nProfHarvestToolFR - Tool Fatigue Rate // sProfHarvestToolLoc - Location to go to to purchase tool // sProfHarvestToolFrom - Person to by the tool from // nProfHarvestToolCost - Cost for the tool // sProfHarvestMethod - Method used to harvest // sProfHarvestRes - Type of resource produced ResRef // sProfHarvestDeliverLoc - Location to deliver resource // sProfHarvestTag - Tag of Resource Type // nProfHarvestStack - Stack Size of resource produced // nProfHarvestShift - How many units of resource produced per shift // nProfHarvestWage - Wage paid at the end of the shift // nProfHarvestWear - Tool wear per resource harvested /////////////////////////////////////////////////////////////////////////////// #include "npcact_h_prof" #include "npcact_h_money" //////////////////////////////// // PROTOTYPES //////////////////////////////// //////////////////////////////////////////////////////////////////////// MAIN void main() { object oMe=OBJECT_SELF; object oOb; int nN; string sS; int nState=GetLocalInt(oMe,"nProfState"); int nSpeed=GetLocalInt(oMe,"nGNBStateSpeed"); string sHarvLoc=GetLocalString(oMe,"sProfHarvestLoc"); string sHarvPlc=GetLocalString(oMe,"sProfHarvestPlace"); string sToolTag=GetLocalString(oMe,"sProfHarvestTool"); string sToolRes=GetLocalString(oMe,"sProfHarvestRes"); string sToolLoc=GetLocalString(oMe,"sProfHarvestToolLoc"); string sToolFrom=GetLocalString(oMe,"sProfHarvestToolFrom"); int nToolCost=GetLocalInt(oMe,"nProfHarvestToolCost"); string sHarvMeth=GetLocalString(oMe,"sProfHarvestMethod"); string sHarvRes=GetLocalString(oMe,"sProfHarvestRes"); string sDeliverLoc=GetLocalString(oMe,"sProfHarvestDeliverLoc"); string sHarvTag=GetLocalString(oMe,"sProfHarvestTag"); int nShiftLen=GetLocalInt(oMe,"nProfHarvestShift"); int nWage=GetLocalInt(oMe,"nProfHarvestWage"); int nShiftCount=GetLocalInt(oMe,"nProfHarvestShiftCount"); int nStack=GetLocalInt(oMe,"nProfHarvestStack"); int nWear=GetLocalInt(oMe,"nProfHarvestWear"); int nCurrency=GetLocalInt(oMe,"nCurrency"); object oItem; if (nSpeed<1) nSpeed=6; if (nStack<1) nStack=1; SetLocalInt(oMe,"bGNBProfessions",TRUE); // professions controls if (GetStringLength(sHarvLoc)>0&&GetStringLength(sHarvRes)>0&&nShiftLen>=nShiftCount) { // some critical information exists SetLocalInt(oMe,"nGNBProfProc",1); SetLocalInt(oMe,"nGNBProfFail",nSpeed+3); switch(nState) { case 0: { // choose head to location or get tool if (GetStringLength(sToolTag)>0) { // should have a tool oOb=GetItemPossessedBy(oMe,sToolTag); if (GetIsObjectValid(oOb)) { // has tool SetLocalInt(oMe,"nProfState",1); // go to work } // has tool else { // go get tool SetLocalInt(oMe,"nProfState",7); // go get tool } // go get tool } // should have a tool else { // no tool SetLocalInt(oMe,"nProfState",1); // go to work } // no tool break; } // choose head to location or get tool case 1: { // head to work location oOb=GetNearestObjectByTag(sHarvLoc,oMe,1); if (GetIsObjectValid(oOb)==FALSE) oOb=GetObjectByTag(sHarvLoc); if (GetIsObjectValid(oOb)) { // location exists if (GetArea(oOb)!=GetArea(oMe)||GetDistanceBetween(oMe,oOb)>2.5) { // move to destination fnMoveToDestination(oMe,oOb); } // move to destination else { // arrived if (GetStringLength(sHarvPlc)>0) { SetLocalInt(oMe,"nProfState",2); } else { SetLocalInt(oMe,"nProfState",3); } } // arrived } // location exists else { // error AssignCommand(oMe,SpeakString("ERROR: I am missing my sProfHarvestLoc variable or the destination does not exist!")); SetLocalInt(oMe,"nProfState",9); } // error break; } // head to work location case 2: { // move to placeable or location oOb=GetNearestObjectByTag(sHarvPlc,oMe,1); if (GetIsObjectValid(oOb)==FALSE) oOb=GetObjectByTag(sHarvPlc); if (GetIsObjectValid(oOb)) { // placeable exists if (GetArea(oOb)!=GetArea(oMe)||GetDistanceBetween(oMe,oOb)>2.5) { // move to destination fnMoveToDestination(oMe,oOb); } // move to destination else { // arrived SetLocalInt(oMe,"nProfState",3); } // arrived } // placeable exists else { // error AssignCommand(oMe,SpeakString("ERROR: The value stored in sProfHarvestPlace does not correspond to an object tag!")); SetLocalInt(oMe,"nProfState",9); } // error break; } // move to placeable or location case 3: { // do harvest method if (GetStringLength(sHarvMeth)>0) { // harvest method exists DeleteLocalInt(oMe,"bPROFActDone"); SetLocalInt(oMe,"nProfState",4); if (GetStringLength(sToolTag)>0) { oOb=GetItemPossessedBy(oMe,sToolTag); } fnPROFActionMethod(sHarvMeth,oOb,oMe); } // harvest method exists else { // no harvest method AssignCommand(oMe,SpeakString("ERROR: The value sProfHarvestMethod is not defined! A method is needed.")); SetLocalInt(oMe,"nProfState",9); } // no harvest method break; } // do harvest method case 4: { // limbo waiting state if (GetLocalInt(oMe,"bPROFActDone")) { SetLocalInt(oMe,"nProfState",5); } break; } // limbo waiting state case 5: { // produce resource and wear on tool oOb=CreateItemOnObject(sHarvRes,oMe,nStack); if (GetIsObjectValid(oOb)==TRUE) { // valid if (nWear>0) { // wearing of tools is possible oOb=GetItemPossessedBy(oMe,sToolTag); if (GetIsObjectValid(oOb)) { // tool exists nN=GetLocalInt(oOb,"nWearing"); nN=nN+nWear; SetLocalInt(oOb,"nWearing",nN); if (nN>99) { // tool breaks AssignCommand(oMe,SpeakString("My "+GetName(oOb)+" has broken.")); DestroyObject(oOb); } // tool breaks } // tool exists } // wearing of tools is possible SetLocalInt(oMe,"nProfState",6); } // valid else { // error AssignCommand(oMe,SpeakString("ERROR: The resref stored in sProfHarvestRes does not actually correspond to an item!")); SetLocalInt(oMe,"nProfState",9); } // error break; } // produce resource and wear on tool case 6: { // deliver resources oOb=GetNearestObjectByTag(sDeliverLoc,oMe,1); if (GetIsObjectValid(oOb)==FALSE) oOb=GetObjectByTag(sDeliverLoc); if (GetIsObjectValid(oOb)) { // deliver location exists if (GetArea(oOb)!=GetArea(oMe)||GetDistanceBetween(oOb,oMe)>2.5) { // move to deliver location fnMoveToDestination(oMe,oOb); } // move to deliver location else { // arrived AssignCommand(oMe,SetFacingPoint(GetPosition(oOb))); if ((GetObjectType(oOb)==OBJECT_TYPE_PLACEABLE&&GetHasInventory(oOb)==TRUE)||GetObjectType(oOb)==OBJECT_TYPE_STORE) { // container or store oItem=GetItemPossessedBy(oMe,sHarvTag); if (GetIsObjectValid(oItem)) { // items to place AssignCommand(oMe,ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,3.0)); sS=GetResRef(oItem); nN=GetItemStackSize(oItem); DestroyObject(oItem); CreateItemOnObject(sS,oOb,nN); } // items to place else { // no more items nShiftCount++; SetLocalInt(oMe,"nProfHarvestShiftCount",nShiftCount); if (nShiftCount==nShiftLen) { SetLocalInt(oMe,"nProfState",9); } else { DeleteLocalInt(oMe,"nProfState"); } } // no more items } // container or store else { // drop stuff oOb=GetItemPossessedBy(oMe,sHarvTag); if (GetIsObjectValid(oOb)) { // drop it AssignCommand(oMe,ActionPutDownItem(oOb)); } // drop it else { // no more items nShiftCount++; SetLocalInt(oMe,"nProfHarvestShiftCount",nShiftCount); if (nShiftCount==nShiftLen) { SetLocalInt(oMe,"nProfState",9); } else { DeleteLocalInt(oMe,"nProfState"); } } // no more items } // drop stuff } // arrived } // deliver location exists else { // drop the stuff where I stand oOb=GetItemPossessedBy(oMe,sHarvTag); if (GetIsObjectValid(oOb)) { // drop it AssignCommand(oMe,ActionPutDownItem(oOb)); } // drop it else { // no more items nShiftCount++; SetLocalInt(oMe,"nProfHarvestShiftCount",nShiftCount); if (nShiftCount==nShiftLen) { SetLocalInt(oMe,"nProfState",9); } else { DeleteLocalInt(oMe,"nProfState"); } } // no more items } // drop the stuff where I stand break; } // deliver resources case 7: { // go to tool purchase location oOb=GetNearestObjectByTag(sToolLoc,oMe,1); if (GetIsObjectValid(oOb)==FALSE) oOb=GetObjectByTag(sToolLoc); if (GetIsObjectValid(oOb)) { // tool location exists if (GetArea(oOb)!=GetArea(oMe)||GetDistanceBetween(oMe,oOb)>2.5) { // move fnMoveToDestination(oMe,oOb); } // move else { // arrived SetLocalInt(oMe,"nProfState",8); } // arrived } // tool location exists else { // error AssignCommand(oMe,SpeakString("ERROR: The value in sProfHarvestToolLoc does not produce an actual destination!")); SetLocalInt(oMe,"nProfState",9); } // error break; } // go to tool purchase location case 8: { // purchase tool oOb=GetNearestObjectByTag(sToolFrom,oMe,1); if (GetIsObjectValid(oOb)==FALSE) oOb=GetObjectByTag(sToolFrom); if (GetIsObjectValid(oOb)) { // tool purchase from valid if (GetArea(oMe)!=GetArea(oOb)||GetDistanceBetween(oMe,oOb)>2.5) { // move fnMoveToDestination(oMe,oOb); } // move else { // arrived if (nToolCost>0&&nToolCost<=GetWealth(oMe,nCurrency)) { // have the gold to buy the tool if (GetObjectType(oOb)==OBJECT_TYPE_STORE) { // store nN=GetStoreGold(oOb); nN=nN+nToolCost; SetStoreGold(oOb,nN); TakeCoins(oMe,nToolCost,"ANY",nCurrency,TRUE); oOb=CreateItemOnObject(sToolRes,oMe); SetLocalInt(oMe,"nProfState",1); } // store else if (GetObjectType(oOb)==OBJECT_TYPE_CREATURE) { // creature AssignCommand(oOb,TakeCoins(oMe,nToolCost,"ANY",nCurrency)); AssignCommand(oMe,SpeakString("I'd like to make a purchase.")); DelayCommand(3.0,AssignCommand(oOb,SpeakString("Thank ye for the purchase."))); oOb=CreateItemOnObject(sToolRes,oMe); SetLocalInt(oMe,"nProfState",1); } // creature else { // instant create TakeCoins(oMe,nToolCost,"ANY",nCurrency,TRUE); oOb=CreateItemOnObject(sToolRes,oMe); SetLocalInt(oMe,"nProfState",1); } // instant create } // have the gold to buy the tool else if (nToolCost==0) { // free tool oOb=CreateItemOnObject(sToolRes,oMe); SetLocalInt(oMe,"nProfState",1); } // free tool else { // cannot afford the tool AssignCommand(oMe,SpeakString("I don't have enough gold to buy a tool!")); SetLocalInt(oMe,"nProfState",9); } // cannot afford the tool } // arrived } // tool purchase from valid else { // error AssignCommand(oMe,SpeakString("ERROR: The value of sProfHarvestToolFrom does not actually correspond to a store or creature!")); SetLocalInt(oMe,"nProfState",9); } // error break; } // purchase tool case 9: { // end of shift if (nWage>0&&GetItemPossessedBy(oMe,sToolTag)!=OBJECT_INVALID) { // pay wage GiveCoins(oMe,nWage,"ANY",nCurrency); } // pay wage nShiftCount=nShiftLen+10; SetLocalInt(oMe,"nProfHarvestShiftCount",nShiftCount); break; } // end of shift default: { DeleteLocalInt(oMe,"nProfState"); break; } } DelayCommand(IntToFloat(nSpeed),ExecuteScript("npcact_p_harvest",oMe)); SetLocalInt(oMe,"nGNBProfFail",nSpeed+3); SetLocalInt(oMe,"nGNBProfProc",1); } // some critical information exists else { // end DeleteLocalInt(oMe,"bGNBProfessions"); DeleteLocalInt(oMe,"nProfHarvestShiftCount"); DeleteLocalInt(oMe,"nProfState"); } // end } //////////////////////////////////////////////////////////////////////// MAIN //////////////////////////////// // FUNCTIONS ////////////////////////////////