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

@@ -0,0 +1,98 @@
package mod.sin.actions.items;
import com.wurmonline.server.Items;
import com.wurmonline.server.Server;
import com.wurmonline.server.behaviours.Action;
import com.wurmonline.server.behaviours.ActionEntry;
import com.wurmonline.server.behaviours.Actions;
import com.wurmonline.server.behaviours.NoSuchActionException;
import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.players.Player;
import com.wurmonline.server.skills.NoSuchSkillException;
import com.wurmonline.server.skills.Skill;
import com.wurmonline.server.skills.SkillList;
import mod.sin.items.WoodEssence;
import org.gotti.wurmunlimited.modsupport.actions.ActionPerformer;
import org.gotti.wurmunlimited.modsupport.actions.BehaviourProvider;
import org.gotti.wurmunlimited.modsupport.actions.ModAction;
import org.gotti.wurmunlimited.modsupport.actions.ModActions;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class WoodEssenceAction implements ModAction, BehaviourProvider, ActionPerformer {
private static Logger logger = Logger.getLogger(WoodEssenceAction.class.getName());
private final short actionId;
private final ActionEntry actionEntry;
public WoodEssenceAction() {
logger.log(Level.WARNING, "WoodEssenceAction()");
actionId = (short) ModActions.getNextActionId();
actionEntry = ActionEntry.createEntry(
actionId,
"Imbue",
"imbuing",
new int[] { 6 }
//new int[] { 6 /* ACTION_TYPE_NOMOVE */ } // 6 /* ACTION_TYPE_NOMOVE */, 48 /* ACTION_TYPE_ENEMY_ALWAYS */, 36 /* ACTION_TYPE_ALWAYS_USE_ACTIVE_ITEM */
);
ModActions.registerAction(actionEntry);
}
@Override
public List<ActionEntry> getBehavioursFor(Creature performer, Item source, Item object)
{
if(performer instanceof Player && source != null && object != null && object.isWood() && source.getTemplateId() == WoodEssence.templateId && source != object && object.getTemplateId() != WoodEssence.templateId) {
return Arrays.asList(actionEntry);
}
return null;
}
@Override
public boolean action(Action act, Creature performer, Item source, Item target, short action, float counter) {
try {
if(source.getTemplateId() != WoodEssence.templateId) {
performer.getCommunicator().sendNormalServerMessage("You must use a wood essence to do that!");
return true;
}
if(source.getWurmId() == target.getWurmId()) {
performer.getCommunicator().sendNormalServerMessage("You cannot infuse the essence with itself!");
return true;
}
if(!performer.isWithinDistanceTo(target, 4)) {
performer.getCommunicator().sendNormalServerMessage("You are too far away to do that!");
return true;
}
if(counter == 1.0f) {
performer.getCommunicator().sendNormalServerMessage("You begin infusing the " + target.getName() +".");
Server.getInstance().broadCastAction(performer.getName() + " begins infusing the " + target.getName() + ".", performer, 5);
Skill infuseSkill = performer.getSkills().getSkill(SkillList.ALCHEMY_NATURAL);
int time = Actions.getStandardActionTime(performer, infuseSkill, source, 0d);
act.setTimeLeft(time);
performer.sendActionControl("Infusing", true, act.getTimeLeft());
}
else if(counter * 10 > performer.getCurrentAction().getTimeLeft()) {
performer.getCommunicator().sendNormalServerMessage("You finish imbuing " + target.getName() + " with the properties of another tree. It's damaged in the process.");
target.setMaterial(source.getMaterial());
Items.destroyItem(source.getWurmId());
source.setDamage(20f);
return true;
}
return false;
} catch (NoSuchActionException | NoSuchSkillException e) {
e.printStackTrace();
performer.getCommunicator().sendNormalServerMessage("Something interrupts your infusing!");
return true;
}
}
@Override
public short getActionId() {
return 0;
}
}

View File

@@ -106,7 +106,7 @@ public class WyvernRed implements ModCreature, CreatureTypes {
vehicle.setName(creature.getName());
vehicle.setMaxHeightDiff(0.10f);
vehicle.setMaxDepth(-50f);
vehicle.setMaxSpeed(40.0f);
vehicle.setMaxSpeed(35.0f);
vehicle.setCommandType((byte) 3);
vehicle.setCanHaveEquipment(true);
}

View File

@@ -42,7 +42,7 @@ public class ChaosCrystal implements ItemTypes, MiscConstants {
itemBuilder.difficulty(5.0f);
itemBuilder.weightGrams(250);
itemBuilder.material(Materials.MATERIAL_CRYSTAL);
itemBuilder.value(10000);
itemBuilder.value(100000);
itemBuilder.isTraded(true);
ItemTemplate template = itemBuilder.build();

View File

@@ -15,7 +15,7 @@ public class WoodEssence implements ItemTypes, MiscConstants {
public void createTemplate() throws IOException {
String name = "wood essence";
ItemTemplateBuilder itemBuilder = new ItemTemplateBuilder("mod.item.wood.essence");
itemBuilder.name(name, "wood essences", "A tool kit for directing pipes into a source of water.");
itemBuilder.name(name, "wood essences", "The essence of a log. Can be used to change a wooden item's material.");
itemBuilder.descriptions("excellent", "good", "ok", "poor");
itemBuilder.itemTypes(new short[]{ // {108, 146, 44, 21, 147, 113} - War Arrow
ItemTypes.ITEM_TYPE_FULLPRICE,
@@ -45,7 +45,7 @@ public class WoodEssence implements ItemTypes, MiscConstants {
public void initCreationEntry() {
logger.info("initCreationEntry()");
if(templateId > 0) {
CreationEntryCreator.createSimpleEntry(SkillList.FORESTRY, ItemList.sourceSalt, ItemList.log, templateId, true, true, 0.0f, true, false, CreationCategories.RESOURCES);
CreationEntryCreator.createSimpleEntry(SkillList.ALCHEMY_NATURAL, ItemList.sourceSalt, ItemList.log, templateId, true, true, 0.0f, true, false, CreationCategories.RESOURCES);
}
else{
logger.info("woodEssence does not have a template ID on creation entry.");

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