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

  1. -- boxing character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local hifi = getStateObjectFromID(msg.sender);
  6.         storeStateObject("hifi", hifi);
  7.         
  8.         if (hifi) then
  9.             -- hifi does exist
  10.             if exitIfWrongPosition(getParent(), hifi, retrieveData("actionPointName")) then return end;            
  11.         
  12.             --local actionPoint = getParent().getClosestFreeActionPoint(getParent(), hifi, {"dance1", "dance2"});
  13.             local actionPointName = retrieveData("actionPointName");
  14.             local actionPoint = getParent().getFreeActionPoint(hifi, actionPointName);
  15.             
  16.             if (not actionPoint) then
  17.                 -- action points is locked
  18.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  19.                 sendMsg("emoThink", getParent().walkSO);
  20.                 exitStateMachine();
  21.             else
  22.                 getParent().lockActionPoint(hifi, actionPoint.getName());
  23.             end
  24.         else
  25.             -- sink does not exist anymore
  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.         print("exit hifi");
  37. --        local hifi = retrieveStateObject("hifi");
  38. --        getParent().stopAllActivities(hifi);
  39. --        getParent().unlockActionPoints(hifi);
  40. --        removeStateObject("hifi");
  41.         
  42.         unlockAll("hifi");
  43.         
  44.         getParent().stopAllActivities();        
  45.     end )
  46.     
  47.     -- dance
  48.     state("dance")
  49.     
  50.         onEnter(function(msg)
  51.             startAnimation("danceElaine", false, retrieveData("scale", 1.0));
  52.             
  53.             local hifi = retrieveStateObject("hifi");
  54.             local dance = getParent().startActivity("dance", hifi);
  55.             local length, scale = getActivityLength(dance);
  56.             storeData("scale", scale);
  57.             
  58.             sendMsg("addListener", hifi);
  59.             sendDelayedMsgThis("stopDancing", length);
  60.             
  61.             local numListeners = hifi.retrieveData("numListeners", 0);
  62.             
  63.             --print("start dance with ", numListeners);
  64.             
  65.             if (numListeners > 1) then
  66.                 getParent().startActivity("flirtDancing", hifi);
  67.             end
  68.             
  69.                         
  70.         end )
  71.  
  72.         onExit(function(msg)
  73.             local hifi = retrieveStateObject("hifi");
  74.             sendMsg("removeListener", hifi);
  75.         end )
  76.         
  77.         onMsg("stopDancing", function(msg)
  78.             exitStateMachine();
  79.         end )
  80.         
  81.  
  82.         onMsg("end", function(msg)
  83.             local s = getParent().getGameObjectServer();
  84.             
  85.             if testCancel() or (s.addListener(0) == 0) then
  86.                 --exitStateMachine();
  87.                 sendMsgThis("stopDancing");
  88.             else
  89.                 startAnimation("danceElaine", false, retrieveData("scale", 1.0));
  90.                 
  91.                 local hifi = retrieveStateObject("hifi");
  92.                 local numListeners = hifi.retrieveData("numListeners");
  93.                 if (numListeners == nil) then numListeners = 0 end
  94.                 
  95.                 --print("keep dance with ", numListeners);
  96.  
  97.                 if (numListeners > 1) then
  98.                     if (not getParent().hasActivity("flirtDancing", hifi)) then
  99.                         --print("start flirtDancing");
  100.                         getParent().startActivity("flirtDancing", hifi);
  101.                     end
  102.                 else
  103.                     if (getParent().hasActivity("flirtDancing", hifi)) then
  104.                         --print("end flirtDancing");
  105.                         getParent().stopActivity("flirtDancing", hifi);
  106.                     end
  107.                 end
  108.             end
  109.         end )    
  110.             
  111.         
  112. endStateMachine()
  113.