Pest control refactor

This commit is contained in:
dginovker 2019-06-15 18:32:00 -04:00
parent 223f1e33bf
commit 0ecae80828
16 changed files with 76 additions and 36 deletions

View file

@ -11,6 +11,8 @@ import org.crandor.net.amsc.WorldCommunicator;
import org.crandor.tools.TimeStamp;
import org.crandor.tools.backup.AutoBackup;
import java.net.BindException;
/**
* The main class, for those that are unable to read the class' name.
* @author Emperor
@ -51,7 +53,14 @@ public final class Main{
SQLManager.init();
Runtime.getRuntime().addShutdownHook(new Thread(new SystemShutdownHook()));
SystemLogger.log("Starting NIO reactor...");
reactor = NioReactor.configure(43594 + GameWorld.getSettings().getWorldId());
try {
reactor = NioReactor.configure(43594 + GameWorld.getSettings().getWorldId());
} catch (BindException e) {
System.out.println("Port " + 43594 + GameWorld.getSettings().getWorldId() + " is already in use!");
throw e;
}
WorldCommunicator.connect();
reactor.start();
SystemLogger.log(GameWorld.getName() + " flags " + GameWorld.getSettings().toString());

View file

@ -231,7 +231,7 @@ public class AIPlayer extends Player {
ArrayList<Node> nodeList = getNodeInRange(range, entry);
if (nodeList.isEmpty())
{
System.out.println("nodelist empty");
//System.out.println("nodelist empty");
return null;
}
Node node = getClosestNodeinNodeList(nodeList);
@ -243,7 +243,7 @@ public class AIPlayer extends Player {
ArrayList<Node> nodeList = getNodeInRange(range, entrys);
if (nodeList.isEmpty())
{
System.out.println("nodelist empty");
//System.out.println("nodelist empty");
return null;
}
Node node = getClosestNodeinNodeList(nodeList);
@ -297,7 +297,7 @@ public class AIPlayer extends Player {
{
if (nodes.isEmpty())
{
System.out.println("nodelist empty");
//System.out.println("nodelist empty");
return null;
}

View file

@ -1,38 +1,41 @@
package org.crandor.game.node.entity.player.ai.pvmbots;
package org.crandor.game.node.entity.player.ai.minigamebots;
import java.util.ArrayList;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.player.ai.AIPlayer;
import org.crandor.game.node.entity.player.link.TeleportManager.TeleportType;
import org.crandor.game.node.entity.player.ai.pvmbots.PvMBots;
import org.crandor.game.node.entity.player.link.prayer.*;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.zone.impl.WildernessZone;
import org.crandor.net.packet.in.InteractionPacket;
import org.crandor.tools.RandomFunction;
import plugin.activity.pestcontrol.PCLanderZone;
public class PestControlTestBot extends PvMBots{
import static plugin.activity.pestcontrol.PestControlHelper.*;
public class PestControlTestBot extends PvMBots {
private int tick = 0;
private int movetimer = 0;
public PestControlTestBot(String name, Location l) {
super(name, l);
super(name, legitimizeLocation(l));
// TODO Auto-generated constructor stub
}
private static Location legitimizeLocation(Location l) {
return PCLanderZone.landerContainsLoc(l) ? new Location(2657, 2639, 0) : l;
}
@Override
public void tick()
{
super.tick();
Node test = getClosestNodeWithEntry(15, 14315);
Node test = getClosestNodeWithEntry(15, NOVICE_GANGPLANK);
if (test != null) {
int x = test.getLocation().getX();
int y = test.getLocation().getY();
if (this.getLocation() != new Location(2660, 2638))
if (!this.getLocation().equals(new Location(2660, 2638)))
InteractionPacket.handleObjectInteraction(this, 0, x, y, test.getId());
}

View file

@ -6,6 +6,7 @@ import org.crandor.game.container.impl.EquipmentContainer;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.entity.combat.CombatSpell;
import org.crandor.game.node.entity.player.ai.AIPlayer;
import org.crandor.game.node.entity.player.ai.minigamebots.PestControlTestBot;
import org.crandor.game.node.entity.player.link.SpellBookManager;
import org.crandor.game.node.entity.player.link.appearance.Gender;
import org.crandor.game.node.item.Item;

View file

@ -5,6 +5,7 @@ import org.crandor.game.node.Node;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.object.GameObject;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.zone.MapZone;
import org.crandor.game.world.map.zone.ZoneBorders;
import org.crandor.game.world.map.zone.ZoneRestriction;
@ -89,11 +90,20 @@ public final class PCLanderZone extends MapZone {
return super.leave(e, logout);
}
private static ZoneBorders boatA = new ZoneBorders(2659, 2637, 2664, 2664); //I should probably find the real names
private static ZoneBorders boatB = new ZoneBorders(2637, 2641, 2642, 2648);
private static ZoneBorders boatC = new ZoneBorders(2631, 2648, 2636, 2655);
@Override
public void configure() {
register(new ZoneBorders(2659, 2637, 2664, 2664));
register(new ZoneBorders(2637, 2641, 2642, 2648));
register(new ZoneBorders(2631, 2648, 2636, 2655));
register(boatA);
register(boatB);
register(boatC);
}
public static boolean landerContainsLoc(Location l)
{
return boatA.insideBorder(l) || boatB.insideBorder(l) || boatC.insideBorder(l);
}
}

View file

@ -12,6 +12,8 @@ import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.RegionPlane;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.tools.RandomFunction;
import plugin.activity.pestcontrol.monsters.PCRavagerNPC;
import plugin.activity.pestcontrol.monsters.PCSpinnerNPC;
/**
* Handles the portal NPC.

View file

@ -1,7 +1,6 @@
package plugin.activity.pestcontrol;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.crandor.ServerConstants;
@ -29,6 +28,7 @@ import org.crandor.plugin.PluginManager;
import org.crandor.tools.RandomFunction;
import org.crandor.plugin.InitializablePlugin;
import org.crandor.tools.StringUtils;
import plugin.activity.pestcontrol.monsters.*;
/**
* Handles the Pest Control activity.
@ -74,24 +74,24 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
@Override
public boolean pulse() {
for (Iterator<PestControlSession> it = sessions.iterator(); it.hasNext();) {
PestControlSession session = it.next();
if (session != null && session.update()) {
it.remove();
sessions.removeIf(session -> session != null && session.update());
ticks++;
if (waitingPlayers.size() >= MAX_TEAM_SIZE && ticks < 575)
{
ticks = 585;
}
if ((ticks < 450 && ticks % 100 == 0) || (ticks % 50 == 0) || ticks == 596) {
for (Player p : waitingPlayers) {
updateTime(p);
}
}
if (++ticks >= 500) { // 500
if (ticks >= 500) { // 500
if (waitingPlayers.size() >= MIN_TEAM_SIZE) {
PestControlActivityPlugin.this.start();
} else {
ticks = 400;
}
}
if ((ticks < 450 && ticks % 100 == 0) || (ticks % 50 == 0)) {
for (Player p : waitingPlayers) {
updateTime(p);
}
}
return false;
}
};
@ -105,6 +105,7 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
session.getRegion().getRegionZones().add(new RegionZone(this, session.getRegion().getBorders()));
sessions.add(session);
ticks = 0;
updatePlayerCount();
}
/**

View file

@ -0,0 +1,5 @@
package plugin.activity.pestcontrol;
public class PestControlHelper {
public static final int NOVICE_GANGPLANK = 14315;
}

View file

@ -18,6 +18,8 @@ import org.crandor.game.world.map.RegionPlane;
import org.crandor.game.world.map.build.DynamicRegion;
import org.crandor.tools.RandomFunction;
import static plugin.activity.pestcontrol.PestControlActivityPlugin.MAX_TEAM_SIZE;
/**
* Represents a pest control session.
* @author Emperor
@ -219,7 +221,7 @@ public final class PestControlSession {
for (Iterator<Player> it = waitingPlayers.iterator(); it.hasNext();) {
Player p = it.next();
if (p.getSession().isActive()) {
if (++count > 25) {
if (++count > MAX_TEAM_SIZE) {
int priority = p.getAttribute("pc_prior", 0) + 1;
p.getPacketDispatch().sendMessage("You have been given priority level " + priority + " over other players in joining the next");
p.getPacketDispatch().sendMessage("game.");

View file

@ -11,6 +11,7 @@ import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.plugin.Plugin;
import org.crandor.tools.RandomFunction;
import plugin.activity.pestcontrol.monsters.*;
/**
* Handles the void knight seal.

View file

@ -1,4 +1,4 @@
package plugin.activity.pestcontrol;
package plugin.activity.pestcontrol.monsters;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.combat.BattleState;
@ -10,6 +10,7 @@ import org.crandor.game.node.entity.npc.AbstractNPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.MapDistance;
import plugin.activity.pestcontrol.PestControlSession;
/**
* Handles the Defiler NPCs.

View file

@ -1,4 +1,4 @@
package plugin.activity.pestcontrol;
package plugin.activity.pestcontrol.monsters;
import org.crandor.game.interaction.MovementPulse;
import org.crandor.game.node.Node;
@ -15,6 +15,7 @@ import org.crandor.game.world.map.MapDistance;
import org.crandor.game.world.map.path.Pathfinder;
import org.crandor.game.world.map.zone.ZoneBorders;
import org.crandor.tools.RandomFunction;
import plugin.activity.pestcontrol.PestControlSession;
/**
* Handles the Ravager pest control NPC.

View file

@ -1,4 +1,4 @@
package plugin.activity.pestcontrol;
package plugin.activity.pestcontrol.monsters;
import java.util.ArrayList;
import java.util.Collections;
@ -20,6 +20,7 @@ import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.tools.RandomFunction;
import plugin.activity.pestcontrol.PestControlSession;
/**
* Handles the pest control shifter NPCs.

View file

@ -1,4 +1,4 @@
package plugin.activity.pestcontrol;
package plugin.activity.pestcontrol.monsters;
import org.crandor.game.interaction.MovementPulse;
import org.crandor.game.node.entity.Entity;
@ -16,6 +16,7 @@ import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.tools.RandomFunction;
import plugin.activity.pestcontrol.PestControlSession;
/**
* Handles a pest control spinner NPC.

View file

@ -1,4 +1,4 @@
package plugin.activity.pestcontrol;
package plugin.activity.pestcontrol.monsters;
import java.util.ArrayList;
@ -17,6 +17,7 @@ import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.tools.RandomFunction;
import plugin.activity.pestcontrol.PestControlSession;
/**
* Handles the pest control splatter NPC.

View file

@ -1,4 +1,4 @@
package plugin.activity.pestcontrol;
package plugin.activity.pestcontrol.monsters;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.combat.BattleState;
@ -18,6 +18,7 @@ import org.crandor.game.world.map.MapDistance;
import org.crandor.game.world.update.flag.context.Animation;
import org.crandor.game.world.update.flag.context.Graphics;
import org.crandor.plugin.Plugin;
import plugin.activity.pestcontrol.PestControlSession;
/**
* Handles the torcher pest control NPC.