/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package server.life;
import java.awt.Point;
import java.util.concurrent.atomic.AtomicBoolean;
import server.Randomizer;
import server.maps.MapleMap;
import tools.packet.CWvsContext;
public class SpawnPointAreaBoss extends Spawns {
private final MapleMonsterStats monster;
private final Point pos1;
private final Point pos2;
private final Point pos3;
private long nextPossibleSpawn;
private final int mobTime, fh, f, id;
private final AtomicBoolean spawned = new AtomicBoolean(false);
private final String msg;
public SpawnPointAreaBoss(final MapleMonster monster, final Point pos1, final Point pos2, final Point pos3, final int mobTime, final String msg, final boolean shouldSpawn) {
this.monster = monster.getStats();
this.id = monster.getId();
this.fh = monster.getFh();
this.f = monster.getF();
this.pos1 = pos1;
this.pos2 = pos2;
this.pos3 = pos3;
this.mobTime = (mobTime < 0 ? -1 : (mobTime * 1000));
this.msg = msg;
this.nextPossibleSpawn = System.currentTimeMillis() + (shouldSpawn ? 0 : this.mobTime);
}
@Override
public final int getF() {
return f;
}
@Override
public final int getFh() {
return fh;
}
@Override
public final MapleMonsterStats getMonster() {
return monster;
}
@Override
public final byte getCarnivalTeam() {
return -1;
}
@Override
public final int getCarnivalId() {
return -1;
}
@Override
public final boolean shouldSpawn(long time) {
if (mobTime < 0 || spawned.get()) {
return false;
}
return nextPossibleSpawn <= time;
}
@Override
public final Point getPosition() {
final int rand = Randomizer.nextInt(3);
return rand == 0 ? pos1 : rand == 1 ? pos2 : pos3;
}
@Override
public final MapleMonster spawnMonster(final MapleMap map) {
final Point pos = getPosition();
final MapleMonster mob = new MapleMonster(id, monster);
mob.setPosition(pos);
mob.setCy(pos.y);
mob.setRx0(pos.x - 50);
mob.setRx1(pos.x + 50); //these dont matter for mobs
mob.setFh(fh);
mob.setF(f);
spawned.set(true);
mob.addListener(new MonsterListener() {
@Override
public void monsterKilled() {
nextPossibleSpawn = System.currentTimeMillis();
if (mobTime > 0) {
nextPossibleSpawn += mobTime;
}
spawned.set(false);
}
});
map.spawnMonster(mob, -2);
if (msg != null) {
map.broadcastMessage(CWvsContext.broadcastMsg(6, msg));
}
return mob;
}
@Override
public final int getMobTime() {
return mobTime;
}
}