diff --git a/scripts/equipment/slot_protection.py b/scripts/equipment/slot_protection.py index 3e16a86c..e6de1f33 100644 --- a/scripts/equipment/slot_protection.py +++ b/scripts/equipment/slot_protection.py @@ -1,7 +1,7 @@ import sys def chest2(): - return "35.71" + return "35.70" def pants1(): return "21.43" diff --git a/scripts/expertise/expertise_me_agility_1.py b/scripts/expertise/expertise_me_agility_1.py index 29ea50ff..30d90811 100644 --- a/scripts/expertise/expertise_me_agility_1.py +++ b/scripts/expertise/expertise_me_agility_1.py @@ -1,48 +1,7 @@ import sys -def addExpertisePoint(core, actor): - - player = actor.getSlottedObject('ghost') - - if not player: - return - - if not player.getProfession() == 'medic_1a': - return - - actor.addSkill('expertise_me_agility_1') - - actor.addSkillMod('agility_modified', 25) - - addAbilities(core, actor, player) - - return - -def removeExpertisePoint(core, actor): - - player = actor.getSlottedObject('ghost') - - if not player: - return - - if not player.getProfession() == 'medic_1a': - return - - actor.removeSkill('expertise_me_agility_1') - - actor.removeSkillMod('agility_modified', 25) - - removeAbilities(core, actor, player) - - return - -# this checks what abilities the player gets by level, need to also call this on level-up def addAbilities(core, actor, player): - - return def removeAbilities(core, actor, player): - - return diff --git a/scripts/expertise/expertise_me_enhance_agility_1.py b/scripts/expertise/expertise_me_enhance_agility_1.py index fd112eb9..bf7958db 100644 --- a/scripts/expertise/expertise_me_enhance_agility_1.py +++ b/scripts/expertise/expertise_me_enhance_agility_1.py @@ -1,48 +1,14 @@ import sys -def addExpertisePoint(core, actor): - - player = actor.getSlottedObject('ghost') - - if not player: - return - - if not player.getProfession() == 'medic_1a': - return - - actor.addSkill('expertise_me_enhance_agility_1') - - - addAbilities(core, actor, player) - - return - -def removeExpertisePoint(core, actor): - - player = actor.getSlottedObject('ghost') - - if not player: - return - - if not player.getProfession() == 'medic_1a': - return - - actor.removeSkill('expertise_me_enhance_agility_1') - - - removeAbilities(core, actor, player) - - return - -# this checks what abilities the player gets by level, need to also call this on level-up def addAbilities(core, actor, player): - - actor.addAbility('me_enhance_agility_1') - + if actor.getLevel() >= 10: + actor.addAbility("me_enhance_agility_1") + if actor.getLevel() >= 34: + actor.addAbility("me_enhance_agility_2") + if actor.getLevel() >= 62: + actor.addAbility("me_enhance_agility_3") return def removeAbilities(core, actor, player): - - actor.removeAbility('me_enhance_agility_1') - + actor.removeAbility("me_enhance_agility_1") return diff --git a/src/resources/objects/SWGMap.java b/src/resources/objects/SWGMap.java index 0227a725..923ccff4 100644 --- a/src/resources/objects/SWGMap.java +++ b/src/resources/objects/SWGMap.java @@ -119,13 +119,17 @@ public class SWGMap implements Map { if (map.containsKey(key)) { V oldValue = map.put(key, value); - queue(item(2, (String) key, ((IDelta) value).getBytes(), true, true)); + if (oldValue != null) { + queue(item(2, (String) key, ((IDelta) value).getBytes(), true, true)); + } return oldValue; } else { V oldValue = map.put(key, value); - queue(item(0, (String) key, ((IDelta) value).getBytes(), true, true)); + if (oldValue != null) { + queue(item(0, (String) key, ((IDelta) value).getBytes(), true, true)); + } return oldValue; } @@ -170,7 +174,9 @@ public class SWGMap implements Map { key instanceof Integer || key instanceof Float || key instanceof Long) { V value = map.remove(key); - queue(item(1, key, ((IDelta) map.get(key)).getBytes(), true, true)); + if (value != null) { + queue(item(1, key, ((IDelta) map.get(key)).getBytes(), true, true)); + } return value; } @@ -230,6 +236,7 @@ public class SWGMap implements Map { } } if (useData) buffer.put(data); + buffer.flip(); updateCounter++; @@ -241,6 +248,7 @@ public class SWGMap implements Map { buffer.putInt(1); buffer.putInt(updateCounter); buffer.put(data); + buffer.flip(); messageBuilder.sendListDelta(viewType, updateType, buffer); } @@ -255,6 +263,7 @@ public class SWGMap implements Map { buffer.putInt(data.size()); buffer.putInt(updateCounter); for (byte[] queued : data) buffer.put(queued); + buffer.flip(); messageBuilder.sendListDelta(viewType, updateType, buffer); } diff --git a/src/resources/objects/SkillMod.java b/src/resources/objects/SkillMod.java index d155b882..a9550ce4 100644 --- a/src/resources/objects/SkillMod.java +++ b/src/resources/objects/SkillMod.java @@ -67,12 +67,9 @@ public class SkillMod extends Delta { @Override public byte[] getBytes() { - IoBuffer buffer = createBuffer(name.length() + 10); - - buffer.put(getAsciiString(name)); + IoBuffer buffer = createBuffer(8); buffer.putInt(base); buffer.putInt((int) modifier); - return buffer.array(); } diff --git a/src/resources/objects/creature/CreatureMessageBuilder.java b/src/resources/objects/creature/CreatureMessageBuilder.java index 8b96fced..23b6ed4f 100644 --- a/src/resources/objects/creature/CreatureMessageBuilder.java +++ b/src/resources/objects/creature/CreatureMessageBuilder.java @@ -157,20 +157,14 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { buffer.putInt(0); // HAM Encumberance List unused in NGE buffer.putInt(0); - if(creature.getSkillMods().isEmpty()) { - buffer.putInt(0); - buffer.putInt(0); - } else { - buffer.putInt(creature.getSkillMods().size()); - buffer.putInt(creature.getSkillMods().getUpdateCounter()); - - for(SkillMod skillMod : creature.getSkillMods()) { - buffer.put((byte) 0); - buffer.put(getAsciiString(skillMod.getName())); - buffer.putInt(skillMod.getBase()); - buffer.putInt((int) skillMod.getModifier()); - } + buffer.putInt(creature.getSkillMods().size()); + buffer.putInt(creature.getSkillMods().getUpdateCounter()); + for (SkillMod skillMod : creature.getSkillMods().values()) { + buffer.put((byte) 0); + buffer.put(getAsciiString(skillMod.getName())); + buffer.put(skillMod.getBytes()); } + buffer.putFloat(creature.getSpeedMultiplierBase()); buffer.putFloat(creature.getSpeedMultiplierMod()); @@ -850,46 +844,6 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { } - public IoBuffer buildAddSkillModDelta(String name, int base) { - - CreatureObject creature = (CreatureObject) object; - - IoBuffer buffer = bufferPool.allocate(19 + name.length(), false).order(ByteOrder.LITTLE_ENDIAN); - buffer.putInt(1); - buffer.putInt(creature.getSkillModsUpdateCounter()); - buffer.put((byte) 0); - buffer.put(getAsciiString(name)); - buffer.putInt(base); - buffer.putInt(0); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("CREO", (byte) 4, (short) 1, (short) 3, buffer, size + 4); - - return buffer; - - } - - public IoBuffer buildRemoveSkillModDelta(String name, int base) { - - CreatureObject creature = (CreatureObject) object; - - IoBuffer buffer = bufferPool.allocate(19 + name.length(), false).order(ByteOrder.LITTLE_ENDIAN); - buffer.putInt(1); - buffer.putInt(creature.getSkillModsUpdateCounter()); - buffer.put((byte) 1); - buffer.put(getAsciiString(name)); - buffer.putInt(base); - buffer.putInt(0); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("CREO", (byte) 4, (short) 1, (short) 3, buffer, size + 4); - - return buffer; - - } - public IoBuffer buildAddSkillDelta(String name) { CreatureObject creature = (CreatureObject) object; @@ -1226,7 +1180,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { buffer = createDelta("CREO", (byte) 4, (short) 1, (byte) 3, buffer.flip(), buffer.array().length + 4); if (object.getClient() != null && object.getClient().getSession() != null) { - //object.getClient().getSession().write(buffer); + object.getClient().getSession().write(buffer); } break; } diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 5a26a8bf..40f7d8f0 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -49,6 +49,7 @@ import engine.clients.Client; import resources.objects.Buff; import resources.objects.DamageOverTime; import resources.objects.SWGList; +import resources.objects.SWGMap; import resources.objects.SkillMod; import engine.resources.objects.IPersistent; import engine.resources.objects.MissionCriticalObject; @@ -59,7 +60,7 @@ import engine.resources.scene.Quaternion; import resources.objects.tangible.TangibleObject; import resources.objects.weapon.WeaponObject; -@Entity(version=4) +@Entity(version=5) public class CreatureObject extends TangibleObject implements IPersistent { @NotPersistent @@ -83,9 +84,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { // CREO 4 private float accelerationMultiplierBase = 1; private float accelerationMultiplierMod = 1; - private SWGList skillMods; - @NotPersistent - private int skillModsUpdateCounter = 0; + private SWGMap skillMods; private float speedMultiplierBase = 1; private float speedMultiplierMod = 1; private float runSpeed = (float) 7.3; @@ -184,7 +183,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { messageBuilder = new CreatureMessageBuilder(this); loadTemplateData(); skills = new SWGList(messageBuilder, 1, 3); - skillMods = new SWGList(messageBuilder, 4, 3); + skillMods = new SWGMap(messageBuilder, 4, 3); abilities = new SWGList(messageBuilder, 4, 14); missionCriticalObjects = new SWGList(messageBuilder, 4, 13); equipmentList = new SWGList(messageBuilder, 6, 0x17); @@ -559,20 +558,13 @@ public class CreatureObject extends TangibleObject implements IPersistent { this.accelerationMultiplierMod = accelerationMultiplierMod; } } - - public SWGList getSkillMods() { + + public SWGMap getSkillMods() { return skillMods; } public SkillMod getSkillMod(String name) { - synchronized(skillMods.getMutex()) { - for(SkillMod skillMod : skillMods.get()) { - if(skillMod.getName().equals(name)) - return skillMod; - } - } - - return null; + return skillMods.get(name); } public int getSkillModBase(String name) { @@ -581,66 +573,41 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void addSkillMod(String name, int base) { - if(getSkillMod(name) == null) { - // TODO: Send skill mods delta in sendListDelta - SkillMod skillMod = new SkillMod(); - skillMod.setBase(base); - skillMod.setName(name); - skillMod.setModifier(0); - skillMods.add(skillMod); + SkillMod mod; + + if (getSkillMod(name) == null) { + mod = new SkillMod(); + mod.setBase(base); + mod.setName(name); + mod.setModifier(0); } else { - - SkillMod mod = getSkillMod(name); + mod = getSkillMod(name); mod.setBase(mod.getBase() + base); - - if(getClient() != null) { - setSkillModsUpdateCounter((short) (getSkillModsUpdateCounter() + 1)); - getClient().getSession().write(messageBuilder.buildAddSkillModDelta(name, mod.getBase())); - } } + skillMods.put(name, mod); } public void deductSkillMod(String name, int base) { - - if(getSkillMod(name) == null) + if (getSkillMod(name) == null) { return; + } SkillMod mod = getSkillMod(name); mod.setBase(mod.getBase() - base); - if(mod.getBase() <= 0) { + if (mod.getBase() <= 0) { removeSkillMod(mod); } else { - skillMods.set(skillMods.indexOf(mod), mod); - if(getClient() != null) { - setSkillModsUpdateCounter((short) (getSkillModsUpdateCounter() + 1)); - getClient().getSession().write(messageBuilder.buildAddSkillModDelta(name, mod.getBase())); - } - } - } - - public void removeSkillMod(SkillMod mod) { - skillMods.remove(mod); - - if(getClient() != null) { - setSkillModsUpdateCounter((short) (getSkillModsUpdateCounter() + 1)); - getClient().getSession().write(messageBuilder.buildRemoveSkillModDelta(mod.getName(), mod.getBase())); - } - } - - public short getSkillModsUpdateCounter() { - synchronized(objectMutex) { - return (short) skillModsUpdateCounter; + skillMods.put(name, mod); } } - public void setSkillModsUpdateCounter(short skillModsUpdateCounter) { - synchronized(objectMutex) { - this.skillModsUpdateCounter = skillModsUpdateCounter; + public void removeSkillMod(SkillMod mod) { + if (mod != null) { + skillMods.remove(mod); } } - public float getSpeedMultiplierBase() { synchronized(objectMutex) { diff --git a/src/services/DevService.java b/src/services/DevService.java index 102e6155..efe65147 100644 --- a/src/services/DevService.java +++ b/src/services/DevService.java @@ -80,11 +80,10 @@ public class DevService implements INetworkDispatch { suiOptions.put((long) 12, "Reset expertise"); break; case 2: // Items - suiOptions.put((long) 20, "(Light) Jedi Robe"); - suiOptions.put((long) 21, "(Dark) Jedi Robe"); - suiOptions.put((long) 22, "Armor"); - suiOptions.put((long) 23, "Weapons"); - suiOptions.put((long) 24, "Misc Items"); + suiOptions.put((long) 20, "Armor"); + suiOptions.put((long) 21, "Weapons"); + suiOptions.put((long) 22, "Misc Items"); + suiOptions.put((long) 23, "Jedi Items"); break; case 3: // [Items] Weapons suiOptions.put((long) 30, "Jedi Weapons"); @@ -115,6 +114,11 @@ public class DevService implements INetworkDispatch { suiOptions.put((long) 81, "Ithorian Guardian"); suiOptions.put((long) 82, "Kashyyykian Ceremonial"); break; + case 9: // [Items] Jedi Items + suiOptions.put((long) 90, "(Light) Jedi Robe"); + suiOptions.put((long) 91, "(Dark) Jedi Robe"); + suiOptions.put((long) 92, "Belt of Master Bodo Baas"); + break; } final SUIWindow window = core.suiService.createListBox(ListBoxType.LIST_BOX_OK_CANCEL, "Character Builder Terminal", "Select the desired option and click OK.", suiOptions, creature, null, 10); @@ -164,22 +168,19 @@ public class DevService implements INetworkDispatch { return; // Items - case 20: // (Light) Jedi Robe - inventory.add(core.objectService.createObject("object/tangible/wearables/robe/shared_robe_jedi_light_s03.iff", planet)); - return; - case 21: // (Dark) Jedi Robe - inventory.add(core.objectService.createObject("object/tangible/wearables/robe/shared_robe_jedi_dark_s03.iff", planet)); - return; - case 22: // Armor + case 20: // Armor sendCharacterBuilderSUI(player, 5); return; - case 23: // Weapons + case 21: // Weapons sendCharacterBuilderSUI(player, 3); return; - - case 24: // Misc Items + case 22: // Misc Items sendCharacterBuilderSUI(player, 4); return; + case 23: // Jedi Items + sendCharacterBuilderSUI(player, 9); + return; + // [Items] Weapons case 30: // Jedi Weapons TangibleObject lightsaber1 = (TangibleObject) core.objectService.createObject("object/weapon/melee/sword/crafted_saber/shared_sword_lightsaber_one_handed_gen5.iff", planet); @@ -889,6 +890,16 @@ public class DevService implements INetworkDispatch { inventory.add(cer_chest); return; + + case 90: // (Light) Jedi Robe + inventory.add(core.objectService.createObject("object/tangible/wearables/robe/shared_robe_jedi_light_s03.iff", planet)); + return; + case 91: // (Dark) Jedi Robe + inventory.add(core.objectService.createObject("object/tangible/wearables/robe/shared_robe_jedi_dark_s03.iff", planet)); + return; + case 92: // Belt of Master Bodo Baas + inventory.add(core.objectService.createObject("object/tangible/wearables/backpack/shared_fannypack_s01.iff", planet)); + return; } } }); diff --git a/src/services/EquipmentService.java b/src/services/EquipmentService.java index bcd0a519..1f5c9348 100644 --- a/src/services/EquipmentService.java +++ b/src/services/EquipmentService.java @@ -45,6 +45,7 @@ import engine.resources.objects.SWGObject; import engine.resources.service.INetworkDispatch; import engine.resources.service.INetworkRemoteEvent; import resources.objects.player.PlayerObject; +import resources.objects.tangible.TangibleObject; import services.equipment.BonusSetTemplate; import services.spawn.MobileTemplate; @@ -83,33 +84,6 @@ public class EquipmentService implements INetworkDispatch { return weaponCriticalChance; } - private void addWeaponCriticalChance(CreatureObject actor, SWGObject item) { - actor.addSkillMod("display_only_critical", getWeaponCriticalChance(actor, item)); - } - - private void deductWeaponCriticalChance(CreatureObject actor, SWGObject item) { - actor.deductSkillMod("display_only_critical", getWeaponCriticalChance(actor, item)); - } - - public String getFormalProfessionName(String stfName) { - String formalName = ""; - - switch (stfName) { - case "force_sensitive_1a": formalName = "Jedi"; break; - case "bounty_hunter_1a": formalName = "Bounty Hunter"; break; - case "officer_1a": formalName = "Officer"; break; - case "smuggler_1a": formalName = "Smuggler"; break; - case "entertainer_1a": formalName = "Entertainer"; break; - case "spy_1a": formalName = "Spy"; break; - case "medic_1a": formalName = "Medic"; break; - case "commando_1a": formalName = "Commando"; break; - - default: formalName = "Trader"; break; // Ziggy: Trader profession names are a bit irregular, so this is used. - - } - return formalName; - } - public boolean canEquip(CreatureObject actor, SWGObject item) { boolean result = true; @@ -117,14 +91,14 @@ public class EquipmentService implements INetworkDispatch { return false; if (item.getAttributes().toString().contains("cat_armor")) - if (actor.getLevel() >= 22) - result = true; - else - return false; + { + if (actor.hasAbility("wear_all_armor")) result = true; // Change to "wear_all_armor" ability instead of lvl 22 + else return false; + } if (item.getStringAttribute("class_required") != null) { String profession = ((PlayerObject) actor.getSlottedObject("ghost")).getProfession(); - if (item.getStringAttribute("class_required").contentEquals(getFormalProfessionName(profession)) || item.getStringAttribute("class_required").contentEquals("None")) + if (item.getStringAttribute("class_required").contentEquals(core.playerService.getFormalProfessionName(profession)) || item.getStringAttribute("class_required").contentEquals("None")) result = true; else return false; @@ -137,59 +111,81 @@ public class EquipmentService implements INetworkDispatch { return false; if (item.getAttributes().containsKey("required_combat_level")) + { if (actor.getLevel() >= item.getIntAttribute("required_combat_level")) result = true; else return false; + } + + if(item.getAttachment("unity") != null) + { + actor.sendSystemMessage("@unity:cannot_remove_ring", (byte) 0); + return false; + } return result; } - private float calculateArmorProtection (float protection, String slotName) { - return protection *= (Float.parseFloat(core.scriptService.getMethod("scripts/equipment/", "slot_protection", slotName).__call__().asString()) / 100); + private void calculateArmorProtection(CreatureObject creature, boolean equipping)//float protection, String slotName) + { + int wornArmourPieces = 0; + Map protection = new TreeMap(); + + for(SWGObject item : creature.getEquipmentList()) + { + Map attributes = new TreeMap(item.getAttributes()); + //if(attributes.containsKey("")) wornArmourPieces++; + boolean incPieceCount = false; + + for(Entry e : attributes.entrySet()) + { + if(e.getKey().startsWith("cat_armor_standard_protection")) + { + String protectionType = e.getKey().replace("cat_armor_standard_protection.armor_eff_", ""); + float modifier = Float.parseFloat(core.scriptService.getMethod("scripts/equipment/", "slot_protection", creature.getSlotNameForObject(item)).__call__().asString()) / 100; + Float protectionAmount = Float.parseFloat((String) e.getValue()) * modifier; + + if(protection.containsKey(protectionType)) protection.replace(protectionType, protection.get(protectionType) + protectionAmount); + else protection.put(protectionType, protectionAmount); + incPieceCount = true; + } + else if(e.getKey().startsWith("cat_armor_special_protection")) + { + String protectionType = e.getKey().replace("cat_armor_special_protection.special_protection_type_", ""); + float modifier = Float.parseFloat(core.scriptService.getMethod("scripts/equipment/", "slot_protection", creature.getSlotNameForObject(item)).__call__().asString()) / 100; + Float protectionAmount = Float.parseFloat((String) e.getValue()) * modifier; + + if(protection.containsKey(protectionType)) protection.replace(protectionType, protection.get(protectionType) + protectionAmount); + else protection.put(protectionType, protectionAmount); + incPieceCount = true; + } + } + if(incPieceCount) wornArmourPieces++; + } + + //if(wornArmourPieces >= 3) + //{ + for(Entry e : protection.entrySet()) + { + System.out.println("ProtectionType: " + e.getKey()); + System.out.println("ProtectionAmount: " + e.getValue()); + + core.skillModService.deductSkillMod(creature, e.getKey(), creature.getSkillModBase(e.getKey())); + core.skillModService.addSkillMod(creature, e.getKey(), (int) e.getValue().floatValue()); + } + //} + } - - private void addArmorProtection(CreatureObject actor, String protectionType, float protection, String slotName) { - actor.addSkillMod(protectionType, (int) (calculateArmorProtection(protection, slotName))); - } - - private void deductArmorProtection(CreatureObject actor, String protectionType, float protection, String slotName) { - actor.deductSkillMod(protectionType, (int) calculateArmorProtection(protection, slotName)); - } - - private void addForceProtection(CreatureObject actor, SWGObject item) { - actor.addSkillMod("kinetic", getForceProtection(item)); - actor.addSkillMod("energy", getForceProtection(item)); - actor.addSkillMod("heat", getForceProtection(item)); - actor.addSkillMod("cold", getForceProtection(item)); - actor.addSkillMod("acid", getForceProtection(item)); - actor.addSkillMod("electricity", getForceProtection(item)); - } - - private void deductForceProtection(CreatureObject actor, SWGObject item) { - actor.deductSkillMod("kinetic", getForceProtection(item)); - actor.deductSkillMod("energy", getForceProtection(item)); - actor.deductSkillMod("heat", getForceProtection(item)); - actor.deductSkillMod("cold", getForceProtection(item)); - actor.deductSkillMod("acid", getForceProtection(item)); - actor.deductSkillMod("electricity", getForceProtection(item)); - } - - private int getForceProtection(SWGObject item) { - return core.scriptService.getMethod("scripts/equipment/", "force_protection", item.getAttachment("type") + "_" + item.getStringAttribute("protection_level")).__call__().asInt(); - } - - public void equip(CreatureObject actor, SWGObject item) { + + public void equip(CreatureObject actor, SWGObject item) + { String template = ((item.getAttachment("customServerTemplate") == null) ? item.getTemplate() : (item.getTemplate().split("shared_")[0] + "shared_" + ((String) item.getAttachment("customServerTemplate")) + ".iff")); String serverTemplate = template.replace(".iff", ""); - PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "equip"); - if(func != null) - func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); - - if (item.getStringAttribute("protection_level") != null) - addForceProtection(actor, item); - // TODO: faction restrictions - You had to be a Combatant as minimum in order to EQUIP an item. + PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "equip"); + if(func != null) func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); + // TODO: Species restrictions // TODO: Gender restrictions // TODO: crit enhancement from crafted weapons @@ -197,107 +193,117 @@ public class EquipmentService implements INetworkDispatch { // TODO: Calculate actual armor values (REMINDER: Check if the player is wearing a jedi robe/cloak (look for force protection intensity). If they are, they shouldn't receive any additional protection from other items with armour.) // TODO: bio-link (assign it by objectID with setAttachment and then just display the customName for that objectID). - if(item.getStringAttribute("cat_wpn_damage.wpn_category") != null) - addWeaponCriticalChance(actor, item); - - Map attributes = new TreeMap(item.getAttributes()); - - for(Entry e : attributes.entrySet()) { - if(e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) { - core.skillModService.addSkillMod(actor, e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); - } - - if(e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) { - core.skillModService.addSkillMod(actor, e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); - } - - if(e.getKey().startsWith("cat_armor_standard_protection")) { - addArmorProtection(actor, e.getKey().replace("cat_armor_standard_protection.armor_eff_", ""), Float.parseFloat((String) e.getValue()), actor.getSlotNameForObject(item)); - } - - if(e.getKey().startsWith("cat_armor_special_protection")) { - addArmorProtection(actor, e.getKey().replace("cat_armor_special_protection.special_protection_type_", ""), Float.parseFloat((String) e.getValue()), actor.getSlotNameForObject(item)); - } - - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) { - actor.setMaxHealth(actor.getMaxHealth() + Integer.parseInt((String) e.getValue())); - } - - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) { - actor.setMaxAction(actor.getMaxAction() + Integer.parseInt((String) e.getValue())); - } - - } - - if(item.getStringAttribute("proc_name") != null) core.buffService.addBuffToCreature(actor, item.getStringAttribute("proc_name").replace("@ui_buff:", ""), actor); - - - if(!actor.getEquipmentList().contains(item)) - actor.addObjectToEquipList(item); - - if(item.getAttachment("setBonus") != null) + if(!actor.getEquipmentList().contains(item)) { - BonusSetTemplate bonus = bonusSetTemplates.get((String)item.getAttachment("setBonus")); - bonus.callScript(actor); + actor.addObjectToEquipList(item); + processItemAtrributes(actor, item, true); } } - public void unequip(CreatureObject actor, SWGObject item) { + public void unequip(CreatureObject actor, SWGObject item) + { String template = ((item.getAttachment("customServerTemplate") == null) ? item.getTemplate() : (item.getTemplate().split("shared_")[0] + "shared_" + ((String) item.getAttachment("customServerTemplate")) + ".iff")); String serverTemplate = template.replace(".iff", ""); + PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "unequip"); - if(func != null) - func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); + if(func != null) func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); - if (item.getStringAttribute("protection_level") != null) - deductForceProtection(actor, item); - - if(item.getStringAttribute("cat_wpn_damage.wpn_category") != null) - deductWeaponCriticalChance(actor, item); + if(actor.getEquipmentList().contains(item)) + { + actor.removeObjectFromEquipList(item); + processItemAtrributes(actor, item, false); + } + } + + public void processItemAtrributes(CreatureObject creature, SWGObject item, boolean equipping) + { Map attributes = new TreeMap(item.getAttributes()); - for(Entry e : attributes.entrySet()) { - - if(e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) { - core.skillModService.deductSkillMod(actor, e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); - } - if(e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) { - core.skillModService.deductSkillMod(actor, e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); - } - - if(e.getKey().startsWith("cat_armor_standard_protection")) { - deductArmorProtection(actor, e.getKey().replace("cat_armor_standard_protection.armor_eff_", ""), Float.parseFloat((String) e.getValue()), actor.getSlotNameForObject(item)); - } - - if(e.getKey().startsWith("cat_armor_special_protection")) { - deductArmorProtection(actor, e.getKey().replace("cat_armor_special_protection.special_protection_type_", ""), Float.parseFloat((String) e.getValue()), actor.getSlotNameForObject(item)); - } - - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) { - actor.setMaxHealth(actor.getMaxHealth() - Integer.parseInt((String) e.getValue())); - } - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) { - actor.setMaxAction(actor.getMaxAction() - Integer.parseInt((String) e.getValue())); - } - - } + calculateArmorProtection(creature, equipping); - if(item.getAttachment("unity") != null) { - actor.sendSystemMessage("@unity:cannot_remove_ring", (byte) 0); - return; + if(equipping) + { + if(item.getStringAttribute("cat_wpn_damage.wpn_category") != null) creature.addSkillMod("display_only_critical", getWeaponCriticalChance(creature, item)); + if(item.getStringAttribute("protection_level") != null) addForceProtection(creature, item); + if(item.getStringAttribute("proc_name") != null) core.buffService.addBuffToCreature(creature, item.getStringAttribute("proc_name").replace("@ui_buff:", ""), creature); + + for(Entry e : attributes.entrySet()) + { + if(e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) + { + core.skillModService.addSkillMod(creature, e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); + } + + if(e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) + { + core.skillModService.addSkillMod(creature, e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); + } + + /*if(e.getKey().startsWith("cat_armor_standard_protection")) + { + addArmorProtection(creature, e.getKey().replace("cat_armor_standard_protection.armor_eff_", ""), Float.parseFloat((String) e.getValue()), creature.getSlotNameForObject(item)); + } + + if(e.getKey().startsWith("cat_armor_special_protection")) + { + addArmorProtection(creature, e.getKey().replace("cat_armor_special_protection.special_protection_type_", ""), Float.parseFloat((String) e.getValue()), creature.getSlotNameForObject(item)); + } */ + + if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) + { + creature.setMaxHealth(creature.getMaxHealth() + Integer.parseInt((String) e.getValue())); + } + + if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) + { + creature.setMaxAction(creature.getMaxAction() + Integer.parseInt((String) e.getValue())); + } + + } + } + else + { + if(item.getStringAttribute("cat_wpn_damage.wpn_category") != null) creature.deductSkillMod("display_only_critical", getWeaponCriticalChance(creature, item)); + if(item.getStringAttribute("protection_level") != null) deductForceProtection(creature, item); + if(item.getStringAttribute("proc_name") != null) core.buffService.removeBuffFromCreatureByName(creature, item.getStringAttribute("proc_name").replace("@ui_buff:", "")); + + for(Entry e : attributes.entrySet()) + { + if(e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) + { + core.skillModService.deductSkillMod(creature, e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); + } + if(e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) + { + core.skillModService.deductSkillMod(creature, e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); + } + + /*if(e.getKey().startsWith("cat_armor_standard_protection")) + { + deductArmorProtection(creature, e.getKey().replace("cat_armor_standard_protection.armor_eff_", ""), Float.parseFloat((String) e.getValue()), creature.getSlotNameForObject(item)); + } + + if(e.getKey().startsWith("cat_armor_special_protection")) + { + deductArmorProtection(creature, e.getKey().replace("cat_armor_special_protection.special_protection_type_", ""), Float.parseFloat((String) e.getValue()), creature.getSlotNameForObject(item)); + } */ + + if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) + { + creature.setMaxHealth(creature.getMaxHealth() - Integer.parseInt((String) e.getValue())); + } + if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) + { + creature.setMaxAction(creature.getMaxAction() - Integer.parseInt((String) e.getValue())); + } + } } - if(item.getStringAttribute("proc_name") != null) core.buffService.removeBuffFromCreatureByName(actor, item.getStringAttribute("proc_name").replace("@ui_buff:", "")); - - - if(actor.getEquipmentList().contains(item)) - actor.removeObjectFromEquipList(item); - if(item.getAttachment("setBonus") != null) { BonusSetTemplate bonus = bonusSetTemplates.get((String)item.getAttachment("setBonus")); - bonus.callScript(actor); + bonus.callScript(creature); } } @@ -308,17 +314,42 @@ public class EquipmentService implements INetworkDispatch { public void loadBonusSets() { Path p = Paths.get("scripts/equipment/bonus_sets/"); - FileVisitor fv = new SimpleFileVisitor() { + FileVisitor fv = new SimpleFileVisitor() + { @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException + { core.scriptService.callScript("scripts/equipment/bonus_sets/", file.getFileName().toString().replace(".py", ""), "addBonusSet", core); return FileVisitResult.CONTINUE; } }; - try { + try + { Files.walkFileTree(p, fv); - } catch (IOException e) { - e.printStackTrace(); - } + } + catch (IOException e) { e.printStackTrace(); } + } + + // Need to refactor below + private void addForceProtection(CreatureObject actor, SWGObject item) { + core.skillModService.addSkillMod(actor, "kinetic", getForceProtection(item)); + core.skillModService.addSkillMod(actor, "energy", getForceProtection(item)); + core.skillModService.addSkillMod(actor, "heat", getForceProtection(item)); + core.skillModService.addSkillMod(actor, "cold", getForceProtection(item)); + core.skillModService.addSkillMod(actor, "acid", getForceProtection(item)); + core.skillModService.addSkillMod(actor, "electricity", getForceProtection(item)); + } + + private void deductForceProtection(CreatureObject actor, SWGObject item) { + core.skillModService.deductSkillMod(actor, "kinetic", getForceProtection(item)); + core.skillModService.deductSkillMod(actor, "energy", getForceProtection(item)); + core.skillModService.deductSkillMod(actor, "heat", getForceProtection(item)); + core.skillModService.deductSkillMod(actor, "cold", getForceProtection(item)); + core.skillModService.deductSkillMod(actor, "acid", getForceProtection(item)); + core.skillModService.deductSkillMod(actor, "electricity", getForceProtection(item)); + } + + private int getForceProtection(SWGObject item) { + return core.scriptService.getMethod("scripts/equipment/", "force_protection", item.getAttachment("type") + "_" + item.getStringAttribute("protection_level")).__call__().asInt(); } } diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index f52a6a92..9df745c2 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -558,7 +558,7 @@ public class PlayerService implements INetworkDispatch { } /* - * Resets to level 0 + * Resets to level 1 */ public void resetLevel(CreatureObject creature) { PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost"); @@ -576,18 +576,13 @@ public class PlayerService implements INetworkDispatch { case "object/tangible/datapad/shared_character_datapad.iff": case "object/tangible/bank/shared_character_bank.iff": case "object/tangible/mission_bag/shared_mission_bag.iff": - case "object/weapon/creature/shared_creature_default_weapon.iff": { + case "object/weapon/creature/shared_creature_default_weapon.iff": continue; - } - default: { - // - } + default: + core.equipmentService.unequip(creature, equipment); } - - core.equipmentService.unequip(creature, equipment); } - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } @@ -597,10 +592,30 @@ public class PlayerService implements INetworkDispatch { core.buffService.clearBuffs(creature); - for (String skill : creature.getSkills()) { - core.skillService.removeSkill(creature, skill); + try { + String[] skills; + + DatatableVisitor skillTemplate = ClientFileManager.loadFile("datatables/skill_template/skill_template.iff", DatatableVisitor.class); + + for (int s = 0; s < skillTemplate.getRowCount(); s++) { + if (skillTemplate.getObject(s, 0) != null) { + if (((String) skillTemplate.getObject(s, 0)).equals(player.getProfession())) { + skills = ((String) skillTemplate.getObject(s, 4)).split(","); + + for (String skill : skills) { + creature.removeSkill(skill); + } + + break; + } + } + } + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); } - + + core.skillService.resetExpertise(creature); + String xpType = ((player.getProfession().contains("entertainer")) ? "entertainer" : ((player.getProfession().contains("trader")) ? "crafting" : "combat_general")); player.setXp(xpType, 0); @@ -619,7 +634,7 @@ public class PlayerService implements INetworkDispatch { creature.setAction(300); creature.setGrantedHealth(0); - creature.setLevel((short) 0); + creature.setLevel((short) 1); } /* @@ -637,11 +652,9 @@ public class PlayerService implements INetworkDispatch { return; } - resetLevel(creature); + if(level == 0) return; - if (level == 0) { - return; - } + resetLevel(creature); try { experienceTable = ClientFileManager.loadFile("datatables/player/player_level.iff", DatatableVisitor.class); @@ -802,6 +815,11 @@ public class PlayerService implements INetworkDispatch { DatatableVisitor experienceTable; PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost"); experience *= xpMultiplier; + + if (creature.getLevel() >= 90) { + return; + } + //synchronized(objectMutex) { try { experienceTable = ClientFileManager.loadFile("datatables/player/player_level.iff", DatatableVisitor.class); @@ -814,7 +832,7 @@ public class PlayerService implements INetworkDispatch { experience += ((experience * experienceBonus) / 100); // 1. Add the experience. - if (experience > 0) { + if (experience > 0 && !creature.isStationary()) { creature.showFlyText("base_player", "prose_flytext_xp", "", experience, (float) 2.5, new RGB(180, 60, 240), 1); } @@ -1208,6 +1226,25 @@ public class PlayerService implements INetworkDispatch { core.suiService.openSUIWindow(ringWindow); } + public String getFormalProfessionName(String template) { + String formalName = ""; + + switch (template) { + case "force_sensitive_1a": formalName = "Jedi"; break; + case "bounty_hunter_1a": formalName = "Bounty Hunter"; break; + case "officer_1a": formalName = "Officer"; break; + case "smuggler_1a": formalName = "Smuggler"; break; + case "entertainer_1a": formalName = "Entertainer"; break; + case "spy_1a": formalName = "Spy"; break; + case "medic_1a": formalName = "Medic"; break; + case "commando_1a": formalName = "Commando"; break; + + default: formalName = "Trader"; break; // Ziggy: Trader profession names are a bit irregular, so this is used. + + } + return formalName; + } + @Override public void shutdown() { // TODO Auto-generated method stub