Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize Stats of Deathmatch & Adventure Island Creatures #723

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 19 additions & 0 deletions src/games/stendhal/server/entity/creature/Creature.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -368,6 +369,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
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 Down Expand Up @@ -163,7 +163,7 @@ public Creature calculateNextCreature(final int questLevel) {
*/
DeathMatchCreature spawnNewCreature(final Creature template, final Player player, final DeathmatchInfo deathmatchInfo) {
DeathMatchCreature creature = new DeathMatchCreature(
new ArenaCreature(template.getNewInstance(), deathmatchInfo.getArena().getShape()), deathmatchInfo);
new ArenaCreature(template.getNewInstanceRandomizeStats(), deathmatchInfo.getArena().getShape()), deathmatchInfo);

if (StendhalRPAction.placeat(deathmatchInfo.getZone(), creature, player.getX(), player.getY(), deathmatchInfo.getArena().getShape())) {
creature.clearDropItemList();
Expand Down
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 Down Expand Up @@ -89,6 +89,8 @@ private void init(final Player player) {
creature = new Creature(creatureSpawner.calculateNextCreature(level));
}

// randomize stats
creature = creature.getNewInstanceRandomizeStats();
if (StendhalRPAction.placeat(this, creature, Rand.randUniform(MIN_X, MAX_X),
Rand.randUniform(MIN_Y, MAX_Y))) {
numCreatures++;
Expand Down
Loading