Skip to content

Commit

Permalink
Move creature stats randomization to Creature class
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 14, 2024
1 parent b9fd3df commit 925fd14
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2013 - Marauroa *
* (C) Copyright 2003-2024 - Marauroa *
***************************************************************************
***************************************************************************
* *
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 20 additions & 1 deletion src/games/stendhal/server/entity/creature/Creature.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2023 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -26,6 +26,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;
Expand Down Expand Up @@ -370,6 +371,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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 925fd14

Please sign in to comment.