Partial sync L2jUnity free release Feb 18th 2015.

This commit is contained in:
MobiusDev 2016-10-26 18:04:21 +00:00
parent 7b56568b81
commit 236412d1bf
10 changed files with 54 additions and 108 deletions

View File

@ -21,8 +21,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -139,7 +139,7 @@ public final class MailManager
public final List<Message> getInbox(int objectId) public final List<Message> getInbox(int objectId)
{ {
final List<Message> inbox = new ArrayList<>(); final List<Message> inbox = new LinkedList<>();
for (Message msg : getMessages()) for (Message msg : getMessages())
{ {
if ((msg != null) && (msg.getReceiverId() == objectId) && !msg.isDeletedByReceiver()) if ((msg != null) && (msg.getReceiverId() == objectId) && !msg.isDeletedByReceiver())
@ -157,7 +157,7 @@ public final class MailManager
public final List<Message> getOutbox(int objectId) public final List<Message> getOutbox(int objectId)
{ {
final List<Message> outbox = new ArrayList<>(); final List<Message> outbox = new LinkedList<>();
for (Message msg : getMessages()) for (Message msg : getMessages())
{ {
if ((msg != null) && (msg.getSenderId() == objectId) && !msg.isDeletedBySender()) if ((msg != null) && (msg.getSenderId() == objectId) && !msg.isDeletedBySender())

View File

@ -20,7 +20,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,6 +30,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
import com.l2jmobius.commons.database.DatabaseFactory; import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.ThreadPoolManager; import com.l2jmobius.gameserver.ThreadPoolManager;
@ -643,14 +644,9 @@ public class AutoSpawnHandler
return _npcList; return _npcList;
} }
public List<L2Spawn> getSpawns() public Collection<L2Spawn> getSpawns()
{ {
final List<L2Spawn> npcSpawns = new ArrayList<>(); return _npcList.stream().map(L2Npc::getSpawn).collect(Collectors.toList());
for (L2Npc npcInst : _npcList)
{
npcSpawns.add(npcInst.getSpawn());
}
return npcSpawns;
} }
public void setSpawnCount(int spawnCount) public void setSpawnCount(int spawnCount)

View File

@ -11064,11 +11064,6 @@ public final class L2PcInstance extends L2Playable
return _lastServerPosition; return _lastServerPosition;
} }
public int getLastServerDistance(int x, int y, int z)
{
return (int) Util.calculateDistance(x, y, z, _lastServerPosition.getX(), _lastServerPosition.getY(), _lastServerPosition.getZ(), true, false);
}
@Override @Override
public void addExpAndSp(long addToExp, long addToSp) public void addExpAndSp(long addToExp, long addToSp)
{ {

View File

@ -131,7 +131,7 @@ public class CharKnownList extends ObjectKnownList
{ {
pIter.remove(); pIter.remove();
} }
else if (!player.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(player), getActiveObject(), player, true)) else if (!player.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(player), getActiveObject(), player, true))
{ {
pIter.remove(); pIter.remove();
removeKnownObject(player, true); removeKnownObject(player, true);
@ -152,7 +152,7 @@ public class CharKnownList extends ObjectKnownList
{ {
continue; continue;
} }
else if (!summon.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(summon), getActiveObject(), summon, true)) else if (!summon.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(summon), getActiveObject(), summon, true))
{ {
sIter.remove(); sIter.remove();
removeKnownObject(summon, true); removeKnownObject(summon, true);
@ -171,7 +171,7 @@ public class CharKnownList extends ObjectKnownList
{ {
oIter.remove(); oIter.remove();
} }
else if (!object.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(object), getActiveObject(), object, true)) else if (!object.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(object), getActiveObject(), object, true))
{ {
oIter.remove(); oIter.remove();
removeKnownObject(object, true); removeKnownObject(object, true);

View File

@ -61,7 +61,7 @@ public class ObjectKnownList
} }
// Check if object is not inside distance to watch object // Check if object is not inside distance to watch object
if (!Util.checkIfInShortRadius(getDistanceToWatchObject(object), getActiveObject(), object, true)) if (!Util.checkIfInShortRange(getDistanceToWatchObject(object), getActiveObject(), object, true))
{ {
return false; return false;
} }
@ -169,7 +169,7 @@ public class ObjectKnownList
} }
// Remove all objects invisible or too far // Remove all objects invisible or too far
if (!object.isVisible() || !Util.checkIfInShortRadius(getDistanceToForgetObject(object), getActiveObject(), object, true)) if (!object.isVisible() || !Util.checkIfInShortRange(getDistanceToForgetObject(object), getActiveObject(), object, true))
{ {
oIter.remove(); oIter.remove();
removeKnownObject(object, true); removeKnownObject(object, true);

View File

@ -135,7 +135,7 @@ public class PcStat extends PlayableStat
// if this player has a pet and it is in his range he takes from the owner's Exp, give the pet Exp now // if this player has a pet and it is in his range he takes from the owner's Exp, give the pet Exp now
final L2Summon sPet = activeChar.getPet(); final L2Summon sPet = activeChar.getPet();
if ((sPet != null) && Util.checkIfInShortRadius(Config.ALT_PARTY_RANGE, activeChar, sPet, false)) if ((sPet != null) && Util.checkIfInShortRange(Config.ALT_PARTY_RANGE, activeChar, sPet, false))
{ {
final L2PetInstance pet = (L2PetInstance) sPet; final L2PetInstance pet = (L2PetInstance) sPet;
ratioTakenByPlayer = pet.getPetLevelData().getOwnerExpTaken() / 100f; ratioTakenByPlayer = pet.getPetLevelData().getOwnerExpTaken() / 100f;

View File

@ -17,6 +17,7 @@
package com.l2jmobius.gameserver.model.entity; package com.l2jmobius.gameserver.model.entity;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import java.util.List; import java.util.List;
import com.l2jmobius.gameserver.model.L2Clan; import com.l2jmobius.gameserver.model.L2Clan;
@ -37,7 +38,7 @@ public interface Siegable
L2SiegeClan getAttackerClan(L2Clan clan); L2SiegeClan getAttackerClan(L2Clan clan);
List<L2SiegeClan> getAttackerClans(); Collection<L2SiegeClan> getAttackerClans();
List<L2PcInstance> getAttackersInZone(); List<L2PcInstance> getAttackersInZone();

View File

@ -21,6 +21,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -70,7 +72,7 @@ public abstract class ClanHallSiegeEngine extends Quest implements Siegable
protected final Logger _log; protected final Logger _log;
private final Map<Integer, L2SiegeClan> _attackers = new ConcurrentHashMap<>(); private final Map<Integer, L2SiegeClan> _attackers = new ConcurrentHashMap<>();
private List<L2Spawn> _guards; private Collection<L2Spawn> _guards;
public SiegableHall _hall; public SiegableHall _hall;
public ScheduledFuture<?> _siegeTask; public ScheduledFuture<?> _siegeTask;
@ -212,7 +214,12 @@ public abstract class ClanHallSiegeEngine extends Quest implements Siegable
@Override @Override
public boolean checkIsAttacker(L2Clan clan) public boolean checkIsAttacker(L2Clan clan)
{ {
return (clan != null) && _attackers.containsKey(clan.getId()); if (clan == null)
{
return false;
}
return _attackers.containsKey(clan.getId());
} }
@Override @Override
@ -234,9 +241,9 @@ public abstract class ClanHallSiegeEngine extends Quest implements Siegable
} }
@Override @Override
public List<L2SiegeClan> getAttackerClans() public Collection<L2SiegeClan> getAttackerClans()
{ {
return new ArrayList<>(_attackers.values()); return Collections.unmodifiableCollection(_attackers.values());
} }
@Override @Override

View File

@ -16,9 +16,11 @@
*/ */
package com.l2jmobius.gameserver.network.serverpackets; package com.l2jmobius.gameserver.network.serverpackets;
import java.util.ArrayList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import com.l2jmobius.gameserver.model.skills.Skill;
public class ExEnchantSkillList extends L2GameServerPacket public class ExEnchantSkillList extends L2GameServerPacket
{ {
public enum EnchantSkillType public enum EnchantSkillType
@ -30,29 +32,16 @@ public class ExEnchantSkillList extends L2GameServerPacket
} }
private final EnchantSkillType _type; private final EnchantSkillType _type;
private final List<Skill> _skills; private final List<Skill> _skills = new LinkedList<>();
static class Skill
{
public int id;
public int nextLevel;
Skill(int pId, int pNextLevel)
{
id = pId;
nextLevel = pNextLevel;
}
}
public void addSkill(int id, int level)
{
_skills.add(new Skill(id, level));
}
public ExEnchantSkillList(EnchantSkillType type) public ExEnchantSkillList(EnchantSkillType type)
{ {
_type = type; _type = type;
_skills = new ArrayList<>(); }
public void addSkill(Skill skill)
{
_skills.add(skill);
} }
@Override @Override
@ -63,10 +52,10 @@ public class ExEnchantSkillList extends L2GameServerPacket
writeD(_type.ordinal()); writeD(_type.ordinal());
writeD(_skills.size()); writeD(_skills.size());
for (Skill sk : _skills) for (Skill skill : _skills)
{ {
writeD(sk.id); writeD(skill.getId());
writeD(sk.nextLevel); writeD(skill.getLevel());
} }
} }
} }

