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

  1. -- bookshelf  state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         if (repairMenu()) then return end
  7.         
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button;
  11.         button = addPieMenuButton("pm_takeBoardgame", "takeBoardgame");
  12.         button.addDescription(ACTIVITY, "playBoardgame");
  13.  
  14.         button = addPieMenuButton("pm_takeNovel", "takeBook", "Novel");
  15.         button.addDescription(ACTIVITY, "readNovel");
  16.  
  17.         button = addPieMenuButton("pm_takeSpecBook", "takeBook", "SpecBook");
  18.         button.addDescription(ACTIVITY, "readSpecBook");
  19.  
  20.     end )
  21.  
  22.     onMsg("takeBoardgame", function(msg)
  23.         -- get the game object server
  24.         local gameObjectServer = getGameObjectServer();
  25.         -- get character who initiated this action
  26.         local character = getStateObjectFromID(msg.sender);
  27.         
  28.         -- check if activity if possible
  29.         local possible, result, activity = activityPossible(character, msg.name, this);
  30.                                   
  31.         -- don't care if timeslot is not fulfilled
  32.         if (possible or enumCompare(result, TIMESLOT)) then
  33.             -- walk to the closest action point
  34.             local actionPoint = character.getFreeActionPoint(this, "take1");
  35.             -- get the walk state object
  36.             local wso = character.walkSO;
  37.             if (actionPoint) then
  38.                 -- create state machine contexts
  39.                 local wsoContext = StateMachineContext();
  40.                 -- store the action point
  41.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  42.                 wsoContext.storeStateObject("bookshelf", this);
  43.                 if (wso.walkToActionPoint(actionPoint)) then
  44.                     wso.queueStateMachine("bookshelfChar.takeBoardgame", this, wsoContext);
  45.                 else
  46.                     print("no path found");
  47.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  48.                 end
  49.             else
  50.                 print("no action point found");
  51.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  52.             end
  53.         else
  54.             -- activity not possible
  55.             print(msg.name .. " not possible");
  56.             
  57.             local emoticon;
  58.             if (enumCompare(result, NO_CONDITION)) then
  59.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  60.             else
  61.                 emoticon = EMOTICON_CANNOT;
  62.             end
  63.             instantAbort(character, emoticon, "emoThink");
  64.         end
  65.     end )
  66.     
  67.  
  68.     onMsg("takeBook", function(msg)
  69.         -- get the game object server
  70.         local gameObjectServer = getGameObjectServer();
  71.         -- get character who initiated this action
  72.         local character = getStateObjectFromID(msg.sender);
  73.         -- walk to the closest action point
  74.         local actionPoint = character.getFreeActionPoint(this, "take1");
  75.         
  76.         -- check if activity if possible
  77.         local possible, result, activity = activityPossible(character, msg.name, this);
  78.                                
  79.         -- don't care if timeslot is not fulfilled
  80.         if (possible or enumCompare(result, TIMESLOT)) then
  81.             -- get the walk state object
  82.             local wso = character.walkSO;
  83.             if (actionPoint) then
  84.                 -- create state machine contexts
  85.                 local wsoContext = StateMachineContext();
  86.                 -- store the action point
  87.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  88.                 wsoContext.storeData("bookType", msg.data);
  89.                 wsoContext.storeStateObject("bookshelf", this);
  90.                 if (wso.walkToActionPoint(actionPoint)) then
  91.                     wso.queueStateMachine("bookshelfChar.takeBook", this, wsoContext);
  92.                 else
  93.                     print("no path found");
  94.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  95.                 end
  96.             else
  97.                 print("no action point found");
  98.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  99.             end
  100.         else
  101.             -- activity not possible
  102.             print(msg.name .. " not possible");
  103.             
  104.             local emoticon;
  105.             if (enumCompare(result, NO_CONDITION)) then
  106.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  107.             else
  108.                 emoticon = EMOTICON_CANNOT;
  109.             end
  110.             instantAbort(character, emoticon, "emoThink");
  111.         end
  112.  
  113.     end )
  114.     
  115.  
  116.             
  117. endStateMachine()
  118.