Merged with released L2J-Unity files.
This commit is contained in:
95
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBufferAI.java
vendored
Normal file
95
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBufferAI.java
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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 ai.others.NpcBuffers;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.SkillData;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.skills.BuffInfo;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class NpcBufferAI implements Runnable
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(NpcBufferAI.class.getName());
|
||||
private final L2Npc _npc;
|
||||
private final NpcBufferSkillData _skillData;
|
||||
|
||||
protected NpcBufferAI(L2Npc npc, NpcBufferSkillData skill)
|
||||
{
|
||||
_npc = npc;
|
||||
_skillData = skill;
|
||||
}
|
||||
|
||||
private Skill getSkill(L2PcInstance player)
|
||||
{
|
||||
if (_skillData.getScaleToLevel() < 1)
|
||||
{
|
||||
return _skillData.getSkill();
|
||||
}
|
||||
|
||||
final BuffInfo currentBuff = player.getEffectList().getBuffInfoBySkillId(_skillData.getSkill().getId());
|
||||
if (currentBuff != null)
|
||||
{
|
||||
int level = currentBuff.getSkill().getLevel();
|
||||
if (_skillData.getScaleToLevel() > level)
|
||||
{
|
||||
level++;
|
||||
}
|
||||
|
||||
final Skill skill = SkillData.getInstance().getSkill(_skillData.getSkill().getId(), level);
|
||||
if (skill == null)
|
||||
{
|
||||
LOGGER.warning("Requested non existing skill level: " + level + " for id: " + _skillData.getSkill().getId());
|
||||
}
|
||||
return skill;
|
||||
}
|
||||
|
||||
return _skillData.getSkill();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if ((_npc == null) || !_npc.isSpawned() || _npc.isDecayed() || _npc.isDead() || (_skillData == null) || (_skillData.getSkill() == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_npc.getSummoner() == null) || !_npc.getSummoner().isPlayer())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final L2PcInstance player = _npc.getSummoner().getActingPlayer();
|
||||
|
||||
final Skill skill = getSkill(player);
|
||||
if (skill == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_npc.doCast(skill);
|
||||
|
||||
ThreadPoolManager.getInstance().scheduleGeneral(this, skill.getReuseDelay());
|
||||
}
|
||||
}
|
49
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBufferData.java
vendored
Normal file
49
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBufferData.java
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 ai.others.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;
|
||||
}
|
||||
}
|
53
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBufferSkillData.java
vendored
Normal file
53
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBufferSkillData.java
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 ai.others.NpcBuffers;
|
||||
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.holders.SkillHolder;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class NpcBufferSkillData
|
||||
{
|
||||
private final SkillHolder _skill;
|
||||
private final int _scaleToLevel;
|
||||
private final int _initialDelay;
|
||||
|
||||
public NpcBufferSkillData(StatsSet set)
|
||||
{
|
||||
_skill = new SkillHolder(set.getInt("id"), set.getInt("level"));
|
||||
_scaleToLevel = set.getInt("scaleToLevel", -1);
|
||||
_initialDelay = set.getInt("initialDelay", 0) * 1000;
|
||||
}
|
||||
|
||||
public Skill getSkill()
|
||||
{
|
||||
return _skill.getSkill();
|
||||
}
|
||||
|
||||
public int getScaleToLevel()
|
||||
{
|
||||
return _scaleToLevel;
|
||||
}
|
||||
|
||||
public int getInitialDelay()
|
||||
{
|
||||
return _initialDelay;
|
||||
}
|
||||
}
|
65
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffers.java
vendored
Normal file
65
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffers.java
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 ai.others.NpcBuffers;
|
||||
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
import ai.AbstractNpcAI;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public final class NpcBuffers extends AbstractNpcAI
|
||||
{
|
||||
private final NpcBuffersData _npcBuffers = new NpcBuffersData();
|
||||
|
||||
private NpcBuffers()
|
||||
{
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
110
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffersData.java
vendored
Normal file
110
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffersData.java
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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 ai.others.NpcBuffers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class NpcBuffersData implements IGameXmlReader
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(NpcBuffersData.class.getName());
|
||||
|
||||
private final Map<Integer, NpcBufferData> _npcBuffers = new HashMap<>();
|
||||
|
||||
protected NpcBuffersData()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
parseDatapackFile("data/scripts/ai/others/NpcBuffers/NpcBuffersData.xml");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded: " + _npcBuffers.size() + " buffers data.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseDocument(Document doc, File f)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
20
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffersData.xml
vendored
Normal file
20
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffersData.xml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<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" /> <!-- Birthday Cake Vitality Buff -->
|
||||
</npc>
|
||||
<npc id="139"> <!-- Birthday Cake -->
|
||||
<skill id="22035" level="1" initialDelay="1" /> <!-- Birthday Cake Vitality Buff -->
|
||||
</npc>
|
||||
<npc id="13007"> <!-- Special Christmas Tree -->
|
||||
<skill id="2139" level="1" initialDelay="1" /> <!-- Special Tree Recovery Bonus -->
|
||||
</npc>
|
||||
<npc id="13423"> <!-- Protection Stone -->
|
||||
<skill id="11360" level="1" scaleToLevel="3" initialDelay="3" /> <!-- Arcane Protection -->
|
||||
</npc>
|
||||
<npc id="13424"> <!-- Protection Stone -->
|
||||
<skill id="11367" level="1" scaleToLevel="3" initialDelay="3" /> <!-- Arcane Protection -->
|
||||
</npc>
|
||||
<npc id="13425"> <!-- Protection Stone -->
|
||||
<skill id="11368" level="1" scaleToLevel="3" initialDelay="3" /> <!-- Arcane Protection -->
|
||||
</npc>
|
||||
</list>
|
23
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffersData.xsd
vendored
Normal file
23
trunk/dist/game/data/scripts/ai/others/NpcBuffers/NpcBuffersData.xsd
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<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" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:attribute type="xs:positiveInteger" name="id" use="required" />
|
||||
<xs:attribute type="xs:positiveInteger" name="level" use="required" />
|
||||
<xs:attribute type="xs:positiveInteger" name="scaleToLevel" use="optional" />
|
||||
<xs:attribute type="xs:positiveInteger" name="initialDelay" 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>
|
Reference in New Issue
Block a user