Merge pull request #280 from Jamix77/master

Fixed everything
This commit is contained in:
Daniel Ginovker 2020-03-30 12:23:39 -04:00 committed by GitHub
commit 531dafa834
4 changed files with 19 additions and 76 deletions

View file

@ -11,24 +11,17 @@ import org.crandor.game.node.entity.npc.agg.AggressiveBehavior;
import org.crandor.game.node.entity.npc.agg.AggressiveHandler; import org.crandor.game.node.entity.npc.agg.AggressiveHandler;
import org.crandor.game.node.entity.player.Player; import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.info.Rights; import org.crandor.game.node.entity.player.info.Rights;
import org.crandor.game.node.item.GroundItemManager;
import org.crandor.game.node.item.Item; import org.crandor.game.node.item.Item;
import org.crandor.game.world.map.Location; import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.zone.MapZone; import org.crandor.game.world.map.zone.MapZone;
import org.crandor.game.world.map.zone.RegionZone; import org.crandor.game.world.map.zone.RegionZone;
import org.crandor.game.world.map.zone.ZoneBorders; import org.crandor.game.world.map.zone.ZoneBorders;
import org.crandor.game.world.repository.Repository;
import org.crandor.tools.RandomFunction;
/** /**
* Handles the wilderness zone. * Handles the wilderness zone.
* @author Emperor * @author Emperor
*/ */
public final class WildernessZone extends MapZone { public final class WildernessZone extends MapZone {
/**
* The PvP gear items
*/
private static int[] PVP_GEAR = { 13887, 13893, 13899, 13905, 13870, 13873, 13876, 13879, 13883, 13884, 13890, 13896, 13902, 13858, 13861, 13864, 13867};
/** /**
* The wilderness zone. * The wilderness zone.
@ -55,70 +48,6 @@ public final class WildernessZone extends MapZone {
} }
} }
/**
* calculate drop rate for rev items based on combat level
* @author ceik
* @param combatLevel
* @return
*/
public int getNewDropRate(int combatLevel){
double x = combatLevel;
double A = 44044.5491;
double B = -7360.19548;
return (int) (A + (B * Math.log(x)));
}
/**
* Handles rev drops
* @author ceik
* @param e The entity dying.
* @param killer The killer.
* @return true
*/
@Override
public boolean death(Entity e, Entity killer) {
if(e instanceof NPC && killer instanceof Player && (e.asNpc().getName().contains("Revenant") || e.asNpc().getName().equals("Chaos elemental"))){
int combatLevel = e.asNpc().getDefinition().getCombatLevel();
int dropRate = getNewDropRate(combatLevel);
for(int i = 0; i < PVP_GEAR.length; i++){
boolean chance = RandomFunction.random(dropRate) == dropRate / 2;
if(chance){
Item reward;
if(PVP_GEAR[i] == 13879 || PVP_GEAR[i] == 13883){ // checks if it's a javelin or throwing axe
reward = new Item(PVP_GEAR[i],RandomFunction.random(15,50));
} else {
reward = new Item(PVP_GEAR[i]);
}
Repository.sendNews(killer.asPlayer().getUsername() + " has received a " + reward.getName() + " from a " + e.asNpc().getName() + "!");
GroundItemManager.create(reward,((NPC) e).getDropLocation(),killer.asPlayer());
return true;
}
}
e.asNpc().getDefinition().getDropTables().drop(e.asNpc(),killer);
}
return true;
}
/**
* Fixes attack options for the revs
* @param e The entity.
* @param target The target to interact with.
* @param option The option.
* @return true
*/
@Override
public boolean interact(Entity e, Node target, Option option) {
if(target instanceof NPC){
if(target.asNpc().getName().contains("Revenant")){
e.asPlayer().getProperties().getCombatPulse().attack(target);
return true;
}
}
return super.interact(e, target, option);
}
@Override @Override
public boolean enter(Entity e) { public boolean enter(Entity e) {
if (e instanceof Player) { if (e instanceof Player) {

View file

@ -30,7 +30,7 @@ public class SlotSwitchPacket implements IncomingPacket {
if (withInterfaceId == 762) { if (withInterfaceId == 762) {
if (withChildId == 73) { if (withChildId == 73) {
container = player.getBank(); container = player.getBank();
switchItem(slot, secondSlot, container, player.getBank().isInsertItems()); switchItem(slot, secondSlot, container, player.getBank().isInsertItems(), player);
player.debug("Switching item [" + slot + ", " + interfaceId + ", " + childId + "] with [" + secondSlot + ", " + withInterfaceId + ", " + withChildId + "]!"); player.debug("Switching item [" + slot + ", " + interfaceId + ", " + childId + "] with [" + secondSlot + ", " + withInterfaceId + ", " + withChildId + "]!");
} }
else { else {
@ -54,7 +54,7 @@ public class SlotSwitchPacket implements IncomingPacket {
break; break;
default: default:
player.debug("Switching item slot [from=" + slot + ", to=" + secondSlot + ", child=" + childId + ", to child=" + withChildId + "]."); player.debug("Switching item slot [from=" + slot + ", to=" + secondSlot + ", child=" + childId + ", to child=" + withChildId + "].");
switchItem(slot, secondSlot, container, false); switchItem(slot, secondSlot, container, false, player);
break; break;
} }
return; return;
@ -65,7 +65,7 @@ public class SlotSwitchPacket implements IncomingPacket {
boolean insert = buffer.get() == 1; boolean insert = buffer.get() == 1;
int interfaceId = interfaceHash >> 16; int interfaceId = interfaceHash >> 16;
Container container = interfaceId == 762 ? player.getBank() : (interfaceId == 15 || interfaceId == 149 || interfaceId == 763) ? player.getInventory() : null; Container container = interfaceId == 762 ? player.getBank() : (interfaceId == 15 || interfaceId == 149 || interfaceId == 763) ? player.getInventory() : null;
switchItem(slot, secondSlot, container, insert); switchItem(slot, secondSlot, container, insert, player);
} }
/** /**
@ -75,12 +75,19 @@ public class SlotSwitchPacket implements IncomingPacket {
* @param container The container. * @param container The container.
* @param insert If inserting should happen. * @param insert If inserting should happen.
*/ */
public void switchItem(int slot, int secondSlot, Container container, boolean insert) { public void switchItem(int slot, int secondSlot, Container container, boolean insert, Player player) {
if (container == null || slot < 0 || slot >= container.toArray().length || secondSlot < 0 || secondSlot >= container.toArray().length) { if (container == null || slot < 0 || slot >= container.toArray().length || secondSlot < 0 || secondSlot >= container.toArray().length) {
return; return;
} }
final Item item = container.get(slot); final Item item = container.get(slot);
final Item second = container.get(secondSlot); final Item second = container.get(secondSlot);
if (player.getInterfaceManager().hasChatbox()) {
player.getInterfaceManager().closeChatbox();
switchItem(secondSlot,slot,container,insert,player);
container.refresh();
return;
}
if (item == null) { if (item == null) {
return; return;
} }

View file

@ -112,6 +112,13 @@ public class RevenantNPC extends AbstractNPC {
if (killer instanceof Player) { if (killer instanceof Player) {
killer.asPlayer().getAudioManager().send(4063, true); killer.asPlayer().getAudioManager().send(4063, true);
} }
int chance = RandomFunction.getRandom(120);
if (chance == 1) {
int item = RandomFunction.getRandom(PVP_DROPS.length - 1);
Item i = new Item(PVP_DROPS[item]);
GroundItemManager.create(i, itemLoc, killer.asPlayer());
Repository.sendNews(killer.getUsername() + " has just received a " + i.getName() + " from a " + getName() + ".");
}
} }
@Override @Override

View file

@ -30,7 +30,7 @@ public class RevenantPlugin implements Plugin<Object> {
/** /**
* The maximum amount of revenants spawned. * The maximum amount of revenants spawned.
*/ */
private static final int MAX = 50; private static final int MAX = 20;
@Override @Override
public Plugin<Object> newInstance(Object arg) throws Throwable { public Plugin<Object> newInstance(Object arg) throws Throwable {