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

  1. -- fridge character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local fridge = getStateObjectFromID(msg.sender);
  6.         storeStateObject("fridge", fridge);
  7.         
  8.         if (fridge) then
  9.             -- fridge does exist
  10.             
  11.             if exitIfWrongPosition(getParent(), fridge, retrieveData("actionPointName")) then return end;    
  12.             
  13.             if (getParent().isOneActionPointLocked(fridge)) then
  14.                 -- action point is locked
  15.                 print(" >>>> fridge action point is locked abort by " .. getParent().getCharacterName())
  16.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  17.                 sendMsg("emoThink", getParent().walkSO);
  18.                 exitStateMachine();
  19.             else
  20.                 print(" >>>> fridge locked by " .. getParent().getCharacterName())
  21.                 getParent().lockActionPoints(fridge);
  22.             end
  23.         else
  24.             -- fridge does not exist anymore
  25.             print(" >>>> fridge does not exist anymore abort by " .. getParent().getCharacterName())
  26.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  27.             sendMsg("emoThink", getParent().walkSO);
  28.             exitStateMachine();
  29.         end
  30.         
  31.         freeHands(getParent());
  32.  
  33.     end )
  34.     
  35.     onExit(function(msg)
  36.         local fridge = retrieveStateObject("fridge");
  37.         getParent().unlockActionPoints(fridge);
  38.         removeStateObject("fridge");
  39.     end )
  40.     
  41.     -- open the fridge
  42.     state("open")
  43.     
  44.         onEnter(function(msg)
  45.             local fridge = retrieveStateObject("fridge");
  46.             -- create the cracker box
  47.             --local crackerBox = fridge.createGameObject("CrackerBox");
  48.             -- start to open the fridge
  49.             startAnimation("openFridge");
  50.             fridge.startAnimation("fridge");
  51.             -- show the inside of the fridge
  52.             fridge.setChildEnable("fridgeIn", true);
  53.             -- show the cracker box
  54.             --fridge.setChildEnable("CrackerBox", true);
  55.             -- send a delayed message for open sound
  56.             sendDelayedMsgThis("openSound", 800);
  57.             -- send a delayed message for attach
  58.             sendDelayedMsgThis("grabBreakfast", 5000);
  59.             -- send a delayed message for close sound
  60.             sendDelayedMsgThis("closeSound", 6000);
  61.         end )
  62.     
  63.         onMsg("openSound", function(msg)
  64.             local fridge = retrieveStateObject("fridge");
  65.             fridge.playSound("fridgeOpen");
  66.             fridge.loopSound("fridgeLoop");
  67.         end)
  68.  
  69.         onMsg("grabBreakfast", function(msg)
  70.             -- attach cracker box to left hand of character
  71.             local fridge = retrieveStateObject("fridge");
  72.             --getParent().attachLeftObjectHolder(fridge, "CrackerBox");
  73.             -- attach tablet
  74.             print("create tablet");
  75.             local tabletType = retrieveData("tabletType", "tabletBreakfast");
  76.             local tablet = getParent().loadGameObject("StandardGO", tabletType);
  77.             storeStateObject("tablet", tablet);
  78.             getParent().attachLeftObjectHolder(tablet);            
  79.             fridge.playSound("fridgeTake");
  80.             
  81.             local hso = getParent().handSO;
  82.             if (not hso) then
  83.                 print("no hands found");
  84.             else
  85.                 hso.setPose("leftHandHold");
  86.             end
  87.             
  88.         end)
  89.  
  90.         onMsg("closeSound", function(msg)
  91.             local fridge = retrieveStateObject("fridge");
  92.             fridge.playSound("fridgeClose");
  93.             fridge.stopSound("fridgeLoop");
  94.         end)
  95.  
  96.         onMsg("end", function(msg)
  97.             print("end")
  98.             -- hide the inside of the fridge
  99.             local fridge = retrieveStateObject("fridge");
  100.             fridge.setChildEnable("fridgeIn", false);
  101.             
  102.             if testCancel() then
  103.                 -- detach tablet if attached to left hand
  104.                 local tablet = getParent().getLeftHeldObject();
  105.                 if (tablet) then
  106.                     getParent().detachLeftObjectHolder();
  107.                     tablet.deleteGameObject();
  108.                 end
  109.                 local hso = getParent().handSO;
  110.                 hso.stopPose();
  111.                 exitStateMachine();
  112.             else            
  113.                 setState("lookForChair");                
  114.             end
  115.         end )    
  116.         
  117.         onExit(function(msg)
  118.             -- getParent().detachObjectAnimator();
  119.         end)
  120.         
  121.         
  122.     -- look for free chair
  123.     state("lookForChair")
  124.         print("lookForChair");
  125.     
  126.         onEnter(function(msg)                
  127.                 
  128.             local tablet = retrieveStateObject("tablet");
  129.                                                 
  130.             getParent().handSO.setPose("leftHandHold");
  131.             getParent().attachLeftObjectHolder(tablet);                            
  132.             
  133.             local wsoContext = StateMachineContext();
  134.             wsoContext.storeStateObject("tablet", tablet);
  135.             wsoContext.storeStateObject("tableObject", tablet);
  136.             wsoContext.storeData("chairCommand", "eatByTableChar.sitDown");
  137.             wsoContext.storeData("checkPartnerChair", true);
  138.             queueStateMachine("tableChairChar.findChair", this, wsoContext);
  139.             exitStateMachine();
  140.         end)
  141.         
  142. --    onMsg("noPlaceToEat", function(msg)
  143. --            print("no place to eat");
  144. --            -- detach tablet if attached to left hand
  145. --            getParent().detachLeftObjectHolder();
  146. --            getParent().detachRightObjectHolder();
  147. --            local tablet = retrieveStateObject("tablet");
  148. --            if (tablet) then
  149. --                tablet.deleteGameObject();
  150. --            end
  151. --            local hso = getParent().handSO;
  152. --            hso.stopPose();
  153. --            
  154. --            getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  155. --            exitStateMachine();
  156. --            sendMsg("emoThink", getParent().walkSO);
  157. --        end)
  158.  
  159.     
  160.         
  161. endStateMachine()
  162.