RPG level stats

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

RPG level stats

Post by dafhi »

Code: Select all

' -------------------------------------------------------------------
'  RPG level stats  by dafhi
'
'  release date:  2018 Oct 26
'
'  Based upon my journey through World of Warcraft
'  coded sometime around 2015
' -------------------------------------------------------------------


type stat_literal         as long

function  stat_func(incr as single=1, _base as stat_literal=10, expon as single=1, index as stat_literal=1) as stat_literal
  return _base + incr * (expon ^ (index-1) -1)
End Function


type tStatCurve
  as single               increment = 1, expon = 1
  as ushort               bas, index
  as integer              val
  declare sub             new_level
  declare sub             calc_abs(level as integer)
  declare constructor(_base as ushort=10, incr as single=3, expon as single=1)
End Type
constructor tStatCurve(_bas as ushort, incr as single, expo as single)
  bas=_bas:  expon=expo:  increment = incr
End Constructor
sub  tStatCurve.calc_abs(_index as integer)
  index = _index:  val = stat_func(increment,bas,expon,index)
End sub
sub tStatCurve.new_level
  calc_abs index+1
End sub


type NPC
  as stat_literal         level
  as tStatCurve           expworth = type<tStatCurve>(10, 1, 1.25)
  as tStatCurve           hp = type<tStatCurve>(50, 15, 1.2)
  declare sub             stats(level as stat_literal)
End Type
sub NPC.stats(_level as stat_literal)
  level = _level
  expworth.calc_abs level
  hp.calc_abs level
end sub


type Toon
  as stat_literal         level, hp, def, stam, stren, dex, intel
  declare sub             new_level
  as tStatCurve           expbar = type<tStatCurve>(50, 120, 1.25) 'increment, base, exponent
  as tStatCurve           crvHP = type<tStatCurve>(15, 50, 1.2)
  as tStatCurve           crvDef = type<tStatCurve>(15, 50, 1.2)
 private:
End Type
sub Toon.new_level
  level += 1
  expbar.new_level
End Sub


dim as Toon           Player
dim as NPC            mob

? "level", "exp bar", "npc exp", "npc hp"
for i as integer = 1 to 18
  player.new_level
  mob.stats i
  ? player.level, player.expbar.val, mob.expworth.val, mob.hp.val
next

sleep
Post Reply