From f8f2d156c1321ac89d251f009bc512623dac35e4 Mon Sep 17 00:00:00 2001 From: Treeku Date: Mon, 8 Sep 2014 20:20:57 +0100 Subject: [PATCH 1/7] Added minor method to get equipment for object --- .../objects/creature/CreatureObject.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 2245768d..642dd787 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -899,7 +899,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { public boolean isWearing(SWGObject object) { for (Equipment equipment : getEquipmentList()) { - if (equipment.getObjectId() == object.getObjectId()) { + if (equipment.getObjectId() == object.getObjectID()) { return true; } } @@ -907,10 +907,26 @@ public class CreatureObject extends TangibleObject implements IPersistent { return false; } + public Equipment getEquipmentForObject(SWGObject object) { + for (Equipment equipment : getEquipmentList()) { + if (equipment.getObjectId() == object.getObjectID()) { + return equipment; + } + } + + for (Equipment equipment : getAppearanceEquipmentList()) { + if (equipment.getObjectId() == object.getObjectID()) { + return equipment; + } + } + + return null; + } + public void removeObjectFromEquipList(SWGObject object) { if (object instanceof TangibleObject) { for (Equipment equipment : getEquipmentList()) { - if (equipment.getObjectId() == object.getObjectId()) { + if (equipment.getObjectId() == object.getObjectID()) { getEquipmentList().remove(equipment); } } @@ -1131,7 +1147,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { public boolean isWearingAppearance(SWGObject object) { for (Equipment equipment : getAppearanceEquipmentList()) { - if (equipment.getObjectId() == object.getObjectId()) { + if (equipment.getObjectId() == object.getObjectID()) { return true; } } @@ -1142,7 +1158,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { public void removeObjectFromAppearanceEquipList(SWGObject object) { if (object instanceof TangibleObject) { for (Equipment equipment : getAppearanceEquipmentList()) { - if (equipment.getObjectId() == object.getObjectId()) { + if (equipment.getObjectId() == object.getObjectID()) { getAppearanceEquipmentList().remove(equipment); } } From 511e04045c807416cf4632723d7a688d9cf07b3f Mon Sep 17 00:00:00 2001 From: Treeku Date: Mon, 8 Sep 2014 21:28:23 +0100 Subject: [PATCH 2/7] Equipment performs operations in the correct order --- src/services/equipment/EquipmentService.java | 75 +++++++++++++------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/src/services/equipment/EquipmentService.java b/src/services/equipment/EquipmentService.java index 511f49f8..8f27e8e1 100644 --- a/src/services/equipment/EquipmentService.java +++ b/src/services/equipment/EquipmentService.java @@ -65,12 +65,31 @@ public class EquipmentService implements INetworkDispatch { SWGObject container = actor; if (canWear(actor, container, item)) { - Vector slotNames = container.getSlotNamesForObject(item); + List replacedEquipment = new ArrayList(); - for (String slotName : slotNames) { - if (container.getSlottedObject(slotName) != null && !slotNames.iterator().hasNext()) { + for (String slotName : container.getSlotNamesForObject(item)) { + if (container.getSlottedObject(slotName) != null) { + replacedEquipment.add(actor.getEquipmentForObject(container.getSlottedObject(slotName))); container.transferTo(actor, actor.getSlottedObject("inventory"), container.getSlottedObject(slotName)); - break; + } + } + + container.transferTo(actor, container, item); + + for (SWGObject replacedItem : replacedEquipment) { + if (actor.isWearing(replacedItem)) { + String template = ((replacedItem.getAttachment("customServerTemplate") == null) ? replacedItem.getTemplate() : (replacedItem.getTemplate().split("shared_")[0] + "shared_" + ((String) replacedItem.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(replacedItem)); + } + + processItemAtrributes(actor, replacedItem, false); + } else { + replacedEquipment.remove(replacedItem); } } @@ -83,9 +102,14 @@ public class EquipmentService implements INetworkDispatch { func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); } - actor.addObjectToEquipList(item); processItemAtrributes(actor, item, true); + if (replacedEquipment.size() > 0) { + actor.getEquipmentList().removeAll(replacedEquipment); + } + + actor.addObjectToEquipList(item); + if (item instanceof WeaponObject) { actor.setWeaponId(item.getObjectID()); } @@ -94,6 +118,12 @@ public class EquipmentService implements INetworkDispatch { public void unequip(CreatureObject actor, SWGObject item) { if (actor.isWearing(item)) { + if (item instanceof WeaponObject) { + actor.setWeaponId(actor.getSlottedObject("default_weapon").getObjectID()); + } + + container.transferTo(actor, actor.getSlottedObject("inventory"), 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", ""); @@ -103,12 +133,9 @@ public class EquipmentService implements INetworkDispatch { func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); } - if (item instanceof WeaponObject) { - actor.setWeaponId(actor.getSlottedObject("default_weapon").getObjectID()); - } + processItemAtrributes(actor, item, false); actor.removeObjectFromEquipList(item); - processItemAtrributes(actor, item, false); } } @@ -116,20 +143,22 @@ public class EquipmentService implements INetworkDispatch { SWGObject container = actor.getSlottedObject("appearance_inventory"); if (canWear(actor, container, item)) { - Vector slotNames = container.getSlotNamesForObject(item); - - for (String slotName : slotNames) { - if (container.getSlottedObject(slotName) != null && !slotNames.iterator().hasNext()) { + for (String slotName : container.getSlotNamesForObject(item)) { + if (container.getSlottedObject(slotName) != null) { return; } } + container.transferTo(actor, container, item); + actor.addObjectToAppearanceEquipList(item); } } public void unequipAppearance(CreatureObject actor, SWGObject item) { - if (actor.isWearingAppearance(item) ) { + if (actor.isWearingAppearance(item)) { + container.transferTo(actor, actor.getSlottedObject("inventory"), item); + actor.removeObjectFromAppearanceEquipList(item); } } @@ -154,9 +183,7 @@ public class EquipmentService implements INetworkDispatch { } if (item.getAttributes().toString().contains("cat_armor")) { - if (actor.hasAbility("wear_all_armor")) { - return true; - } else { + if (!actor.hasAbility("wear_all_armor")) { actor.sendSystemMessage("@error_message:insufficient_skill", DisplayType.Broadcast); // I am unsure if this is the right message return false; } @@ -166,27 +193,21 @@ public class EquipmentService implements INetworkDispatch { String classRequired = item.getStringAttribute("class_required"); String profession = ((PlayerObject) actor.getSlottedObject("ghost")).getProfession(); - if (classRequired.contains(core.playerService.getFormalProfessionName(profession)) || classRequired.equals("None")) { - return true; - } else { + if (!classRequired.contains(core.playerService.getFormalProfessionName(profession)) && !classRequired.equals("None")) { actor.sendSystemMessage("@error_message:insufficient_skill", DisplayType.Broadcast); // I am unsure if this is the right message return false; } } if (item.getStringAttribute("faction_restriction") != null) { - if (item.getStringAttribute("faction_restriction").toLowerCase().contentEquals(actor.getFaction()) && actor.getFactionStatus() >= FactionStatus.Combatant) { - return true; - } else { + if (!item.getStringAttribute("faction_restriction").toLowerCase().contentEquals(actor.getFaction()) || actor.getFactionStatus() < FactionStatus.Combatant) { actor.sendSystemMessage("@faction_recruiter:must_be_faction_member_use", DisplayType.Broadcast); // will have to somehow manage prose %TO for faction name return false; } } if (item.getAttributes().containsKey("required_combat_level")) { - if (actor.getLevel() >= item.getIntAttribute("required_combat_level")) { - return true; - } else { + if (actor.getLevel() < item.getIntAttribute("required_combat_level")) { actor.sendSystemMessage("@error_message:insufficient_skill", DisplayType.Broadcast); // I am unsure if this is the right message return false; } @@ -623,7 +644,7 @@ public class EquipmentService implements INetworkDispatch { FileVisitor fv = new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - core.scriptService.callScript("scripts/equipment/bonus_sets/", file.getFileName().toString().replace(".py", ""), "addBonusSet", core); + core.scriptService.callScript("scripts/equipment/bonus_sets/", file.getFileName().toString().replace(".py", ""), "addBonusSet", core); return FileVisitResult.CONTINUE; } }; From abc6b8de01456a6a1ca611d1f775cb2bfca4f007 Mon Sep 17 00:00:00 2001 From: Treeku Date: Mon, 8 Sep 2014 21:48:30 +0100 Subject: [PATCH 3/7] Updated transferitemarmor --- scripts/commands/transferitemarmor.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/commands/transferitemarmor.py b/scripts/commands/transferitemarmor.py index 46a741f3..421c0f05 100644 --- a/scripts/commands/transferitemarmor.py +++ b/scripts/commands/transferitemarmor.py @@ -15,13 +15,16 @@ def run(core, actor, target, commandString): if container == oldContainer: print 'Error: New container is same as old container.' return; - - if oldContainer == actor.getSlottedObject('appearance_inventory'): - core.equipmentService.unequipAppearance(actor, target) - - oldContainer.transferTo(actor, container, target) - - if container == actor.getSlottedObject('appearance_inventory'): - core.equipmentService.equipAppearance(actor, target) - + + if oldContainer == actor: + core.equipmentService.unequip(actor, target) + elif oldContainer == actor.getSlottedObject('appearance_inventory'): + core.equipmentService.unequipAppearance(actor, target) + elif container == actor: + core.equipmentService.equip(actor, target) + elif container == actor.getSlottedObject('appearance_inventory'): + core.equipmentService.equipAppearance(actor, target) + else: + oldContainer.transferTo(actor, container, target) + return From b98cdcbc47fe6e90932bc98c6d6825c38c39d0ec Mon Sep 17 00:00:00 2001 From: Treeku Date: Mon, 8 Sep 2014 21:50:45 +0100 Subject: [PATCH 4/7] Updated transferitemmisc --- scripts/commands/transferitemmisc.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/commands/transferitemmisc.py b/scripts/commands/transferitemmisc.py index c0708738..e7b5e32c 100644 --- a/scripts/commands/transferitemmisc.py +++ b/scripts/commands/transferitemmisc.py @@ -58,12 +58,15 @@ def run(core, actor, target, commandString): print 'Error: New container is same as old container.' return; - if oldContainer == actor.getSlottedObject('appearance_inventory'): + if oldContainer == actor: + core.equipmentService.unequip(actor, target) + elif oldContainer == actor.getSlottedObject('appearance_inventory'): core.equipmentService.unequipAppearance(actor, target) - - oldContainer.transferTo(actor, container, target) - - if container == actor.getSlottedObject('appearance_inventory'): + elif container == actor: + core.equipmentService.equip(actor, target) + elif container == actor.getSlottedObject('appearance_inventory'): core.equipmentService.equipAppearance(actor, target) + else: + oldContainer.transferTo(actor, container, target) return From 8d8a4d78f46a058656c8add60332a11f3abe2910 Mon Sep 17 00:00:00 2001 From: Treeku Date: Mon, 8 Sep 2014 21:53:01 +0100 Subject: [PATCH 5/7] Updated transferitemweapon --- scripts/commands/transferitemweapon.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/commands/transferitemweapon.py b/scripts/commands/transferitemweapon.py index 25b9378b..c5ec91b8 100644 --- a/scripts/commands/transferitemweapon.py +++ b/scripts/commands/transferitemweapon.py @@ -16,7 +16,11 @@ def run(core, actor, target, commandString): print 'Error: New container is same as old container.' return; - oldContainer.transferTo(actor, container, target) + if oldContainer == actor: + core.equipmentService.unequip(actor, target) + elif container == actor: + core.equipmentService.equip(actor, target) + else: + oldContainer.transferTo(actor, container, target) return - From 95d0ce89e9339d5ff7e59dfbf648c6031d5b675c Mon Sep 17 00:00:00 2001 From: Treeku Date: Mon, 8 Sep 2014 22:16:29 +0100 Subject: [PATCH 6/7] Fixed some syntax errors --- src/services/equipment/EquipmentService.java | 24 ++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/services/equipment/EquipmentService.java b/src/services/equipment/EquipmentService.java index 8f27e8e1..705d1f15 100644 --- a/src/services/equipment/EquipmentService.java +++ b/src/services/equipment/EquipmentService.java @@ -63,6 +63,7 @@ public class EquipmentService implements INetworkDispatch { public void equip(CreatureObject actor, SWGObject item) { SWGObject container = actor; + SWGObject oldContainer = item.getContainer(); if (canWear(actor, container, item)) { List replacedEquipment = new ArrayList(); @@ -74,7 +75,11 @@ public class EquipmentService implements INetworkDispatch { } } - container.transferTo(actor, container, item); + if (oldContainer == null) { + container.add(item); + } else { + oldContainer.transferTo(actor, container, item); + } for (SWGObject replacedItem : replacedEquipment) { if (actor.isWearing(replacedItem)) { @@ -117,12 +122,15 @@ public class EquipmentService implements INetworkDispatch { } public void unequip(CreatureObject actor, SWGObject item) { + SWGObject container = actor.getSlottedObject("inventory"); + SWGObject oldContainer = item.getContainer(); + if (actor.isWearing(item)) { if (item instanceof WeaponObject) { actor.setWeaponId(actor.getSlottedObject("default_weapon").getObjectID()); } - container.transferTo(actor, actor.getSlottedObject("inventory"), item); + oldContainer.transferTo(actor, container, 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", ""); @@ -141,6 +149,7 @@ public class EquipmentService implements INetworkDispatch { public void equipAppearance(CreatureObject actor, SWGObject item) { SWGObject container = actor.getSlottedObject("appearance_inventory"); + SWGObject oldContainer = item.getContainer(); if (canWear(actor, container, item)) { for (String slotName : container.getSlotNamesForObject(item)) { @@ -149,15 +158,22 @@ public class EquipmentService implements INetworkDispatch { } } - container.transferTo(actor, container, item); + if (oldContainer == null) { + container.add(item); + } else { + container.transferTo(actor, container, item); + } actor.addObjectToAppearanceEquipList(item); } } public void unequipAppearance(CreatureObject actor, SWGObject item) { + SWGObject container = actor.getSlottedObject("inventory"); + SWGObject oldContainer = item.getContainer(); + if (actor.isWearingAppearance(item)) { - container.transferTo(actor, actor.getSlottedObject("inventory"), item); + oldContainer.transferTo(actor, container, item); actor.removeObjectFromAppearanceEquipList(item); } From 34994eeab5f208538032b4a59fef089d4c905780 Mon Sep 17 00:00:00 2001 From: Treeku Date: Mon, 8 Sep 2014 22:43:39 +0100 Subject: [PATCH 7/7] Changed respec, frogs to remove equipment better --- src/services/PlayerService.java | 35 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index be544185..df096e2d 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -787,27 +787,24 @@ public class PlayerService implements INetworkDispatch { public void resetLevel(CreatureObject creature, boolean unequipItems) { PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost"); SWGObject inventory = creature.getSlottedObject("inventory"); + SWGObject appearance = creature.getSlottedObject("appearance_inventory"); if (unequipItems) { try { - for (Equipment equipmentObject : new ArrayList(creature.getEquipmentList())) { - - SWGObject equipment = core.objectService.getObject(equipmentObject.getObjectId()); - - if (equipment == null || equipment.getTemplate().startsWith("object/tangible/hair/")) { - continue; + String[] slots = { "hat", "earring_r", "earring_l", "eyes", "mouth", "neck", "cloak", "back", "chest1", "chest2", "chest3_r", "chest3_l", "bicep_r", "bicep_l", "bracer_lower_r", "bracer_upper_r", "bracer_lower_l", "bracer_upper_l", "wrist_r", "wrist_l", "gloves", "hold_r", "hold_l", "ring_r", "ring_l", "utility_belt", "pants1", "pants2", "shoes" }; + + for (String slot : slots) { + if (creature.getSlottedObject(slot) != null) { + core.equipmentService.unequip(creature, creature.getSlottedObject(slot)); } - - switch (equipment.getTemplate()) { - case "object/tangible/inventory/shared_character_inventory.iff": - case "object/tangible/inventory/shared_appearance_inventory.iff": - 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": - continue; - default: - creature.transferTo(creature, inventory, equipment); + } + + + slots = { "hat", "earring_r", "earring_l", "eyes", "mouth", "neck", "cloak", "back", "chest1", "chest2", "chest3_r", "chest3_l", "bicep_r", "bicep_l", "bracer_lower_r", "bracer_upper_r", "bracer_lower_l", "bracer_upper_l", "wrist_r", "wrist_l", "gloves", "utility_belt", "pants1", "pants2", "shoes" }; + + for (String slot : slots) { + if (appearance.getSlottedObject(slot) != null) { + core.equipmentService.unequip(creature, creature.getSlottedObject(slot)); } } } catch (Exception e) { @@ -815,10 +812,6 @@ public class PlayerService implements INetworkDispatch { } } - //for (SWGObject equipment : creature.getAppearanceEquipmentList()) { - //core.equipmentService.unequip(creature, equipment); - //} - for (Buff buff : creature.getBuffList().values().toArray(new Buff[] { })) { if (buff.isRemoveOnRespec()) { core.buffService.removeBuffFromCreature(creature, buff);