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

  1. -- chair character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         print("chair character state machine onEnter");
  7.         local chair = retrieveStateObject("chair");
  8.         if (not chair) then chair = getStateObjectFromID(msg.sender); end;        
  9.         storeStateObject("chair", chair);
  10.         
  11.         if (chair) then
  12.         
  13.             if exitIfWrongPosition(getParent(), chair, retrieveData("actionPointName")) then return end;    
  14.         
  15.             --chair does exist
  16.             if (getParent().isOneActionPointLocked(chair)) then
  17.                 -- action point is locked
  18.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  19.                 sendMsg("emoThink", getParent().walkSO);
  20.                 exitStateMachine();
  21.             else
  22.                 getParent().lockActionPoints(chair);
  23.                 -- check wich side of chair
  24.                 local actionPointName = retrieveData("actionPointName");
  25.                 print(actionPointName);
  26.                 
  27.                 -- coming from left behind
  28.                  if (actionPointName == "sit2") then
  29.                     storeData("mirrorAnims", true);
  30.                 else
  31.                     storeData("mirrorAnims", false);
  32.                 end
  33.                 
  34.                 -- coming from front
  35.                  if (actionPointName == "sit3") then
  36.                     storeData("fromFront", true);
  37.                 else
  38.                     storeData("fromFront", false);
  39.                 end
  40.                 
  41.             end
  42.         else
  43.             -- chair does not exist anymore
  44.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  45.             sendMsg("emoThink", getParent().walkSO);
  46.             exitStateMachine();
  47.         end
  48.         
  49.         freeHands(getParent());
  50.     end )
  51.     
  52.     onExit(function(msg)
  53. --        local chair = retrieveStateObject("chair");
  54. --        getParent().unlockActionPoints(chair);
  55. --        removeStateObject("chair");
  56.         
  57.         unlockAll("chair");
  58.         
  59.         getParent().stopAllActivities();
  60.     end )
  61.     
  62.     -- sit down on chair
  63.     state("sitDown")
  64.     
  65.         onEnter(function(msg)
  66.         print("sitDown onEnter");
  67.             local chair = retrieveStateObject("chair");
  68.             
  69.             if (retrieveData("fromFront") == true) then
  70.                 setPose("sitdownChairHandsDown");
  71.                 sendDelayedMsgThis("sitSound", 2000);
  72.             else
  73.                 setPose("sitdownChair", retrieveData("mirrorAnims"));
  74.                 chair.startAnimation("ChairSitdown");
  75.                 chair.playSound("Stuhl hinsetzen");
  76.                 -- send a delayed message for sit sound
  77.                 sendDelayedMsgThis("sitSound", 3000);
  78.             end
  79.             
  80.             
  81.         end )
  82.     
  83.         onMsg("end", function(msg)
  84.             setCurrentPosition();
  85.             if testCancel() then
  86.                 setState("standUp");
  87.             else
  88.                 local chair = retrieveStateObject("chair");
  89.                 getParent().startActivity("sit", chair);
  90.                 sendDelayedMsgThis("act", 5000);
  91.                 this.actionComplete();
  92.                 
  93.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  94.                 
  95.                 --notify mission that the character sat on the chair
  96.                 getParent().sendMsg(
  97.                     "sat",
  98.                     getParent().getGameObjectServer().mission, 
  99.                     tostring(chair.getUniqueID()) );
  100.  
  101.             end
  102.         end )    
  103.     
  104.         onMsg("queue", function(msg)
  105.             setState("standUp");
  106.         end )        
  107.     
  108.         onMsg("sitSound", function(msg)
  109.             local chair = retrieveStateObject("chair");
  110.             --chair.playSound("Stuhl setzen");
  111.             makeChairSound(chair, "Down");
  112.         end )    
  113.         
  114.         onMsg("act", function(msg)
  115.             doSomething();
  116.             sendDelayedMsgThis("act", 5000);
  117.         end )
  118.         
  119.         onMsg("testCancel", function(msg)
  120.             if testCancel() or (this.getParent().getActivityQueueCount() > 1) or (not this.getParent().getCurrentActivityGain()) then
  121.                 setState("standUp");
  122.             else
  123.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  124.             end
  125.         end )
  126.         
  127.     -- stand up from chair
  128.     state("standUp")
  129.     
  130.         onEnter(function(msg)
  131.             local chair = retrieveStateObject("chair");
  132.             getParent().stopAllActivities(chair);
  133.         
  134.             if (retrieveData("fromFront") == true) then
  135.                 startAnimation("standupChairHandsDown");
  136.                 sendDelayedMsgThis("upSound", 500);
  137.             else
  138.                 startAnimation("standupChair", retrieveData("mirrorAnims"));
  139.                 chair.startAnimation("ChairSitdown", -1);
  140.                 sendDelayedMsgThis("upSound", 900);
  141.             end
  142.  
  143.         end )
  144.         
  145.         
  146.         onMsg("upSound", function(msg)
  147.             local chair = retrieveStateObject("chair");
  148.             makeChairSound(chair, "Up");
  149.         end )    
  150.     
  151.         onMsg("end", function(msg)
  152.             if (retrieveData("fromFront") == true) then
  153.                 flipPoseDirection();
  154.                 print("flip");
  155.             end;
  156.             setCurrentPosition();
  157.             exitStateMachine();
  158.         end )    
  159.     
  160. endStateMachine()