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

  1. -- sofa character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5. --        local sofa = retrieveStateObject("seat");
  6.         local sofa = getStoredOrSender("seat", msg)
  7.  
  8.  
  9.         
  10.         if (not sofa) then
  11.             -- sofa does not exist anymore
  12.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  13.             sendMsg("emoThink", getParent().walkSO);
  14.             exitStateMachine();
  15.         else
  16.             storeStateObject("sofa", sofa);
  17.         end
  18.         
  19.         --freeHands(getParent());
  20.     end )
  21.     
  22.     onExit(function(msg)
  23. --        local sofa = retrieveStateObject("sofa");
  24. --        getParent().unlockActionPoints(sofa);
  25. --        getParent().stopAllActivities(sofa);
  26. --        removeStateObject("sofa");
  27.  
  28.         unlockAll("sofa");
  29.         
  30.         getParent().stopAllActivities();        
  31.     end )
  32.     
  33.     -- sit down on sofa
  34.     state("sitDown")
  35.     
  36.         onEnter(function(msg)
  37.                 
  38.             local sofa = retrieveStateObject("sofa");
  39.             local actionPointName = retrieveData("actionPointName");
  40.             
  41.             if (getParent().isActionPointLocked(sofa, actionPointName)) then
  42.                 -- action point is locked
  43.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  44.                 sendMsg("emoThink", getParent().walkSO);
  45.                 freeHands(getParent());
  46.                 exitStateMachine();
  47.             else
  48.                 getParent().lockActionPoint(sofa, actionPointName);
  49.                 setPose("sitdownArmchair");
  50.                 sofa.playSound("Sofa setzen");
  51.             end
  52.             
  53.         end )
  54.     
  55.         onMsg("end", function(msg)
  56.         
  57.             if testCancel() then
  58.                 setState("standUp");
  59.             else
  60.                 setState("readSitting");
  61.             end
  62.  
  63.         end )    
  64.     
  65.         
  66.         
  67.     -- stand up from sofa
  68.     state("readSitting")
  69.     
  70.         onEnter(function(msg)
  71.         
  72.             -- remove closed book
  73.             getParent().detachLeftObjectHolder();    
  74.             local book = retrieveStateObject("book");
  75.             if (book) then book.deleteGameObject(); end
  76.             
  77.             -- load open book
  78.             book = getParent().loadGameObject("StandardGO","bookOpen");
  79.             if (not book) then
  80.                 print("create bookOpen failed");
  81.             end
  82.             storeStateObject("book", book);
  83.             getParent().attachLeftObjectHolder(book);
  84.                                     
  85.             local hands = getParent().handSO;
  86.             hands.stopAnimation();
  87.             
  88.             startAnimation("readBookPage");
  89.             
  90.             local sofa = retrieveStateObject("sofa");
  91.             getParent().startActivity("sit", sofa);
  92.             print(" read activity " .. retrieveData("bookType", " UNKONWN "));
  93.             local readBook = getParent().startActivity("read" .. retrieveData("bookType", "Novel"), book);
  94.             local length, scale = getActivityLength(readBook);
  95.             storeData("length", length);
  96.             
  97.             sendDelayedMsgThis("complete", length);
  98.             sendDelayedMsgThis("turnPage", 3000);
  99.         
  100.             -- this.actionComplete();
  101.             
  102.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  103.  
  104.         end )    
  105.         
  106.         onMsg("turnPage", function(msg)
  107.             startAnimation("readBookPage");
  108.             sendDelayedMsgThis("turnPage", random(5000, 20000));
  109.         end )
  110.  
  111.         onMsg("end", function(msg)
  112.             if (testCancel()) then
  113.                 setState("standUp");
  114.             end
  115.         end )
  116.  
  117.         onMsg("queue", function(msg)
  118.             setState("standUp");
  119.         end )
  120.  
  121.         onMsg("complete", function(msg)
  122.             setState("standUp");
  123.         end )
  124.         
  125.         onMsg("testCancel", function(msg)
  126.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  127.                 setState("standUp");
  128.             else
  129.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  130.             end
  131.         end )
  132.         
  133.     -- stand up from sofa
  134.     state("standUp")
  135.     
  136.         onEnter(function(msg)
  137.             startAnimation("standupArmchair");
  138.             
  139.             
  140.             local sofa = retrieveStateObject("sofa");
  141.             getParent().stopAllActivities(sofa);
  142.             
  143.             local hands = getParent().handSO;
  144.             hands.stopAnimation();
  145.             
  146.             getParent().detachLeftObjectHolder();    
  147.             local book = retrieveStateObject("book");
  148.             if (book) then 
  149.                 book.deleteGameObject();
  150.                 getParent().stopAllActivities(book);
  151.             end
  152.             
  153.         end )
  154.     
  155.         onMsg("end", function(msg)
  156.             exitStateMachine();
  157.         end )    
  158.     
  159.  
  160.     
  161. endStateMachine()
  162.