diff --git a/src/games/stendhal/server/core/rule/defaultruleset/DefaultCreature.java b/src/games/stendhal/server/core/rule/defaultruleset/DefaultCreature.java index 8066baff781..32a6e0aa279 100644 --- a/src/games/stendhal/server/core/rule/defaultruleset/DefaultCreature.java +++ b/src/games/stendhal/server/core/rule/defaultruleset/DefaultCreature.java @@ -1,6 +1,6 @@ /* $Id$ */ /*************************************************************************** - * (C) Copyright 2003-2013 - Marauroa * + * (C) Copyright 2003-2024 - Marauroa * *************************************************************************** *************************************************************************** * * @@ -382,6 +382,16 @@ public int compare(final DropItem o1, final DropItem o2) { return creature; } + /** + * Creates a creature instance with randomized stats. + * + * @return + * New creature instance. + */ + public Creature getCreatureRandomizeStats() { + return getCreature().getNewInstanceRandomizeStats(); + } + /** @return the tileid. */ public String getTileId() { return tileid; diff --git a/src/games/stendhal/server/entity/creature/Creature.java b/src/games/stendhal/server/entity/creature/Creature.java index 895a563e0d3..21943234305 100644 --- a/src/games/stendhal/server/entity/creature/Creature.java +++ b/src/games/stendhal/server/entity/creature/Creature.java @@ -28,6 +28,7 @@ import games.stendhal.common.Rand; import games.stendhal.common.constants.Nature; import games.stendhal.common.constants.SoundLayer; +import games.stendhal.common.constants.Testing; import games.stendhal.server.core.engine.SingletonRepository; import games.stendhal.server.core.engine.StendhalRPRuleProcessor; import games.stendhal.server.core.engine.StendhalRPZone; @@ -372,6 +373,24 @@ public Creature getNewInstance() { return new Creature(this); } + /** + * Creates a new creature with randomized stats using this instance as a template. + * + * @return + * New creature instance. + */ + public Creature getNewInstanceRandomizeStats() { + final Creature newInstance = getNewInstance(); + // A bit of randomization to make Joan and Snaketails a bit happier. + // :) + newInstance.setAtk(Rand.randGaussian(newInstance.getAtk(), newInstance.getAtk() / 10)); + newInstance.setDef(Rand.randGaussian(newInstance.getDef(), newInstance.getDef() / 10)); + if (Testing.COMBAT) { + newInstance.setRatk(Rand.randGaussian(newInstance.getRatk(), newInstance.getRatk() / 10)); + } + return newInstance; + } + /** * Sets the sound played at creature's death * diff --git a/src/games/stendhal/server/entity/mapstuff/spawner/CreatureRespawnPoint.java b/src/games/stendhal/server/entity/mapstuff/spawner/CreatureRespawnPoint.java index 7d71e7fa533..b81fd3919a0 100644 --- a/src/games/stendhal/server/entity/mapstuff/spawner/CreatureRespawnPoint.java +++ b/src/games/stendhal/server/entity/mapstuff/spawner/CreatureRespawnPoint.java @@ -250,18 +250,9 @@ public StendhalRPZone getZone() { * Pops up a new creature. */ protected void respawn() { - try { // clone the prototype creature - final Creature newentity = prototypeCreature.getNewInstance(); - - // A bit of randomization to make Joan and Snaketails a bit happier. - // :) - newentity.setAtk(Rand.randGaussian(newentity.getAtk(), - newentity.getAtk() / 10)); - newentity.setDef(Rand.randGaussian(newentity.getDef(), - newentity.getDef() / 10)); - + final Creature newentity = prototypeCreature.getNewInstanceRandomizeStats(); newentity.registerObjectsForNotification(observers); if (StendhalRPAction.placeat(zone, newentity, x, y)) {