Sphere Community Game/Scripting

From Spheriki

Jump to: navigation, search

This page contains information about the structure of scripts in the Sphere Community Game, and is a nice place for sneak-peeks at how things are going in the game. The information on this page is also useful for tips and ideas about how to structure a game.

Redirection:


Contents

Main Script Structure

The following is the basic structure for scripts in the SCG. Script construction is planned to start on the 10th of January, so please restructure before that date (at which time this notice will be removed).

  • startup.js
    • This is the starting script.
    • Preload important global resources. Will wait until all are loaded.
    • Start background-loading of secondary global resources. These are loaded behind-the scenes.
    • Evaluate all other scripts.
  • resources.js
    • Contains the Resources() object.
    • Controls the resources in the SCG. All resources are listed here, to be loaded according to its priority level and stage.
    • Contains functions relevant to the resource handling system.
  • filehandling.js
    • Contains the File() object.
    • Controls the files used in the SCG. Prevent double-loading, validate save files, and read from string tables. See more in the Data Model section.
    • Contain save file loading and saving (SaveFile Object)
    • Autoload the item, battle, and other data tables.
  • characters.js
    • Contains the Character() object, thus the objects within that. See Data Model.
    • Control characters in-game. Stores all character information.
  • maps.js
    • Contains the Map() object.
    • Handles map condition and storyline synchronization.
  • battle.js
    • Contains the Battle() object.
    • Handles all battles. Map Engine is not turned off.
  • gui.js
    • Contains various objects, such as Menu(), ItemWindow(), etc.
    • Also handle all player-input, except for battles.
  • audio.js
    • Handle Sound and AmbientSound Resource Objects.
  • graphics.js
    • Handle ScreenObject Resource Objects.


Data Model

The following is technical information on the SCG's data model.

Player Data Model

Players and enemies all share the same basic stats. These stats are used during battle calculation, AI, and interaction with items.

Visible Stats

The following are stats visible to the player (as numbers) and can be modified via items directly:

  • Health Points (HP) range 0 to 9999, shown on main screen
  • Magic Points (MP) range 0 to 9999, shown on main screen
  • Attack Points (AP) range 0 to 999
  • Defense Points (DP) range 0 to 999
  • Speed Points (SP) range 0 to 999

These stats are dynamically modified during battle, by skills, and as side-effects of items/equipment.

Hidden Stats

These stats are normally not shown to the player, but play important roles in battle. Items/skills/equipment may hold values that modify these, but these effects are only shown as +/- icons.

  • Accuracy - main modifier on how accurate attacks are
  • Reaction - control delay between movements
  • Range - modifier on range of skills
  • Crisis - modifier on many stats

AI Stats

The stats here are used by AI (however, the player characters also have these). These generally control how the AI behave and battle. Events during battle (or before it) can influence these.

  • Confidence
  • Fear
  • Teamwork
  • MainAllies (array of objects)
  • MainEnemies (array of objects)
  • EnvironmentAdv (array of objects)
  • EnvironmentDis (array of objects)

Item Data Model

Items are initialy loaded from an items array located in data/items.js file. This file looks like this:


var itemLines = [
 ['<itemid>', <ItemType>, <price>, <IEC>, <param1>, <param2>,,<paramN>],
 // etc...
]

Where:

  • itemid (string) - the name of the item. This will also be used to construct the filename of the image representing this object. So it will look for <itemid>_icon.png for an image of that item. Besides that it will also look in the stringtable for <itemid>.label for a short name of the item, and <itemid>.descr for a longer description of the object.
  • itemType - The typename of the item. This dictates much of its behaviour. Valid item names are
    • Blade - item is a blade, like a knife or a sword. When equipped will show blade attack animation
    • Bow - item is a bow, when equipped will show bow attack animation
    • Static - item has no default usage, should be defined elsewhere
    • Recovery - item can be used in inventory and applies one action one time and will then be removed from that inventory
    • Shield - item is a shield, should be worn in the hand to have effect
    • Cap - item is a cap, should be worn on the head to have effect
    • ...more to come
  • price (int, optional) - Normal advised price in a shop. Prices in shops may vary depending on their location and the availability of an item in that region.
  • IEC (string, optional) - The item effect code when equipped
  • param1-N, (mixed, optional) - Optional parameters may be passed, which might have meaning for some types of items.

For example:

var itemLines = [
 ['broadsword', Blade, 150, 'AP+10;DP+5'], // broadsword 
 ['potion_mp10', Recovery, 10, 'MP+10'], // potion recovers 10 mp
 ['potion_mp10p', Recovery, 100, 'max MP+10'] // potion adds 10 mp to max
 // etc...
]

Attacking an enemy The attack on an enemy is the result of the gained AP when wearing an offense object. Therefor it does not need to be explicitly stated. The attack routine will take the total AP and uncertainty factors into account when caculating the total number of hitpoints.

Special item effects Special item effects can be added later programmatically. The array of items will be converted into actual item objects which can be modified by scripting. For example, if you which to say something when the broadsword is equipped you can do so:

items['broadsword'].onEquip = function(event) {
  this.prototype.onEquip(event); // propagate event for correct handling
  event.character.say('What a mighty sword, I can kick butt with this!');
}

Also see the item members paragraph below for more information on the item object.

Item members

