Mafia's Code: Difference between revisions
imported>Bumcheekcity m Created page with '==Character== ===Under Hardcore or Ronin=== <p><pre> KoLCharacter.canInteract(); </pre></p> This function returns true if the character is out of Hardcore or Ronin, false otherwi…' |
imported>Bale mNo edit summary |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 10: | Line 10: | ||
We can either use: | We can either use: | ||
<p><pre> | <p><pre> | ||
InventoryManager.hasItem( final int itemId ) | |||
InventoryManager.hasItem( final int itemId, boolean shouldCreate ) | |||
InventoryManager.hasItem( final AdventureResult item ) | |||
InventoryManager.hasItem( final AdventureResult item, final boolean shouldCreate ) | |||
InventoryManager.hasItem( 1650, true ); | |||
InventoryManager.hasItem( ItemPool.MILK_OF_MAGNESIUM, true ); | |||
</pre></p> | </pre></p> | ||
Essentially the top three overloaded functions call the bottom function, telling it NOT to create the item. | Essentially the top three overloaded functions call the bottom function, telling it NOT to create the item. | ||
Line 19: | Line 22: | ||
Setting "shouldCreate" to true will NOT create the item, instead it will find out if you COULD create the item. | Setting "shouldCreate" to true will NOT create the item, instead it will find out if you COULD create the item. | ||
hasItem() will return true if you have the item, or could create it and specify shouldCreate to be true. | hasItem() will return true if you have the item, or could create it and specify shouldCreate to be true. | ||
===The Item Pool=== | |||
The Item Pool, at '''/objectpool/itempool/ItemPool.java''' is primarily a list of items, mapped to their item number. Its purpose is to make code more readable. ItemPool.UNDERWORLD_ACORN is much more obvious than "4274". | |||
===Create an Item=== | |||
<p><pre> | |||
CreateItemRequest beltCreator = CreateItemRequest.getInstance( ItemPool.BADASS_BELT ); | |||
// getQuantityPossible() should take meat paste or | |||
// Muscle Sign into account | |||
if ( beltCreator.getQuantityPossible() > 0 ) | |||
{ | |||
beltCreator.setQuantityNeeded( 1 ); | |||
RequestThread.postRequest( beltCreator ); | |||
} | |||
</pre></p> | |||
===Indicate that Meat or Items have been Gained or Lost=== | |||
<p><pre> | |||
ResultProcessor.processMeat( -300 ); | |||
ResultProcessor.processItem( ItemPool.WET_STUNT_NUT_STEW, -1 ); | |||
</pre></p> | |||
Obviously just change the negative numbers to positive ones to indicate gaining items or meat. | |||
===Inventory or Meat changes as results of gaining an Item=== | |||
Occasionally, gaining an item means silently losing others, and this needs to be reflected. For example, when we gain the S.O.C.K., we lose the four Immateria, and when we gain the steel margarita/lasagne/-scented air freshener we lose Azazel's unicorn, lollipop and tutu. | |||
Go to /session/ResultProcessor.java and edit the gainItem() function intuitively. | |||
Note that this should not be used for items that can, for example, be bought in the mall. It is only suitable for items that can only be obtained through quest adventuring. | |||
==Effects== | ==Effects== | ||
Line 29: | Line 62: | ||
Both of these are boolean variables. | Both of these are boolean variables. | ||
===See if we are under any effect=== | |||
<p><pre> | |||
KoLConstants.activeEffects.contains( EffectPool.get( "Half-Astral" ) ); | |||
</pre></p> | |||
Or we could add "Half-Astral" to the /objectpool/EffectPool.java file, and then use: | |||
<p><pre> | |||
KoLConstants.activeEffects.contains( EffectPool.get( EffectPool.HALF_ASTRAL ) ); | |||
AdventureResult astral = EffectPool.get( EffectPool.HALF_ASTRAL ); | |||
KoLConstants.activeEffects.contains( astral ); | |||
</pre></p> | |||
This would have the advantage of only needing a single change should Jick ever decide to change the name of an effect. | |||
==Interacting with the Player== | |||
===A Yes/No dialogue box=== | |||
<p><pre> | |||
if ( !InputFieldUtilities.confirm( "Are you sure you want to drink without ode?" ) ) | |||
{ | |||
return false; | |||
} | |||
</pre></p> | |||
===Is the Script being run unattended?=== | |||
If Mafia is being run from the command line, or similar, a user may not be able to see, let alone answer, dialogue boxes. In this case: | |||
<p><pre> | |||
StaticEntity.isHeadless() | |||
</pre></p> | |||
returns ''true'' if the user can not respond to dialogue boxes. | |||
==Changing Text on a Page== | |||
Edit RequestEditorKit.java. | |||
[[Category:Tech Support]] |
Latest revision as of 09:49, 22 May 2010
Character
Under Hardcore or Ronin
KoLCharacter.canInteract();
This function returns true if the character is out of Hardcore or Ronin, false otherwise. It is essentially used to check mall access.
Items
Check if we have a certain Item
We can either use:
InventoryManager.hasItem( final int itemId ) InventoryManager.hasItem( final int itemId, boolean shouldCreate ) InventoryManager.hasItem( final AdventureResult item ) InventoryManager.hasItem( final AdventureResult item, final boolean shouldCreate ) InventoryManager.hasItem( 1650, true ); InventoryManager.hasItem( ItemPool.MILK_OF_MAGNESIUM, true );
Essentially the top three overloaded functions call the bottom function, telling it NOT to create the item.
Setting "shouldCreate" to true will NOT create the item, instead it will find out if you COULD create the item.
hasItem() will return true if you have the item, or could create it and specify shouldCreate to be true.
The Item Pool
The Item Pool, at /objectpool/itempool/ItemPool.java is primarily a list of items, mapped to their item number. Its purpose is to make code more readable. ItemPool.UNDERWORLD_ACORN is much more obvious than "4274".
Create an Item
CreateItemRequest beltCreator = CreateItemRequest.getInstance( ItemPool.BADASS_BELT ); // getQuantityPossible() should take meat paste or // Muscle Sign into account if ( beltCreator.getQuantityPossible() > 0 ) { beltCreator.setQuantityNeeded( 1 ); RequestThread.postRequest( beltCreator ); }
Indicate that Meat or Items have been Gained or Lost
ResultProcessor.processMeat( -300 ); ResultProcessor.processItem( ItemPool.WET_STUNT_NUT_STEW, -1 );
Obviously just change the negative numbers to positive ones to indicate gaining items or meat.
Inventory or Meat changes as results of gaining an Item
Occasionally, gaining an item means silently losing others, and this needs to be reflected. For example, when we gain the S.O.C.K., we lose the four Immateria, and when we gain the steel margarita/lasagne/-scented air freshener we lose Azazel's unicorn, lollipop and tutu.
Go to /session/ResultProcessor.java and edit the gainItem() function intuitively.
Note that this should not be used for items that can, for example, be bought in the mall. It is only suitable for items that can only be obtained through quest adventuring.
Effects
See if we are under the effects of Ode or Got Milk
KoLConstants.activeEffects.contains( ItemDatabase.ODE ); KoLConstants.activeEffects.contains( ItemDatabase.MILK );
Both of these are boolean variables.
See if we are under any effect
KoLConstants.activeEffects.contains( EffectPool.get( "Half-Astral" ) );
Or we could add "Half-Astral" to the /objectpool/EffectPool.java file, and then use:
KoLConstants.activeEffects.contains( EffectPool.get( EffectPool.HALF_ASTRAL ) ); AdventureResult astral = EffectPool.get( EffectPool.HALF_ASTRAL ); KoLConstants.activeEffects.contains( astral );
This would have the advantage of only needing a single change should Jick ever decide to change the name of an effect.
Interacting with the Player
A Yes/No dialogue box
if ( !InputFieldUtilities.confirm( "Are you sure you want to drink without ode?" ) ) { return false; }
Is the Script being run unattended?
If Mafia is being run from the command line, or similar, a user may not be able to see, let alone answer, dialogue boxes. In this case:
StaticEntity.isHeadless()
returns true if the user can not respond to dialogue boxes.
Changing Text on a Page
Edit RequestEditorKit.java.