diff options
Diffstat (limited to 'sassbot/modules/artifact2-0/Combat.py')
-rw-r--r-- | sassbot/modules/artifact2-0/Combat.py | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/sassbot/modules/artifact2-0/Combat.py b/sassbot/modules/artifact2-0/Combat.py new file mode 100644 index 0000000..155f4c8 --- /dev/null +++ b/sassbot/modules/artifact2-0/Combat.py @@ -0,0 +1,160 @@ +#Python modules
+import MySQLdb
+import math
+import re
+import sys
+import random
+
+#Artifact Modules
+sys.path.insert(0, '/home/bouncer/sassbot/modules/artifact2-0/')
+import PlayerStats
+import Items
+import Enemy
+import PlayerDeath
+
+def PlayerInCombat(phenny, parameters, playerStats, strCmd1, strCmd2):
+ 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)
+
+ playerStats = PlayerStats.RefreshStats(phenny, parameters)
+ enemyStats = Enemy.GetStats(phenny, parameters, enemyStats)
+ strAttackLog = '\x0399'
+
+ # Attack
+ if strCmd1 == 'a' or strCmd1 == 'attack':
+ # Players attack
+ strAttackLog = strAttackLog + PerformAttack(phenny, playerStats, enemyStats, parameters)
+
+ if enemyStats['HP'] < 1:
+ strAttackLog = strAttackLog + "The \03" + str(enemyStats['EnemyColor']) + enemyStats['EnemyName'] + "\0399 falls to the floor. "
+ c.execute("UPDATE `Players` SET `State`='Rest', `RestedHeal`=0, `ChallengeRating`=`ChallengeRating`+0.1 WHERE `Nick`=%s;",(parameters["Nick"]));db.commit();
+
+ if random.randint(1, 3) == 1 and enemyStats['Class'] == 'Minor':
+ # Equipment Drop
+ itemGen = Items.GenerateEquipment(phenny, parameters, "0:0:0:0:0")
+ Items.AddToInventory(phenny, parameters, itemGen)
+ strAttackLog = strAttackLog + "You obtained a " + itemGen['RarityColor'] + " " + itemGen['EquipmentName'] + "\x0399. "
+
+ # Rare drops
+ elif enemyStats['Class'] == 'Rare':
+ #
+ # REQUIRES REWRITE
+ #
+ if enemyStats['Unlock'] == 'Chaos':
+ c.execute("SELECT `EquipmentName`, `EquipmentSlot`, `EquipmentType`, `HandsReq`, `Locked`, `Scaling`, `Strength`, `Dexterity`, `Constitution`, `Intelligence`, `Dodge`, `Crit`, `Armor`, `Requirement` FROM `Items_Master` WHERE `Requirement`='Chaos'")
+ sqlItem = c.fetchone()
+ c.execute("INSERT INTO `Items_PlayerInventory` (`Nick`,`Equipped`,`EquipmentColor`,`EquipmentName`,`EquipmentSlot`,`EquipmentType`,`Permanent`,`Scaling`,`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'], 0, 06, sqlItem['EquipmentName'], sqlItem['EquipmentSlot'],
+ sqlItem['EquipmentType'], 0, sqlItem['Scaling'],
+ sqlItem['HandsReq'], sqlItem['Strength'], sqlItem['Dexterity'],
+ sqlItem['Constitution'], sqlItem['Intelligence'], sqlItem['Dodge'],
+ sqlItem['Crit'], sqlItem['Armor']));
+ db.commit();
+ #TEMP FIX - add a better solution to clearing the enemies
+ c.execute("DELETE FROM `CombatEnemy` WHERE `Nick`=%s", (parameters["Nick"]));db.commit();
+ return "\x0399You acquire a \x0306Shard of Chaos\x0399 from the remains of the enemy."
+
+ # LootDrop
+ if random.randint(1, 1) == 1:
+ strItemName, intItemPotency = Items.CreateItem(phenny, enemyStats, playerStats, parameters)
+ strAttackLog = strAttackLog + "You got " + str(intItemPotency) + " " + strItemName + ". "
+ c.execute("UPDATE `Players` SET `Currency`=`Currency`+%s WHERE `Nick`=%s;",(intItemPotency, parameters["Nick"]));db.commit();
+
+ c.execute("DELETE FROM `CombatEnemy` WHERE `Nick`=%s", (parameters["Nick"]));
+ db.commit();
+ # Attempt to restock shop
+ if random.randint(1, 2) == 1:
+ strAttackLog = strAttackLog + "The shop has been restocked. "
+ c.execute("DELETE FROM `PlayerShop` WHERE `Nick`=%s", (parameters["Nick"]));db.commit();
+
+ intItemsAdded = 0
+ intItemsToAdd = random.randint(2,4)
+
+ while intItemsAdded < intItemsToAdd:
+ Items.AddToShop(phenny, parameters, Items.GenerateEquipment(phenny, parameters, '0:0:0:0:1'))
+ intItemsAdded += 1
+
+ #Unlock boss items
+ if enemyStats['Unlock'] is not 'Default' and enemyStats['Class'] is 'Boss':
+ c.execute("SELECT COUNT(`Requirement`) AS `Requirement` FROM `Items_PlayerPool` INNER JOIN `Items_Master` ON `Items_PlayerPool`.`EquipmentName` = `Items_Master`.`EquipmentName` WHERE `Nick`=%s and `Requirement`=%s",(parameters['Nick'], enemyStats['Unlock']))
+ sqlUnlockCheck = c.fetchone()
+ if str(sqlUnlockCheck['Requirement']) == '0':
+ UnlockItems(phenny, parameters, str(enemyStats['Unlock']))
+ return "Additional items will now begin appearing"
+
+ playerStats = PlayerStats.RefreshStats(phenny, parameters)
+ if playerStats['ChallengeRating'] == int(math.ceil(playerStats['ChallengeRating'] / 1) * 1):
+ c.execute("UPDATE `Players` SET `AttributePoints`=2 WHERE `Nick`=%s;", (parameters["Nick"]));db.commit();
+ strAttackLog = strAttackLog + "You have gained 2 attribute points"
+ else:
+ # Enemys attack
+ strAttackLog = strAttackLog + PerformAttack(phenny, enemyStats, playerStats, parameters)
+
+ if playerStats['HP'] <= 0:
+ strAttackLog = strAttackLog + "You died. "
+ PlayerDeath.CharacterDeath(phenny, playerStats, parameters)
+
+ return "\0399" + strAttackLog
+
+ # flee
+ elif strCmd1.lower() == 'f' or strCmd1.lower() == 'flee':
+ if random.randint(1, 3) == 1:
+ return FleeCombat(phenny, parameters)
+ else:
+ return "You failed to escape. " + PerformAttack(phenny, enemyStats, playerStats, parameters)
+ if playerStats['HP'] <= 0:
+ PlayerDeath.CharacterDeath(phenny, playerStats, parameters)
+ return "You were struck down as you attempted to flee. You died."
+
+ # Admin commands
+ elif strCmd1.lower() == 'admin' and input.admin:
+ return PerformAttack(phenny, playerStats, enemyStats, parameters["Nick"])
+ else:
+ return "\0399Available commands: (a)ttack, (f)lee"
+
+
+def PerformAttack(phenny, attackerStats, defenderStats, 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)
+
+ # determine if attacker hits
+ if random.randint(0, 100) < int(defenderStats['DodgePercentage']):
+ db.close()
+ if attackerStats['UnitType'] == 'Player':
+ return "You miss. "
+ elif attackerStats['UnitType'] == 'Enemy':
+ return "You dodge the \03" + str(attackerStats['EnemyColor']) + attackerStats['EnemyName'] + "\0399's attack. "
+
+ if random.randint(0,100) < int(defenderStats['BlockPercentage']):
+ db.close()
+ if attackerStats['UnitType'] == 'Player':
+ return "The enemy blocks your attack. "
+ elif attackerStats['UnitType'] == 'Enemy':
+ return "You block the \03" + str(attackerStats['EnemyColor']) + attackerStats['EnemyName'] + "\0399's attack. "
+
+ #Calculate total damage caused
+ intAttackerDamage = int(float(attackerStats['Strength']) + random.uniform(float(attackerStats['Strength']) * -0.2,float(attackerStats['Strength']) * 0.2))
+
+ #Apply Armor reduction
+ intAttackerDamage = int(math.ceil(intAttackerDamage - (intAttackerDamage * defenderStats['ArmorPercentage'] / 100.0)))
+
+ # Determine if the attacker is going to crit
+ strCrit = 'did'
+ if random.randint(0, 100) < attackerStats['CritPercentage']:
+ intAttackerDamage = intAttackerDamage * 2
+ strCrit = 'CRIT'
+
+ # Update defender health
+ defenderStats['HP'] = defenderStats['HP'] - intAttackerDamage
+ if defenderStats['UnitType'] == 'Enemy':
+ c.execute("UPDATE `CombatEnemy` SET `HP`=%s WHERE `Nick`=%s;", (defenderStats['HP'], parameters['Nick']));db.commit();
+ elif defenderStats['UnitType'] == 'Player':
+ c.execute("UPDATE `Players` SET `HP`=%s WHERE `Nick`=%s;", (defenderStats['HP'], parameters['Nick']));db.commit();
+
+ db.close()
+
+ if attackerStats['UnitType'] == 'Player':
+ return "You " + strCrit + " " + str(intAttackerDamage) + " damage. "
+ elif attackerStats['UnitType'] == 'Enemy':
+ return "The \03" + str(attackerStats['EnemyColor']) + attackerStats[
+ 'EnemyName'] + "\0399 " + strCrit + " " + str(intAttackerDamage) + " damage. "
\ No newline at end of file |