Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/ClanCondition.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/ClanCondition.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/ClanCondition.java (revision 0)
- @@ -0,0 +1,32 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition;
- +
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public abstract class ClanCondition extends Condition
- +{
- + private ClanConditionType _type;
- +
- + public ClanCondition(Object value, ClanConditionType type)
- + {
- + super(value);
- + _type = type;
- + }
- +
- + public ClanConditionType getType()
- + {
- + return _type;
- + }
- +
- + public enum ClanConditionType
- + {
- + MUST_BE_CLAN_LEADER,
- + MIN_CLAN_LEVEL,
- + MIN_CLAN_MEMBERS_COUNT,
- + CRP_AMMOUNT,
- + IS_CASTLE_LORD,
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatsCondition.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatsCondition.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatsCondition.java (revision 0)
- @@ -0,0 +1,34 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition;
- +
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public abstract class StatsCondition extends Condition
- +{
- + private StatsConditionType _type;
- +
- + public StatsCondition(Object value, StatsConditionType type)
- + {
- + super(value);
- + _type = type;
- + }
- +
- + public StatsConditionType getType()
- + {
- + return _type;
- + }
- +
- + public enum StatsConditionType
- + {
- + MIN_PVP_COUNT,
- + MIN_PK_COUNT,
- + MAX_HP,
- + MAX_MP,
- + MAX_CP,
- + MIN_KARMA,
- + MIN_RANK,
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatusCondition.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatusCondition.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatusCondition.java (revision 0)
- @@ -0,0 +1,36 @@
- +
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition;
- +
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public abstract class StatusCondition extends Condition
- +{
- + private StatusConditionType _type;
- +
- + public StatusCondition(Object value, StatusConditionType type)
- + {
- + super(value);
- + _type = type;
- + }
- +
- + public StatusConditionType getType()
- + {
- + return _type;
- + }
- +
- + public enum StatusConditionType
- + {
- + MUST_BE_NOBLE,
- + MUST_BE_HERO,
- + MUST_BE_MARRIED,
- + MUST_BE_ACADEMY_MEMBER,
- + MUST_BE_MAGE,
- + MUST_BE_SUMMONER,
- + HAS_COMMON_CRAFT,
- + HAS_DWARVEN_CRAFT,
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Achievement.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Achievement.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Achievement.java (revision 0)
- @@ -0,0 +1,110 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.base;
- +
- +import java.util.logging.Logger;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +
- +import javolution.util.FastList;
- +import javolution.util.FastMap;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class Achievement
- +{
- + private int _id;
- + private String _name;
- + private String _reward;
- + private String _description = "No Description!";
- + private boolean _repeatable;
- +
- + private FastMap<Integer, Long> _rewardList;
- + private FastList<Condition> _conditions;
- +
- + private static Logger _log = Logger.getLogger(Achievement.class.getName());
- +
- + public Achievement(int id, String name, String description, String reward, boolean repeatable, FastList<Condition> conditions)
- + {
- + _rewardList = new FastMap<Integer, Long>();
- + _id = id;
- + _name = name;
- + _description = description;
- + _reward = reward;
- + _conditions = conditions;
- + _repeatable = repeatable;
- +
- + createRewardList();
- + }
- +
- + private void createRewardList()
- + {
- + for (String s : _reward.split(";"))
- + {
- + if (s == null || s.isEmpty())
- + continue;
- +
- + String[] split = s.split(",");
- + Integer item = 0;
- + Long count = new Long(0);
- + try
- + {
- + item = Integer.valueOf(split[0]);
- + count = Long.valueOf(split[1]);
- + }
- + catch(NumberFormatException nfe)
- + {
- + _log.warning("[AchievementsEngine] Error: Wrong reward " + nfe);
- + }
- + _rewardList.put(item, count);
- + }
- + }
- +
- + public boolean meetAchievementRequirements(L2PcInstance player)
- + {
- + for (Condition c: getConditions())
- + {
- + if (!c.meetConditionRequirements(player))
- + {
- + return false;
- + }
- + }
- + return true;
- + }
- +
- + public int getID()
- + {
- + return _id;
- + }
- +
- + public String getName()
- + {
- + return _name;
- + }
- +
- + public String getDescription()
- + {
- + return _description;
- + }
- +
- + public String getReward()
- + {
- + return _reward;
- + }
- +
- + public boolean isRepeatable()
- + {
- + return _repeatable;
- + }
- +
- + public FastMap<Integer, Long> getRewardList()
- + {
- + return _rewardList;
- + }
- +
- + public FastList<Condition> getConditions()
- + {
- + return _conditions;
- + }
- +}
- +
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Condition.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Condition.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Condition.java (revision 0)
- @@ -0,0 +1,24 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.base;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public abstract class Condition
- +{
- + private Object _value;
- +
- + public Condition(Object value)
- + {
- + _value = value;
- + }
- +
- + public abstract boolean meetConditionRequirements(L2PcInstance player);
- +
- + public Object getValue()
- + {
- + return _value;
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/AchievementsManager.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/AchievementsManager.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/AchievementsManager.java (revision 0)
- @@ -0,0 +1,246 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine;
- +
- +import java.io.File;
- +import java.io.FileInputStream;
- +import java.io.InputStreamReader;
- +import java.sql.Connection;
- +import java.sql.SQLException;
- +import java.sql.Statement;
- +import java.util.Map;
- +import java.util.logging.Logger;
- +
- +import javax.xml.parsers.DocumentBuilderFactory;
- +
- +import javolution.util.FastList;
- +import javolution.util.FastMap;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +import org.xml.sax.InputSource;
- +
- +import com.l2jserver.Config;
- +import com.l2jserver.L2DatabaseFactory;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Achievement;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.ClanCondition.ClanConditionType;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatsCondition.StatsConditionType;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatusCondition.StatusConditionType;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Adena;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Clan;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.ItemsCount;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Level;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Stats;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Status;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.WeaponEnchant;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class AchievementsManager
- +{
- + private Map<Integer, Achievement> _achievementList = new FastMap<Integer, Achievement>();
- +
- + private final String ACHIEVEMENTS_FILE_PATH = Config.DATAPACK_ROOT + "/data/achievements.xml";
- +
- + private static Logger _log = Logger.getLogger(AchievementsManager.class.getName());
- +
- + public AchievementsManager()
- + {
- + loadAchievements();
- + }
- +
- + private void loadAchievements()
- + {
- + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- + factory.setValidating(false);
- + factory.setIgnoringComments(true);
- +
- + File file = new File(ACHIEVEMENTS_FILE_PATH);
- +
- + if (!file.exists())
- + {
- + _log.warning("[AchievementsEngine] Error: achievements xml file does not exist, check directory!");
- + }
- + try
- + {
- + InputSource in = new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8"));
- + in.setEncoding("UTF-8");
- + Document doc = factory.newDocumentBuilder().parse(in);
- +
- + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
- + {
- + if (n.getNodeName().equalsIgnoreCase("list"))
- + {
- + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
- + {
- + if (d.getNodeName().equalsIgnoreCase("achievement"))
- + {
- + int id = checkInt(d, "id");
- +
- + String name = String.valueOf(d.getAttributes().getNamedItem("name").getNodeValue());
- + String description = String.valueOf(d.getAttributes().getNamedItem("description").getNodeValue());
- + String reward = String.valueOf(d.getAttributes().getNamedItem("reward").getNodeValue());
- + boolean repeat = checkBoolean(d, "repeatable");
- +
- + FastList<Condition> conditions = conditionList(d.getAttributes());
- +
- + _achievementList.put(id, new Achievement(id, name, description, reward, repeat, conditions));
- + alterTable(id);
- + }
- + }
- + }
- + }
- +
- + _log.info("[AchievementsEngine] Successfully loaded: " + getAchievementList().size() + " achievements from xml!");
- + }
- + catch (Exception e)
- + {
- + _log.warning("[AchievementsEngine] Error: " + e);
- + e.printStackTrace();
- + }
- + }
- +
- + public void rewardForAchievement(int achievementID, L2PcInstance player)
- + {
- + Achievement achievement = _achievementList.get(achievementID);
- +
- + for (int id: achievement.getRewardList().keySet())
- + player.addItem(achievement.getName(), id, achievement.getRewardList().get(id), player, true);
- + }
- +
- + private boolean checkBoolean(Node d, String nodename)
- + {
- + boolean b = false;
- +
- + try
- + {
- + b = Boolean.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
- + }
- + catch (Exception e)
- + {
- +
- + }
- + return b;
- + }
- +
- + private int checkInt(Node d, String nodename)
- + {
- + int i = 0;
- +
- + try
- + {
- + i = Integer.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
- + }
- + catch (Exception e)
- + {
- +
- + }
- + return i;
- + }
- +
- + /**
- + * Alter table, catch exception if already exist.
- + * @param fieldID
- + */
- + private void alterTable(int fieldID)
- + {
- + Connection con = null;
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + Statement statement = con.createStatement();
- + statement.executeUpdate("ALTER TABLE achievements ADD a" + fieldID + " INT DEFAULT 0");
- + statement.close();
- + }
- + catch (SQLException e)
- + {
- +
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + }
- +
- + public FastList<Condition> conditionList(NamedNodeMap attributesList)
- + {
- + FastList<Condition> conditions = new FastList<Condition>();
- +
- + for (int j = 0; j < attributesList.getLength(); j++)
- + {
- + addToConditionList(attributesList.item(j).getNodeName(), attributesList.item(j).getNodeValue(), conditions);
- + }
- +
- + return conditions;
- + }
- +
- + public Map<Integer, Achievement> getAchievementList()
- + {
- + return _achievementList;
- + }
- +
- + public static AchievementsManager getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final AchievementsManager _instance = new AchievementsManager();
- + }
- +
- + private void addToConditionList(String nodeName, Object value, FastList<Condition> conditions)
- + {
- + if (nodeName.equals("minLevel"))
- + conditions.add(new Level(value));
- + else if (nodeName.equals("minPvPCount"))
- + conditions.add(new Stats(value, StatsConditionType.MIN_PVP_COUNT));
- + else if (nodeName.equals("minPkCount"))
- + conditions.add(new Stats(value, StatsConditionType.MIN_PK_COUNT));
- + else if (nodeName.equals("minClanLevel"))
- + conditions.add(new Clan(value, ClanConditionType.MIN_CLAN_LEVEL));
- + else if (nodeName.equals("mustBeHero"))
- + conditions.add(new Status(value, StatusConditionType.MUST_BE_HERO));
- + else if (nodeName.equals("mustBeNoble"))
- + conditions.add(new Status(value, StatusConditionType.MUST_BE_NOBLE));
- + else if (nodeName.equals("minWeaponEnchant"))
- + conditions.add(new WeaponEnchant(value));
- + else if (nodeName.equals("minKarmaCount"))
- + conditions.add(new Stats(value, StatsConditionType.MIN_KARMA));
- + else if (nodeName.equals("minRankCount"))
- + conditions.add(new Stats(value, StatsConditionType.MIN_RANK));
- + else if (nodeName.equals("minAdenaCount"))
- + conditions.add(new Adena(value));
- + else if (nodeName.equals("minClanMembersCount"))
- + conditions.add(new Clan(value, ClanConditionType.MIN_CLAN_MEMBERS_COUNT));
- + else if (nodeName.equals("mustBeClanLeader"))
- + conditions.add(new Clan(value, ClanConditionType.MUST_BE_CLAN_LEADER));
- + else if (nodeName.equals("maxHP"))
- + conditions.add(new Stats(value, StatsConditionType.MAX_HP));
- + else if (nodeName.equals("maxMP"))
- + conditions.add(new Stats(value, StatsConditionType.MAX_MP));
- + else if (nodeName.equals("maxCP"))
- + conditions.add(new Stats(value, StatsConditionType.MAX_CP));
- + else if (nodeName.equals("mustBeMarried"))
- + conditions.add(new Status(value, StatusConditionType.MUST_BE_MARRIED));
- + else if (nodeName.equals("itemAmmount"))
- + conditions.add(new ItemsCount(value));
- + else if (nodeName.equals("crpAmmount"))
- + conditions.add(new Clan(value, ClanConditionType.CRP_AMMOUNT));
- + else if (nodeName.equals("lordOfCastle"))
- + conditions.add(new Clan(value, ClanConditionType.IS_CASTLE_LORD));
- + else if (nodeName.equals("mustBeAcademyMember"))
- + conditions.add(new Status(value, StatusConditionType.MUST_BE_ACADEMY_MEMBER));
- + else if (nodeName.equals("mustBeMageClass"))
- + conditions.add(new Status(value, StatusConditionType.MUST_BE_MAGE));
- + else if (nodeName.equals("mustBeSummoner"))
- + conditions.add(new Status(value, StatusConditionType.MUST_BE_SUMMONER));
- + else if (nodeName.equals("hasCommonCraft"))
- + conditions.add(new Status(value, StatusConditionType.HAS_COMMON_CRAFT));
- + else if (nodeName.equals("hasDwarvenCraft"))
- + conditions.add(new Status(value, StatusConditionType.HAS_DWARVEN_CRAFT));
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Adena.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Adena.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Adena.java (revision 0)
- @@ -0,0 +1,33 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class Adena extends Condition
- +{
- + public Adena(Object value)
- + {
- + super(value);
- + }
- +
- + @Override
- + public boolean meetConditionRequirements(L2PcInstance player)
- + {
- + if (getValue() == null)
- + {
- + return false;
- + }
- + else
- + {
- + long val = Integer.parseInt(getValue().toString());
- +
- + if (player.getInventory().getAdena() >= val)
- + return true;
- + }
- + return false;
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Clan.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Clan.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Clan.java (revision 0)
- @@ -0,0 +1,69 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.ClanCondition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class Clan extends ClanCondition
- +{
- + public Clan(Object value, ClanConditionType type)
- + {
- + super(value, type);
- + }
- +
- + @Override
- + public boolean meetConditionRequirements(L2PcInstance player)
- + {
- + if (getValue() == null)
- + {
- + return false;
- + }
- +
- + if (player.getClan() != null)
- + {
- + int val = Integer.parseInt(getValue().toString());
- +
- + switch (getType())
- + {
- + case MIN_CLAN_LEVEL:
- + if (player.getClan().getLevel() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MIN_CLAN_MEMBERS_COUNT:
- + if (player.getClan().getMembersCount() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MUST_BE_CLAN_LEADER:
- + if (player.isClanLeader())
- + {
- + return true;
- + }
- + break;
- +
- + case CRP_AMMOUNT:
- + if (player.getClan().getReputationScore() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case IS_CASTLE_LORD:
- + if (player.isCastleLord(val))
- + {
- + return true;
- + }
- + break;
- + }
- + }
- + return false;
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/ItemsCount.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/ItemsCount.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/ItemsCount.java (revision 0)
- @@ -0,0 +1,53 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
- +
- +import java.util.StringTokenizer;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + * <br><br>
- + * Condition: ItemsCount
- + * Check if player has proper ammount of item in inventory.
- + */
- +public class ItemsCount extends Condition
- +{
- + public ItemsCount(Object value)
- + {
- + super(value);
- + }
- +
- + @Override
- + public boolean meetConditionRequirements(L2PcInstance player)
- + {
- + if (getValue() == null)
- + {
- + return false;
- + }
- + else
- + {
- + String s = getValue().toString();
- + StringTokenizer st = new StringTokenizer(s, ",");
- + int id = 0;
- + long ammount = 0;
- +
- + try
- + {
- + id = Integer.parseInt(st.nextToken());
- + ammount = Integer.parseInt(st.nextToken());
- +
- + if (player.getInventory().getItemsByItemId(id).size() >= ammount)
- + {
- + return true;
- + }
- + }
- + catch (NumberFormatException nfe)
- + {
- + nfe.printStackTrace();
- + }
- + }
- + return false;
- + }
- +}
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Level.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Level.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Level.java (revision 0)
- @@ -0,0 +1,33 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class Level extends Condition
- +{
- + public Level(Object value)
- + {
- + super(value);
- + }
- +
- + @Override
- + public boolean meetConditionRequirements(L2PcInstance player)
- + {
- + if (getValue() == null)
- + {
- + return false;
- + }
- + else
- + {
- + int val = Integer.parseInt(getValue().toString());
- +
- + if (player.getLevel() >= val)
- + return true;
- + }
- + return false;
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Stats.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Stats.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Stats.java (revision 0)
- @@ -0,0 +1,81 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatsCondition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class Stats extends StatsCondition
- +{
- + public Stats(Object value, StatsConditionType type)
- + {
- + super(value, type);
- + }
- +
- + @Override
- + public boolean meetConditionRequirements(L2PcInstance player)
- + {
- + if (getValue() == null)
- + {
- + return false;
- + }
- +
- + int val = Integer.parseInt(getValue().toString());
- +
- + switch (getType())
- + {
- + case MAX_HP:
- + if (player.getMaxHp() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MAX_CP:
- + if (player.getMaxCp() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MAX_MP:
- + if (player.getMaxMp() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MIN_PK_COUNT:
- + if (player.getPkKills() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MIN_PVP_COUNT:
- + if (player.getPvpKills() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MIN_KARMA:
- + if (player.getKarma() >= val)
- + {
- + return true;
- + }
- + break;
- +
- + case MIN_RANK:
- + if (player.getRank() >= val)
- + {
- + return true;
- + }
- + break;
- + }
- +
- + return false;
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Status.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Status.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Status.java (revision 0)
- @@ -0,0 +1,85 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatusCondition;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class Status extends StatusCondition
- +{
- + public Status(Object value, StatusConditionType type)
- + {
- + super(value, type);
- + }
- +
- + @Override
- + public boolean meetConditionRequirements(L2PcInstance player)
- + {
- + if (getValue() == null)
- + {
- + return false;
- + }
- +
- + switch (getType())
- + {
- + case MUST_BE_NOBLE:
- + if (player.isNoble())
- + {
- + return true;
- + }
- + break;
- +
- + case MUST_BE_HERO:
- + if (player.isHero())
- + {
- + return true;
- + }
- + break;
- +
- + case MUST_BE_MARRIED:
- + if (player.isMarried())
- + {
- + return true;
- + }
- + break;
- +
- + case MUST_BE_ACADEMY_MEMBER:
- + if (player.isAcademyMember())
- + {
- + return true;
- + }
- + break;
- +
- + case MUST_BE_MAGE:
- + if (player.isMageClass())
- + {
- + return true;
- + }
- + break;
- +
- + case MUST_BE_SUMMONER:
- + if (player.getClassId().isSummoner())
- + {
- + return true;
- + }
- + break;
- +
- + case HAS_COMMON_CRAFT:
- + if (player.hasCommonCraft())
- + {
- + return true;
- + }
- + break;
- +
- + case HAS_DWARVEN_CRAFT:
- + if (player.hasCommonCraft())
- + {
- + return true;
- + }
- + break;
- + } //TODO CLASS ID
- + return false;
- + }
- +}
- \ No newline at end of file
- Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/WeaponEnchant.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/WeaponEnchant.java (revision 0)
- +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/WeaponEnchant.java (revision 0)
- @@ -0,0 +1,40 @@
- +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
- +
- +import com.l2jserver.gameserver.model.L2ItemInstance;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
- +import com.l2jserver.gameserver.model.itemcontainer.Inventory;
- +
- +/**
- + * @author Matim
- + * @version 1.0
- + */
- +public class WeaponEnchant extends Condition
- +{
- + public WeaponEnchant(Object value)
- + {
- + super(value);
- + }
- +
- + @Override
- + public boolean meetConditionRequirements(L2PcInstance player)
- + {
- + if (getValue() == null)
- + {
- + return false;
- + }
- +
- + int val = Integer.parseInt(getValue().toString());
- +
- + L2ItemInstance weapon = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
- +
- + if (weapon != null)
- + {
- + if (weapon.getEnchantLevel() >= val)
- + {
- + return true;
- + }
- + }
- + return false;
- + }
- +}[/code]
- for L2PcInstance
- [code]+private List<Integer> _completedAchievements = new FastList<Integer>();
- +
- + public boolean readyAchievementsList()
- + {
- + if (_completedAchievements.isEmpty())
- + return false;
- + else
- + return true;
- + }
- +
- + public void saveAchievemntData()
- + {
- +
- + }
- +
- + public void getAchievemntData()
- + {
- + Connection con = null;
- + try
- + {
- + PreparedStatement statement;
- + PreparedStatement insertStatement;
- + ResultSet rs;
- + con = L2DatabaseFactory.getInstance().getConnection();
- +
- + statement = con.prepareStatement("SELECT * from achievements WHERE owner_id=" + getObjectId());
- +
- + rs = statement.executeQuery();
- +
- + String values = "owner_id";
- + String in = Integer.toString(getObjectId());
- + String questionMarks = in;
- + int ilosc = AchievementsManager.getInstance().getAchievementList().size();
- +
- + if (rs.next())
- + {
- + _completedAchievements.clear();
- + for (int i=1; i <=ilosc; i++)
- + {
- + int a = rs.getInt("a" + i);
- +
- + if (!_completedAchievements.contains(i))
- + if (a == 1)
- + _completedAchievements.add(i);
- + }
- + }
- + else
- + {
- + //Player hasnt entry in database, means we have to create it.
- +
- + for (int i=1; i <=ilosc; i++)
- + {
- + values += ", a" + i;
- + questionMarks += ", 0";
- + }
- +
- + String s = "INSERT INTO achievements(" + values + ") VALUES (" + questionMarks + ")";
- + insertStatement = con.prepareStatement(s);
- +
- + insertStatement.execute();
- + insertStatement.close();
- + }
- + }
- + catch (SQLException e)
- + {
- + _log.warning("[ACHIEVEMENTS ENGINE GETDATA]" + e);
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + }
- +
- + public void saveAchievementData(int achievementID)
- + {
- + Connection con = null;
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + Statement statement = con.createStatement();
- + statement.executeUpdate("UPDATE achievements SET a" + achievementID + "=1 WHERE owner_id=" + getObjectId());
- + statement.close();
- +
- + if (!_completedAchievements.contains(achievementID))
- + _completedAchievements.add(achievementID);
- + }
- + catch (SQLException e)
- + {
- + _log.warning("[ACHIEVEMENTS SAVE GETDATA]" + e);
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + }
- +
- + public List<Integer> getCompletedAchievements()
- + {
- + return _completedAchievements;
- + }
- +
Advertisement
Add Comment
Please, Sign In to add comment