HowToAddItemsStendhal: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Teiv
imported>AntumDeluge
Add GFX: add asset warning
 
(120 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Navigation for Stendhal Top}}
{{Navigation for Stendhal Extenders}}
You can add new item to game in a few very simple steps:
You can add new item to game in a few very simple steps:


== Preparation ==
=Edit items.xml=

Download stendhal-0.xx-src.tar.gz from the stendhal-website and unpack it. All ''items''.xml files are located in the /data/conf/items/ directory. They are arranged according to ''class'' (see below) such as shields, swords, keys, food, etc.
Setup a development environment as described in [[Stendhal on Eclipse]].

==Edit items.xml==
All ''items''.xml files are located in the /data/conf/items/ directory. They are arranged according to ''class'' (see below) such as shields, swords, keys, food, etc.
The file contains all the description of the items in game.
The file contains all the description of the items in game.
Lets start with how to do weapons, for example in swords.xml:
Lets start with how to do weapons, for example in swords.xml:
Line 98: Line 104:


= Add GFX=
= Add GFX=

{{AssetWarning}}


Now place the 32x32 sprite in the folder '''data/sprites/items/<class>/<subclass>.png'''
Now place the 32x32 sprite in the folder '''data/sprites/items/<class>/<subclass>.png'''


See also [[StendhalOpenTasks#Monsters and Items| How to know graphics specifications for items]]
See also [[StendhalRefactoringGraphics#Items| How to know graphics specifications for items]]


If you want your item image animated (like money) simply make a 32N x 32 sprite. E.g. if it has 5 frames in the animation it will be a 160 x 32 sprite. It will automatically appear animated.
If you want your item image animated (like money) simply make a 32N x 32 sprite. E.g. if it has 5 frames in the animation it will be a 160 x 32 sprite. It will automatically appear animated.


= Edit GameObjects =
= Register the class =
So far we have defined what the item is like to the server. Registering the class tells the client what to do with it. (Is it stackable and should have numbers displayed, is it useable and should have a Use displayed?) '''Most classes are already registered and you may be able to ignore this section... read on to find out.'''
Usually you need to register your item class unless it really does nothing. If you're adding an item which is like what we already have (i.e. justa new shield) it's done for you, the shield class is registered. <!--To do: where does this go now-->

Items will default to behave as a non stackable, non useable Item to the client. This covers armor, weapons, most items that don't change. Stackable but non useable classes get registered by class i.e. money, missiles, herbs etc. And most Useable items like food, drink, are registered as a whole class. So if you are adding to any existing class you very likely can ignore all this following stuff. Just come back if something doesn't work... like you expected to be able to use your new item and can't. Or if you are adding a totally new class.

So, if you have a new class and you want it to be stackable or useable <small>or is a totally new client side object, extending Item,</small> then add your class with type (item), class and your chosen behaviour to the rest in ''src/games/stendhal/client/entity/factory/EntityMap.java'', e.g.

<source lang = "java">
// flower was a new class of stackables
register("item", "flower", null, StackableItem.class);
// drink was a new class of Useables
register("item", "drink", null, UseableItem.class);
// Box is a new client side object
register("item", "box", null, Box.class);
</source>

What if your item is part of a class which has a mixture of stackable and non stackable or useable and non useable? Remember the default is non stackable and non useable. So then you need to register the special ones individually. This is done by type (item), class, as before, and also subclass (same as in the xml) to specify which exact item you meant.

<source lang = "java">
// most tools don't have a Use but the sugar mill should. the subclass in xml is sugarmill
register("item", "tool", "sugarmill", UseableItem.class);
</source>

Finally, go to ''src/games/stendhal/client/gui/j2d/entity/EntityViewFactory.java'' and configure item in the same way only if you needed to add to EntityMap above. The examples are

<source lang = "java">
// flower was a new class of stackables
register("item", "flower", null, StackableItem2DView.class);
// drink was a new class of Useables
register("item", "drink", null, UseableItem2DView.class);
// Box is a new client side object
register("item", "box", null, Box2DView.class);

// most tools don't have a Use but the sugar mill should. the subclass in xml is sugarmill
register("item", "tool", "sugarmill", UseableItem2DView.class);
</source>

== Add Grammar ==
Item names should be short and enough to identify the item, but in spoken and written English there may be some extra words associated with saying the item. For example, Carmen should offer to sell ''100 bottles of potion'' not ''100 potion''. (Add npc text example here?)

Some examples:
{|
|-
|potion
|bottle of potion
|-
|leather legs
|pair of leather legs
|-
|wine
|glass of wine
|-
|plate armor
|suit of plate armor
|-
|meat
|piece of meat
|}

To add such a grammatical prefix to NPC speech and speech recognition, edit [http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/src/games/stendhal/common/grammar/PrefixManager.java src/games/stendhal/common/grammar/PrefixManager.java].
{{TODO|The new structure needs documentation on the different options for register, registerEnd and registerPrefix.}}

== Add to game==
===Dropped by creature===
You can have a creature drop your newly made item. This is done by editing that creature in its XML file, found in the file location [http://arianne.cvs.sourceforge.net/viewvc/arianne/data/conf/creatures?view=markup projects/stendhal/data/conf/creatures]. Every creature in the game is located in this folder, categorized by creature type. For example, rats can be found in the file [http://arianne.cvs.sourceforge.net/viewvc/arianne/data/conf/creatures/animal.xml?view=markup projects/stendhal/data/conf/creatures/animal.xml].


===Add to map or grower===
register("item",null,Item.class);
You may wish to add items to a map (for player to pick up or harvest). You can either add to zone by creating a java file (good for one - off items like the poison and scroll of Haizen's table in his hut) or add using tiled which is more work initially but allows you to add to the objects layer in tiled again and again in future. (Good for iron ore to collect from the ground, herbs etc). This needs a whole tutorial on spawners (also knows as growers), please see [[HowToAddGrowers]].
register("item","book",Book.class);
register("item","food",StackableItem.class);
register("item","drink",StackableItem.class);
register("item","money",StackableItem.class);
register("item","projectiles",StackableItem.class);


===Sold by NPC===
If the NPC is not already created, you can [[Stendhal NPC Coding|code a new NPC]]. Then you will need to add a seller behaviour to your NPC, which should be covered separately. Until that is done, look at Seller examples such as Margaret in Semos Tavern in your source code. The file is [http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/src/games/stendhal/server/maps/semos/tavern/BarMaidNPC.java?view=markup src/games/stendhal/server/maps/semos/tavern/BarMaidNPC.java]. If you have any problems with the NPC understanding the item name, you might like to check [[How to test NPC Parser]].


===Produced by NPC===
= Add to game=
Creatures can drop items, see [[HowToAddCreaturesStendhal]]. Perhaps you will want your NPC to equip the player with an item as part of a quest, see [[HowToCreateQuests]] or an NPC to sell the item. For the latter you will need to understand NPC seller behaviour which should be covered separately. Until that is done, look at Seller examples such as Margaret in Semos Tavern in your source code.
If the NPC is not already created, you can [[Stendhal NPC Coding|code a new NPC]]. You will need to add a Producer behaviour to your NPC, which should be covered separately. Until that is done, look at Producer examples such as Arlindo in Ados Bakery in your source code. The file is [http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/src/games/stendhal/server/maps/ados/bakery/BakerNPC.java?view=markup src/games/stendhal/server/maps/ados/bakery/BakerNPC.java]. If you have any problems with the NPC understanding the item name, you might like to check [[How to test NPC Parser]].


===Item Quests and Quest Rewards===
You may wish to add items to a map (for player to pick up or harvest). You can either add to zone by creating a java file (good for one - off items like the poison and scroll of Haizen's table in his hut) or add using tiled which is more work initially but allows you to add to the objects layer in tiled again and again in future. (Good for iron ore to collect from the ground, herbs etc). This needs a whole tutorial on spawners (also knows as growers), see [[HowToAddGrowers]] - so watch this space!
Perhaps you will want your NPC to equip the player with an item as part of a quest, see [[HowToCreateQuests]]. You can also add your items to either the [[StendhalQuest#Daily_Item_Quest|Daily Item quest]] or the [[StendhalQuest#Kirdneh_Museum_needs_help.21|Weekly item quest]], which are related to the appearance around the world (e.g. rare item?).