home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
repairChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
5KB
|
189 lines
-- repair state machine
beginStateMachine()
onEnter(function(msg)
local object = getStateObjectFromID(msg.sender);
storeStateObject("object", object);
if (object) then
-- object does exist
local actionPointName = retrieveData("actionPointName");
if exitIfWrongPosition(getParent(), object, actionPointName) then return end;
if (object.isBroken()) then
-- object does exist
if (getParent().isOneActionPointLocked(object)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(object);
end
else
-- object is not broken anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
else
-- object does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
end )
onExit(function(msg)
-- local object = retrieveStateObject("object");
-- if (object) then
-- getParent().unlockActionPoints(object);
-- getParent().stopAllActivities(object);
-- removeStateObject("object");
-- end
unlockAll("object");
freeHands(getParent());
getParent().stopAllActivities();
end )
state("repairStart")
onEnter(function(msg)
local screwdriver = getParent().loadGameObject("StandardGO", "screwdriver");
getParent().attachRightObjectHolder(screwdriver);
startAnimation("repairStart");
sendDelayedMsgThis("dropScrewdriver", 8320);
sendDelayedMsgThis("grabHammer", 9000);
end )
onMsg("dropScrewdriver", function(msg)
freeHands(getParent());
end )
onMsg("grabHammer", function(msg)
local hammer = getParent().loadGameObject("StandardGO", "hammer");
getParent().attachRightObjectHolder(hammer);
end )
onMsg("end", function(msg)
if (testCancel()) then
exitStateMachine();
else
setState("repair");
end
end )
state("repair")
onEnter(function(msg)
local object = retrieveStateObject("object");
local repair = getParent().startActivity("repair", object);
local length, scale = getActivityLength(repair);
storeData("scale", scale);
startAnimation("repairLoop", false, scale);
sendDelayedMsgThis("hammerSound", 900);
sendDelayedMsgThis("hammerSound", 1500);
sendDelayedMsgThis("hammerSound", 2000);
sendDelayedMsgThis("complete", length);
end )
onMsg("hammerSound", function(msg)
getParent().playSound("hammer3");
end )
onMsg("complete", function(msg)
local object = retrieveStateObject("object");
getParent().stopActivity("repair", object);
--object.setBroken(false);
storeData("finished", true);
setState("repairEnd");
end )
onMsg("end", function(msg)
if testCancel() then
local object = retrieveStateObject("object");
getParent().stopActivity("repair", object);
setState("repairEnd");
else
startAnimation("repairLoop", false, retrieveData("scale"));
sendDelayedMsgThis("hammerSound", 900);
sendDelayedMsgThis("hammerSound", 1500);
sendDelayedMsgThis("hammerSound", 2000);
end
end )
state("repairEnd")
onEnter(function(msg)
sendDelayedMsgThis("dropHammer", 1360);
sendDelayedMsgThis("grabScrewdriver", 2280);
startAnimation("repairEnd");
end )
onMsg("dropHammer", function(msg)
getParent().playSound("dropHeavyStuff");
freeHands(getParent());
end )
onMsg("grabScrewdriver", function(msg)
local screwdriver = getParent().loadGameObject("StandardGO", "screwdriver");
getParent().attachRightObjectHolder(screwdriver);
end )
onMsg("end", function(msg)
freeHands(getParent());
if (retrieveData("finished", false) == true) then
local obj = retrieveStateObject("object");
obj.setBroken(FALSE);
local char = getParent();
if (char.hasSkill("repair3")) then
obj.setBrokenValue(0.0);
elseif (char.hasSkill("repair2")) then
obj.setBrokenValue(0.25);
elseif (char.hasSkill("repair1")) then
obj.setBrokenValue(0.5);
end
end;
exitAndGoAway();
end )
onExit(function(msg)
local object = retrieveStateObject("object");
--notify mission that the character repaired the particular object
getParent().sendMsg(
"repaired",
getParent().getGameObjectServer().mission,
tostring(object.getUniqueID()) );
end )
endStateMachine()