home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
sinkChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
10KB
|
384 lines
-- sink character state machine
beginStateMachine()
onEnter(function(msg)
--local sink = getStateObjectFromID(msg.sender);
local sink = getStoredOrSender("dishwasher", msg)
storeStateObject("sink", sink);
if (sink) then
-- sink does exist
local actionPointName = retrieveData("actionPointName");
if exitIfWrongPosition(getParent(), sink, actionPointName) then return end;
if (getParent().isOneActionPointLocked(sink)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(sink);
end
else
-- sink does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
end )
onExit(function(msg)
-- local sink = retrieveStateObject("sink");
-- getParent().unlockActionPoints(sink);
-- getParent().stopAllActivities(sink);
-- removeStateObject("sink");
unlockAll("sink");
getParent().stopAllActivities();
end )
state("washHandsStart")
onEnter(function(msg)
startAnimation("washHandsStart");
end )
onMsg("end", function(msg)
if (testCancel()) then
exitStateMachine();
else
setState("washHands");
end
end )
state("washHands")
onEnter(function(msg)
local sink = retrieveStateObject("sink");
local washHands = getParent().startActivity("washHands", sink);
local length, scale = getActivityLength(washHands);
storeData("scale", scale);
sink.loopSound("washHands");
startAnimation("washHandsLoop", false, scale);
sendDelayedMsgThis("complete", length);
end )
onMsg("complete", function(msg)
setState("washHandsEnd");
end )
onMsg("end", function(msg)
if testCancel() then
sendMsgThis("complete");
else
startAnimation("washHandsLoop", false, retrieveData("scale"));
end
end )
onExit(function(msg)
local sink = retrieveStateObject("sink");
sink.stopSound("washHands");
getParent().stopActivity("washHands", sink);
end)
state("washHandsEnd")
onEnter(function(msg)
-- grab sponge
startAnimation("washHandsEnd");
end )
onMsg("end", function(msg)
--exitStateMachine();
--goAway();
exitAndGoAway();
end )
--washDishes---------------------------------------------------------------------------------------
state("washDishesStart")
onEnter(function(msg)
print("onEnter washDishesStart cancel :" .. tostring(testCancel()));
local sink = retrieveStateObject("sink");
addDish(sink, retrieveData("numDishes", 0));
startAnimation("washDishesStart");
sendDelayedMsgThis("grabBrush", 2800);
--setTopQueueEntry(getParent(), "pm_washDishes")
end )
onMsg("grabBrush", function(msg)
local brush = getParent().loadGameObject("StandardGO","sinkBrush");
storeStateObject("brush", brush);
getParent().attachRightObjectHolder(brush);
local plate = getParent().loadGameObject("StandardGO","plate");
storeStateObject("plate", plate);
getParent().attachLeftObjectHolder(plate);
local sink = retrieveStateObject("sink");
addDish(sink, -1);
end )
onMsg("end", function(msg)
if (testCancel()) then
setState("washDishesEnd");
else
setState("washDishes");
end
end )
state("washDishes")
onEnter(function(msg)
local sink = retrieveStateObject("sink");
local washDishes = getParent().startActivity("washDishes", sink);
local length, scale = getActivityLength(washDishes);
storeData("length", length);
storeData("scale", scale);
print("washDishes length: " .. length);
sendDelayedMsgThis("plateReady", length);
startAnimation("washDishesLoop", false, scale);
sink.loopSound("washHands");
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end )
onMsg("queue", function(msg)
sendMsgThis("complete");
end )
onMsg("plateReady", function(msg)
local sink = retrieveStateObject("sink");
if (getDish(sink) < 1) then
sendMsgThis("complete");
else
addDish(sink, -1);
sendDelayedMsgThis("plateReady", retrieveData("length"));
end
end )
onMsg("complete", function(msg)
local sink = retrieveStateObject("sink");
sink.stopSound("washHands");
getParent().stopActivity("washDishes", sink);
setState("washDishesEnd");
end )
onMsg("testCancel", function(msg)
if testCancel() then
sendMsgThis("complete");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
local sink = retrieveStateObject("sink");
if testCancel() or (getDish(sink) < 1) then
sendMsgThis("complete");
else
startAnimation("washDishesLoop", false, retrieveData("scale"));
end
end )
state("washDishesEnd")
onEnter(function(msg)
startAnimation("washDishesEnd");
freeHands(getParent());
end )
onMsg("end", function(msg)
--exitAndGoAway();
exitStateMachine();
end )
--brushTeeth---------------------------------------------------------------------------------------
state("brushTeethStart")
onEnter(function(msg)
startAnimation("brushTeethStart");
sendDelayedMsgThis("grabBrush", 1600);
end )
onMsg("grabBrush", function(msg)
brush = getParent().loadGameObject("StandardGO","toothBrush");
if (not brush) then
print("create brush failed");
end
storeStateObject("brush", brush);
getParent().attachRightObjectHolder(brush);
end )
onMsg("end", function(msg)
if testCancel() then
getParent().detachRightObjectHolder();
local brush = retrieveStateObject("brush");
if (brush) then brush.deleteGameObject(); end
exitStateMachine();
else
setState("brushTeeth");
end
end )
state("brushTeeth")
onEnter(function(msg)
local sink = retrieveStateObject("sink");
local brushTeeth = getParent().startActivity("brushTeeth", sink);
local length, scale = getActivityLength(brushTeeth);
storeData("scale", scale);
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
print("brushTeeth, length:" .. length);
getParent().loopSound("brushTeeth");
startAnimation(genderize(getParent(), "brushTeethLoop"), false, scale);
-- this.actionComplete();
end )
onMsg("complete", function(msg)
local sink = retrieveStateObject("sink");
getParent().stopSound("brushTeeth");
getParent().stopActivity("brushTeeth", sink);
setState("brushTeethEnd");
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
sendMsgThis("complete");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if testCancel() then
sendMsgThis("complete");
else
startAnimation(genderize(getParent(), "brushTeethLoop"), false, retrieveData("scale"));
end
end )
state("brushTeethEnd")
onEnter(function(msg)
startAnimation("brushTeethEnd");
sendDelayedMsgThis("openWater", 1700);
sendDelayedMsgThis("dropBrush", 7360);
end )
onExit(function(msg)
local sink = retrieveStateObject("sink");
sink.stopSound("washHands");
freeHands(getParent());
end )
onMsg("openWater", function(msg)
local sink = retrieveStateObject("sink");
sink.loopSound("washHands");
end )
onMsg("dropBrush", function(msg)
local sink = retrieveStateObject("sink");
sink.stopSound("washHands");
freeHands(getParent());
end )
onMsg("end", function(msg)
exitAndGoAway();
end )
state("makeHair")
onEnter(function(msg)
local sink = retrieveStateObject("sink");
--getParent().startActivity("makeHair", sink);
local makeHair = getParent().startActivity("makeHair", sink);
local length, scale = getActivityLength(makeHair);
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
local hairBrush = getParent().loadGameObject("StandardGO", "hairBrush");
local hairSpray = getParent().loadGameObject("StandardGO", "hairSpray");
getParent().attachRightObjectHolder(hairBrush);
getParent().attachLeftObjectHolder(hairSpray);
sendMsgThis("startLoop");
end )
onMsg("startLoop", function(msg)
startAnimation("makeHair");
sendDelayedMsgThis("brushSound", 600);
sendDelayedMsgThis("spraySound", 5800);
end )
onMsg("brushSound", function(msg)
getParent().playSound("hairBrush");
end )
onMsg("spraySound", function(msg)
getParent().playSound("hairSpray");
end )
onMsg("complete", function(msg)
freeHands(getParent());
getParent().stopActivity("makeHair", retrieveStateObject("sink"));
exitAndGoAway();
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
sendMsgThis("complete");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if testCancel() then
sendMsgThis("complete");
else
sendMsgThis("startLoop");
end
end )
endStateMachine()