forked from arianne/stendhal
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for dynamic creature spawning
Position of spawn in zone is random instead of a static point arianne#713
- Loading branch information
1 parent
e6958eb
commit 0e80963
Showing
6 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/games/stendhal/server/core/config/zone/CreatureSpawnsXMLReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*************************************************************************** | ||
* Copyright © 2024 - Faiumoni e. V. * | ||
*************************************************************************** | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
package games.stendhal.server.core.config.zone; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.w3c.dom.Element; | ||
|
||
import games.stendhal.common.MathHelper; | ||
import games.stendhal.server.core.engine.StendhalRPZone; | ||
import games.stendhal.server.entity.mapstuff.spawner.DynamicCreatureSpawner; | ||
|
||
|
||
/** | ||
* Parses info for dynamically spawned creatures. | ||
*/ | ||
public class CreatureSpawnsXMLReader extends SetupXMLReader { | ||
|
||
private static Logger logger = Logger.getLogger(CreatureSpawnsXMLReader.class); | ||
|
||
|
||
@Override | ||
public SetupDescriptor read(final Element element) { | ||
final CreatureSpawnsDescriptor desc = new CreatureSpawnsDescriptor(); | ||
readParameters(desc, element); | ||
return desc; | ||
} | ||
|
||
private static class CreatureSpawnsDescriptor extends SetupDescriptor { | ||
@Override | ||
public void setup(final StendhalRPZone zone) { | ||
final DynamicCreatureSpawner spawner = new DynamicCreatureSpawner(zone); | ||
final Map<String, String> params = getParameters(); | ||
for (final String name: params.keySet()) { | ||
final int max = MathHelper.parseIntDefault(params.get(name), 0); | ||
if (max < 0) { | ||
logger.warn("Max must be a positive integer, not registering dynamic spawn for creature \"" + name + "\""); | ||
continue; | ||
} | ||
spawner.register(name, max); | ||
} | ||
// NOTE: does zone need to know about dynamic spawner? | ||
zone.setDynamicSpawner(spawner); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.