More concurrency fixes + Zombify + BPQ available
Fixed some inconsistencies due to race conditions in the project, added Zombify monster effect, made BPQ available and some minor patches.
This commit is contained in:
@@ -699,7 +699,8 @@ public class MapleStatEffect {
|
||||
AutobanFactory.MPCON.addPoint(applyfrom.getAutobanManager(), "mpCon hack for skill:" + sourceid + "; Player MP: " + applyto.getMp() + " MP Needed: " + getMpCon());
|
||||
} */
|
||||
if (hpchange != 0) {
|
||||
if (hpchange < 0 && (-hpchange) > applyto.getHp()) {
|
||||
if (hpchange < 0 && (-hpchange) > applyto.getHp() && !applyto.hasDisease(MapleDisease.ZOMBIFY)) {
|
||||
applyto.getClient().announce(MaplePacketCreator.enableActions());
|
||||
return false;
|
||||
}
|
||||
int newHp = applyto.getHp() + hpchange;
|
||||
@@ -712,6 +713,7 @@ public class MapleStatEffect {
|
||||
int newMp = applyto.getMp() + mpchange;
|
||||
if (mpchange != 0) {
|
||||
if (mpchange < 0 && -mpchange > applyto.getMp()) {
|
||||
applyto.getClient().announce(MaplePacketCreator.enableActions());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1037,12 +1039,18 @@ public class MapleStatEffect {
|
||||
} else {
|
||||
hpchange += hp;
|
||||
}
|
||||
} else {
|
||||
if (applyfrom.hasDisease(MapleDisease.ZOMBIFY)) {
|
||||
hpchange /= 2;
|
||||
}
|
||||
} else { // assumption: this is heal
|
||||
hpchange += makeHealHP(hp / 100.0, applyfrom.getTotalMagic(), 3, 5);
|
||||
if (applyfrom.hasDisease(MapleDisease.ZOMBIFY)) {
|
||||
hpchange = -hpchange;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hpR != 0) {
|
||||
hpchange += (int) (applyfrom.getCurrentMaxHp() * hpR);
|
||||
hpchange += (int) (applyfrom.getCurrentMaxHp() * hpR) / (applyfrom.hasDisease(MapleDisease.ZOMBIFY) ? 2 : 1);
|
||||
applyfrom.checkBerserk();
|
||||
}
|
||||
if (primary) {
|
||||
|
||||
108
src/server/events/BalrogPQ.java
Normal file
108
src/server/events/BalrogPQ.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package server.events;
|
||||
import client.MapleCharacter;
|
||||
import java.util.*;
|
||||
import server.life.MapleLifeFactory;
|
||||
import java.awt.Point;
|
||||
import server.maps.MapleMap;
|
||||
import server.TimerManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author FateJiki
|
||||
* @Mapid 105100300
|
||||
*/
|
||||
public class BalrogPQ {
|
||||
public static final int[] EasyBalrogParts = {8830002, 8830003, 8830000};
|
||||
public static final int[] HardBalrogParts = {8830000, 8830001, 8830002};
|
||||
public static List<MapleCharacter> candidates = new ArrayList<MapleCharacter>();
|
||||
public static boolean hasStarted = false;
|
||||
public static String partyLeader = "undefined";
|
||||
public static boolean balrogSpawned = false;
|
||||
public static long timeStamp = 0;
|
||||
public static byte channel = 1;
|
||||
|
||||
public static void addCandidate(MapleCharacter chr){
|
||||
synchronized(candidates){
|
||||
candidates.add(chr);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warpAllCandidates(){
|
||||
for(MapleCharacter c : candidates){
|
||||
c.changeMap(105100300);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFull(MapleCharacter chr){
|
||||
return chr.getClient().getChannelServer().getMapFactory().getMap(105100300).getCharacters().size() > 0;
|
||||
}
|
||||
|
||||
public static void warpIn(MapleCharacter chr){
|
||||
if(hasStarted){
|
||||
chr.changeMap(105100300);
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleChecks(MapleMap map){
|
||||
final MapleMap fmap = map;
|
||||
TimerManager tMan = TimerManager.getInstance();
|
||||
tMan.schedule(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
for(MapleCharacter chrs : fmap.getCharacters()){
|
||||
chrs.changeMap(105100100);
|
||||
chrs.message("You did not defeat the balrog in time..");
|
||||
close();
|
||||
}
|
||||
}
|
||||
} , 60 * 60 * 1000);
|
||||
|
||||
tMan.schedule(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
if(fmap.getCharacters().size() <= 3){
|
||||
if(fmap.getCharacters().size() > 0){
|
||||
for(MapleCharacter chrs : fmap.getCharacters()){
|
||||
chrs.message("[The Order]: What? You're down to that many mercenaries? I need you get you out of there.");
|
||||
chrs.changeMap(105100100);
|
||||
}
|
||||
}
|
||||
fmap.killAllMonsters();
|
||||
close();
|
||||
}
|
||||
}
|
||||
} , 60 * 1000);
|
||||
}
|
||||
|
||||
public static void open(MapleCharacter chr){
|
||||
channel = (byte)chr.getClient().getChannel();
|
||||
hasStarted = true;
|
||||
timeStamp = System.currentTimeMillis();
|
||||
scheduleChecks(chr.getClient().getChannelServer().getMapFactory().getMap(105100300));
|
||||
}
|
||||
|
||||
public static int getSecondsLeft(){ // assuming the thing lasts 60 minutes
|
||||
int hour = 60 * 60; // 3600 seconds = 1hr
|
||||
long elapsed = System.currentTimeMillis() - timeStamp;
|
||||
int secondsLeft = (int)(hour - (elapsed / 1000));
|
||||
return secondsLeft;
|
||||
}
|
||||
|
||||
public static void close(){
|
||||
hasStarted = false;
|
||||
balrogSpawned = false;
|
||||
partyLeader = "undefined";
|
||||
candidates.clear();
|
||||
timeStamp = 0;
|
||||
}
|
||||
public static void spawnBalrog(int mode, MapleCharacter chr){
|
||||
if(!balrogSpawned){
|
||||
for(int i = 0; i < HardBalrogParts.length; i++){
|
||||
chr.getClient().getChannelServer().getMapFactory().getMap(105100300).spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(HardBalrogParts[i]), new Point(412, 258));
|
||||
balrogSpawned = true;
|
||||
}
|
||||
} else {
|
||||
// DO NUFFIN'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public class MobSkill {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unhandeled Mob skill: " + skillId);
|
||||
System.out.println("Unhandled Mob skill: " + skillId);
|
||||
break;
|
||||
}
|
||||
if (stats.size() > 0) {
|
||||
|
||||
@@ -28,6 +28,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataProvider;
|
||||
import provider.MapleDataProviderFactory;
|
||||
@@ -42,20 +44,22 @@ public class MobSkillFactory {
|
||||
private static Map<String, MobSkill> mobSkills = new HashMap<String, MobSkill>();
|
||||
private final static MapleDataProvider dataSource = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Skill.wz"));
|
||||
private static MapleData skillRoot = dataSource.getData("MobSkill.img");
|
||||
private static ReentrantReadWriteLock dataLock = new ReentrantReadWriteLock();
|
||||
private final static ReentrantReadWriteLock dataLock = new ReentrantReadWriteLock();
|
||||
private final static ReadLock rL = dataLock.readLock();
|
||||
private final static WriteLock wL = dataLock.writeLock();
|
||||
|
||||
public static MobSkill getMobSkill(final int skillId, final int level) {
|
||||
final String key = skillId + "" + level;
|
||||
dataLock.readLock().lock();
|
||||
rL.lock();
|
||||
try {
|
||||
MobSkill ret = mobSkills.get(key);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
} finally {
|
||||
dataLock.readLock().unlock();
|
||||
rL.unlock();
|
||||
}
|
||||
dataLock.writeLock().lock();
|
||||
wL.lock();
|
||||
try {
|
||||
MobSkill ret;
|
||||
ret = mobSkills.get(key);
|
||||
@@ -103,7 +107,7 @@ public class MobSkillFactory {
|
||||
}
|
||||
return ret;
|
||||
} finally {
|
||||
dataLock.writeLock().unlock();
|
||||
wL.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ import tools.Pair;
|
||||
import tools.Randomizer;
|
||||
|
||||
public class MapleMap {
|
||||
|
||||
private static final List<MapleMapObjectType> rangedMapobjectTypes = Arrays.asList(MapleMapObjectType.SHOP, MapleMapObjectType.ITEM, MapleMapObjectType.NPC, MapleMapObjectType.MONSTER, MapleMapObjectType.DOOR, MapleMapObjectType.SUMMON, MapleMapObjectType.REACTOR);
|
||||
private Map<Integer, MapleMapObject> mapobjects = new LinkedHashMap<>();
|
||||
private Collection<SpawnPoint> monsterSpawn = Collections.synchronizedList(new LinkedList<SpawnPoint>());
|
||||
@@ -875,7 +874,13 @@ public class MapleMap {
|
||||
}
|
||||
|
||||
public Collection<MapleMapObject> getMapObjects() {
|
||||
return Collections.unmodifiableCollection(mapobjects.values());
|
||||
objectRLock.lock();
|
||||
try {
|
||||
return Collections.unmodifiableCollection(mapobjects.values());
|
||||
}
|
||||
finally {
|
||||
objectRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsNPC(int npcid) {
|
||||
@@ -898,7 +903,12 @@ public class MapleMap {
|
||||
}
|
||||
|
||||
public MapleMapObject getMapObject(int oid) {
|
||||
return mapobjects.get(oid);
|
||||
objectRLock.lock();
|
||||
try {
|
||||
return mapobjects.get(oid);
|
||||
} finally {
|
||||
objectRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1285,11 +1295,9 @@ public class MapleMap {
|
||||
|
||||
public void addPlayer(final MapleCharacter chr) {
|
||||
chrWLock.lock();
|
||||
chrRLock.lock();
|
||||
try {
|
||||
characters.add(chr);
|
||||
} finally {
|
||||
chrRLock.unlock();
|
||||
chrWLock.unlock();
|
||||
}
|
||||
chr.setMapId(mapid);
|
||||
@@ -1528,11 +1536,9 @@ public class MapleMap {
|
||||
|
||||
public void removePlayer(MapleCharacter chr) {
|
||||
chrWLock.lock();
|
||||
chrRLock.lock();
|
||||
try {
|
||||
characters.remove(chr);
|
||||
} finally {
|
||||
chrRLock.unlock();
|
||||
chrWLock.unlock();
|
||||
}
|
||||
removeMapObject(chr.getObjectId());
|
||||
@@ -1841,6 +1847,8 @@ public class MapleMap {
|
||||
player.setPosition(newPosition);
|
||||
Collection<MapleMapObject> visibleObjects = player.getVisibleMapObjects();
|
||||
MapleMapObject[] visibleObjectsNow = visibleObjects.toArray(new MapleMapObject[visibleObjects.size()]);
|
||||
|
||||
objectRLock.lock();
|
||||
try {
|
||||
for (MapleMapObject mo : visibleObjectsNow) {
|
||||
if (mo != null) {
|
||||
@@ -1853,7 +1861,10 @@ public class MapleMap {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
objectRLock.unlock();
|
||||
}
|
||||
|
||||
for (MapleMapObject mo : getMapObjectsInRange(player.getPosition(), 722500, rangedMapobjectTypes)) {
|
||||
if (!player.isMapObjectVisible(mo)) {
|
||||
mo.sendSpawnData(player.getClient());
|
||||
@@ -2399,17 +2410,22 @@ public class MapleMap {
|
||||
}
|
||||
|
||||
public void toggleHiddenNPC(int id) {
|
||||
for (MapleMapObject obj : mapobjects.values()) {
|
||||
if (obj.getType() == MapleMapObjectType.NPC) {
|
||||
MapleNPC npc = (MapleNPC) obj;
|
||||
if (npc.getId() == id) {
|
||||
npc.setHide(!npc.isHidden());
|
||||
if (!npc.isHidden()) //Should only be hidden upon changing maps
|
||||
{
|
||||
broadcastMessage(MaplePacketCreator.spawnNPC(npc));
|
||||
objectRLock.lock();
|
||||
try {
|
||||
for (MapleMapObject obj : mapobjects.values()) {
|
||||
if (obj.getType() == MapleMapObjectType.NPC) {
|
||||
MapleNPC npc = (MapleNPC) obj;
|
||||
if (npc.getId() == id) {
|
||||
npc.setHide(!npc.isHidden());
|
||||
if (!npc.isHidden()) //Should only be hidden upon changing maps
|
||||
{
|
||||
broadcastMessage(MaplePacketCreator.spawnNPC(npc));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
objectRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user