Schematics basics finished, schematics are added in the item creation entry part, schematics are auto-created and assigned afterwards.

This commit is contained in:
mstoppelli
2018-12-11 03:05:52 -05:00
parent 8d0e7429fe
commit 968f46cd39
12 changed files with 309 additions and 32 deletions

View File

@@ -57,7 +57,7 @@ public class ItemBonusRechargeAction implements ModAction, BehaviourProvider, Ac
} }
if (counter == 1.0f) { if (counter == 1.0f) {
performer.getCommunicator().sendNormalServerMessage("You begin recharging the " + target.getName()); performer.getCommunicator().sendNormalServerMessage("You begin recharging the " + target.getName());
final int time = 15000; final int time = 150;
performer.getCurrentAction().setTimeLeft(time); performer.getCurrentAction().setTimeLeft(time);
performer.sendActionControl("Recharging...", true, time); performer.sendActionControl("Recharging...", true, time);
} }

View File

@@ -0,0 +1,4 @@
package mod.sin.actions.items;
public class PermafrostTemperatureAction {
}

View File

@@ -0,0 +1,115 @@
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.NoSuchActionException;
import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.items.ItemTemplateFactory;
import com.wurmonline.server.players.Player;
import mod.sin.wyvern.schematics.SchematicWrapper;
import mod.sin.wyvern.schematics.Schematics;
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.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ReadSchematicAction implements ModAction, BehaviourProvider, ActionPerformer {
private static Logger logger = Logger.getLogger(ReadSchematicAction.class.getName());
private final short actionId;
private final ActionEntry actionEntry;
public ReadSchematicAction() {
logger.log(Level.WARNING, "ReadSchematicAction()");
actionId = (short) ModActions.getNextActionId();
actionEntry = ActionEntry.createEntry(
actionId,
"Read schematic",
"reading",
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)
{
return this.getBehavioursFor(performer, object);
}
// Menu without activated object
@Override
public List<ActionEntry> getBehavioursFor(Creature performer, Item object)
{
if(performer instanceof Player && object != null && Schematics.isASchematic(object)) {
return Collections.singletonList(actionEntry);
}
return null;
}
@Override
public boolean action(Action act, Creature performer, Item source, Item target, short action, float counter)
{
return this.action(act, performer, target, action, counter);
}
@Override
public boolean action(Action act, Creature performer, Item target, short action, float counter) {
try {
SchematicWrapper wrapper = Schematics.getSchematicWrapper(target.getTemplateId());
if(!Schematics.isASchematic(target) || wrapper == null) {
performer.getCommunicator().sendNormalServerMessage("You cannot read that right now.");
return true;
}
if(counter == 1.0f) {
if(Schematics.playerKnowsSchematic(performer, wrapper.product)) {
performer.getCommunicator().sendNormalServerMessage("You already know how to make that item.");
return true;
}
performer.getCommunicator().sendNormalServerMessage("You begin reading the schematic...");
Server.getInstance().broadCastAction(performer.getName() + " begins reading a schematic.", performer, 5);
final int time = 150;
performer.getCurrentAction().setTimeLeft(time);
performer.sendActionControl("Reading schematic", true, time);
}
else {
int time = performer.getCurrentAction().getTimeLeft();
if (counter * 10.0f > time) {
Items.destroyItem(target.getWurmId());
Schematics.learnSchematic(wrapper.product, performer.getName());
performer.getCommunicator().sendNormalServerMessage("You learn the schematic for " + ItemTemplateFactory.getInstance().getTemplateName(wrapper.product) + "!");
logger.info(performer.getName() + " learned the schematic for " + ItemTemplateFactory.getInstance().getTemplateName(wrapper.product));
return true;
}
}
return false;
} catch (NoSuchActionException e) {
e.printStackTrace();
return true;
} catch (SQLException e) {
performer.getCommunicator().sendNormalServerMessage("Something went wrong. Alert a GM as soon as possible.");
logger.info("SQL Error with schematic");
e.printStackTrace();
return true;
}
}
@Override
public short getActionId() {
return actionId;
}
}

View File

@@ -62,14 +62,15 @@ public class Gremlin implements ModCreature, CreatureTypes {
@Override @Override
public void addEncounters() { public void addEncounters() {
if (templateId == 0 ) { if (templateId == 0 ) {
return; return;
} }
// enable encounters when ready for event
new EncounterBuilder(Tiles.Tile.TILE_TREE.id)
/** new EncounterBuilder(Tiles.Tile.TILE_TREE.id)
.addCreatures(templateId, 5) .addCreatures(templateId, 5)
.build(1); .build(1);**/
} }
} }

