Puzzle Controllers
From Web-Adventure-Kit-Wiki
Contents |
[edit] Overview
A puzzle controller is a class derivate of PuzzleControllerBase. This is where you specify what happens with the game when you use an object on another, or interact with a character, etc. Here is where the consequences of the actions made by the player's character take place.
When you make an action inside the game for example use a key with a door or pick up a shovel. WAK starts an automatic look up of a method to answer to that action. The association between the method and the action is made automatic by the name of your methods inside the PuzzleController. If you have a key item with an id “Ikey” and a door with id “SIDoor” your method name to respond to the previously mentioned use action is:
UseIKeyAndSIDoor( key:IInteractable, door:IInteractable )
If you have a method with that name and signature inside of any of your Puzzle Controllers this will be called automatically.
The PuzzleController must be created by the author of the adventure inside the game project and you have to add them to the AdventureMaster like is shown below calling to the method “AddPuzzleController” from your AdventureMaster instance.
You can check in the demos of WAK the calling to AddPuzzleController in the Initialize method of the main class of each project.
[edit] Parameters
To understand which parameters you will receive when your puzzle methods are called let me introduce you part of the family of classes used by WAK.
You will always receive an Iinteractable object as parameter or parameters for your methods, but you can downcast them to other derivate classes to fit your needs. Based on the action and the id you know what kind of object you will receive. If you are creating a method to “Talkto” a character instead of
TalkToCharId( pChar:ISceneInteractable )
you might want to do this:
TalkToCharId( pChar:AbstractCharacterDisplay )
So when you work with the variable pChar the auto-complete of your IDE and the flash player will be happier to know the specific type of the data structure on which you are working on.
[edit] Special warning for Characters
When you are creating methods to use some action with a character on the scene. For example “TalkToCharacterId” you will receive the character's display as parameter and not the Character data structure.
[edit] Method Names and Actions
[edit] Use
Base Name: Use
Parameters: 2
Connector: And
Example: function UseIKeyAndSIDoor( pKey:IInteractable, pDoor:IInteractable)
Scumm: Is selected manually from the actions menu, and called when has all the parameters selected by the player.
SCI and Modern: Is called after the player selected and item from the inventory and used it on something in the scene.
[edit] Close
Base Name: Close
Parameters: 1
Example: function CloseSIDoor(pDoor:IInteractable)
Scumm and SCI: Is selected manually from the actions menu, and called when has the required parameter to close.
Modern: Not used at all.
[edit] Give
Base Name: Give
Parameters: 2
Connector: To
Example: function GiveIGoldToTrader(pGold:IInteractable,pChar:IInteractable)
Scumm: Is selected manually from the actions menu, and called when has all the parameters selected by the player.
SCI and Modern: There is no “give” action, but you can use “Use” action to give something to a character.
[edit] Interact
Base Name: Interact
Parameters: 1
Example: function InteractSIChest(pChest:IInteractable)
Scumm: Not used at all.
SCI: Is selected manually from the actions menu, and selected when the player selected the target of the interaction.
Modern: Is the action by default, whenever you click over an item on the scene this action is called.
[edit] Look At
Base Name: Lookat
Parameters: 1
Example: function LookAtSIGrogMachine(pMachine:IInteractable)
Scumm and SCI: Is selected manually from the actions menu. By default the “LookAt” action display the item's description in the corresponding way for each system. You must define a this method only if you want to override this behaviour.
Modern: Not used at all.
[edit] Open
Base Name: Open
Parameters: 1
Example: function OpenSIDoor(pDoor:IInteractable)
Scumm and SCI: Is selected manually from the actions menu, and selected when the player selected the target of the action.
Modern: Not used at all.
[edit] Pick Up
Base Name: Pickup
Parameters: 1
Example: function PickupSIShovel(pDoor:IInteractable)
Scumm and SCI: Is selected manually from the actions menu, and selected when the player selected the target of the action.
Modern: Not used at all.
[edit] Pull
Base Name: Pull
Parameters: 1
Example: function PullSISword(pSword:IInteractable)
Scumm and SCI: Is selected manually from the actions menu, and selected when the player selected the target of the action.
Modern: Not used at all.
[edit] Push
Base Name: Push
Parameters: 1
Example: function PushSISword(pSword:IInteractable)
Scumm and SCI: Is selected manually from the actions menu, and selected when the player selected the target of the action.
Modern: Not used at all.
[edit] Talk To
Base Name: Talkto
Parameters: 1
Example: function TalktoCharId(pChar:IInteractable)
Scumm and SCI: Is selected manually from the actions menu, and selected when the player selected the target of the action.
Modern: Not used at all.
[edit] Walk To
This is treated like an special case and it is never dispatched as call.
[edit] End of action
End of action or EndOfAction(); is a method that must be called every time you finish your code in a method inside a puzzle controller which is handling an action. This allows WAK to restore the state of the user interface and other tasks after the result of an action was completed.
[edit] Grouping Puzzle Controllers
You can have one or more PuzzleControllers in your game. And you can group them or use it to sort your methods. Is a good practice divide your PuzzleControllers in two groups, one to handle actions which are bounded to an specific scene and one for handle actions which are global to the whole game. But this is up to the adventure author/programmer to deal with this in the best way he or she likes. Just remember add your PuzzleControllers to the AdventureMaster so WAK knows where to look for action handlers. You can add and remove PuzzleControllers in the middle of the game as needed.




