mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Rewrote the music system to use regions
This commit is contained in:
parent
58d9101ef6
commit
d15b47fc65
6 changed files with 2664 additions and 1677 deletions
File diff suppressed because it is too large
Load diff
2530
Server/data/configs/music_regions.json
Normal file
2530
Server/data/configs/music_regions.json
Normal file
File diff suppressed because it is too large
Load diff
62
Server/data/configs/music_tiles.json
Normal file
62
Server/data/configs/music_tiles.json
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
[
|
||||
{
|
||||
"id": "98",
|
||||
"borders": "{3072,3456,3135,3519,[3076,3456,3085,3458]~,[3082,3459,3085,3460]}"
|
||||
},
|
||||
{
|
||||
"id": "141",
|
||||
"borders": "{3072,3392,3135,3455,[3076,3452,3085,3455]}"
|
||||
},
|
||||
{
|
||||
"id": "228",
|
||||
"borders": "{2896,5446,2919,5462}"
|
||||
},
|
||||
{
|
||||
"id": "229",
|
||||
"borders": "{2921,5456,2937,5479}"
|
||||
},
|
||||
{
|
||||
"id": "230",
|
||||
"borders": "{2904,5481,2927,5497}"
|
||||
},
|
||||
{
|
||||
"id": "231",
|
||||
"borders": "{2886,5464,2902,5487}"
|
||||
},
|
||||
{
|
||||
"id": "386",
|
||||
"borders": "{2820,5312,2849,5369}-{2849,5349,2880,5374}"
|
||||
},
|
||||
{
|
||||
"id": "391",
|
||||
"borders": "{2879,5340,2944,5366}-{2909,5316,2944,5340}"
|
||||
},
|
||||
{
|
||||
"id": "399",
|
||||
"borders": "{2816,5248,2943,5375,[2823,5250,2844,5310]~,[2844,5250,2878,5280]~,[2879,5340,2944,5366]~,[2909,5316,2944,5340]~,[2820,5312,2849,5369]~,[2849,5349,2880,5374]~,[2885,5253,2934,5278]~,[2913,5278,2937,5306]}"
|
||||
},
|
||||
{
|
||||
"id": "404",
|
||||
"borders": "{2823,5250,2844,5310}-{2844,5250,2878,5276}"
|
||||
},
|
||||
{
|
||||
"id": "408",
|
||||
"borders": "{2885,5253,2934,5278}-{2913,5278,2937,5306}"
|
||||
},
|
||||
{
|
||||
"id": "459",
|
||||
"borders": "{3137,5442,3192,5564}-{3193,5442,3198,5472}-{3193,5507,3198,5564}"
|
||||
},
|
||||
{
|
||||
"id": "467",
|
||||
"borders": "{3199,5441,3262,5564}-{3193,5482,3198,5497}"
|
||||
},
|
||||
{
|
||||
"id": "488",
|
||||
"borders": "{3263,5441,3327,5566}"
|
||||
},
|
||||
{
|
||||
"id": "492",
|
||||
"borders": "{3076,3452,3085,3460,[3076,3459,3081,3460]}"
|
||||
}
|
||||
]
|
||||
|
|
@ -22,10 +22,7 @@ class MusicConfigLoader {
|
|||
val parser = JSONParser()
|
||||
var reader: FileReader? = null
|
||||
fun load(){
|
||||
var count = 0
|
||||
reader = FileReader(ServerConstants.CONFIG_PATH + "music_configs.json")
|
||||
var configs = parser.parse(reader) as JSONArray
|
||||
|
||||
// Populate the server data map
|
||||
val songs = DataMap.get(1351)
|
||||
val names = DataMap.get(1345)
|
||||
|
||||
|
|
@ -35,6 +32,23 @@ class MusicConfigLoader {
|
|||
MusicEntry.getSongs().putIfAbsent(songId, entry)
|
||||
}
|
||||
|
||||
// Parse the region-wide music config file
|
||||
var count = 0
|
||||
reader = FileReader(ServerConstants.CONFIG_PATH + "music_regions.json")
|
||||
var configs = parser.parse(reader) as JSONArray
|
||||
for(config in configs) {
|
||||
val e = config as JSONObject
|
||||
val region = Integer.parseInt(e["region"].toString())
|
||||
val id = Integer.parseInt(e["id"].toString())
|
||||
RegionManager.forId(region).music = MusicEntry.forId(id)
|
||||
count++
|
||||
log(this::class.java, Log.FINE, "Parsed $count region music configs.")
|
||||
}
|
||||
|
||||
// Parse the file with tile-specific music locations
|
||||
count = 0
|
||||
reader = FileReader(ServerConstants.CONFIG_PATH + "music_tiles.json")
|
||||
configs = parser.parse(reader) as JSONArray
|
||||
for(config in configs) {
|
||||
val e = config as JSONObject
|
||||
val musicId = Integer.parseInt(e["id"].toString())
|
||||
|
|
@ -43,9 +57,6 @@ class MusicConfigLoader {
|
|||
var tokens: Array<String>? = null
|
||||
var borders: ZoneBorders? = null
|
||||
for (border in borderArray) {
|
||||
if(border.isEmpty()){
|
||||
continue
|
||||
}
|
||||
tokens = border.replace("{", "").replace("}", "").split(",").toTypedArray()
|
||||
borders = ZoneBorders(tokens[0].toInt(), tokens[1].toInt(), tokens[2].toInt(), tokens[3].toInt())
|
||||
if (border.contains("[")) { //no exception borders
|
||||
|
|
@ -59,8 +70,6 @@ class MusicConfigLoader {
|
|||
e = exception.replace("[", "").replace("]", "").split(",".toRegex()).toTypedArray()
|
||||
borders.addException(ZoneBorders(e[0].toInt(), e[1].toInt(), e[2].toInt(), e[3].toInt()))
|
||||
}
|
||||
e = null
|
||||
exceptions = null
|
||||
}
|
||||
val zone = MusicZone(musicId, borders)
|
||||
for (id in borders.getRegionIds()) {
|
||||
|
|
@ -69,6 +78,6 @@ class MusicConfigLoader {
|
|||
}
|
||||
count++
|
||||
}
|
||||
log(this::class.java, Log.FINE, "Parsed $count music configs.")
|
||||
log(this::class.java, Log.FINE, "Parsed $count tile music configs.")
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package core.game.world.map;
|
|||
import core.cache.Cache;
|
||||
import core.game.node.entity.npc.NPC;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.entity.player.link.music.MusicEntry;
|
||||
import core.game.node.entity.player.link.music.MusicZone;
|
||||
import core.game.system.communication.CommunicationInfo;
|
||||
import core.game.system.task.Pulse;
|
||||
|
|
@ -11,7 +12,6 @@ import core.game.world.map.build.LandscapeParser;
|
|||
import core.game.world.map.build.MapscapeParser;
|
||||
import core.game.world.map.zone.RegionZone;
|
||||
import core.tools.Log;
|
||||
import core.tools.SystemLogger;
|
||||
import core.game.system.config.XteaParser;
|
||||
import core.game.world.GameWorld;
|
||||
import core.game.world.repository.Repository;
|
||||
|
|
@ -62,7 +62,12 @@ public class Region {
|
|||
private final List<RegionZone> regionZones = new ArrayList<>(20);
|
||||
|
||||
/**
|
||||
* The music zones lying in this region.
|
||||
* The region-wide music track for this region.
|
||||
*/
|
||||
private MusicEntry music = null;
|
||||
|
||||
/**
|
||||
* Any tile-specific music zones lying in this region.
|
||||
*/
|
||||
private final List<MusicZone> musicZones = new ArrayList<>(20);
|
||||
|
||||
|
|
@ -473,6 +478,21 @@ public class Region {
|
|||
return planes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the region-wide music track.
|
||||
*/
|
||||
public void setMusic(MusicEntry music) {
|
||||
this.music = music;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region-wide music track
|
||||
* @return The music entry
|
||||
*/
|
||||
public MusicEntry getMusic() {
|
||||
return this.music;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the regionZones.
|
||||
* @return The regionZones.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import core.game.node.Node;
|
|||
import core.game.node.entity.Entity;
|
||||
import core.game.node.entity.combat.CombatStyle;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.entity.player.link.music.MusicEntry;
|
||||
import core.game.node.entity.player.link.music.MusicZone;
|
||||
import core.game.node.entity.player.link.request.RequestType;
|
||||
import core.game.node.item.Item;
|
||||
|
|
@ -15,6 +16,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import core.game.world.map.Region;
|
||||
import org.rs09.consts.Items;
|
||||
|
||||
/**
|
||||
|
|
@ -396,22 +398,26 @@ public final class ZoneMonitor {
|
|||
for (Iterator<MusicZone> it = musicZones.iterator(); it.hasNext();) {
|
||||
MusicZone zone = it.next();
|
||||
if (!zone.getBorders().insideBorder(l.getX(), l.getY())) {
|
||||
zone.leave(player, false);
|
||||
if (zone.leave(player, false)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
for (MusicZone zone : player.getViewport().getRegion().getMusicZones()) {
|
||||
if (!zone.getBorders().insideBorder(l.getX(), l.getY())) {
|
||||
continue;
|
||||
}
|
||||
if (!musicZones.contains(zone)) {
|
||||
Region r = player.getViewport().getRegion();
|
||||
for (MusicZone zone : r.getMusicZones()) {
|
||||
if (zone.getBorders().insideBorder(l.getX(), l.getY())) {
|
||||
zone.enter(player);
|
||||
musicZones.add(zone);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (musicZones.isEmpty() && !player.getMusicPlayer().isPlaying()) {
|
||||
MusicEntry music = r.getMusic();
|
||||
if (music == null) {
|
||||
if (!player.getMusicPlayer().isPlaying()) {
|
||||
player.getMusicPlayer().playDefault();
|
||||
}
|
||||
} else {
|
||||
player.getMusicPlayer().play(music);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue