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

  1. -- phone character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local phone = getStateObjectFromID(msg.sender);
  6.         storeStateObject("phone", phone);
  7.         
  8.         if (phone) then
  9.             -- phone does exist
  10.             local actionPointName = retrieveData("actionPointName");
  11.             local actionPoint = getParent().getFreeActionPoint(phone, actionPointName);
  12.  
  13.             if exitIfWrongPosition(getParent(), phone, actionPointName) then return end;    
  14.  
  15.             --if (getParent().isOneActionPointLocked(phone)) then
  16.             if (not actionPoint) then
  17.                 -- action point is locked
  18.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  19.                 sendMsg("emoThink", getParent().walkSO);
  20.                 exitStateMachine();
  21.             else
  22.                 -- getParent().lockActionPoint(phone, actionPointName);
  23.                 getParent().lockActionPoints(phone);
  24.             end
  25.         else
  26.             -- phone does not exist anymore
  27.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  28.             sendMsg("emoThink", getParent().walkSO);
  29.             exitStateMachine();
  30.         end
  31.         
  32.         freeHands(getParent());
  33.                 
  34.     end )
  35.     
  36.     onExit(function(msg)
  37. --        local phone = retrieveStateObject("phone");
  38. --        getParent().unlockActionPoints(phone);
  39. --        getParent().stopAllActivities(phone);
  40. --        removeStateObject("phone");
  41.         
  42.         unlockAll("phone");        
  43.         
  44.         getParent().stopAllActivities();    
  45.     end )
  46.     
  47.     -----------------------------------------------------------------------------------------
  48.     -----------------------------------------------------------------------------------------
  49.     -----------------------------------------------------------------------------------------
  50.     
  51.     
  52.     state("callFriendsStart")
  53.     
  54.         onEnter(function(msg)
  55.             startAnimation("phoneStart");
  56.             -- this.actionComplete();
  57.             
  58.             sendDelayedMsgThis("takeHandle", 800);
  59.         end )    
  60.             
  61.         onMsg("takeHandle", function(msg)
  62.             local phone = retrieveStateObject("phone");            
  63.             local handle = phone.createGameObject("handle");
  64.             getParent().attachRightObjectHolder(handle);            
  65.         end )    
  66.  
  67.  
  68.         onMsg("end", function(msg)
  69.             if testCancel() then
  70.                 setState("callFriendsStop");
  71.             else
  72.                 setState("callFriends");
  73.             end
  74.         end )    
  75.  
  76.     state("callFriends")
  77.     
  78.         onEnter(function(msg)
  79.             startAnimation("phoneLoop");
  80.             
  81.             local phone = retrieveStateObject("phone");            
  82.             local callFriends = getParent().startActivity("callFriends", phone);
  83.             local length, scale = getActivityLength(callFriends);
  84.  
  85.             sendDelayedMsgThis("talk", random(5000, 10000));
  86.             sendDelayedMsgThis("complete", length);
  87.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  88.             
  89. --            getParent().getGameObjectServer().payMoney(1);
  90.         end )
  91.         
  92.         onExit(function(msg)
  93.             local phone = retrieveStateObject("phone");
  94.             getParent().stopAllActivities(phone);
  95.         end )
  96.         
  97.         onMsg("talk", function(msg)
  98.             print("talk in wso  " .. getParent().getCharacterName());
  99.             sendMsg("talk", getParent().mimicSO);
  100.             sendDelayedMsgThis("talk", random(5000, 10000));
  101.         end )
  102.  
  103.                 
  104.         onMsg("complete", function(msg)
  105.             setState("callFriendsStop");
  106.         end )            
  107.  
  108.         onMsg("testCancel", function(msg)
  109.             if testCancel() then
  110.                 sendMsgThis("complete");
  111.             else
  112.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  113.             end
  114.         end )            
  115.  
  116.  
  117.         onMsg("end", function(msg)
  118.             if testCancel() then
  119.                 sendMsgThis("complete");
  120.             else
  121.                 startAnimation("phoneLoop");
  122.             end
  123.         end )    
  124.         
  125.         
  126.     state("callFriendsStop")
  127.     
  128.         onEnter(function(msg)
  129.             startAnimation("phoneStart", false, -1.0);
  130.             
  131.             sendDelayedMsgThis("dropHandle", 1600);
  132.         end )    
  133.             
  134.         onMsg("dropHandle", function(msg)
  135.             freeHands(getParent());
  136.             --getParent().detachRightObjectHolder();            
  137.         end )    
  138.  
  139.  
  140.         onMsg("end", function(msg)
  141.             exitAndGoAway();
  142.         end )    
  143.  
  144.     -----------------------------------------------------------------------------------------
  145.     -----------------------------------------------------------------------------------------
  146.     -----------------------------------------------------------------------------------------
  147.         
  148.     
  149.     state("callPizzaStart")
  150.     
  151.         onEnter(function(msg)
  152.             startAnimation("phoneStart");
  153.             -- this.actionComplete();
  154.             
  155.             sendDelayedMsgThis("takeHandle", 800);
  156.         end )    
  157.             
  158.         onMsg("takeHandle", function(msg)
  159.             local phone = retrieveStateObject("phone");            
  160.             local handle = phone.createGameObject("handle");
  161.             getParent().attachRightObjectHolder(handle);            
  162.         end )    
  163.  
  164.  
  165.         onMsg("end", function(msg)
  166.             if testCancel() then
  167.                 setState("callPizzaAborted");
  168.             else
  169.                 setState("callPizza");
  170.             end
  171.         end )    
  172.  
  173.     state("callPizza")
  174.     
  175.         onEnter(function(msg)
  176.             startAnimation("phoneLoop");
  177.             
  178.             local phone = retrieveStateObject("phone");            
  179.             local callPizza = getParent().startActivity("callPizza", phone);
  180.             local length, scale = getActivityLength(callPizza);
  181.  
  182.             sendDelayedMsgThis("talk", random(5000, 10000));
  183.             sendDelayedMsgThis("complete", length);
  184.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  185.             
  186. --            getParent().getGameObjectServer().payMoney(1);
  187.         end )
  188.         
  189.         onExit(function(msg)
  190.             local phone = retrieveStateObject("phone");
  191.             getParent().stopAllActivities(phone);
  192.         end )
  193.         
  194.         onMsg("talk", function(msg)
  195.             print("talk in wso  " .. getParent().getCharacterName());
  196.             sendMsg("talk", getParent().mimicSO);
  197.             sendDelayedMsgThis("talk", random(5000, 10000));
  198.         end )
  199.  
  200.         onMsg("canceled", function(msg)
  201.             setState("callPizzaAborted");
  202.         end )            
  203.                 
  204.         onMsg("complete", function(msg)
  205.             setState("callPizzaStop");
  206.         end )            
  207.  
  208.         onMsg("testCancel", function(msg)
  209.             if testCancel() then
  210.                 sendMsgThis("canceled");
  211.             else
  212.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  213.             end
  214.         end )            
  215.  
  216.  
  217.         onMsg("end", function(msg)
  218.             if testCancel() then
  219.                 sendMsgThis("canceled");
  220.             else
  221.                 startAnimation("phoneLoop");
  222.             end
  223.         end )
  224.         
  225.         
  226.     state("callPizzaStop")
  227.     
  228.         onEnter(function(msg)
  229.             startAnimation("phoneStart", false, -1.0);
  230.             
  231.             sendDelayedMsgThis("dropHandle", 1600);
  232.         end )    
  233.             
  234.         onMsg("dropHandle", function(msg)
  235.             freeHands(getParent());
  236.             --getParent().detachRightObjectHolder();            
  237.         end )    
  238.  
  239.  
  240.         onMsg("end", function(msg)
  241.             if (testCancel()) then
  242.                 exitStateMachine();
  243.             else
  244.                 local character = this.getParent();
  245.                 local staircase, actionPoint = getReachableObjectWithBehavior(character, "staircase", {"topStep"}, true)
  246.                 
  247.                 
  248. --                local staircases = getParent().getObjectsWithBehavior("staircase");
  249. --                local staircase = staircases[1];
  250. --                if (not staircase) then
  251. --                    print("no staircase");
  252. --                    exitStateMachine();
  253. --                    return
  254. --                end
  255. --                -- walk to the closest action point
  256. --                local actionPoint = character.getFreeActionPoint(staircase, "topStep");
  257.                 
  258.                 
  259.                 --local actionPoint = character.getClosestFreeActionPointToClickPoint(staircase, {"topStep"});
  260.                 if (actionPoint) then
  261.                 -- get the walk state object
  262.                     local wso = character.walkSO;
  263.                     -- create state machine contexts
  264.                     local wsoContext = StateMachineContext();
  265.                     -- store the action point
  266.                     --wsoContext.storeData("actionPointName", actionPoint.getName());
  267.                     --wsoContext.storeStateObject("staircase", staircase);
  268.                     if (wso.walkToActionPoint(actionPoint)) then
  269.                         print("queue staircaseChar.goGetPizza");
  270.                         wso.queueStateMachine("staircaseChar.goGetPizza", staircase, wsoContext);
  271.                         exitStateMachine();
  272.                     else
  273.                         print("no path found");
  274.                         character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  275.                         sendMsg("emoThink", character.walkSO);
  276.                         setState("callPizzaAborted");
  277.                     end
  278.                 else
  279.                     print("no action point found");
  280.                     character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  281.                     sendMsg("emoThink", character.walkSO);
  282.                     setState("callPizzaAborted");
  283.                 end
  284.             end
  285.         end )
  286.             
  287.     state("callPizzaAborted")
  288.     
  289.         onEnter(function(msg)
  290.             startAnimation("phoneStart", false, -1.0);
  291.             
  292.             sendDelayedMsgThis("dropHandle", 1600);
  293.         end )    
  294.             
  295.         onMsg("dropHandle", function(msg)
  296.             freeHands(getParent());
  297.             --getParent().detachRightObjectHolder();            
  298.         end )    
  299.  
  300.  
  301.         onMsg("end", function(msg)
  302.             exitStateMachine();
  303.         end )
  304.  
  305.  
  306. --    state("callPizza")
  307. --    
  308. --        onEnter(function(msg)
  309. --            startAnimation("phone");
  310. --            this.actionComplete();
  311. --        end )        
  312. --
  313. --        onMsg("queue", function(msg)
  314. --            exitStateMachine();
  315. --        end )    
  316. --
  317. --        onMsg("end", function(msg)
  318. --            if (testCancel()) then
  319. --                exitStateMachine();
  320. --            else
  321. --                local staircases = getParent().getObjectsWithBehavior("staircase");
  322. --                local staircase = staircases[1];
  323. --                if (not staircase) then
  324. --                    print("no staircase");
  325. --                    exitStateMachine();
  326. --                    return
  327. --                end
  328. --                
  329. --                local character = this.getParent();
  330. --                
  331. --                -- walk to the closest action point
  332. --                local actionPoint = character.getFreeActionPoint(staircase, "topStep");
  333. --                --local actionPoint = character.getClosestFreeActionPointToClickPoint(staircase, {"topStep"});
  334. --                if (actionPoint) then
  335. --                -- get the walk state object
  336. --                    local wso = character.walkSO;
  337. --                    -- create state machine contexts
  338. --                    local wsoContext = StateMachineContext();
  339. --                    -- store the action point
  340. --                    --wsoContext.storeData("actionPointName", actionPoint.getName());
  341. --                    --wsoContext.storeStateObject("staircase", staircase);
  342. --                    if (wso.walkToActionPoint(actionPoint)) then
  343. --                        wso.queueStateMachine("staircaseChar.goGetPizza", staircase, wsoContext);
  344. --                    else
  345. --                        print("no path found");
  346. --                        character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  347. --                        sendMsg("emoThink", character.walkSO);
  348. --                    end
  349. --                else
  350. --                    print("no action point found");
  351. --                    character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  352. --                    sendMsg("emoThink", character.walkSO);
  353. --                end
  354. --            end
  355. --        end )    
  356. --
  357. --    state("callOffice")
  358. --    
  359. --        onEnter(function(msg)
  360. --            startAnimation("phone");
  361. --            this.actionComplete();
  362. --        end )        
  363. --
  364. --        onMsg("queue", function(msg)
  365. --            exitStateMachine();
  366. --        end )    
  367. --
  368. --        onMsg("end", function(msg)
  369. --            exitStateMachine();
  370. --        end )    
  371.  
  372.                 
  373. endStateMachine()
  374.