Sign in to follow this  
deuces225

Equipping items to a player in RPG game

Recommended Posts

deuces225    120
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
ApochPiQ    23003
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
deuces225    120
[quote name='ApochPiQ' timestamp='1310253763' post='4833188']
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.
[/quote]

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([i]arguments);
[/i]Weapon Slingshot = new Weapon([i]arguments[/i]);
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this