$Id: tech-spec 25 2006-10-21 15:44:09Z steven $

.-------------------.
| Table of Contents |
'-------------------'

1. Creating a Character
2. The World Map
3. Main Index Page
4. Party Listing
5. Class/Job System
6. Character Party System


.-------------------------.
| 1. Creating a Character |
'-------------------------'

Choose a name, gender, elemental affinity, and class.
* The name cannot be already in use.
* Gender determines small differences in HP/MP/ATK/DEF/MATK/MDEF
* Elemental affinity allows your character to be bound with an element.
  Effects include taking less damage from the specified element, though the reverse
  can also hold true, as you can receive more damage from opposing elements.
* The class pretty much controls how much each stat can go up when increasing a level,
  along with the skills the character learns (after gaining a certain amount of JP)

When validating the character:
	strip out any characters in the name that aren't [A-z0-9_ -]
	make sure the name is not already in use
	make sure the gender is valid
	make sure the element is valid / forum level high enough to use
	make sure class is valid / forum level is high enough + it's a base class

Table rpg_char
char_id		unsigned int	Primary key.
owner_id	unsigned int	Index. Owner's user id.
name		varchar(32)		Unique. Character's name.
gender
job
element
level
experience
hp
maxhp
mp
maxmp
attack
defense
magic
magicdef
agility
luck
ip
created
righthand
lefthand
body
head
accessory1
accessory2
statusinfo
party_id
ap
skill_cooking
skill_crafting
skill_alchemy
skill_smithing
secondjob
reactionskill
effectskill

.------------------.
| 2. The World Map |
'------------------'

There are no images. That's right. I'm sacrificing pretty graphics in order to
create an immersive world where elegant descriptions flush out the world's true nature.
Makes 56k people happy as well, I'd assume.
500 character description = 0.5kb, 400x245 image = 25+kb

Each location can be in one location group. Location groups allow you to define special
rules like encounters and their rates, along with other assorted properties like taxes.

Each location can contain any number of "objects," which can be anything from items to a
user-owned shop.

For smaller objects that don't require a new page reload, a popup div containing more
options/info would be suitable. For NPCs - a simple div with their message will show up.
For items, its description would come up, along with an option to pick it up or cancel.
If picked up, the object is removed from the location and added to the party's inventory.
Unless, of course, the party's inventory is at its maximum.

location_id
group_id
name
description
modifier
x
y
exits
objects
warp_to

.--------------------.
| 3. Main Index Page |
'--------------------'







.---------------------------.
| 6. Character Party System |
'---------------------------'

* You organize your characters into "parties"
* Each party can contain 1 to 4 characters.
* Characters that aren't in parties are in "Reserves"
* When you move on the world map, you are moving one of your parties.
* Each party can hold X number of items, depending on the party's size.
  -- Addition - maybe store the maximum item storage with the party data,
     so that certain effects/items/whatever can allow more items to be carried.
* You can exchange items between your reserve inventory and party inventory
  when your party is in a location group that allows it, and not in battle.
* You can choose to drop an item from your party's inventory while on the map,
  and doing so, the item will appear at the location for anyone to see (and pick up).
* Battles are party VS party.

Table rpg_party
party_id	unsigned int	Primary key.
name		varchar(32)		Name to identify the party.
user_id		unsigned int	User ID of party's owner, here to make things easier
char1_id	unsigned int	ID of character in slot 1
char2_id	unsigned int	ID of character in slot 2
char3_id	unsigned int	ID of character in slot 3
char4_id	unsigned int	ID of character in slot 4
location_id	unsigned int	Location ID of where the party is located
itemstorage	unsigned short	Maximum amount of items the party can hold
itemcount	unsigned short	Current number of items the party holds
battle_id	unsigned int	ID of battle the party is in

Example on getting party's total item count - 
SELECT SUM(quantity) AS totalitems FROM rpg_party_inv WHERE party_id = x

Example on getting a list of important info on all items - 
SELECT pinv.item_id, pinv.quantity, rpg_item.*
FROM rpg_party_inv AS pinv
LEFT JOIN rpg_item USING (item_id)
WHERE pinv.party_id = x

Example on adding an item to a party's inventory - 
function add_item_to_party(partyid, itemid, amount)
	if partyinfo[itemcount] + amount > partyinfo[itemstorage]
		error...
	// check if it exists
	SELECT item_id FROM rpg_party_inv WHERE party_id = partyid AND item_id = itemid
	// already exists, update
	UPDATE rpg_party_inv SET quantity = quantity + amount 
	WHERE party_id = partyid AND item_id = itemid
	// insert a new one
	INSERT INTO rpg_party_inv (party_id, item_id, quantity) VALUES (partyid, itemid, amount)
	// update partyinfo
	partyinfo[itemcount] += amount
	// make sure to save partyinfo on shutdown
	save_partyinfo(partyinfo);

// Example on removing an item - 
function remove_item_from_party(partyid, itemid, amount)
	UPDATE rpg_party_inv SET quantity = quantity - amount
	WHERE party_id = partyid AND item_id = itemid
	// if the resultant quantity is zero, a cron will pick the row up and trash it


Table rpg_party_inv
party_inv_id	uint		Primary key.
party_id		uint		Index. ID of the party which owns the item.
item_id			uint		ID of the item.
quantity		ushort		Quantity of the item carried.


,---------------------------,
| NPC Message System        |
'---------------------------'

Store messages in a table with message_id, npc_id, parent, choice, text, choicearray
When getting the first message, select from messages where npc_id = x and parent = 0
the message is shown, and choicearray is parsed to print different buttons
when clicking on the button, there is JS that will send the choiceid clicked back
to the server, which will select from messages where npc_id = x and parent = y and choice = z

and so on...