View File

@ -179,39 +179,6 @@ public final class Util
return new String(arr); return new String(arr);
} }
/**
* (Based on ucwords() function of PHP)<br>
* DrHouse: still functional but must be rewritten to avoid += to concat strings
* @param str - the string to capitalize
* @return a string with the first letter of every word in {@code str} capitalized
*/
@Deprecated
public static String capitalizeWords(String str)
{
if ((str == null) || str.isEmpty())
{
return str;
}
final char[] charArray = str.toCharArray();
final StringBuilder result = new StringBuilder();
// Capitalize the first letter in the given string!
charArray[0] = Character.toUpperCase(charArray[0]);
for (int i = 0; i < charArray.length; i++)
{
if (Character.isWhitespace(charArray[i]))
{
charArray[i + 1] = Character.toUpperCase(charArray[i + 1]);
}
result.append(charArray[i]);
}
return result.toString();
}
/** /**
* @param range * @param range
* @param obj1 * @param obj1
@ -221,7 +188,11 @@ public final class Util
*/ */
public static boolean checkIfInRange(int range, L2Object obj1, L2Object obj2, boolean includeZAxis) public static boolean checkIfInRange(int range, L2Object obj1, L2Object obj2, boolean includeZAxis)
{ {
if ((obj1 == null) || (obj2 == null) || (obj1.getInstanceId() != obj2.getInstanceId())) if ((obj1 == null) || (obj2 == null))
{
return false;
}
if (obj1.getInstanceId() != obj2.getInstanceId())
{ {
return false; return false;
} }
@ -230,52 +201,39 @@ public final class Util
return true; // not limited return true; // not limited
} }
int rad = obj1 instanceof L2Character ? 0 + ((L2Character) obj1).getTemplate().getCollisionRadius() : 0; int radius = 0;
if (obj1 instanceof L2Character)
{
radius += ((L2Character) obj1).getTemplate().getCollisionRadius();
}
if (obj2 instanceof L2Character) if (obj2 instanceof L2Character)
{ {
rad += ((L2Character) obj2).getTemplate().getCollisionRadius(); radius += ((L2Character) obj2).getTemplate().getCollisionRadius();
} }
final double dx = obj1.getX() - obj2.getX(); return calculateDistance(obj1, obj2, includeZAxis, false) <= (range + radius);
final double dy = obj1.getY() - obj2.getY();
double d = (dx * dx) + (dy * dy);
if (includeZAxis)
{
final double dz = obj1.getZ() - obj2.getZ();
d += dz * dz;
}
return d <= ((range * range) + (2 * range * rad) + (rad * rad));
} }
/** /**
* Checks if object is within short (sqrt(int.max_value)) radius, not using collisionRadius. Faster calculation than checkIfInRange if distance is short and collisionRadius isn't needed. Not for long distance checks (potential teleports, far away castles etc). * Checks if object is within short (sqrt(int.max_value)) radius, not using collisionRadius. Faster calculation than checkIfInRange if distance is short and collisionRadius isn't needed. Not for long distance checks (potential teleports, far away castles etc).
* @param radius * @param range
* @param obj1 * @param obj1
* @param obj2 * @param obj2
* @param includeZAxis if true, check also Z axis (3-dimensional check), otherwise only 2D * @param includeZAxis if true, check also Z axis (3-dimensional check), otherwise only 2D
* @return {@code true} if objects are within specified range between each other, {@code false} otherwise * @return {@code true} if objects are within specified range between each other, {@code false} otherwise
*/ */
public static boolean checkIfInShortRadius(int radius, L2Object obj1, L2Object obj2, boolean includeZAxis) public static boolean checkIfInShortRange(int range, L2Object obj1, L2Object obj2, boolean includeZAxis)
{ {
if ((obj1 == null) || (obj2 == null)) if ((obj1 == null) || (obj2 == null))
{ {
return false; return false;
} }
if (radius == -1) if (range == -1)
{ {
return true; // not limited return true; // not limited
} }
final int dx = obj1.getX() - obj2.getX(); return calculateDistance(obj1, obj2, includeZAxis, false) <= range;
final int dy = obj1.getY() - obj2.getY();
if (!includeZAxis)
{
return ((dx * dx) + (dy * dy)) <= (radius * radius);
}
final int dz = obj1.getZ() - obj2.getZ();
return ((dx * dx) + (dy * dy) + (dz * dz)) <= (radius * radius);
} }
/** /**