Constructor Summary | Method Summary | Constructor Detail | Method Detail | Testing | Script Source

ReportReader.js
Class ReportReader



function ReportReader

description: contains functions for reading an english Tribal Wars battle report

run on: game.php?screen=report&mode=all&view=

Constructor Summary
ReportReader(HTMLDocument gameDocument)
Returns a ReportReader that reads from the specified HTMLDocument object

Method Summary
ArraygetAttacker()
Returns an array of information about the attacking player: (id,name)
ArraygetAttackerLosses()
Returns the troops that the attacker lost, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
ArraygetAttackerQuantity()
Returns the troops that the attacker sent, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
ArraygetAttackerVillage()
Returns an array of information about the attacker's village: (x,y,id)
ArraygetBuildingLevels()
Returns an array of the building levels
ArraygetDefender()
Returns an array of information about the defending player: (id,name). id = 0 for barbarians, id = -1 for deleted player
ArraygetDefenderLosses
Returns the troops that the defender lost, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
ArraygetDefenderQuantity
Returns the defending troops, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
ArraygetDefenderVillage()
Returns an array of information about the defender's village: (x,y,id)
StringgetDotColor()
Returns the color of the dot, signifying the result of the battle
ArraygetEspionageLevel()
Returns a number representing the amount of information available
ArraygetHaul()
Returns the pillaged resources, in an array: (timber,clay,iron)
NumbergetLuck()
Returns the attacker's luck in the battle
ArraygetLoyalty()
Returns the loyalty of the defender's village, in an array: (from,to)
NumbergetMorale()
Returns the attacker's morale
NumbergetReportId()
Returns the report ID that's used as a key
ArraygetResources()
Returns the resources scouted, in an array: (timber,clay,iron)
DategetSent()
Returns the date and time the report was received
ArraygetSupportKilled()
Returns information about "Defender's troops in other villages", in an array of Reinforcements
ArraygetUnitsInTransit()
Returns information about the defender's troops in transit, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
ArraygetUnitsOutside()
Returns the defender's troops outside the village, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)

Constructor Summary

ReportReader(HTMLDocument gameDocument)

Returns a ReportReader that reads from the specified HTMLDocument object
Parameters:

gameDocument:HTMLDocument - HTMLDocument object that the report will be read from. If the user doesn't have a premium account, game.php will be embedded within a frame. The following code can be used to retrieve the game document for both premium and non-premium users:
var gameDocument = (window.frames.length>0)?window.main.document:document;

initializing a report reader will then look like this:
myReportReader = new ReportReader(gameDocument);



Method Summary

getAttacker()

Returns an array of information about the attacking player: (id,name)
Returns:

player:Array(id:Number,name:String)


getAttackerLosses()

Returns the troops that the attacker lost, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
Returns:

troops:Array(spear:Number,sword:Number,archer:Number,axe:Number,scout:Number,lcav:Number,acav:Number,hcav:Number,ram:Number,cat:Number,paladin:Number,noble:Number)


getAttackerQuantity()

Returns the troops that the attacker sent, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
Returns:

troops:Array(spear:Number,sword:Number,archer:Number,axe:Number,scout:Number,lcav:Number,acav:Number,hcav:Number,ram:Number,cat:Number,paladin:Number,noble:Number)


getAttackerVillage()

Returns an array of information about the attacker's village: (x,y,id)
Returns:

village:Array(x:Number,y:Number,id:Number), where x and y are the coordinates that are usually seen as (x|y)


getBuildingLevels()

Returns an array of the building levels
Returns:

buildingLevels:Array(hq:Number,barracks:Number,stable:Number...) -an array of the building levels scouted
BuildingIndex
hq0
barracks1
stable2
workshop3
church4
church_f5
academy6
smithy7
rally point8
statue9
market10
timber camp11
clay pit12
iron mine13
farm14
warehouse15
hiding place16
wall17


getDefender()

Returns an array of information about the defending player: (id,name)
Returns:

player:Array(id:Number,name:String)


getDefenderLosses()

Returns the troops that the defender lost, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
Returns:

troops:Array(spear:Number,sword:Number,archer:Number,axe:Number,scout:Number,lcav:Number,acav:Number,hcav:Number,ram:Number,cat:Number,paladin:Number,noble:Number)


getDefenderQuantity()

Returns the troops the defending troops, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
Returns:

troops:Array(spear:Number,sword:Number,archer:Number,axe:Number,scout:Number,lcav:Number,acav:Number,hcav:Number,ram:Number,cat:Number,paladin:Number,noble:Number)


getDefenderVillage()

Returns an array of information about the defender's village: (x,y,id)
Returns:

village:Array(x:Number,y:Number,id:Number), where x and y are the coordinates that are usually seen as (x|y)


getDotColor()

Returns the color of the dot, signifying the result of the battle
Returns:

color:String
ColorSignificance
blueonly attacking scouts survived
greenall attacking units survived
redno attacking units survived
yellowsome attacking units survived, but not all


getEspionageLevel()

Returns a number representing the amount of information available
Returns:

espionageLevel:Number
ValueSignificance
0nothing scouted
1resources
2buildings
3external troops


getHaul()

Returns the pillaged resources, in an array: (timber,clay,iron)
Returns:

resources:Array(timber:Number,clay:Number,iron:Number)


getLuck()

Returns the attacker's luck in the battle
Returns:

luck:Number


getLoyalty()

Returns the loyalty of the defender's village, in an array: (from,to)
Returns:

loyalty:Array(from:Number,to:Number) -from is the loyalty before the battle, and to is the loyalty after the battle.


getMorale()

Returns the attacker's morale
Returns:

morale:Number


getReportId()

Returns the report ID that's used as a key
Returns:

reportID:Number


getResources()

Returns the resources scouted, in an array: (timber,clay,iron)
Returns:

resources:Array(timber:Number,clay:Number,iron:Number)


getSent()

Returns the date and time the report was received
Returns:

sent:Date - formatted as a Date object for use with calculations


getSupportKilled()

Returns information about "Defender's troops in other villages", in an array of Reinforcements
Returns:

reinforcements:Array(reinforcement0:Reinforcements, reinforcement1:Reinforcements, reinforcement2:Reinforcements...)


getUnitsInTransit()

Returns information about the defender's troops in transit, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
Returns:

troops:Array(spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)


getUnitsOutside()

Returns the defender's troops outside the village, in an array: (spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)
Returns:

troops:Array(spear,sword,archer,axe,scout,lcav,acav,hcav,ram,cat,paladin,noble)



Testing

The function testReportReader() can be called to open a debug window with the information that was read from the report.

Script Source

ReportReader.js