This commit is contained in:
mobius
2015-01-01 20:02:50 +00:00
parent eeae660458
commit a6a3718849
17894 changed files with 2818932 additions and 0 deletions

View File

@@ -0,0 +1,221 @@
/*
* Copyright (C) 2004-2014 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server 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.
*
* L2J Server 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 ai.npc.NpcBuffers;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2Party;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.actor.instance.L2TamedBeastInstance;
import com.l2jserver.gameserver.model.skills.Skill;
import com.l2jserver.gameserver.model.zone.ZoneId;
import com.l2jserver.gameserver.util.Util;
/**
* @author UnAfraid
*/
public class NpcBufferAI implements Runnable
{
private final L2Npc _npc;
private final NpcBufferSkillData _skillData;
protected NpcBufferAI(L2Npc npc, NpcBufferSkillData skill)
{
_npc = npc;
_skillData = skill;
}
@Override
public void run()
{
if ((_npc == null) || !_npc.isVisible() || _npc.isDecayed() || _npc.isDead() || (_skillData == null) || (_skillData.getSkill() == null))
{
return;
}
if ((_npc.getSummoner() == null) || !_npc.getSummoner().isPlayer())
{
return;
}
final Skill skill = _skillData.getSkill();
final L2PcInstance player = _npc.getSummoner().getActingPlayer();
switch (_skillData.getAffectScope())
{
case PARTY:
{
if (player.isInParty())
{
for (L2PcInstance member : player.getParty().getMembers())
{
if (Util.checkIfInRange(skill.getAffectRange(), _npc, member, true) && !member.isDead())
{
skill.applyEffects(player, member);
}
}
}
else
{
if (Util.checkIfInRange(skill.getAffectRange(), _npc, player, true) && !player.isDead())
{
skill.applyEffects(player, player);
}
}
break;
}
case RANGE:
{
for (L2Character target : _npc.getKnownList().getKnownCharactersInRadius(skill.getAffectRange()))
{
switch (_skillData.getAffectObject())
{
case FRIEND:
{
if (isFriendly(player, target) && !target.isDead())
{
skill.applyEffects(target, target);
}
break;
}
case NOT_FRIEND:
{
if (isEnemy(player, target) && !target.isDead())
{
// Update PvP status
if (target.isPlayable())
{
player.updatePvPStatus(target);
}
skill.applyEffects(target, target);
}
break;
}
}
}
break;
}
}
ThreadPoolManager.getInstance().scheduleGeneral(this, _skillData.getDelay());
}
/**
* Verifies if the character is an friend and can be affected by positive effect.
* @param player the player
* @param target the target
* @return {@code true} if target can be affected by positive effect, {@code false} otherwise
*/
private boolean isFriendly(L2PcInstance player, L2Character target)
{
if (target.isPlayable())
{
final L2PcInstance targetPlayer = target.getActingPlayer();
if (player == targetPlayer)
{
return true;
}
if (player.isInParty() && targetPlayer.isInParty())
{
final L2Party party = player.getParty();
if (party.containsPlayer(targetPlayer))
{
return true;
}
if (party.isInCommandChannel() && party.getCommandChannel().containsPlayer(targetPlayer))
{
return true;
}
}
if ((player.getClanId() > 0) && (player.getClanId() == targetPlayer.getClanId()))
{
return true;
}
if ((player.getAllyId() > 0) && (player.getAllyId() == targetPlayer.getAllyId()))
{
return true;
}
if ((player.getSiegeState() > 0) && player.isInsideZone(ZoneId.SIEGE) && (player.getSiegeState() == targetPlayer.getSiegeState()) && (player.getSiegeSide() == targetPlayer.getSiegeSide()))
{
return true;
}
}
return false;
}
/**
* Verifies if the character is an enemy and can be affected by negative effect.
* @param player the player
* @param target the target
* @return {@code true} if target can be affected by negative effect, {@code false} otherwise
*/
private boolean isEnemy(L2PcInstance player, L2Character target)
{
if (isFriendly(player, target))
{
return false;
}
if (target instanceof L2TamedBeastInstance)
{
return isEnemy(player, ((L2TamedBeastInstance) target).getOwner());
}
if (target.isMonster())
{
return true;
}
if (target.isPlayable())
{
final L2PcInstance targetPlayer = target.getActingPlayer();
if (!isFriendly(player, targetPlayer))
{
if (targetPlayer.getPvpFlag() != 0)
{
return true;
}
if (targetPlayer.getKarma() != 0)
{
return true;
}
if ((player.getClan() != null) && (targetPlayer.getClan() != null) && player.getClan().isAtWarWith(targetPlayer.getClan()))
{
return true;
}
if (targetPlayer.isInsideZone(ZoneId.PVP))
{
return true;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2004-2014 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server 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.
*
* L2J Server 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 ai.npc.NpcBuffers;
import java.util.ArrayList;
import java.util.List;
/**
* @author UnAfraid
*/
public class NpcBufferData
{
private final int _id;
private final List<NpcBufferSkillData> _skills = new ArrayList<>();
public NpcBufferData(int id)
{
_id = id;
}
public int getId()
{
return _id;
}
public void addSkill(NpcBufferSkillData skill)
{
_skills.add(skill);
}
public List<NpcBufferSkillData> getSkills()
{
return _skills;
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2004-2014 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server 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.
*
* L2J Server 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 ai.npc.NpcBuffers;
import com.l2jserver.gameserver.model.StatsSet;
import com.l2jserver.gameserver.model.holders.SkillHolder;
import com.l2jserver.gameserver.model.skills.Skill;
import com.l2jserver.gameserver.model.skills.targets.AffectObject;
import com.l2jserver.gameserver.model.skills.targets.AffectScope;
/**
* @author UnAfraid
*/
public class NpcBufferSkillData
{
private final SkillHolder _skill;
private final int _initialDelay;
private final int _delay;
private final AffectScope _affectScope;
private final AffectObject _affectObject;
public NpcBufferSkillData(StatsSet set)
{
_skill = new SkillHolder(set.getInt("id"), set.getInt("level"));
_initialDelay = set.getInt("skillInitDelay", 0) * 1000;
_delay = set.getInt("delay") * 1000;
_affectScope = set.getEnum("affectScope", AffectScope.class);
_affectObject = set.getEnum("affectObject", AffectObject.class);
}
public Skill getSkill()
{
return _skill.getSkill();
}
public int getInitialDelay()
{
return _initialDelay;
}
public int getDelay()
{
return _delay;
}
public AffectScope getAffectScope()
{
return _affectScope;
}
public AffectObject getAffectObject()
{
return _affectObject;
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2004-2014 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server 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.
*
* L2J Server 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 ai.npc.NpcBuffers;
import ai.npc.AbstractNpcAI;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
/**
* @author UnAfraid
*/
public final class NpcBuffers extends AbstractNpcAI
{
private final NpcBuffersData _npcBuffers = new NpcBuffersData();
private NpcBuffers()
{
super(NpcBuffers.class.getSimpleName(), "npc");
for (int npcId : _npcBuffers.getNpcBufferIds())
{
// TODO: Cleanup once npc rework is finished and default html is configurable.
addFirstTalkId(npcId);
addSpawnId(npcId);
}
}
// TODO: Cleanup once npc rework is finished and default html is configurable.
@Override
public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
return null;
}
@Override
public String onSpawn(L2Npc npc)
{
final NpcBufferData data = _npcBuffers.getNpcBuffer(npc.getId());
for (NpcBufferSkillData skill : data.getSkills())
{
ThreadPoolManager.getInstance().scheduleAi(new NpcBufferAI(npc, skill), skill.getInitialDelay());
}
return super.onSpawn(npc);
}
public static void main(String[] args)
{
new NpcBuffers();
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) 2004-2014 L2J DataPack
*
* This file is part of L2J DataPack.
*
* L2J DataPack 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.
*
* L2J DataPack 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 ai.npc.NpcBuffers;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.l2jserver.gameserver.engines.DocumentParser;
import com.l2jserver.gameserver.model.StatsSet;
/**
* @author UnAfraid
*/
public class NpcBuffersData implements DocumentParser
{
private final Map<Integer, NpcBufferData> _npcBuffers = new HashMap<>();
protected NpcBuffersData()
{
load();
}
@Override
public void load()
{
parseDatapackFile("data/scripts/ai/npc/NpcBuffers/NpcBuffersData.xml");
LOGGER.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _npcBuffers.size() + " buffers data.");
}
@Override
public void parseDocument(Document doc)
{
StatsSet set;
Node attr;
NamedNodeMap attrs;
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("npc".equalsIgnoreCase(d.getNodeName()))
{
attrs = d.getAttributes();
final int npcId = parseInteger(attrs, "id");
final NpcBufferData npc = new NpcBufferData(npcId);
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
{
switch (c.getNodeName())
{
case "skill":
{
attrs = c.getAttributes();
set = new StatsSet();
for (int i = 0; i < attrs.getLength(); i++)
{
attr = attrs.item(i);
set.set(attr.getNodeName(), attr.getNodeValue());
}
npc.addSkill(new NpcBufferSkillData(set));
break;
}
}
}
_npcBuffers.put(npcId, npc);
}
}
}
}
}
public NpcBufferData getNpcBuffer(int npcId)
{
return _npcBuffers.get(npcId);
}
public Collection<NpcBufferData> getNpcBuffers()
{
return _npcBuffers.values();
}
public Set<Integer> getNpcBufferIds()
{
return _npcBuffers.keySet();
}
}

View File

@@ -0,0 +1,101 @@
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NpcBuffersData.xsd">
<npc id="106"> <!-- Birthday Cake -->
<skill id="22250" level="1" initialDelay="1" delay="60" affectScope="PARTY" affectObject="FRIEND" /> <!-- Birthday Cake Vitality Buff -->
</npc>
<npc id="139"> <!-- Birthday Cake -->
<skill id="22035" level="1" initialDelay="1" delay="60" affectScope="PARTY" affectObject="FRIEND" /> <!-- Birthday Cake Vitality Buff -->
</npc>
<npc id="143"> <!-- Totem of Body -->
<skill id="23308" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Totem's Energy - Body -->
</npc>
<npc id="144"> <!-- Totem of Spirit -->
<skill id="23309" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Totem's Energy - Spirit -->
</npc>
<npc id="145"> <!-- Totem of Bravery -->
<skill id="23310" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Totem's Energy - Courage -->
</npc>
<npc id="146"> <!-- Totem of Fortitude -->
<skill id="23311" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Totem's Energy - Fortitude -->
</npc>
<npc id="13007"> <!-- Special Christmas Tree -->
<skill id="2139" level="1" initialDelay="1" delay="10" affectScope="RANGE" affectObject="FRIEND" /> <!-- Special Tree Recovery Bonus -->
</npc>
<npc id="13018">
<skill id="5123" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Maximum Defense -->
</npc>
<npc id="13019">
<skill id="5124" level="1" initialDelay="1" delay="2" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Anti-Music -->
</npc>
<npc id="13020">
<skill id="5125" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Maximum Resist Status -->
</npc>
<npc id="13021">
<skill id="5126" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Maximum Recovery -->
</npc>
<npc id="13022">
<skill id="5127" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Recover Force -->
</npc>
<npc id="13023">
<skill id="5128" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Maximize long-range weapon use -->
</npc>
<npc id="13024">
<skill id="5129" level="1" initialDelay="1" delay="5" affectScope="RANGE" affectObject="FRIEND" /> <!-- Smokescreen -->
</npc>
<npc id="13028">
<skill id="5145" level="1" initialDelay="1" delay="2" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Day of Doom -->
</npc>
<npc id="13030">
<skill id="5134" level="1" initialDelay="1" delay="2" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Anti-Summoning Field -->
</npc>
<npc id="13071"> <!-- Virtual Image -->
<skill id="5272" level="1" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13072"> <!-- Virtual Image -->
<skill id="5272" level="2" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13073"> <!-- Virtual Image -->
<skill id="5272" level="3" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13074"> <!-- Virtual Image -->
<skill id="5272" level="4" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13075"> <!-- Virtual Image -->
<skill id="5272" level="5" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13076"> <!-- Virtual Image -->
<skill id="5272" level="6" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13257"> <!-- Virtual Image -->
<skill id="5272" level="7" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13258"> <!-- Virtual Image -->
<skill id="5272" level="8" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13259"> <!-- Virtual Image -->
<skill id="5272" level="9" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13260"> <!-- Virtual Image -->
<skill id="5272" level="10" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13261"> <!-- Virtual Image -->
<skill id="5272" level="11" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13262"> <!-- Virtual Image -->
<skill id="5272" level="12" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13263"> <!-- Virtual Image -->
<skill id="5272" level="13" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13264"> <!-- Virtual Image -->
<skill id="5272" level="14" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13265"> <!-- Virtual Image -->
<skill id="5272" level="15" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13266"> <!-- Virtual Image -->
<skill id="5272" level="16" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
<npc id="13267"> <!-- Virtual Image -->
<skill id="5272" level="17" delay="5" affectScope="RANGE" affectObject="NOT_FRIEND" /> <!-- Decoy Provocation -->
</npc>
</list>

View File

@@ -0,0 +1,25 @@
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element name="npc" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="skill">
<xs:complexType>
<xs:attribute type="xs:positiveInteger" name="id" use="required" />
<xs:attribute type="xs:short" name="level" use="required" />
<xs:attribute type="xs:positiveInteger" name="initialDelay" use="optional" />
<xs:attribute type="xs:positiveInteger" name="delay" use="required" />
<xs:attribute type="xs:string" name="affectScope" use="optional" />
<xs:attribute type="xs:string" name="affectObject" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:positiveInteger" name="id" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>