diff --git a/ngengine_public.jar b/ngengine_public.jar index 0d2614d2..7dd51213 100644 Binary files a/ngengine_public.jar and b/ngengine_public.jar differ diff --git a/scripts/commands/transferitemarmor.py b/scripts/commands/transferitemarmor.py index 931dc47d..ab107cf3 100644 --- a/scripts/commands/transferitemarmor.py +++ b/scripts/commands/transferitemarmor.py @@ -9,9 +9,31 @@ def run(core, actor, target, commandString): containerID = long(parsedMsg[1]) container = objService.getObject(containerID) if target and container and target.getContainer(): - print 'Armor Test' oldContainer = target.getContainer() - oldContainer.transferTo(actor, container, target) + if container == oldContainer: + print 'Error: New container is same as old container.' + return; + replacedObject = None + slotName = None + if actor == container: + slotName = container.getSlotNameForObject(target) + replacedObject = container.getSlottedObject(slotName) + + oldContainer.transferTo(actor, container, target) + + if actor == container: + if target.getTemplate().find('/wearables/') or target.getTemplate().find('/weapon/'): + core.equipmentService.equip(actor, target, replacedObject) + #path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' + #module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') + #core.scriptService.callScript(path, 'equip', module, core, actor, target) + + if actor == oldContainer: + if target.getTemplate().find('/wearables/') or target.getTemplate().find('/weapon/'): + #path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' + #module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') + #core.scriptService.callScript(path, 'unequip', module, core, actor, target) + core.equipmentService.unequip(actor, target, replacedObject) return \ No newline at end of file diff --git a/scripts/commands/transferitemmisc.py b/scripts/commands/transferitemmisc.py index 83f34e8d..53eef0d6 100644 --- a/scripts/commands/transferitemmisc.py +++ b/scripts/commands/transferitemmisc.py @@ -15,18 +15,26 @@ def run(core, actor, target, commandString): print 'Error: New container is same as old container.' return; + replacedObject = None + slotName = None + if actor == container: + slotName = container.getSlotNameForObject(target) + replacedObject = container.getSlottedObject(slotName) + oldContainer.transferTo(actor, container, target) if actor == container: if target.getTemplate().find('/wearables/') or target.getTemplate().find('/weapon/'): - path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' - module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') - core.scriptService.callScript(path, 'equip', module, core, actor, target) + core.equipmentService.equip(actor, target, replacedObject) + #path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' + #module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') + #core.scriptService.callScript(path, 'equip', module, core, actor, target) if actor == oldContainer: if target.getTemplate().find('/wearables/') or target.getTemplate().find('/weapon/'): - path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' - module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') - core.scriptService.callScript(path, 'unequip', module, core, actor, target) - + #path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' + #module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') + #core.scriptService.callScript(path, 'unequip', module, core, actor, target) + core.equipmentService.unequip(actor, target) + return \ No newline at end of file diff --git a/scripts/commands/transferitemweapon.py b/scripts/commands/transferitemweapon.py index a480461a..0bb7f55f 100644 --- a/scripts/commands/transferitemweapon.py +++ b/scripts/commands/transferitemweapon.py @@ -9,9 +9,32 @@ def run(core, actor, target, commandString): containerID = long(parsedMsg[1]) container = objService.getObject(containerID) if target and container and target.getContainer(): - print 'Weapon Test' oldContainer = target.getContainer() - oldContainer.transferTo(actor, container, target) + if container == oldContainer: + print 'Error: New container is same as old container.' + return; + + replacedObject = None + slotName = None + if actor == container: + slotName = container.getSlotNameForObject(target) + replacedObject = container.getSlottedObject(slotName) + + oldContainer.transferTo(actor, container, target) + + if actor == container: + if target.getTemplate().find('/wearables/') or target.getTemplate().find('/weapon/'): + core.equipmentService.equip(actor, target, replacedObject) + #path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' + #module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') + #core.scriptService.callScript(path, 'equip', module, core, actor, target) + + if actor == oldContainer: + if target.getTemplate().find('/wearables/') or target.getTemplate().find('/weapon/'): + #path = 'scripts/' + target.getTemplate().rpartition('/')[0] + '/' + #module = target.getTemplate().rpartition('/')[2].replace('shared_', '').replace('.iff', '') + #core.scriptService.callScript(path, 'unequip', module, core, actor, target) + core.equipmentService.unequip(actor, target, replacedObject) actor.setWeaponId(target.getObjectID()) return \ No newline at end of file diff --git a/scripts/demo.py b/scripts/demo.py index b2b49987..feebb5bc 100644 --- a/scripts/demo.py +++ b/scripts/demo.py @@ -12,6 +12,7 @@ def CreateStartingCharacter(core, object): testObject.setMaxDamage(1150) testObject.setElementalDamage(50) testObject.setIntAttribute('cat_wpn_damage.weapon_dps', testObject.getDamagePerSecond()) + testObject.setIntAttribute('cat_skill_mod_bonus.@stat_n:precision_modified', 35) object.addSkillMod('constitution_modified' , 350) object.addSkillMod('strength_modified' , 350) object.addSkillMod('precision_modified' , 350) diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 0ebb0880..30fe452c 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -37,6 +37,7 @@ import services.AttributeService; import services.BuffService; import services.CharacterService; import services.ConnectionService; +import services.EquipmentService; import services.GroupService; import services.LoginService; import services.PlayerService; @@ -120,6 +121,7 @@ public class NGECore { public StaticService staticService; public GroupService groupService; public SkillModService skillModService; + public EquipmentService equipmentService; // Login Server public NetworkDispatch loginDispatch; @@ -144,7 +146,6 @@ public class NGECore { if (!(config.loadConfigFile())) { config = DefaultConfig.getConfig(); } - // Database databaseConnection = new DatabaseConnection(); databaseConnection.connect(config.getString("DB.URL"), config.getString("DB.NAME"), config.getString("DB.USER"), config.getString("DB.PASS"), "postgresql"); @@ -173,6 +174,7 @@ public class NGECore { buffService = new BuffService(this); groupService = new GroupService(this); skillModService = new SkillModService(this); + equipmentService = new EquipmentService(this); // Ping Server try { diff --git a/src/services/EquipmentService.java b/src/services/EquipmentService.java new file mode 100644 index 00000000..8223e3b0 --- /dev/null +++ b/src/services/EquipmentService.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package services; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; +import org.python.core.Py; +import org.python.core.PyObject; +import resources.objects.creature.CreatureObject; +import main.NGECore; +import engine.resources.objects.SWGObject; +import engine.resources.service.INetworkDispatch; +import engine.resources.service.INetworkRemoteEvent; + +public class EquipmentService implements INetworkDispatch { + + private NGECore core; + + public EquipmentService(NGECore core) { + this.core = core; + } + + @Override + public void insertOpcodes(Map arg0, Map arg1) { + + } + + @Override + public void shutdown() { + + } + + public void equip(CreatureObject actor, SWGObject item, SWGObject replacedItem) { + + if(replacedItem != null) + unequip(actor, replacedItem); + + String template = item.getTemplate(); + 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)); + + // TODO: add health/action bonus from crafted weapon with augmentations + + 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())); + } + + } + + } + + public void unequip(CreatureObject actor, SWGObject item) { + + String template = item.getTemplate(); + 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)); + + // TODO: remove health/action bonus from crafted weapon with augmentations + + 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())); + } + + } + + } + + +} diff --git a/src/services/ScriptService.java b/src/services/ScriptService.java index beac5ff5..bf8cca6b 100644 --- a/src/services/ScriptService.java +++ b/src/services/ScriptService.java @@ -95,10 +95,9 @@ public class ScriptService { } public PyObject getMethod(String path, String module, String method) { - PythonInterpreter interpreter = new PythonInterpreter(); - interpreter.cleanup(); - interpreter.exec("import sys\nsys.path.append('" + path + "')\nfrom " + module + " import " + method); - PyObject func = interpreter.get(method); + PythonInterpreter python = new PythonInterpreter(); + python.execfile(path + module + ".py"); + PyObject func = python.get(method); return func; }