Skip to content

Commit

Permalink
Changed setNoDecay behaviour slightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mthec committed Apr 24, 2020
1 parent 0d238dc commit 84519da
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 57 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'mod.wurmunlimited.delivery'
version = '0.5.8'
version = '0.5.9-beta'

sourceCompatibility = 1.8
def $shortName = 'deliverycontracts'
Expand All @@ -16,7 +16,9 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testImplementation 'org.mockito:mockito-inline:2.+'
implementation fileTree(dir: 'E:/Steam/steamapps/common/Wurm Unlimited/WurmServerLauncher/', includes: ["modlauncher.jar", "javassist.jar", "server.jar"])
implementation fileTree(dir: 'E:/Steam/steamapps/common/Wurm Unlimited/WurmServerLauncher/', includes: ["server.jar"])
implementation fileTree(dir: 'E:/Steam/steamapps/common/Wurm Unlimited/WurmServerLauncher/lib/', includes: ["javassist-3.23.1.jar",
"ServerLauncher-0.43.jar", "WurmUnlimitedCommon-1.9.2.7.jar", "annotations-16.0.2.jar", "sqlite-jdbc-3.8.11.2.jar"])
}

jar {
Expand Down
Expand Up @@ -52,14 +52,13 @@ public List<ActionEntry> getBehavioursFor(Creature performer, Item subject, Item

private void unMarkItemAndSubItems(Item item) {
item.setMailed(false);
if (DeliveryContractsMod.setNoDecay) {
if (DeliveryContractsMod.setNoDecay || (DeliveryContractsMod.setNoDecayFood && item.isFood())) {
String description = item.getDescription();
if (description.endsWith("*"))
item.setDescription(description.substring(0, description.length() - 1));
else
item.setHasNoDecay(false);
} else if (DeliveryContractsMod.setNoDecayFood && item.isFood())
item.setHasNoDecay(false);
}

for (Item subItem : item.getItems()) {
unMarkItemAndSubItems(subItem);
Expand Down
Expand Up @@ -245,12 +245,10 @@ private void actuallyTake(Creature performer, Item target, Item contract) throws

private void markItemAndSubItems(Item target) {
target.setMailed(true);
if (DeliveryContractsMod.setNoDecay) {
if (DeliveryContractsMod.setNoDecay || (DeliveryContractsMod.setNoDecayFood && target.isFood())) {
if (target.hasNoDecay())
target.setDescription(target.getDescription() + "*");
target.setHasNoDecay(true);
} else if (DeliveryContractsMod.setNoDecayFood && target.isFood()) {
target.setHasNoDecay(true);
}

for (Item item : target.getItems()) {
Expand Down
Expand Up @@ -43,7 +43,6 @@ public class DeliveryContractsMod implements WurmServerMod, Configurable, PreIni
public static boolean setNoDecayFood;
private long lastCleanup;

// TODO - Temp
public static final Set<Item> blockWeight = new HashSet<>();

// The following would be nice, but would require big workaround that is arguably not worth the effort for marginal benefit.
Expand Down
Expand Up @@ -8,8 +8,8 @@
import com.wurmonline.server.items.Trade;
import com.wurmonline.server.villages.Village;
import com.wurmonline.server.zones.VolaTile;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nullable;
import java.util.logging.Logger;

public class Creature {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/wurmonline/server/items/ItemFactory.java
@@ -1,6 +1,6 @@
package com.wurmonline.server.items;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

public class ItemFactory {

Expand Down
Expand Up @@ -368,66 +368,65 @@ private int setOwnerStuff(ItemTemplate template, int weight) throws Throwable {
return changeOwner(new Object[] { template }, template.getTemplateId(), weight);
}

// TODO - Re-enable.
// @Test
// void testSetOwnerBlocksContractContentsWeightBeingAddedToCreature() throws Throwable {
// assertEquals(0, setOwner(DeliveryContractsMod.getTemplateId(), 1000));
// }
@Test
void testSetOwnerBlocksContractContentsWeightBeingAddedToCreature() throws Throwable {
assertEquals(0, setOwner(DeliveryContractsMod.getTemplateId(), 1000));
}

@Test
void testSetOwnerAllowsNotContractContentsWeightBeingAddedToCreature() throws Throwable {
int weight = 1000;
assertEquals(weight, setOwner(ItemList.backPack, weight));
}

// @Test
// void testSetOwnerStuffBlocksContractContentsWeightBeingAddedToCreature() throws Throwable {
// assertEquals(0, setOwnerStuff(new ItemTemplate(DeliveryContractsMod.getTemplateId(), "contract"), 1000));
// }
@Test
void testSetOwnerStuffBlocksContractContentsWeightBeingAddedToCreature() throws Throwable {
assertEquals(0, setOwnerStuff(new ItemTemplate(DeliveryContractsMod.getTemplateId(), "contract"), 1000));
}

@Test
void testSetOwnerStuffAllowsNotContractContentsWeightBeingAddedToCreature() throws Throwable {
int weight = 1000;
assertEquals(weight, setOwnerStuff(new ItemTemplate(ItemList.backPack, "backpack"), weight));
}

// @Test
// void testAddCarriedWeightBlocks() throws Throwable {
// DeliveryContractsMod deliveryContractsMod = new DeliveryContractsMod();
// Creature player = new Player();
// int weight = 100000;
//
// InvocationHandler handler = deliveryContractsMod::addCarriedWeight;
// Method method = mock(Method.class);
// Object[] args = new Object[] { weight };
//
// DeliveryContractsMod.addWeightToBlock(player, weight);
//
// assertNull(handler.invoke(player, method, args));
// verify(method, never()).invoke(player, args);
//
// assertNull(handler.invoke(player, method, args));
// verify(method, times(1)).invoke(player, args);
// }
//
// @Test
// void testRemoveCarriedWeightBlocks() throws Throwable {
// DeliveryContractsMod deliveryContractsMod = new DeliveryContractsMod();
// Creature player = new Player();
// int weight = 100000;
//
// InvocationHandler handler = deliveryContractsMod::removeCarriedWeight;
// Method method = mock(Method.class);
// Object[] args = new Object[] { weight };
//
// DeliveryContractsMod.addWeightToBlock(player, weight);
//
// assertTrue((Boolean)handler.invoke(player, method, args));
// verify(method, never()).invoke(player, args);
//
// assertNull(handler.invoke(player, method, args));
// verify(method, times(1)).invoke(player, args);
// }
@Test
void testAddCarriedWeightBlocks() throws Throwable {
DeliveryContractsMod deliveryContractsMod = new DeliveryContractsMod();
Creature player = new Player();
int weight = 100000;

InvocationHandler handler = deliveryContractsMod::addCarriedWeight;
Method method = mock(Method.class);
Object[] args = new Object[] { weight };

DeliveryContractsMod.addWeightToBlock(player, weight);

assertNull(handler.invoke(player, method, args));
verify(method, never()).invoke(player, args);

assertNull(handler.invoke(player, method, args));
verify(method, times(1)).invoke(player, args);
}

@Test
void testRemoveCarriedWeightBlocks() throws Throwable {
DeliveryContractsMod deliveryContractsMod = new DeliveryContractsMod();
Creature player = new Player();
int weight = 100000;

InvocationHandler handler = deliveryContractsMod::removeCarriedWeight;
Method method = mock(Method.class);
Object[] args = new Object[] { weight };

DeliveryContractsMod.addWeightToBlock(player, weight);

assertTrue((Boolean)handler.invoke(player, method, args));
verify(method, never()).invoke(player, args);

assertNull(handler.invoke(player, method, args));
verify(method, times(1)).invoke(player, args);
}

@Test
void testGetItemsAsArrayReturnsEmptyIfContractWhenTraded() throws Throwable {
Expand Down

0 comments on commit 84519da

Please sign in to comment.