Developer Store
Support
Member Forums

Screenshots
FAQ
Documentation
License
Known Issues
Downloads

MMOWorkshop BACK!

PyTorque
TGB Web Browser


hallsofvalhalla

hallsofvalhalla - Been A while
xapken - Wizards and Champions
J.C. Smith - The Repopulation - 0.5.2 Build Notes
EmpireGames - Elementals in Rise of Heroes
Empire Games - WarPath.
jaidurn - Warcall 0.0.1.0 build notes
medafor - Final detailing of models
Thamior - Presence system GONE! [May 25th 2009)]
... MORE BLOGS!

Building a MMO
Wow I had no idea....
Quest Remnants of Chaos
Checking to see if anyone is sti...
Well here I am again :)
T3D and MMOKit
afx 2.0
Terrain specularity [video]
Torque T3D MMO Kit
[3dFoin] Dragon Bug

Pick up items from the ground

The MMOKit allows selecting mobs, corpses and bindpoints. You can interact with static shapes that have a dialog attached. None of these options helps much in my plan to have items you can drop and pick up.

That means I have to add another option in the selecting code in PyTorque. I added this to rpg/gui/rpgTSCtrl.cc in process() starting in line 303:

 if (! corpseSelect) {
	 mask = ItemObjectType;
	 if (gServerContainer.collideBox(startPnt, endPnt, mask, &ri)) {
		 selected = ri.object;
         char wtf[64];
         dSprintf(wtf,64,"%s",selected->getIdString());
         int doubleClick = m_doubleClick;
         const char* vret = Con::evaluatef("Py::Select(\"%s\",\"%s\",%i, %i, %i);",
             so->getIdString(),wtf,m_charIndex,doubleClick,m_modifier&SI_SHIFT);
	 return;
	 }
 }

In world/SimMind select() we have to check for a selected item:

    def select(self,srcId,tgtId,charIndex,doubleClick,modifier_shift):
        if self.selectCredit.get(srcId,None):
            return
        try:
            src = self.simLookup[srcId]
        except KeyError:
            print "simmind.select: source not found"
            return
        try:
            tgt = self.simLookup[tgtId]
        except KeyError:
            try:
                tgt = self.simItemLookup[tgtId]
                print "simmind: select() : %s"%tgtId
                self.perspective.callRemote('SimAvatar','select',srcId,tgtId,charIndex,doubleClick,modifier_shift)
                return
            except KeyError:
                print "simmind.select: target not found"
                return
        
        self.selectCredit[srcId] = True
        
        d = self.perspective.callRemote('SimAvatar','select',srcId,tgtId,charIndex,doubleClick,modifier_shift)
        d.addCallback(self.grantSelectCredit,srcId)
        d.addErrback(self.grantSelectCredit,srcId)

In case it's not a SimObject we check the simItemLookup where the SimItem objects are stored. We call the perspective_select in SimAvatar as we do with a SimObject.

    #mouse selection
    def perspective_select(self,srcId,tgtId,charIndex,doubleClick,modifier_shift):
        try:  # can be deleted in the meantime
            self.zone.select(self.simLookup[srcId],self.simLookup[tgtId],charIndex,doubleClick,modifier_shift)
        except KeyError:
            try:
                self.zone.selectItem(self.simLookup[srcId],self.simItemLookup[tgtId],charIndex,doubleClick,modifier_shift)
            except KeyError:
                traceback.print_exc()

As with dropping we end up in the zone code in a new function selectItem in ZoneInstance:

    def selectItem(self,srcSimObject,tgtSimItem,charIndex,doubleClick,modifier_shift):
        item = self.itemLookup[tgtSimItem]
        mob = self.mobLookup[srcSimObject]
        player = mob.player
        try:
            print "selectItem:"
            print tgtSimItem.position
            distance = (vec3(player.simObject.position) - vec3(map(float, tgtSimItem.position))).length()
            if distance > 2.0:
                player.sendGameText(RPG_MSG_GAME_LOOT,r'The item is too far away.\n')
                return
        except:
            print_exc()
        if doubleClick or modifier_shift:
            if player.giveItemInstance(item):
                # remove from itemLookup (key:SimItem, value:Item)
                del self.itemLookup[tgtSimItem]
                droppedItem = self.itemDropped[tgtSimItem]
                droppedItem.destroySelf();
                del self.itemDropped[tgtSimItem]
                self.simAvatar.deleteItem(tgtSimItem)
                return
        player.sendGameText(RPG_MSG_GAME_LOOT,r'This is %s.\n'%item.name)

The deleteItem in world/SimAvatar is:

    def deleteItem(self, simItem):
        self.mind.callRemote("deleteItem", simItem.id)

and in world/SimMind:

    def remote_deleteItem(self, id):
        tge = TGEObject(id)
        si = self.simItemLookup[id]
        del self.simItemLookup[id]
        self.simItems.remove(si)
        tge.delete()