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

@@ -103,6 +103,7 @@ public class ItemMod {
public static PipingKit PIPING_KIT = new PipingKit();
public static StableContract STABLE_CONTRACT = new StableContract();
public static MoreAnchors MORE_ANCHORS = new MoreAnchors();
public static WoodEssence WOOD_ESSENCE = new WoodEssence();
public static void createItems(){
logger.info("createItems()");
@@ -137,6 +138,7 @@ public class ItemMod {
WARHAMMER_HEAD.createTemplate();
PIPING_KIT.createTemplate();
STABLE_CONTRACT.createTemplate();
WOOD_ESSENCE.createTemplate();
// Arena Fragments
@@ -193,6 +195,7 @@ public class ItemMod {
ModActions.registerAction(new TreasureBoxAction());
ModActions.registerAction(new PipingKitAction());
ModActions.registerAction(new StableContractAction());
ModActions.registerAction(new WoodEssenceAction());
}
public static void initCreationEntries(){
@@ -215,6 +218,7 @@ public class ItemMod {
WARHAMMER_HEAD.initCreationEntry();
//HUGE_CRATE.initCreationEntry();
MORE_ANCHORS.initCreationEntry();
WOOD_ESSENCE.initCreationEntry();
// Spectral set
/*SPECTRAL_BOOT.initCreationEntry();

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);
}

View File

@@ -28,6 +28,7 @@ import javassist.bytecode.Descriptor;
import mod.sin.items.*;
import mod.sin.kingdomoffices.ItemCreator;
import mod.sin.lib.Util;
import mod.sin.wyvern.bonusoverhaul.ItemBonusOverhaul;
import org.gotti.wurmunlimited.modloader.ReflectionUtil;
import org.gotti.wurmunlimited.modloader.classhooks.HookException;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
@@ -160,6 +161,7 @@ implements WurmServerMod, Configurable, PreInitable, Initable, ItemTemplatesCrea
Mastercraft.preInit();
Mastercraft.addNewTitles();
SupplyDepots.preInit();
ItemBonusOverhaul.preInit();
Class<WyvernMods> thisClass = WyvernMods.class;
ClassPool classPool = HookManager.getInstance().getClassPool();
@@ -252,6 +254,7 @@ implements WurmServerMod, Configurable, PreInitable, Initable, ItemTemplatesCrea
Bounty.init();
Mastercraft.changeExistingTitles();
}
@Override
@@ -260,7 +263,13 @@ implements WurmServerMod, Configurable, PreInitable, Initable, ItemTemplatesCrea
ItemMod.createItems();
logger.info("Creating Cache items.");
Caches.createItems();
try {
logger.info("Overhauling item bonuses...");
try {
ItemBonusOverhaul.initializeBonuses();
} catch (NoSuchTemplateException e) {
throw new HookException(e);
}
try {
logger.info("Editing existing item templates.");
ItemMod.modifyItems();
logger.info("Registering permissions hook for custom items.");

View File

@@ -0,0 +1,106 @@
package mod.sin.wyvern.bonusoverhaul;
import com.wurmonline.server.creatures.SpellEffectsEnum;
import com.wurmonline.server.items.*;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
import mod.sin.armour.GlimmerscaleVest;
import mod.sin.lib.Util;
import mod.sin.wyvern.MiscChanges;
import org.gotti.wurmunlimited.modloader.classhooks.HookException;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
import org.gotti.wurmunlimited.modloader.interfaces.PreInitable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
public class ItemBonusOverhaul {
private static List<ItemBonusWrapper> itemBonuses = new ArrayList<>();
private static Logger logger = Logger.getLogger(ItemBonusOverhaul.class.getName());
/**
* Called to add all itemBonusWrapper objects to the itemBonuses list to be called upon later.
*/
public static void initializeBonuses() throws NoSuchTemplateException {
itemBonuses.add(new ItemBonusWrapper(GlimmerscaleVest.templateId, SpellEffectsEnum.ITEM_RING_CR, false, 1.0f, false));
for(ItemBonusWrapper wrapper: itemBonuses) {
ItemTemplate template = ItemTemplateFactory.getInstance().getTemplate(wrapper.getTemplateid());
template.setHasItemBonus(true);
}
}
public static float getNewBonusValueForItem(Item item) {
ItemBonusWrapper wrapper = matchTemplateidToWrapper(item.getTemplateId());
if(wrapper != null) {
logger.info("A call to getNewBonusValue found the wrapper for " + item.getTemplateId() + ".");
return wrapper.getValue() * .01f * item.getCurrentQualityLevel();
}
logger.info("A call to getNewBonusValue did not find the wrapper for " + item.getTemplateId() + ".");
return 0.0f;
}
public static boolean getNewTimed(Item item) {
ItemBonusWrapper wrapper = matchTemplateidToWrapper(item.getTemplateId());
if(wrapper != null) {
return wrapper.isTimed();
}
return false;
}
public static boolean getNewStackable(Item item) {
ItemBonusWrapper wrapper = matchTemplateidToWrapper(item.getTemplateId());
if(wrapper != null) {
return wrapper.isStackable();
}
return false;
}
public static SpellEffectsEnum getNewEffectForTemplateId(int templateid, int extraInfo) {
ItemBonusWrapper wrapper = matchTemplateidToWrapper(templateid);
if(wrapper != null) {
return wrapper.getEffect();
}
return null;
}
public static ItemBonusWrapper matchTemplateidToWrapper(int templateId) {
for(ItemBonusWrapper wrapper:itemBonuses) {
if(templateId == wrapper.getTemplateid()) {
return wrapper;
}
}
return null;
}
public static void preInit() {
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
final Class<ItemBonusOverhaul> thisClass = ItemBonusOverhaul.class;
String replace;
CtClass itemBonus = classPool.get("com.wurmonline.server.players.ItemBonus");
CtClass ctSpellEffectsEnum = classPool.get("com.wurmonline.server.creatures.SpellEffectsEnum");
Util.setReason("Overwrite default itemBonus value checking");
replace = "{ return " + ItemBonusOverhaul.class.getName() + ".getNewBonusValueForItem($1); }";
Util.setBodyDeclared(thisClass, itemBonus, "getBonusValueForItem", replace);
Util.setReason("Overwrite default itemBonus stack checking");
replace = "{ return " + ItemBonusOverhaul.class.getName() + ".getNewStackable($1); }";
Util.setBodyDeclared(thisClass, itemBonus, "getStacking", replace);
Util.setReason("Overwrite default itemBonus timed checking");
replace = "{ return " + ItemBonusOverhaul.class.getName() + ".getNewTimed($1); }";
Util.setBodyDeclared(thisClass, itemBonus, "isTimed", replace);
Util.setReason("Overwrite default item spell effect lookup with one checking the custom list.");
replace = "{ return " + ItemBonusOverhaul.class.getName() + ".getNewEffectForTemplateId($1, $2); }";
Util.setBodyDeclared(thisClass, ctSpellEffectsEnum, "getEnumForItemTemplateId", replace);
} catch (NotFoundException e) {
throw new HookException(e);
}
}
}

View File

@@ -0,0 +1,59 @@
package mod.sin.wyvern.bonusoverhaul;
import com.wurmonline.server.creatures.SpellEffectsEnum;
public class ItemBonusWrapper {
private int templateid;
private SpellEffectsEnum effect;
private boolean stackable;
private float value;
private boolean timed;
public ItemBonusWrapper(int templateid, SpellEffectsEnum effect, boolean stackable, float value, boolean timed) {
this.templateid = templateid;
this.effect = effect;
this.stackable = stackable;
this.value = value;
this.timed = timed;
}
public int getTemplateid() {
return templateid;
}
public void setTemplateid(int templateid) {
this.templateid = templateid;
}
public SpellEffectsEnum getEffect() {
return effect;
}
public void setEffect(SpellEffectsEnum effect) {
this.effect = effect;
}
public boolean isStackable() {
return stackable;
}
public void setStackable(boolean stackable) {
this.stackable = stackable;
}
public float getValue() {
return value;
}
public void setValue(float value) {
this.value = value;
}
public boolean isTimed() {
return timed;
}
public void setTimed(boolean timed) {
this.timed = timed;
}
}

View File

@@ -22,6 +22,8 @@ import mod.sin.armour.SpectralHide;
import mod.sin.creatures.Reaper;
import mod.sin.creatures.SpectralDrake;
import mod.sin.items.AffinityOrb;
import mod.sin.items.EnchantersCrystal;
import mod.sin.items.TreasureBox;
import mod.sin.items.caches.RiftCache;
import mod.sin.items.caches.TitanCache;
import mod.sin.kingdomoffices.ItemCreator;
@@ -112,7 +114,19 @@ public class PlayerBounty {
e.printStackTrace();
}
}
public static void rewardRareLoot(Player player, Creature mob) {
try {
double fightskill = player.getFightingSkill().getKnowledge();
int quality = random.nextInt((int)fightskill);
Item crystal = ItemFactory.createItem(TreasureBox.templateId, quality, (random.nextInt((int)fightskill) < 20 ? (byte)0:(byte)1), "");
player.getInventory().insertItem(crystal);
player.getCommunicator().sendNormalServerMessage("You find something in your inventory!");
} catch (FailedException | NoSuchTemplateException e) {
e.printStackTrace();
}
}
;
public static void checkPlayerReward(Player player, Creature mob){
try{
if(mob.isReborn() || mob.isBred()){
@@ -145,6 +159,7 @@ public class PlayerBounty {
if(RareSpawns.isRareCreature(mob)){
Item riftCache = ItemFactory.createItem(RiftCache.templateId, 50f+(30f*Server.rand.nextFloat()), mob.getName());
player.getInventory().insertItem(riftCache, true);
rewardRareLoot(player, mob);
}
if(Titans.isTitan(mob)){
player.addTitle(Title.getTitle(700));