View File

@@ -21,7 +21,8 @@ public class CrystalPermaFrost implements MiscConstants, ItemTypes {
ItemTypes.ITEM_TYPE_MAGIC, ItemTypes.ITEM_TYPE_MAGIC,
ItemTypes.ITEM_TYPE_FULLPRICE, ItemTypes.ITEM_TYPE_FULLPRICE,
ItemTypes.ITEM_TYPE_NOSELLBACK, ItemTypes.ITEM_TYPE_NOSELLBACK,
ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE,
ItemTypes.ITEM_TYPE_NO_IMPROVE
}); });
itemBuilder.imageNumber((short) 859); itemBuilder.imageNumber((short) 859);
itemBuilder.behaviourType((short) 1); itemBuilder.behaviourType((short) 1);
@@ -31,7 +32,7 @@ public class CrystalPermaFrost implements MiscConstants, ItemTypes {
itemBuilder.primarySkill((int) NOID); itemBuilder.primarySkill((int) NOID);
itemBuilder.bodySpaces(EMPTY_BYTE_PRIMITIVE_ARRAY); itemBuilder.bodySpaces(EMPTY_BYTE_PRIMITIVE_ARRAY);
itemBuilder.modelName("model.valrei."); itemBuilder.modelName("model.valrei.");
itemBuilder.difficulty(5.0f); itemBuilder.difficulty(50.0f);
itemBuilder.weightGrams(2000); itemBuilder.weightGrams(2000);
itemBuilder.material(Materials.MATERIAL_CRYSTAL); itemBuilder.material(Materials.MATERIAL_CRYSTAL);
itemBuilder.value(0); itemBuilder.value(0);

View File

@@ -22,7 +22,8 @@ public class HolidaySpirit implements ItemTypes, MiscConstants {
ItemTypes.ITEM_TYPE_MAGIC, ItemTypes.ITEM_TYPE_MAGIC,
ItemTypes.ITEM_TYPE_FULLPRICE, ItemTypes.ITEM_TYPE_FULLPRICE,
ItemTypes.ITEM_TYPE_NOSELLBACK, ItemTypes.ITEM_TYPE_NOSELLBACK,
ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE,
ItemTypes.ITEM_TYPE_NO_IMPROVE
}); });
itemBuilder.imageNumber((short) 859); itemBuilder.imageNumber((short) 859);
itemBuilder.behaviourType((short) 1); itemBuilder.behaviourType((short) 1);

View File

@@ -3,6 +3,8 @@ package mod.sin.items;
import com.wurmonline.server.MiscConstants; import com.wurmonline.server.MiscConstants;
import com.wurmonline.server.items.*; import com.wurmonline.server.items.*;
import com.wurmonline.server.skills.SkillList; import com.wurmonline.server.skills.SkillList;
import mod.sin.wyvern.schematics.SchematicWrapper;
import mod.sin.wyvern.schematics.Schematics;
import org.gotti.wurmunlimited.modsupport.ItemTemplateBuilder; import org.gotti.wurmunlimited.modsupport.ItemTemplateBuilder;
import java.io.IOException; import java.io.IOException;
@@ -23,21 +25,22 @@ public class WandPermaFrost implements MiscConstants {
ItemTypes.ITEM_TYPE_NOSELLBACK, ItemTypes.ITEM_TYPE_NOSELLBACK,
ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE
}); });
itemBuilder.imageNumber((short) 859); itemBuilder.imageNumber((short) 400);
itemBuilder.behaviourType((short) 1); itemBuilder.behaviourType((short) 1);
itemBuilder.combatDamage(0); itemBuilder.combatDamage(0);
itemBuilder.decayTime(Long.MAX_VALUE); itemBuilder.decayTime(Long.MAX_VALUE);
itemBuilder.dimensions(1, 1, 1); itemBuilder.dimensions(1, 1, 1);
itemBuilder.primarySkill((int) NOID); itemBuilder.primarySkill((int) NOID);
itemBuilder.bodySpaces(EMPTY_BYTE_PRIMITIVE_ARRAY); itemBuilder.bodySpaces(EMPTY_BYTE_PRIMITIVE_ARRAY);
itemBuilder.modelName("model.valrei."); itemBuilder.modelName("model.magic.wand.nature.");
itemBuilder.difficulty(5.0f); itemBuilder.difficulty(70.0f);
itemBuilder.weightGrams(3000); itemBuilder.weightGrams(3000);
itemBuilder.material(Materials.MATERIAL_CRYSTAL); itemBuilder.material(Materials.MATERIAL_CRYSTAL);
itemBuilder.value(0); itemBuilder.value(0);
ItemTemplate template = itemBuilder.build(); ItemTemplate template = itemBuilder.build();
templateId = template.getTemplateId(); templateId = template.getTemplateId();
Schematics.schematics.add(new SchematicWrapper(templateId, 0, false, 0, 0));
logger.info(name + " TemplateID: " + templateId); logger.info(name + " TemplateID: " + templateId);
} }

