Revision: 19
http://pykol.svn.sourceforge.net/pykol/?rev=19&view=rev
Author: misza13
Date: 2007-05-04 14:58:24 -0700 (Fri, 04 May 2007)
Log Message:
-----------
Added elementary routines for automatic adventuring (start an adventure and attack with weapon until fight is won).
Added Paths:
-----------
adventure.py
Added: adventure.py
===================================================================
--- adventure.py (rev 0)
+++ adventure.py 2007-05-04 21:58:24 UTC (rev 19)
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+#
+# (C) Misza <mi...@mi...>, 2007
+#
+# Distributed under the terms of the MIT license.
+#
+
+import re
+
+class AutoAdventurer:
+ def __init__(self, site):
+ self.site = site
+
+ def adventure(self, snarfblat):
+ print 'Starting adventure...'
+ response, data = self.site.getPage('adventure.php?snarfblat='+snarfblat)
+
+ if response.getheader('location')=='fight.php':
+ self.fighting = True
+ while self.fighting:
+ self.fight()
+
+ def fight(self):
+ response, data = self.site.getPage('fight.php')
+ print data
+
+ monRX = re.search(r"You're fighting <span id='monname'>(?P<monname>.*?)</span>",data)
+ print "You're fighting %s" % monRX.group('monname')
+
+ tackRX = re.search(r"<input id='tack' class=button type=submit value=\"Attack with your (?P<tackitem>.*?)\">",data)
+
+ formdata = {
+ 'action' : 'attack',
+ 'tack' : 'Attack with your ' + tackRX.group('tackitem'),
+ }
+ response, data = self.site.postForm('fight.php',formdata)
+
+ if "You win the fight!" in data:
+ print "You win the fight!"
+ self.fighting = False
+ else:
+ self.fighting = True
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|