Esempio n. 1
0
def getItemDescription(cursor, roomid, cmd):
	query = Q.GetItemDescription % {DC.RoomID: roomid}
	res = pgDB.fetch(cursor, query)
	cmd = cmd[1]
	desc = "You look around but you can't see a %s.\r\n" %cmd
	for description, keywords in res:
		keywords = keywords.split(",")
		if cmd in keywords:
			desc = description + "\r\n"
	return desc
Esempio n. 2
0
def getItemDescription(cursor, roomid, cmd):
    query = Q.GetItemDescription % {DC.RoomID: roomid}
    res = pgDB.fetch(cursor, query)
    cmd = cmd[1]
    desc = "You look around but you can't see a %s.\r\n" % cmd
    for description, keywords in res:
        keywords = keywords.split(",")
        if cmd in keywords:
            desc = description + "\r\n"
    return desc
Esempio n. 3
0
def getItemForUser(cursor, cmdList, roomID, username):
	"""
	Gives a user the item they tried to pickup if possible.
	"""
	query = Q.GetItemsForUser % {DC.RoomID: roomID}
	res = pgDB.fetch(cursor, query)
	print "res = %s" %res
	cmd = cmdList[1]
	print "cmd = %s" %cmd
	desc = "You screw your eyes shut and wish really hard for a %s\r\n" %cmd
	for itemID, keywords, itemCount in res:
		keywords = keywords.split(",")
		print "keywords %s" %keywords
		if cmd in keywords:
			print "cmd in keywords"
			print "itemCount %s"  %itemCount
			if int(itemCount) > 0:
				print "hello" 
				# FIXME: Do all these queries in one transaction.
				# Get The users existing inventory.
				InventoryQ = Q.GetUserInventory % {"UserID":username}
				inventory = pgDB.fetchOne(cursor, InventoryQ)

				# Remove one of the item from the room it was in.
				itemCount = int(itemCount) - 1
				UpdateCount = Q.UpdateItemCount % {"ItemID":itemID,
												"ItemCount":itemCount,}
				pgDB.executeOne(cursor, UpdateCount)

				# Place one of the item into the users inventory.
				newInventory = []
				existing = ""
				if inventory[0]:
					print "inventory %s" %repr(inventory)
					inventory = inventory.split(",")
					for item, count in inventory[0].split(":"):
						if itemID == item:
							count = int(count) + 1
							existing = "1"
							newInventory.append("%s:%s" %(itemID, str(count)))
						else:
							newInventory.append("%s:%s" %(itemID, count))
							
				if not existing:
					newInventory.append("%s:1" %itemID)
				
				newInventory = ",".join(newInventory)
				
				UpdateInvQ = Q.UpdateUserInventory % {"UserID":username,
													"Inventory":newInventory,}
				pgDB.executeOne(cursor, UpdateInvQ)
			else:
				desc = "You pickup a %s\r\n" %cmd
	return desc
Esempio n. 4
0
def getItemForUser(cursor, cmdList, roomID, userID):
    """
	Takes an item from a room and places it in the users inventory.
	"""
    query = Q.GetItemsForUser % {DC.RoomID: roomID}
    res = pgDB.fetch(cursor, query)
    cmd = cmdList[1]
    desc = "You screw your eyes shut and wish really hard for a %s.\r\n" % cmd
    for itemID, keywords, roomItemCount in res:
        keywords = keywords.split(",")
        if cmd in keywords:
            if int(roomItemCount) == -1:
                desc = "I can't do that Dave.\r\n"
            elif int(roomItemCount) > 0:
                # Remove one of the item(s) from the room it was in.
                itemCount = int(roomItemCount) - 1
                updateCount = Q.UpdateRoomItemCount % {
                    "ItemID": itemID,
                    "ItemCount": roomItemCount,
                    "RoomID": roomID
                }
                pgDB.executeOne(cursor, updateCount)

                #Create/update a stack of items if the user already has one.
                userItemCountQ = Q.GetUserItemCount % {
                    "ItemID": itemID,
                    "UserID": userID
                }
                userItemCount = pgDB.fetchOne(cursor, userItemCountQ)

                #increment the item count and update the database
                if not userItemCount:
                    userItemCount = 1

                    updateInvQ = Q.CreateUserItem % {
                        "UserID": userID,
                        "ItemID": itemID,
                        "ItemCount": userItemCount
                    }
                else:
                    userItemCount = int(userItemCount[0]) + 1

                    updateInvQ = Q.UpdateUserItem % {
                        "UserID": userID,
                        "ItemID": itemID,
                        "ItemCount": userItemCount
                    }

                res = pgDB.executeOne(cursor, updateInvQ)
                desc = "You pickup the %s.\r\n" % cmd
    return desc
Esempio n. 5
0
def getItemForUser(cursor, cmdList, roomID, userID):
	"""
	Takes an item from a room and places it in the users inventory.
	"""
	query = Q.GetItemsForUser % {DC.RoomID: roomID}
	res = pgDB.fetch(cursor, query)
	cmd = cmdList[1]
	desc = "You screw your eyes shut and wish really hard for a %s.\r\n" %cmd
	for itemID, keywords, roomItemCount in res:
		keywords = keywords.split(",")
		if cmd in keywords:
			if int(roomItemCount) == -1:
				desc = "I can't do that Dave.\r\n"
			elif int(roomItemCount) > 0:
				# Remove one of the item(s) from the room it was in.
				itemCount = int(roomItemCount) - 1
				updateCount = Q.UpdateRoomItemCount % {"ItemID":itemID,
												"ItemCount":roomItemCount,
												"RoomID":roomID}
				pgDB.executeOne(cursor, updateCount)

				#Create/update a stack of items if the user already has one.
				userItemCountQ = Q.GetUserItemCount % { "ItemID" : itemID,
														"UserID" : userID}
				userItemCount = pgDB.fetchOne(cursor, userItemCountQ)

				#increment the item count and update the database
				if not userItemCount:
					userItemCount = 1

					updateInvQ = Q.CreateUserItem % {"UserID":userID,
													"ItemID": itemID,
													"ItemCount": userItemCount}
				else:
					userItemCount = int(userItemCount[0]) + 1

					updateInvQ = Q.UpdateUserItem % {"UserID":userID,
													"ItemID": itemID,
													"ItemCount": userItemCount}

				res	= pgDB.executeOne(cursor, updateInvQ)
				desc = "You pickup the %s.\r\n" %cmd
	return desc
Esempio n. 6
0
def getThreads(cursor, useridList):
	print useridList
	users = "('" + "','".join(useridList) + "')"
	query = Q.GetThreads % users
	return pgDB.fetch(cursor, query)
Esempio n. 7
0
def getUsersInRoom(cursor, roomid):
	query = Q.GetUsersInRoom % {DC.Location: roomid}
	return pgDB.fetch(cursor, query)
Esempio n. 8
0
def getThreads(cursor, useridList):
    print useridList
    users = "('" + "','".join(useridList) + "')"
    query = Q.GetThreads % users
    return pgDB.fetch(cursor, query)
Esempio n. 9
0
def getUsersInRoom(cursor, roomid):
    query = Q.GetUsersInRoom % {DC.Location: roomid}
    return pgDB.fetch(cursor, query)