From 1d19309cd59dbac7e6c0505b3c1944d2b081788f Mon Sep 17 00:00:00 2001 From: Jason Le Long Date: Sat, 24 Mar 2018 22:35:35 +0000 Subject: First build V2 --- sassbot/modules/artifact2-0/Items.py | 211 +++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 sassbot/modules/artifact2-0/Items.py (limited to 'sassbot/modules/artifact2-0/Items.py') diff --git a/sassbot/modules/artifact2-0/Items.py b/sassbot/modules/artifact2-0/Items.py new file mode 100644 index 0000000..7841d7d --- /dev/null +++ b/sassbot/modules/artifact2-0/Items.py @@ -0,0 +1,211 @@ +import MySQLdb +import random + +def GenerateEquipment(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=''; + + + itemCode = itemCode.split(':') + + #Generate Rarity + itemGenRarity = CreateEquipmentRarity(phenny, parameters, itemCode[0]) + + #Generate Item + itemGenEquipment = CreateEquipmentName(phenny, parameters, itemCode[1]) + itemGenEquipment['FabledPrefix'] = '' + + #Generate Enchantment + itemGenEnchantment = CreateEquipmentEnchantment(phenny, parameters, itemCode[2], int(itemGenRarity["ID"])) + + #Generate Element + itemGenElement = CreateEquipmentElement(phenny, parameters, itemCode[3], int(itemGenRarity["ID"])) + + #Attempt creating an Artifact + itemGenEquipment = CreateEquipmentArtifact(phenny, parameters, itemGenEquipment, itemCode[4]) + + strRaritySpacing = "" if len(itemGenRarity['RarityName']) == 0 else " " + + + + itemGen={} + itemGen['RarityColor'] = "\x03"+itemGenRarity['RarityColor'] + itemGen['EquipmentName'] = (itemGenEquipment['FabledPrefix'] + + itemGenRarity['RarityName'] + + strRaritySpacing + + ("" if itemGenElement == {} else itemGenElement['EffectName'] + " ") + + itemGenEquipment['EquipmentName'] + " " + + ("" if itemGenEnchantment == {} else itemGenEnchantment['Name'] + " ")) + + itemGen['EquipmentSlot'] = itemGenEquipment['EquipmentSlot'] + itemGen['EquipmentType'] = itemGenEquipment['EquipmentType'] + itemGen['HandsReq'] = itemGenEquipment['HandsReq'] + itemGen['Strength'] = itemGenEquipment['Strength'] + itemGen['Dexterity'] = itemGenEquipment['Dexterity'] + itemGen['Constitution'] = itemGenEquipment['Constitution'] + itemGen['Intelligence'] = itemGenEquipment['Intelligence'] + itemGen['Dodge'] = itemGenEquipment['Dodge'] + itemGen['Crit'] = itemGenEquipment['Crit'] + itemGen['Armor'] = itemGenEquipment['Armor'] + itemGen['Precision'] = itemGenEquipment['Precision'] + itemGen['Resistance'] = itemGenEquipment['Resistance'] + itemGen['Luck'] = itemGenEquipment['Luck'] + itemGen['Block'] = itemGenEquipment['Block'] + itemGen['Permanent'] = itemGenEquipment['Permanent'] + + itemGen['Cost'] = (itemGenEquipment['Cost'] + + (0 if itemGenElement == {} else itemGenElement['Cost']) + + (0 if itemGenEnchantment == {} else itemGenEnchantment['Cost']) + + (0 if itemGenRarity == {} else itemGenRarity['RarityCost'])) + + return itemGen + +def CreateEquipmentName(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() + + #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 + itemGenEquipment['Cost'] = 100 + return itemGenEquipment + +def CreateEquipmentElement(phenny, parameters, itemCode, RarityID): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + + if random.randint(1, 3) is 1 or RarityID <= 3: + itemGenElement = {} + else: + 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() + + itemGenElement['Cost'] = 200 + return itemGenElement + +def CreateEquipmentRarity(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`,`RarityCost` 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 CreateEquipmentEnchantment(phenny, parameters, itemCode, RarityID): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + + if random.randint(1, 3) is 1 or RarityID <= 2: + itemGenEnchantment = {} + else: + 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() + + itemGenEnchantment['Cost'] = 200 + return itemGenEnchantment + +def CreateEquipmentArtifact(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: + # 0 - Will attempt to add an artifact randomly and not exceed the standard limit + if random.randint(1, 100) == 1 and int(itemCode) == 0: + 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 + # 1 - Will not generate item as an artifact + elif int(itemCode) == 1: + itemGenEquipment['FabledPrefix'] = '' + + # 2 - Will force the item to become an artifact and exceed the limit of 2 artifacts + elif int(itemCode) == 2: + 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() + itemGenEquipment['FabledPrefix'] = 'Fabled ' + itemGenEquipment['Permanent'] = 1 + return itemGenEquipment + +def CreateItem(phenny, enemyStats, playerStats, parameters): + import random + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + + # Get random element + c.execute("SELECT `LootName`,`ItemType`,`Potency` FROM `GenLoot` WHERE `Locked`=0 ORDER BY RAND() LIMIT 1") + sqlRarity = c.fetchone() + strLootName = sqlRarity['LootName'] + strItemType = sqlRarity['ItemType'] + intPotency = sqlRarity['Potency'] + + if strItemType == 'Quantity': + intPotency = enemyStats['GoldCarried'] + int( + random.uniform(float(enemyStats['GoldCarried']) * -0.3, float(enemyStats['GoldCarried']) * 0.3)) + + db.close() + return strLootName, intPotency + +def AddToShop(phenny, parameters, item): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + c.execute("""INSERT INTO `PlayerShop` (`Nick`,`Cost`,`Equipped`,`EquipmentColor`,`EquipmentName`,`EquipmentSlot`,`EquipmentType`,`Permanent`,`HandsReq`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`Dodge`,`Crit`,`Armor`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);""", (parameters['Nick'], item['Cost'], 0, item['RarityColor'], item['EquipmentName'], item['EquipmentSlot'], item['EquipmentType'],item['Permanent'], item['HandsReq'], item['Strength'], item['Dexterity'], item['Constitution'], item['Intelligence'], item['Dodge'], item['Crit'], item['Armor']));db.commit(); + return + +def AddToInventory(phenny, parameters, item): + db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB']) + c = db.cursor(MySQLdb.cursors.DictCursor) + c.execute("""INSERT INTO `Items_PlayerInventory` (`EquipmentColor`,`EquipmentName`,`EquipmentSlot`,`EquipmentType`,`Permanent`,`HandsReq`,`Equipped`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`Dodge`,`Crit`,`Armor`,`Nick`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);""", (item['RarityColor'], item['EquipmentName'], item['EquipmentSlot'], item['EquipmentType'],item['Permanent'], item['HandsReq'], 0, item['Strength'], item['Dexterity'], item['Constitution'], item['Intelligence'], item['Dodge'], item['Crit'], item['Armor'],parameters['Nick']));db.commit(); + return \ No newline at end of file -- cgit v1.2.3