home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
chairChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
4KB
|
160 lines
-- chair character state machine
beginStateMachine()
onEnter(function(msg)
print("chair character state machine onEnter");
local chair = retrieveStateObject("chair");
if (not chair) then chair = getStateObjectFromID(msg.sender); end;
storeStateObject("chair", chair);
if (chair) then
if exitIfWrongPosition(getParent(), chair, retrieveData("actionPointName")) then return end;
--chair does exist
if (getParent().isOneActionPointLocked(chair)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(chair);
-- check wich side of chair
local actionPointName = retrieveData("actionPointName");
print(actionPointName);
-- coming from left behind
if (actionPointName == "sit2") then
storeData("mirrorAnims", true);
else
storeData("mirrorAnims", false);
end
-- coming from front
if (actionPointName == "sit3") then
storeData("fromFront", true);
else
storeData("fromFront", false);
end
end
else
-- chair does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
end )
onExit(function(msg)
-- local chair = retrieveStateObject("chair");
-- getParent().unlockActionPoints(chair);
-- removeStateObject("chair");
unlockAll("chair");
getParent().stopAllActivities();
end )
-- sit down on chair
state("sitDown")
onEnter(function(msg)
print("sitDown onEnter");
local chair = retrieveStateObject("chair");
if (retrieveData("fromFront") == true) then
setPose("sitdownChairHandsDown");
sendDelayedMsgThis("sitSound", 2000);
else
setPose("sitdownChair", retrieveData("mirrorAnims"));
chair.startAnimation("ChairSitdown");
chair.playSound("Stuhl hinsetzen");
-- send a delayed message for sit sound
sendDelayedMsgThis("sitSound", 3000);
end
end )
onMsg("end", function(msg)
setCurrentPosition();
if testCancel() then
setState("standUp");
else
local chair = retrieveStateObject("chair");
getParent().startActivity("sit", chair);
sendDelayedMsgThis("act", 5000);
this.actionComplete();
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
--notify mission that the character sat on the chair
getParent().sendMsg(
"sat",
getParent().getGameObjectServer().mission,
tostring(chair.getUniqueID()) );
end
end )
onMsg("queue", function(msg)
setState("standUp");
end )
onMsg("sitSound", function(msg)
local chair = retrieveStateObject("chair");
--chair.playSound("Stuhl setzen");
makeChairSound(chair, "Down");
end )
onMsg("act", function(msg)
doSomething();
sendDelayedMsgThis("act", 5000);
end )
onMsg("testCancel", function(msg)
if testCancel() or (this.getParent().getActivityQueueCount() > 1) or (not this.getParent().getCurrentActivityGain()) then
setState("standUp");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
-- stand up from chair
state("standUp")
onEnter(function(msg)
local chair = retrieveStateObject("chair");
getParent().stopAllActivities(chair);
if (retrieveData("fromFront") == true) then
startAnimation("standupChairHandsDown");
sendDelayedMsgThis("upSound", 500);
else
startAnimation("standupChair", retrieveData("mirrorAnims"));
chair.startAnimation("ChairSitdown", -1);
sendDelayedMsgThis("upSound", 900);
end
end )
onMsg("upSound", function(msg)
local chair = retrieveStateObject("chair");
makeChairSound(chair, "Up");
end )
onMsg("end", function(msg)
if (retrieveData("fromFront") == true) then
flipPoseDirection();
print("flip");
end;
setCurrentPosition();
exitStateMachine();
end )
endStateMachine()