home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
tableChairChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
3KB
|
98 lines
-- find chair at table character state machine
beginStateMachine()
onEnter(function(msg)
local chairCommand = retrieveData("chairCommand", "chairChar.sitDown");
print("tableChairChar on Enter chairCommand:" .. chairCommand);
end )
onExit(function(msg)
print("tableChairChar on Exit chairCommand");
removeStateObject("tableObject");
end )
-- find a chair to sit down
state("findChair")
onEnter(function(msg)
local character = getParent();
local tableObject = retrieveStateObject("tableObject");
local checkPartnerChair = retrieveData("checkPartnerChair", false);
print("findChair checkPartnerChair " .. tostring(checkPartnerChair));
-- try first to get a table with a partner chair
local table, tableActionPointName, chair = getNextFreeChairByTable(character, tableObject, checkPartnerChair);
-- if failed try any table
if (not chair and checkPartnerChair) then
table, tableActionPointName, chair = getNextFreeChairByTable(character, tableObject);
end
if (chair) then
-- go to chair
local actionPoint = getParent().getClosestFreeActionPoint(character, chair, {"sit1", "sit2"});
if (actionPoint) then
print("free chair found , ap:" .. actionPoint.getName());
if (walkToActionPoint(actionPoint)) then
local wsoContext = StateMachineContext();
-- store the action point
wsoContext.storeStateObject("chair", chair);
wsoContext.storeStateObject("table", table);
wsoContext.storeData("tableActionPointName", tableActionPointName);
wsoContext.storeData("chairActionPointName", actionPoint.getName());
queueStateMachine(retrieveData("chairCommand", "chairChar.sitDown"), this, wsoContext);
exitStateMachine();
else
-- no path to chair was found
character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
--sendMsg("emoThink", character.walkSO);
--sendDelayedMsgThis("cancelFind", 2000);
setState("fail");
end
else
character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
--sendMsg("emoThink", character.walkSO);
--sendDelayedMsgThis("cancelFind", 2000);
setState("fail");
end
else
character.setEmoticon(EMOTICON_NOSEAT, EMOTICON_DELAY);
--sendMsg("emoThink", character.walkSO);
--sendDelayedMsgThis("cancelFind", EMOTICON_DELAY);
setState("fail");
end
end )
state("fail")
onEnter(function(msg)
startAnimation("emoThink");
end )
onMsg("end", function(msg)
freeHands(getParent());
exitAndGoAway();
end )
endStateMachine()