Here follows a list of the default members of an item. Note that in normal cases you'll have enough by defining the item in the itemLines array. knowledge of the item properies is only required for objects that require functionality which is not 'out of the box'.

properties

  • name (string) - the name of an item
  • label (string) - the label of an item in the currenct language
  • descr (string) - the description of an item in the current language
  • price (int) - the advised price of an object
  • effect (Effect object) - the effect an object has when used or equipped
  • location (Location enum) - the wear location (HEAD, HANDS, BODY, FEET) priliminiary list, expect changes.

events

  • onGain - event handler for when an item is added to the inventory
  • onDrop - event handler for when an item is removed from the inventory
  • onEquip - event handler for when an item is equipped from the inventory
  • onUnequip - event handler for when an item is unequipped from the character
  • onUse - event handler for when the object is used by selecting use from in the inventory screen
  • onAttack - event handler for when the item is used in an offensive strike

Do not forget to call the prototype event handler when overwriting.

Item Effect Code

This code is used in determining the effects of items. Usually this code is used in direct map application, or in items/equipment.

Syntax: {[max]} {stat1,stat2,...,statx} {+/+%/+%n/%} {value} [; Syntax]

Example of increasing hp, mp and str by 200 points.

hp,mp,str + 200

Example of increasing max hp with 20, and give maximum hp

max hp + 20; hp 100%

If max is not prefixed to the string

  • + means to directly add. This will be capped.
  • +% means to add by a certain percentage of a full amount.
  • +%n means to add by a certain percentage of now.
  • % means to set to this percentage of a full amount.

If max is prefixed, then all values are added to the maximum amount, not the current amount. The current amount will not change (although the current percentage does).

Skill System

Daniel concentrates on magic skills, while Tilde is armed with an assortment of combat abilities. In battle, it will be possible to combine the use of these skills.

Outside of battle, Daniel and Tilde share a skill grid. The skills of each character run along the sides. If Daniel had 3 skills and Tilde had 4, they would form a grid with 12 cells.

Each cell can be filled with a special item. That item contains a special effect or combined skill.

e.g. The grid might look like this:

Daniel's skills
Ice Fire Wind
Tilde's skills Backslash Karmic Coin (auto: counter)
Smash Hailstone (skill: Sleet Storm) Honour Medal (stat: str + 1)
Blade Burst Oil Drop (skill: Flame Burst)
Corrupt Rune Reverse (absorb: ice)

This is only an example! This stuff may or may not show up in the final game.

The player can choose which items go in what cells. The places an item can go are restricted, e.g. Hailstone can fit with Ice or Wind, but not Fire.

The placement of an item may change what effect it has, e.g. putting the Honour Medal in the Smash/Ice cell (instead of the Smash/Fire cell) would offer stat: def + 1 (instead of stat: str + 1).

All skill: effects are special: they can be used in battle. When Daniel and Tilde use their normal skills together (on the sides), they will join forces and use the combined skill (in the cell,) e.g. if Daniel uses Fire, and Tilde uses Blade Burst, they will activate Oil Drop's Flame Burst.

Note that the way that combined skills are set up, the way that Daniel and Tilde actually combine their skills will differ, depending on the sort of battle system that is decided.

The gaining of items can vary from being quest rewards, being found in dungeons/caves/whatever, winning them from random encounters or bosses, and so on.


New:

Image:S_skillgrid.png

A live in-game screenshot of a working skill grid system/data model. It even fufills all the blatent lies we told above. Disregard the items/effects, they're just for testing.

Some info on how the skill system is set up:

Firstly we're going to have a 2d array for the skill grid, which would incorporate all the different combinations of Daniel's and Tildes's Skill's e.g g_sgrid[0][0] refers to Ice/Backslash.

Each slot in this array will then point to a specific item via a reference integer. i.e: g_sgrid[0][0] = 0, which obviously corresponds to that items position in the items array.

The next part is that if each item does different things depending on where it's placed, it will need a 2d array the same size as the one above to refer to the different attributes for different slots. In the above example, each would be 3 * 4, regardless if the item couldn't be equipped in certain categories, it's too hard to keep performing operations to find the right slot based on where it could be equipped. Now each slot in this 2d array would hold a reference integer which refers to a specific slot in an "item effect" array. And everything about the skill/stat/effect will be stored here including functions for when the item is equipped/removed, etc...

As for items not being able to be equipped in certain slots, we will merely set the skill for that slot for that item to 0. Then we just need to make the equip function not allow zero's to be placed and voila.

So in summary...

g_sgrid, a 2d array
g_items, an array
g_items[a].skills, a 2d array
g_skills, an array, where each slot is an object with y properties and z functions.


Status effects

If you have any ideas, feel free to simply add them. If you want to make changes, make a topic in the discussion page first.

  • Mute: Character can't talk, resulting in that the person can't use sound skills and some other skills (like more magic-like skills).
  • Deaf: Character becomes deaf for this battle, making him immune for some spells but also lowering the success rate of using magic.
  • Dumb: Character can't use any skills of the scripting category.
  • Pause: Character is paused (stop effect).
  • Fast: Character can do things twice as fast.
  • Slow: Opposite of fast. :P
  • Data distortion: Kind of like the poison effect in other games: sucks hit points away in timed intervals.
Personal tools