Basic RPG Class Structuring and Design

Started by
2 comments, last by Scouting Ninja 6 years, 3 months ago

Hi, I am new to Game Development and am currently making my first game in Unity using c#. I am a second year uni student studying computer science (internet security specialization). I am new to unity and have had trouble understanding how the game engine actually functions and how I should use the engine to my advantage when programming. Currently I am making a RPG and want to implement an efficient and scalable item database. My plan is to store all items in the game in an xml database using the built in unity xml serializer. I have an abstract class item -> weapon, armour, potion, ring etc. Each of these classes have respective values (damage, cost etc.). For a relatively generic and straightforward item system: How would you organize your code? What interfaces/classes/other would you implement; why? In your experience what kinds of issues have you run into and how did you work around them? Is there any other advice with regards to rpg design in general?

Advertisement
49 minutes ago, standinonstilts said:

Hi, I am new to Game Development and am currently making my first game in Unity using c#. I am a second year uni student studying computer science (internet security specialization). I am new to unity and have had trouble understanding how the game engine actually functions and how I should use the engine to my advantage when programming. Currently I am making a RPG and want to implement an efficient and scalable item database. My plan is to store all items in the game in an xml database using the built in unity xml serializer. I have an abstract class item -> weapon, armour, potion, ring etc. Each of these classes have respective values (damage, cost etc.). For a relatively generic and straightforward item system: How would you organize your code? What interfaces/classes/other would you implement; why? In your experience what kinds of issues have you run into and how did you work around them? Is there any other advice with regards to rpg design in general?

I cannot give you the basic run down of how Unity's engine works because I work in a game engine that I've programmed myself. What defines components of any game engine can differ, but the core is usually the same. The engine handles events, input, logic, audio, networking (sometimes), and drawing. There can be a ton more like physics, advanced AI, collision detection, animations, gui features, file input and output, ect... You will want to start simple, and get to the point where you understand the proper structure of a game loop in Unity. See the following and understand what is happening and why: https://docs.unity3d.com/Manual/ExecutionOrder.html

You're going to handle the item loading usually in your setup phase which takes the data from the file and loads it into your item manager class. From there, you will just call upon that class when you need to reference an item by index.

I would never recommend an RPG for a first game, however when you're dealing with importing items from a sheet you can store the information through arrays, and lists, ect... I would just make different sheets for different types of items (Armor, Weapon, Misc), then in your setup phase, import each sheet into their appropriate class.

I cannot really answer the rest because I haven't ran into issues. I've made item lists that important into Tool Kits, and RPG engines that I've developed just fine. As long as you have a way to import the items, and get the data you're good to go. Usually I have an item class that has a private container that holds the type 'item' based on my structure, and I have public functions that will get attributes from the container either by keyword, or id number reference.

Your item class will hold everything about your item: Type, Cost, Damage, or whatever else. You can also make a new item structure that is just for potion usage as well, which wouldn't benefit from having "Damage" as an attribute.

Your Item Manager class will hold the container which has the type 'item', and in your Item Manager Class you can program functions that pull details such as 'costAmount("key")' which will then return the value. This function would pass the key to your container, then you can pull data through the item functions. ie: itemList["hat"].costAmount()

Assuming you're in a shop buying items, and you've clicked a sword. The following could happen:

if (player1.getGold() < itemManager.weapon.costAmount("sword")) { // display not enough gold } else { // buy item }

If you bought the item, you would just add it to the player inventory. If you're using different classes to separate Armor, Weapons, and Potions you can store 2 IDs per slot, one that references 1 = armor, 2 = weapon, 3 = potion, and the other id asks as the key. There are many many ways to do all of this.

player1.inventory.addItem(2, "sword");

Then if you need to equip a weapon item, you'll know to check if your inventory item object which is stored in a container as well meets the following requirement:

if (player1.inventory.atSlot(1).classType() == 2 && player1.equipSlot.weapon.isEmpty()) { player1.equipSlot.weapon.equipItem("sword"); }

I still do not recommend programming an RPG as your first project, but you're free to do so. I hope this helps.

Programmer and 3D Artist

2 hours ago, standinonstilts said:

RPG and want to implement an efficient and scalable item database.

If you haven't done this in Unity yet, here is how: https://unity3d.com/learn/tutorials/topics/scripting/inheritance

The same as with any object inheritance. You will start with a base class and work down.

So you would make one script for items.

Then 4 script objects for Weapons, Consumables, Wearables and KeyItems.

Then each will get there own subs for example: Weapons -> 1 handed, 2 handed.

Just keep doing this until you are happy and then at the very end make a converter to go from Unity C# to XML. That is how I would do it.

2 hours ago, standinonstilts said:

What interfaces/classes/other would you implement; why?

What ever I think is more important to the game.

For example if each character has 2 weapon slots for there hands 1 and 2 handed weapon groups are needed. But if characters can only have one weapon and don't have a offhand slot you can just skip these.

In the end it's about what makes it easy for you and what the game needs.

This topic is closed to new replies.

Advertisement