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

  1. -- bathtub character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         print("bath character state machine onEnter");
  7.         local bathtub = getStateObjectFromID(msg.sender);
  8.         storeStateObject("bathtub", bathtub);
  9.         
  10.         storeData("initOutfit", getParent().getOutfit());
  11.  
  12.         if (bathtub) then
  13.             
  14.             -- bathtub  does exist
  15.             local actionPointName = retrieveData("actionPointName");
  16.             local actionPoint = getParent().getFreeActionPoint(bathtub, actionPointName);
  17.             
  18.             if exitIfWrongPosition(getParent(), bathtub, actionPointName) then return end;    
  19.                         
  20.             
  21.             if (actionPoint) then
  22.                 -- action point is free
  23.                 getParent().lockActionPoints(bathtub);
  24.                  if (actionPointName == "water2") then
  25.                     storeData("mirrorAnims", true);
  26.                 else
  27.                     storeData("mirrorAnims", false);
  28.                 end
  29.             else
  30.                 -- action point is not free anymore
  31.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  32.                 sendMsg("emoThink", getParent().walkSO);
  33.                 exitStateMachine();
  34.             end
  35.                                     
  36.         else
  37.             -- bathtub does not exist anymore
  38.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  39.             sendMsg("emoThink", getParent().walkSO);
  40.             exitStateMachine();
  41.         end
  42.         
  43.         freeHands(getParent());
  44.     end )
  45.     
  46.     
  47.     
  48.     onExit(function(msg)
  49.         local bathtub = retrieveStateObject("bathtub");
  50. --        if (bathtub) then
  51. --            getParent().unlockActionPoints(bathtub);
  52. --            getParent().stopAllActivities(bathtub);
  53. --            removeStateObject("bathtub");
  54. --        end;
  55.  
  56.         unlockAll("bathtub");
  57.         
  58.         local water = bathtub.findChildGO("water");
  59.         if (water) then
  60.             bathtub.setChildEnable("water", false);
  61.             water.stopSkeletonAnimation();
  62.         end;    
  63.     end )
  64.     
  65.     onReturn(function(msg)
  66.         print("bath character state machine onReturn");
  67.         local actionPointName = retrieveData("actionPointName");
  68.         if (actionPointName == "enter2")  then
  69.             storeData("mirrorAnims", true);
  70.         else
  71.             storeData("mirrorAnims", false);
  72.         end
  73.         setState("undressOutside");
  74.     end )
  75.     
  76.     state("openWater")
  77.     
  78.         onEnter(function(msg)
  79.             print("openWater onEnter");            
  80.             startAnimation("bathtubWater", retrieveData("mirrorAnims"));
  81.             
  82.                         
  83.             sendDelayedMsgThis("waterSound", 1500);
  84.         end )
  85.         
  86.         onMsg("waterSound", function(msg)
  87.             local bathtub = retrieveStateObject("bathtub");
  88.             bathtub.playSound("bathWaterIn");
  89.         end )    
  90.         
  91.         onMsg("end", function(msg)
  92.             if testCancel() then
  93.                 exitStateMachine();
  94.             else
  95.                 --setState("enterTub");
  96.                 local bathtub = retrieveStateObject("bathtub");
  97.                                 
  98.                 local actionPoint = getParent().getClosestFreeActionPoint(getParent(), bathtub, {"enter1", "enter2"});
  99.                                 
  100.                 if (actionPoint) then
  101.                     if (walkToPointImmediate(actionPoint)) then
  102.                         print("enterStateMachine subwalk");
  103.                         storeData("actionPointName", actionPoint.getName());
  104.                         enterStateMachine("subwalk.walk");
  105.                     else
  106.                         print("no path found");
  107.                         getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  108.                         sendMsg("emoThink", getParent().walkSO);
  109.                         exitStateMachine();
  110.                     end
  111.                 else
  112.                     print("no action point found");
  113.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  114.                     sendMsg("emoThink", getParent().walkSO);
  115.                     exitStateMachine();
  116.                 end                
  117.             end
  118.         end )            
  119.     
  120. --        onMsg("end", function(msg)
  121. --            if testCancel() then
  122. --                exitStateMachine();
  123. --            else
  124. --                --setState("enterTub");
  125. --                local bathtub = retrieveStateObject("bathtub");
  126. --                
  127. --                exitStateMachine();
  128. --                
  129. --                local actionPoint = getParent().getClosestFreeActionPoint(getParent(), bathtub, {"enter1", "enter2"});
  130. --                if (actionPoint) then
  131. --                    if (walkToActionPoint(actionPoint)) then
  132. --                        queueStateMachine("bathtubChar.undressOutside", bathtub);
  133. --                    else
  134. --                        print("no path found");
  135. --                        getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  136. --                        sendMsg("emoThink", getParent().walkSO);
  137. --                        exitStateMachine();
  138. --                    end
  139. --                else
  140. --                    print("no action point found");
  141. --                    getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  142. --                    sendMsg("emoThink", getParent().walkSO);
  143. --                    exitStateMachine();
  144. --                end
  145. --                
  146. --                
  147. --            end
  148. --        end )    
  149.     
  150.     
  151.     -- undress outside the tub
  152.     state("undressOutside")
  153.     
  154.         onEnter(function(msg)
  155.         
  156.         
  157.             local character = getParent();        
  158.             local other, result = getDisturbingChar(character, "showNaked");
  159.             if (other) then
  160.                 exitStateMachine();
  161.                 character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  162.                 other.sendMsg("emoShameChar", character.walkSO);        
  163.                 return    
  164.             end;
  165.         
  166. --            local character = getParent();
  167. --            local others = character.getCharactersInRoom();
  168. --                    
  169. --            for c = 1, getn(others) do
  170. --                local other = others[c];
  171. --                --print("checkShyness other found");
  172. --                if (not activityPossible(character, "showInUnderwear", other)) then
  173. --                    exitStateMachine();
  174. --                    --print("checkShyness sendMsg emoShame");
  175. --                    character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  176. --                    other.sendMsg("emoShameChar", character.walkSO);        
  177. --                    return    
  178. --                end;
  179. --            end;
  180. --        
  181.         
  182.             
  183.             local bathtub = retrieveStateObject("bathtub");    
  184.             if testCancel() or bathtub.isBroken() then
  185.                 exitStateMachine();
  186.             else
  187.                 --startAnimation("ausziehen2");
  188.                 startAnimation(getChangeOutfitAnim(getParent()));
  189.                 sendDelayedMsgThis("underwear", 1600);    
  190.                 
  191.                 --local water = bathtub.loadGameObjectIntoGameObject("StandardGO","bathtubWater");
  192.                 local water = bathtub.findChildGO("water");
  193.                 bathtub.setChildEnable("water", true);
  194.                 water.startSkeletonAnimation("waves");            
  195.                 --storeStateObject("water", water);
  196.             end
  197.  
  198.         end )
  199.         
  200.         onMsg("underwear", function(msg)
  201.             getParent().changeOutfit(NOTHING);
  202.         end )
  203.         
  204.     
  205.         onMsg("end", function(msg)
  206.             if testCancel() then
  207.                 local initOutfit = retrieveData("initOutfit");        
  208.                 getParent().changeOutfit(initOutfit);
  209.                 --local water = retrieveStateObject("water");
  210.                 --removeStateObject("water");
  211.                 --water.deleteGameObject();
  212.                 
  213. --                local water = bathtub.findChildGO("water");
  214. --                bathtub.setChildEnable("water", false);
  215. --                water.stopSkeletonAnimation();    
  216.                         
  217.                 exitStateMachine();
  218.             else
  219.                 setState("enterTub");
  220.                 sendDelayedMsgThis("act", 5000);
  221.             end
  222.         end )    
  223.     
  224.             
  225.  
  226.     state("enterTub")
  227.     
  228.         onEnter(function(msg)
  229.             print("enterTub onEnter");            
  230.             startAnimation("bathtubEnter", retrieveData("mirrorAnims"));
  231.             --getParent().enableBlend(true);
  232.             sendDelayedMsgThis("splashSound", 3800);
  233.         end )
  234.         
  235.         onMsg("splashSound", function(msg)
  236.             getParent().playSound("splashSoft");
  237.         end )    
  238.  
  239.     
  240.         onMsg("end", function(msg)
  241.             if testCancel() then
  242.                 setState("exitTub");
  243.             else
  244.                 setState("lay");
  245.             end
  246.         end )    
  247.     
  248.             
  249.         
  250.     -- lay
  251.     state("lay")
  252.     
  253.         onEnter(function(msg)
  254.         
  255.             local bathtub = retrieveStateObject("bathtub");            
  256.             local bath = getParent().startActivity("bath", bathtub);
  257.             local length, scale = getActivityLength(bath);
  258.             storeData("scale", scale);
  259.             
  260.             sendDelayedMsgThis("complete", length);
  261.             --actionComplete();
  262.             
  263.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  264.             
  265.             startAnimation("bathtubLay", retrieveData("mirrorAnims"));
  266.             bathtub.loopSound("bathLoop");
  267.             
  268.             dirtify(bathtub, DIRTIFY_PER_BATH);
  269.             
  270.             
  271.         end )
  272.         
  273.         onExit(function(msg)
  274.             local bathtub = retrieveStateObject("bathtub");
  275.             getParent().stopAllActivities(bathtub);
  276.             bathtub.stopSound("bathLoop");
  277.             bathtub.playSound("bathWaterOut");
  278.         end )
  279.         
  280.         onMsg("complete", function(msg)
  281.             setState("exitTub");
  282.         end )
  283.             
  284.         onMsg("queue", function(msg)
  285.             setState("exitTub");
  286.         end )
  287.             
  288.         onMsg("end", function(msg)
  289.             startAnimation("bathtubLay", retrieveData("mirrorAnims"));
  290.         end )
  291.  
  292.         onMsg("testCancel", function(msg)
  293.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  294.                 setState("exitTub");
  295.             else
  296.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  297.             end
  298.         end )            
  299.         
  300.     -- stand up from tub
  301.     state("exitTub")
  302.     
  303.         onEnter(function(msg)
  304.             print("exitTub onEnter");
  305.             startAnimation("bathtubExit", retrieveData("mirrorAnims"));
  306.             sendDelayedMsgThis("splashSound", 1000);
  307.             sendDelayedMsgThis("towel", 3000);
  308.         end )
  309.         
  310.         onMsg("splashSound", function(msg)
  311.             local bathtub = retrieveStateObject("bathtub");
  312.             bathtub.playSound("splashSoft");
  313.         end )
  314.         
  315.         onMsg("towel", function(msg)
  316.             getParent().changeOutfit(TOWEL);
  317.         end )
  318.     
  319.         onMsg("end", function(msg)
  320.             print("exitTub onExit");            
  321. --            local initOutfit = retrieveData("initOutfit");        
  322. --            print("   initOutfit onExit", initOutfit);            
  323. --            getParent().changeOutfit(initOutfit);
  324.             --local water = retrieveStateObject("water");
  325.             --water.deleteGameObject();
  326.             --getParent().enableBlend(false);
  327. --            local bathtub = retrieveStateObject("bathtub");
  328. --            
  329. --            local water = bathtub.findChildGO("water");
  330. --            water.stopSkeletonAnimation();            
  331. --            bathtub.setChildEnable("water", false);
  332.             
  333.  
  334.             exitStateMachine();
  335.         end )
  336.         
  337.  
  338.     state("cleanStart")
  339.     
  340.         onEnter(function(msg)
  341.             -- grab sponge
  342.             print("cleanStart onEnter");
  343.             local sponge = getParent().loadGameObject("StandardGO","sponge");
  344.             getParent().attachRightObjectHolder(sponge);
  345.             storeStateObject("sponge", sponge);
  346.             startAnimation("cleanBathtubStart");            
  347.         end )
  348.     
  349.         onMsg("end", function(msg)
  350.             if (testCancel()) then
  351.                 exitStateMachine();
  352.             else
  353.                 setState("clean");
  354.             end
  355.         end )    
  356.  
  357.         
  358.     -- clean up 
  359.     state("clean")
  360.     
  361.         onEnter(function(msg)
  362.             local bathtub = retrieveStateObject("bathtub");
  363.             local clean = getParent().startActivity("clean", bathtub);
  364.             local length, scale = getActivityLength(clean);
  365.             storeData("scale", scale);
  366.                         
  367.             startAnimation("cleanBathtubLoop", false, scale);
  368.             bathtub.playSound("cleanBathtub", 0.25);
  369.             
  370.                         
  371.             --sendDelayedMsgThis("complete", length);
  372.             --this.actionComplete();
  373.             
  374.         end )
  375.         
  376.         
  377.         onExit(function(msg)
  378.             local bathtub = retrieveStateObject("bathtub");
  379.             --bathtub.stopSound("cleanBathtub");
  380.         end )    
  381.         
  382.         
  383. --        onMsg("cancel", function(msg)
  384. --            
  385. --            getParent().stopActivity("clean", retrieveStateObject("bathtub"));
  386. --            setState("cleanEnd");
  387. --        end )    
  388. --    
  389. --        onMsg("gueue", function(msg)
  390. --            sendMsgThis("complete");
  391. --        end )    
  392.  
  393.         onMsg("complete", function(msg)            
  394.             getParent().stopActivity("clean", retrieveStateObject("bathtub"));
  395.             setState("cleanEnd");
  396.         end )    
  397.     
  398.         onMsg("end", function(msg)
  399.             local bathtub = retrieveStateObject("bathtub");
  400.             local dirt = bathtub.getDirtiness();
  401.             if (testCancel() or dirt<0.01) then
  402.                 sendMsgThis("complete");
  403.             else
  404.                 local scale = retrieveData("scale");
  405.                 startAnimation("cleanBathtubLoop", false, scale);            
  406.                 bathtub.playSound("cleanBathtub", 0.25);
  407.                 clean(bathtub, CLEAN_PER_LOOP);            
  408.             end
  409.         end )    
  410.                     
  411.         
  412.     state("cleanEnd")
  413.     
  414.         onEnter(function(msg)
  415.             -- remove sponge
  416.             local sponge = getParent().getRightHeldObject()
  417.             getParent().detachRightObjectHolder();
  418.             if (sponge) then sponge.deleteGameObject(); end
  419.             removeStateObject("sponge");
  420.  
  421.             startAnimation("cleanBathtubEnd");            
  422.         end )
  423.     
  424.         onMsg("end", function(msg)
  425.             if (not testCancel()) then queueNextClean(getParent()) end;
  426.             exitStateMachine();
  427.         end )    
  428.  
  429.  
  430.  
  431.             
  432.     
  433. endStateMachine()