Introducing Boss Rush PQ. Corrected a few issues regarding rewardings in PiratePQ and EllinPQ and implemented a standardized way to script PQs.
166 lines
5.9 KiB
Java
166 lines
5.9 KiB
Java
/*
|
|
This file is part of the OdinMS Maple Story Server
|
|
Copyright (C) 2008 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 as
|
|
published by the Free Software Foundation 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 scripting.reactor;
|
|
|
|
import client.MapleClient;
|
|
import client.inventory.Equip;
|
|
import client.inventory.Item;
|
|
import client.inventory.MapleInventoryType;
|
|
import java.awt.Point;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import scripting.AbstractPlayerInteraction;
|
|
import server.MapleItemInformationProvider;
|
|
import server.life.MapleLifeFactory;
|
|
import server.life.MapleNPC;
|
|
import server.maps.MapMonitor;
|
|
import server.maps.MapleReactor;
|
|
import server.maps.ReactorDropEntry;
|
|
import tools.MaplePacketCreator;
|
|
|
|
/**
|
|
* @author Lerk
|
|
*/
|
|
public class ReactorActionManager extends AbstractPlayerInteraction {
|
|
private MapleReactor reactor;
|
|
private MapleClient client;
|
|
|
|
public ReactorActionManager(MapleClient c, MapleReactor reactor) {
|
|
super(c);
|
|
this.reactor = reactor;
|
|
this.client = c;
|
|
}
|
|
|
|
public void dropItems() {
|
|
dropItems(false, 0, 0, 0, 0);
|
|
}
|
|
|
|
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso) {
|
|
dropItems(meso, mesoChance, minMeso, maxMeso, 0);
|
|
}
|
|
|
|
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
|
dropItems((int)reactor.getPosition().getX(), (int)reactor.getPosition().getY(), meso, mesoChance, minMeso, maxMeso, minItems);
|
|
}
|
|
|
|
public void dropItems(int posX, int posY, boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
|
List<ReactorDropEntry> chances = getDropChances();
|
|
List<ReactorDropEntry> items = new LinkedList<>();
|
|
int numItems = 0;
|
|
if (meso && Math.random() < (1 / (double) mesoChance)) {
|
|
items.add(new ReactorDropEntry(0, mesoChance, -1));
|
|
}
|
|
Iterator<ReactorDropEntry> iter = chances.iterator();
|
|
while (iter.hasNext()) {
|
|
ReactorDropEntry d = iter.next();
|
|
if (Math.random() < (c.getPlayer().getDropRate() / (double) d.chance)) {
|
|
numItems++;
|
|
items.add(d);
|
|
}
|
|
}
|
|
while (items.size() < minItems) {
|
|
items.add(new ReactorDropEntry(0, mesoChance, -1));
|
|
numItems++;
|
|
}
|
|
java.util.Collections.shuffle(items);
|
|
|
|
final Point dropPos = new Point(posX, posY);
|
|
dropPos.x -= (12 * numItems);
|
|
|
|
for (ReactorDropEntry d : items) {
|
|
if (d.itemId == 0) {
|
|
int range = maxMeso - minMeso;
|
|
int displayDrop = (int) (Math.random() * range) + minMeso;
|
|
int mesoDrop = (displayDrop * client.getWorldServer().getMesoRate());
|
|
reactor.getMap().spawnMesoDrop(mesoDrop, dropPos, reactor, client.getPlayer(), false, (byte) 2);
|
|
} else {
|
|
Item drop;
|
|
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
|
if (ii.getInventoryType(d.itemId) != MapleInventoryType.EQUIP) {
|
|
drop = new Item(d.itemId, (short) 0, (short) 1);
|
|
} else {
|
|
drop = ii.randomizeStats((Equip) ii.getEquipById(d.itemId));
|
|
}
|
|
reactor.getMap().spawnItemDrop(reactor, getPlayer(), drop, dropPos, false, false);
|
|
}
|
|
dropPos.x += 25;
|
|
}
|
|
}
|
|
|
|
private List<ReactorDropEntry> getDropChances() {
|
|
return ReactorScriptManager.getInstance().getDrops(reactor.getId());
|
|
}
|
|
|
|
public void spawnMonster(int id) {
|
|
spawnMonster(id, 1, getPosition());
|
|
}
|
|
|
|
public void createMapMonitor(int mapId, String portal) {
|
|
new MapMonitor(client.getChannelServer().getMapFactory().getMap(mapId), portal);
|
|
}
|
|
|
|
public void spawnMonster(int id, int qty) {
|
|
spawnMonster(id, qty, getPosition());
|
|
}
|
|
|
|
public void spawnMonster(int id, int qty, int x, int y) {
|
|
spawnMonster(id, qty, new Point(x, y));
|
|
}
|
|
|
|
private void spawnMonster(int id, int qty, Point pos) {
|
|
for (int i = 0; i < qty; i++) {
|
|
reactor.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(id), pos);
|
|
}
|
|
}
|
|
|
|
public Point getPosition() {
|
|
Point pos = reactor.getPosition();
|
|
pos.y -= 10;
|
|
return pos;
|
|
}
|
|
|
|
public void spawnNpc(int npcId) {
|
|
spawnNpc(npcId, getPosition());
|
|
}
|
|
|
|
public void spawnNpc(int npcId, Point pos) {
|
|
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
|
|
if (npc != null) {
|
|
npc.setPosition(pos);
|
|
npc.setCy(pos.y);
|
|
npc.setRx0(pos.x + 50);
|
|
npc.setRx1(pos.x - 50);
|
|
npc.setFh(reactor.getMap().getFootholds().findBelow(pos).getId());
|
|
reactor.getMap().addMapObject(npc);
|
|
reactor.getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc));
|
|
}
|
|
}
|
|
|
|
public MapleReactor getReactor() {
|
|
return reactor;
|
|
}
|
|
|
|
public void spawnFakeMonster(int id) {
|
|
reactor.getMap().spawnFakeMonsterOnGroundBelow(MapleLifeFactory.getMonster(id), getPosition());
|
|
}
|
|
} |