mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-09-12 22:45:31 -04:00
Start of FactionStanding, Custom Object Scripts
This commit is contained in:
@@ -51,6 +51,7 @@ import services.collections.CollectionService;
|
||||
import services.combat.CombatService;
|
||||
import services.command.CombatCommand;
|
||||
import services.command.CommandService;
|
||||
import services.gcw.FactionService;
|
||||
import services.gcw.GCWService;
|
||||
import services.guild.GuildService;
|
||||
import services.map.MapService;
|
||||
@@ -115,6 +116,7 @@ public class NGECore {
|
||||
public AttributeService attributeService;
|
||||
public SUIService suiService;
|
||||
public GuildService guildService;
|
||||
public FactionService factionService;
|
||||
public GCWService gcwService;
|
||||
public TradeService tradeService;
|
||||
public CombatService combatService;
|
||||
@@ -258,6 +260,9 @@ public class NGECore {
|
||||
guildService = new GuildService(this);
|
||||
zoneDispatch.addService(guildService);
|
||||
|
||||
factionService = new FactionService(this);
|
||||
zoneDispatch.addService(factionService);
|
||||
|
||||
gcwService = new GCWService(this);
|
||||
zoneDispatch.addService(gcwService);
|
||||
|
||||
@@ -274,7 +279,6 @@ public class NGECore {
|
||||
didServerCrash = false;
|
||||
System.out.println("Started Server.");
|
||||
setGalaxyStatus(2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,5 +55,6 @@ public class Opcodes {
|
||||
public static int ClientMfdStatusUpdateMessage = CRC.StringtoCRC("ClientMdfStatusUpdateMessage");
|
||||
public static int PlayMusicMessage = CRC.StringtoCRC("PlayMusicMessage");
|
||||
public static int PlanetTravelPointListRequest = 0x96405D4D;
|
||||
public static int FactionRequestMessage = CRC.StringtoCRC("FactionRequestMessage");
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import resources.objects.waypoint.WaypointObject;
|
||||
|
||||
@@ -119,6 +120,8 @@ public class PlayerObject extends SWGObject {
|
||||
@NotPersistent
|
||||
private long lastPlayTimeUpdate = System.currentTimeMillis();
|
||||
|
||||
private Map<String, Integer> factionStandingMap = new TreeMap<String, Integer>();
|
||||
|
||||
public PlayerObject() {
|
||||
super();
|
||||
messageBuilder = new PlayerMessageBuilder(this);
|
||||
@@ -537,7 +540,30 @@ public class PlayerObject extends SWGObject {
|
||||
this.jediState = jediState;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Integer> getFactionStandingMap() {
|
||||
return factionStandingMap;
|
||||
}
|
||||
|
||||
public void setFactionStanding(String faction, int factionStanding) {
|
||||
synchronized(objectMutex) {
|
||||
factionStandingMap.put(faction, ((factionStanding < -5000) ? -5000 : ((factionStanding > 5000) ? 5000 : factionStanding)));
|
||||
}
|
||||
}
|
||||
|
||||
public void modifyFactionStanding(String faction, int modifier) {
|
||||
synchronized(objectMutex) {
|
||||
int factionStanding = (((factionStandingMap.containsKey(faction)) ? factionStandingMap.get(faction) : 0) + modifier);
|
||||
factionStandingMap.put(faction, ((factionStanding < -5000) ? -5000 : ((factionStanding > 5000) ? 5000 : factionStanding)));
|
||||
}
|
||||
}
|
||||
|
||||
public int getFactionStanding(String faction) {
|
||||
synchronized(objectMutex) {
|
||||
return ((factionStandingMap.containsKey(faction)) ? factionStandingMap.get(faction) : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBaselines(Client destination) {
|
||||
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 <Project SWG>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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.gcw;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import main.NGECore;
|
||||
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
import org.python.core.Py;
|
||||
import org.python.core.PyObject;
|
||||
|
||||
import resources.common.FileUtilities;
|
||||
import resources.common.Opcodes;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.objects.player.PlayerObject;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
|
||||
import engine.clientdata.ClientFileManager;
|
||||
import engine.clientdata.visitors.DatatableVisitor;
|
||||
import engine.resources.common.CRC;
|
||||
import engine.resources.objects.SWGObject;
|
||||
import engine.resources.service.INetworkDispatch;
|
||||
import engine.resources.service.INetworkRemoteEvent;
|
||||
|
||||
public class FactionService implements INetworkDispatch {
|
||||
|
||||
private NGECore core;
|
||||
|
||||
private Map<String, Integer> factionMap = new TreeMap<String, Integer>();
|
||||
|
||||
public FactionService(NGECore core) {
|
||||
DatatableVisitor factionTable;
|
||||
|
||||
this.core = core;
|
||||
|
||||
try {
|
||||
factionTable = ClientFileManager.loadFile("strings/en/faction/faction_names.stf", DatatableVisitor.class);
|
||||
|
||||
for (int s = 0; s < factionTable.getRowCount(); s++) {
|
||||
if (factionTable.getObject(s, 0) != null) {
|
||||
String faction = ((String) factionTable.getObject(s, 1));
|
||||
factionMap.put(faction, CRC.StringtoCRC(faction));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCRC(String faction) {
|
||||
return CRC.StringtoCRC(faction);
|
||||
}
|
||||
|
||||
public String getName(int factionCrc) {
|
||||
for (Entry<String, Integer> entry : factionMap.entrySet()) {
|
||||
if (factionCrc == entry.getValue()) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public void addFactionStanding(CreatureObject creature, String faction, int factionStanding) {
|
||||
if (creature == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost");
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.modifyFactionStanding(faction, factionStanding);
|
||||
}
|
||||
|
||||
public void removeFactionStanding(CreatureObject creature, String faction, int factionStanding) {
|
||||
if (creature == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost");
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.modifyFactionStanding(faction, factionStanding);
|
||||
}
|
||||
|
||||
public void updateFactionStanding(SWGObject killedObject) {
|
||||
if (!(killedObject instanceof TangibleObject) || killedObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TangibleObject target = (TangibleObject) killedObject;
|
||||
|
||||
if (!(((TangibleObject) killedObject).getKiller() instanceof TangibleObject) || ((TangibleObject) killedObject).getKiller() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TangibleObject killer = ((TangibleObject) killedObject).getKiller();
|
||||
|
||||
if (killer != null && target != null && isFaction(target.getFaction())) {
|
||||
if (FileUtilities.doesFileExist("scripts/faction/standing/" + target.getFaction() + ".py")) {
|
||||
|
||||
PyObject method = core.scriptService.getMethod("scripts/faction/standing/", target.getFaction(), "update");
|
||||
|
||||
if (method != null && method.isCallable()) {
|
||||
method.__call__(Py.java2py(core), Py.java2py(killer), Py.java2py(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFaction(String faction) {
|
||||
if (factionMap.containsKey(faction)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getFactionMap() {
|
||||
return factionMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> swgOpcodes, Map<Integer, INetworkRemoteEvent> objControllerOpcodes) {
|
||||
|
||||
swgOpcodes.put(Opcodes.FactionRequestMessage, new INetworkRemoteEvent() {
|
||||
|
||||
@Override
|
||||
public void handlePacket(IoSession session, IoBuffer buffer) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation) {
|
||||
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation, String customServerTemplate) {
|
||||
SWGObject object = null;
|
||||
CrcStringTableVisitor crcTable;
|
||||
try {
|
||||
@@ -199,16 +199,49 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
object.setPlanetId(planet.getID());
|
||||
|
||||
object.setAttachment("serverTemplate", ((customServerTemplate != null) ? customServerTemplate : object.getTemplate()));
|
||||
|
||||
loadServerTemplate(object);
|
||||
|
||||
objectList.put(objectID, object);
|
||||
|
||||
|
||||
// Set Default Tangible Options
|
||||
/*
|
||||
if (Template.startsWith("object/creature/") || Template.startsWith("object/mobile/")) {
|
||||
((CreatureObject) object).setOptionsBitmask(Options.MOBILE);
|
||||
|
||||
if (Template.startsWith("object/mobile/beast_master/")) {
|
||||
((CreatureObject) object).setOptionsBitmask(Options.NONE);
|
||||
} else if (Template.startsWith("object/mobile/vendor/")) {
|
||||
((CreatureObject) object).setOptionsBitmask(Options.INVULNERABLE | Options.USABLE);
|
||||
} else if (Template.startsWith("object/mobile/vehicle/")) {
|
||||
((CreatureObject) object).addOption(Options.INVULNERABLE | Options.MOUNT);
|
||||
} else if (Template.startsWith("object/mobile/hologram/")) {
|
||||
((CreatureObject) object).addOption(Options.INVULNERABLE);
|
||||
} else if (Template.startsWith("object/creature/npc/theme_park/")) {
|
||||
((CreatureObject) object).addOption(Options.INVULNERABLE);
|
||||
} else if (Template.startsWith("object/creature/general/")) {
|
||||
((CreatureObject) object).setOptionsBitmask(Options.INVULNERABLE | Options.CONVERSABLE);
|
||||
} else if (Template.startsWith("object/creature/droid/")) {
|
||||
((CreatureObject) object).addOption(Options.INVULNERABLE);
|
||||
}
|
||||
} else if (object instanceof TangibleObject) {
|
||||
((TangibleObject) object).setOptionsBitmask(Options.INVULNERABLE);
|
||||
|
||||
if (Template.startsWith("object/tangible/vendor/")) {
|
||||
((CreatureObject) object).addOption(Options.USABLE);
|
||||
} else if (Template.startsWith("object/creature/droid/")) {
|
||||
((CreatureObject) object).addOption(Options.INVULNERABLE);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
public void loadServerTemplate(SWGObject object) {
|
||||
|
||||
String template = object.getTemplate();
|
||||
String template = ((object.getAttachment("serverTemplate") == null) ? object.getTemplate() : ((String) object.getAttachment("serverTemplate")));
|
||||
String serverTemplate = template.replace(".iff", "");
|
||||
// check if template is empty(4 default lines) to reduce RAM usage(saves about 500 MB of RAM)
|
||||
try {
|
||||
@@ -239,6 +272,10 @@ public class ObjectService implements INetworkDispatch {
|
||||
return createObject(Template, 0, planet, new Point3D(x, y, z), new Quaternion(1, 0, 0, 0));
|
||||
}
|
||||
|
||||
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation) {
|
||||
return createObject(Template, objectID, planet, position, orientation, null);
|
||||
}
|
||||
|
||||
public void addObjectToScene(SWGObject object) {
|
||||
|
||||
core.simulationService.add(object, object.getPosition().x, object.getPosition().z);
|
||||
@@ -296,6 +333,18 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
if (object instanceof CreatureObject) {
|
||||
if (core.factionService.getFactionMap().containsKey(((CreatureObject) object).getFaction())) {
|
||||
if (FileUtilities.doesFileExist(filePath)) {
|
||||
PyObject method = core.scriptService.getMethod("scripts/" + object.getTemplate().split("shared_" , 2)[0].replace("shared_", ""), object.getTemplate().split("shared_" , 2)[1].replace(".iff", ""), "destroy");
|
||||
|
||||
if (method != null && method.isCallable()) {
|
||||
method.__call__(Py.java2py(core), Py.java2py(((TangibleObject) object).getKiller()), Py.java2py(object));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (object == null) {
|
||||
return;
|
||||
}
|
||||
@@ -505,6 +554,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
objControllerOpcodes.put(ObjControllerOpcodes.USE_OBJECT, new INetworkRemoteEvent() {
|
||||
|
||||
@Override
|
||||
@@ -529,6 +579,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
|
||||
});
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user