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

  1. -- kommode state machine
  2. beginStateMachine()
  3.     
  4.     onMsg("buildMenu", function(msg)
  5.     
  6.         if (repairMenu()) then return end
  7.     
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         -- get character who initiated this action
  11.         local character = getStateObjectFromID(msg.sender);
  12.         if (character) then
  13.             -- get the pie menu buttons
  14.             local outfits = character.getOutfits();
  15.             for i = 1, getn(outfits) do
  16.                 local button;
  17.                 local outfit = outfits[i];
  18.                 if not enumCompare(outfit.getID(), character.getOutfit()) then
  19.                     --print("######### outfitname: "..outfit.getName().." - outfit - "..tostring(outfit.getID()));
  20.                     button = addPieMenuButton(outfit.getName(), "outfit", tostring(outfit.getID()));
  21.                 end
  22.                 -- button.addIcon("guiIconComfort");
  23.             end
  24.         end
  25.     end )
  26.     
  27.     -- change outfit
  28.     onMsg("outfit", function(msg)
  29.         -- get the game object server
  30.         local gameObjectServer = getGameObjectServer();
  31.         -- get character who initiated this action
  32.         local character = getStateObjectFromID(msg.sender);
  33.         
  34.         -- check if activity if possible
  35.         local possible, result, activity = activityPossible(character, msg.name, this);
  36.         
  37.         -- don't care if timeslot is not fulfilled
  38.         if (possible or enumCompare(result, TIMESLOT)) then
  39.             -- walk to the closest action point
  40.             local actionPoint = character.getClosestFreeActionPoint(character, this, {"change1", "change2"});
  41.             --local actionPoints = character.getFreeActionPoints(this, {"change1", "change2"});
  42.             if (actionPoint) then
  43.                 -- get the walk state object
  44.                 local wso = character.walkSO;
  45.                 if (wso.walkToActionPoint(actionPoint)) then            
  46.                     -- notify current mission 
  47.                     character.sendMsg("outfit", gameObjectServer.mission);
  48.     
  49.                     print("walkToActionPoint true");
  50.                     -- create state machine contexts
  51.                     local wsoContext = StateMachineContext();
  52.                     -- store the action point
  53.                     wsoContext.storeData("actionPointName", actionPoint.getName());
  54.                     -- store the outfit
  55.                     wsoContext.storeData("outfit", tonumber(msg.data));
  56.                     wso.queueStateMachine("kommodeChar.outfit", this, wsoContext);
  57.                 else
  58.                     print("no path found for actionpoint " .. actionPoint.getName());
  59.                     -- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  60.                     -- sendMsg("emoThink", character.walkSO);
  61.                     instantAbort(character, EMOTICON_NOPATH, "emoThink");
  62.                 end
  63.             else
  64.                 print("no action point found");
  65.                 -- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  66.                 -- sendMsg("emoThink", character.walkSO);
  67.                 instantAbort(character, EMOTICON_CANNOT, "emoThink");
  68.             end
  69.         else
  70.             -- activity not possible
  71.             print(msg.name .. " not possible");
  72.             
  73.             local emoticon;
  74.             if (enumCompare(result, NO_CONDITION)) then
  75.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  76.             else
  77.                 emoticon = EMOTICON_CANNOT;
  78.             end
  79.             instantAbort(character, emoticon, "emoThink");        
  80.         end
  81.     end )
  82.             
  83. endStateMachine()
  84.