From 349eb3309077dc27a294be96839929e96aa76e04 Mon Sep 17 00:00:00 2001 From: Seefo Date: Tue, 1 Apr 2014 16:08:03 -0400 Subject: [PATCH] Added framework for bonus sets --- .../bonus_sets/set_bonus_jedi_robe.py | 15 ++++ .../wearables/robe/robe_jedi_light_s03.py | 4 +- src/main/NGECore.java | 2 + src/services/EquipmentService.java | 40 +++++++++- src/services/equipment/BonusSetTemplate.java | 75 +++++++++++++++++++ 5 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 scripts/equipment/bonus_sets/set_bonus_jedi_robe.py create mode 100644 src/services/equipment/BonusSetTemplate.java diff --git a/scripts/equipment/bonus_sets/set_bonus_jedi_robe.py b/scripts/equipment/bonus_sets/set_bonus_jedi_robe.py new file mode 100644 index 00000000..e95ceff4 --- /dev/null +++ b/scripts/equipment/bonus_sets/set_bonus_jedi_robe.py @@ -0,0 +1,15 @@ +import sys +from services.equipment import BonusSetTemplate +from java.util import Vector + +def addBonusSet(core): + bonusSet = BonusSetTemplate("set_bonus_jedi_robe") + bonusSet.addRequiredTemplate("object/tangible/wearables/necklace/shared_necklace_primitive_03.iff") + + core.equipmentService.addBonusSetTemplate(bonusSet) + +def handleEquip(core, creature, set): + wornItems = set.getWornTemplateCount(creature) + + if wornItems == 1: + print('Success!') \ No newline at end of file diff --git a/scripts/object/tangible/wearables/robe/robe_jedi_light_s03.py b/scripts/object/tangible/wearables/robe/robe_jedi_light_s03.py index ba7c4c85..abc45f94 100644 --- a/scripts/object/tangible/wearables/robe/robe_jedi_light_s03.py +++ b/scripts/object/tangible/wearables/robe/robe_jedi_light_s03.py @@ -11,6 +11,8 @@ def setup(core, object): object.setStringAttribute('protection_level', 'Luminous') object.setStringAttribute('class_required', 'Jedi') object.setIntAttribute('required_combat_level', 80) - object.setAttachment('type', 'jedi_robe') object.setStringAttribute('@set_bonus:piece_bonus_count_2', '@set_bonus:set_bonus_jedi_robe_1') + + object.setAttachment('type', 'jedi_robe') + object.setAttachment('setBonus', 'set_bonus_jedi_robe') return diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 88977fe3..9b9d392e 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -420,6 +420,8 @@ public class NGECore { spawnService.loadLairGroups(); spawnService.loadSpawnAreas(); + equipmentService.loadBonusSets(); + retroService.run(); didServerCrash = false; diff --git a/src/services/EquipmentService.java b/src/services/EquipmentService.java index 9995f4a7..5a324cde 100644 --- a/src/services/EquipmentService.java +++ b/src/services/EquipmentService.java @@ -21,10 +21,20 @@ ******************************************************************************/ package services; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import java.util.TreeMap; +import org.python.antlr.ast.Str; import org.python.core.Py; import org.python.core.PyObject; @@ -35,10 +45,13 @@ import engine.resources.objects.SWGObject; import engine.resources.service.INetworkDispatch; import engine.resources.service.INetworkRemoteEvent; import resources.objects.player.PlayerObject; +import services.equipment.BonusSetTemplate; +import services.spawn.MobileTemplate; public class EquipmentService implements INetworkDispatch { private NGECore core; + private Map bonusSetTemplates = new ConcurrentHashMap(); public EquipmentService(NGECore core) { this.core = core; @@ -217,13 +230,16 @@ public class EquipmentService implements INetworkDispatch { } if(item.getStringAttribute("proc_name") != null) core.buffService.addBuffToCreature(actor, item.getStringAttribute("proc_name").replace("@ui_buff:", ""), actor); - + if(item.getAttachment("setBonus") != null) + { + BonusSetTemplate bonus = bonusSetTemplates.get((String)item.getAttachment("setBonus")); + bonus.callScript(actor); + } if(!actor.getEquipmentList().contains(item)) actor.addObjectToEquipList(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", ""); @@ -277,4 +293,24 @@ public class EquipmentService implements INetworkDispatch { } + public void addBonusSetTemplate(BonusSetTemplate bonusSet) + { + bonusSetTemplates.put(bonusSet.getName(), bonusSet); + } + + public void loadBonusSets() { + Path p = Paths.get("scripts/equipment/bonus_sets/"); + 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); + return FileVisitResult.CONTINUE; + } + }; + try { + Files.walkFileTree(p, fv); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/services/equipment/BonusSetTemplate.java b/src/services/equipment/BonusSetTemplate.java new file mode 100644 index 00000000..3b965e0a --- /dev/null +++ b/src/services/equipment/BonusSetTemplate.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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.equipment; + +import java.util.Vector; + +import main.NGECore; + +import org.python.core.Py; +import org.python.core.PyObject; + +import engine.resources.objects.SWGObject; +import resources.objects.creature.CreatureObject; + +public class BonusSetTemplate +{ + private String name; + private Vector requiredWornTemplates; + + public BonusSetTemplate(String name) + { + this.name = name; + this.requiredWornTemplates = new Vector(); + } + + public void addRequiredTemplate(String template) + { + requiredWornTemplates.add(template); + } + + public String getName() + { + return this.name; + } + + public int getWornTemplateCount(CreatureObject creature) + { + int wornItems = 0; + + for (SWGObject item : creature.getEquipmentList().get()) + { + if(requiredWornTemplates.contains(item.getTemplate())) wornItems++; + } + + System.out.println("[BonusSetTemplate] Worn items: " + wornItems); + return wornItems; + } + + public void callScript(CreatureObject creature) + { + System.out.println("[BonusSetTemplate] Calling script for: " + this.getName()); + + PyObject func = NGECore.getInstance().scriptService.getMethod("scripts/equipment/bonus_sets/", name, "handleEquip"); + if(func != null) func.__call__(Py.java2py(NGECore.getInstance()), Py.java2py(creature), Py.java2py(this)); + } +}