home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Statemachine / shower.lua < prev    next >
Text File  |  2004-03-05  |  3KB  |  97 lines

  1. -- shower state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button ;
  12.         button = addPieMenuButton("pm_shower", "shower");
  13.         button.addDescription(ACTIVITY, "shower");
  14.         button.addDescription(ACTIVITY, "improveObjectTidiness");
  15.         -- button.addIcon("guiIconHygiene");
  16.     end )
  17.     
  18.     --take a shower
  19.     onMsg("shower", function(msg)
  20.         -- get the game object server
  21.         local gameObjectServer = getGameObjectServer();
  22.         -- get character who initiated this action
  23.         local character = getStateObjectFromID(msg.sender);
  24.         -- check if activity if possible
  25.         local possible, result, activity = activityPossible(character, msg.name, this);
  26.         
  27.         -- don't care if timeslot is not fulfilled
  28.         if (possible or enumCompare(result, TIMESLOT)) then
  29.             -- if this is broken: abort characters action
  30.             if abortIfBroken(character) then return end;        
  31.             -- walk to the closest action point
  32.             local actionPoint = character.getFreeActionPoint(this, "enter");
  33.             if (actionPoint) then
  34.             -- get the walk state object
  35.                 local wso = character.walkSO;
  36.                 -- create state machine contexts
  37.                 local wsoContext = StateMachineContext();
  38.                 -- store the action point
  39.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  40.                 if (wso.walkToActionPoint(actionPoint)) then
  41.                     wso.queueStateMachine("showerChar.undressOutside", this, wsoContext);
  42.                 else
  43.                     print("no pathfound");
  44.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  45.     --                character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  46.     --                sendMsg("emoThink", character.walkSO);
  47.                 end
  48.             else
  49.                 print("no action point found");
  50.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  51.     --            character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  52.     --            sendMsg("emoThink", character.walkSO);
  53.             end
  54.         else
  55.             -- activity not possible
  56.             print(msg.name .. " not possible");
  57.             
  58.             local emoticon;
  59.             if (enumCompare(result, NO_CONDITION)) then
  60.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  61.             else
  62.                 emoticon = EMOTICON_CANNOT;
  63.             end
  64.             instantAbort(character, emoticon, "emoThink");    
  65.         end
  66.     end )
  67.     
  68.     
  69.     -- repair
  70.     onMsg("repair", function(msg)
  71.     
  72.         print("onMsg repair");
  73.         -- get character who initiated this action
  74.         local character = getStateObjectFromID(msg.sender);
  75.         -- walk to the closest action point
  76.         local actionPoint = character.getFreeActionPoint(this, "repair");
  77.         -- get the walk state object
  78.         local wso = character.walkSO;
  79.         if (actionPoint) then
  80.             -- create state machine contexts
  81.             local wsoContext = StateMachineContext();
  82.             -- store the action point
  83.             wsoContext.storeData("actionPointName", actionPoint.getName());
  84.             if (wso.walkToActionPoint(actionPoint)) then
  85.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  86.             else
  87.                 print("no path found");
  88.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  89.             end
  90.         else
  91.             print("no action point found");
  92.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  93.         end
  94.     end )
  95.                 
  96. endStateMachine()
  97.