Made familiar code more testable

Fixed an issue with the bloated leech "blood drain" ability
This commit is contained in:
Ceikry
2023-07-31 15:08:47 +00:00
parent ee79b0750c
commit 105f7d5b86
6 changed files with 168 additions and 26 deletions
@@ -23,7 +23,7 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<
override fun login(player: Player) {
if(player.isArtificial) return
val instance = content.global.ame.RandomEventManager(player)
val instance = RandomEventManager(player)
player.hook(Event.Tick, instance)
setAttribute(player, "random-manager", instance)
instance.rollNextSpawn()
@@ -66,7 +66,7 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<
}
private fun rollNextSpawn() {
nextSpawn = GameWorld.ticks + RandomFunction.random(content.global.ame.RandomEventManager.Companion.MIN_DELAY_TICKS, content.global.ame.RandomEventManager.Companion.MAX_DELAY_TICKS)
nextSpawn = GameWorld.ticks + RandomFunction.random(MIN_DELAY_TICKS, MAX_DELAY_TICKS)
}
override fun defineCommands() {
@@ -77,16 +77,16 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<
if (target == null)
reject(player, "Unable to find player $username!")
content.global.ame.RandomEventManager.Companion.getInstance(target!!)?.fireEvent()
getInstance(target!!)?.fireEvent()
}
}
companion object {
const val AVG_DELAY_TICKS = 6000 // 60 minutes
const val MIN_DELAY_TICKS = content.global.ame.RandomEventManager.Companion.AVG_DELAY_TICKS / 2
const val MAX_DELAY_TICKS = content.global.ame.RandomEventManager.Companion.MIN_DELAY_TICKS + content.global.ame.RandomEventManager.Companion.AVG_DELAY_TICKS // window of 60 min centered on 60 min (30 to 90 min)
var AVG_DELAY_TICKS = 6000 // 60 minutes
var MIN_DELAY_TICKS = AVG_DELAY_TICKS / 2
var MAX_DELAY_TICKS = MIN_DELAY_TICKS + AVG_DELAY_TICKS // window of 60 min centered on 60 min (30 to 90 min)
@JvmStatic fun getInstance(player: Player): content.global.ame.RandomEventManager?
@JvmStatic fun getInstance(player: Player): RandomEventManager?
{
return getAttribute(player, "random-manager", null)
}
@@ -39,14 +39,18 @@ public class BloatedLeechNPC extends Familiar {
@Override
protected boolean specialMove(FamiliarSpecial special) {
curePoison(owner);
curePoison(owner);
removeTimer(owner, "disease");
for (int i = 0; i < Skills.SKILL_NAME.length; i++) {
if (owner.getSkills().getLevel(i) < owner.getSkills().getStaticLevel(i)) {
owner.getSkills().setLevel(i, owner.getSkills().getStaticLevel(i));
owner.getSkills().updateLevel(
i,
(int) Math.ceil(owner.getSkills().getStaticLevel(i) * 0.2),
owner.getSkills().getStaticLevel(i)
);
}
}
owner.getSkills().rechargePrayerPoints();
getImpactHandler().manualHit(owner, RandomFunction.random(2), HitsplatType.NORMAL);
owner.getImpactHandler().manualHit(owner, RandomFunction.random(1, 5), HitsplatType.NORMAL);
return true;
}
@@ -347,26 +347,26 @@ public abstract class Familiar extends NPC implements Plugin<Object> {
* Checks if the familiar can execute its special move and does so if able.
* @param special The familiar special object.
*/
public void executeSpecialMove(FamiliarSpecial special) {
public boolean executeSpecialMove(FamiliarSpecial special) {
if (special.getNode() == this) {
return;
return false;
}
if (specialCost > specialPoints) {
owner.getPacketDispatch().sendMessage("Your familiar does not have enough special move points left.");
return;
return false;
}
SummoningScroll scroll = SummoningScroll.forPouch(pouchId);
if (scroll == null) {
owner.getPacketDispatch().sendMessage("Invalid scroll for pouch " + pouchId + " - report!");
return;
return false;
}
if (!owner.getInventory().contains(scroll.getItemId(), 1)) {
owner.getPacketDispatch().sendMessage("You do not have enough scrolls left to do this special move.");
return;
return false;
}
if (owner.getLocation().getDistance(getLocation()) > 15) {
owner.getPacketDispatch().sendMessage("Your familiar is too far away to use that scroll, or it cannot see you.");
return;
return false;
}
if (specialMove(special)) {
setAttribute("special-delay", GameWorld.getTicks() + 3);
@@ -376,6 +376,7 @@ public abstract class Familiar extends NPC implements Plugin<Object> {
updateSpecialPoints(specialCost);
owner.getSkills().addExperience(Skills.SUMMONING, scroll.getExperience(), true);
}
return true;
}
/**