Skip to content

Commit

Permalink
Release 1.7.0 (#33)
Browse files Browse the repository at this point in the history
* Add deathAttack, fansite and notes3 to Item.
* Update dependencies
* Support Loot Statistics.
  • Loading branch information
benjaminkomen authored Dec 25, 2019
1 parent 8c16710 commit 214adfd
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=http://mirror.novg.net/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.zip
distributionUrl=http://ftp.tudelft.nl/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The following resources are available:
| Items | [items](https://tibiawiki.dev/api/items) | [Carlin Sword](https://tibiawiki.dev/api/items/Carlin_Sword) |
| Keys | [keys](https://tibiawiki.dev/api/keys) | [Key 4055](https://tibiawiki.dev/api/keys/Key_4055) |
| Locations | [locations](https://tibiawiki.dev/api/locations) | [Thais](https://tibiawiki.dev/api/locations/Thais) |
| Loot Statistics | [loot statistics](https://tibiawiki.dev/api/lootstatistics) | [Ferumbras](https://tibiawiki.dev/api/lootstatistics/Ferumbras) |
| Loot Statistics | [loot](https://tibiawiki.dev/api/loot) | [Ferumbras](https://tibiawiki.dev/api/loot/Ferumbras) |
| Missiles | [missiles](https://tibiawiki.dev/api/missiles) | [Throwing Cake Missile](https://tibiawiki.dev/api/missiles/Throwing_Cake_Missile) |
| Mounts | [mounts](https://tibiawiki.dev/api/mounts) | [Donkey](https://tibiawiki.dev/api/mounts/Donkey) |
| NPCs | [npcs](https://tibiawiki.dev/api/npcs) | [Sam](https://tibiawiki.dev/api/npcs/Sam) |
Expand Down
23 changes: 11 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

<groupId>com.tibiawiki</groupId>
<artifactId>TibiaWikiApi</artifactId>
<version>1.6.3</version>
<version>1.7.0</version>
<packaging>jar</packaging>
<name>TibiaWikiApi</name>
<url>https://github.com/benjaminkomen/TibiaWikiApi</url> <!-- https://tibiawiki.dev -->

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -21,24 +21,23 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<slf4j.version>1.7.28</slf4j.version>
<logback.version>1.2.3</logback.version>
<logstash.version>6.2</logstash.version>
<json.version>20180813</json.version>
<lombok.version>1.18.8</lombok.version>
<jetbrains.version>17.0.0</jetbrains.version>
<streamex.version>0.6.8</streamex.version>
<junit.jupiter.version>5.4.2</junit.jupiter.version>
<mockito.version>2.27.0</mockito.version>
<logstash.version>6.3</logstash.version>
<json.version>20190722</json.version>
<lombok.version>1.18.10</lombok.version>
<jetbrains.version>18.0.0</jetbrains.version>
<streamex.version>0.7.2</streamex.version>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<mockito.version>3.2.4</mockito.version>
<hamcrest.version>2.2</hamcrest.version>
<maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>2.22.2</maven.failsafe.plugin.version>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<build.helper.maven.plugin.version>3.0.0</build.helper.maven.plugin.version>
<jwiki.version>2.0.1</jwiki.version>
<guava.version>27.1-jre</guava.version>
<ow2.asm.version>7.1</ow2.asm.version>
<guava.version>28.1-jre</guava.version>
<swagger.jersey2.jaxrs.version>1.5.21</swagger.jersey2.jaxrs.version>
<javax.activation.version>1.1.1</javax.activation.version>
<vavr.version>0.10.0</vavr.version>
<vavr.version>0.10.2</vavr.version>
</properties>

<repositories>
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/com/tibiawiki/domain/factories/ArticleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ArticleFactory {

private static final Logger log = LoggerFactory.getLogger(ArticleFactory.class);
private static final String INFOBOX_HEADER = "{{Infobox";
private static final String LOOT2_HEADER = "{{Loot2";

public String extractInfoboxPartOfArticle(String articleContent) {
return extractInfoboxPartOfArticle(Map.entry("Unknown", articleContent));
Expand All @@ -40,9 +41,32 @@ public String extractInfoboxPartOfArticle(Map.Entry<String, String> pageNameAndA
return TemplateUtils.getBetweenOuterBalancedBrackets(articleContent, INFOBOX_HEADER);
}

public String extractLootPartOfArticle(String articleContent) {
return extractLootPartOfArticle(Map.entry("Unknown", articleContent));
}

/**
* Given a certain Article, extract the part from it which is the first loot statistics template, or an empty String if it does not contain
* an Loot2 template (which is perfectly valid in some cases).
*/
public String extractLootPartOfArticle(Map.Entry<String, String> pageNameAndArticleContent) {
final String pageName = pageNameAndArticleContent.getKey();
final String articleContent = pageNameAndArticleContent.getValue();

if (!articleContent.contains(LOOT2_HEADER)) {
if (log.isWarnEnabled()) {
log.warn("Cannot extract loot statistics template from article '{}'," +
" since it contains no Loot2 template.", pageName);
}
return "";
}

return TemplateUtils.getBetweenOuterBalancedBrackets(articleContent, LOOT2_HEADER);
}

/**
* @param originalArticleContent the original article content with the old infobox content
* @param newContent the new infobox content
* @param newContent the new infobox content
* @return the full article content with the old infobox content replaced by the new infobox content
*/
public String insertInfoboxPartOfArticle(String originalArticleContent, String newContent) {
Expand Down
83 changes: 80 additions & 3 deletions src/main/java/com/tibiawiki/domain/factories/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -43,9 +44,10 @@ public class JsonFactory {
private static final String ITEM_ID = "itemid";
private static final String EFFECT_ID = "effectid";
private static final String LOWER_LEVELS = "lowerlevels";
private static final List ITEMS_WITH_NO_DROPPEDBY_LIST = Arrays.asList("Gold Coin", "Platinum Coin");
private static final List<String> ITEMS_WITH_NO_DROPPEDBY_LIST = Arrays.asList("Gold Coin", "Platinum Coin");
private static final String INFOBOX_HEADER_PATTERN = "\\{\\{Infobox[\\s|_](.*?)[\\||\\n]";
private static final String RARITY_PATTERN = "(always|common|uncommon|semi-rare|rare|very rare|extremely rare)(|\\?)";
private static final String LOOT_LINE_NAME_PATTERN = "(\\w+:\\d+)";
private static final String UNKNOWN = "Unknown";
private static final String RARITY = "rarity";
private static final String AMOUNT = "amount";
Expand Down Expand Up @@ -76,11 +78,27 @@ public JSONObject convertInfoboxPartOfArticleToJson(@Nullable final String infob
}
}

parametersAndValues.putAll(TemplateUtils.splitByParameter(infoboxTemplatePartOfArticleSanitized));
parametersAndValues.putAll(TemplateUtils.splitInfoboxByParameter(infoboxTemplatePartOfArticleSanitized));
parametersAndValues.put(TEMPLATE_TYPE, templateType);
return enhanceJsonObject(new JSONObject(parametersAndValues));
}

/**
* Convert a String which consists of key-value pairs of loot2 template parameters to a JSON object, or an empty
* JSON object if the input was empty.
*/
@NotNull
public JSONObject convertLootPartOfArticleToJson(@Nullable final String lootPartOfArticle) {
if (lootPartOfArticle == null || "".equals(lootPartOfArticle)) {
return new JSONObject();
}

String lootTemplatePartOfArticleSanitized = TemplateUtils.removeFirstAndLastLine(lootPartOfArticle);

Map<String, String> parametersAndValues = new HashMap<>(TemplateUtils.splitLootByParameter(lootTemplatePartOfArticleSanitized));
return enhanceLootJsonObject(new JSONObject(parametersAndValues));
}

@NotNull
public String convertJsonToInfoboxPartOfArticle(@Nullable JSONObject jsonObject, List<String> fieldOrder) {
if (jsonObject == null || jsonObject.isEmpty()) {
Expand Down Expand Up @@ -222,6 +240,65 @@ protected JSONObject enhanceJsonObject(@NotNull JSONObject jsonObject) {
return jsonObject;
}

/**
* The input jsonObject has real key-value pairs such as version, kills and name, but also Loot lines which need to be
* converted.
*/
@NotNull
protected JSONObject enhanceLootJsonObject(@NotNull JSONObject jsonObject) {

JSONObject enhancedJsonObject = new JSONObject();
JSONArray lootArray = new JSONArray();

final Iterator<String> keyIterator = jsonObject.keys();

// iterate over json object entries
while (keyIterator.hasNext()) {
String key = keyIterator.next();
Object value = jsonObject.get(key);

if (value instanceof String) {
String stringValue = (String) value;

// do not modify normal keys such as version, kills and name. We assume they are always lowercase
if (Character.isLowerCase(key.codePointAt(0))) {
enhancedJsonObject.put(key, stringValue);
} else {
lootArray.put(makeLootEntry(key, stringValue));
}
}
}

if (lootArray.length() > 0) {
enhancedJsonObject.put("loot", lootArray);
}

return enhancedJsonObject;
}

/**
* We get a stringValue here which can be one of the following values:
* - "times:25"
* - "times:25, amount:1, total:25"
*/
private JSONObject makeLootEntry(String key, String stringValue) {
JSONObject lootEntry = new JSONObject();

lootEntry.put("itemName", key);

Pattern pattern = Pattern.compile(LOOT_LINE_NAME_PATTERN);
Matcher matcher = pattern.matcher(stringValue);
while (matcher.find()) {
if (matcher.groupCount() > 0 && matcher.group(1) != null) {
String timesAmountOrTotal = matcher.group(1);
String[] splitToLabelAndNumber = timesAmountOrTotal.split(":");
lootEntry.put(splitToLabelAndNumber[0], splitToLabelAndNumber[1]);
}
}

return lootEntry;
}

/**
* Usually the articleName is the value from the key 'name', but for books, locations or keys it is different.
*/
Expand Down Expand Up @@ -345,7 +422,7 @@ private JSONArray makeLowerLevelsArray(String lowerLevelsValue) {
}

final List<JSONObject> infoboxHuntSkillJsonObjects = infoboxHuntSkillsList.stream()
.map(s -> new JSONObject(new HashMap<>(TemplateUtils.splitByParameter(s))))
.map(s -> new JSONObject(new HashMap<>(TemplateUtils.splitInfoboxByParameter(s))))
.collect(Collectors.toList());

return new JSONArray(infoboxHuntSkillJsonObjects);
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/com/tibiawiki/domain/objects/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Item extends WikiObject {
private final Integer earthAttack;
private final Integer iceAttack;
private final Integer energyAttack;
private final Integer deathAttack;
private final Integer defense;
private final String defensemod;
private final Integer imbueslots;
Expand Down Expand Up @@ -93,6 +94,8 @@ public class Item extends WikiObject {
private final String npcpricerook;
private final String buyfrom;
private final String sellto;
private final String notes2;
private final String fansite;

private Item() {
this.itemid = null;
Expand All @@ -117,6 +120,7 @@ private Item() {
this.earthAttack = null;
this.iceAttack = null;
this.energyAttack = null;
this.deathAttack = null;
this.defense = null;
this.defensemod = null;
this.imbueslots = null;
Expand Down Expand Up @@ -167,17 +171,19 @@ private Item() {
this.npcpricerook = null;
this.buyfrom = null;
this.sellto = null;
this.notes2 = null;
this.fansite = null;
}

@SuppressWarnings("squid:S00107")
@Builder
private Item(String name, Article article, String actualname, String plural, String implemented, String notes,
private Item(String name, Article article, String actualname, String plural, String implemented, String notes, String notes2,
String history, Status status, List<Integer> itemid, YesNo marketable, YesNo usable, String sprites,
String flavortext, Status ingamestatus, String words, ItemClass itemclass, String primarytype,
String secondarytype, Integer lightcolor, Integer lightradius, Integer levelrequired,
String vocrequired, Integer mlrequired, Hands hands, WeaponType type, String attack,
Integer fireAttack, Integer earthAttack, Integer iceAttack, Integer energyAttack, Integer defense,
String defensemod, Integer imbueslots, String imbuements,
Integer fireAttack, Integer earthAttack, Integer iceAttack, Integer energyAttack, Integer deathAttack,
Integer defense, String defensemod, Integer imbueslots, String imbuements,
YesNo enchantable, YesNo enchanted, String range, String attackModification, String hitpointModification,
Integer armor, String resist, Integer charges, Percentage criticalHitChance,
Percentage criticalHitExtraDamage, Percentage manaleechChance, Percentage manaleechAmount,
Expand All @@ -187,7 +193,7 @@ private Item(String name, Article article, String actualname, String plural, Str
YesNo writable, YesNo rewritable, Integer writechars, YesNo hangable, YesNo holdsliquid, Integer mana,
DamageElement damagetype, String damage, Integer volume, String duration, YesNo destructible,
List<String> droppedby, String value, String npcvalue, String npcprice, String npcvaluerook,
String npcpricerook, String buyfrom, String sellto) {
String npcpricerook, String buyfrom, String sellto, String fansite) {
super(name, article, actualname, plural, implemented, notes, history, status);
this.itemid = itemid;
this.marketable = marketable;
Expand All @@ -211,6 +217,7 @@ private Item(String name, Article article, String actualname, String plural, Str
this.earthAttack = earthAttack;
this.iceAttack = iceAttack;
this.energyAttack = energyAttack;
this.deathAttack = deathAttack;
this.defense = defense;
this.defensemod = defensemod;
this.imbueslots = imbueslots;
Expand Down Expand Up @@ -261,6 +268,8 @@ private Item(String name, Article article, String actualname, String plural, Str
this.npcpricerook = npcpricerook;
this.buyfrom = buyfrom;
this.sellto = sellto;
this.notes2 = notes2;
this.fansite = fansite;
}

@JsonGetter("atk_mod")
Expand Down Expand Up @@ -323,6 +332,11 @@ public Integer getEnergyAttack() {
return energyAttack;
}

@JsonGetter("death_attack")
public Integer getDeathAttack() {
return deathAttack;
}

@Override
public String getTemplateType() {
return InfoboxTemplate.ITEM.getTemplateName();
Expand All @@ -333,12 +347,12 @@ public List<String> fieldOrder() {
return Arrays.asList("name", "article", "actualname", "plural", "itemid", "marketable", "usable", "sprites",
"flavortext", "implemented", "words", "itemclass", "primarytype", "secondarytype", "lightcolor",
"lightradius", "levelrequired", "vocrequired", "mlrequired", "hands", "type", "attack", "fire_attack",
"earth_attack", "ice_attack", "energy_attack", "defense", "defensemod", "imbueslots", "imbuements",
"earth_attack", "ice_attack", "energy_attack", "death_attack", "defense", "defensemod", "imbueslots", "imbuements",
"enchantable", "enchanted", "range", "atk_mod", "hit_mod", "armor", "resist", "charges", "crithit_ch",
"critextra_dmg", "manaleech_ch", "manaleech_am", "hpleech_ch", "hpleech_am", "attrib", "weight",
"stackable", "pickupable", "immobile", "walkable", "unshootable", "blockspath", "rotatable", "mapcolor",
"consumable", "regenseconds", "sounds", "writable", "rewritable", "writechars", "hangable", "holdsliquid",
"mana", "damagetype", "damage", "volume", "duration", "destructible", "droppedby", "value", "npcvalue",
"npcprice", "npcvaluerook", "npcpricerook", "buyfrom", "sellto", "notes", "history", "status");
"npcprice", "npcvaluerook", "npcpricerook", "buyfrom", "sellto", "notes", "notes2", "fansite", "history", "status");
}
}
Loading

0 comments on commit 214adfd

Please sign in to comment.