Skip to content

Commit 05da8f5

Browse files
committed
Added support for new tournament fields
1 parent 1913748 commit 05da8f5

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ Changelog
66
Due to this library relying on external content, older versions are not guaranteed to work.
77
Try to always use the latest version.
88

9+
.. v3.2.0:
10+
11+
3.2.0 (2020-08-10)
12+
==================
13+
14+
- Added support for the new rules and score set added for the most recent Tournament.
15+
- Added ``ScoreSet.creature_kills``
16+
- Added ``ScoreSet.area_discovery``
17+
- Added ``ScoreSet.skill_gain_loss``
18+
- Added ``RuleSet.shared_xp_bonus``
19+
920
.. v3.1.0:
1021
1122
3.1.0 (2020-07-29)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ No fetching is done by this module, you must provide the html content.
1515
- Type consistent attributes.
1616
- All objects can be converted to JSON strings.
1717
- Can be used with any networking library.
18-
- Support for characters, guilds, houses and worlds.
18+
- Support for characters, guilds, houses and worlds, tournaments, forums, etc.
1919

2020
## Installing
2121
Install and update using pip

tibiapy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from tibiapy.world import *
1717
from tibiapy.client import *
1818

19-
__version__ = '3.1.0'
19+
__version__ = '3.2.0'
2020

2121
from logging import NullHandler
2222

tibiapy/tournament.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ class RuleSet(abc.Serializable):
197197
The percentage of rent prices relative to the regular price.
198198
house_auction_durations: :class:`int`
199199
The duration of house auctions.
200+
shared_xp_bonus: :class:`bool`
201+
Whether there is a bonus for sharing experience or not.
200202
"""
201203

202204
__slots__ = (
@@ -211,6 +213,7 @@ class RuleSet(abc.Serializable):
211213
"loot_probability",
212214
"rent_percentage",
213215
"house_auction_durations",
216+
"shared_xp_bonus",
214217
)
215218

216219
def __init__(self, **kwargs):
@@ -225,6 +228,7 @@ def __init__(self, **kwargs):
225228
self.loot_probability = kwargs.get("loot_probability")
226229
self.rent_percentage = kwargs.get("rent_percentage")
227230
self.house_auction_durations = kwargs.get("house_auction_durations")
231+
self.shared_xp_bonus = kwargs.get("shared_xp_bonus")
228232

229233
def __repr__(self):
230234
attributes = ""
@@ -253,24 +257,36 @@ class ScoreSet(abc.Serializable):
253257
254258
Attributes
255259
----------
260+
creature_kills: :class:`dict`
261+
Points received for participating in creature kills.
256262
level_gain_loss: :class:`int`
257263
The points gained for leveling up or lost for losing a level.
264+
skill_gain_loss: :class:`int`
265+
The points gained for leveling up or lost for losing a skill level.
258266
charm_point_multiplier: :class:`int`
259267
The multiplier for every charm point.
260268
character_death: :class:`int`
261269
The points lost for dying.
270+
area_discovery: :class:`int`
271+
Points that will be added to the score for discovering an area entirely.
262272
"""
263273

264274
__slots__ = (
275+
"creature_kills",
265276
"level_gain_loss",
277+
"skill_gain_loss",
266278
"charm_point_multiplier",
267279
"character_death",
280+
"area_discovery",
268281
)
269282

270283
def __init__(self, **kwargs):
284+
self.creature_kills = kwargs.get("creature_kills", {})
271285
self.level_gain_loss = kwargs.get("level_gain_loss", 0)
286+
self.skill_gain_loss = kwargs.get("skill_gain_loss", 0)
272287
self.charm_point_multiplier = kwargs.get("charm_point_multiplier", 0)
273288
self.character_death = kwargs.get("character_death", 0)
289+
self.area_discovery = kwargs.get("area_discovery", 0)
274290

275291
def __repr__(self):
276292
attributes = ""
@@ -453,7 +469,7 @@ def _parse_tournament_rules(self, table):
453469
The table containing the tournament rule set.
454470
"""
455471
rows = table.find_all('tr')
456-
bool_fields = ("playtime_reduced_only_in_combat",)
472+
bool_fields = ("playtime_reduced_only_in_combat", "shared_xp_bonus")
457473
float_fields = (
458474
"death_penalty_modifier",
459475
"xp_multiplier",
@@ -486,15 +502,22 @@ def _parse_tournament_scores(self, table):
486502
table: :class:`bs4.BeautifulSoup`
487503
The parsed table containing the tournament score set.
488504
"""
505+
creatures = {}
489506
rows = table.find_all('tr')
490507
rules = {}
491508
for row in rows[1:]:
492509
cols_raw = row.find_all('td')
493510
cols = [ele.text.strip() for ele in cols_raw]
494511
field, value, *_ = cols
512+
icon = cols_raw[2].find("span")
495513
field = field.replace("\xa0", "_").replace(" ", "_").replace(":", "").replace("/", "_").lower()
496514
value = re.sub(r'[^-0-9]', '', value.replace("+/-", ""))
497-
rules[field] = parse_integer(value)
515+
if not icon:
516+
creatures[field.replace("_", " ")] = int(value)
517+
else:
518+
rules[field] = parse_integer(value)
519+
if "creature_kills" in rules:
520+
rules["creature_kills"] = creatures
498521
self.score_set = ScoreSet(**rules)
499522

500523
def _parse_tournament_rewards(self, table):
@@ -583,7 +606,7 @@ def _parse_archive_list(self, archive_table):
583606
584607
Parameters
585608
----------
586-
archive_table: :class:`bs4.BeautifulSoup`
609+
archive_table: :class:`bs4.Tag`
587610
The parsed element containing the table.
588611
"""
589612
_, *options = archive_table.find_all("option")

0 commit comments

Comments
 (0)