summaryrefslogtreecommitdiff
path: root/sassbot/modules/artifact2-0/Resting.py
diff options
context:
space:
mode:
Diffstat (limited to 'sassbot/modules/artifact2-0/Resting.py')
-rw-r--r--sassbot/modules/artifact2-0/Resting.py201
1 files changed, 201 insertions, 0 deletions
diff --git a/sassbot/modules/artifact2-0/Resting.py b/sassbot/modules/artifact2-0/Resting.py
new file mode 100644
index 0000000..b495587
--- /dev/null
+++ b/sassbot/modules/artifact2-0/Resting.py
@@ -0,0 +1,201 @@
+#Python modules
+import MySQLdb
+import math
+import re
+import sys
+
+#Artifact Modules
+sys.path.insert(0, '/home/bouncer/sassbot/modules/artifact2-0/')
+import PlayerStats
+import Enemy
+
+def PlayerResting(phenny, parameters, playerStats, strCmd1, strCmd2):
+ db = MySQLdb.connect(host='localhost', user=phenny.config.mysql_username, passwd=phenny.config.mysql_password, db=parameters['LiveDB'])
+ c = db.cursor(MySQLdb.cursors.DictCursor)
+
+ # Inventory
+ if strCmd1.lower() == 'i' or strCmd1.lower() == 'inventory':
+ try:
+ strCmd2 = int(strCmd2)
+ except ValueError:
+ strCmd2 = 1
+
+ c.execute("SELECT COUNT(ID) AS `ID` FROM `Items_PlayerInventory` WHERE `Nick`=%s", (parameters["Nick"]))
+ sqlSumResult = c.fetchone()
+ intTotalPages = int(math.ceil(float(sqlSumResult["ID"]) / float(5)))
+
+ c.execute("SELECT `ID`,`Equipped`,`EquipmentColor`,`EquipmentName`,`HandsReq` FROM `Items_PlayerInventory` WHERE `Nick` = %s LIMIT 5 OFFSET %s;",(parameters["Nick"], (int(strCmd2) * 5) - 5))
+ sqlItem = c.fetchall()
+
+ if int(strCmd2) > 0 and int(strCmd2) <= intTotalPages:
+ phenny.write(('NOTICE', parameters["Nick"]), "Page " + str(strCmd2) + " of " + str(intTotalPages) + ". ( http://lexicade.uk/artifact.php?nick=" + parameters["Nick"] + " )")
+ for row in sqlItem:
+ strEquipped = 'Equipped ' if str(row["Equipped"]) == '1' else 'Unequipped'
+ strHands = "--" if str(row["HandsReq"]) == '0' else str(row["HandsReq"]) + "H"
+
+ phenny.write(('NOTICE', parameters["Nick"]),str(row["ID"]) + " " + strEquipped + " " + strHands + "\x03" + str(row["EquipmentColor"]) + " " + str(row["EquipmentName"]) + "\0399")
+
+ # Equip
+ elif strCmd1.lower() == 'e' or strCmd1.lower() == 'equip':
+ if playerStats['State'] == 'Rest':
+ # Check to unequip
+ if strCmd2 == 'u' or strCmd2 == 'unequip':
+ c.execute("UPDATE `Items_PlayerInventory` SET `Equipped`=0 WHERE `Nick`=%s;", (parameters["Nick"]));db.commit();
+ return "All items have been unequipped."
+
+ # Check to see if an ID was supplied
+ elif re.match("^[0-9]+$", strCmd2):
+ c.execute("SELECT `ID`,`Nick`,`EquipmentColor`,`EquipmentSlot`,`EquipmentType`,`EquipmentName`,`Equipped`,`HandsReq` FROM `Items_PlayerInventory` WHERE `Nick`=%s AND `ID`=%s",(parameters["Nick"], strCmd2))
+ sqlItem = c.fetchone()
+ if sqlItem is not None:
+ EquipmentID = sqlItem['ID']
+ EquipmentNick = sqlItem['Nick']
+ EquipmentSlot = sqlItem['EquipmentSlot']
+ EquipmentType = sqlItem['EquipmentType']
+ EquipmentName = sqlItem['EquipmentName']
+ EquipmentColor = sqlItem['EquipmentColor']
+ EquipmentEquipped = sqlItem['Equipped']
+ EquipmentHandsReq = sqlItem['HandsReq']
+
+ # If selected item is weapon
+ if EquipmentType == 'Weapon':
+
+ c.execute("SELECT sum(`HandsReq`) AS `HandsReq` FROM `Items_PlayerInventory` WHERE `Nick`=%s AND `EquipmentType`='Weapon' AND `Equipped`=1",(parameters["Nick"]))
+ sqlHandsUsed = c.fetchone()
+ if sqlHandsUsed["HandsReq"] is None:
+ intHandsUsed = 0
+ else:
+ intHandsUsed = sqlHandsUsed["HandsReq"]
+
+ if int(intHandsUsed) + EquipmentHandsReq <= 2 and EquipmentEquipped == 0:
+ c.execute("UPDATE `Items_PlayerInventory` SET `Equipped`=1 WHERE `ID`=%s and `Nick`=%s;",(strCmd2, parameters["Nick"]));db.commit();
+ return "\0399Equipping your \03" + str(EquipmentColor) + EquipmentName + "\0399."
+ elif EquipmentEquipped == 1:
+ c.execute("UPDATE `Items_PlayerInventory` SET `Equipped`=0 WHERE `ID`=%s and `Nick`=%s;",(strCmd2, parameters["Nick"]));db.commit();
+ return "\0399Unequipping your \03" + str(EquipmentColor) + EquipmentName + "\0399."
+ else:
+ return "You can only wield one two-handed weapon, or two one-handed weapons."
+
+ # If selected item is Armor
+ elif EquipmentType == 'Armor':
+ c.execute("SELECT `ID`,`EquipmentType`,`EquipmentSlot` FROM `Items_PlayerInventory` WHERE `Nick`=%s AND `EquipmentType`='Armor' AND `EquipmentSlot`=%s AND `Equipped`=1 GROUP BY `EquipmentType`",(parameters["Nick"], EquipmentSlot))
+ sqlArmor = c.fetchone()
+ if sqlArmor is None:
+ c.execute("UPDATE `Items_PlayerInventory` SET `Equipped`=1 WHERE `ID`=%s and `Nick`=%s;",(strCmd2, parameters["Nick"]));db.commit();
+ return "\0399Equipping your \03" + str(EquipmentColor) + EquipmentName + "\0399."
+
+ elif sqlArmor['ID'] == EquipmentID:
+ strArmorID = sqlArmor['ID']
+ strArmorType = sqlArmor['EquipmentType']
+ strArmorHands = sqlArmor['EquipmentSlot']
+ c.execute("UPDATE `Items_PlayerInventory` SET `Equipped`=0 WHERE `ID`=%s and `Nick`=%s;",(strCmd2, parameters["Nick"]));db.commit();
+ return "\0399Unequipping your \03" + str(EquipmentColor) + EquipmentName + "\0399."
+
+ else:
+ return "\0399You already have an item in this slot."
+
+ # All other checks failed, print help message
+ else:
+ return "Available commands: e (u)nequip all, e <ID to equip/unequip>"
+ else:
+ return "You must rest before changing your equipment."
+
+ # Destroy
+ elif strCmd1.lower() == 'd' or strCmd1.lower() == 'destroy':
+ if re.match("^[0-9]+$", strCmd2):
+ c.execute("SELECT `ID`,`Nick`,`EquipmentColor`,`EquipmentSlot`,`EquipmentType`,`EquipmentName`,`Equipped`,`HandsReq` FROM `Items_PlayerInventory` WHERE `Nick`=%s AND `ID`=%s",(parameters["Nick"], strCmd2))
+ sqlItem = c.fetchone()
+ itemName = sqlItem['EquipmentName']
+ itemColor = sqlItem['EquipmentColor']
+ if sqlItem is not None:
+ c.execute("DELETE FROM `Items_PlayerInventory` WHERE `Nick`=%s AND `ID`=%s",(parameters["Nick"], strCmd2));db.commit();
+ return "Your \x03" + str(itemColor) + itemName + "\x0399 has been destroyed."
+
+ # Battle
+ elif strCmd1.lower() == 'b' or strCmd1.lower() == 'battle':
+ enemyStats = {}
+ if playerStats['ChallengeRating'] == int(math.ceil(playerStats['ChallengeRating'] / 4) * 4):
+ enemyStats = Enemy.Create(phenny, enemyStats, playerStats, parameters)
+ return "\0399Your fighting has caught the attention of the \03" + str(enemyStats['EnemyColor'])+enemyStats['EnemyName'] + "\0399."
+ else:
+ enemyStats = Enemy.Create(phenny, enemyStats, playerStats, parameters)
+ return "\0399You've been attacked by \03" + str(enemyStats['EnemyColor']) + enemyStats['EnemyName'] + "\0399."
+
+ # Character
+ elif strCmd1.lower() == 'c' or strCmd1.lower() == 'character':
+ PlayerStats.RefreshStats(phenny, parameters)
+ return PlayerStats.PrintStats(phenny, input, parameters)
+
+ # Shop
+ elif strCmd1.lower() == 's' or strCmd1.lower() == 'shop':
+ if strCmd2 is '':
+ c.execute("SELECT `ID`,`Cost`,`EquipmentColor`,`EquipmentName` FROM `PlayerShop` WHERE `Nick`=%s",parameters["Nick"])
+ sqlShopItem = c.fetchone()
+ while sqlShopItem is not None:
+ phenny.write(('NOTICE', parameters["Nick"]), str(sqlShopItem['ID']) + " \03" + sqlShopItem['EquipmentColor'] + sqlShopItem['EquipmentName'] + "\0399 " + str(sqlShopItem['Cost']) + " gold")
+ # phenny.reply("\03"+sqlShopItem['EquipmentColor']+sqlShopItem['EquipmentName']+"\0399 "+str(sqlShopItem['Cost'])+" gold")
+ sqlShopItem = c.fetchone()
+ else:
+ c.execute("SELECT `ID`,`Cost` FROM `PlayerShop` WHERE `ID`=%s and `Nick`=%s",(strCmd2, parameters["Nick"]))
+ sqlItemBought = c.fetchone()
+ if sqlItemBought is None:
+ return "\0399The shopkeep doesn't know what item you ask for."
+
+ elif playerStats['Currency'] < sqlItemBought['Cost']:
+ return "You cannot afford this item."
+
+ else:
+
+
+
+ c.execute("SELECT `Nick`,`Cost`,`EquipmentColor`,`EquipmentName`,`EquipmentSlot`,`EquipmentType`,`HandsReq`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`Dodge`,`Crit`,`Armor`, `Precision`, `Resistance`, `Luck`, `Block` FROM `PlayerShop` WHERE `ID`=%s",strCmd2)
+ sqlItemBought = c.fetchone()
+ c.execute("INSERT INTO `Items_PlayerInventory` (`Nick`,`Equipped`,`EquipmentColor`,`EquipmentName`,`EquipmentSlot`,`EquipmentType`,`HandsReq`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`Dodge`,`Crit`,`Armor`, `Precision`, `Resistance`, `Luck`, `Block`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);", (
+ parameters["Nick"], 0, sqlItemBought['EquipmentColor'], sqlItemBought['EquipmentName'],sqlItemBought['EquipmentSlot'], sqlItemBought['EquipmentType'],
+ sqlItemBought['HandsReq'], sqlItemBought['Strength'], sqlItemBought['Dexterity'],sqlItemBought['Constitution'], sqlItemBought['Intelligence'],
+ sqlItemBought['Dodge'], sqlItemBought['Crit'],sqlItemBought['Armor'],sqlItemBought['Precision'],sqlItemBought['Resistance'],sqlItemBought['Luck'],sqlItemBought['Block']));db.commit();
+ c.execute("DELETE FROM `PlayerShop` WHERE `Nick`=%s and `ID`=%s",(str(parameters["Nick"]), strCmd2));db.commit();
+ c.execute("UPDATE `Players` SET `Currency`=`Currency`-%s WHERE `Nick`=%s;",(sqlItemBought['Cost'], parameters["Nick"]));db.commit();
+ return "\0399The \03" + sqlItemBought['EquipmentColor'] + sqlItemBought['EquipmentName'] + "\0399 has been added to your inventory."
+
+ # Heal
+ elif strCmd1.lower() == 'r' or strCmd1.lower() == 'rest':
+ playerStats = PlayerStats.RefreshStats(phenny, parameters)
+ intHPGained = int(math.ceil(playerStats['MaxHP'] / 2))
+
+ if playerStats['RestedHeal'] == 0:
+ if playerStats['HP'] >= playerStats['MaxHP']:
+ return "\0399You rest. You are already at max HP."
+
+ elif intHPGained + playerStats['HP'] > playerStats['MaxHP']:
+ intHPGained = playerStats['MaxHP']
+ c.execute("UPDATE `Players` SET `HP`=%s, `RestedHeal`=1 WHERE `Nick`=%s;",(intHPGained, parameters["Nick"]));db.commit();
+ return "\0399You rest and your wounds heal completely."
+
+ elif playerStats['HP'] < playerStats['MaxHP']:
+ c.execute("UPDATE `Players` SET `HP`=`HP`+%s, `RestedHeal`=1 WHERE `Nick`=%s;",(intHPGained, parameters["Nick"]));db.commit();
+ return "\0399You rest and you recover " + str(intHPGained) + " HP."
+ else:
+ return "\0399You rest."
+
+ # DEBUG - CREATE WEAPON
+ elif strCmd1.lower() == 'z':
+ itemCode = input.group(2)[2:].split(':')
+ #phenny.say(str(itemCode[0])+str(itemCode[1])+str(itemCode[2])+str(itemCode[3]))
+ return GenerateItem.CreateItem(phenny, parameters, itemCode)
+
+ # Version
+ elif strCmd1.lower() == 'v' or strCmd1.lower() == 'version':
+ return "Version 1.3 - Notes can be found at: http://www.lexicade.uk/dev.php?view=patchnotes"
+
+ # Admin commands
+ elif strCmd1.lower() == 'genitem' and input.admin:
+ GenEquipment(phenny, itemGenEquipment, parameters, 'Items_PlayerPool')
+
+ # Death
+ elif strCmd1.lower() == 'suicide':
+ CharacterDeath(phenny, playerStats, parameters)
+ return "You committed suicide."
+
+ else:
+ return "\0399Available commands: (i)nventory, (e)quip, (b)attle, (c)haracter, (s)hop, (r)est, (v)ersion, (d)estroy." \ No newline at end of file