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

  1. -- staircase character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6. --        local staircase = retrieveStateObject("staircase");
  7. --        if (not staircase) then
  8. --            -- no staircase was stored
  9. --            staircase = getStateObjectFromID(msg.sender);
  10. --            storeStateObject("staircase", staircase);
  11. --        end
  12. --    
  13.     
  14.         local staircase = getStateObjectFromID(msg.sender)
  15.         storeStateObject("staircase", staircase);
  16.         
  17.         if (getParent().isOneActionPointLocked(staircase)) then
  18.             -- action point is locked
  19.             print("staircase character onEnter: action point is locked ");
  20.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  21.             sendMsg("emoThink", getParent().walkSO);
  22.             exitStateMachine();
  23.         else
  24.             --getParent().lockActionPoints(staircase);
  25.         end
  26.         
  27.         getParent().enableBlobShadow(false);
  28.  
  29.         
  30.     end )
  31.     
  32.     onExit(function(msg)
  33. --        local staircase = retrieveStateObject("staircase");
  34. --        if (staircase) then
  35. --            getParent().unlockActionPoints(staircase);
  36. --            getParent().stopAllActivities(staircase);
  37. --            removeStateObject("staircase");
  38. --        end
  39.         unlockAll("staircase");    
  40.             
  41.         getParent().enableBlobShadow(true);
  42.         
  43.         getParent().stopAllActivities();
  44.     end )
  45.     
  46.     
  47.     state("dress")
  48.     
  49.         onEnter(function(msg)
  50.             --startAnimation("ausziehen2");
  51.             startAnimation(getChangeOutfitAnim(getParent()));
  52.             sendDelayedMsgThis("switchOutfit", 1600);
  53.         end )
  54.         
  55.         onMsg("switchOutfit", function(msg)
  56.             changeOutfit(getParent(), ARCHTYPE);
  57.         end )
  58.     
  59.         onMsg("end", function(msg)
  60.             setState(retrieveData("stateAfterDress"))
  61.         end )    
  62.     
  63.     -- go to work
  64.     state("goToWork")
  65.     
  66.         onEnter(function(msg)
  67.             print("goToWork");
  68.             
  69.             if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
  70.                 storeData("stateAfterDress", "goToWork");
  71.                 setState("dress");
  72.                 return
  73.             end
  74.                         
  75.             startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
  76.             sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
  77.             
  78.             -- deactivate walkability
  79.             getParent().setWalkability(1);
  80.         end )
  81.         
  82.         onMsg("stepSound", function(msg)
  83.             makeStepSound("Wood");
  84.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  85.         end )
  86.         
  87.         onMsg("end", function(msg)
  88.             if testCancel() then
  89.                 setState("comeFromWork")
  90.             else
  91.                 setState("atWork");
  92.             end            
  93.         end )
  94.  
  95.     state("atWork")
  96.     
  97.         onEnter(function(msg)
  98.             local workDur = getParent().getWorkDurationInGameTime();
  99.             print("atWork for " .. workDur);
  100.             sendDelayedMsgThis("comeBack", workDur);
  101.             getParent().setAtHome(false);
  102.             getParent().setAtWork(true);
  103.             local staircase = retrieveStateObject("staircase");
  104.             getParent().startActivity("work", staircase);
  105.             
  106.             -- make queue entry uncancellble
  107.             local entry = getParent().getActivityQueueEntry(0);
  108.             if (entry) then entry.setUserCancel(false); end;
  109.             
  110.          end )
  111.         
  112.         onMsg("comeBack", function(msg)
  113.             getParent().setAtHome(true);
  114.             getParent().setAtWork(false);
  115.             setState("comeFromWork");
  116.             local staircase = retrieveStateObject("staircase");
  117.             getParent().stopActivity("work", staircase);
  118.             
  119.             -- get the money for the day!
  120.             local daylyIncome = getParent().getWorkIncome();
  121.             getParent().getGameObjectServer().addMoney(daylyIncome);
  122.         end )
  123.  
  124.  
  125.     state("comeFromWork")
  126.     
  127.         onEnter(function(msg)
  128.             print("comeFromWork");
  129.             
  130.             startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
  131.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  132.         end )
  133.         
  134.         onMsg("stepSound", function(msg)
  135.             makeStepSound("Wood");
  136.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  137.         end )
  138.         
  139.         onMsg("end", function(msg)        
  140.             local partner = getOtherCharacter(getParent());                
  141.             if (partner) then
  142.                 --getParent().sendMsg("imBackAtHome", partner);
  143.             end
  144.             
  145.             -- reactivate walkability
  146.             getParent().setWalkability(0);
  147.             
  148.             flipPoseDirection();
  149.             exitAndGoAway(4.0);
  150.         end )
  151.  
  152.  
  153.  
  154.     
  155.         
  156.     -- go shoping
  157.     state("goToShop")
  158.     
  159.     
  160.         onEnter(function(msg)
  161.             print("goToShop");
  162.             
  163.             
  164.             if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
  165.                 storeData("stateAfterDress", "goToShop");
  166.                 setState("dress");
  167.                 return
  168.             end
  169.             
  170.             startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
  171.             sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
  172.             
  173.             -- deactivate walkability
  174.             getParent().setWalkability(1);
  175.         end )
  176.         
  177.         onMsg("stepSound", function(msg)
  178.             makeStepSound("Wood");
  179.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  180.         end )
  181.         
  182.         onMsg("end", function(msg)
  183.             if testCancel() then
  184.                 setState("comeFromShop")
  185.             else
  186.                 setState("atShop");
  187.             end            
  188.         end )
  189.  
  190.     state("atShop")
  191.     
  192.         onEnter(function(msg)
  193.             print("atShop");
  194.             getParent().setAtHome(false);
  195.             sendDelayedMsgThis("comeBack", random(10000, 20000));
  196.         end )
  197.         
  198.         onMsg("comeBack", function(msg)
  199.             getParent().setAtHome(true);
  200.             setState("comeFromShop");
  201.         end )
  202.  
  203.  
  204.     state("comeFromShop")
  205.     
  206.         onEnter(function(msg)
  207.             print("comeFromShop");
  208.             startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
  209.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  210.         end )
  211.         
  212.         onMsg("stepSound", function(msg)
  213.             makeStepSound("Wood");
  214.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  215.         end )
  216.         
  217.         onMsg("end", function(msg)
  218.             local partner = getOtherCharacter(getParent());                
  219.             if (partner) then
  220.                 --getParent().sendMsg("imBackAtHome", partner);
  221.             end
  222.             flipPoseDirection();
  223.             
  224.             -- reactivate walkability
  225.             getParent().setWalkability(0);
  226.             
  227.             exitStateMachine();
  228.         end )
  229.         
  230.         
  231.         
  232.  
  233.     
  234.         
  235.     -- go buy gift
  236.     state("goBuyGift")
  237.     
  238.     
  239.         onEnter(function(msg)
  240.             print("goBuyGift");
  241.             
  242.             if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
  243.                 storeData("stateAfterDress", "goBuyGift");
  244.                 setState("dress");
  245.                 return
  246.             end
  247.             
  248.             
  249.             startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
  250.             sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
  251.             
  252.             -- deactivate walkability
  253.             getParent().setWalkability(1);
  254.         end )
  255.         
  256.         onMsg("stepSound", function(msg)
  257.             makeStepSound("Wood");
  258.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  259.         end )
  260.         
  261.         onMsg("end", function(msg)
  262.             if testCancel() then
  263.                 setState("comeBuyGift")
  264.             else
  265.                 setState("atBuyGift");
  266.             end            
  267.         end )
  268.  
  269.     state("atBuyGift")
  270.     
  271.         onEnter(function(msg)
  272.             print("atBuyGift");
  273.             getParent().setAtHome(false);
  274.             sendDelayedMsgThis("comeBack", random(1000, 1000));
  275.         end )
  276.         
  277.         onMsg("comeBack", function(msg)
  278.             getParent().setAtHome(true);
  279.             setState("comeBuyGift");
  280.         end )
  281.  
  282.  
  283.     state("comeBuyGift")
  284.     
  285.         onEnter(function(msg)
  286.             print("comeBuyGift");
  287.             local gift = getParent().loadGameObject("StandardGO", "gift");
  288.             getParent().attachRightObjectHolder(gift);
  289.             getParent().handSO.setPose("rightHandHoldGift");
  290.             startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
  291.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  292.         end )
  293.         
  294.         onMsg("stepSound", function(msg)
  295.             makeStepSound("Wood");
  296.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  297.         end )
  298.         
  299.         onMsg("end", function(msg)
  300.             
  301.             local character = getParent();
  302.             local partner = getOtherCharacter(character);
  303.             
  304.             -- reactivate walkability
  305.             getParent().setWalkability(0);
  306.             
  307.             if (partner) and (partner.walkSO.getStateMachine().getName() ~= "staircaseChar") then
  308.                 print("partner for " .. character.getCharacterName() .. " to give the gift : " .. partner.getCharacterName())
  309.                 flipPoseDirection();
  310.                 character.pushCommand("pm_giveGift", "giveGift", partner);    
  311.                 exitStateMachine();            
  312.                 --getParent().sendMsg("giveGift", partner);
  313.             else            
  314.                 print("partner for " .. character.getCharacterName() .. " to give the gift : NONE")
  315.                 freeHands(character);
  316.                 flipPoseDirection();    
  317.                 exitAndGoAway();                
  318.             end
  319.             
  320.         end )        
  321.  
  322.     -- go shoping
  323.     state("goTrash")
  324.     
  325.         onEnter(function(msg)
  326.             print("goTrash");
  327.             
  328.             if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
  329.                 storeData("stateAfterDress", "goTrash");
  330.                 setState("dress");
  331.                 return
  332.             end
  333.             
  334.             startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
  335.             sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
  336.             
  337.             -- deactivate walkability
  338.             getParent().setWalkability(1);
  339.         end )
  340.         
  341.         onMsg("stepSound", function(msg)
  342.             makeStepSound("Wood");
  343.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  344.         end )
  345.         
  346.         
  347.         onMsg("end", function(msg)
  348.             setState("comeTrash")
  349.         end )
  350.  
  351.     state("comeTrash")
  352.     
  353.         onEnter(function(msg)
  354.             print("comeTrash");
  355.             local trashbag = getParent().getLeftHeldObject()
  356.             getParent().detachLeftObjectHolder()
  357.             if (trashbag) then trashbag.deleteGameObject(); end
  358.             getParent().handSO.stopPose();
  359.             startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
  360.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  361.         end )
  362.         
  363.         onMsg("stepSound", function(msg)
  364.             makeStepSound("Wood");
  365.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  366.         end )
  367.         
  368.         
  369.         onMsg("end", function(msg)                    
  370.             flipPoseDirection();
  371.             
  372.             -- reactivate walkability
  373.             getParent().setWalkability(0);
  374.             
  375.             exitAndGoAway(4.0);
  376.         end )
  377.         
  378.         
  379.         
  380.  
  381.         
  382.     -- get pizza
  383.     state("goGetPizza")
  384.     
  385.     
  386.         onEnter(function(msg)
  387.             print("goGetPizza");
  388.             
  389.             if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
  390.                 storeData("stateAfterDress", "goGetPizza");
  391.                 setState("dress");
  392.                 return
  393.             end
  394.                     
  395.             startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
  396.             sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
  397.             
  398.             -- deactivate walkability
  399.             getParent().setWalkability(1);
  400.         end )
  401.         
  402.         onMsg("stepSound", function(msg)
  403.             makeStepSound("Wood");
  404.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  405.         end )
  406.         
  407.         
  408.         onMsg("end", function(msg)
  409.             setState("comeGetPizza");
  410.         end )
  411.         
  412.     state("comeGetPizza")
  413.     
  414.         onEnter(function(msg)
  415.             print("comeGetPizza");
  416.             
  417.             local pizzaBox = getParent().loadGameObject("StandardGO","pizzaBox");
  418.             storeStateObject("pizzaBox", pizzaBox);
  419.             getParent().attachLeftObjectHolder(pizzaBox);            
  420.             getParent().handSO.setPose("leftHandHold");
  421.             startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
  422.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  423.                         
  424.         end )
  425.         
  426.         onMsg("stepSound", function(msg)
  427.             makeStepSound("Wood");
  428.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  429.         end )
  430.         
  431.         
  432.         onMsg("end", function(msg)
  433.         
  434.             flipPoseDirection();
  435.             
  436.             if testCancel() then
  437.                 freeHands(getParent());
  438.             else
  439.                 local wsoContext = StateMachineContext();
  440.                 --wsoContext.storeStateObject("tablet", tablet);
  441.                 wsoContext.storeData("chairCommand", "eatByTableChar.sitDown");
  442.                 wsoContext.storeStateObject("tableObject", retrieveStateObject("pizzaBox"));
  443.                 queueStateMachine("tableChairChar.findChair", this, wsoContext);
  444.             end
  445.             
  446.             -- reactivate walkability
  447.             getParent().setWalkability(0);
  448.             
  449.             exitStateMachine();
  450.                         
  451.         end )
  452.         
  453.         
  454.         
  455.         
  456.         
  457.         
  458.     --------------------------------------------------------------------------------------
  459.         
  460.         
  461.     -- go to beach house
  462.     state("goToOtherHouse")
  463.     
  464.         onEnter(function(msg)
  465.             print("goToOtherHouse");
  466.             
  467.             if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
  468.                 storeData("stateAfterDress", "goToOtherHouse");
  469.                 setState("dress");
  470.                 return
  471.             end
  472.                                     
  473.             startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
  474.             sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
  475.             sendDelayedMsgThis("callOther", 3000);
  476.             
  477.             -- deactivate walkability
  478.             getParent().setWalkability(1);
  479.         end )
  480.         
  481.         
  482.         onMsg("callOther", function(msg)
  483.         
  484.             local other = getOtherCharacter(getParent());
  485.             print("callOther other:"..tostring(other).." activePart:"..tostring(retrieveData("activePart", false)));
  486.             if other and retrieveData("activePart", false) then
  487.                 local buttonText = getLeaveButtonText(getParent());
  488.                 local staircase = retrieveStateObject("staircase");
  489.                 other.cancelAllActivities();
  490.                 other.queueCommand(buttonText, "changeHouse", staircase, "");
  491.             end
  492.             
  493.         end )
  494.         
  495.         
  496.         onMsg("stepSound", function(msg)
  497.             makeStepSound("Wood");
  498.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  499.         end )
  500.         
  501.         onMsg("end", function(msg)
  502.             if testCancel() then
  503.                 setState("comeFromOtherHouse")
  504.             else
  505.                 setState("atOtherHouse");
  506.             end            
  507.         end )
  508.         
  509.         
  510.         
  511.         
  512.         
  513.         
  514.     -- in fact only in the staircase, waiting for other character
  515.     state("atOtherHouse")
  516.     
  517.         onEnter(function(msg)
  518.         
  519.             print("atOtherHouse");
  520.             
  521.             local staircase = retrieveStateObject("staircase");
  522.             local otherWaiting = getOtherWaitingToLeave(getParent(), staircase)
  523.             if otherWaiting then
  524.                 setState("comeFromOtherHouse");
  525.                 setTopQueueEntry(getParent(), getComeBackButtonText(staircase));
  526.                 
  527.                 otherWaiting.walkSO.storeData("comeBackDelay", 2000);
  528.                 otherWaiting.walkSO.setState("comeFromOtherHouse");
  529.                 setTopQueueEntry(otherWaiting, getComeBackButtonText(staircase));
  530.                 
  531.                 toggleOutsideWorld(getParent())
  532.             else
  533.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  534.             end
  535.          end )
  536.          
  537.         onMsg("testCancel", function(msg)
  538.             if testCancel() then
  539.                 sendMsgThis("comeBack");
  540.             else
  541.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  542.             end
  543.         end )
  544.          
  545.         
  546.         onMsg("comeBack", function(msg)
  547.             setState("comeFromOtherHouse");
  548.         end )
  549.  
  550.  
  551.     state("comeFromOtherHouse")
  552.     
  553.         onEnter(function(msg)
  554.             print("comeFromOtherHouse onEnter comeBackDelay:" .. tostring(retrieveData("comeBackDelay")));            
  555.             sendDelayedMsgThis("start", retrieveData("comeBackDelay", 0));
  556.         end )
  557.         
  558.         onMsg("start", function(msg)
  559.             print("comeFromOtherHouse start");            
  560.             startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
  561.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  562.         end )
  563.  
  564.         onMsg("stepSound", function(msg)
  565.             makeStepSound("Wood");
  566.             sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
  567.         end )
  568.         
  569.         onMsg("end", function(msg)        
  570.             -- reactivate walkability
  571.             getParent().setWalkability(0);
  572.             
  573.             flipPoseDirection();
  574.             exitAndGoAway(4.0);
  575.         end )
  576.  
  577.  
  578. endStateMachine()