View File

@@ -0,0 +1,49 @@
package mod.sin.items.schematicitems;
import com.wurmonline.server.MiscConstants;
import com.wurmonline.server.items.ItemTemplate;
import com.wurmonline.server.items.ItemTemplateFactory;
import com.wurmonline.server.items.ItemTypes;
import com.wurmonline.server.items.Materials;
import mod.sin.wyvern.schematics.SchematicWrapper;
import mod.sin.wyvern.schematics.Schematics;
import org.gotti.wurmunlimited.modsupport.ItemTemplateBuilder;
import java.io.IOException;
import java.util.logging.Logger;
public class SchematicItems implements ItemTypes, MiscConstants {
public static Logger logger = Logger.getLogger(SchematicItems.class.getName());
public static int templateId;
public void createTemplate() throws IOException {
for(SchematicWrapper wrapper : Schematics.schematics) {
String productName = ItemTemplateFactory.getInstance().getTemplateName(wrapper.product);
String name = "schematic for " + productName;
ItemTemplateBuilder itemBuilder = new ItemTemplateBuilder("mod.item.schematic." + productName);
itemBuilder.name(name, "schematics for " + productName, "A schematic. Looks like it might create a " + productName);
itemBuilder.itemTypes(new short[]{
ItemTypes.ITEM_TYPE_FULLPRICE,
ItemTypes.ITEM_TYPE_NOSELLBACK,
ItemTypes.ITEM_TYPE_ALWAYS_BANKABLE
});
itemBuilder.imageNumber((short) 640);
itemBuilder.behaviourType((short) 1);
itemBuilder.combatDamage(0);
itemBuilder.decayTime(Long.MAX_VALUE);
itemBuilder.dimensions(1, 1, 1);
itemBuilder.primarySkill((int) NOID);
itemBuilder.bodySpaces(EMPTY_BYTE_PRIMITIVE_ARRAY);
itemBuilder.modelName("model.resource.sheet.papyrus.");
itemBuilder.difficulty(5.0f);
itemBuilder.weightGrams(100);
itemBuilder.material(Materials.MATERIAL_PAPER);
itemBuilder.value(0);
ItemTemplate template = itemBuilder.build();
templateId = template.getTemplateId();
logger.info(name + " TemplateID: " + templateId);
wrapper.schematicTemplateId = templateId;
}
}
}

View File

