dymek84

achievements

Aug 22nd, 2012
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 40.24 KB | None | 0 0
  1. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/ClanCondition.java
  2. ===================================================================
  3. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/ClanCondition.java   (revision 0)
  4. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/ClanCondition.java   (revision 0)
  5. @@ -0,0 +1,32 @@
  6. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition;
  7. +
  8. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  9. +
  10. +/**
  11. + * @author Matim
  12. + * @version 1.0
  13. + */
  14. +public abstract class ClanCondition extends Condition
  15. +{
  16. +        private ClanConditionType _type;
  17. +        
  18. +        public ClanCondition(Object value, ClanConditionType type)
  19. +        {
  20. +                super(value);
  21. +                _type = type;
  22. +        }
  23. +        
  24. +        public ClanConditionType getType()
  25. +        {
  26. +                return _type;
  27. +        }
  28. +        
  29. +        public enum ClanConditionType
  30. +        {
  31. +                MUST_BE_CLAN_LEADER,
  32. +                MIN_CLAN_LEVEL,
  33. +                MIN_CLAN_MEMBERS_COUNT,
  34. +                CRP_AMMOUNT,
  35. +                IS_CASTLE_LORD,
  36. +        }
  37. +}
  38. \ No newline at end of file
  39. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatsCondition.java
  40. ===================================================================
  41. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatsCondition.java  (revision 0)
  42. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatsCondition.java  (revision 0)
  43. @@ -0,0 +1,34 @@
  44. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition;
  45. +
  46. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  47. +
  48. +/**
  49. + * @author Matim
  50. + * @version 1.0
  51. + */
  52. +public abstract class StatsCondition extends Condition
  53. +{
  54. +        private StatsConditionType _type;
  55. +        
  56. +        public StatsCondition(Object value, StatsConditionType type)
  57. +        {
  58. +                super(value);
  59. +                _type = type;
  60. +        }
  61. +        
  62. +        public StatsConditionType getType()
  63. +        {
  64. +                return _type;
  65. +        }
  66. +        
  67. +        public enum StatsConditionType
  68. +        {
  69. +                MIN_PVP_COUNT,
  70. +                MIN_PK_COUNT,
  71. +                MAX_HP,
  72. +                MAX_MP,
  73. +                MAX_CP,
  74. +                MIN_KARMA,
  75. +                MIN_RANK,
  76. +        }
  77. +}
  78. \ No newline at end of file
  79. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatusCondition.java
  80. ===================================================================
  81. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatusCondition.java (revision 0)
  82. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/condition/StatusCondition.java (revision 0)
  83. @@ -0,0 +1,36 @@
  84. +
  85. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition;
  86. +
  87. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  88. +
  89. +/**
  90. + * @author Matim
  91. + * @version 1.0
  92. + */
  93. +public abstract class StatusCondition extends Condition
  94. +{
  95. +        private StatusConditionType _type;
  96. +        
  97. +        public StatusCondition(Object value, StatusConditionType type)
  98. +        {
  99. +                super(value);
  100. +                _type = type;
  101. +        }
  102. +        
  103. +        public StatusConditionType getType()
  104. +        {
  105. +                return _type;
  106. +        }
  107. +        
  108. +        public enum StatusConditionType
  109. +        {
  110. +                MUST_BE_NOBLE,
  111. +                MUST_BE_HERO,
  112. +                MUST_BE_MARRIED,
  113. +                MUST_BE_ACADEMY_MEMBER,
  114. +                MUST_BE_MAGE,
  115. +                MUST_BE_SUMMONER,
  116. +                HAS_COMMON_CRAFT,
  117. +                HAS_DWARVEN_CRAFT,
  118. +        }
  119. +}
  120. \ No newline at end of file
  121. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Achievement.java
  122. ===================================================================
  123. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Achievement.java  (revision 0)
  124. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Achievement.java  (revision 0)
  125. @@ -0,0 +1,110 @@
  126. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.base;
  127. +
  128. +import java.util.logging.Logger;
  129. +
  130. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  131. +
  132. +import javolution.util.FastList;
  133. +import javolution.util.FastMap;
  134. +
  135. +/**
  136. + * @author Matim
  137. + * @version 1.0
  138. + */
  139. +public class Achievement
  140. +{
  141. +        private int _id;
  142. +        private String _name;
  143. +        private String _reward;
  144. +        private String _description = "No Description!";
  145. +        private boolean _repeatable;
  146. +        
  147. +        private FastMap<Integer, Long> _rewardList;
  148. +        private FastList<Condition> _conditions;
  149. +        
  150. +        private static Logger _log = Logger.getLogger(Achievement.class.getName());
  151. +        
  152. +        public Achievement(int id, String name, String description, String reward, boolean repeatable, FastList<Condition> conditions)
  153. +        {
  154. +                _rewardList = new FastMap<Integer, Long>();
  155. +                _id = id;
  156. +                _name = name;
  157. +                _description = description;
  158. +                _reward = reward;
  159. +                _conditions = conditions;
  160. +                _repeatable = repeatable;
  161. +
  162. +                createRewardList();
  163. +        }
  164. +        
  165. +        private void createRewardList()
  166. +        {
  167. +                for (String s : _reward.split(";"))
  168. +                {
  169. +                        if (s == null || s.isEmpty())
  170. +                                continue;
  171. +                        
  172. +                        String[] split = s.split(",");
  173. +                        Integer item = 0;
  174. +                        Long count = new Long(0);
  175. +                        try
  176. +                        {
  177. +                                item = Integer.valueOf(split[0]);
  178. +                                count = Long.valueOf(split[1]);
  179. +                        }
  180. +                        catch(NumberFormatException nfe)
  181. +                        {
  182. +                                _log.warning("[AchievementsEngine] Error: Wrong reward " + nfe);
  183. +                        }
  184. +                        _rewardList.put(item, count);
  185. +                }
  186. +        }
  187. +        
  188. +        public boolean meetAchievementRequirements(L2PcInstance player)
  189. +        {
  190. +                for (Condition c: getConditions())
  191. +                {
  192. +                        if (!c.meetConditionRequirements(player))
  193. +                        {
  194. +                                return false;
  195. +                        }
  196. +                }
  197. +                return true;
  198. +        }
  199. +        
  200. +        public int getID()
  201. +        {
  202. +                return _id;
  203. +        }
  204. +        
  205. +        public String getName()
  206. +        {
  207. +                return _name;
  208. +        }
  209. +        
  210. +        public String getDescription()
  211. +        {
  212. +                return _description;
  213. +        }
  214. +        
  215. +        public String getReward()
  216. +        {
  217. +                return _reward;
  218. +        }
  219. +        
  220. +        public boolean isRepeatable()
  221. +        {
  222. +                return _repeatable;
  223. +        }
  224. +        
  225. +        public FastMap<Integer, Long> getRewardList()
  226. +        {
  227. +                return _rewardList;
  228. +        }
  229. +        
  230. +        public FastList<Condition> getConditions()
  231. +        {
  232. +                return _conditions;
  233. +        }
  234. +}
  235. +
  236. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Condition.java
  237. ===================================================================
  238. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Condition.java    (revision 0)
  239. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/base/Condition.java    (revision 0)
  240. @@ -0,0 +1,24 @@
  241. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.base;
  242. +
  243. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  244. +
  245. +/**
  246. + * @author Matim
  247. + * @version 1.0
  248. + */
  249. +public abstract class Condition
  250. +{
  251. +        private Object _value;
  252. +        
  253. +        public Condition(Object value)
  254. +        {
  255. +                _value = value;
  256. +        }
  257. +        
  258. +        public abstract boolean meetConditionRequirements(L2PcInstance player);
  259. +        
  260. +        public Object getValue()
  261. +        {
  262. +                return _value;
  263. +        }
  264. +}
  265. \ No newline at end of file
  266. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/AchievementsManager.java
  267. ===================================================================
  268. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/AchievementsManager.java   (revision 0)
  269. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/AchievementsManager.java   (revision 0)
  270. @@ -0,0 +1,246 @@
  271. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine;
  272. +
  273. +import java.io.File;
  274. +import java.io.FileInputStream;
  275. +import java.io.InputStreamReader;
  276. +import java.sql.Connection;
  277. +import java.sql.SQLException;
  278. +import java.sql.Statement;
  279. +import java.util.Map;
  280. +import java.util.logging.Logger;
  281. +
  282. +import javax.xml.parsers.DocumentBuilderFactory;
  283. +
  284. +import javolution.util.FastList;
  285. +import javolution.util.FastMap;
  286. +
  287. +import org.w3c.dom.Document;
  288. +import org.w3c.dom.NamedNodeMap;
  289. +import org.w3c.dom.Node;
  290. +import org.xml.sax.InputSource;
  291. +
  292. +import com.l2jserver.Config;
  293. +import com.l2jserver.L2DatabaseFactory;
  294. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  295. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Achievement;
  296. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  297. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.ClanCondition.ClanConditionType;
  298. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatsCondition.StatsConditionType;
  299. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatusCondition.StatusConditionType;
  300. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Adena;
  301. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Clan;
  302. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.ItemsCount;
  303. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Level;
  304. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Stats;
  305. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.Status;
  306. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions.WeaponEnchant;
  307. +
  308. +/**
  309. + * @author Matim
  310. + * @version 1.0
  311. + */
  312. +public class AchievementsManager
  313. +{
  314. +        private Map<Integer, Achievement> _achievementList = new FastMap<Integer, Achievement>();
  315. +        
  316. +        private final String ACHIEVEMENTS_FILE_PATH = Config.DATAPACK_ROOT + "/data/achievements.xml";
  317. +        
  318. +        private static Logger _log = Logger.getLogger(AchievementsManager.class.getName());
  319. +        
  320. +        public AchievementsManager()
  321. +        {
  322. +                loadAchievements();
  323. +        }
  324. +        
  325. +        private void loadAchievements()
  326. +        {
  327. +                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  328. +                factory.setValidating(false);
  329. +                factory.setIgnoringComments(true);
  330. +                
  331. +                File file = new File(ACHIEVEMENTS_FILE_PATH);
  332. +                
  333. +                if (!file.exists())
  334. +                {
  335. +                        _log.warning("[AchievementsEngine] Error: achievements xml file does not exist, check directory!");
  336. +                }
  337. +                try
  338. +                {
  339. +                        InputSource in = new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8"));
  340. +                        in.setEncoding("UTF-8");
  341. +                        Document doc = factory.newDocumentBuilder().parse(in);
  342. +                        
  343. +                        for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  344. +                        {
  345. +                                if (n.getNodeName().equalsIgnoreCase("list"))
  346. +                                {
  347. +                                        for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  348. +                                        {
  349. +                                                if (d.getNodeName().equalsIgnoreCase("achievement"))
  350. +                                                {
  351. +                                                        int id = checkInt(d, "id");
  352. +                                                        
  353. +                                                        String name = String.valueOf(d.getAttributes().getNamedItem("name").getNodeValue());
  354. +                                                        String description = String.valueOf(d.getAttributes().getNamedItem("description").getNodeValue());
  355. +                                                        String reward = String.valueOf(d.getAttributes().getNamedItem("reward").getNodeValue());
  356. +                                                        boolean repeat = checkBoolean(d, "repeatable");
  357. +                                                        
  358. +                                                        FastList<Condition> conditions = conditionList(d.getAttributes());
  359. +                                                        
  360. +                                                        _achievementList.put(id, new Achievement(id, name, description, reward, repeat, conditions));
  361. +                                                        alterTable(id);
  362. +                                                }
  363. +                                        }
  364. +                                }
  365. +                        }
  366. +                        
  367. +                        _log.info("[AchievementsEngine] Successfully loaded: " + getAchievementList().size() + " achievements from xml!");
  368. +                }
  369. +                catch (Exception e)
  370. +                {
  371. +                        _log.warning("[AchievementsEngine] Error: " + e);
  372. +                        e.printStackTrace();
  373. +                }
  374. +        }
  375. +        
  376. +        public void rewardForAchievement(int achievementID, L2PcInstance player)
  377. +        {
  378. +                Achievement achievement = _achievementList.get(achievementID);
  379. +                
  380. +                for (int id: achievement.getRewardList().keySet())
  381. +                        player.addItem(achievement.getName(), id, achievement.getRewardList().get(id), player, true);
  382. +        }
  383. +        
  384. +        private boolean checkBoolean(Node d, String nodename)
  385. +        {
  386. +                boolean b = false;
  387. +                
  388. +                try
  389. +                {
  390. +                        b = Boolean.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
  391. +                }
  392. +                catch (Exception e)
  393. +                {
  394. +                        
  395. +                }
  396. +                return b;
  397. +        }
  398. +        
  399. +        private int checkInt(Node d, String nodename)
  400. +        {
  401. +                int i = 0;
  402. +                
  403. +                try
  404. +                {
  405. +                        i = Integer.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
  406. +                }
  407. +                catch (Exception e)
  408. +                {
  409. +                        
  410. +                }
  411. +                return i;
  412. +        }
  413. +        
  414. +        /**
  415. +         * Alter table, catch exception if already exist.
  416. +         * @param fieldID
  417. +         */
  418. +        private void alterTable(int fieldID)
  419. +        {
  420. +                Connection con = null;
  421. +                try
  422. +                {
  423. +                        con = L2DatabaseFactory.getInstance().getConnection();
  424. +                        Statement statement = con.createStatement();
  425. +                        statement.executeUpdate("ALTER TABLE achievements ADD a" + fieldID + " INT DEFAULT 0");
  426. +                        statement.close();
  427. +                }
  428. +                catch (SQLException e)
  429. +                {
  430. +
  431. +                }
  432. +                finally
  433. +                {
  434. +                        L2DatabaseFactory.close(con);
  435. +                }
  436. +        }
  437. +        
  438. +        public FastList<Condition> conditionList(NamedNodeMap attributesList)
  439. +        {
  440. +                FastList<Condition> conditions = new FastList<Condition>();
  441. +                
  442. +            for (int j = 0; j < attributesList.getLength(); j++)
  443. +            {
  444. +                addToConditionList(attributesList.item(j).getNodeName(), attributesList.item(j).getNodeValue(), conditions);
  445. +            }
  446. +                
  447. +                return conditions;
  448. +        }
  449. +        
  450. +        public Map<Integer, Achievement> getAchievementList()
  451. +        {
  452. +                return _achievementList;
  453. +        }
  454. +        
  455. +        public static AchievementsManager getInstance()
  456. +        {
  457. +                return SingletonHolder._instance;
  458. +        }
  459. +                
  460. +        private static class SingletonHolder
  461. +        {
  462. +                protected static final AchievementsManager _instance = new AchievementsManager();
  463. +        }
  464. +        
  465. +        private void addToConditionList(String nodeName, Object value, FastList<Condition> conditions)
  466. +        {
  467. +                if (nodeName.equals("minLevel"))
  468. +                        conditions.add(new Level(value));
  469. +                else if (nodeName.equals("minPvPCount"))
  470. +                        conditions.add(new Stats(value, StatsConditionType.MIN_PVP_COUNT));
  471. +                else if (nodeName.equals("minPkCount"))
  472. +                        conditions.add(new Stats(value, StatsConditionType.MIN_PK_COUNT));
  473. +                else if (nodeName.equals("minClanLevel"))
  474. +                        conditions.add(new Clan(value, ClanConditionType.MIN_CLAN_LEVEL));
  475. +                else if (nodeName.equals("mustBeHero"))
  476. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_HERO));
  477. +                else if (nodeName.equals("mustBeNoble"))
  478. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_NOBLE));
  479. +                else if (nodeName.equals("minWeaponEnchant"))
  480. +                        conditions.add(new WeaponEnchant(value));                      
  481. +                else if (nodeName.equals("minKarmaCount"))
  482. +                        conditions.add(new Stats(value, StatsConditionType.MIN_KARMA));
  483. +                else if (nodeName.equals("minRankCount"))
  484. +                    conditions.add(new Stats(value, StatsConditionType.MIN_RANK));
  485. +                else if (nodeName.equals("minAdenaCount"))
  486. +                        conditions.add(new Adena(value));
  487. +                else if (nodeName.equals("minClanMembersCount"))
  488. +                        conditions.add(new Clan(value, ClanConditionType.MIN_CLAN_MEMBERS_COUNT));
  489. +                else if (nodeName.equals("mustBeClanLeader"))
  490. +                        conditions.add(new Clan(value, ClanConditionType.MUST_BE_CLAN_LEADER));
  491. +                else if (nodeName.equals("maxHP"))
  492. +                        conditions.add(new Stats(value, StatsConditionType.MAX_HP));
  493. +                else if (nodeName.equals("maxMP"))
  494. +                        conditions.add(new Stats(value, StatsConditionType.MAX_MP));
  495. +                else if (nodeName.equals("maxCP"))
  496. +                        conditions.add(new Stats(value, StatsConditionType.MAX_CP));
  497. +                else if (nodeName.equals("mustBeMarried"))
  498. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_MARRIED));
  499. +                else if (nodeName.equals("itemAmmount"))
  500. +                        conditions.add(new ItemsCount(value));
  501. +                else if (nodeName.equals("crpAmmount"))
  502. +                        conditions.add(new Clan(value, ClanConditionType.CRP_AMMOUNT));
  503. +                else if (nodeName.equals("lordOfCastle"))
  504. +                        conditions.add(new Clan(value, ClanConditionType.IS_CASTLE_LORD));
  505. +                else if (nodeName.equals("mustBeAcademyMember"))
  506. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_ACADEMY_MEMBER));
  507. +                else if (nodeName.equals("mustBeMageClass"))
  508. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_MAGE));    
  509. +                else if (nodeName.equals("mustBeSummoner"))
  510. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_SUMMONER));
  511. +                else if (nodeName.equals("hasCommonCraft"))
  512. +                        conditions.add(new Status(value, StatusConditionType.HAS_COMMON_CRAFT));
  513. +                else if (nodeName.equals("hasDwarvenCraft"))
  514. +                        conditions.add(new Status(value, StatusConditionType.HAS_DWARVEN_CRAFT));
  515. +        }
  516. +}
  517. \ No newline at end of file
  518. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Adena.java
  519. ===================================================================
  520. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Adena.java  (revision 0)
  521. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Adena.java  (revision 0)
  522. @@ -0,0 +1,33 @@
  523. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
  524. +
  525. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  526. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  527. +
  528. +/**
  529. + * @author Matim
  530. + * @version 1.0
  531. + */
  532. +public class Adena extends Condition
  533. +{
  534. +        public Adena(Object value)
  535. +        {
  536. +                super(value);
  537. +        }
  538. +
  539. +        @Override
  540. +        public boolean meetConditionRequirements(L2PcInstance player)
  541. +        {
  542. +                if (getValue() == null)
  543. +                {
  544. +                        return false;
  545. +                }
  546. +                else
  547. +                {
  548. +                        long val = Integer.parseInt(getValue().toString());
  549. +                        
  550. +                        if (player.getInventory().getAdena() >= val)
  551. +                                return true;
  552. +                }
  553. +                return false;
  554. +        }
  555. +}
  556. \ No newline at end of file
  557. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Clan.java
  558. ===================================================================
  559. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Clan.java   (revision 0)
  560. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Clan.java   (revision 0)
  561. @@ -0,0 +1,69 @@
  562. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
  563. +
  564. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  565. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.ClanCondition;
  566. +
  567. +/**
  568. + * @author Matim
  569. + * @version 1.0
  570. + */
  571. +public class Clan extends ClanCondition
  572. +{
  573. +        public Clan(Object value, ClanConditionType type)
  574. +        {
  575. +                super(value, type);
  576. +        }
  577. +
  578. +        @Override
  579. +        public boolean meetConditionRequirements(L2PcInstance player)
  580. +        {
  581. +                if (getValue() == null)
  582. +                {
  583. +                        return false;
  584. +                }
  585. +                
  586. +            if (player.getClan() != null)
  587. +                {
  588. +                        int val = Integer.parseInt(getValue().toString());
  589. +                        
  590. +                        switch (getType())
  591. +                        {
  592. +                                case MIN_CLAN_LEVEL:
  593. +                                        if (player.getClan().getLevel() >= val)
  594. +                                        {
  595. +                                                return true;
  596. +                                        }
  597. +                                    break;
  598. +                                    
  599. +                                case MIN_CLAN_MEMBERS_COUNT:
  600. +                                        if (player.getClan().getMembersCount() >= val)
  601. +                                        {
  602. +                                                return true;
  603. +                                        }
  604. +                                    break;
  605. +                                    
  606. +                                case MUST_BE_CLAN_LEADER:
  607. +                                        if (player.isClanLeader())
  608. +                                        {
  609. +                                                return true;
  610. +                                        }
  611. +                                    break;
  612. +                                    
  613. +                                case CRP_AMMOUNT:
  614. +                                        if (player.getClan().getReputationScore() >= val)
  615. +                                        {
  616. +                                                return true;
  617. +                                        }
  618. +                                        break;
  619. +                                        
  620. +                                case IS_CASTLE_LORD:
  621. +                                        if (player.isCastleLord(val))
  622. +                                        {
  623. +                                                return true;
  624. +                                        }
  625. +                                        break;
  626. +                        }
  627. +                }
  628. +                return false;
  629. +        }
  630. +}
  631. \ No newline at end of file
  632. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/ItemsCount.java
  633. ===================================================================
  634. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/ItemsCount.java (revision 0)
  635. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/ItemsCount.java (revision 0)
  636. @@ -0,0 +1,53 @@
  637. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
  638. +
  639. +import java.util.StringTokenizer;
  640. +
  641. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  642. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  643. +
  644. +/**
  645. + * @author Matim
  646. + * @version 1.0
  647. + * <br><br>
  648. + * Condition: ItemsCount
  649. + * Check if player has proper ammount of item in inventory.
  650. + */
  651. +public class ItemsCount extends Condition
  652. +{
  653. +        public ItemsCount(Object value)
  654. +        {
  655. +                super(value);
  656. +        }
  657. +
  658. +        @Override
  659. +        public boolean meetConditionRequirements(L2PcInstance player)
  660. +        {
  661. +                if (getValue() == null)
  662. +                {
  663. +                        return false;
  664. +                }
  665. +                else
  666. +                {
  667. +                        String s = getValue().toString();
  668. +                        StringTokenizer st = new StringTokenizer(s, ",");
  669. +                        int id = 0;
  670. +                        long ammount = 0;
  671. +                        
  672. +                        try
  673. +                        {
  674. +                                id = Integer.parseInt(st.nextToken());
  675. +                                ammount = Integer.parseInt(st.nextToken());
  676. +                                
  677. +                                if (player.getInventory().getItemsByItemId(id).size() >= ammount)
  678. +                                {
  679. +                                        return true;
  680. +                                }
  681. +                        }
  682. +                        catch (NumberFormatException nfe)
  683. +                        {
  684. +                                nfe.printStackTrace();
  685. +                        }
  686. +                }
  687. +                return false;
  688. +        }
  689. +}
  690. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Level.java
  691. ===================================================================
  692. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Level.java  (revision 0)
  693. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Level.java  (revision 0)
  694. @@ -0,0 +1,33 @@
  695. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
  696. +
  697. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  698. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  699. +
  700. +/**
  701. + * @author Matim
  702. + * @version 1.0
  703. + */
  704. +public class Level extends Condition
  705. +{
  706. +        public Level(Object value)
  707. +        {
  708. +                super(value);
  709. +        }
  710. +        
  711. +        @Override
  712. +        public boolean meetConditionRequirements(L2PcInstance player)
  713. +        {
  714. +                if (getValue() == null)
  715. +                {
  716. +                        return false;
  717. +                }
  718. +                else
  719. +                {
  720. +                        int val = Integer.parseInt(getValue().toString());
  721. +                        
  722. +                        if (player.getLevel() >= val)
  723. +                                return true;
  724. +                }
  725. +                return false;
  726. +        }
  727. +}
  728. \ No newline at end of file
  729. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Stats.java
  730. ===================================================================
  731. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Stats.java  (revision 0)
  732. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Stats.java  (revision 0)
  733. @@ -0,0 +1,81 @@
  734. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
  735. +
  736. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  737. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatsCondition;
  738. +
  739. +/**
  740. + * @author Matim
  741. + * @version 1.0
  742. + */
  743. +public class Stats extends StatsCondition
  744. +{
  745. +        public Stats(Object value, StatsConditionType type)
  746. +        {
  747. +                super(value, type);
  748. +        }
  749. +
  750. +        @Override
  751. +        public boolean meetConditionRequirements(L2PcInstance player)
  752. +        {
  753. +                if (getValue() == null)
  754. +                {
  755. +                        return false;
  756. +                }
  757. +                
  758. +                int val = Integer.parseInt(getValue().toString());
  759. +                
  760. +                switch (getType())
  761. +                {
  762. +                        case MAX_HP:
  763. +                                if (player.getMaxHp() >= val)
  764. +                                {
  765. +                                        return true;
  766. +                                }
  767. +                                break;
  768. +                                
  769. +                        case MAX_CP:
  770. +                                if (player.getMaxCp() >= val)
  771. +                                {
  772. +                                        return true;
  773. +                                }
  774. +                                break;
  775. +                                
  776. +                        case MAX_MP:
  777. +                                if (player.getMaxMp() >= val)
  778. +                                {
  779. +                                        return true;
  780. +                                }
  781. +                                break;
  782. +                                
  783. +                        case MIN_PK_COUNT:
  784. +                                if (player.getPkKills() >= val)
  785. +                                {
  786. +                                        return true;
  787. +                                }
  788. +                                break;
  789. +                                
  790. +                        case MIN_PVP_COUNT:
  791. +                                if (player.getPvpKills() >= val)
  792. +                                {
  793. +                                        return true;
  794. +                                }
  795. +                                break;
  796. +                                
  797. +                        case MIN_KARMA:
  798. +                                if (player.getKarma() >= val)
  799. +                                {
  800. +                                        return true;
  801. +                                }
  802. +                                break;
  803. +                                
  804. +                        case MIN_RANK:
  805. +                            if (player.getRank() >= val)
  806. +                            {
  807. +                                    return true;
  808. +                            }
  809. +                            break;
  810. +                }
  811. +                
  812. +                return false;
  813. +        }
  814. +}
  815. \ No newline at end of file
  816. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Status.java
  817. ===================================================================
  818. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Status.java (revision 0)
  819. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/Status.java (revision 0)
  820. @@ -0,0 +1,85 @@
  821. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
  822. +
  823. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  824. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.condition.StatusCondition;
  825. +
  826. +/**
  827. + * @author Matim
  828. + * @version 1.0
  829. + */
  830. +public class Status extends StatusCondition
  831. +{
  832. +        public Status(Object value, StatusConditionType type)
  833. +        {
  834. +                super(value, type);
  835. +        }
  836. +
  837. +        @Override
  838. +        public boolean meetConditionRequirements(L2PcInstance player)
  839. +        {
  840. +                if (getValue() == null)
  841. +                {
  842. +                        return false;
  843. +                }
  844. +                
  845. +                switch (getType())
  846. +                {
  847. +                        case MUST_BE_NOBLE:
  848. +                                if (player.isNoble())
  849. +                                {
  850. +                                        return true;
  851. +                                }
  852. +                                break;
  853. +                                
  854. +                        case MUST_BE_HERO:
  855. +                                if (player.isHero())
  856. +                                {
  857. +                                        return true;
  858. +                                }
  859. +                                break;
  860. +                                
  861. +                        case MUST_BE_MARRIED:
  862. +                                if (player.isMarried())
  863. +                                {
  864. +                                        return true;
  865. +                                }
  866. +                                break;
  867. +                                
  868. +                        case MUST_BE_ACADEMY_MEMBER:
  869. +                                if (player.isAcademyMember())
  870. +                                {
  871. +                                        return true;
  872. +                                }
  873. +                                break;
  874. +                                
  875. +                        case MUST_BE_MAGE:
  876. +                                if (player.isMageClass())
  877. +                                {
  878. +                                        return true;
  879. +                                }
  880. +                                break;
  881. +                                
  882. +                        case MUST_BE_SUMMONER:
  883. +                                if (player.getClassId().isSummoner())
  884. +                                {
  885. +                                        return true;
  886. +                                }
  887. +                                break;
  888. +                                
  889. +                        case HAS_COMMON_CRAFT:
  890. +                                if (player.hasCommonCraft())
  891. +                                {
  892. +                                        return true;
  893. +                                }
  894. +                                break;
  895. +                                
  896. +                        case HAS_DWARVEN_CRAFT:
  897. +                                if (player.hasCommonCraft())
  898. +                                {
  899. +                                        return true;
  900. +                                }
  901. +                                break;
  902. +                } //TODO CLASS ID
  903. +                return false;
  904. +        }
  905. +}
  906. \ No newline at end of file
  907. Index: java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/WeaponEnchant.java
  908. ===================================================================
  909. --- java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/WeaponEnchant.java  (revision 0)
  910. +++ java/com/l2jserver/gameserver/model/entity/AchievmentsEngine/conditions/WeaponEnchant.java  (revision 0)
  911. @@ -0,0 +1,40 @@
  912. +package com.l2jserver.gameserver.model.entity.AchievmentsEngine.conditions;
  913. +
  914. +import com.l2jserver.gameserver.model.L2ItemInstance;
  915. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  916. +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition;
  917. +import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  918. +
  919. +/**
  920. + * @author Matim
  921. + * @version 1.0
  922. + */
  923. +public class WeaponEnchant extends Condition
  924. +{
  925. +        public WeaponEnchant(Object value)
  926. +        {
  927. +                super(value);
  928. +        }
  929. +
  930. +        @Override
  931. +        public boolean meetConditionRequirements(L2PcInstance player)
  932. +        {
  933. +                if (getValue() == null)
  934. +                {
  935. +                        return false;
  936. +                }
  937. +                
  938. +                int val = Integer.parseInt(getValue().toString());
  939. +                
  940. +                L2ItemInstance weapon = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  941. +                
  942. +                if (weapon != null)
  943. +                {
  944. +                        if (weapon.getEnchantLevel() >= val)
  945. +                        {
  946. +                                return true;
  947. +                        }
  948. +                }
  949. +                return false;
  950. +        }
  951. +}[/code]
  952.  
  953. for L2PcInstance
  954.  
  955. [code]+private List<Integer> _completedAchievements = new FastList<Integer>();
  956. +  
  957. +   public boolean readyAchievementsList()
  958. +   {
  959. +       if (_completedAchievements.isEmpty())
  960. +           return false;
  961. +       else
  962. +           return true;
  963. +   }
  964. +  
  965. +   public void saveAchievemntData()
  966. +   {
  967. +      
  968. +   }
  969. +  
  970. +   public void getAchievemntData()
  971. +   {
  972. +       Connection con = null;
  973. +       try
  974. +       {          
  975. +           PreparedStatement statement;
  976. +           PreparedStatement insertStatement;
  977. +           ResultSet rs;
  978. +           con = L2DatabaseFactory.getInstance().getConnection();
  979. +          
  980. +           statement = con.prepareStatement("SELECT * from achievements WHERE owner_id=" + getObjectId());
  981. +          
  982. +           rs = statement.executeQuery();  
  983. +          
  984. +           String values = "owner_id";
  985. +           String in = Integer.toString(getObjectId());
  986. +           String questionMarks = in;
  987. +           int ilosc = AchievementsManager.getInstance().getAchievementList().size();
  988. +          
  989. +           if (rs.next())
  990. +           {  
  991. +               _completedAchievements.clear();
  992. +               for (int i=1; i <=ilosc; i++)
  993. +               {
  994. +                   int a = rs.getInt("a" + i);
  995. +                  
  996. +                   if (!_completedAchievements.contains(i))
  997. +                       if (a == 1)
  998. +                           _completedAchievements.add(i);
  999. +               }
  1000. +           }
  1001. +           else
  1002. +           {
  1003. +               //Player hasnt entry in database, means we have to create it.
  1004. +              
  1005. +               for (int i=1; i <=ilosc; i++)
  1006. +               {
  1007. +                   values += ", a" + i;
  1008. +                   questionMarks += ", 0";
  1009. +               }
  1010. +              
  1011. +               String s = "INSERT INTO achievements(" + values + ") VALUES (" + questionMarks + ")";
  1012. +               insertStatement = con.prepareStatement(s);
  1013. +              
  1014. +               insertStatement.execute();
  1015. +               insertStatement.close();
  1016. +           }
  1017. +       }
  1018. +       catch (SQLException e)
  1019. +       {
  1020. +           _log.warning("[ACHIEVEMENTS ENGINE GETDATA]" + e);
  1021. +       }
  1022. +       finally
  1023. +       {
  1024. +           L2DatabaseFactory.close(con);
  1025. +       }
  1026. +   }
  1027. +  
  1028. +   public void saveAchievementData(int achievementID)
  1029. +   {
  1030. +       Connection con = null;
  1031. +       try
  1032. +       {          
  1033. +           con = L2DatabaseFactory.getInstance().getConnection();
  1034. +           Statement statement = con.createStatement();
  1035. +           statement.executeUpdate("UPDATE achievements SET a" + achievementID + "=1 WHERE owner_id=" + getObjectId());
  1036. +           statement.close();
  1037. +          
  1038. +           if (!_completedAchievements.contains(achievementID))
  1039. +               _completedAchievements.add(achievementID);
  1040. +       }
  1041. +       catch (SQLException e)
  1042. +       {
  1043. +           _log.warning("[ACHIEVEMENTS SAVE GETDATA]" + e);
  1044. +       }
  1045. +       finally
  1046. +       {
  1047. +           L2DatabaseFactory.close(con);
  1048. +       }
  1049. +   }
  1050. +  
  1051. +   public List<Integer> getCompletedAchievements()
  1052. +   {
  1053. +       return _completedAchievements;
  1054. +   }
  1055. +
Advertisement
Add Comment
Please, Sign In to add comment