Addition of localisations for NPC name and titles.

This commit is contained in:
MobiusDevelopment
2019-07-14 13:03:02 +00:00
parent 95ba581cf5
commit aa201e6cae
130 changed files with 3351 additions and 72 deletions

View File

@@ -81,6 +81,7 @@ import org.l2jmobius.gameserver.data.xml.impl.LuckyGameData;
import org.l2jmobius.gameserver.data.xml.impl.MonsterBookData;
import org.l2jmobius.gameserver.data.xml.impl.MultisellData;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.data.xml.impl.NpcNameLocalisationData;
import org.l2jmobius.gameserver.data.xml.impl.OptionData;
import org.l2jmobius.gameserver.data.xml.impl.PetDataTable;
import org.l2jmobius.gameserver.data.xml.impl.PetSkillData;
@@ -355,6 +356,7 @@ public class GameServer
if (Config.MULTILANG_ENABLE)
{
SendMessageLocalisationData.getInstance();
NpcNameLocalisationData.getInstance();
}
printSection("Scripts");

View File

@@ -0,0 +1,126 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.data.xml.impl;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.l2jmobius.Config;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.model.StatsSet;
/**
* @author Mobius
*/
public class NpcNameLocalisationData implements IXmlReader
{
private final static Logger LOGGER = Logger.getLogger(NpcNameLocalisationData.class.getName());
private final static Map<String, Map<Integer, String[]>> NPC_NAME_LOCALISATIONS = new ConcurrentHashMap<>();
private static String _lang;
protected NpcNameLocalisationData()
{
load();
}
@Override
public void load()
{
NPC_NAME_LOCALISATIONS.clear();
if (Config.MULTILANG_ENABLE)
{
for (String lang : Config.MULTILANG_ALLOWED)
{
final File file = new File("data/lang/" + lang + "/NpcNameLocalisation.xml");
if (!file.isFile())
{
continue;
}
NPC_NAME_LOCALISATIONS.put(lang, new ConcurrentHashMap<Integer, String[]>());
_lang = lang;
parseDatapackFile("data/lang/" + lang + "/NpcNameLocalisation.xml");
final int count = NPC_NAME_LOCALISATIONS.get(lang).values().size();
if (count == 0)
{
NPC_NAME_LOCALISATIONS.remove(lang);
}
else
{
LOGGER.info(getClass().getSimpleName() + ": Loaded localisations for '" + lang + "'");
}
}
}
}
@Override
public void parseDocument(Document doc, File f)
{
forEach(doc, "list", listNode -> forEach(listNode, "localisation", localisationNode ->
{
final StatsSet set = new StatsSet(parseAttributes(localisationNode));
NPC_NAME_LOCALISATIONS.get(_lang).put(set.getInt("id"), new String[]
{
set.getString("name"),
set.getString("title")
});
}));
}
/**
* @param lang
* @param id
* @return a String Array[] that contains NPC name and title or Null if is does not exist.
*/
public String[] getLocalisation(String lang, int id)
{
final Map<Integer, String[]> localisations = NPC_NAME_LOCALISATIONS.get(lang);
if (localisations != null)
{
return localisations.get(id);
}
return null;
}
public boolean hasLocalisation(int id)
{
for (Map<Integer, String[]> data : NPC_NAME_LOCALISATIONS.values())
{
if (data.containsKey(id))
{
return true;
}
}
return false;
}
public static NpcNameLocalisationData getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final NpcNameLocalisationData INSTANCE = new NpcNameLocalisationData();
}
}

View File

@@ -69,6 +69,7 @@ import org.l2jmobius.gameserver.data.xml.impl.ExperienceData;
import org.l2jmobius.gameserver.data.xml.impl.HennaData;
import org.l2jmobius.gameserver.data.xml.impl.MonsterBookData;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.data.xml.impl.NpcNameLocalisationData;
import org.l2jmobius.gameserver.data.xml.impl.PetDataTable;
import org.l2jmobius.gameserver.data.xml.impl.PlayerTemplateData;
import org.l2jmobius.gameserver.data.xml.impl.PlayerXpPercentLostData;
@@ -11649,7 +11650,19 @@ public final class PlayerInstance extends Playable
{
sm = new SystemMessage(SystemMessageId.C1_HAS_INFLICTED_S3_DAMAGE_ON_C2);
sm.addPcName(this);
sm.addString(target.getName());
// Localisation related.
String targetName = target.getName();
if (Config.MULTILANG_ENABLE && target.isNpc())
{
final String[] localisation = NpcNameLocalisationData.getInstance().getLocalisation(_lang, target.getId());
if (localisation != null)
{
targetName = localisation[0];
}
}
sm.addString(targetName);
sm.addInt(damage);
sm.addPopup(target.getObjectId(), getObjectId(), -damage);
}

