Advertisement
ChristianMacedo

Anchievement para C4

Nov 19th, 2022 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.80 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P core
  3. diff --git java/net/sf/l2j/achievementEngine/Achievement.java
  4. new file mode 100644
  5. index 0000000..a37c61e
  6. --- /dev/null
  7. +++ java/net/sf/l2j/achievementEngine/Achievement.java
  8. @@ -0,0 +1,106 @@
  9. +package net.sf.l2j.achievementEngine;
  10. +
  11. +import java.util.logging.Logger;
  12. +
  13. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  14. +
  15. +import java.util.ArrayList;
  16. +import java.util.HashMap;
  17. +
  18. +public class Achievement
  19. +{
  20. + private int _id;
  21. + private String _name;
  22. + private String _reward;
  23. + private String _description = "No Description!";
  24. + private boolean _repeatable;
  25. +
  26. + private HashMap<Integer, Long> _rewardList;
  27. + private ArrayList<Condition> _conditions;
  28. +
  29. + private static Logger _log = Logger.getLogger(Achievement.class.getName());
  30. +
  31. + public Achievement(int id, String name, String description, String reward, boolean repeatable, ArrayList<Condition> conditions)
  32. + {
  33. + _rewardList = new HashMap<Integer, Long>();
  34. + _id = id;
  35. + _name = name;
  36. + _description = description;
  37. + _reward = reward;
  38. + _conditions = conditions;
  39. + _repeatable = repeatable;
  40. +
  41. + createRewardList();
  42. + }
  43. +
  44. + private void createRewardList()
  45. + {
  46. + for (String s : _reward.split(";"))
  47. + {
  48. + if (s == null || s.isEmpty())
  49. + continue;
  50. +
  51. + String[] split = s.split(",");
  52. + Integer item = 0;
  53. + //Long count = new Long(0);
  54. + Long count = Long.valueOf(0);
  55. + try
  56. + {
  57. + item = Integer.valueOf(split[0]);
  58. + count = Long.valueOf(split[1]);
  59. + }
  60. + catch(NumberFormatException nfe)
  61. + {
  62. + _log.warning("[AchievementsEngine] Error: Wrong reward " + nfe);
  63. + }
  64. + _rewardList.put(item, count);
  65. + }
  66. + }
  67. +
  68. + public boolean meetAchievementRequirements(L2PcInstance player)
  69. + {
  70. + for (Condition c: getConditions())
  71. + {
  72. + if (!c.meetConditionRequirements(player))
  73. + {
  74. + return false;
  75. + }
  76. + }
  77. + return true;
  78. + }
  79. +
  80. + public int getID()
  81. + {
  82. + return _id;
  83. + }
  84. +
  85. + public String getName()
  86. + {
  87. + return _name;
  88. + }
  89. +
  90. + public String getDescription()
  91. + {
  92. + return _description;
  93. + }
  94. +
  95. + public String getReward()
  96. + {
  97. + return _reward;
  98. + }
  99. +
  100. + public boolean isRepeatable()
  101. + {
  102. + return _repeatable;
  103. + }
  104. +
  105. + public HashMap<Integer, Long> getRewardList()
  106. + {
  107. + return _rewardList;
  108. + }
  109. +
  110. + public ArrayList<Condition> getConditions()
  111. + {
  112. + return _conditions;
  113. + }
  114. +}
  115. diff --git java/net/sf/l2j/achievementEngine/AchievementsManager.java
  116. new file mode 100644
  117. index 0000000..b6ca1d8
  118. --- /dev/null
  119. +++ java/net/sf/l2j/achievementEngine/AchievementsManager.java
  120. @@ -0,0 +1,272 @@
  121. +package net.sf.l2j.achievementEngine;
  122. +
  123. +import java.io.File;
  124. +import java.sql.Connection;
  125. +import java.sql.SQLException;
  126. +import java.sql.Statement;
  127. +import java.util.ArrayList;
  128. +import java.util.HashMap;
  129. +import java.util.Map;
  130. +import java.util.logging.Logger;
  131. +
  132. +import javax.xml.parsers.DocumentBuilderFactory;
  133. +
  134. +import org.w3c.dom.Document;
  135. +import org.w3c.dom.NamedNodeMap;
  136. +import org.w3c.dom.Node;
  137. +
  138. +import net.sf.l2j.L2DatabaseFactory;
  139. +import net.sf.l2j.achievementEngine.EnchantAmor.Chest;
  140. +import net.sf.l2j.achievementEngine.EnchantAmor.Feet;
  141. +import net.sf.l2j.achievementEngine.EnchantAmor.Gloves;
  142. +import net.sf.l2j.achievementEngine.EnchantAmor.Head;
  143. +import net.sf.l2j.achievementEngine.EnchantAmor.Legs;
  144. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  145. +
  146. +public class AchievementsManager
  147. +{
  148. + private Map<Integer, Achievement> _achievementList = new HashMap<Integer, Achievement>();
  149. +
  150. +
  151. + private static Logger _log = Logger.getLogger(AchievementsManager.class.getName());
  152. +
  153. + public AchievementsManager()
  154. + {
  155. + loadAchievements();
  156. + }
  157. +
  158. + private void loadAchievements()
  159. + {
  160. + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  161. + factory.setValidating(false);
  162. + factory.setIgnoringComments(true);
  163. +
  164. + File file = new File("config/achievements.xml");
  165. + if (!file.exists())
  166. + {
  167. + _log.warning("[AchievementsEngine] Error: achievements xml file does not exist, check directory!");
  168. + }
  169. + try
  170. + {
  171. + Document doc = factory.newDocumentBuilder().parse(file);
  172. +
  173. + for (Node list = doc.getFirstChild(); list != null; list = list.getNextSibling())
  174. + {
  175. + if("list".equalsIgnoreCase(list.getNodeName()))
  176. + {
  177. + for (Node achievement = list.getFirstChild(); achievement != null; achievement = achievement.getNextSibling())
  178. + {
  179. + if("achievement".equalsIgnoreCase(achievement.getNodeName()))
  180. + {
  181. + int id = checkInt(achievement, "id");
  182. +
  183. + String name = String.valueOf(achievement.getAttributes().getNamedItem("name").getNodeValue());
  184. + String description = String.valueOf(achievement.getAttributes().getNamedItem("description").getNodeValue());
  185. + String reward = String.valueOf(achievement.getAttributes().getNamedItem("reward").getNodeValue());
  186. + boolean repeat = checkBoolean(achievement, "repeatable");
  187. +
  188. + ArrayList<Condition> conditions = conditionList(achievement.getAttributes());
  189. +
  190. + _achievementList.put(id, new Achievement(id, name, description, reward, repeat, conditions));
  191. + alterTable(id);
  192. + }
  193. + }
  194. + }
  195. + }
  196. + _log.info("--------------------------------------------------------------------");
  197. + _log.info(" ");
  198. + _log.info("[AchievementsEngine] Successfully loaded: " + getAchievementList().size() + " achievements from xml!");
  199. + _log.info(" AchievementsEngine ");
  200. + _log.info(" ");
  201. + _log.info("--------------------------------------------------------------------");
  202. + }
  203. + catch (Exception e)
  204. + {
  205. + _log.warning("[AchievementsEngine] Error: " + e);
  206. + e.printStackTrace();
  207. + }
  208. + }
  209. +
  210. + public void rewardForAchievement(int achievementID, L2PcInstance player)
  211. + {
  212. + Achievement achievement = _achievementList.get(achievementID);
  213. +
  214. + for (int id: achievement.getRewardList().keySet())
  215. + player.addItem(achievement.getName(), id, achievement.getRewardList().get(id), player, true);
  216. + }
  217. +
  218. + private boolean checkBoolean(Node d, String nodename)
  219. + {
  220. + boolean b = false;
  221. +
  222. + try
  223. + {
  224. + b = Boolean.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
  225. + }
  226. + catch (Exception e)
  227. + {
  228. +
  229. + }
  230. + return b;
  231. + }
  232. +
  233. + private int checkInt(Node d, String nodename)
  234. + {
  235. + int i = 0;
  236. +
  237. + try
  238. + {
  239. + i = Integer.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
  240. + }
  241. + catch (Exception e)
  242. + {
  243. +
  244. + }
  245. + return i;
  246. + }
  247. +
  248. + /**
  249. + * Alter table, catch exception if already exist.
  250. + * @param fieldID
  251. + */
  252. + private void alterTable(int fieldID)
  253. + {
  254. + Connection con = null;
  255. + try
  256. + {
  257. + con = L2DatabaseFactory.getInstance().getConnection();
  258. + Statement statement = con.createStatement();
  259. + statement.executeUpdate("ALTER TABLE achievements ADD a" + fieldID + " INT DEFAULT 0");
  260. + statement.close();
  261. + }
  262. + catch (SQLException e)
  263. + {
  264. +
  265. + }
  266. + }
  267. +
  268. + public ArrayList<Condition> conditionList(NamedNodeMap attributesList)
  269. + {
  270. + ArrayList<Condition> conditions = new ArrayList<Condition>();
  271. +
  272. + for (int j = 0; j < attributesList.getLength(); j++)
  273. + {
  274. + addToConditionList(attributesList.item(j).getNodeName(), attributesList.item(j).getNodeValue(), conditions);
  275. + }
  276. +
  277. + return conditions;
  278. + }
  279. +
  280. + public Map<Integer, Achievement> getAchievementList()
  281. + {
  282. + return _achievementList;
  283. + }
  284. +
  285. + public static AchievementsManager getInstance()
  286. + {
  287. + return SingletonHolder._instance;
  288. + }
  289. +
  290. + private static class SingletonHolder
  291. + {
  292. + protected static final AchievementsManager _instance = new AchievementsManager();
  293. + }
  294. +
  295. + private void addToConditionList(String nodeName, Object value, ArrayList<Condition> conditions)
  296. + {
  297. + if (nodeName.equals("minLevel"))
  298. + conditions.add(new Level(value));
  299. +
  300. + else if (nodeName.equals("minPvPCount"))
  301. + conditions.add(new Pvp(value));
  302. +
  303. + else if (nodeName.equals("minPkCount"))
  304. + conditions.add(new Pk(value));
  305. +
  306. + else if (nodeName.equals("minClanLevel"))
  307. + conditions.add(new ClanLevel(value));
  308. +
  309. + else if (nodeName.equals("mustBeHero"))
  310. + conditions.add(new Hero(value));
  311. +
  312. + else if (nodeName.equals("mustBeNoble"))
  313. + conditions.add(new Noble(value));
  314. +
  315. + else if (nodeName.equals("mustBeClanLeader"))
  316. + conditions.add(new ClanLeader(value));
  317. +
  318. + else if (nodeName.equals("minWeaponEnchant"))
  319. + conditions.add(new WeaponEnchant(value));
  320. +
  321. + else if (nodeName.equals("minKarmaCount"))
  322. + conditions.add(new Karma(value));
  323. +
  324. + else if (nodeName.equals("minAdenaCount"))
  325. + conditions.add(new Adena(value));
  326. +
  327. + else if (nodeName.equals("minClanMembersCount"))
  328. + conditions.add(new MinCMcount(value));
  329. +
  330. + else if (nodeName.equals("maxHP"))
  331. + conditions.add(new Maxhp(value));
  332. +
  333. + else if (nodeName.equals("maxMP"))
  334. + conditions.add(new Maxmp(value));
  335. +
  336. + else if (nodeName.equals("maxCP"))
  337. + conditions.add(new Maxcp(value));
  338. +
  339. + else if (nodeName.equals("mustBeMarried"))
  340. + conditions.add(new Marry(value));
  341. +
  342. + else if (nodeName.equals("itemAmmount"))
  343. + conditions.add(new ItemsCount(value));
  344. +
  345. + //else if (nodeName.equals("crpAmmount"))
  346. + //conditions.add(new Crp(value));
  347. +
  348. + else if (nodeName.equals("lordOfCastle"))
  349. + conditions.add(new Castle(value));
  350. +
  351. + else if (nodeName.equals("mustBeMageClass"))
  352. + conditions.add(new Mageclass(value));
  353. +
  354. + else if (nodeName.equals("mustBeVip"))
  355. + conditions.add(new Noble(value));
  356. +
  357. + //else if (nodeName.equals("raidToKill"))
  358. + //conditions.add(new RaidKill(value));
  359. +
  360. + else if (nodeName.equals("CompleteAchievements"))
  361. + conditions.add(new CompleteAchievements(value));
  362. +
  363. + else if (nodeName.equals("minSubclassCount"))
  364. + conditions.add(new Sub(value));
  365. +
  366. + else if (nodeName.equals("minSkillEnchant"))
  367. + conditions.add(new SkillEnchant(value));
  368. +
  369. + else if (nodeName.equals("minOnlineTime"))
  370. + conditions.add(new OnlineTime(value));
  371. +
  372. + // else if (nodeName.equals("Cursedweapon"))
  373. + // conditions.add(new CursedWeapon(value));
  374. +
  375. + else if (nodeName.equals("minHeadEnchant"))
  376. + conditions.add(new Head(value));
  377. +
  378. + else if (nodeName.equals("minChestEnchant"))
  379. + conditions.add(new Chest(value));
  380. +
  381. + else if (nodeName.equals("minFeetEnchant"))
  382. + conditions.add(new Feet(value));
  383. +
  384. + else if (nodeName.equals("minLegsEnchant"))
  385. + conditions.add(new Legs(value));
  386. +
  387. + else if (nodeName.equals("minGlovestEnchant"))
  388. + conditions.add(new Gloves(value));
  389. +
  390. +
  391. + }
  392. +}
  393. \ No newline at end of file
  394. diff --git java/net/sf/l2j/achievementEngine/Adena.java
  395. new file mode 100644
  396. index 0000000..780b473
  397. --- /dev/null
  398. +++ java/net/sf/l2j/achievementEngine/Adena.java
  399. @@ -0,0 +1,26 @@
  400. +package net.sf.l2j.achievementEngine;
  401. +
  402. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  403. +
  404. +public class Adena extends Condition
  405. +{
  406. + public Adena(Object value)
  407. + {
  408. + super(value);
  409. + setName("Adena");
  410. + }
  411. +
  412. + @Override
  413. + public boolean meetConditionRequirements(L2PcInstance player)
  414. + {
  415. + if (getValue() == null)
  416. + {
  417. + return false;
  418. + }
  419. + long val = Integer.parseInt(getValue().toString());
  420. +
  421. + if (player.getInventory().getAdena() >= val)
  422. + return true;
  423. + return false;
  424. + }
  425. +}
  426. \ No newline at end of file
  427. diff --git java/net/sf/l2j/achievementEngine/Castle.java
  428. new file mode 100644
  429. index 0000000..ad77e91
  430. --- /dev/null
  431. +++ java/net/sf/l2j/achievementEngine/Castle.java
  432. @@ -0,0 +1,28 @@
  433. +package net.sf.l2j.achievementEngine;
  434. +
  435. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  436. +
  437. +
  438. +public class Castle extends Condition
  439. +{
  440. + public Castle(Object value)
  441. + {
  442. + super(value);
  443. + setName("Have Castle");
  444. + }
  445. +
  446. + @Override
  447. + public boolean meetConditionRequirements(L2PcInstance player)
  448. + {
  449. + if (getValue() == null)
  450. + {
  451. + return false;
  452. + }
  453. + if (player.getClan() != null)
  454. + {
  455. + if ((player.isCastleLord(5)) || (player.isCastleLord(3)) || (player.isCastleLord(7)))
  456. + return true;
  457. + }
  458. + return false;
  459. + }
  460. +}
  461. \ No newline at end of file
  462. diff --git java/net/sf/l2j/achievementEngine/ClanLeader.java
  463. new file mode 100644
  464. index 0000000..3f00e9b
  465. --- /dev/null
  466. +++ java/net/sf/l2j/achievementEngine/ClanLeader.java
  467. @@ -0,0 +1,25 @@
  468. +package net.sf.l2j.achievementEngine;
  469. +
  470. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  471. +
  472. +
  473. +public class ClanLeader extends Condition
  474. +{
  475. + public ClanLeader(Object value)
  476. + {
  477. + super(value);
  478. + setName("Be Clan Leader");
  479. + }
  480. +
  481. + @Override
  482. + public boolean meetConditionRequirements(L2PcInstance player)
  483. + {
  484. + if (getValue() == null)
  485. + {
  486. + return false;
  487. + }
  488. +
  489. + return (player.getClan() != null) &&
  490. + (player.isClanLeader());
  491. + }
  492. +}
  493. \ No newline at end of file
  494. diff --git java/net/sf/l2j/achievementEngine/ClanLevel.java
  495. new file mode 100644
  496. index 0000000..0239700
  497. --- /dev/null
  498. +++ java/net/sf/l2j/achievementEngine/ClanLevel.java
  499. @@ -0,0 +1,28 @@
  500. +package net.sf.l2j.achievementEngine;
  501. +
  502. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  503. +
  504. +public class ClanLevel extends Condition
  505. +{
  506. + public ClanLevel(Object value)
  507. + {
  508. + super(value);
  509. + setName("Clan Level");
  510. + }
  511. +
  512. + @Override
  513. + public boolean meetConditionRequirements(L2PcInstance player)
  514. + {
  515. + if (getValue() == null) {
  516. + return false;
  517. + }
  518. + if (player.getClan() != null)
  519. + {
  520. + int val = Integer.parseInt(getValue().toString());
  521. +
  522. + if (player.getClan().getLevel() >= val)
  523. + return true;
  524. + }
  525. + return false;
  526. + }
  527. +}
  528. \ No newline at end of file
  529. diff --git java/net/sf/l2j/achievementEngine/CompleteAchievements.java
  530. new file mode 100644
  531. index 0000000..8fa7162
  532. --- /dev/null
  533. +++ java/net/sf/l2j/achievementEngine/CompleteAchievements.java
  534. @@ -0,0 +1,27 @@
  535. +package net.sf.l2j.achievementEngine;
  536. +
  537. +import java.util.List;
  538. +
  539. +import net.sf.l2j.achievementEngine.Condition;
  540. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  541. +
  542. +public class CompleteAchievements extends Condition
  543. +{
  544. + public CompleteAchievements(Object value)
  545. + {
  546. + super(value);
  547. + setName("Complete Achievements");
  548. + }
  549. +
  550. + @Override
  551. + public boolean meetConditionRequirements(L2PcInstance player)
  552. + {
  553. + if (getValue() == null)
  554. + {
  555. + return false;
  556. + }
  557. + int val = Integer.parseInt(getValue().toString());
  558. +
  559. + return player.getCompletedAchievements().size() >= val;
  560. + }
  561. +}
  562. \ No newline at end of file
  563. diff --git java/net/sf/l2j/achievementEngine/Condition.java
  564. new file mode 100644
  565. index 0000000..5e382f8
  566. --- /dev/null
  567. +++ java/net/sf/l2j/achievementEngine/Condition.java
  568. @@ -0,0 +1,30 @@
  569. +package net. sf.l2j.achievementEngine;
  570. +
  571. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  572. +
  573. +public abstract class Condition
  574. +{
  575. + private Object _value;
  576. + private String _name;
  577. +
  578. + public Condition(Object value)
  579. + {
  580. + _value = value;
  581. + }
  582. +
  583. + public abstract boolean meetConditionRequirements(L2PcInstance paramL2PcInstance);
  584. +
  585. + public Object getValue() {
  586. + return _value;
  587. + }
  588. +
  589. + public void setName(String s)
  590. + {
  591. + _name = s;
  592. + }
  593. +
  594. + public String getName()
  595. + {
  596. + return _name;
  597. + }
  598. +}
  599. \ No newline at end of file
  600. diff --git java/net/sf/l2j/achievementEngine/EnchantAmor/Chest.java
  601. new file mode 100644
  602. index 0000000..2a11444
  603. --- /dev/null
  604. +++ java/net/sf/l2j/achievementEngine/EnchantAmor/Chest.java
  605. @@ -0,0 +1,37 @@
  606. +package net.sf.l2j.achievementEngine.EnchantAmor;
  607. +
  608. +import net.sf.l2j.achievementEngine.Condition;
  609. +import net.sf.l2j.gameserver.model.L2ItemInstance;
  610. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  611. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  612. +
  613. +public class Chest extends Condition
  614. +{
  615. + public Chest(Object value)
  616. + {
  617. + super(value);
  618. + setName("Chests");
  619. + }
  620. +
  621. + @Override
  622. + public boolean meetConditionRequirements(L2PcInstance player)
  623. + {
  624. + if (getValue() == null)
  625. + {
  626. + return false;
  627. + }
  628. +
  629. + int val = Integer.parseInt(getValue().toString());
  630. +
  631. + L2ItemInstance armor = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  632. +
  633. + if (armor != null)
  634. + {
  635. + if (armor.getEnchantLevel() >= val)
  636. + {
  637. + return true;
  638. + }
  639. + }
  640. + return false;
  641. + }
  642. +}
  643. \ No newline at end of file
  644. diff --git java/net/sf/l2j/achievementEngine/EnchantAmor/Feet.java
  645. new file mode 100644
  646. index 0000000..bbc1d25
  647. --- /dev/null
  648. +++ java/net/sf/l2j/achievementEngine/EnchantAmor/Feet.java
  649. @@ -0,0 +1,37 @@
  650. +package net.sf.l2j.achievementEngine.EnchantAmor;
  651. +
  652. +import net.sf.l2j.achievementEngine.Condition;
  653. +import net.sf.l2j.gameserver.model.L2ItemInstance;
  654. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  655. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  656. +
  657. +public class Feet extends Condition
  658. +{
  659. + public Feet(Object value)
  660. + {
  661. + super(value);
  662. + setName("Boots");
  663. + }
  664. +
  665. + @Override
  666. + public boolean meetConditionRequirements(L2PcInstance player)
  667. + {
  668. + if (getValue() == null)
  669. + {
  670. + return false;
  671. + }
  672. +
  673. + int val = Integer.parseInt(getValue().toString());
  674. +
  675. + L2ItemInstance armor = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_FEET);
  676. +
  677. + if (armor != null)
  678. + {
  679. + if (armor.getEnchantLevel() >= val)
  680. + {
  681. + return true;
  682. + }
  683. + }
  684. + return false;
  685. + }
  686. +}
  687. \ No newline at end of file
  688. diff --git java/net/sf/l2j/achievementEngine/EnchantAmor/Gloves.java
  689. new file mode 100644
  690. index 0000000..b797d64
  691. --- /dev/null
  692. +++ java/net/sf/l2j/achievementEngine/EnchantAmor/Gloves.java
  693. @@ -0,0 +1,37 @@
  694. +package net.sf.l2j.achievementEngine.EnchantAmor;
  695. +
  696. +import net.sf.l2j.achievementEngine.Condition;
  697. +import net.sf.l2j.gameserver.model.L2ItemInstance;
  698. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  699. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;;
  700. +
  701. +public class Gloves extends Condition
  702. +{
  703. + public Gloves(Object value)
  704. + {
  705. + super(value);
  706. + setName("Gloves");
  707. + }
  708. +
  709. + @Override
  710. + public boolean meetConditionRequirements(L2PcInstance player)
  711. + {
  712. + if (getValue() == null)
  713. + {
  714. + return false;
  715. + }
  716. +
  717. + int val = Integer.parseInt(getValue().toString());
  718. +
  719. + L2ItemInstance armor = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  720. +
  721. + if (armor != null)
  722. + {
  723. + if (armor.getEnchantLevel() >= val)
  724. + {
  725. + return true;
  726. + }
  727. + }
  728. + return false;
  729. + }
  730. +}
  731. \ No newline at end of file
  732. diff --git java/net/sf/l2j/achievementEngine/EnchantAmor/Head.java
  733. new file mode 100644
  734. index 0000000..0d0d43c
  735. --- /dev/null
  736. +++ java/net/sf/l2j/achievementEngine/EnchantAmor/Head.java
  737. @@ -0,0 +1,37 @@
  738. +package net.sf.l2j.achievementEngine.EnchantAmor;
  739. +
  740. +import net.sf.l2j.achievementEngine.Condition;
  741. +import net.sf.l2j.gameserver.model.L2ItemInstance;
  742. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  743. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  744. +
  745. +public class Head extends Condition
  746. +{
  747. + public Head(Object value)
  748. + {
  749. + super(value);
  750. + setName("Helmets");
  751. + }
  752. +
  753. + @Override
  754. + public boolean meetConditionRequirements(L2PcInstance player)
  755. + {
  756. + if (getValue() == null)
  757. + {
  758. + return false;
  759. + }
  760. +
  761. + int val = Integer.parseInt(getValue().toString());
  762. +
  763. + L2ItemInstance armor = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  764. +
  765. + if (armor != null)
  766. + {
  767. + if (armor.getEnchantLevel() >= val)
  768. + {
  769. + return true;
  770. + }
  771. + }
  772. + return false;
  773. + }
  774. +}
  775. \ No newline at end of file
  776. diff --git java/net/sf/l2j/achievementEngine/EnchantAmor/Legs.java
  777. new file mode 100644
  778. index 0000000..0647c27
  779. --- /dev/null
  780. +++ java/net/sf/l2j/achievementEngine/EnchantAmor/Legs.java
  781. @@ -0,0 +1,37 @@
  782. +package net.sf.l2j.achievementEngine.EnchantAmor;
  783. +
  784. +import net.sf.l2j.achievementEngine.Condition;
  785. +import net.sf.l2j.gameserver.model.L2ItemInstance;
  786. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  787. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  788. +
  789. +public class Legs extends Condition
  790. +{
  791. + public Legs(Object value)
  792. + {
  793. + super(value);
  794. + setName("Legs");
  795. + }
  796. +
  797. + @Override
  798. + public boolean meetConditionRequirements(L2PcInstance player)
  799. + {
  800. + if (getValue() == null)
  801. + {
  802. + return false;
  803. + }
  804. +
  805. + int val = Integer.parseInt(getValue().toString());
  806. +
  807. + L2ItemInstance armor = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  808. +
  809. + if (armor != null)
  810. + {
  811. + if (armor.getEnchantLevel() >= val)
  812. + {
  813. + return true;
  814. + }
  815. + }
  816. + return false;
  817. + }
  818. +}
  819. \ No newline at end of file
  820. diff --git java/net/sf/l2j/achievementEngine/Hero.java
  821. new file mode 100644
  822. index 0000000..cac874b
  823. --- /dev/null
  824. +++ java/net/sf/l2j/achievementEngine/Hero.java
  825. @@ -0,0 +1,22 @@
  826. +package net.sf.l2j.achievementEngine;
  827. +
  828. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  829. +
  830. +public class Hero extends Condition
  831. +{
  832. + public Hero(Object value)
  833. + {
  834. + super(value);
  835. + setName("Hero");
  836. + }
  837. +
  838. + @Override
  839. + public boolean meetConditionRequirements(L2PcInstance player)
  840. + {
  841. + if (getValue() == null) {
  842. + return false;
  843. + }
  844. +
  845. + return player.isHero();
  846. + }
  847. +}
  848. \ No newline at end of file
  849. diff --git java/net/sf/l2j/achievementEngine/ItemsCount.java
  850. new file mode 100644
  851. index 0000000..3a6bd5b
  852. --- /dev/null
  853. +++ java/net/sf/l2j/achievementEngine/ItemsCount.java
  854. @@ -0,0 +1,39 @@
  855. +package net.sf.l2j.achievementEngine;
  856. +
  857. +import java.util.StringTokenizer;
  858. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  859. +
  860. +public class ItemsCount extends Condition
  861. +{
  862. + public ItemsCount(Object value)
  863. + {
  864. + super(value);
  865. + setName("Items Count");
  866. + }
  867. +
  868. + @Override
  869. + public boolean meetConditionRequirements(L2PcInstance player)
  870. + {
  871. + if (getValue() == null) {
  872. + return false;
  873. + }
  874. +
  875. + String s = getValue().toString();
  876. + StringTokenizer st = new StringTokenizer(s, ",");
  877. + int id = 0;
  878. + int ammount = 0;
  879. + try
  880. + {
  881. + id = Integer.parseInt(st.nextToken());
  882. + ammount = Integer.parseInt(st.nextToken());
  883. + if (player.getInventory().getInventoryItemCount(id, 0) >= ammount)
  884. + return true;
  885. + }
  886. + catch (NumberFormatException nfe)
  887. + {
  888. + nfe.printStackTrace();
  889. + }
  890. +
  891. + return false;
  892. + }
  893. +}
  894. \ No newline at end of file
  895. diff --git java/net/sf/l2j/achievementEngine/Karma.java
  896. new file mode 100644
  897. index 0000000..0363e9f
  898. --- /dev/null
  899. +++ java/net/sf/l2j/achievementEngine/Karma.java
  900. @@ -0,0 +1,23 @@
  901. +package net.sf.l2j.achievementEngine;
  902. +
  903. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  904. +
  905. +public class Karma extends Condition
  906. +{
  907. + public Karma(Object value)
  908. + {
  909. + super(value);
  910. + setName("Karma Count");
  911. + }
  912. +
  913. + @Override
  914. + public boolean meetConditionRequirements(L2PcInstance player)
  915. + {
  916. + if (getValue() == null) {
  917. + return false;
  918. + }
  919. + int val = Integer.parseInt(getValue().toString());
  920. +
  921. + return player.getKarma() >= val;
  922. + }
  923. +}
  924. \ No newline at end of file
  925. diff --git java/net/sf/l2j/achievementEngine/Level.java
  926. new file mode 100644
  927. index 0000000..804e638
  928. --- /dev/null
  929. +++ java/net/sf/l2j/achievementEngine/Level.java
  930. @@ -0,0 +1,26 @@
  931. +
  932. +package net.sf.l2j.achievementEngine;
  933. +
  934. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  935. +
  936. +public class Level extends Condition
  937. +{
  938. + public Level(Object value)
  939. + {
  940. + super(value);
  941. + setName("Level");
  942. + }
  943. +
  944. + @Override
  945. + public boolean meetConditionRequirements(L2PcInstance player)
  946. + {
  947. + if (getValue() == null)
  948. + {
  949. + return false;
  950. + }
  951. +
  952. + int val = Integer.parseInt(getValue().toString());
  953. +
  954. + return player.getLevel() >= val;
  955. + }
  956. +}
  957. \ No newline at end of file
  958. diff --git java/net/sf/l2j/achievementEngine/Mageclass.java
  959. new file mode 100644
  960. index 0000000..92c79e0
  961. --- /dev/null
  962. +++ java/net/sf/l2j/achievementEngine/Mageclass.java
  963. @@ -0,0 +1,23 @@
  964. +package net.sf.l2j.achievementEngine;
  965. +
  966. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  967. +
  968. +public class Mageclass extends Condition
  969. +{
  970. + public Mageclass(Object value)
  971. + {
  972. + super(value);
  973. + setName("Mage Class");
  974. + }
  975. +
  976. + @Override
  977. + public boolean meetConditionRequirements(L2PcInstance player)
  978. + {
  979. + if (getValue() == null)
  980. + {
  981. + return false;
  982. + }
  983. +
  984. + return player.isMageClass();
  985. + }
  986. +}
  987. \ No newline at end of file
  988. diff --git java/net/sf/l2j/achievementEngine/Marry.java
  989. new file mode 100644
  990. index 0000000..b8fbdcd
  991. --- /dev/null
  992. +++ java/net/sf/l2j/achievementEngine/Marry.java
  993. @@ -0,0 +1,22 @@
  994. +package net.sf.l2j.achievementEngine;
  995. +
  996. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  997. +
  998. +public class Marry extends Condition
  999. +{
  1000. + public Marry(Object value)
  1001. + {
  1002. + super(value);
  1003. + setName("Married");
  1004. + }
  1005. +
  1006. + @Override
  1007. + public boolean meetConditionRequirements(L2PcInstance player)
  1008. + {
  1009. + if (getValue() == null) {
  1010. + return false;
  1011. + }
  1012. +
  1013. + return player.isMarried();
  1014. + }
  1015. +}
  1016. \ No newline at end of file
  1017. diff --git java/net/sf/l2j/achievementEngine/Maxcp.java
  1018. new file mode 100644
  1019. index 0000000..c883f61
  1020. --- /dev/null
  1021. +++ java/net/sf/l2j/achievementEngine/Maxcp.java
  1022. @@ -0,0 +1,23 @@
  1023. +package net.sf.l2j.achievementEngine;
  1024. +
  1025. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1026. +
  1027. +public class Maxcp extends Condition
  1028. +{
  1029. + public Maxcp(Object value)
  1030. + {
  1031. + super(value);
  1032. + setName("Max CP");
  1033. + }
  1034. +
  1035. + @Override
  1036. + public boolean meetConditionRequirements(L2PcInstance player)
  1037. + {
  1038. + if (getValue() == null) {
  1039. + return false;
  1040. + }
  1041. + int val = Integer.parseInt(getValue().toString());
  1042. +
  1043. + return player.getMaxCp() >= val;
  1044. + }
  1045. +}
  1046. \ No newline at end of file
  1047. diff --git java/net/sf/l2j/achievementEngine/Maxhp.java
  1048. new file mode 100644
  1049. index 0000000..5b264a2
  1050. --- /dev/null
  1051. +++ java/net/sf/l2j/achievementEngine/Maxhp.java
  1052. @@ -0,0 +1,23 @@
  1053. +package net.sf.l2j.achievementEngine;
  1054. +
  1055. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1056. +
  1057. +public class Maxhp extends Condition
  1058. +{
  1059. + public Maxhp(Object value)
  1060. + {
  1061. + super(value);
  1062. + setName("Max HP");
  1063. + }
  1064. +
  1065. + @Override
  1066. + public boolean meetConditionRequirements(L2PcInstance player)
  1067. + {
  1068. + if (getValue() == null) {
  1069. + return false;
  1070. + }
  1071. + int val = Integer.parseInt(getValue().toString());
  1072. +
  1073. + return player.getMaxHp() >= val;
  1074. + }
  1075. +}
  1076. \ No newline at end of file
  1077. diff --git java/net/sf/l2j/achievementEngine/Maxmp.java
  1078. new file mode 100644
  1079. index 0000000..dbb6c63
  1080. --- /dev/null
  1081. +++ java/net/sf/l2j/achievementEngine/Maxmp.java
  1082. @@ -0,0 +1,23 @@
  1083. +package net.sf.l2j.achievementEngine;
  1084. +
  1085. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1086. +
  1087. +public class Maxmp extends Condition
  1088. +{
  1089. + public Maxmp(Object value)
  1090. + {
  1091. + super(value);
  1092. + setName("Max MP");
  1093. + }
  1094. +
  1095. + @Override
  1096. + public boolean meetConditionRequirements(L2PcInstance player)
  1097. + {
  1098. + if (getValue() == null) {
  1099. + return false;
  1100. + }
  1101. + int val = Integer.parseInt(getValue().toString());
  1102. +
  1103. + return player.getMaxMp() >= val;
  1104. + }
  1105. +}
  1106. \ No newline at end of file
  1107. diff --git java/net/sf/l2j/achievementEngine/MinCMcount.java
  1108. new file mode 100644
  1109. index 0000000..72a6ac1
  1110. --- /dev/null
  1111. +++ java/net/sf/l2j/achievementEngine/MinCMcount.java
  1112. @@ -0,0 +1,28 @@
  1113. +package net.sf.l2j.achievementEngine;
  1114. +
  1115. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1116. +
  1117. +public class MinCMcount extends Condition
  1118. +{
  1119. + public MinCMcount(Object value)
  1120. + {
  1121. + super(value);
  1122. + setName("Clan Members Count");
  1123. + }
  1124. +
  1125. + @Override
  1126. + public boolean meetConditionRequirements(L2PcInstance player)
  1127. + {
  1128. + if (getValue() == null) {
  1129. + return false;
  1130. + }
  1131. + if (player.getClan() != null)
  1132. + {
  1133. + int val = Integer.parseInt(getValue().toString());
  1134. +
  1135. + if (player.getClan().getMembersCount() >= val)
  1136. + return true;
  1137. + }
  1138. + return false;
  1139. + }
  1140. +}
  1141. \ No newline at end of file
  1142. diff --git java/net/sf/l2j/achievementEngine/Noble.java
  1143. new file mode 100644
  1144. index 0000000..0be07a8
  1145. --- /dev/null
  1146. +++ java/net/sf/l2j/achievementEngine/Noble.java
  1147. @@ -0,0 +1,23 @@
  1148. +package net.sf.l2j.achievementEngine;
  1149. +
  1150. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1151. +
  1152. +public class Noble extends Condition
  1153. +{
  1154. + public Noble(Object value)
  1155. + {
  1156. + super(value);
  1157. + setName("Noble");
  1158. + }
  1159. +
  1160. + @Override
  1161. + public boolean meetConditionRequirements(L2PcInstance player)
  1162. + {
  1163. + if (getValue() == null)
  1164. + {
  1165. + return false;
  1166. + }
  1167. +
  1168. + return player.isNoble();
  1169. + }
  1170. +}
  1171. \ No newline at end of file
  1172. diff --git java/net/sf/l2j/achievementEngine/OnlineTime.java
  1173. new file mode 100644
  1174. index 0000000..203412c
  1175. --- /dev/null
  1176. +++ java/net/sf/l2j/achievementEngine/OnlineTime.java
  1177. @@ -0,0 +1,24 @@
  1178. +package net.sf.l2j.achievementEngine;
  1179. +
  1180. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1181. +
  1182. +public class OnlineTime extends Condition
  1183. +{
  1184. + public OnlineTime(Object value)
  1185. + {
  1186. + super(value);
  1187. + setName("Online Time");
  1188. + }
  1189. +
  1190. + @Override
  1191. + public boolean meetConditionRequirements(L2PcInstance player)
  1192. + {
  1193. + if (getValue() == null)
  1194. + {
  1195. + return false;
  1196. + }
  1197. + int val = Integer.parseInt(getValue().toString());
  1198. +
  1199. + return player.getOnlineTime() >= val;
  1200. + }
  1201. +}
  1202. \ No newline at end of file
  1203. diff --git java/net/sf/l2j/achievementEngine/Pk.java
  1204. new file mode 100644
  1205. index 0000000..e9535cb
  1206. --- /dev/null
  1207. +++ java/net/sf/l2j/achievementEngine/Pk.java
  1208. @@ -0,0 +1,24 @@
  1209. +package net.sf.l2j.achievementEngine;
  1210. +
  1211. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1212. +
  1213. +public class Pk extends Condition
  1214. +{
  1215. + public Pk(Object value)
  1216. + {
  1217. + super(value);
  1218. + setName("PK Count");
  1219. + }
  1220. +
  1221. + @Override
  1222. + public boolean meetConditionRequirements(L2PcInstance player)
  1223. + {
  1224. + if (getValue() == null)
  1225. + {
  1226. + return false;
  1227. + }
  1228. + int val = Integer.parseInt(getValue().toString());
  1229. +
  1230. + return player.getPkKills() >= val;
  1231. + }
  1232. +}
  1233. \ No newline at end of file
  1234. diff --git java/net/sf/l2j/achievementEngine/Pvp.java
  1235. new file mode 100644
  1236. index 0000000..a901d4a
  1237. --- /dev/null
  1238. +++ java/net/sf/l2j/achievementEngine/Pvp.java
  1239. @@ -0,0 +1,24 @@
  1240. +package net.sf.l2j.achievementEngine;
  1241. +
  1242. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1243. +
  1244. +public class Pvp extends Condition
  1245. +{
  1246. + public Pvp(Object value)
  1247. + {
  1248. + super(value);
  1249. + setName("PvP Count");
  1250. + }
  1251. +
  1252. + @Override
  1253. + public boolean meetConditionRequirements(L2PcInstance player)
  1254. + {
  1255. + if (getValue() == null)
  1256. + {
  1257. + return false;
  1258. + }
  1259. + int val = Integer.parseInt(getValue().toString());
  1260. +
  1261. + return player.getPvpKills() >= val;
  1262. + }
  1263. +}
  1264. \ No newline at end of file
  1265. diff --git java/net/sf/l2j/achievementEngine/SkillEnchant.java
  1266. new file mode 100644
  1267. index 0000000..2888f1b
  1268. --- /dev/null
  1269. +++ java/net/sf/l2j/achievementEngine/SkillEnchant.java
  1270. @@ -0,0 +1,35 @@
  1271. +package net.sf.l2j.achievementEngine;
  1272. +
  1273. +import net.sf.l2j.gameserver.model.L2Skill;
  1274. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1275. +
  1276. +public class SkillEnchant extends Condition
  1277. +{
  1278. + public SkillEnchant(Object value)
  1279. + {
  1280. + super(value);
  1281. + setName("Skill Enchant");
  1282. + }
  1283. +
  1284. + @Override
  1285. + public boolean meetConditionRequirements(L2PcInstance player)
  1286. + {
  1287. + if (getValue() == null) {
  1288. + return false;
  1289. + }
  1290. + int val = Integer.parseInt(getValue().toString());
  1291. +
  1292. + for (L2Skill s : player.getAllSkills())
  1293. + {
  1294. + String lvl = String.valueOf(s.getLevel());
  1295. + if (lvl.length() <= 2)
  1296. + continue;
  1297. + int sklvl = Integer.parseInt(lvl.substring(1));
  1298. + if (sklvl >= val) {
  1299. + return true;
  1300. + }
  1301. + }
  1302. +
  1303. + return false;
  1304. + }
  1305. +}
  1306. \ No newline at end of file
  1307. diff --git java/net/sf/l2j/achievementEngine/Sub.java
  1308. new file mode 100644
  1309. index 0000000..6a0103d
  1310. --- /dev/null
  1311. +++ java/net/sf/l2j/achievementEngine/Sub.java
  1312. @@ -0,0 +1,24 @@
  1313. +package net.sf.l2j.achievementEngine;
  1314. +
  1315. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1316. +
  1317. +public class Sub extends Condition
  1318. +{
  1319. + public Sub(Object value)
  1320. + {
  1321. + super(value);
  1322. + setName("Subclass Count");
  1323. + }
  1324. +
  1325. + @Override
  1326. + public boolean meetConditionRequirements(L2PcInstance player)
  1327. + {
  1328. + if (getValue() == null)
  1329. + {
  1330. + return false;
  1331. + }
  1332. + int val = Integer.parseInt(getValue().toString());
  1333. +
  1334. + return player.getSubClasses().size() >= val;
  1335. + }
  1336. +}
  1337. \ No newline at end of file
  1338. diff --git java/net/sf/l2j/achievementEngine/WeaponEnchant.java
  1339. new file mode 100644
  1340. index 0000000..7a9731f
  1341. --- /dev/null
  1342. +++ java/net/sf/l2j/achievementEngine/WeaponEnchant.java
  1343. @@ -0,0 +1,36 @@
  1344. +package net.sf.l2j.achievementEngine;
  1345. +
  1346. +import net.sf.l2j.gameserver.model.L2ItemInstance;
  1347. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1348. +import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  1349. +
  1350. +public class WeaponEnchant extends Condition
  1351. +{
  1352. + public WeaponEnchant(Object value)
  1353. + {
  1354. + super(value);
  1355. + setName("Weapon Enchant");
  1356. + }
  1357. +
  1358. + @Override
  1359. + public boolean meetConditionRequirements(L2PcInstance player)
  1360. + {
  1361. + if (getValue() == null)
  1362. + {
  1363. + return false;
  1364. + }
  1365. +
  1366. + int val = Integer.parseInt(getValue().toString());
  1367. +
  1368. + L2ItemInstance weapon = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1369. +
  1370. + if (weapon != null)
  1371. + {
  1372. + if (weapon.getEnchantLevel() >= val)
  1373. + {
  1374. + return true;
  1375. + }
  1376. + }
  1377. + return false;
  1378. + }
  1379. +}
  1380. \ No newline at end of file
  1381. diff --git java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  1382. index ee0c3ba..7f49bd7 100644
  1383. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  1384. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  1385. @@ -15,12 +15,13 @@
  1386. package net.sf.l2j.gameserver.model.actor.instance;
  1387.  
  1388. import java.sql.Connection;
  1389. import java.sql.PreparedStatement;
  1390. import java.sql.ResultSet;
  1391. import java.sql.SQLException;
  1392. +import java.sql.Statement;
  1393. import java.util.ArrayList;
  1394. import java.util.Arrays;
  1395. import java.util.Calendar;
  1396. import java.util.Collection;
  1397. import java.util.Comparator;
  1398. import java.util.LinkedHashMap;
  1399. @@ -36,13 +37,15 @@
  1400. import java.util.concurrent.atomic.AtomicInteger;
  1401. import java.util.concurrent.locks.ReentrantLock;
  1402. import java.util.logging.Level;
  1403.  
  1404. import net.sf.l2j.Config;
  1405. import net.sf.l2j.L2DatabaseFactory;
  1406. +import net.sf.l2j.achievementEngine.AchievementsManager;
  1407. import net.sf.l2j.gameserver.GameTimeController;
  1408. +import net.sf.l2j.gameserver.Item;
  1409. import net.sf.l2j.gameserver.ItemsAutoDestroy;
  1410. import net.sf.l2j.gameserver.LoginServerThread;
  1411. import net.sf.l2j.gameserver.RecipeController;
  1412. import net.sf.l2j.gameserver.SevenSignsFestival;
  1413. import net.sf.l2j.gameserver.ThreadPoolManager;
  1414. import net.sf.l2j.gameserver.ai.CtrlIntention;
  1415. @@ -672,12 +675,109 @@
  1416. private int _coupleId = 0;
  1417. private boolean _isEngageRequested = false;
  1418. private int _engageId = 0;
  1419. private boolean _isMarryRequested = false;
  1420. private boolean _isMarryAccepted = false;
  1421.  
  1422. + private List<Integer> _completedAchievements = new ArrayList<>();
  1423. +
  1424. + public boolean readyAchievementsList()
  1425. + {
  1426. + if (_completedAchievements.isEmpty())
  1427. + return false;
  1428. + return true;
  1429. + }
  1430. + public long getOnlineTime()
  1431. + {
  1432. + return _onlineTime;
  1433. + }
  1434. + public void saveAchievemntData()
  1435. + {
  1436. +
  1437. + }
  1438. +
  1439. + public void getAchievemntData()
  1440. + {
  1441. + Connection con = null;
  1442. + try
  1443. + {
  1444. + PreparedStatement statement;
  1445. + PreparedStatement insertStatement;
  1446. + ResultSet rs;
  1447. + con = L2DatabaseFactory.getInstance().getConnection();
  1448. +
  1449. + statement = con.prepareStatement("SELECT * from achievements WHERE owner_id=" + getObjectId());
  1450. +
  1451. + rs = statement.executeQuery();
  1452. +
  1453. + String values = "owner_id";
  1454. + String in = Integer.toString(getObjectId());
  1455. + String questionMarks = in;
  1456. + int ilosc = AchievementsManager.getInstance().getAchievementList().size();
  1457. +
  1458. + if (rs.next())
  1459. + {
  1460. + _completedAchievements.clear();
  1461. + for (int i=1; i <=ilosc; i++)
  1462. + {
  1463. + int a = rs.getInt("a" + i);
  1464. +
  1465. + if (!_completedAchievements.contains(i))
  1466. + if (a == 1)
  1467. + _completedAchievements.add(i);
  1468. + }
  1469. + }
  1470. + else
  1471. + {
  1472. + //Player hasnt entry in database, means we have to create it.
  1473. +
  1474. + for (int i=1; i <=ilosc; i++)
  1475. + {
  1476. + values += ", a" + i;
  1477. + questionMarks += ", 0";
  1478. + }
  1479. +
  1480. + String s = "INSERT INTO achievements(" + values + ") VALUES (" + questionMarks + ")";
  1481. + insertStatement = con.prepareStatement(s);
  1482. +
  1483. + insertStatement.execute();
  1484. + insertStatement.close();
  1485. + }
  1486. + }
  1487. + catch (Exception e)
  1488. + {
  1489. + _log.warning("[ACHIEVEMENTS ENGINE GETDATA]" + e);
  1490. + }
  1491. + }
  1492. +
  1493. + public void saveAchievementData(int achievementID)
  1494. + {
  1495. + Connection con = null;
  1496. + try
  1497. + {
  1498. + con = L2DatabaseFactory.getInstance().getConnection();
  1499. + Statement statement = con.createStatement();
  1500. + statement.executeUpdate("UPDATE achievements SET a" + achievementID + "=1 WHERE owner_id=" + getObjectId());
  1501. + statement.close();
  1502. +
  1503. + if (!_completedAchievements.contains(achievementID))
  1504. + _completedAchievements.add(achievementID);
  1505. + }
  1506. + catch (SQLException e)
  1507. + {
  1508. + _log.warning("[ACHIEVEMENTS SAVE GETDATA]" + e);
  1509. + }
  1510. +
  1511. + }
  1512. +
  1513. + public List<Integer> getCompletedAchievements()
  1514. + {
  1515. + return _completedAchievements;
  1516. + }
  1517. // NPC Buffer schemes
  1518. private String _editingSchemeName;
  1519. private final Map<String, List<String>> _schemes = new ConcurrentSkipListMap<>();
  1520.  
  1521. /** Skill casting information (used to queue when several skills are cast in a short time) **/
  1522. public class SkillDat
  1523. @@ -3215,14 +3315,16 @@
  1524. * @param process : String Identifier of process triggering this action
  1525. * @param itemId : int Item Identifier of the item to be added
  1526. * @param count : int Quantity of items to be added
  1527. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  1528. * @param sendMessage : boolean Specifies whether to send message to Client about this action
  1529. */
  1530. - public void addItem(String process, int itemId, int count, L2Object reference, boolean sendMessage)
  1531. + public void addItem(String process, int itemId, long countL, L2Object reference, boolean sendMessage)
  1532. {
  1533. + int count = 0;
  1534. + count = (int)countL;
  1535. if (count > 0)
  1536. {
  1537. // Sends message to client if requested
  1538. if (sendMessage)
  1539. {
  1540. if (count > 1)
  1541. diff --git java/net/sf/l2j/gameserver/model/actor/instance/L2achievementsInstance.java
  1542. new file mode 100644
  1543. index 0000000..980a111
  1544. --- /dev/null
  1545. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2achievementsInstance.java
  1546. @@ -0,0 +1,261 @@
  1547. +package net.sf.l2j.gameserver.model.actor.instance;
  1548. +
  1549. +import java.util.StringTokenizer;
  1550. +
  1551. +import net.sf.l2j.achievementEngine.Achievement;
  1552. +import net.sf.l2j.achievementEngine.AchievementsManager;
  1553. +import net.sf.l2j.achievementEngine.Condition;
  1554. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  1555. +import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  1556. +
  1557. +public class L2achievementsInstance extends L2NpcInstance
  1558. +{
  1559. +public L2achievementsInstance(int objectId, L2NpcTemplate template)
  1560. + {
  1561. + super(objectId, template);
  1562. +}
  1563. +
  1564. +@Override
  1565. + public void onBypassFeedback(L2PcInstance player, String command)
  1566. + {
  1567. + if (command.startsWith("showMyAchievements"))
  1568. + {
  1569. + player.getAchievemntData();
  1570. + showMyAchievements(player);
  1571. + }
  1572. + else if (command.startsWith("achievementInfo"))
  1573. + {
  1574. + StringTokenizer st = new StringTokenizer(command, " ");
  1575. + st.nextToken();
  1576. + int id = Integer.parseInt(st.nextToken());
  1577. +
  1578. + showAchievementInfo(id, player);
  1579. + }
  1580. + else if (command.startsWith("topList"))
  1581. + {
  1582. + showTopListWindow(player);
  1583. + }
  1584. + else if (command.startsWith("showMainWindow"))
  1585. + {
  1586. + showChatWindow(player, 0);
  1587. + }
  1588. + else if (command.startsWith("getReward"))
  1589. + {
  1590. + StringTokenizer st = new StringTokenizer(command, " ");
  1591. + st.nextToken();
  1592. + int id = Integer.parseInt(st.nextToken());
  1593. + AchievementsManager.getInstance().rewardForAchievement(id, player);
  1594. + player.saveAchievementData(id);
  1595. + showMyAchievements(player);
  1596. +
  1597. + }
  1598. + else if (command.startsWith ("showMyStats"))
  1599. + {
  1600. + showMyStatsWindow(player);
  1601. + }
  1602. + else if (command.startsWith("showHelpWindow"))
  1603. + {
  1604. + showHelpWindow(player);
  1605. + }
  1606. + }
  1607. +
  1608. + @Override
  1609. + public void showChatWindow(L2PcInstance player, int val)
  1610. + {
  1611. + StringBuilder tb = new StringBuilder();
  1612. + tb.append("<html><title>Achievements Manager</title>");
  1613. + tb.append("<body><center><br><br><img src=\"L2UI_CH3.herotower_deco\" width=\"256\" height=\"32\"><br>");
  1614. + tb.append("<br><br><button value=\"My Achievements\" action=\"bypass -h npc_%objectId%_showMyAchievements\" width=\"75\" height=\"21\" back=\"L2UI_CH3.Btn1_normal\" fore=\"L2UI_CH3.Btn1_normal\">");
  1615. + tb.append("<br><br><button value=\"Statistics\" action=\"bypass -h npc_%objectId%_showMyStats\" width=\"75\" height=\"21\" back=\"L2UI_CH3.Btn1_normal\" fore=\"L2UI_CH3.Btn1_normal\">");
  1616. + tb.append("<br><br><button value=\"Help\" action=\"bypass -h npc_%objectId%_showHelpWindow\" width=\"75\" height=\"21\" back=\"L2UI_CH3.Btn1_normal\" fore=\"L2UI_CH3.Btn1_normal\">");
  1617. + tb.append("</center></body>");
  1618. + tb.append("</html>");
  1619. +
  1620. + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1621. + msg.setHtml(tb.toString());
  1622. + msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1623. +
  1624. + player.sendPacket(msg);
  1625. + }
  1626. +
  1627. + private void showMyAchievements(L2PcInstance player)
  1628. + {
  1629. + StringBuilder tb = new StringBuilder();
  1630. + tb.append("<html><title>Achievements Manager</title><body><br>");
  1631. +
  1632. + tb.append("<center><font color=\"LEVEL\">My achievements</font>:</center><br>");
  1633. +
  1634. + if (AchievementsManager.getInstance().getAchievementList().isEmpty())
  1635. + {
  1636. + tb.append("There are no Achievements created yet!");
  1637. + }
  1638. + else
  1639. + {
  1640. + int i = 0;
  1641. +
  1642. + tb.append("<table width=270 border=0 >");
  1643. + tb.append("<tr><td width=270 align=\"left\">Name:</td><td width=60 align=\"right\">Info:</td><td width=200 align=\"center\">Status:</td></tr></table>");
  1644. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1645. +
  1646. + for (Achievement a: AchievementsManager.getInstance().getAchievementList().values())
  1647. + {
  1648. + tb.append(getTableColor(i));
  1649. + tb.append("<tr><td width=270 align=\"left\">" + a.getName() + "</td><td width=50 align=\"right\"><a action=\"bypass -h npc_%objectId%_achievementInfo "
  1650. + + a.getID() + "\">info</a></td><td width=200 align=\"center\">" + getStatusString(a.getID(), player) + "</td></tr></table>");
  1651. + i++;
  1652. + }
  1653. +
  1654. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1655. + tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=134 height=21 back=\"L2UI_ch3.BigButton3_over\" fore=\"L2UI_ch3.BigButton3\"><center>");
  1656. + }
  1657. +
  1658. + tb.append("</center></body></html>");
  1659. + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1660. + msg.setHtml(tb.toString());
  1661. + msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1662. +
  1663. + player.sendPacket(msg);
  1664. + }
  1665. +
  1666. + private void showAchievementInfo(int achievementID, L2PcInstance player)
  1667. + {
  1668. + Achievement a = AchievementsManager.getInstance().getAchievementList().get(achievementID);
  1669. +
  1670. + StringBuilder tb = new StringBuilder();
  1671. + tb.append("<html><title>Achievements Manager</title><body><br>");
  1672. +
  1673. + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">");
  1674. + tb.append("<tr><td width=270 align=\"center\">" + a.getName() + "</td></tr></table><br>");
  1675. + tb.append("<center>Status: " + getStatusString(achievementID, player));
  1676. +
  1677. + if (a.meetAchievementRequirements(player) && !player.getCompletedAchievements().contains(achievementID))
  1678. + {
  1679. + tb.append("<button value=\"Receive Reward!\" action=\"bypass -h npc_%objectId%_getReward " + a.getID() + "\" width=134 height=21 back=\"L2UI_ch3.BigButton3_over\" fore=\"L2UI_ch3.BigButton3\">");
  1680. + }
  1681. +
  1682. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1683. +
  1684. + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">");
  1685. + tb.append("<tr><td width=270 align=\"center\">Description</td></tr></table><br>");
  1686. + tb.append(a.getDescription());
  1687. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1688. +
  1689. + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">");
  1690. + tb.append("<tr><td width=270 align=\"left\">Condition:</td><td width=100 align=\"right\">Value:</td><td width=200 align=\"center\">Status:</td></tr></table>");
  1691. + tb.append(getConditionsStatus(achievementID, player));
  1692. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1693. + tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMyAchievements\" width=134 height=21 back=\"L2UI_ch3.BigButton3_over\" fore=\"L2UI_ch3.BigButton3\"><center>");
  1694. +
  1695. + tb.append("</center></body></html>");
  1696. + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1697. + msg.setHtml(tb.toString());
  1698. + msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1699. +
  1700. + player.sendPacket(msg);
  1701. + }
  1702. +
  1703. + private void showMyStatsWindow(L2PcInstance player)
  1704. + {
  1705. + StringBuilder tb = new StringBuilder();
  1706. + tb.append("<html><title>Achievements Manager</title><body><center><br>");
  1707. + tb.append("Check your <font color=\"LEVEL\">Achievements </font>statistics:");
  1708. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1709. +
  1710. + player.getAchievemntData();
  1711. + int completedCount = player.getCompletedAchievements().size();
  1712. +
  1713. + tb.append("You have completed: " + completedCount + "/<font color=\"LEVEL\">" + AchievementsManager.getInstance().getAchievementList().size() + "</font>");
  1714. +
  1715. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1716. + tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=134 height=21 back=\"L2UI_ch3.BigButton3_over\" fore=\"L2UI_ch3.BigButton3\"><center>");
  1717. +
  1718. + tb.append("</center></body></html>");
  1719. + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1720. + msg.setHtml(tb.toString());
  1721. + msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1722. +
  1723. + player.sendPacket(msg);
  1724. + }
  1725. +
  1726. + private void showTopListWindow(L2PcInstance player )
  1727. + {
  1728. + StringBuilder tb = new StringBuilder();
  1729. + tb.append("<html><title>Achievements Manager</title><body><center><br>");
  1730. + tb.append("Check your <font color=\"LEVEL\">Achievements </font>Top List:");
  1731. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1732. +
  1733. + tb.append("List Player " + player.getCompletedAchievements() + " ");
  1734. +
  1735. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1736. + tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=134 height=21 back=\"L2UI_ch3.BigButton3_over\" fore=\"L2UI_ch3.BigButton3\"><center>");
  1737. +
  1738. + tb.append("</center></body></html>");
  1739. + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1740. + msg.setHtml(tb.toString());
  1741. + msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1742. +
  1743. + player.sendPacket(msg);
  1744. + }
  1745. +
  1746. + private void showHelpWindow(L2PcInstance player)
  1747. + {
  1748. + StringBuilder tb = new StringBuilder();
  1749. + tb.append("<html><title>Achievements Manager</title><body><center><br>");
  1750. + tb.append("Achievements <font color=\"LEVEL\">Help </font>page:");
  1751. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1752. +
  1753. + tb.append("<center>You can check status of your achievements, receive reward if every condition of achievement is meet, if not you can check which condition is still not meet, by using info button");
  1754. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1755. + tb.append("<font color=\"FF0000\">Not Completed</font> - you did not meet the achivement requirements.<br>");
  1756. + tb.append("<font color=\"LEVEL\">Get Reward</font> - you may receive reward, click info.<br>");
  1757. + tb.append("<font color=\"5EA82E\">Completed</font> - achievement completed, reward received.<br></center>");
  1758. +
  1759. + tb.append("Achievements Engine by <font color=\"LEVEL\">L2JSanne</font>");
  1760. + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1761. + tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=134 height=21 back=\"L2UI_ch3.BigButton3_over\" fore=\"L2UI_ch3.BigButton3\"><center>");
  1762. +
  1763. + tb.append("</center></body></html>");
  1764. + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1765. + msg.setHtml(tb.toString());
  1766. + msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1767. +
  1768. + player.sendPacket(msg);
  1769. + }
  1770. +
  1771. + private String getStatusString(int achievementID, L2PcInstance player)
  1772. + {
  1773. + if (player.getCompletedAchievements().contains(achievementID))
  1774. + {
  1775. + return "<font color=\"5EA82E\">Completed</font>";
  1776. + }
  1777. + if (AchievementsManager.getInstance().getAchievementList().get(achievementID).meetAchievementRequirements(player))
  1778. + {
  1779. + return "<font color=\"LEVEL\">Get Reward</font>";
  1780. + }
  1781. + return "<font color=\"FF0000\">Not Completed</font>";
  1782. + }
  1783. +
  1784. + private String getTableColor(int i)
  1785. + {
  1786. + if (i % 2 == 0)
  1787. + return "<table width=270 border=0 bgcolor=\"444444\">";
  1788. + return "<table width=270 border=0>";
  1789. + }
  1790. +
  1791. + private String getConditionsStatus(int achievementID, L2PcInstance player)
  1792. + {
  1793. + int i = 0;
  1794. + String s = "</center>";
  1795. + Achievement a = AchievementsManager.getInstance().getAchievementList().get(achievementID);
  1796. + String completed = "<font color=\"5EA82E\">Completed</font></td></tr></table>";
  1797. + String notcompleted = "<font color=\"FF0000\">Not Completed</font></td></tr></table>";
  1798. +
  1799. + for (Condition c: a.getConditions())
  1800. + {
  1801. + s+= getTableColor(i);
  1802. + s+= "<tr><td width=270 align=\"left\">" + c.getName() + "</td><td width=50 align=\"right\">" + c.getValue() + "</td><td width=200 align=\"center\">";
  1803. + i++;
  1804. +
  1805. + if (c.meetConditionRequirements(player))
  1806. + s+= completed;
  1807. + else
  1808. + s+= notcompleted;
  1809. + }
  1810. + return s;
  1811. + }
  1812. +}
  1813. \ No newline at end of file
  1814.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement