diff --git a/ngengine_public.jar b/ngengine_public.jar index e7007eeb..71e72b65 100644 Binary files a/ngengine_public.jar and b/ngengine_public.jar differ diff --git a/src/main/NGECore.java b/src/main/NGECore.java index fca62567..1c03d1fb 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -28,6 +28,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import net.engio.mbassy.bus.config.BusConfiguration; @@ -145,6 +152,8 @@ public class NGECore { private ObjectDatabase creatureODB; private ObjectDatabase mailODB; + + private BusConfiguration eventBusConfig = BusConfiguration.Default(1, new ThreadPoolExecutor(1, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue())); public NGECore() { @@ -253,7 +262,7 @@ public class NGECore { terrainService.addPlanet(10, "dathomir", "terrain/dathomir.trn", true); terrainService.addPlanet(11, "mustafar", "terrain/mustafar.trn", true); terrainService.addPlanet(12, "kashyyyk_main", "terrain/kashyyyk_main.trn", true); - + terrainService.loadClientPois(); // Travel Points travelService.loadTravelPoints(); simulationService = new SimulationService(this); @@ -430,5 +439,10 @@ public class NGECore { public static NGECore getInstance() { return instance; } + + public BusConfiguration getEventBusConfig() { + return eventBusConfig; + } + } diff --git a/src/resources/common/collidables/AbstractCollidable.java b/src/resources/common/collidables/AbstractCollidable.java index ae20ceb1..dbdeed91 100644 --- a/src/resources/common/collidables/AbstractCollidable.java +++ b/src/resources/common/collidables/AbstractCollidable.java @@ -30,6 +30,7 @@ import org.python.core.PyObject; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; public abstract class AbstractCollidable { @@ -38,6 +39,7 @@ public abstract class AbstractCollidable { private Planet planet; public abstract boolean doesCollide(SWGObject obj); + public abstract boolean doesCollide(Point3D position); public PyObject getCallback() { return callback; diff --git a/src/resources/common/collidables/CollidableCircle.java b/src/resources/common/collidables/CollidableCircle.java index 15cdf75e..f17cab76 100644 --- a/src/resources/common/collidables/CollidableCircle.java +++ b/src/resources/common/collidables/CollidableCircle.java @@ -71,4 +71,13 @@ public class CollidableCircle extends AbstractCollidable { return center.getDistance(objectPos) <= radius; } } + + @Override + public boolean doesCollide(Point3D position) { + if(useYAxis) { + return center.getDistance(position) <= radius && position.y == center.y; + } else { + return center.getDistance(position) <= radius; + } + } } diff --git a/src/resources/objects/tangible/TangibleMessageBuilder.java b/src/resources/objects/tangible/TangibleMessageBuilder.java index b15e4bbd..fdb7142b 100644 --- a/src/resources/objects/tangible/TangibleMessageBuilder.java +++ b/src/resources/objects/tangible/TangibleMessageBuilder.java @@ -51,7 +51,7 @@ public class TangibleMessageBuilder extends ObjectMessageBuilder { buffer.put(getUnicodeString(object.getCustomName())); buffer.putInt(object.getVolume()); buffer.putInt(0); - buffer.putInt(0); // unknowns + buffer.putInt(0); // faction vars if(tangible.getCustomization() == null || tangible.getCustomization().length < 1) buffer.putShort((short) 0); @@ -59,12 +59,14 @@ public class TangibleMessageBuilder extends ObjectMessageBuilder { buffer.putShort((short) tangible.getCustomization().length); buffer.put(tangible.getCustomization()); } + + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(tangible.getOptionsBitmask()); - buffer.putInt(tangible.getIncapTimer()); + buffer.putInt(0); // number of item uses buffer.putInt(tangible.getConditionDamage()); buffer.putInt(tangible.getMaxDamage()); - buffer.putInt(0); - buffer.putInt(0x64); buffer.put((byte) (tangible.isStaticObject() ? 1 : 0)); int size = buffer.position(); @@ -123,6 +125,18 @@ public class TangibleMessageBuilder extends ObjectMessageBuilder { return buffer; } + public IoBuffer buildConditionDamageDelta(int conditionDamage) { + + IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(conditionDamage); + int size = buffer.position(); + buffer.flip(); + buffer = createDelta("TANO", (byte) 3, (short) 1, (short) 0x0A, buffer, size + 4); + + return buffer; + + } + @Override public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { // TODO Auto-generated method stub diff --git a/src/resources/objects/tangible/TangibleObject.java b/src/resources/objects/tangible/TangibleObject.java index 4fece110..d35baf08 100644 --- a/src/resources/objects/tangible/TangibleObject.java +++ b/src/resources/objects/tangible/TangibleObject.java @@ -29,6 +29,7 @@ import java.util.Vector; import protocol.swg.ObjControllerMessage; import protocol.swg.PlayClientEffectObjectMessage; import protocol.swg.StopClientEffectObjectByLabel; +import protocol.swg.UpdatePVPStatusMessage; import protocol.swg.objectControllerObjects.ShowFlyText; import resources.common.RGB; @@ -57,7 +58,7 @@ public class TangibleObject extends SWGObject { protected byte[] customization; private List componentCustomizations = new ArrayList(); protected int optionsBitmask = 0; - private int maxDamage = 0; + private int maxDamage = 1000; private boolean staticObject = false; protected String faction = ""; @NotPersistent @@ -92,12 +93,17 @@ public class TangibleObject extends SWGObject { this.incapTimer = incapTimer; } - public int getConditionDamage() { + public synchronized int getConditionDamage() { return conditionDamage; } - public void setConditionDamage(int conditionDamage) { + public synchronized void setConditionDamage(int conditionDamage) { + if(conditionDamage < 0) + conditionDamage = 0; + else if(conditionDamage > getMaxDamage()) + conditionDamage = getMaxDamage(); this.conditionDamage = conditionDamage; + notifyObservers(messageBuilder.buildConditionDamageDelta(conditionDamage), false); } public byte[] getCustomization() { @@ -142,7 +148,7 @@ public class TangibleObject extends SWGObject { public int getPvPBitmask() { synchronized(objectMutex) { - return optionsBitmask; + return pvpBitmask; } } @@ -291,6 +297,11 @@ public class TangibleObject extends SWGObject { destination.getSession().write(messageBuilder.buildBaseline8()); destination.getSession().write(messageBuilder.buildBaseline9()); + UpdatePVPStatusMessage upvpm = new UpdatePVPStatusMessage(getObjectID()); + upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Neutral); + upvpm.setStatus(1); + destination.getSession().write(upvpm.serialize()); + } diff --git a/src/services/SimulationService.java b/src/services/SimulationService.java index cfd1671b..b52b2de9 100644 --- a/src/services/SimulationService.java +++ b/src/services/SimulationService.java @@ -68,8 +68,10 @@ import protocol.swg.objectControllerObjects.TargetUpdate; import resources.objects.cell.CellObject; import resources.objects.creature.CreatureObject; import resources.objects.player.PlayerObject; +import resources.objects.tangible.TangibleObject; import resources.common.*; import resources.common.collidables.AbstractCollidable; +import services.ai.LairActor; import toxi.geom.Line3D; import toxi.geom.Ray3D; import toxi.geom.Vec3D; @@ -543,11 +545,9 @@ public class SimulationService implements INetworkDispatch { CreatureObject object = (CreatureObject) client.getParent(); Quaternion orientation = object.getOrientation(); Point3D position = object.getPosition(); - - Point3D pos = object.getWorldPosition(); - + Collection newAwareObjects = get(object.getPlanet(), pos.x, pos.z, 512); for(Iterator it = newAwareObjects.iterator(); it.hasNext();) { SWGObject obj = it.next(); @@ -561,6 +561,7 @@ public class SimulationService implements INetworkDispatch { if(object.getParentId() == 0) add(object, pos.x, pos.z); + PlayerObject ghost = (PlayerObject) object.getSlottedObject("ghost"); if (ghost != null) { diff --git a/src/services/TerrainService.java b/src/services/TerrainService.java index 789f54f9..eb1c9808 100644 --- a/src/services/TerrainService.java +++ b/src/services/TerrainService.java @@ -26,9 +26,17 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import resources.common.FileUtilities; +import resources.common.collidables.CollidableCircle; + +import engine.clientdata.ClientFileManager; +import engine.clientdata.visitors.DatatableVisitor; import engine.resources.config.Config; +import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; import main.NGECore; @@ -36,13 +44,66 @@ public class TerrainService { private NGECore core; private List planets = Collections.synchronizedList(new ArrayList()); + private Map> noBuildAreas = new ConcurrentHashMap>(); public TerrainService(NGECore core) { - - this.core = core; - + this.core = core; } + public void loadClientPois() { + + try { + + DatatableVisitor poiTable = ClientFileManager.loadFile("datatables/clientpoi/clientpoi.iff", DatatableVisitor.class); + + for (int i = 0; i < poiTable.getRowCount(); i++) { + + Planet planet = getPlanetByName((String) poiTable.getObject(i, 0)); + + if(planet == null) + continue; + + float x = (Float) poiTable.getObject(i, 4); + float z = (Float) poiTable.getObject(i, 6); + + CollidableCircle poiArea = new CollidableCircle(new Point3D(x, 0, z), 150, planet); + noBuildAreas.get(planet).add(poiArea); + + } + + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + + } + + private void loadClientRegions(Planet planet) { + + if(!FileUtilities.doesFileExist("datatables/clientregion/" + planet.getName() + ".iff")) + return; + + try { + + DatatableVisitor regionTable = ClientFileManager.loadFile("datatables/clientpoi/clientpoi.iff", DatatableVisitor.class); + + for (int i = 0; i < regionTable.getRowCount(); i++) { + + float x = (Float) regionTable.getObject(i, 1); + float z = (Float) regionTable.getObject(i, 2); + float radius = (Float) regionTable.getObject(i, 3); + + CollidableCircle region = new CollidableCircle(new Point3D(x, 0, z), radius, planet); + noBuildAreas.get(planet).add(region); + + } + + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + + } + + public boolean isWater(int planetId, float x, float z) { if(getPlanetByID(planetId) == null) @@ -112,6 +173,8 @@ public class TerrainService { Planet planet = new Planet(ID, name, path, loadSnapshot); planets.add(planet); core.mapService.addPlanet(planet); + noBuildAreas.put(planet, new ArrayList()); + loadClientRegions(planet); } @@ -157,6 +220,21 @@ public class TerrainService { } + public boolean canBuildAtPosition(SWGObject object, float x, float z) { + + if(isWater(object.getPlanet(), z, z)) + return false; + + Point3D position = new Point3D(x, 0, z); + + for(CollidableCircle noBuildArea : noBuildAreas.get(object.getPlanet())) { + if(noBuildArea.doesCollide(position)) + return false; + } + + return true; + + } diff --git a/src/services/ai/AIActor.java b/src/services/ai/AIActor.java index edb0a500..bb8efca5 100644 --- a/src/services/ai/AIActor.java +++ b/src/services/ai/AIActor.java @@ -23,11 +23,14 @@ package services.ai; import engine.resources.scene.Point3D; import resources.objects.creature.CreatureObject; +import services.ai.states.AIState; public class AIActor { private CreatureObject creature; private Point3D spawnPosition; + private volatile AIState currentState; + private CreatureObject followObject; public AIActor(CreatureObject creature, Point3D spawnPosition) { this.creature = creature; @@ -54,4 +57,24 @@ public class AIActor { } + public AIState getCurrentState() { + return currentState; + } + + public void setCurrentState(AIState currentState) { + if(currentState == this.currentState) + return; + this.currentState.onExit(); + this.currentState = currentState; + currentState.onEnter(); + } + + public CreatureObject getFollowObject() { + return followObject; + } + + public void setFollowObject(CreatureObject followObject) { + this.followObject = followObject; + } + } diff --git a/src/services/ai/AIService.java b/src/services/ai/AIService.java index 7c130f8b..f55abe6a 100644 --- a/src/services/ai/AIService.java +++ b/src/services/ai/AIService.java @@ -21,6 +21,28 @@ ******************************************************************************/ package services.ai; +import java.util.Vector; + +import engine.resources.scene.Point3D; + +import main.NGECore; + public class AIService { + + private Vector aiActors = new Vector(); + private NGECore core; + + public AIService(NGECore core) { + this.core = core; + } + + public void spawnCreature(String template, float x, float y, float z) { + spawnCreature(template, new Point3D(x, y, z)); + } + + public void spawnCreature(String template, Point3D position) { + + } + } diff --git a/src/services/ai/LairActor.java b/src/services/ai/LairActor.java index 1e7b3d6e..09043e82 100644 --- a/src/services/ai/LairActor.java +++ b/src/services/ai/LairActor.java @@ -22,10 +22,7 @@ package services.ai; import java.util.Vector; - import net.engio.mbassy.listener.Handler; - -import resources.objects.creature.CreatureObject; import resources.objects.tangible.TangibleObject; import services.combat.CombatEvents.DamageTaken; @@ -116,6 +113,17 @@ public class LairActor { private void healLair() { + if(lairObject.getConditionDamage() == 0 || creatures.isEmpty()) + return; + + int healAmount = 0; + + for(AIActor ai : creatures) { + healAmount += lairObject.getMaxDamage() / 100; + } + + lairObject.setConditionDamage(lairObject.getConditionDamage() - healAmount); + lairObject.playEffectObject("clienteffect/healing_healdamage.cef", "root"); } diff --git a/src/services/ai/states/AIState.java b/src/services/ai/states/AIState.java new file mode 100644 index 00000000..3da9131c --- /dev/null +++ b/src/services/ai/states/AIState.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.ai.states; + +public abstract class AIState { + + public abstract byte onEnter(); + public abstract byte onExit(); + public abstract byte move(); + public abstract byte recover(); + + public enum StateResult {; + + // default error state result + public static final byte NONE = 0; + // finished with state + public static final byte FINISHED = 1; + // unfinished with state, call recover() + public static final byte UNFINISHED = 2; + public static final byte DEAD = 3; + // for deaggro or idling + public static final byte IDLE = 4; + + } + + + +} diff --git a/src/services/ai/states/AttackState.java b/src/services/ai/states/AttackState.java new file mode 100644 index 00000000..fedb6112 --- /dev/null +++ b/src/services/ai/states/AttackState.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.ai.states; + +public class AttackState extends AIState { + + @Override + public byte onEnter() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte onExit() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte move() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte recover() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/services/ai/states/DeathState.java b/src/services/ai/states/DeathState.java new file mode 100644 index 00000000..aee6e323 --- /dev/null +++ b/src/services/ai/states/DeathState.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.ai.states; + +public class DeathState extends AIState { + + @Override + public byte onEnter() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte onExit() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte move() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte recover() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/services/ai/states/IdleState.java b/src/services/ai/states/IdleState.java new file mode 100644 index 00000000..597630e9 --- /dev/null +++ b/src/services/ai/states/IdleState.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.ai.states; + +public class IdleState extends AIState { + + @Override + public byte onEnter() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte onExit() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte move() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte recover() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/services/ai/states/PatrolState.java b/src/services/ai/states/PatrolState.java new file mode 100644 index 00000000..81e4eace --- /dev/null +++ b/src/services/ai/states/PatrolState.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.ai.states; + +public class PatrolState extends AIState { + + @Override + public byte onEnter() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte onExit() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte move() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte recover() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/services/ai/states/RetreatState.java b/src/services/ai/states/RetreatState.java new file mode 100644 index 00000000..64e4fa71 --- /dev/null +++ b/src/services/ai/states/RetreatState.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.ai.states; + +public class RetreatState extends AIState { + + @Override + public byte onEnter() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte onExit() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte move() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte recover() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/services/ai/states/SpawnState.java b/src/services/ai/states/SpawnState.java new file mode 100644 index 00000000..4d46a557 --- /dev/null +++ b/src/services/ai/states/SpawnState.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.ai.states; + +public class SpawnState extends AIState { + + @Override + public byte onEnter() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte onExit() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte move() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte recover() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/services/combat/CombatEvents.java b/src/services/combat/CombatEvents.java index 7814df76..f41a0098 100644 --- a/src/services/combat/CombatEvents.java +++ b/src/services/combat/CombatEvents.java @@ -24,7 +24,7 @@ package services.combat; import resources.objects.creature.CreatureObject; import engine.resources.common.Event; -public class CombatEvents { +public class CombatEvents implements Event { public class DamageTaken implements Event { diff --git a/src/services/combat/CombatService.java b/src/services/combat/CombatService.java index 423ecdbb..06a84ce2 100644 --- a/src/services/combat/CombatService.java +++ b/src/services/combat/CombatService.java @@ -48,6 +48,7 @@ import resources.objects.player.PlayerObject; import resources.objects.tangible.TangibleObject; import resources.objects.waypoint.WaypointObject; import resources.objects.weapon.WeaponObject; +import services.combat.CombatEvents.DamageTaken; import services.command.CombatCommand; import services.sui.SUIService.MessageBoxType; import services.sui.SUIWindow; @@ -64,6 +65,7 @@ public class CombatService implements INetworkDispatch { private NGECore core; private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + private CombatEvents events = new CombatEvents(); public CombatService(NGECore core) { this.core = core; @@ -240,8 +242,24 @@ public class CombatService implements INetworkDispatch { } float damage = calculateDamage(attacker, target, weapon, command); + + if(damage > 0) + applyDamage(attacker, target, (int) damage); + + sendCombatPackets(attacker, target, weapon, command, actionCounter, damage, 0, HitType.HIT); + + if(FileUtilities.doesFileExist("scripts/commands/combat/" + command.getCommandName() + ".py")) + core.scriptService.callScript("scripts/commands/combat/", command.getCommandName(), "run", core, attacker, target, null); + } + private void applyDamage(CreatureObject attacker, TangibleObject target, int damage) { + target.setConditionDamage(target.getConditionDamage() + damage); + DamageTaken event = events.new DamageTaken(); + event.attacker = attacker; + target.getEventBus().publish(event); + } + private void doAreaCombat(CreatureObject attacker, CreatureObject target, WeaponObject weapon, CombatCommand command, int actionCounter) { float x = attacker.getWorldPosition().x; @@ -358,7 +376,7 @@ public class CombatService implements INetworkDispatch { } - private void sendCombatPackets(CreatureObject attacker, CreatureObject target, WeaponObject weapon, CombatCommand command, int actionCounter, float damage, int armorAbsorbed, int hitType) { + private void sendCombatPackets(CreatureObject attacker, TangibleObject target, WeaponObject weapon, CombatCommand command, int actionCounter, float damage, int armorAbsorbed, int hitType) { String animationStr = command.getRandomAnimation(weapon); diff --git a/src/services/spawn/DynamicSpawnArea.java b/src/services/spawn/DynamicSpawnArea.java new file mode 100644 index 00000000..09aafcd3 --- /dev/null +++ b/src/services/spawn/DynamicSpawnArea.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.spawn; + +public class DynamicSpawnArea extends SpawnArea { + +} diff --git a/src/services/spawn/LairSpawnArea.java b/src/services/spawn/LairSpawnArea.java new file mode 100644 index 00000000..63dc0200 --- /dev/null +++ b/src/services/spawn/LairSpawnArea.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.spawn; + +public class LairSpawnArea extends SpawnArea { + +} diff --git a/src/services/spawn/SpawnArea.java b/src/services/spawn/SpawnArea.java new file mode 100644 index 00000000..342749a5 --- /dev/null +++ b/src/services/spawn/SpawnArea.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.spawn; + +import engine.resources.scene.Planet; + +public abstract class SpawnArea { + + private Planet planet; + + public Planet getPlanet() { + return planet; + } + + public void setPlanet(Planet planet) { + this.planet = planet; + } + +} diff --git a/src/services/spawn/SpawnService.java b/src/services/spawn/SpawnService.java new file mode 100644 index 00000000..7c6435e3 --- /dev/null +++ b/src/services/spawn/SpawnService.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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.spawn; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import engine.resources.scene.Planet; +import main.NGECore; + +public class SpawnService { + + private NGECore core; + private Map> spawnAreas = new ConcurrentHashMap>(); + + public SpawnService(NGECore core) { + + } + +} diff --git a/src/services/spawn/StaticSpawnArea.java b/src/services/spawn/StaticSpawnArea.java new file mode 100644 index 00000000..9a0911fd --- /dev/null +++ b/src/services/spawn/StaticSpawnArea.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.spawn; + +public class StaticSpawnArea extends SpawnArea { + +}