2 Replies - 3956 Views - Last Post: 27 December 2012 - 06:11 PM Rate Topic: -----

#1 Mr909  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-December 12

Customizing calls, aliasing, and functions on container object

Posted 19 December 2012 - 05:14 PM

So, I'm trying to develop an RPG inventory array for asymmetric objects, that is to say, each object will have attributes that are vastly different from other objects in the same inventory.
In an attempt to solve this, I gave my item class only four characteristics, the name, cost, and weight (common to all items) and then a list of "nodes" defining additional object attributes. The thing is, due to the lack of internal order or count on the nodes being relevant (I don't want/need to know the individual node position) I was trying to simplify node modification along these guidelines:

Objects are subject to an upper limit of 1 node_container. I want to modify ctyp and size by using (item).size instead of (item).nodes[x].size, where x is the position of the node.

For attack and materials, I want to modify only the first instance of a node_attack. So, (item).dmg would actually modify (item).nodes[x].dmg, where x is the first instance of an attack node. In theory, it would be great if I could have a way to choose which attack to modify by modifying the call, but that's totally beyond me.

I'm also trying to modify the sort calls to sort the node list according to type, but I don't know how to determine which objects are in the list.

I was also wondering if I could use the set attribute call to modify the attribute in a freshly created node upon detection that the node currently doesn't exist, i.e. setting dmg would automatically add a node_attack to the item's node container. I started figuring out the get attribute calls, but I kept getting all sorts of crazy syntax errors I'd never even heard before.

I've currently tried this several different times, and the documentation on objects provides little to no help without examples as to how to actually implement it. I've been running in circles and Googling the heck out of it to no avail.



class item:
	name=str()
	cost=int()
	weight=int()
	nodes=[]

	def __repr__(self):
		return self.name

	def len(self):
		return len(self.nodes)

	def pop(n):
		return self.nodes.pop(n)

	def append(i):
		self.nodes.append(i)

class node_attack:
	skname=str()
	dmg=int()
	acc=float()

class node_container:
	ctyp=int()
	size=int()

class node_material:
	matname=str()
	mat=int()
	vol=int()

class node_feature:
	ftyp=int()
	detail=str()


Is This A Good Question/Topic? 0
  • +

Replies To: Customizing calls, aliasing, and functions on container object

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Customizing calls, aliasing, and functions on container object

Posted 24 December 2012 - 12:56 AM

Have you considered using inheritance where you can have a basic "Item" class, and then you can create subclasses of this item class for the more specific types of items.

ie:

Base Class: Item class
Child Class: consumable
Child Class: Ammo
Child Class: Equipment
Grandchild Class: Weapon
Grandchild Class: Armor


This post has been edited by atraub: 24 December 2012 - 12:58 AM

Was This Post Helpful? 0
  • +
  • -

#3 Mr909  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-December 12

Re: Customizing calls, aliasing, and functions on container object

Posted 27 December 2012 - 06:11 PM

Yeah, that was my original setup in the original project but I found it wasn't nearly as flexible as it could have been.

I shall elaborate on what I meant for "asymmetric objects"

In Diablo II and other such games, items have characteristics that vary widely, not only between subtypes but between items of the same subtype. I.E.

Basic Sword- 5 Traits
  • Subtype (Of Weapon)-Sword
  • Graphic
  • Space Occupied
  • Weapon Damage
  • Durability


Enchanted Sword +1, 2 Sockets (1 Amethyst) -8 Traits
  • Subtype (Of Weapon)-Sword
  • Graphic
  • Space Occupied
  • Weapon Damage
  • Durability
  • Enchantment 1 Data
  • Socket (Amethyst)
  • Socket (Empty)


So, as you see, items are going to be asymmetric no matter what. I also plan to implement features that involve weapons that have multiple attacks, etc. and it would be really easy if I could just have one big list of traits to draw from.

Either way, even if subtypes were subclasses, there becomes a smaller version of the node-type problem with the main inventory, it being a list of items that are the same subclass of a different main class. I would still have to figure out how to do what I set out to do, that is, figure out which item had which attribute, edit attributes if they existed, etc. It just helps a lot with the severe amount of overlap, especially between the equipment types.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1