Synopsis:
Functions specific to the general rules of the Fighting Fantasy gamebook system
Description:
While the FFCombat library handles the combat routines for a Fighting Fantasy adventure, this library provides routines common to many Fighting Fantasy gamebook most notably the Test Your Luck routine and implements the routine required for gaining a statistic (e.g. Skill Stamina or Luck) without exceeding the Initial value.
Requirements:
- Include Hosted Library: GeneralLib
Functions:
- &spend_gold($quantity)
Requires: permanent variable: $gold
Subtracts the value supplied by the $quantity parameter from the permanent variable $gold providing that it will not take $gold below zero.
Returns 1 if successful or 0 if unsuccessful.
Example:
if(&spend_gold(5)) {&print ‘you give the barmaid 5 gold’} else {&print ‘you cannot afford a pint’}
Will display ‘you give the barmaid 5 gold’ and subtract 5 from the variable $gold if $gold equals 5 or more, or display ‘you cannot afford a pint’ if $gold is less than 5.
- &gain_stat($stat, $quantity)
Requires: permanent variables: $skill, $iskill, $stamina, $istamina, $luck, $iluck
Adds the value in $quantity to either $skill $stamina or $luck depending if $stat parameter is ‘skill’, ‘stamina’, or ‘luck’. The total value will be capped according to the value in permanent variable $iskill, $istamina, or $iluck (being the ‘initial’ values) appropriately. If the addition attempts to go over the initial value a warning message may be displayed if called in an output context. There is no defined return value for this function. Note that if the author has for some reason elected to allow the Character to exceed his initial values (e.g. simply adding to $skill without regard for initial value) while the fnnction will not increase the stat any more it neither will it decrease the current stat value.
Example: &gain_stat(‘luck’,5);
Adds up to 5 points to $luck limited by the ceiling in $iluck.
Note to self for development: this would be much better written as a function that simply returns the new value for the base skill, and takes (current_base,initial_value,quantity) as parameters, as this would then become a generally useful function and not limited by any required variables.
- &lose_stat($stat,$quantity)
Requires: permanent variables: $iskill,$skill,$istamina,$stamina,$iluck,$luck
This is only relevant for initial values (base values can safely be lost with a simple subtraction). The parameter $stat must be set to either: ‘initial skill’,'initial stamina’ or ‘initial luck’, and will reduce the relevant permanent variables accordingly while maintaining the excess of any exceptional values the author has allowed for a base stat (e.g. if a character has an inital skill of 11 and a current skill of 13, and is instructed to lose 2 initial skill, both values will be reduced by 2, however if a character has an inital skill of 11 and a current skill of 10 and is instructed to do the same both values will drop to 9).
Example: &lose_stat(‘inital skill’,3);
Reduces $iskill by 3 and also $skill by 3 if $skill is equal to or more than $iskill, if $skill is less than $iskill it will either be reduced to the new level of $iskill or left alone if it is already equal to or less than the the new value of $iskill.
- &testluck()
Requires: permanent variable: $luck
Performs the Test Your Luck operation. Rolls 2 dice, and returns 1 if the Test was succesful (Lucky, total equal or less than $luck) or 0 if unsuccesful (Unlucky, total greater than $luck), and subtracts 1 from $luck before returning the result. It also outputs a warning if the characters $luck is already less than 2 since that is an automatic failure (useful for combat or other situations where testing luck is voluntary).
Example: if(&testluck()){&print ‘you dodged the trap’} else {&print ‘the trap got you, lose 2 stamina’;$stamina=$stamina-2;}
Tests the chracters luck, if lucky they dodge the trap, if unlucky the trap gets them and they lose 2 stamina.
Note: would be good to make the warning appear depending on the voluntary status of the Test and abort if it is voluntary (or provide an option to do abort or continue in case the character wants to lose the test for some reson)
- &damage($damage)
Requires: permanent variable: $stamina
Subtracts $damage value from $stamina, and if $stamina drops below 0 outputs an enforced bookend tag (forcing the end of the adventure)
Example: &damage(5);
- &testskill($skill)
Requires: Nothing
Performs a simple variation of testluck on the passed $skill variable, but does not decrease any global $skill – this is a common operation in Fighting Fantasy adventures. 2 dice rolled if total less than or equal to $skill the test was succesful and returns 1, else fails and returns 0;
Example: if(&testskill($skill)){&print ‘You dodged the Dragons Breath’} else {&print ‘The Dragons Breath turns you to a crisp’;}
Self explanatory I hope.
Note: some adventures fail the test on a roll that is *equal* to or more than Skill, must adapt.