home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
staircaseChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
15KB
|
578 lines
-- staircase character state machine
beginStateMachine()
onEnter(function(msg)
-- local staircase = retrieveStateObject("staircase");
-- if (not staircase) then
-- -- no staircase was stored
-- staircase = getStateObjectFromID(msg.sender);
-- storeStateObject("staircase", staircase);
-- end
--
local staircase = getStateObjectFromID(msg.sender)
storeStateObject("staircase", staircase);
if (getParent().isOneActionPointLocked(staircase)) then
-- action point is locked
print("staircase character onEnter: action point is locked ");
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
--getParent().lockActionPoints(staircase);
end
getParent().enableBlobShadow(false);
end )
onExit(function(msg)
-- local staircase = retrieveStateObject("staircase");
-- if (staircase) then
-- getParent().unlockActionPoints(staircase);
-- getParent().stopAllActivities(staircase);
-- removeStateObject("staircase");
-- end
unlockAll("staircase");
getParent().enableBlobShadow(true);
getParent().stopAllActivities();
end )
state("dress")
onEnter(function(msg)
--startAnimation("ausziehen2");
startAnimation(getChangeOutfitAnim(getParent()));
sendDelayedMsgThis("switchOutfit", 1600);
end )
onMsg("switchOutfit", function(msg)
changeOutfit(getParent(), ARCHTYPE);
end )
onMsg("end", function(msg)
setState(retrieveData("stateAfterDress"))
end )
-- go to work
state("goToWork")
onEnter(function(msg)
print("goToWork");
if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
storeData("stateAfterDress", "goToWork");
setState("dress");
return
end
startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
-- deactivate walkability
getParent().setWalkability(1);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
if testCancel() then
setState("comeFromWork")
else
setState("atWork");
end
end )
state("atWork")
onEnter(function(msg)
local workDur = getParent().getWorkDurationInGameTime();
print("atWork for " .. workDur);
sendDelayedMsgThis("comeBack", workDur);
getParent().setAtHome(false);
getParent().setAtWork(true);
local staircase = retrieveStateObject("staircase");
getParent().startActivity("work", staircase);
-- make queue entry uncancellble
local entry = getParent().getActivityQueueEntry(0);
if (entry) then entry.setUserCancel(false); end;
end )
onMsg("comeBack", function(msg)
getParent().setAtHome(true);
getParent().setAtWork(false);
setState("comeFromWork");
local staircase = retrieveStateObject("staircase");
getParent().stopActivity("work", staircase);
-- get the money for the day!
local daylyIncome = getParent().getWorkIncome();
getParent().getGameObjectServer().addMoney(daylyIncome);
end )
state("comeFromWork")
onEnter(function(msg)
print("comeFromWork");
startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
local partner = getOtherCharacter(getParent());
if (partner) then
--getParent().sendMsg("imBackAtHome", partner);
end
-- reactivate walkability
getParent().setWalkability(0);
flipPoseDirection();
exitAndGoAway(4.0);
end )
-- go shoping
state("goToShop")
onEnter(function(msg)
print("goToShop");
if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
storeData("stateAfterDress", "goToShop");
setState("dress");
return
end
startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
-- deactivate walkability
getParent().setWalkability(1);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
if testCancel() then
setState("comeFromShop")
else
setState("atShop");
end
end )
state("atShop")
onEnter(function(msg)
print("atShop");
getParent().setAtHome(false);
sendDelayedMsgThis("comeBack", random(10000, 20000));
end )
onMsg("comeBack", function(msg)
getParent().setAtHome(true);
setState("comeFromShop");
end )
state("comeFromShop")
onEnter(function(msg)
print("comeFromShop");
startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
local partner = getOtherCharacter(getParent());
if (partner) then
--getParent().sendMsg("imBackAtHome", partner);
end
flipPoseDirection();
-- reactivate walkability
getParent().setWalkability(0);
exitStateMachine();
end )
-- go buy gift
state("goBuyGift")
onEnter(function(msg)
print("goBuyGift");
if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
storeData("stateAfterDress", "goBuyGift");
setState("dress");
return
end
startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
-- deactivate walkability
getParent().setWalkability(1);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
if testCancel() then
setState("comeBuyGift")
else
setState("atBuyGift");
end
end )
state("atBuyGift")
onEnter(function(msg)
print("atBuyGift");
getParent().setAtHome(false);
sendDelayedMsgThis("comeBack", random(1000, 1000));
end )
onMsg("comeBack", function(msg)
getParent().setAtHome(true);
setState("comeBuyGift");
end )
state("comeBuyGift")
onEnter(function(msg)
print("comeBuyGift");
local gift = getParent().loadGameObject("StandardGO", "gift");
getParent().attachRightObjectHolder(gift);
getParent().handSO.setPose("rightHandHoldGift");
startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
local character = getParent();
local partner = getOtherCharacter(character);
-- reactivate walkability
getParent().setWalkability(0);
if (partner) and (partner.walkSO.getStateMachine().getName() ~= "staircaseChar") then
print("partner for " .. character.getCharacterName() .. " to give the gift : " .. partner.getCharacterName())
flipPoseDirection();
character.pushCommand("pm_giveGift", "giveGift", partner);
exitStateMachine();
--getParent().sendMsg("giveGift", partner);
else
print("partner for " .. character.getCharacterName() .. " to give the gift : NONE")
freeHands(character);
flipPoseDirection();
exitAndGoAway();
end
end )
-- go shoping
state("goTrash")
onEnter(function(msg)
print("goTrash");
if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
storeData("stateAfterDress", "goTrash");
setState("dress");
return
end
startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
-- deactivate walkability
getParent().setWalkability(1);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
setState("comeTrash")
end )
state("comeTrash")
onEnter(function(msg)
print("comeTrash");
local trashbag = getParent().getLeftHeldObject()
getParent().detachLeftObjectHolder()
if (trashbag) then trashbag.deleteGameObject(); end
getParent().handSO.stopPose();
startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
flipPoseDirection();
-- reactivate walkability
getParent().setWalkability(0);
exitAndGoAway(4.0);
end )
-- get pizza
state("goGetPizza")
onEnter(function(msg)
print("goGetPizza");
if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
storeData("stateAfterDress", "goGetPizza");
setState("dress");
return
end
startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
-- deactivate walkability
getParent().setWalkability(1);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
setState("comeGetPizza");
end )
state("comeGetPizza")
onEnter(function(msg)
print("comeGetPizza");
local pizzaBox = getParent().loadGameObject("StandardGO","pizzaBox");
storeStateObject("pizzaBox", pizzaBox);
getParent().attachLeftObjectHolder(pizzaBox);
getParent().handSO.setPose("leftHandHold");
startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
flipPoseDirection();
if testCancel() then
freeHands(getParent());
else
local wsoContext = StateMachineContext();
--wsoContext.storeStateObject("tablet", tablet);
wsoContext.storeData("chairCommand", "eatByTableChar.sitDown");
wsoContext.storeStateObject("tableObject", retrieveStateObject("pizzaBox"));
queueStateMachine("tableChairChar.findChair", this, wsoContext);
end
-- reactivate walkability
getParent().setWalkability(0);
exitStateMachine();
end )
--------------------------------------------------------------------------------------
-- go to beach house
state("goToOtherHouse")
onEnter(function(msg)
print("goToOtherHouse");
if (not hasOutfit(getParent(), ARCHTYPE) and not hasOutfit(getParent(), STANDARD)) then
storeData("stateAfterDress", "goToOtherHouse");
setState("dress");
return
end
startAnimation("stairsDown", false, STAIRS_DOWN_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_DOWN_SPEEDUP);
sendDelayedMsgThis("callOther", 3000);
-- deactivate walkability
getParent().setWalkability(1);
end )
onMsg("callOther", function(msg)
local other = getOtherCharacter(getParent());
print("callOther other:"..tostring(other).." activePart:"..tostring(retrieveData("activePart", false)));
if other and retrieveData("activePart", false) then
local buttonText = getLeaveButtonText(getParent());
local staircase = retrieveStateObject("staircase");
other.cancelAllActivities();
other.queueCommand(buttonText, "changeHouse", staircase, "");
end
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
if testCancel() then
setState("comeFromOtherHouse")
else
setState("atOtherHouse");
end
end )
-- in fact only in the staircase, waiting for other character
state("atOtherHouse")
onEnter(function(msg)
print("atOtherHouse");
local staircase = retrieveStateObject("staircase");
local otherWaiting = getOtherWaitingToLeave(getParent(), staircase)
if otherWaiting then
setState("comeFromOtherHouse");
setTopQueueEntry(getParent(), getComeBackButtonText(staircase));
otherWaiting.walkSO.storeData("comeBackDelay", 2000);
otherWaiting.walkSO.setState("comeFromOtherHouse");
setTopQueueEntry(otherWaiting, getComeBackButtonText(staircase));
toggleOutsideWorld(getParent())
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("testCancel", function(msg)
if testCancel() then
sendMsgThis("comeBack");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("comeBack", function(msg)
setState("comeFromOtherHouse");
end )
state("comeFromOtherHouse")
onEnter(function(msg)
print("comeFromOtherHouse onEnter comeBackDelay:" .. tostring(retrieveData("comeBackDelay")));
sendDelayedMsgThis("start", retrieveData("comeBackDelay", 0));
end )
onMsg("start", function(msg)
print("comeFromOtherHouse start");
startAnimation("stairsUp", false, STAIRS_UP_SPEEDUP);
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("stepSound", function(msg)
makeStepSound("Wood");
sendDelayedMsgThis("stepSound", 400/STAIRS_UP_SPEEDUP);
end )
onMsg("end", function(msg)
-- reactivate walkability
getParent().setWalkability(0);
flipPoseDirection();
exitAndGoAway(4.0);
end )
endStateMachine()