@@ -11,6 +11,8 @@ import java.util.logging.Logger;
import com.wurmonline.server.Servers; import com.wurmonline.server.Servers;
import com.wurmonline.server.behaviours.Action; import com.wurmonline.server.behaviours.Action;
import com.wurmonline.server.combat.ArmourTemplate;
import mod.sin.items.schematicitems.SchematicItems;
import mod.sin.lib.Util; import mod.sin.lib.Util;
import mod.sin.items.caches.*; import mod.sin.items.caches.*;
import org.gotti.wurmunlimited.modloader.ReflectionUtil; import org.gotti.wurmunlimited.modloader.ReflectionUtil;
@@ -111,6 +113,7 @@ public class ItemMod {
public static HolidaySpirit HOLIDAY_SPIRIT = new HolidaySpirit(); public static HolidaySpirit HOLIDAY_SPIRIT = new HolidaySpirit();
public static WandPermaFrost WAND_PERMA_FROST = new WandPermaFrost(); public static WandPermaFrost WAND_PERMA_FROST = new WandPermaFrost();
public static CrystalPermaFrost CRYSTAL_PERMA_FROST = new CrystalPermaFrost(); public static CrystalPermaFrost CRYSTAL_PERMA_FROST = new CrystalPermaFrost();
public static SchematicItems SCHEMATIC_ITEMS = new SchematicItems();
public static void createItems(){ public static void createItems(){
logger.info("createItems()"); logger.info("createItems()");
@@ -154,6 +157,9 @@ public class ItemMod {
CRYSTAL_PERMA_FROST.createTemplate(); CRYSTAL_PERMA_FROST.createTemplate();
WAND_PERMA_FROST.createTemplate(); WAND_PERMA_FROST.createTemplate();
// This must come after any schematic based items have already been created.
SCHEMATIC_ITEMS.createTemplate();
// Arena Fragments // Arena Fragments
KEY_FRAGMENT.createTemplate(); KEY_FRAGMENT.createTemplate();
@@ -214,6 +220,7 @@ public class ItemMod {
ModActions.registerAction(new StableContractAction()); ModActions.registerAction(new StableContractAction());
ModActions.registerAction(new WoodEssenceAction()); ModActions.registerAction(new WoodEssenceAction());
ModActions.registerAction(new ItemBonusRechargeAction()); ModActions.registerAction(new ItemBonusRechargeAction());
ModActions.registerAction(new ReadSchematicAction());
} }
public static void initCreationEntries(){ public static void initCreationEntries(){
@@ -285,7 +292,7 @@ public class ItemMod {
logger.info("Beginning custom armour creation."); logger.info("Beginning custom armour creation.");
Map<Integer, Armour> armours = ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(Armour.class, "armours")); Map<Integer, Armour> armours = ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(Armour.class, "armours"));
armours.put(SpectralBoot.templateId, new ArmourTemplate(SpectralBoot.templateId, ArmourTemplate.ARMOUR_TYPE_LEATHER_DRAGON, 0.3f)); armours.put(SpectralBoot.templateId, new ArmourTemplate(SpectralBoot.templateId, ArmourTemplate.ARMOUR_TYPE_LEATHER_DRAGON., 0.3f));
armours.put(SpectralCap.templateId, new Armour(SpectralCap.templateId, 0.003f, 0.3f)); armours.put(SpectralCap.templateId, new Armour(SpectralCap.templateId, 0.003f, 0.3f));
armours.put(SpectralGlove.templateId, new Armour(SpectralGlove.templateId, 0.002f, 0.3f)); armours.put(SpectralGlove.templateId, new Armour(SpectralGlove.templateId, 0.002f, 0.3f));
armours.put(SpectralHose.templateId, new Armour(SpectralHose.templateId, 0.0075f, 0.3f)); armours.put(SpectralHose.templateId, new Armour(SpectralHose.templateId, 0.0075f, 0.3f));

View File

@@ -266,6 +266,8 @@ implements WurmServerMod, Configurable, PreInitable, Initable, ItemTemplatesCrea
} catch (NoSuchTemplateException e) { } catch (NoSuchTemplateException e) {
throw new HookException(e); throw new HookException(e);
} }
logger.info("Registering schematics...");
Schematics.initSchematicList();
try { try {
logger.info("Editing existing item templates."); logger.info("Editing existing item templates.");
ItemMod.modifyItems(); ItemMod.modifyItems();

View File

@@ -0,0 +1,17 @@
package mod.sin.wyvern.schematics;
public class SchematicWrapper {
public int product;
public int schematicTemplateId;
public boolean isSkillRequired;
public int primarySkill;
public int requiredSkillLevel;
public SchematicWrapper(int product, int schematicTemplateId, boolean isSkillRequired, int primarySkill, int requiredSkillLevel) {
this.product = product;
this.schematicTemplateId = schematicTemplateId;
this.isSkillRequired = isSkillRequired;
this.primarySkill = primarySkill;
this.requiredSkillLevel = requiredSkillLevel;
}
}

View File

@@ -2,6 +2,8 @@ package mod.sin.wyvern.schematics;
import com.wurmonline.server.creatures.Creature; import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.items.CreationEntry; import com.wurmonline.server.items.CreationEntry;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.items.ItemTemplateFactory;
import javassist.ClassPool; import javassist.ClassPool;
import javassist.CtClass; import javassist.CtClass;
import javassist.NotFoundException; import javassist.NotFoundException;
@@ -15,13 +17,13 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Logger;
public class Schematics { public class Schematics {
private static ArrayList<Integer> schematics = new ArrayList<>(); public static ArrayList<SchematicWrapper> schematics = new ArrayList<>();
private static Logger logger = Logger.getLogger(Schematics.class.getName());
public static void preInit() { public static void preInit() {
initSchematicList();
try { try {
Util.setReason("Overriding difficulty check to check for creationentry requirements"); Util.setReason("Overriding difficulty check to check for creationentry requirements");
ClassPool classPool = HookManager.getInstance().getClassPool(); ClassPool classPool = HookManager.getInstance().getClassPool();
@@ -29,9 +31,9 @@ public class Schematics {
String replace; String replace;
CtClass ctCreationEntry = classPool.get("com.wurmonline.server.items.CreationEntry"); CtClass ctCreationEntry = classPool.get("com.wurmonline.server.items.CreationEntry");
replace = "boolean hasSchematic = " + Schematics.class.getName() + "checkSchematic($3, $0);" + replace = "boolean hasSchematic = " + Schematics.class.getName() + ".checkSchematic($3, $0);" +
"if(!hasSchematic) {" + "if(!hasSchematic) {" +
"return 0.0f" + "return 0.0f;" +
"}"; "}";
Util.insertBeforeDeclared(thisClass, ctCreationEntry, "getDifficultyFor", replace); Util.insertBeforeDeclared(thisClass, ctCreationEntry, "getDifficultyFor", replace);
} catch (NotFoundException e) { } catch (NotFoundException e) {
@@ -39,9 +41,12 @@ public class Schematics {
} }
} }
private static void initSchematicList() { public static void initSchematicList() {
// Add items to schematic list here. These items will require the player to have read a schematic before // Moved this. Items should be added to schematics in the file definition, after acquiring a templateid.
schematics.add(WandPermaFrost.templateId); for(SchematicWrapper i : schematics) {
logger.info("Schematic registered for " + i.product + ItemTemplateFactory.getInstance().getTemplateName(i.product));
}
} }
/** /**
@@ -52,22 +57,94 @@ public class Schematics {
*/ */
public static boolean checkSchematic(Creature performer, CreationEntry ce) { public static boolean checkSchematic(Creature performer, CreationEntry ce) {
int product = ce.getObjectCreated(); int product = ce.getObjectCreated();
if(schematics.contains(product)) { return checkSchematic(performer, product);
try { }
Connection dbcon = ModSupportDb.getModSupportDb();
PreparedStatement ps = dbcon.prepareStatement("SELECT * FROM SchematicMap"); public static boolean checkSchematic(Creature performer, int product) {
ResultSet rs = ps.executeQuery(); if(requiresASchematic(product)) {
while (rs.next()) { if(!playerKnowsSchematic(performer, product)) {
if (rs.getString("name").equals(performer.getName()) && rs.getInt("templateid") == product) { performer.getCommunicator().sendNormalServerMessage("You don't know how to make that. Try finding a schematic for the item.");
return true; logger.info("Player " + performer.getName() + " does not have schematic for " + ItemTemplateFactory.getInstance().getTemplateName(product));
} return false;
}
} catch (SQLException e) {
throw new RuntimeException(e);
} }
return false;
} }
return true; return true;
} }
public static boolean playerKnowsSchematic(Creature performer, int product) {
try {
Connection dbcon = ModSupportDb.getModSupportDb();
PreparedStatement ps = dbcon.prepareStatement("SELECT * FROM SchematicMap");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
if (rs.getString("name").equals(performer.getName()) && rs.getInt("templateid") == product) {
logger.info("Player " + performer.getName() + " has schematic for " + ItemTemplateFactory.getInstance().getTemplateName(product));
return true;
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return false;
}
/**
* Makes a player learn a schematic
* @param templateid schematic product
* @param name performer name
* @return if the schematic was learned
*/
public static boolean learnSchematic(int templateid, String name) throws SQLException {
try {
Connection dbcon = ModSupportDb.getModSupportDb();
PreparedStatement ps = dbcon.prepareStatement("SELECT * FROM SchematicMap");
ResultSet rs = ps.executeQuery();
while(rs.next()) {
if(rs.getString("name").equals(name) && rs.getInt("templateid") == templateid) {
return false;
}
}
ps = dbcon.prepareStatement("INSERT INTO SchematicMap(name, templateid) VALUES(?, ?)");
ps.setString(1, name);
ps.setInt(2, templateid);
ps.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
logger.info("ERROR: Failed to add schematic " + templateid + " to " + name + ".");
throw e;
}
}
public static boolean requiresASchematic(int templateId) {
return getSchematicFor(templateId) != null;
}
public static boolean isASchematic(Item item) {
for(SchematicWrapper wrapper : schematics) {
if(wrapper.schematicTemplateId == item.getTemplateId()) {
return true;
}
}
return false;
}
public static SchematicWrapper getSchematicFor(int product) {
for(SchematicWrapper wrapper : schematics) {
if(wrapper.product == product) {
return wrapper;
}
}
return null;
}
public static SchematicWrapper getSchematicWrapper(int schematicId) {
for(SchematicWrapper wrapper : schematics) {
if(wrapper.schematicTemplateId == schematicId) {
return wrapper;
}
}
return null;
}
} }