Project

rpg_level

0.0
No commit activity in last 3 years
No release in over 3 years
Manage the Level/EXP that is known as the most commonly growth system of role-playing games.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
>= 0
~> 10.0
~> 3.0
 Project Readme

RpgLevel

Build Status

Manage the Level/EXP that is known as the most commonly growth system of role-playing games.

Feature

The feature of this module has been aggregated into the following formula:

level = formula_of_exp_table(exp)

This design has been often used in the classic RPGs, such as "Wizardry", "D&D", "Rouge-like", ..etc.

Installation

Add this line to your application's Gemfile:

gem 'rpg_level'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rpg_level

Example

require 'rpg_level'

rpg_level = RpgLevel.new

# Define EXP Table by formula
#
#   Lv1 = 0
#   Lv2 = 4
#   Lv3 = 6  (Total = 10)
#   Lv4 = 8  (Total = 18)
#   Lv5 = 10 (Total = 28)
#
rpg_level.define_exp_table(5) {|data| data[:level] * 2}

# Obtain 12 experience points
# It also means that leveling up at the same time
rpg_level.obtain_exp(12)

# Get current level
p(rpg_level.level)  # => 3

# Get more information
p(rpg_level.level_status)  # => {:level=>3, :next_necessary_exp=>8, :lacking_exp_for_next=>6, :obtained_exp_for_next=>2}