Jump to content
  • Advertisement
Sign in to follow this  
deuces225

Equipping items to a player in RPG game

This topic is 2564 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya,


I'm currently working on programming an RPG game/game engine and I'm trying to figure out how to correct my equipment system. I have a class called Weapon that is an extension of an item class. I have multiple of the same weapon in my inventory, let's say a dagger. When one party memeber equips this dagger, each dagger is equipped by this member therefore disabling the other party member to equip said item.


I know the problem is that I am passing the weapon object as a reference instead of value, but I'm unable to figure out how to pass each weapon object as its own weapon without having to create a seperate class for each individual weapon. I know it's a rather simple fix, but I'm racking my brain trying to figure this out.

Finally, Im using Java, but am in the process of translating the project into C++, I'm guessing this may be what pointers are for(probably not actually)...haven't read up on them in a long time so I've forgotten somewhat.
Can't instantiate this weapon!!! Don't wanna have to recreate the constructor parameters each time I make it!



Thanks in advance... =)

Share this post


Link to post
Share on other sites
Advertisement
You need to have a separate instance of Weapon for each actual "physical" weapon item in the game. Then, store a container of Items that are equipped per player. When a player equips a specific item, move the corresponding instance into the container. When unequipping, move back out and into a "on the ground" or "shared among the party" container, or something like that.

Share this post


Link to post
Share on other sites

You need to have a separate instance of Weapon for each actual "physical" weapon item in the game. Then, store a container of Items that are equipped per player. When a player equips a specific item, move the corresponding instance into the container. When unequipping, move back out and into a "on the ground" or "shared among the party" container, or something like that.


Thanks for the reply!

I can picture this, for my weapon constructor i've done that, for each seperate equippable weapon in the game I construct the weapon like so...


//somewhat pseudo code;

Weapon Dagger = new Weapon(arguments);
Weapon Slingshot = new Weapon(arguments);
Inventory.addItem(Dagger);
Inventory.addItem(Slingshot); //Let's say the character's inventory class contains a Dagger, and a Slingshot already
inventory.addItem(Dagger);

for(Item i : Game.n.inv.userTotalItems) //Item are abstract classes that include Weapons/Items/Armor/Key Items etc with Constructors for each different type
//So for each item that is in the userTotalItem(ArrayList of total items by the user), of the inventory class(inv), which is located in my (equipmentMenu), in the game
{
if(i.slotType == selectedSlot.slotType && !i.equipped) (if the slot type of the equippable item matches the actual slot's slot type and it is equipped)
{
listNum++;
System.out.println(listNum+". "+i.name+"("+i.slotType+")");
}
else if(i.slotType == selectedSlot.slotType && i.equipped) (if the slot type of the equippable item matches the actual slot's slot type and it isn't equipped)
{
listNum++;
System.out.println(listNum+". "+i.name+" ("+i.slotType+") ("+i.owner.name+")");
}
}


I think im having problems first off with this block of cde, it only lists the inventory as having one item in the inventory ...


Blagh, I guess what I'm trying to figure out is how to instantiate objects in java?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!