home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
trashcanChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
6KB
|
182 lines
-- trashcan character state machine
beginStateMachine()
onEnter(function(msg)
local trashcan = getStateObjectFromID(msg.sender);
storeStateObject("trashcan", trashcan);
if (trashcan) then
-- trashcan does exist
local actionPointName = retrieveData("actionPointName");
if exitIfWrongPosition(getParent(), trashcan, actionPointName) then return end;
if (getParent().isOneActionPointLocked(trashcan)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(trashcan);
end
else
-- trashcan does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
end )
onExit(function(msg)
-- local trashcan = retrieveStateObject("trashcan");
-- getParent().unlockActionPoints(trashcan);
-- getParent().stopAllActivities(trashcan);
-- removeStateObject("trashcan");
unlockAll("trashcan");
getParent().stopAllActivities();
end )
state("takeTrash")
onEnter(function(msg)
print("takeTrash");
local trashcan = retrieveStateObject("trashcan");
local fillLevel = trashcan.retrieveData("fillLevel", 0.0);
if (fillLevel < 0.01) then
print("takeTrash traschcan empty");
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
return
end
getParent().startActivity("takeTrash", trashcan);
sendDelayedMsgThis("grabCap", 960);
sendDelayedMsgThis("grabBag", 1600);
sendDelayedMsgThis("dropCap", 2600);
startAnimation("takeTrash");
end )
onMsg("grabCap", function(msg)
getParent().playSound("trashcan"); print("grabCap");
-- attach cap to right hand of character
local trashcan = retrieveStateObject("trashcan");
local cap = trashcan.createGameObject("cap");
getParent().attachRightObjectHolder(trashcan, "cap");
end)
onMsg("grabBag", function(msg)
-- attach cap to left hand of character
-- local trashcan = retrieveStateObject("trashcan");
-- local bag = trashcan.createGameObject("cap");
-- getParent().attachRightObjectHolder(trashcan, "cap");
local trashbag = getParent().loadGameObject("StandardGO","trashbag");
if (not trashbag) then print("create trashbag failed"); end
local trashcan = retrieveStateObject("trashcan");
local stink = trashcan.findChildGO("stink");
local rate = stink.getEmitRate();
if (rate > MIN_STINK_RATE) then
print("bagstink rate " .. rate)
trashbag.setChildEnable("stink", true);
local bagstink = trashbag.findChildGO("stink");
bagstink.setEmitRate(rate);
end;
-- storeStateObject("trashbag", trashbag);
getParent().attachLeftObjectHolder(trashbag);
end)
onMsg("dropCap", function(msg)
getParent().playSound("trashcan");
getParent().detachRightObjectHolder();
end)
onMsg("end", function(msg)
local trashcan = retrieveStateObject("trashcan");
getParent().stopActivity("takeTrash", trashcan);
if (testCancel()) then
local trashbag = getParent().getLeftHeldObject()
if (trashbag) then trashbag.deleteGameObject(); end
exitStateMachine();
else
local character = this.getParent();
local staircases = character.getObjectsWithBehavior("staircase");
local staircase = staircases[1];
if (not staircase) then
print("no staircase");
local trashbag = getParent().getLeftHeldObject()
if (trashbag) then trashbag.deleteGameObject(); end
character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", character.walkSO);
exitStateMachine();
return
end
-- walk to the closest action point
local actionPoint = character.getFreeActionPoint(staircase, "topStep");
--local actionPoint = character.getClosestFreeActionPointToClickPoint(staircase, {"topStep"});
if (actionPoint) then
-- get the walk state object
local wso = character.walkSO;
-- create state machine contexts
local wsoContext = StateMachineContext();
-- store the action point
--wsoContext.storeData("actionPointName", actionPoint.getName());
--wsoContext.storeStateObject("staircase", staircase);
if (wso.walkToActionPoint(actionPoint)) then
character.handSO.setPose("leftHandHoldHigh");
wso.queueStateMachine("staircaseChar.goTrash", staircase, wsoContext);
addTrash(trashcan, -1.0);
exitStateMachine();
else
print("no path found");
local trashbag = getParent().getLeftHeldObject()
if (trashbag) then trashbag.deleteGameObject(); end
character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
sendMsg("emoThink", character.walkSO);
exitStateMachine();
end
else
print("no action point found");
local trashbag = getParent().getLeftHeldObject()
if (trashbag) then trashbag.deleteGameObject(); end
character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", character.walkSO);
exitStateMachine();
end
end
end )
endStateMachine()