GithubHelp home page GithubHelp logo

aescarcha / king-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from breuerfelix/king-bot

0.0 2.0 0.0 118 KB

Travian Kingdoms Bot (www.kingdoms.com)

Home Page: https://scriptworld.net/projects/king-bot/

License: MIT License

Python 100.00%

king-bot's Introduction

king-bot

check out the insights of this project: scriptworld.net

feel free to join the official discord channel or contact me! (:

you want to run the bot 24/7, but don't want to use your computer? contact me aswell! (:

youtube video: how to setup the bot. click here !

Build Status MIT license built with Selenium built with Python3

table of contents

getting-started

watch the youtube video if you got problems setting up the bot. click here !

  1. install python3 for your system
    1. get python
  2. clone this repository
  3. install packages
    1. open console
    2. goto this repository
    3. run pip install . or pip install -r requirements.txt
  4. download chromedriver for your system
    1. get chromederiver
    2. move to assets/ folder
  5. edit start.py
    1. insert your credentials (optional)
      1. login without inserting -> see chapter start options
    2. place the actions your bot should do at the end
      1. read documentation for this
      2. read sample_start.py to get an impression
  6. execute script
    1. python start.py
    2. read documentation for options like remote browser or headless browsing
  7. on mac or linux
    1. use python3 and pip3 instead

features

just an overview with method signatures. for details check each chapter.

def start_adventures(interval: int = 100) -> None:
def start_farming(village: int, farmlists: list, interval: int) -> None:
def start_custom_farmlist(reload: bool = False) -> None:
def sort_danger_farms(farmlists: list, to_list: int, red: bool, yellow: bool, interval: int) -> None:
def dodge_attack(village: int, interval: int = 600, units: list = [], target: list = []) -> None:
def upgrade_units_smithy(village: int, units: list, interval: int = 1000) -> None:

farming (travian plus)

the bot will open given village, selects all farmlists from the array, sends them, and go to sleep.
this is by far the simplest implementation of a farm bot.

# sends farmlist with index 1 (the one after the starter list)
# in your first village (index 0) in an interval of 60 seconds
kingbot.start_farming(village=0, farmlists=[1], interval=60)

#sends farmlist 1 and 3 in your second village in an interval of 30 seconds
kingbot.start_farming(1, [1,3], 30)

village:
index of village (0 is the first village)

farmlists:
index of farmlist (0 is the starter list with only 10 farms)
must be an array! you can send multiple lists in this interval

interval:
interval of sending the list in seconds

you can stack as many of them together if you want.
it's also possible to send different farmlist in the same village in different intervals.

sorting out yellow / red farms

note that this feature is not fully tested yet!
i need someone with alot of big farmlists to test this feature for me

this line will let the bot automaticly sort out red or/and yellow farms for you.
it is checking all given farmlists in an interval (in seconds) for danger farms.
if a farm is yellow or red, and you set the equivalent value to True, this farm will be placed onto the farmlist with the index given by the paramter to_list.
the starter farmlist is index 0.

kingbot.sort_danger_farms(farmlists=[0], to_list=1, red=True, yellow=False, interval=240)

farmlists:
array of farmlist indexes (start farmlist is 0)

to_list:
index of the farmlist the 'danger' farms will be put into

red:
True if you want red farms to be sorted out

yellow:
True if you want also yellow farms to be sorted out

interval:
interval of checking the farmlists in seconds

farmlists as .txt file (no travian plus needed)

this technique is a little bit slower than then one with travian plus.
the bot will manually launch every attack at the rally point.
i only implemented this feature for people who doesn't want to pay for the game and still want to farm only around 200 villages.

you have to create a file named farmlist.txt in assets/ folder, which looks like the following: (attention for separators!)

-26;-34;120;0;1,2
-28;-24;70;0;1,2,3,4
-30;-57;300;0;1,2

pattern: x-coordinate ; y-coordinate ; time to wait till sending the troops again in seconds ; index of village ; index of unit in the horizontal bar , amount of units

every line represents one farm. the first 2 values are the x- and y-coordinates.
the third value is the time (in seconds) the bot waits until it sends the farm again.
fourth value is the village from where the troops are going to be send off.
the last values (comma separated!) are the amount and index of the unit which is going to be send.
you can find out the index when trying to launch a new attack. you will be asked which village you want to attack and which troops you wanna use.
from left to right, starting at 0, these are the indexes of the units you want to use.
for example (gauls): 0 = phalanx, 1 = swordsman.
if you want to send different units, just stack them at the end.
...0,1,3,4 -> this would send 1 of unit 0 and 4 of unit 3 to this farm.

attention:
adding a unit index of -1 will send all units with max number to this farm.
adding a unit value of -1 will send all units of this type to this farm.

add the following line to your start.py script:

kingbot.start_custom_farmlist(reload=False)

reload:
if you set this value to True the bot will rescan your farmlist file every minute for changing lines
you can add or remove farms without restarting the script

adventures

this enables auto sending the hero on adventures.
be careful if the hero in low on health! there is no stopping mechanism for now.

kingbot.start_adventures(interval=500)

interval: (optional -> default = 100)
time in seconds the hero thread will sleep until it checks for a new adventure again

dodge incoming attacks

since everybody hates to get attacked at night, the bot is able do dodge incoming attacks.
it will send your units to a given village for raid. make sure the village is inactive and valid.

the bot will wake up 10 minutes before the attack lands, so take a target which is at least 5:01 minutes away. (7:00 if you got a map and also send your hero)
use this method for every village you want to save.

kingbot.dodge_attack(village=0, units=[1, 0, 3], target=[1, 1])

village:
index of village which the bot is going to check (starting at 0)

units:
array of unit indexes which are going to be saved (starting at 0)
insert -1 (units=[-1]) to save all available units in this village

target:
first index is the x-coordinate and second for the y-coordinate of the village the bot will send the units for a robbery

upgrade units in smithy

kingbot.upgrade_units_smithy(village=0, units=[21, 22])

village:
index of village (starting at 0)

units:
list of units you want to upgrade
first one with highest priority, last one with lowest

roman teuton gaul
1: legionnaire 11: clubswinger 21: phalanx
2: praetorian 12: spearfighter 22: swordsman
3: imperian 13: axefighter 23: pathfinder
4: equites legati 14: scout 24: theutates thunder
5: equites imperatoris 15: paladin 25: druidrider
6: equites caesaris 16: teutonic knight 26: headuan
7: battering ram 17: ram 27: ram
8: fire catapult 18: catapult 28: trebuchet
9: senator 19: chief 29: chieftain
10: settler 20: settler 30: settler

the bot checks if it can upgrade given units in given order. first it checks swordsman in this example and if they are not available or maxed out, it will try to upgrade phalax again.
you can increase the list as long as you want to.

the bot can't switch smithy pages for now, so make sure the window is big enough to cover 8 slots.
By default this should be the case, otherwise it will just cover the 4 slots on the front for now.

sleeping time will be the time the academy needs to finish the current research, so the bot won't wake up unnecessarily in the given interval.

upgrade resource fields / buildings

note: this feature is disabled right now, it needs improvement!

this function will upgrade a resource field or building in any village.

on the picture below you can see all field slot id's.
these stay the same no matter what kind of village you have (even in 15er crop villages).

kingbot.upgrade_slot(village=0, slot=5)

village:
index of the village the slot should be upgraded in (starting at 0)

slot:
see the picture below to get the right slot for your field

resource-fields

start options

just an overview. for details check each topic.

short long arguments description
-e --email your_email optional for login
-p --password your_password optional for login
-w --gameworld your_gameworld optional for login
-m - - login manually
-h - - no browser window
-r - - connect to last session

provide credentials

$ python start.py -e [email protected] -p your_password -w your_gameworld
$ python start.py --email [email protected] --password your_password --gameworld your_gameworld

if you don't want to store your credentials into a file, just provide them via arguments like this.
it's also possible to login manually if you dont want to provide your login credentials at all. see below: login manually

all of these options are optional, you can always provice some via code, and some via start options, that's up to you.

headless browsing

$ python start.py -h

if you don't wont a browser window to pop up, or using the script on a dedicated server with no gui, it is possible to run the script in headless mode.
the console window will inform you about important actions the bot will do.

login manually

$ python start.py -m

if you don't trust my program, even if it' open source, you can login manually and don't even type your email or password anywhere in my script.
the bot will open the main page of travian kingdoms.
it will now wait 120 seconds for you to log into your account.
after you are logged in, just open the gameworld you want your bot to run in.
if you are finished, just wait for the timer to end, so the bot can do its work.

note: this is not possible in headless mode!

remote browser

$ python start.py -r

if the script exists because of an exception, it's possible to re-use the browser session so you don't have to go through the whole login process again.
just don't exit the browser window and make sure to remove the functions in the script, which the bot already completed in last session.

note: debug mode must be enabled!

proxy

proxy = '127.0.0.1:1234'

if you want to surf the web via proxy, just insert it in start.py. this is also possible in headless mode.
if the proxy is set to '', it's going to be disabled. it's also disabled by default.

faq

can i play the game while the bot is running?
yes. just open a new browser window and leave the bot window in the background. login to your gameworld and keep playing.
one instance doesn't effect another browser instance. you can also start your script without a browser window.

can i get banned for using the bot?
yes, but the chances are below 1%. it's nearly impossible to detect this bot, because it clicks all buttons just like a human would do.
also there is browser and sleeping time delay, so they can't event check if the interval is always the same.

my internet is really slow. the bot is too fast and can't find elements!
settings.browser_speed = 1.0 -> just increase this value. it will adjust all sleep timers.
you will find that value in start.py file.

how to contribute

you are not quite sure if you are able to contribute ? contact me (: !
i love to teach people who are interested in learning.

code style

  • type definitions at least for method signatures
  • do comments
  • keep your code seperated in files

workflow

  • take an issue or a personal idea to implement
  • fork the repository
  • start scripting
  • make a pull request

nice to know

  • store your login credentials in ./assets/credentials.txt -> ignored by git
    • gameworld;your_email;your_password
  • write your testscript as test_start.py -> ignored by git
  • run mypy for typechecking mypy start.py --ignore-missing-imports
  • set debug flag to True -> kingbot = kingbot(..., debug=True)
    • if your script executes with and error resume your session with python start.py -r

contact

discord: scriptworld#9641
email: [email protected]


i love lowercase

king-bot's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.