From 41a5b19c7900f59fdbdecdcc8d788ccead2ee2a6 Mon Sep 17 00:00:00 2001 From: mstoppelli Date: Fri, 7 Dec 2018 00:49:46 -0500 Subject: [PATCH] Converted back to gradle maybe or something, cleared out old in progress code from item bonuses, giving up on unique skill bonuses, will likely just use skillid to check if its like religion or fighting and not bonus those --- .idea/compiler.xml | 2 + ...com_github_Sindusk_sindusklibrary_v1_0.xml | 9 ---- ...org_gotti_wurmunlimited_common_2613165.xml | 9 ---- ...org_gotti_wurmunlimited_server_2613165.xml | 9 ---- ...nlimited_server_modlauncher_0_33_beta1.xml | 9 ---- ...dle__org_javassist_javassist_3_20_0_GA.xml | 6 ++- .idea/modules.xml | 7 ++- .idea/modules/WyvernMods_main.iml | 2 +- .idea/modules/WyvernMods_test.iml | 2 +- WyvernMods.iml | 2 +- .../mod/sin/actions/AddSubGroupAction.java | 1 - .../sin/actions/items/WoodEssenceAction.java | 9 ++-- src/main/java/mod/sin/items/WoodEssence.java | 11 +++-- .../bonusoverhaul/ItemBonusOverhaul.java | 46 +++++++++++++++++++ .../bonusoverhaul/ItemBonusWrapper.java | 30 ++++++++++++ .../mod/sin/wyvern/bounty/PlayerBounty.java | 4 +- 16 files changed, 104 insertions(+), 54 deletions(-) delete mode 100644 .idea/libraries/Gradle__com_github_Sindusk_sindusklibrary_v1_0.xml delete mode 100644 .idea/libraries/Gradle__org_gotti_wurmunlimited_common_2613165.xml delete mode 100644 .idea/libraries/Gradle__org_gotti_wurmunlimited_server_2613165.xml delete mode 100644 .idea/libraries/Gradle__org_gotti_wurmunlimited_server_modlauncher_0_33_beta1.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index a8d902c..1208fda 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -3,6 +3,8 @@ + + diff --git a/.idea/libraries/Gradle__com_github_Sindusk_sindusklibrary_v1_0.xml b/.idea/libraries/Gradle__com_github_Sindusk_sindusklibrary_v1_0.xml deleted file mode 100644 index d678854..0000000 --- a/.idea/libraries/Gradle__com_github_Sindusk_sindusklibrary_v1_0.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_gotti_wurmunlimited_common_2613165.xml b/.idea/libraries/Gradle__org_gotti_wurmunlimited_common_2613165.xml deleted file mode 100644 index 02cdd92..0000000 --- a/.idea/libraries/Gradle__org_gotti_wurmunlimited_common_2613165.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_gotti_wurmunlimited_server_2613165.xml b/.idea/libraries/Gradle__org_gotti_wurmunlimited_server_2613165.xml deleted file mode 100644 index 09e5f1f..0000000 --- a/.idea/libraries/Gradle__org_gotti_wurmunlimited_server_2613165.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_gotti_wurmunlimited_server_modlauncher_0_33_beta1.xml b/.idea/libraries/Gradle__org_gotti_wurmunlimited_server_modlauncher_0_33_beta1.xml deleted file mode 100644 index 6f76bba..0000000 --- a/.idea/libraries/Gradle__org_gotti_wurmunlimited_server_modlauncher_0_33_beta1.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_javassist_javassist_3_20_0_GA.xml b/.idea/libraries/Gradle__org_javassist_javassist_3_20_0_GA.xml index f60e353..fdd8716 100644 --- a/.idea/libraries/Gradle__org_javassist_javassist_3_20_0_GA.xml +++ b/.idea/libraries/Gradle__org_javassist_javassist_3_20_0_GA.xml @@ -1,9 +1,11 @@ - + - + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index ad87626..4c616f8 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,8 +3,11 @@ - - + + + + + \ No newline at end of file diff --git a/.idea/modules/WyvernMods_main.iml b/.idea/modules/WyvernMods_main.iml index f141708..d8c7a29 100644 --- a/.idea/modules/WyvernMods_main.iml +++ b/.idea/modules/WyvernMods_main.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/WyvernMods_test.iml b/.idea/modules/WyvernMods_test.iml index c2109e4..56bf69c 100644 --- a/.idea/modules/WyvernMods_test.iml +++ b/.idea/modules/WyvernMods_test.iml @@ -1,5 +1,5 @@ - + diff --git a/WyvernMods.iml b/WyvernMods.iml index 8d9127d..4fa2cdc 100644 --- a/WyvernMods.iml +++ b/WyvernMods.iml @@ -1,5 +1,5 @@ - + diff --git a/src/main/java/mod/sin/actions/AddSubGroupAction.java b/src/main/java/mod/sin/actions/AddSubGroupAction.java index 37fafe4..d48dd42 100644 --- a/src/main/java/mod/sin/actions/AddSubGroupAction.java +++ b/src/main/java/mod/sin/actions/AddSubGroupAction.java @@ -28,7 +28,6 @@ public class AddSubGroupAction implements ModAction { public AddSubGroupAction() { logger.log(Level.WARNING, "AddSubGroupAction()"); - actionId = (short) ModActions.getNextActionId(); actionEntry = ActionEntry.createEntry( actionId, diff --git a/src/main/java/mod/sin/actions/items/WoodEssenceAction.java b/src/main/java/mod/sin/actions/items/WoodEssenceAction.java index 8f2c197..9b61be0 100644 --- a/src/main/java/mod/sin/actions/items/WoodEssenceAction.java +++ b/src/main/java/mod/sin/actions/items/WoodEssenceAction.java @@ -37,7 +37,7 @@ public class WoodEssenceAction implements ModAction, BehaviourProvider, ActionPe actionId, "Imbue", "imbuing", - new int[] { 6 } + new int[0] //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); @@ -75,11 +75,12 @@ public class WoodEssenceAction implements ModAction, BehaviourProvider, ActionPe act.setTimeLeft(time); performer.sendActionControl("Infusing", true, act.getTimeLeft()); } - else if(counter * 10 > performer.getCurrentAction().getTimeLeft()) { + else if(counter * 10.0f > 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()); + target.sendUpdate(); Items.destroyItem(source.getWurmId()); - source.setDamage(20f); + target.setDamage(20f); return true; } return false; @@ -93,6 +94,6 @@ public class WoodEssenceAction implements ModAction, BehaviourProvider, ActionPe @Override public short getActionId() { - return 0; + return actionId; } } diff --git a/src/main/java/mod/sin/items/WoodEssence.java b/src/main/java/mod/sin/items/WoodEssence.java index f18b26f..a5c43a9 100644 --- a/src/main/java/mod/sin/items/WoodEssence.java +++ b/src/main/java/mod/sin/items/WoodEssence.java @@ -21,7 +21,8 @@ public class WoodEssence implements ItemTypes, MiscConstants { ItemTypes.ITEM_TYPE_FULLPRICE, ItemTypes.ITEM_TYPE_NOSELLBACK, ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE, - ItemTypes.ITEM_TYPE_WOOD + ItemTypes.ITEM_TYPE_WOOD, + ItemTypes.ITEM_TYPE_NAMED }); itemBuilder.imageNumber((short) 859); itemBuilder.behaviourType((short) 1); @@ -31,8 +32,8 @@ public class WoodEssence implements ItemTypes, MiscConstants { itemBuilder.primarySkill((int) NOID); itemBuilder.bodySpaces(MiscConstants.EMPTY_BYTE_PRIMITIVE_ARRAY); itemBuilder.modelName("model.valrei."); - itemBuilder.difficulty(300.0f); - itemBuilder.weightGrams(4500); + itemBuilder.difficulty(80.0f); + itemBuilder.weightGrams(1); itemBuilder.material(Materials.MATERIAL_WOOD_BIRCH); itemBuilder.value(1); itemBuilder.isTraded(true); @@ -45,7 +46,9 @@ public class WoodEssence implements ItemTypes, MiscConstants { public void initCreationEntry() { logger.info("initCreationEntry()"); if(templateId > 0) { - CreationEntryCreator.createSimpleEntry(SkillList.ALCHEMY_NATURAL, ItemList.sourceSalt, ItemList.log, templateId, true, true, 0.0f, true, false, CreationCategories.RESOURCES); + CreationEntryCreator.createAdvancedEntry(SkillList.ALCHEMY_NATURAL, 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, false, false, CreationCategories.RESOURCES); } else{ logger.info("woodEssence does not have a template ID on creation entry."); diff --git a/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java b/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java index 5533db3..3a9c721 100644 --- a/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java +++ b/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusOverhaul.java @@ -1,17 +1,24 @@ package mod.sin.wyvern.bonusoverhaul; +import com.wurmonline.server.creatures.Creature; import com.wurmonline.server.creatures.SpellEffectsEnum; import com.wurmonline.server.items.*; +import com.wurmonline.server.players.ItemBonus; +import com.wurmonline.server.skills.NoSuchSkillException; +import com.wurmonline.server.skills.Skill; import javassist.ClassPool; import javassist.CtClass; import javassist.NotFoundException; +import javassist.bytecode.Descriptor; import mod.sin.armour.GlimmerscaleVest; import mod.sin.lib.Util; import mod.sin.wyvern.MiscChanges; +import org.gotti.wurmunlimited.modloader.ReflectionUtil; import org.gotti.wurmunlimited.modloader.classhooks.HookException; import org.gotti.wurmunlimited.modloader.classhooks.HookManager; import org.gotti.wurmunlimited.modloader.interfaces.PreInitable; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; @@ -19,6 +26,7 @@ import java.util.logging.Logger; public class ItemBonusOverhaul { private static List itemBonuses = new ArrayList<>(); private static Logger logger = Logger.getLogger(ItemBonusOverhaul.class.getName()); + private static final float SKILLGAIN_BONUS_SCALE = .01f; /** * Called to add all itemBonusWrapper objects to the itemBonuses list to be called upon later. @@ -75,6 +83,40 @@ public class ItemBonusOverhaul { return null; } + public static float getNewSkillBonus(Creature creature, int skillid) { + try { + ItemBonusWrapper wrapper; + CtClass[] params1 = { + CtClass.longType, + CtClass.intType + }; + String desc = Descriptor.ofMethod(CtClass.floatType, params1); + float bonus = ReflectionUtil.callPrivateMethod(ItemBonus.class, ReflectionUtil.getMethod(ItemBonus.class, "getBonus"), creature.getWurmId(), SpellEffectsEnum.ITEM_RING_SKILLGAIN.getTypeId()); + for(Item item:creature.getBody().getContainersAndWornItems()) { + wrapper = matchTemplateidToWrapper(item.getTemplateId()); + if(wrapper != null) { + if(!checkItemBonusForSkill(wrapper, skillid) && wrapper.getEffect() == SpellEffectsEnum.ITEM_RING_SKILLGAIN) { + bonus -= wrapper.getValue() * item.getCurrentQualityLevel() * .01f; + } + } + } + return bonus; + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + return 0.0f; + } + } + + public static boolean checkItemBonusForSkill(ItemBonusWrapper wrapper, int skillid) { + if(wrapper.getEffect() != SpellEffectsEnum.ITEM_RING_SKILLGAIN) { + return false; + } + if(wrapper.isSkillRestricted() && wrapper.getRestrictedSkill() == skillid) { + return true; + } + return !wrapper.isSkillRestricted(); + } + public static void preInit() { try { ClassPool classPool = HookManager.getInstance().getClassPool(); @@ -95,6 +137,10 @@ public class ItemBonusOverhaul { replace = "{ return " + ItemBonusOverhaul.class.getName() + ".getNewTimed($1); }"; Util.setBodyDeclared(thisClass, itemBonus, "isTimed", replace); + Util.setReason("Overwrite default check for bonus skillgain"); + replace = "{ return " + ItemBonusOverhaul.class.getName() + ".getNewSkillBonus($1, $2); }"; + Util.setBodyDeclared(thisClass, itemBonus, "getSkillGainBonus", 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); diff --git a/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusWrapper.java b/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusWrapper.java index 3626d63..1724f1a 100644 --- a/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusWrapper.java +++ b/src/main/java/mod/sin/wyvern/bonusoverhaul/ItemBonusWrapper.java @@ -1,6 +1,7 @@ package mod.sin.wyvern.bonusoverhaul; import com.wurmonline.server.creatures.SpellEffectsEnum; +import com.wurmonline.server.skills.Skill; public class ItemBonusWrapper { private int templateid; @@ -8,6 +9,8 @@ public class ItemBonusWrapper { private boolean stackable; private float value; private boolean timed; + private boolean skillRestricted; + private int restrictedSkill; public ItemBonusWrapper(int templateid, SpellEffectsEnum effect, boolean stackable, float value, boolean timed) { this.templateid = templateid; @@ -15,6 +18,17 @@ public class ItemBonusWrapper { this.stackable = stackable; this.value = value; this.timed = timed; + this.skillRestricted = false; + } + + public ItemBonusWrapper(int templateid, SpellEffectsEnum effect, boolean stackable, float value, boolean timed, boolean skillRestricted, int restrictedSkill) { + this.templateid = templateid; + this.effect = effect; + this.stackable = stackable; + this.value = value; + this.timed = timed; + this.skillRestricted = skillRestricted; + this.restrictedSkill = restrictedSkill; } public int getTemplateid() { @@ -56,4 +70,20 @@ public class ItemBonusWrapper { public void setTimed(boolean timed) { this.timed = timed; } + + public boolean isSkillRestricted() { + return skillRestricted; + } + + public void setSkillRestricted(boolean skillRestricted) { + this.skillRestricted = skillRestricted; + } + + public int getRestrictedSkill() { + return restrictedSkill; + } + + public void setRestrictedSkill(int restrictedSkill) { + this.restrictedSkill = restrictedSkill; + } } diff --git a/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java b/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java index d285866..dfc9554 100644 --- a/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java +++ b/src/main/java/mod/sin/wyvern/bounty/PlayerBounty.java @@ -119,8 +119,8 @@ public class PlayerBounty { 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); + Item treasure = ItemFactory.createItem(TreasureBox.templateId, quality, ""); + player.getInventory().insertItem(treasure); player.getCommunicator().sendNormalServerMessage("You find something in your inventory!"); } catch (FailedException | NoSuchTemplateException e) { e.printStackTrace();