Hit Reactor animation fix + deny spawn points
Fixed reactor sometimes not animating between state changes and introduced mechanic to deny spawning mobs at spawn points.
This commit is contained in:
@@ -31,7 +31,7 @@ public class SpawnPoint {
|
||||
private long nextPossibleSpawn;
|
||||
private int mobInterval = 5000;
|
||||
private AtomicInteger spawnedMonsters = new AtomicInteger(0);
|
||||
private boolean immobile;
|
||||
private boolean immobile, denySpawn = false;
|
||||
|
||||
public SpawnPoint(final MapleMonster monster, Point pos, boolean immobile, int mobTime, int mobInterval, int team) {
|
||||
this.monster = monster.getId();
|
||||
@@ -50,11 +50,15 @@ public class SpawnPoint {
|
||||
}
|
||||
|
||||
public void setDenySpawn(boolean val) {
|
||||
spawnedMonsters.set((val == false) ? 0 : 1);
|
||||
denySpawn = val;
|
||||
}
|
||||
|
||||
public boolean getDenySpawn() {
|
||||
return denySpawn;
|
||||
}
|
||||
|
||||
public boolean shouldSpawn() {
|
||||
if (mobTime < 0 || spawnedMonsters.get() > 0) {
|
||||
if (denySpawn || mobTime < 0 || spawnedMonsters.get() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ public class MapleMap {
|
||||
this.mapobjects.put(curOID, mapobject);
|
||||
for (MapleCharacter chr : characters) {
|
||||
if (condition == null || condition.canSpawn(chr)) {
|
||||
if (chr.getPosition().distanceSq(mapobject.getPosition()) <= 722500) {
|
||||
if (chr.getPosition().distanceSq(mapobject.getPosition()) <= getRangedDistance()) {
|
||||
packetbakery.sendPackets(chr.getClient());
|
||||
chr.addVisibleMapObject(mapobject);
|
||||
}
|
||||
@@ -310,7 +310,7 @@ public class MapleMap {
|
||||
mapobject.setObjectId(curOID);
|
||||
for (MapleCharacter chr : characters) {
|
||||
if (condition == null || condition.canSpawn(chr)) {
|
||||
if (chr.getPosition().distanceSq(mapobject.getPosition()) <= 722500) {
|
||||
if (chr.getPosition().distanceSq(mapobject.getPosition()) <= getRangedDistance()) {
|
||||
packetbakery.sendPackets(chr.getClient());
|
||||
chr.addVisibleMapObject(mapobject);
|
||||
}
|
||||
@@ -796,7 +796,14 @@ public class MapleMap {
|
||||
broadcastMessage(MaplePacketCreator.destroyReactor(reactor));
|
||||
reactor.setAlive(false);
|
||||
removeMapObject(reactor);
|
||||
reactor.setTimerActive(false);
|
||||
|
||||
reactor.lockReactor();
|
||||
try {
|
||||
reactor.setShouldCollect(true);
|
||||
} finally {
|
||||
reactor.unlockReactor();
|
||||
}
|
||||
|
||||
if (reactor.getDelay() > 0) {
|
||||
tMan.schedule(new Runnable() {
|
||||
@Override
|
||||
@@ -814,7 +821,14 @@ public class MapleMap {
|
||||
if (o.getType() == MapleMapObjectType.REACTOR) {
|
||||
final MapleReactor r = ((MapleReactor) o);
|
||||
r.setState((byte) 0);
|
||||
r.setTimerActive(false);
|
||||
|
||||
r.lockReactor();
|
||||
try {
|
||||
r.setShouldCollect(true);
|
||||
} finally {
|
||||
r.unlockReactor();
|
||||
}
|
||||
|
||||
broadcastMessage(MaplePacketCreator.triggerReactor(r, 0));
|
||||
}
|
||||
}
|
||||
@@ -1314,11 +1328,8 @@ public class MapleMap {
|
||||
if (react.getReactItem((byte) 0).getLeft() == item.getItemId() && react.getReactItem((byte) 0).getRight() == item.getQuantity()) {
|
||||
|
||||
if (react.getArea().contains(drop.getPosition())) {
|
||||
if (!react.isTimerActive()) {
|
||||
TimerManager.getInstance().schedule(new ActivateItemReactor(drop, react, c), 5000);
|
||||
react.setTimerActive(true);
|
||||
break;
|
||||
}
|
||||
TimerManager.getInstance().schedule(new ActivateItemReactor(drop, react, c), 5000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1633,7 +1644,7 @@ public class MapleMap {
|
||||
public void broadcastMessage(final byte[] packet) {
|
||||
broadcastMessage(null, packet, Double.POSITIVE_INFINITY, null);
|
||||
}
|
||||
|
||||
|
||||
public void broadcastGMMessage(final byte[] packet) {
|
||||
broadcastGMMessage(null, packet, Double.POSITIVE_INFINITY, null);
|
||||
}
|
||||
@@ -1658,7 +1669,7 @@ public class MapleMap {
|
||||
* @param ranged
|
||||
*/
|
||||
public void broadcastMessage(MapleCharacter source, final byte[] packet, boolean repeatToSource, boolean ranged) {
|
||||
broadcastMessage(repeatToSource ? null : source, packet, ranged ? 722500 : Double.POSITIVE_INFINITY, source.getPosition());
|
||||
broadcastMessage(repeatToSource ? null : source, packet, ranged ? getRangedDistance() : Double.POSITIVE_INFINITY, source.getPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1878,11 +1889,11 @@ public class MapleMap {
|
||||
|
||||
private void updateMapObjectVisibility(MapleCharacter chr, MapleMapObject mo) {
|
||||
if (!chr.isMapObjectVisible(mo)) { // monster entered view range
|
||||
if (mo.getType() == MapleMapObjectType.SUMMON || mo.getPosition().distanceSq(chr.getPosition()) <= 722500) {
|
||||
if (mo.getType() == MapleMapObjectType.SUMMON || mo.getPosition().distanceSq(chr.getPosition()) <= getRangedDistance()) {
|
||||
chr.addVisibleMapObject(mo);
|
||||
mo.sendSpawnData(chr.getClient());
|
||||
}
|
||||
} else if (mo.getType() != MapleMapObjectType.SUMMON && mo.getPosition().distanceSq(chr.getPosition()) > 722500) {
|
||||
} else if (mo.getType() != MapleMapObjectType.SUMMON && mo.getPosition().distanceSq(chr.getPosition()) > getRangedDistance()) {
|
||||
chr.removeVisibleMapObject(mo);
|
||||
mo.sendDestroyData(chr.getClient());
|
||||
}
|
||||
@@ -2081,30 +2092,38 @@ public class MapleMap {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (mapitem != null && mapitem == getMapObject(mapitem.getObjectId())) {
|
||||
mapitem.itemLock.lock();
|
||||
try {
|
||||
TimerManager tMan = TimerManager.getInstance();
|
||||
if (mapitem.isPickedUp()) {
|
||||
return;
|
||||
reactor.lockReactor();
|
||||
try {
|
||||
if (reactor.getShouldCollect() == true && mapitem != null && mapitem == getMapObject(mapitem.getObjectId())) {
|
||||
mapitem.itemLock.lock();
|
||||
try {
|
||||
TimerManager tMan = TimerManager.getInstance();
|
||||
if (mapitem.isPickedUp()) {
|
||||
return;
|
||||
}
|
||||
|
||||
reactor.setShouldCollect(false);
|
||||
MapleMap.this.broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 0, 0), mapitem.getPosition());
|
||||
MapleMap.this.removeMapObject(mapitem);
|
||||
reactor.hitReactor(c, true);
|
||||
|
||||
if (reactor.getDelay() > 0) {
|
||||
tMan.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reactor.setState((byte) 0);
|
||||
broadcastMessage(MaplePacketCreator.triggerReactor(reactor, 0));
|
||||
}
|
||||
}, reactor.getDelay());
|
||||
}
|
||||
} finally {
|
||||
mapitem.itemLock.unlock();
|
||||
}
|
||||
MapleMap.this.broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 0, 0), mapitem.getPosition());
|
||||
MapleMap.this.removeMapObject(mapitem);
|
||||
reactor.hitReactor(c);
|
||||
reactor.setTimerActive(false);
|
||||
if (reactor.getDelay() > 0) {
|
||||
tMan.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reactor.setState((byte) 0);
|
||||
broadcastMessage(MaplePacketCreator.triggerReactor(reactor, 0));
|
||||
}
|
||||
}, reactor.getDelay());
|
||||
}
|
||||
} finally {
|
||||
mapitem.itemLock.unlock();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reactor.unlockReactor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2168,6 +2187,15 @@ public class MapleMap {
|
||||
chrRLock.unlock();
|
||||
}
|
||||
|
||||
/*
|
||||
System.out.println("----------------------------------");
|
||||
for (SpawnPoint spawnPoint : monsterSpawn) {
|
||||
System.out.println("sp " + spawnPoint.getPosition().getX() + ", " + spawnPoint.getPosition().getY() + ": " + spawnPoint.getDenySpawn());
|
||||
}
|
||||
System.out.println("try " + monsterSpawn.size() + " - " + spawnedMonstersOnMap.get());
|
||||
System.out.println("----------------------------------");
|
||||
*/
|
||||
|
||||
short numShouldSpawn = (short) ((monsterSpawn.size() - spawnedMonstersOnMap.get()));//Fking lol'd
|
||||
if (numShouldSpawn > 0) {
|
||||
List<SpawnPoint> randomSpawn = new ArrayList<>(monsterSpawn);
|
||||
|
||||
@@ -26,6 +26,8 @@ import constants.ServerConstants;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import scripting.reactor.ReactorScriptManager;
|
||||
import server.TimerManager;
|
||||
@@ -43,21 +45,30 @@ public class MapleReactor extends AbstractMapleMapObject {
|
||||
private int delay;
|
||||
private MapleMap map;
|
||||
private String name;
|
||||
private boolean timerActive;
|
||||
private boolean alive;
|
||||
private boolean shouldCollect = true;
|
||||
private Lock reactorLock = new ReentrantLock(true);
|
||||
|
||||
public MapleReactor(MapleReactorStats stats, int rid) {
|
||||
this.stats = stats;
|
||||
this.rid = rid;
|
||||
alive = true;
|
||||
}
|
||||
|
||||
public void setTimerActive(boolean active) {
|
||||
this.timerActive = active;
|
||||
|
||||
public void setShouldCollect(boolean collect) {
|
||||
this.shouldCollect = collect;
|
||||
}
|
||||
|
||||
public boolean isTimerActive() {
|
||||
return timerActive;
|
||||
|
||||
public boolean getShouldCollect() {
|
||||
return shouldCollect;
|
||||
}
|
||||
|
||||
public void lockReactor() {
|
||||
reactorLock.lock();
|
||||
}
|
||||
|
||||
public void unlockReactor() {
|
||||
reactorLock.unlock();
|
||||
}
|
||||
|
||||
public void setState(byte state) {
|
||||
@@ -67,6 +78,10 @@ public class MapleReactor extends AbstractMapleMapObject {
|
||||
public byte getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public MapleReactorStats getStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return rid;
|
||||
@@ -129,7 +144,13 @@ public class MapleReactor extends AbstractMapleMapObject {
|
||||
|
||||
public void forceHitReactor(final byte newState) {
|
||||
setState((byte) newState);
|
||||
setTimerActive(false);
|
||||
try {
|
||||
this.lockReactor();
|
||||
this.setShouldCollect(true);
|
||||
}
|
||||
finally {
|
||||
this.unlockReactor();
|
||||
}
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, (short) 0));
|
||||
}
|
||||
|
||||
@@ -137,59 +158,61 @@ public class MapleReactor extends AbstractMapleMapObject {
|
||||
TimerManager.getInstance().schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hitReactor(c);
|
||||
hitReactor(c, false);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
public void hitReactor(MapleClient c) {
|
||||
hitReactor(0, (short) 0, 0, c);
|
||||
public void hitReactor(MapleClient c, boolean itemDrop) {
|
||||
hitReactor(0, (short) 0, 0, c, itemDrop);
|
||||
}
|
||||
|
||||
public synchronized void hitReactor(int charPos, short stance, int skillid, MapleClient c) {
|
||||
try {
|
||||
if(!this.isAlive()) {
|
||||
return;
|
||||
}
|
||||
if(ServerConstants.USE_DEBUG == true) c.getPlayer().dropMessage(5, "Hitted REACTOR " + this.getId() + " with POS " + charPos + " , STANCE " + stance + " , SkillID " + skillid);
|
||||
if (stats.getType(state) < 999 && stats.getType(state) != -1) {//type 2 = only hit from right (kerning swamp plants), 00 is air left 02 is ground left
|
||||
if (!(stats.getType(state) == 2 && (stance == 0 || stance == 2))) { //get next state
|
||||
for (byte b = 0; b < stats.getStateSize(state); b++) {//YAY?
|
||||
List<Integer> activeSkills = stats.getActiveSkills(state, b);
|
||||
if (activeSkills != null) {
|
||||
if (!activeSkills.contains(skillid)) continue;
|
||||
}
|
||||
state = stats.getNextState(state, b);
|
||||
if (stats.getNextState(state, b) == -1) {//end of reactor
|
||||
if (stats.getType(state) < 100) {//reactor broken
|
||||
if (delay > 0) {
|
||||
map.destroyReactor(getObjectId());
|
||||
} else {//trigger as normal
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
}
|
||||
} else {//item-triggered on final step
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
}
|
||||
|
||||
if(ServerConstants.USE_DEBUG == true) c.getPlayer().dropMessage(5, "REACTOR " + this.getId() + " activated");
|
||||
ReactorScriptManager.getInstance().act(c, this);
|
||||
} else { //reactor not broken yet
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
if (state == stats.getNextState(state, b)) {//current state = next state, looping reactor
|
||||
ReactorScriptManager.getInstance().act(c, this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state++;
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
ReactorScriptManager.getInstance().act(c, this);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
public synchronized void hitReactor(int charPos, short stance, int skillid, MapleClient c, boolean itemDrop) {
|
||||
try {
|
||||
if(!this.isAlive()) {
|
||||
return;
|
||||
}
|
||||
if(ServerConstants.USE_DEBUG == true) c.getPlayer().dropMessage(5, "Hitted REACTOR " + this.getId() + " with POS " + charPos + " , STANCE " + stance + " , SkillID " + skillid + " , STATE " + stats.getType(state) + " STATESIZE " + stats.getStateSize(state));
|
||||
int reactorType = stats.getType(state);
|
||||
|
||||
if (reactorType < 999 && reactorType != -1) {//type 2 = only hit from right (kerning swamp plants), 00 is air left 02 is ground left
|
||||
if (!(reactorType == 2 && (stance == 0 || stance == 2))) { //get next state
|
||||
for (byte b = 0; b < stats.getStateSize(state); b++) {//YAY?
|
||||
List<Integer> activeSkills = stats.getActiveSkills(state, b);
|
||||
if (activeSkills != null) {
|
||||
if (!activeSkills.contains(skillid)) continue;
|
||||
}
|
||||
state = stats.getNextState(state, b);
|
||||
if (stats.getNextState(state, b) == -1) {//end of reactor
|
||||
if (reactorType < 100) {//reactor broken
|
||||
if (delay > 0) {
|
||||
map.destroyReactor(getObjectId());
|
||||
} else {//trigger as normal
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
}
|
||||
} else {//item-triggered on final step
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
}
|
||||
|
||||
ReactorScriptManager.getInstance().act(c, this);
|
||||
} else { //reactor not broken yet
|
||||
if (itemDrop) state++; // Duh, if the reactor is triggered by itemdrop, go directly to next state (in this case, instead of staying at 1, it goes to 2)! :)
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
if (state == stats.getNextState(state, b) || itemDrop) {//current state = next state, looping reactor
|
||||
ReactorScriptManager.getInstance().act(c, this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state++;
|
||||
map.broadcastMessage(MaplePacketCreator.triggerReactor(this, stance));
|
||||
ReactorScriptManager.getInstance().act(c, this);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle getArea() {
|
||||
|
||||
Reference in New Issue
Block a user