This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Anatomy of a Class
Equinoxdawg edited this page Mar 4, 2015
·
4 revisions
A Class is a profession that is held by a character, and they can exhibit any number of traits. Below will be a fleshed out, explicit example of a (fictional) class:
Class = require "./../base/Class" # Require the base Class
class MyClass extends Class # Class declaration
baseHp: 70 # This is the base HP for this class
baseHpPerLevel: 20 # This is how much HP this class gets per level
baseHpPerCon: 7 # This is how much HP per point of CON this class gets
baseMp: 2 # This is the base MP for this class
baseMpPerLevel: 2 # This is how much MP this class gets per level
baseMpPerInt: 1 # This is how much MP per point of INT this class gets
baseConPerLevel: 3 # This is how much CON / level this class gets
baseDexPerLevel: 2 # DEX / level
baseAgiPerLevel: 2 # AGI / level
baseStrPerLevel: 3 # STR / level
baseIntPerLevel: 2 # INT / level
baseWisPerLevel: 1 # WIS / level
baseLuckPerLevel: 0 # LUK / level
itemScore: (player, item) -> # This function is a reduction call. It indicates how items should be prioritized.
item.str*1.1 # For example we prioritize STR at 2.1x (base of 1 + 1.1x)
+ item.con*0.8 # CON at 1.8
+ item.dex*0.3 # DEX at 1.3
- item.agi*0.2 # AGI at 0.8 (base of 1 - 0.2)
- item.wis*0.8 # WIS at 0.2 (base of 1 - 0.8)
strPercent: -> # This function is a reduction call. It indicates that this class gives
25 # a passive 25% STR bonus
minDamage: (player) ->
player.calc.damage()*0.50 # This function is a reduction call. It indicates your base minimum damage.
# This means we will hit for at LEAST 50% of our STR value.
load: (player) -> # This function is called when a player changes to this class
super player # Call the default load function.
# In here, you can watch for events and such.
@onGainXp = (player) -> # We must store events so they are properly unloaded
player.gainXp 1
player.on "xp.gain", @onGainXp # When the player gains XP (xp.gain event), give them 1 more XP
unload: (player) -> # This functions is called when the player changes *out* of this class
player.off "xp.gain", @onGainXp # So we want to clean up any events we've set, like @onGainXp
module.exports = exports = MyClass #This class must be exported so the game can access it