View File

@@ -18,6 +18,7 @@ package org.l2jmobius.gameserver.model.actor.status;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.data.xml.impl.NpcNameLocalisationData;
import org.l2jmobius.gameserver.enums.PrivateStoreType;
import org.l2jmobius.gameserver.instancemanager.DuelManager;
import org.l2jmobius.gameserver.model.actor.Creature;
@@ -253,7 +254,19 @@ public class PlayerStatus extends PlayableStatus
// Send a System Message to the PlayerInstance
SystemMessage smsg = new SystemMessage(SystemMessageId.C1_HAS_RECEIVED_S3_DAMAGE_FROM_C2);
smsg.addString(getActiveChar().getName());
smsg.addString(attacker.getName());
// Localisation related.
String targetName = attacker.getName();
if (Config.MULTILANG_ENABLE && attacker.isNpc())
{
final String[] localisation = NpcNameLocalisationData.getInstance().getLocalisation(getActiveChar().getLang(), attacker.getId());
if (localisation != null)
{
targetName = localisation[0];
}
}
smsg.addString(targetName);
smsg.addInt(fullValue);
smsg.addPopup(getActiveChar().getObjectId(), attacker.getObjectId(), -fullValue);
getActiveChar().sendPacket(smsg);

View File

@@ -49,6 +49,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
import org.l2jmobius.gameserver.network.serverpackets.ExShowScreenMessage;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
import org.l2jmobius.gameserver.network.serverpackets.NpcInfo;
import org.l2jmobius.gameserver.network.serverpackets.NpcSay;
import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
@@ -268,6 +269,10 @@ public final class GameClient extends ChannelInboundHandler<GameClient>
{
((ExShowScreenMessage) packet).setLang(lang);
}
else if (packet instanceof NpcInfo)
{
((NpcInfo) packet).setLang(lang);
}
}
}

View File

@@ -21,6 +21,8 @@ import java.util.Set;
import org.l2jmobius.Config;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.data.sql.impl.ClanTable;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.data.xml.impl.NpcNameLocalisationData;
import org.l2jmobius.gameserver.enums.NpcInfoType;
import org.l2jmobius.gameserver.enums.Team;
import org.l2jmobius.gameserver.model.actor.Npc;
@@ -57,6 +59,40 @@ public class NpcInfo extends AbstractMaskPacket<NpcInfoType>
private int _statusMask = 0;
private final Set<AbnormalVisualEffect> _abnormalVisualEffects;
private String[] _localisation;
public void setLang(String lang)
{
_localisation = NpcNameLocalisationData.getInstance().getLocalisation(lang, _npc.getId());
if (_localisation != null)
{
if (!containsMask(NpcInfoType.NAME))
{
addComponentType(NpcInfoType.NAME);
}
_blockSize -= _npc.getName().length() * 2;
_blockSize += _localisation[0].length() * 2;
if (!_localisation[1].equals(""))
{
if (!containsMask(NpcInfoType.TITLE))
{
addComponentType(NpcInfoType.TITLE);
}
final String title = _npc.getTitle();
_initSize -= title.length() * 2;
if (title.equals(""))
{
_initSize += _localisation[1].length() * 2;
}
else
{
_initSize += title.replace(NpcData.getInstance().getTemplate(_npc.getId()).getTitle(), _localisation[1]).length() * 2;
}
}
}
}
public NpcInfo(Npc npc)
{
_npc = npc;
@@ -283,7 +319,22 @@ public class NpcInfo extends AbstractMaskPacket<NpcInfoType>
}
if (containsMask(NpcInfoType.TITLE))
{
packet.writeS(_npc.getTitle());
String title = _npc.getTitle();
// Localisation related.
if ((_localisation != null) && !_localisation[1].equals(""))
{
if (title.equals(""))
{
title = _localisation[1];
}
else
{
title = title.replace(NpcData.getInstance().getTemplate(_npc.getId()).getTitle(), _localisation[1]);
}
}
packet.writeS(title);
}
// Block 2
@@ -344,7 +395,7 @@ public class NpcInfo extends AbstractMaskPacket<NpcInfoType>
}
if (containsMask(NpcInfoType.FLYING))
{
packet.writeD(_npc.isFlying() ? 0x01 : 00);
packet.writeD(_npc.isFlying() ? 0x01 : 0x00);
}
if (containsMask(NpcInfoType.CLONE))
{
@@ -389,7 +440,7 @@ public class NpcInfo extends AbstractMaskPacket<NpcInfoType>
}
if (containsMask(NpcInfoType.NAME))
{
packet.writeS(_npc.getName());
packet.writeS(_localisation != null ? _localisation[0] : _npc.getName());
}
if (containsMask(NpcInfoType.NAME_NPCSTRINGID))
{