Overhauled itemBonuses to actually work. Have yet to test timed bonuses, I think they use auxdata for number of hours left. Wood essence also introduced.

This commit is contained in:
mstoppelli
2018-06-06 08:08:30 -04:00
parent 361432ec1e
commit 5b9fa72644
11 changed files with 359 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
package mod.sin.wyvern;
import com.wurmonline.server.*;
import com.wurmonline.server.behaviours.Vehicle;
import com.wurmonline.server.behaviours.Vehicles;
import com.wurmonline.server.bodys.Wound;
import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.creatures.CreatureTemplateIds;
@@ -29,10 +31,13 @@ import mod.sin.items.SealedMap;
import mod.sin.kingdomoffices.ItemCreator;
import mod.sin.lib.Util;
import mod.sin.wyvern.util.TraderItem;
import org.gotti.wurmunlimited.modloader.ReflectionUtil;
import org.gotti.wurmunlimited.modloader.classhooks.HookException;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
import org.gotti.wurmunlimited.modsupport.ModSupportDb;
import org.gotti.wurmunlimited.modsupport.vehicles.ModVehicleBehaviours;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -158,18 +163,48 @@ public class MiscChanges {
return food.getFoodComplexity()*mult;
}
public static float boatSpeedBonus(Creature captain) {
if(captain.getDeity().getNumber() != Deities.DEITY_VYNORA) {
return 1;
}
else {
if(captain.getFaith() >= 60.0) {
return (float)1.2;
public static float boatSpeedBonus(Vehicle boat) {
try {
Player captain = Players.getInstance().getPlayer(boat.pilotId);
if (captain.getDeity().getNumber() != Deities.DEITY_VYNORA) {
return 1;
}
if (captain.isOffline()) {
return 1;
} else {
if (captain.getFaith() >= 60.0) {
return 1.2f;
}
return 1;
}
} catch (NoSuchPlayerException e) {
e.printStackTrace();
return 1;
}
}
public static void buffBoat(Vehicle boat, Item item) {
try {
Map<Integer, Float> newBoatSpeeds = new HashMap<>();
newBoatSpeeds.put(ItemList.caravel, 20f);
if(!item.isBoat() || newBoatSpeeds.get(item.getTemplateId()) == null) {
return;
}
float newWindImpact = newBoatSpeeds.get(item.getTemplateId());
logger.info("BoatBuff: Changing the wind impact of " + item.getName() + " from " + boat.getWindImpact() + " to " + newWindImpact + ".");
Class vehicleClass = boat.getClass();
float newWindMultiplier = Math.abs(newWindImpact - boat.getWindImpact()) / 10;
float oldSpeed = ReflectionUtil.getPrivateField(boat, ReflectionUtil.getField(vehicleClass, "maxSpeed"));
ReflectionUtil.setPrivateField(boat, ReflectionUtil.getField(vehicleClass, "maxSpeed"), oldSpeed * newWindMultiplier);
ReflectionUtil.callPrivateMethod(boat, ReflectionUtil.getMethod(vehicleClass, "setWindImpact"), (byte)newWindImpact);
byte wi = ReflectionUtil.getPrivateField(boat, ReflectionUtil.getField(vehicleClass, "windImpact"));
float ns = ReflectionUtil.getPrivateField(boat, ReflectionUtil.getField(vehicleClass, "maxSpeed"));
logger.info("BoatBuff: The new max speed of " + item.getName() + " is " + ns + " and the new wind impact is " + wi);
} catch (IllegalAccessException | NoSuchFieldException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
public static long getBedBonus(long secs, long bed){
Optional<Item> beds = Items.getItemOptional(bed);
if(beds.isPresent()) {
@@ -220,7 +255,7 @@ public class MiscChanges {
logger.info("Adding sealed maps to trader restock list");
toRestock.add(new TraderItem(EnchantersCrystal.templateId, 99, true, 10, 101, 10));
logger.info("Adding enchant crystals to trader restock list");
toRestock.add(new TraderItem(ChaosCrystal.templateId, 99, true, 10, 101, 10));
toRestock.add(new TraderItem(ChaosCrystal.templateId, 99, true, 10, 31, 10));
logger.info("Adding chaos crystals to trader restock list");
@@ -333,6 +368,7 @@ public class MiscChanges {
String replace;
// - Create Server tab with initial messages - //
CtClass ctVehicle = classPool.get("com.wurmonline.server.behaviours.Vehicle");
CtClass ctPlayers = classPool.get("com.wurmonline.server.Players");
CtMethod m = ctPlayers.getDeclaredMethod("sendStartGlobalKingdomChat");
String infoTabTitle = "Server";
@@ -635,6 +671,16 @@ public class MiscChanges {
"}";
Util.instrumentDeclared(thisClass, ctTempStates, "checkForChange", "setName", replace);
CtClass[] params13 = {
ctItem
};
String desc13 = Descriptor.ofMethod(ctVehicle, params13);
Util.setReason("Buffing caravels to be less based on wind");
CtClass ctVehicles = classPool.get("com.wurmonline.server.behaviours.Vehicles");
replace = "$_ = $proceed($1, $2);" +
"" + MiscChanges.class.getName() + ".buffBoat($2, $1);";
Util.instrumentDescribed(thisClass, ctVehicles, "createVehicle", desc13, "setSettingsForVehicle", replace);
Util.setReason("Stop royal food decay.");
// Item parent, int parentTemp, boolean insideStructure, boolean deeded, boolean saveLastMaintained, boolean inMagicContainer, boolean inTrashbin
CtClass[] params11 = {
@@ -782,10 +828,10 @@ public class MiscChanges {
replace = "$_ = $proceed($$);" + MiscChanges.class.getName() + ".restockTrader($1);";
Util.instrumentDeclared(thisClass, ctShop, "makeTrade", "getShop", replace);
CtClass ctVehicles = classPool.get("com.wurmonline.server.behaviours.VehicleBehaviour");
Util.setReason("Allow preists of vynora to gain 20% boat speed above 60 faith.");
replace = "$_ = $proceed($1, $2 * " + MiscChanges.class.getName() + ".boatSpeedBonus(Players.getInstance().getPlayer(this.pilotId)));";
ctVehicles.getDeclaredMethod("calculateNewBoatSpeed").instrument(new ExprEditor() {
//Util.setReason("Allow preists of vynora to gain 20% boat speed above 60 faith.");
//replace = "$_ = $proceed($1, $2 * " + MiscChanges.class.getName() + ".boatSpeedBonus(Players.getInstance().getPlayer(this.pilotId)));";
ctVehicle.getDeclaredMethod("calculateNewBoatSpeed").instrument(new ExprEditor() {
private boolean first = true;
@Override
@@ -795,7 +841,7 @@ public class MiscChanges {
first = false;
}
else {
m.replace("$_ = $proceed($1, $2 * " + MiscChanges.class.getName() + ".boatSpeedBonus(Players.getInstance().getPlayer(this.pilotId)));");
m.replace("$_ = $proceed($1, $2 * " + MiscChanges.class.getName() + ".boatSpeedBonus(this));");
logger.info("Allowing preists of vynora to gain 20% boat speed above 60 faith.");
}
}
@@ -825,7 +871,7 @@ public class MiscChanges {
} catch (CannotCompileException | NotFoundException | IllegalArgumentException | ClassCastException e) {
throw new HookException(e);
}
}
}
public static void logMessage(String message){
logger.info(message);
}