summaryrefslogtreecommitdiff
path: root/sassbot/modules/artifact2-0/Enemy.py
diff options
context:
space:
mode:
Diffstat (limited to 'sassbot/modules/artifact2-0/Enemy.py')
-rw-r--r--sassbot/modules/artifact2-0/Enemy.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/sassbot/modules/artifact2-0/Enemy.py b/sassbot/modules/artifact2-0/Enemy.py
new file mode 100644
index 0000000..1d55941
--- /dev/null
+++ b/sassbot/modules/artifact2-0/Enemy.py
@@ -0,0 +1,78 @@
+import MySQLdb
+import math
+import random
+
+def Create(phenny, enemyStats, playerStats, parameters):
+ db = MySQLdb.connect(host="localhost", user=phenny.config.mysql_username, passwd=phenny.config.mysql_password,db=parameters['LiveDB'])
+ c = db.cursor(MySQLdb.cursors.DictCursor)
+
+ # Update player state for combat
+ c.execute("UPDATE `Players` SET `State`='Combat' WHERE `Nick`=%s;", (parameters['Nick']));db.commit();
+
+ if playerStats['ChallengeRating'] == int(math.ceil(playerStats['ChallengeRating'] / 4) * 4):
+ # Get total unluck enemy weighting
+ c.execute("SELECT SUM(`EnemyWeight`) AS `EnemyWeight` FROM `GenEnemy` WHERE `Locked`=0 AND `Class`='Boss'")
+ intTotalWeight = random.randint(1, int(c.fetchone()['EnemyWeight']))
+
+ #Get Boss
+ c.execute("SELECT `EnemyColor`, `EnemyName`, `Season`, `Class`, `Unlock`, `HP`, `Locked`, `EnemyWeight`, `ChallengeRating`, `GoldCarried`, `Strength`, `Dexterity`, `Constitution`, `Intelligence`, `Dodge`, `Crit` "+
+ "FROM `GenEnemy` WHERE `Locked`=0 AND `Class`='Boss'")
+ else:
+ # Get total unluck enemy weighting
+ c.execute("SELECT SUM(`EnemyWeight`) AS `EnemyWeight` FROM `GenEnemy` WHERE `Locked`=0 AND `Class`='Rare' OR `Locked`=0 AND `Class`='Minor'")
+ intTotalWeight = random.randint(1, int(c.fetchone()['EnemyWeight']))
+
+ #Get enemy
+ c.execute("SELECT `EnemyColor`, `EnemyName`, `Season`, `Class`, `Unlock`, `HP`, `Locked`, `EnemyWeight`, `ChallengeRating`, `GoldCarried`, `Strength`, `Dexterity`, `Constitution`, `Intelligence`, `Dodge`, `Crit` "+
+ "FROM `GenEnemy` WHERE `Locked`=0 AND `Class`='Rare' OR "+
+ "`Locked`=0 AND `Class`='Minor'")
+ enemyStats = c.fetchone()
+
+ while True:
+ intTotalWeight = intTotalWeight - enemyStats['EnemyWeight']
+ if intTotalWeight <= 0:
+ break
+ else:
+ enemyStats = c.fetchone()
+
+ #Apply challenge rating modifier to enemy
+ intChallengeModifier = 2
+ enemyStats['HP'] = int(math.ceil(enemyStats['HP'] * playerStats['ChallengeRating']/intChallengeModifier))
+ enemyStats['GoldCarried'] = int(math.ceil(enemyStats['GoldCarried'] * playerStats['ChallengeRating']/intChallengeModifier))
+ enemyStats['Strength'] = int(math.ceil(enemyStats['Strength'] * playerStats['ChallengeRating']/intChallengeModifier))
+ enemyStats['Dexterity'] = int(math.ceil(enemyStats['Dexterity'] * playerStats['ChallengeRating']/intChallengeModifier))
+ enemyStats['Constitution'] = int(math.ceil(enemyStats['Constitution'] * playerStats['ChallengeRating']/intChallengeModifier))
+ enemyStats['Intelligence'] = int(math.ceil(enemyStats['Intelligence'] * playerStats['ChallengeRating']/intChallengeModifier))
+
+ #Create entity in database
+ c.execute("INSERT INTO CombatEnemy(`EnemyColor`,`EnemyName`,`Season`,`Class`,`Nick`,`HP`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`GoldCarried`,`Unlock`) VALUES ('"+
+ str(enemyStats['EnemyColor'])+"','"+str(enemyStats['EnemyName'])+"','"+str(enemyStats['Season'])+"','"+str(enemyStats['Class'])+"','"+parameters['Nick']+"','"+str(enemyStats['HP'])+"','"+str(enemyStats['Strength'])+"','"+str(enemyStats['Dexterity'])+"','"+str(enemyStats['Constitution'])+"','"+str(enemyStats['Intelligence'])+"','"+str(enemyStats['GoldCarried'])+"','"+str(enemyStats['Unlock'])+"')");db.commit();
+
+ #Cleanup
+ db.close()
+ return enemyStats
+
+def GetStats(phenny, parameters, enemyStats):
+ 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("SELECT `EnemyColor`,`EnemyName`, `Class`, `Season`, `Unlock`,`HP`,`GoldCarried`,`Strength`,`Dexterity`,`Constitution`,`Intelligence`,`GoldCarried`, `Dodge`, `Crit` FROM `CombatEnemy` WHERE `Nick`=%s",parameters['Nick'])
+ sqlEnemy = c.fetchone()
+ enemyStats['EnemyColor'] = sqlEnemy['EnemyColor']
+ enemyStats['EnemyName'] = sqlEnemy['EnemyName']
+ enemyStats['Class'] = sqlEnemy['Class']
+ enemyStats['Season'] = sqlEnemy['Season']
+ enemyStats['Unlock'] = sqlEnemy['Unlock']
+ enemyStats['HP'] = sqlEnemy['HP']
+ enemyStats['GoldCarried'] = sqlEnemy['GoldCarried']
+ enemyStats['Strength'] = sqlEnemy['Strength']
+ enemyStats['Dexterity'] = sqlEnemy['Dexterity']
+ enemyStats['Constitution'] = sqlEnemy['Constitution']
+ enemyStats['Intelligence'] = sqlEnemy['Intelligence']
+ enemyStats['DodgePercentage'] = sqlEnemy['Dodge']
+ enemyStats['CritPercentage'] = sqlEnemy['Crit']
+ enemyStats['ArmorPercentage'] = 0
+ enemyStats['UnitType'] = 'Enemy'
+ enemyStats['BlockPercentage'] = 0
+ db.close()
+
+ return enemyStats \ No newline at end of file