From 5b3e69b1b42fd7608822b4b96672202d8402c712 Mon Sep 17 00:00:00 2001 From: Jason Le Long Date: Wed, 7 Mar 2018 17:24:52 +0000 Subject: Alpha 1 --- sassbot/modules/artifact2-0/EquipmentCreate.py | 139 +++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 sassbot/modules/artifact2-0/EquipmentCreate.py (limited to 'sassbot/modules/artifact2-0') diff --git a/sassbot/modules/artifact2-0/EquipmentCreate.py b/sassbot/modules/artifact2-0/EquipmentCreate.py new file mode 100644 index 0000000..e1520d7 --- /dev/null +++ b/sassbot/modules/artifact2-0/EquipmentCreate.py @@ -0,0 +1,139 @@ +import MySQLdb +import random + +def GenerateItem(phenny, parameters, itemCode): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + intIteration=0 + itemName=strRaritySpacing=''; + + #Generate Rarity + itemGenRarity = CreateItemRarity(phenny, parameters, itemCode[0]) + + #Generate Item + itemGenEquipment = CreateItemName(phenny, parameters, itemCode[1]) + + #Generate Enchantment + itemGenEnchantment = CreateItemEnchantment(phenny, parameters, itemCode[2]) + + #Generate Element + itemGenElement = CreateItemElement(phenny, parameters, itemCode[3]) + + #Attempt creating an Artifact + itemGenEquipment = CreateItemArtifact(phenny, parameters, itemGenEquipment, itemCode[4]) + + strRaritySpacing = "" if len(itemGenRarity['RarityName']) == 0 else " " + + itemGen={} + itemGen['EquipmentName'] = "\x03"+itemGenRarity['RarityColor'] + itemGenEquipment['FabledPrefix'] + itemGenRarity['RarityName'] + strRaritySpacing + itemGenElement['EffectName'] + " " + itemGenEquipment['EquipmentName'] + " " + itemGenEnchantment['Name']+"\x0399" + #itemGen['EquipmentName'] + #itemGen['EquipmentSlot'] + #itemGen['EquipmentType'] + #itemGen['HandsReq'] + #itemGen['Strength'] + #itemGen['Dexterity'] + #itemGen['Constitution'] + #itemGen['Intelligence'] + #itemGen['Dodge'] + #itemGen['Crit'] + #itemGen['Armor'] + #itemGen['Precision'] + #itemGen['Resistance'] + #itemGen['Luck'] + #itemGen['BlockitemGen'] + + return itemGen + +def CreateItemName(phenny, parameters, itemCode): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + itemGenEquipment = {} + + #Item by ID + if int(itemCode) is not 0: + c.execute("SELECT `EquipmentName`, `EquipmentSlot`, `EquipmentType`, `HandsReq`, `Strength`, `Dexterity`, `Constitution`, `Intelligence`, `Dodge`, `Crit`, `Armor`, `Precision`, `Resistance`, `Luck`, `Block` FROM `Items_Master` WHERE `ID` = " + str(itemCode)) + itemGenEquipment = c.fetchone() + return itemGenEquipment + + #Item by Random + elif int(itemCode) is 0: + #UPDATE: Should be able to generate an available weapon with just one query + # Pick random item that is available to the player + c.execute("SELECT `Items_PlayerPool`.`Nick`, `Items_PlayerPool`.`EquipmentName`, `Items_Master`.`Locked` FROM `Items_PlayerPool` INNER JOIN `Items_Master` ON `Items_PlayerPool`.`EquipmentName` = `Items_Master`.`EquipmentName` WHERE `Nick`=%s AND `Locked`=0 ORDER BY RAND() LIMIT 1",parameters['Nick']) + sqlItemPlayer = c.fetchone() + + # Get information from randomly picked weapon + c.execute("SELECT `EquipmentName`, `EquipmentSlot`, `EquipmentType`, `HandsReq`, `Strength`, `Dexterity`, `Constitution`, `Intelligence`, `Dodge`, `Crit`, `Armor`, `Precision`, `Resistance`, `Luck`, `Block` FROM `Items_Master` WHERE `EquipmentName`=%s",sqlItemPlayer['EquipmentName']) + itemGenEquipment = c.fetchone() + itemGenEquipment['Permanent'] = 0 + return itemGenEquipment + +def CreateItemElement(phenny, parameters, itemCode): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + itemGenElement = {} + if int(itemCode) is not 0: + c.execute("SELECT `EffectName`, `Strength`, `Dexterity`, `Constitution`, `Intelligence`, `Dodge`, `Crit`, `Armor` FROM `GenElement` WHERE `ID` = %s",itemCode) + itemGenElement = c.fetchone() + elif int(itemCode) is 0: + c.execute("SELECT `EffectName`, `Strength`, `Dexterity`, `Constitution`, `Intelligence`, `Dodge`, `Crit`, `Armor` FROM `GenElement` ORDER BY RAND() LIMIT 1") + itemGenElement = c.fetchone() + return itemGenElement + +def CreateItemRarity(phenny, parameters, itemCode): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + itemGenRarity = {} + if int(itemCode) is not 0: + c.execute("SELECT `ID`,`RarityName`,`RarityColor`,`RarityModifier`,`RarityChance`,`RarityCost` FROM `GenRarity` WHERE `ID` = " + str(itemCode)) + itemGenRarity = c.fetchone() + elif int(itemCode) is 0: + # Obtain sum of all rarities + c.execute("SELECT SUM(`RarityChance`) AS RarityTotal FROM `GenRarity`") + intRarityTotal = c.fetchone()['RarityTotal'] + + # Variable declaration + intIteration = 0 + intRandom = random.randint(1, intRarityTotal) + + while True: + intIteration = intIteration + 1 + + # Obtain Rarity in order of lowest to highest with each iteration + c.execute("SELECT `ID`,`RarityName`,`RarityColor`,`RarityModifier`,`RarityChance` FROM `GenRarity` WHERE `ID` = " + str(intIteration)) + itemGenRarity = c.fetchone() + + # Subtract the current iterations rarity from the random roll + # If intRandom becomes negative, our item rarity has been found. End the loop. + intRandom = intRandom - itemGenRarity['RarityChance'] + if intRandom <= 0: + break + return itemGenRarity + db.close() + +def CreateItemEnchantment(phenny, parameters, itemCode): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + itemGenElement = {} + if int(itemCode) is not 0: + c.execute("SELECT `Name`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`Dodge`, `Crit`, `Armor` FROM `GenEnchantment` WHERE `ID` = %s", str(itemCode)) + itemGenEnchantment = c.fetchone() + elif int(itemCode) is 0: + c.execute("SELECT `Name`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`Dodge`, `Crit`, `Armor` FROM `GenEnchantment` ORDER BY RAND() LIMIT 1") + itemGenEnchantment = c.fetchone() + return itemGenEnchantment + +def CreateItemArtifact(phenny, parameters, itemGenEquipment, itemCode): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + # Gen for Artifact item: + if random.randint(1, 150) == 1 or int(itemCode) == 1: + if itemGenEquipment['EquipmentType'] == 'Armor' or itemGenEquipment['EquipmentType'] == 'Weapon': + c.execute("SELECT COUNT(`Permanent`) AS `Artifacts` FROM `Items_PlayerInventory` WHERE `Nick`=%s AND `Permanent`=1;",parameters['Nick']) + sqlCountArtifacts = c.fetchone() + if sqlCountArtifacts['Artifacts'] < 2: + itemGenEquipment['FabledPrefix'] = 'Fabled ' + itemGenEquipment['Permanent'] = 1 + else: + itemGenEquipment['FabledPrefix'] = '' + return itemGenEquipment \ No newline at end of file -- cgit v1.2.3