Advertisement
ArkeyWave

[IL][L2J] Achievement Engine for L2jfrozen

Jan 10th, 2013
1,921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 68.54 KB | None | 0 0
  1. Go to gameserver/model/actor/instance/L2PcInstance.java:
  2. ### Eclipse Workspace Patch 1.0
  3. #P L2jFrozen_GameServer
  4. Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java
  5. ===================================================================
  6. --- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java    (revision 974)
  7. +++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java    (working copy)
  8. @@ -24,6 +24,7 @@
  9.  import java.sql.PreparedStatement;
  10.  import java.sql.ResultSet;
  11.  import java.sql.SQLException;
  12. +import java.sql.Statement;
  13.  import java.text.SimpleDateFormat;
  14.  import java.util.ArrayList;
  15.  import java.util.Arrays;
  16. @@ -47,6 +48,7 @@
  17.  import org.apache.commons.lang.RandomStringUtils;
  18.  
  19.  import com.l2jfrozen.Config;
  20. +import com.l2jfrozen.AchievementEngine.AchievementsManager;
  21.  import com.l2jfrozen.crypt.nProtect;
  22.  import com.l2jfrozen.gameserver.ai.CtrlIntention;
  23.  import com.l2jfrozen.gameserver.ai.L2CharacterAI;
  24. @@ -1042,6 +1044,106 @@
  25.         /** The _summon request. */
  26.         private SummonRequest _summonRequest = new SummonRequest();
  27.        
  28. +       private List<Integer> _completedAchievements = new FastList<Integer>();
  29. +    
  30. +    public boolean readyAchievementsList()
  31. +     {
  32. +             if (_completedAchievements.isEmpty())
  33. +                     return false;
  34. +                       return true;
  35. +     }
  36. +    
  37. +    public void saveAchievemntData()
  38. +     {
  39. +            
  40. +     }
  41. +    
  42. +    public void getAchievemntData()
  43. +     {
  44. +             Connection con = null;
  45. +             try
  46. +             {                      
  47. +                     PreparedStatement statement;
  48. +                     PreparedStatement insertStatement;
  49. +                     ResultSet rs;
  50. +                     con = L2DatabaseFactory.getInstance().getConnection();
  51. +                    
  52. +                     statement = con.prepareStatement("SELECT * from achievements WHERE owner_id=" + getObjectId());
  53. +                    
  54. +                     rs = statement.executeQuery();  
  55. +                    
  56. +                     String values = "owner_id";
  57. +                     String in = Integer.toString(getObjectId());
  58. +                     String questionMarks = in;
  59. +                     int ilosc = AchievementsManager.getInstance().getAchievementList().size();
  60. +                    
  61. +                    if (rs.next())
  62. +                    {  
  63. +                            _completedAchievements.clear();
  64. +                             for (int i=1; i <=ilosc; i++)
  65. +                            {
  66. +                                     int a = rs.getInt("a" + i);
  67. +                                  
  68. +                                     if (!_completedAchievements.contains(i))
  69. +                                             if (a == 1)
  70. +                                                     _completedAchievements.add(i);
  71. +                             }
  72. +                     }
  73. +                     else
  74. +                     {
  75. +                             //Player hasnt entry in database, means we have to create it.
  76. +                          
  77. +                             for (int i=1; i <=ilosc; i++)
  78. +                             {
  79. +                                     values += ", a" + i;
  80. +                                     questionMarks += ", 0";
  81. +                             }
  82. +                            
  83. +                             String s = "INSERT INTO achievements(" + values + ") VALUES (" + questionMarks + ")";
  84. +                             insertStatement = con.prepareStatement(s);
  85. +                            
  86. +                            insertStatement.execute();
  87. +                           insertStatement.close();
  88. +                     }
  89. +             }
  90. +             catch (SQLException e)
  91. +            {
  92. +                     _log.warning("[ACHIEVEMENTS ENGINE GETDATA]" + e);
  93. +             }
  94. +             finally
  95. +             {
  96. +                     L2DatabaseFactory.close(con);
  97. +             }
  98. +     }
  99. +    
  100. +     public void saveAchievementData(int achievementID)
  101. +     {
  102. +             Connection con = null;
  103. +             try
  104. +             {                      
  105. +                     con = L2DatabaseFactory.getInstance().getConnection();
  106. +                     Statement statement = con.createStatement();
  107. +                    statement.executeUpdate("UPDATE achievements SET a" + achievementID + "=1 WHERE owner_id=" + getObjectId());
  108. +                     statement.close();
  109. +                    
  110. +                     if (!_completedAchievements.contains(achievementID))
  111. +                             _completedAchievements.add(achievementID);
  112. +             }
  113. +             catch (SQLException e)
  114. +            {
  115. +                    _log.warning("[ACHIEVEMENTS SAVE GETDATA]" + e);
  116. +            }
  117. +            finally
  118. +             {
  119. +                     L2DatabaseFactory.close(con);
  120. +             }
  121. +     }
  122. +    
  123. +     public List<Integer> getCompletedAchievements()
  124. +     {
  125. +             return _completedAchievements;
  126. +     }
  127. +      
  128.         /**
  129.          * The Class SummonRequest.
  130.          */
  131. @@ -5114,6 +5216,135 @@
  132.                         }
  133.                 }
  134.         }
  135. +      
  136. +       /*
  137. +        * Conversion to long (Only For Achievement Manager)
  138. +        * Author: Tortex
  139. +        *
  140. +        */
  141. +       public void addItem(String process, int itemId, long countL, L2Object reference, boolean sendMessage)
  142. +       {      
  143. +               int count = 0;
  144. +               count = (int)countL;
  145. +               if(count!=countL)
  146. +               {
  147. +                       count = 1;
  148. +               }
  149. +              
  150. +               if(count > 0)
  151. +               {
  152. +                       // Sends message to client if requested
  153. +                       if(sendMessage && (!isCastingNow()
  154. +                                       && ItemTable.getInstance().createDummyItem(itemId).getItemType() == L2EtcItemType.HERB
  155. +                                       || ItemTable.getInstance().createDummyItem(itemId).getItemType() != L2EtcItemType.HERB))
  156. +                       {
  157. +                               if(count > 1)
  158. +                               {
  159. +                                       if(process.equalsIgnoreCase("sweep") || process.equalsIgnoreCase("Quest"))
  160. +                                       {
  161. +                                               SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  162. +                                               sm.addItemName(itemId);
  163. +                                               sm.addNumber(count);
  164. +                                               sendPacket(sm);
  165. +                                               sm = null;
  166. +                                       }
  167. +                                       else
  168. +                                       {
  169. +                                               SystemMessage sm = new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1_S2);
  170. +                                               sm.addItemName(itemId);
  171. +                                               sm.addNumber(count);
  172. +                                               sendPacket(sm);
  173. +                                               sm = null;
  174. +                                       }
  175. +                               }
  176. +                               else
  177. +                               {
  178. +                                       if(process.equalsIgnoreCase("sweep") || process.equalsIgnoreCase("Quest"))
  179. +                                       {
  180. +                                               SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_ITEM);
  181. +                                               sm.addItemName(itemId);
  182. +                                               sendPacket(sm);
  183. +                                               sm = null;
  184. +                                       }
  185. +                                       else
  186. +                                       {
  187. +                                               SystemMessage sm = new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1);
  188. +                                               sm.addItemName(itemId);
  189. +                                               sendPacket(sm);
  190. +                                               sm = null;
  191. +                                       }
  192. +                               }
  193. +                       }
  194. +                       //Auto use herbs - autoloot
  195. +                       if(ItemTable.getInstance().createDummyItem(itemId).getItemType() == L2EtcItemType.HERB) //If item is herb dont add it to iv :]
  196. +                       {
  197. +                               if(!isCastingNow() && !isCastingPotionNow())
  198. +                               {
  199. +                                       L2ItemInstance herb = new L2ItemInstance(_charId, itemId);
  200. +                                       IItemHandler handler = ItemHandler.getInstance().getItemHandler(herb.getItemId());
  201. +
  202. +                                       if(handler == null)
  203. +                                       {
  204. +                                               _log.warning("No item handler registered for Herb - item ID " + herb.getItemId() + ".");
  205. +                                       }
  206. +                                       else
  207. +                                       {
  208. +                                               handler.useItem(this, herb);
  209. +
  210. +                                               if(_herbstask >= 100)
  211. +                                               {
  212. +                                                       _herbstask -= 100;
  213. +                                               }
  214. +
  215. +                                               handler = null;
  216. +                                       }
  217. +
  218. +                                       herb = null;
  219. +                               }
  220. +                               else
  221. +                               {
  222. +                                       _herbstask += 100;
  223. +                                       ThreadPoolManager.getInstance().scheduleAi(new HerbTask(process, itemId, count, reference, sendMessage), _herbstask);
  224. +                               }
  225. +                       }
  226. +                       else
  227. +                       {
  228. +                               // Add the item to inventory
  229. +                               L2ItemInstance item = _inventory.addItem(process, itemId, count, this, reference);
  230. +
  231. +                               // Send inventory update packet
  232. +                               if(!Config.FORCE_INVENTORY_UPDATE)
  233. +                               {
  234. +                                       InventoryUpdate playerIU = new InventoryUpdate();
  235. +                                       playerIU.addItem(item);
  236. +                                       sendPacket(playerIU);
  237. +                                       playerIU = null;
  238. +                               }
  239. +                               else
  240. +                               {
  241. +                                       sendPacket(new ItemList(this, false));
  242. +                               }
  243. +
  244. +                               // Update current load as well
  245. +                               StatusUpdate su = new StatusUpdate(getObjectId());
  246. +                               su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
  247. +                               sendPacket(su);
  248. +                               su = null;
  249. +
  250. +                               // If over capacity, drop the item
  251. +                               if(!isGM() && !_inventory.validateCapacity(item))
  252. +                               {
  253. +                                       dropItem("InvDrop", item, null, true, true);
  254. +                               }
  255. +                               else if(CursedWeaponsManager.getInstance().isCursed(item.getItemId()))
  256. +                               {
  257. +                                       CursedWeaponsManager.getInstance().activate(this, item);
  258. +                               }
  259. +
  260. +                               item = null;
  261. +                       }
  262. +               }
  263. +       }
  264.  
  265.         /**
  266.          * Destroy item from inventory and send a Server->Client InventoryUpdate packet to the L2PcInstance.
  267. Create a new package com/l2jfrozen/AchievementEngine and add all these classes:
  268. ### Eclipse Workspace Patch 1.0
  269. #P L2jFrozen_GameServer
  270. Index: head-src/com/l2jfrozen/AchievementEngine/ClanCondition.java
  271. ===================================================================
  272. --- head-src/com/l2jfrozen/AchievementEngine/ClanCondition.java (revision 0)
  273. +++ head-src/com/l2jfrozen/AchievementEngine/ClanCondition.java (revision 0)
  274. @@ -0,0 +1,46 @@
  275. +/*
  276. + * This program is free software: you can redistribute it and/or modify it under
  277. + * the terms of the GNU General Public License as published by the Free Software
  278. + * Foundation, either version 3 of the License, or (at your option) any later
  279. + * version.
  280. + *
  281. + * This program is distributed in the hope that it will be useful, but WITHOUT
  282. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  283. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  284. + * details.
  285. + *
  286. + * You should have received a copy of the GNU General Public License along with
  287. + * this program. If not, see <http://www.gnu.org/licenses/>.
  288. + */
  289. +package com.l2jfrozen.AchievementEngine;
  290. +
  291. +import com.l2jfrozen.AchievementEngine.Condition;
  292. +
  293. +/**
  294. + * @author Matim
  295. + * @version 1.0
  296. + */
  297. +public abstract class ClanCondition extends Condition
  298. +{
  299. +        private ClanConditionType _type;
  300. +        
  301. +        public ClanCondition(Object value, ClanConditionType type)
  302. +        {
  303. +                super(value);
  304. +                _type = type;
  305. +        }
  306. +        
  307. +        public ClanConditionType getType()
  308. +        {
  309. +                return _type;
  310. +        }
  311. +      
  312. +        public enum ClanConditionType
  313. +        {
  314. +                MUST_BE_CLAN_LEADER,
  315. +                MIN_CLAN_LEVEL,
  316. +                MIN_CLAN_MEMBERS_COUNT,
  317. +                CRP_AMMOUNT,
  318. +                IS_CASTLE_LORD,
  319. +        }
  320. +}
  321. \ No newline at end of file
  322. Index: head-src/com/l2jfrozen/AchievementEngine/WeaponEnchant.java
  323. ===================================================================
  324. --- head-src/com/l2jfrozen/AchievementEngine/WeaponEnchant.java (revision 0)
  325. +++ head-src/com/l2jfrozen/AchievementEngine/WeaponEnchant.java (revision 0)
  326. @@ -0,0 +1,40 @@
  327. +package com.l2jfrozen.AchievementEngine;
  328. +
  329. +import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
  330. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  331. +import com.l2jfrozen.AchievementEngine.Condition;
  332. +import com.l2jfrozen.gameserver.model.Inventory;
  333. +
  334. +/**
  335. + * @author Matim
  336. + * @version 1.0
  337. + */
  338. +public class WeaponEnchant extends Condition
  339. +{
  340. +        public WeaponEnchant(Object value)
  341. +        {
  342. +                super(value);
  343. +        }
  344. +
  345. +        @Override
  346. +        public boolean meetConditionRequirements(L2PcInstance player)
  347. +        {
  348. +                if (getValue() == null)
  349. +                {
  350. +                        return false;
  351. +                }
  352. +                
  353. +                int val = Integer.parseInt(getValue().toString());
  354. +                
  355. +                L2ItemInstance weapon = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  356. +                
  357. +                if (weapon != null)
  358. +                {
  359. +                        if (weapon.getEnchantLevel() >= val)
  360. +                        {
  361. +                                return true;
  362. +                        }
  363. +                }
  364. +                return false;
  365. +        }
  366. +}
  367. \ No newline at end of file
  368. Index: head-src/com/l2jfrozen/AchievementEngine/Condition.java
  369. ===================================================================
  370. --- head-src/com/l2jfrozen/AchievementEngine/Condition.java     (revision 0)
  371. +++ head-src/com/l2jfrozen/AchievementEngine/Condition.java     (revision 0)
  372. @@ -0,0 +1,38 @@
  373. +/*
  374. + * This program is free software: you can redistribute it and/or modify it under
  375. + * the terms of the GNU General Public License as published by the Free Software
  376. + * Foundation, either version 3 of the License, or (at your option) any later
  377. + * version.
  378. + *
  379. + * This program is distributed in the hope that it will be useful, but WITHOUT
  380. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  381. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  382. + * details.
  383. + *
  384. + * You should have received a copy of the GNU General Public License along with
  385. + * this program. If not, see <http://www.gnu.org/licenses/>.
  386. + */
  387. +package com.l2jfrozen.AchievementEngine;
  388. +
  389. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  390. +
  391. +/**
  392. + * @author Matim
  393. + * @version 1.0
  394. + */
  395. +public abstract class Condition
  396. +{
  397. +        private Object _value;
  398. +        
  399. +        public Condition(Object value)
  400. +        {
  401. +                _value = value;
  402. +        }
  403. +        
  404. +        public abstract boolean meetConditionRequirements(L2PcInstance player);
  405. +        
  406. +        public Object getValue()
  407. +        {
  408. +                return _value;
  409. +        }
  410. +}
  411. \ No newline at end of file
  412. Index: head-src/com/l2jfrozen/AchievementEngine/ItemsCount.java
  413. ===================================================================
  414. --- head-src/com/l2jfrozen/AchievementEngine/ItemsCount.java    (revision 0)
  415. +++ head-src/com/l2jfrozen/AchievementEngine/ItemsCount.java    (revision 0)
  416. @@ -0,0 +1,64 @@
  417. +/*
  418. + * This program is free software: you can redistribute it and/or modify it under
  419. + * the terms of the GNU General Public License as published by the Free Software
  420. + * Foundation, either version 3 of the License, or (at your option) any later
  421. + * version.
  422. + *
  423. + * This program is distributed in the hope that it will be useful, but WITHOUT
  424. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  425. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  426. + * details.
  427. + *
  428. + * You should have received a copy of the GNU General Public License along with
  429. + * this program. If not, see <http://www.gnu.org/licenses/>.
  430. + */
  431. +package com.l2jfrozen.AchievementEngine;
  432. +
  433. +import java.util.StringTokenizer;
  434. +
  435. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  436. +import com.l2jfrozen.AchievementEngine.Condition;
  437. +
  438. +/**
  439. + * @author Matim
  440. + * @version 1.0
  441. + * <br><br>
  442. + * Condition: ItemsCount
  443. + * Check if player has proper ammount of item in inventory.
  444. + */
  445. +public class ItemsCount extends Condition
  446. +{
  447. +        public ItemsCount(Object value)
  448. +        {
  449. +                super(value);
  450. +        }
  451. +
  452. +        @Override
  453. +        public boolean meetConditionRequirements(L2PcInstance player)
  454. +        {
  455. +                if (getValue() == null)
  456. +                {
  457. +                        return false;
  458. +                }
  459. +                               String s = getValue().toString();
  460. +                               StringTokenizer st = new StringTokenizer(s, ",");
  461. +                               int id = 0;
  462. +                               long ammount = 0;
  463. +                              
  464. +                               try
  465. +                               {
  466. +                                       id = Integer.parseInt(st.nextToken());
  467. +                                       ammount = Integer.parseInt(st.nextToken());
  468. +                                      
  469. +                                       if (player.getInventory().getItemByItemId(id).getCount() >= ammount)
  470. +                                       {
  471. +                                               return true;
  472. +                                       }
  473. +                  }
  474. +                               catch (NumberFormatException nfe)
  475. +                               {
  476. +                                       nfe.printStackTrace();
  477. +                  }
  478. +                return false;
  479. +       }
  480. +}
  481. \ No newline at end of file
  482. Index: head-src/com/l2jfrozen/AchievementEngine/StatsCondition.java
  483. ===================================================================
  484. --- head-src/com/l2jfrozen/AchievementEngine/StatsCondition.java        (revision 0)
  485. +++ head-src/com/l2jfrozen/AchievementEngine/StatsCondition.java        (revision 0)
  486. @@ -0,0 +1,34 @@
  487. +package com.l2jfrozen.AchievementEngine;
  488. +
  489. +import com.l2jfrozen.AchievementEngine.Condition;
  490. +
  491. +/**
  492. + * @author Matim
  493. + * @version 1.0
  494. + */
  495. +public abstract class StatsCondition extends Condition
  496. +{
  497. +        private StatsConditionType _type;
  498. +        
  499. +        public StatsCondition(Object value, StatsConditionType type)
  500. +        {
  501. +                super(value);
  502. +                _type = type;
  503. +        }
  504. +        
  505. +        public StatsConditionType getType()
  506. +        {
  507. +                return _type;
  508. +        }
  509. +        
  510. +        public enum StatsConditionType
  511. +        {
  512. +                MIN_PVP_COUNT,
  513. +                MIN_PK_COUNT,
  514. +                MAX_HP,
  515. +                MAX_MP,
  516. +                MAX_CP,
  517. +               MIN_KARMA,
  518. +                MIN_RANK,
  519. +        }
  520. +}
  521. \ No newline at end of file
  522. Index: head-src/com/l2jfrozen/AchievementEngine/StatusCondition.java
  523. ===================================================================
  524. --- head-src/com/l2jfrozen/AchievementEngine/StatusCondition.java       (revision 0)
  525. +++ head-src/com/l2jfrozen/AchievementEngine/StatusCondition.java       (revision 0)
  526. @@ -0,0 +1,49 @@
  527. +/*
  528. + * This program is free software: you can redistribute it and/or modify it under
  529. + * the terms of the GNU General Public License as published by the Free Software
  530. + * Foundation, either version 3 of the License, or (at your option) any later
  531. + * version.
  532. + *
  533. + * This program is distributed in the hope that it will be useful, but WITHOUT
  534. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  535. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  536. + * details.
  537. + *
  538. + * You should have received a copy of the GNU General Public License along with
  539. + * this program. If not, see <http://www.gnu.org/licenses/>.
  540. + */
  541. +package com.l2jfrozen.AchievementEngine;
  542. +
  543. +import com.l2jfrozen.AchievementEngine.Condition;
  544. +
  545. +/**
  546. + * @author Matim
  547. + * @version 1.0
  548. + */
  549. +public abstract class StatusCondition extends Condition
  550. +{
  551. +        private StatusConditionType _type;
  552. +        
  553. +        public StatusCondition(Object value, StatusConditionType type)
  554. +        {
  555. +                super(value);
  556. +                _type = type;
  557. +        }
  558. +        
  559. +        public StatusConditionType getType()
  560. +        {
  561. +                return _type;
  562. +        }
  563. +        
  564. +        public enum StatusConditionType
  565. +        {
  566. +                MUST_BE_NOBLE,
  567. +                MUST_BE_HERO,
  568. +                MUST_BE_MARRIED,
  569. +                MUST_BE_ACADEMY_MEMBER,
  570. +                MUST_BE_MAGE,
  571. +                MUST_BE_SUMMONER,
  572. +                HAS_COMMON_CRAFT,
  573. +                HAS_DWARVEN_CRAFT,
  574. +        }
  575. +}
  576. \ No newline at end of file
  577. Index: head-src/com/l2jfrozen/AchievementEngine/AchievementsManager.java
  578. ===================================================================
  579. --- head-src/com/l2jfrozen/AchievementEngine/AchievementsManager.java   (revision 0)
  580. +++ head-src/com/l2jfrozen/AchievementEngine/AchievementsManager.java   (revision 0)
  581. @@ -0,0 +1,243 @@
  582. +package com.l2jfrozen.AchievementEngine;
  583. +
  584. +import java.io.File;
  585. +
  586. +import java.sql.Connection;
  587. +import java.sql.SQLException;
  588. +import java.sql.Statement;
  589. +import java.util.Map;
  590. +import java.util.logging.Logger;
  591. +
  592. +import javax.xml.parsers.DocumentBuilderFactory;
  593. +
  594. +import javolution.util.FastList;
  595. +import javolution.util.FastMap;
  596. +
  597. +import org.w3c.dom.Document;
  598. +import org.w3c.dom.NamedNodeMap;
  599. +import org.w3c.dom.Node;
  600. +
  601. +
  602. +
  603. +import com.l2jfrozen.Config;
  604. +import com.l2jfrozen.util.database.L2DatabaseFactory;
  605. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  606. +import com.l2jfrozen.AchievementEngine.Achievement;
  607. +import com.l2jfrozen.AchievementEngine.Condition;
  608. +import com.l2jfrozen.AchievementEngine.ClanCondition.ClanConditionType;
  609. +import com.l2jfrozen.AchievementEngine.StatsCondition.StatsConditionType;
  610. +import com.l2jfrozen.AchievementEngine.StatusCondition.StatusConditionType;
  611. +import com.l2jfrozen.AchievementEngine.Adena;
  612. +import com.l2jfrozen.AchievementEngine.Clan;
  613. +import com.l2jfrozen.AchievementEngine.ItemsCount;
  614. +import com.l2jfrozen.AchievementEngine.Level;
  615. +import com.l2jfrozen.AchievementEngine.Stats;
  616. +import com.l2jfrozen.AchievementEngine.Status;
  617. +import com.l2jfrozen.AchievementEngine.WeaponEnchant;
  618. +
  619. +/**
  620. + * @author Matim
  621. + * @version 1.0
  622. + */
  623. +public class AchievementsManager
  624. +{
  625. +        private Map<Integer, Achievement> _achievementList = new FastMap<Integer, Achievement>();
  626. +        
  627. +        
  628. +        private static Logger _log = Logger.getLogger(AchievementsManager.class.getName());
  629. +        
  630. +        public AchievementsManager()
  631. +        {
  632. +                loadAchievements();
  633. +        }
  634. +        
  635. +        private void loadAchievements()
  636. +        {
  637. +                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  638. +                factory.setValidating(false);
  639. +               factory.setIgnoringComments(true);
  640. +                
  641. +                File file = new File(Config.DATAPACK_ROOT + "/config/absolute/achievements.xml");
  642. +                
  643. +                if (!file.exists())
  644. +                {
  645. +                        _log.warning("[AchievementsEngine] Error: achievements xml file does not exist, check directory!");
  646. +                }
  647. +                try
  648. +                {
  649. +                        Document doc = factory.newDocumentBuilder().parse(file);
  650. +                        
  651. +                        for (Node list = doc.getFirstChild(); list != null; list = list.getNextSibling())
  652. +                        {
  653. +                                       if("list".equalsIgnoreCase(list.getNodeName()))
  654. +                                {
  655. +                                        for (Node achievement = list.getFirstChild(); achievement != null; achievement = achievement.getNextSibling())
  656. +                                       {
  657. +                                                               if("achievement".equalsIgnoreCase(achievement.getNodeName()))
  658. +                                                {
  659. +                                                        int id = checkInt(achievement, "id");
  660. +                                                        
  661. +                                                        String name = String.valueOf(achievement.getAttributes().getNamedItem("name").getNodeValue());
  662. +                                                        String description = String.valueOf(achievement.getAttributes().getNamedItem("description").getNodeValue());
  663. +                                                        String reward = String.valueOf(achievement.getAttributes().getNamedItem("reward").getNodeValue());
  664. +                                                        boolean repeat = checkBoolean(achievement, "repeatable");
  665. +                                                        
  666. +                                                        FastList<Condition> conditions = conditionList(achievement.getAttributes());
  667. +                                                        
  668. +                                                        _achievementList.put(id, new Achievement(id, name, description, reward, repeat, conditions));
  669. +                                                        alterTable(id);
  670. +                                                }
  671. +                                        }
  672. +                                }
  673. +                        }
  674. +                        
  675. +                        _log.info("[AchievementsEngine] Successfully loaded: " + getAchievementList().size() + " achievements from xml!");
  676. +                }
  677. +                catch (Exception e)
  678. +                {
  679. +                        _log.warning("[AchievementsEngine] Error: " + e);
  680. +                        e.printStackTrace();
  681. +                }
  682. +        }
  683. +        
  684. +        public void rewardForAchievement(int achievementID, L2PcInstance player)
  685. +        {
  686. +                Achievement achievement = _achievementList.get(achievementID);
  687. +                
  688. +                for (int id: achievement.getRewardList().keySet())
  689. +                player.addItem(achievement.getName(), id, achievement.getRewardList().get(id), player, true);
  690. +        }
  691. +        
  692. +        private boolean checkBoolean(Node d, String nodename)
  693. +        {
  694. +                boolean b = false;
  695. +                
  696. +                try
  697. +                {
  698. +                        b = Boolean.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
  699. +                }
  700. +                catch (Exception e)
  701. +                {
  702. +                        
  703. +                }
  704. +                return b;
  705. +        }
  706. +        
  707. +        private int checkInt(Node d, String nodename)
  708. +        {
  709. +                int i = 0;
  710. +                
  711. +                try
  712. +                {
  713. +                        i = Integer.valueOf(d.getAttributes().getNamedItem(nodename).getNodeValue());
  714. +                }
  715. +                catch (Exception e)
  716. +                {
  717. +                        
  718. +                }
  719. +                return i;
  720. +        }
  721. +        
  722. +        /**
  723. +         * Alter table, catch exception if already exist.
  724. +         * @param fieldID
  725. +         */
  726. +        private void alterTable(int fieldID)
  727. +        {
  728. +                Connection con = null;
  729. +                try
  730. +                {
  731. +                        con = L2DatabaseFactory.getInstance().getConnection();
  732. +                        Statement statement = con.createStatement();
  733. +                        statement.executeUpdate("ALTER TABLE achievements ADD a" + fieldID + " INT DEFAULT 0");
  734. +                        statement.close();
  735. +                }
  736. +                catch (SQLException e)
  737. +                {
  738. +
  739. +                }
  740. +                finally
  741. +                {
  742. +                        L2DatabaseFactory.close(con);
  743. +               }
  744. +        }
  745. +        
  746. +        public FastList<Condition> conditionList(NamedNodeMap attributesList)
  747. +        {
  748. +                FastList<Condition> conditions = new FastList<Condition>();
  749. +                
  750. +           for (int j = 0; j < attributesList.getLength(); j++)
  751. +            {
  752. +                addToConditionList(attributesList.item(j).getNodeName(), attributesList.item(j).getNodeValue(), conditions);
  753. +            }
  754. +                
  755. +                return conditions;
  756. +        }
  757. +        
  758. +        public Map<Integer, Achievement> getAchievementList()
  759. +        {
  760. +                return _achievementList;
  761. +        }
  762. +        
  763. +        public static AchievementsManager getInstance()
  764. +        {
  765. +                return SingletonHolder._instance;
  766. +        }
  767. +                
  768. +        private static class SingletonHolder
  769. +        {
  770. +                protected static final AchievementsManager _instance = new AchievementsManager();
  771. +       }
  772. +        
  773. +        private void addToConditionList(String nodeName, Object value, FastList<Condition> conditions)
  774. +        {
  775. +                if (nodeName.equals("minLevel"))
  776. +                        conditions.add(new Level(value));
  777. +                else if (nodeName.equals("minPvPCount"))
  778. +                       conditions.add(new Stats(value, StatsConditionType.MIN_PVP_COUNT));
  779. +                else if (nodeName.equals("minPkCount"))
  780. +                        conditions.add(new Stats(value, StatsConditionType.MIN_PK_COUNT));
  781. +                else if (nodeName.equals("minClanLevel"))
  782. +                        conditions.add(new Clan(value, ClanConditionType.MIN_CLAN_LEVEL));
  783. +                else if (nodeName.equals("mustBeHero"))
  784. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_HERO));
  785. +                else if (nodeName.equals("mustBeNoble"))
  786. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_NOBLE));
  787. +                else if (nodeName.equals("minWeaponEnchant"))
  788. +                        conditions.add(new WeaponEnchant(value));                      
  789. +                else if (nodeName.equals("minKarmaCount"))
  790. +                        conditions.add(new Stats(value, StatsConditionType.MIN_KARMA));
  791. +                else if (nodeName.equals("minRankCount"))
  792. +                   conditions.add(new Stats(value, StatsConditionType.MIN_RANK));
  793. +                else if (nodeName.equals("minAdenaCount"))
  794. +                        conditions.add(new Adena(value));
  795. +                else if (nodeName.equals("minClanMembersCount"))
  796. +                        conditions.add(new Clan(value, ClanConditionType.MIN_CLAN_MEMBERS_COUNT));
  797. +                else if (nodeName.equals("mustBeClanLeader"))
  798. +                        conditions.add(new Clan(value, ClanConditionType.MUST_BE_CLAN_LEADER));
  799. +                else if (nodeName.equals("maxHP"))
  800. +                        conditions.add(new Stats(value, StatsConditionType.MAX_HP));
  801. +                else if (nodeName.equals("maxMP"))
  802. +                        conditions.add(new Stats(value, StatsConditionType.MAX_MP));
  803. +                else if (nodeName.equals("maxCP"))
  804. +                        conditions.add(new Stats(value, StatsConditionType.MAX_CP));
  805. +                else if (nodeName.equals("mustBeMarried"))
  806. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_MARRIED));
  807. +                else if (nodeName.equals("itemAmmount"))
  808. +                        conditions.add(new ItemsCount(value));
  809. +                else if (nodeName.equals("crpAmmount"))
  810. +                        conditions.add(new Clan(value, ClanConditionType.CRP_AMMOUNT));
  811. +                else if (nodeName.equals("lordOfCastle"))
  812. +                        conditions.add(new Clan(value, ClanConditionType.IS_CASTLE_LORD));
  813. +                else if (nodeName.equals("mustBeAcademyMember"))
  814. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_ACADEMY_MEMBER));
  815. +                else if (nodeName.equals("mustBeMageClass"))
  816. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_MAGE));    
  817. +                else if (nodeName.equals("mustBeSummoner"))
  818. +                        conditions.add(new Status(value, StatusConditionType.MUST_BE_SUMMONER));
  819. +                else if (nodeName.equals("hasCommonCraft"))
  820. +                        conditions.add(new Status(value, StatusConditionType.HAS_COMMON_CRAFT));
  821. +                else if (nodeName.equals("hasDwarvenCraft"))
  822. +                        conditions.add(new Status(value, StatusConditionType.HAS_DWARVEN_CRAFT));
  823. +        }
  824. +}
  825. \ No newline at end of file
  826. Index: head-src/com/l2jfrozen/AchievementEngine/Achievement.java
  827. ===================================================================
  828. --- head-src/com/l2jfrozen/AchievementEngine/Achievement.java   (revision 0)
  829. +++ head-src/com/l2jfrozen/AchievementEngine/Achievement.java   (revision 0)
  830. @@ -0,0 +1,110 @@
  831. +package com.l2jfrozen.AchievementEngine;
  832. +
  833. +import java.util.logging.Logger;
  834. +
  835. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  836. +
  837. +import javolution.util.FastList;
  838. +import javolution.util.FastMap;
  839. +
  840. +/**
  841. + * @author Matim
  842. + * @version 1.0
  843. + */
  844. +public class Achievement
  845. +{
  846. +        private int _id;
  847. +        private String _name;
  848. +        private String _reward;
  849. +        private String _description = "No Description!";
  850. +        private boolean _repeatable;
  851. +      
  852. +        private FastMap<Integer, Long> _rewardList;
  853. +        private FastList<Condition> _conditions;
  854. +        
  855. +        private static Logger _log = Logger.getLogger(Achievement.class.getName());
  856. +        
  857. +        public Achievement(int id, String name, String description, String reward, boolean repeatable, FastList<Condition> conditions)
  858. +        {
  859. +                _rewardList = new FastMap<Integer, Long>();
  860. +                _id = id;
  861. +                _name = name;
  862. +                _description = description;
  863. +                _reward = reward;
  864. +                _conditions = conditions;
  865. +                _repeatable = repeatable;
  866. +
  867. +                createRewardList();
  868. +        }
  869. +        
  870. +        private void createRewardList()
  871. +        {
  872. +                for (String s : _reward.split(";"))
  873. +                {
  874. +                        if (s == null || s.isEmpty())
  875. +                                continue;
  876. +                        
  877. +                        String[] split = s.split(",");
  878. +                        Integer item = 0;
  879. +                        Long count = new Long(0);
  880. +                        try
  881. +                        {
  882. +                                item = Integer.valueOf(split[0]);
  883. +                                count = Long.valueOf(split[1]);
  884. +                        }
  885. +                        catch(NumberFormatException nfe)
  886. +                        {
  887. +                                _log.warning("[AchievementsEngine] Error: Wrong reward " + nfe);
  888. +                       }
  889. +                        _rewardList.put(item, count);
  890. +                }
  891. +        }
  892. +        
  893. +        public boolean meetAchievementRequirements(L2PcInstance player)
  894. +        {
  895. +                for (Condition c: getConditions())
  896. +                {
  897. +                        if (!c.meetConditionRequirements(player))
  898. +                       {
  899. +                                return false;
  900. +                        }
  901. +                }
  902. +                return true;
  903. +        }
  904. +        
  905. +        public int getID()
  906. +        {
  907. +                return _id;
  908. +        }
  909. +        
  910. +        public String getName()
  911. +        {
  912. +                return _name;
  913. +        }
  914. +        
  915. +        public String getDescription()
  916. +        {
  917. +                return _description;
  918. +        }
  919. +        
  920. +        public String getReward()
  921. +        {
  922. +                return _reward;
  923. +        }
  924. +        
  925. +        public boolean isRepeatable()
  926. +        {
  927. +                return _repeatable;
  928. +        }
  929. +        
  930. +        public FastMap<Integer, Long> getRewardList()
  931. +        {
  932. +                return _rewardList;
  933. +        }
  934. +        
  935. +        public FastList<Condition> getConditions()
  936. +        {
  937. +                return _conditions;
  938. +        }
  939. +}
  940. +
  941. Index: head-src/com/l2jfrozen/AchievementEngine/Adena.java
  942. ===================================================================
  943. --- head-src/com/l2jfrozen/AchievementEngine/Adena.java (revision 0)
  944. +++ head-src/com/l2jfrozen/AchievementEngine/Adena.java (revision 0)
  945. @@ -0,0 +1,30 @@
  946. +package com.l2jfrozen.AchievementEngine;
  947. +
  948. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  949. +import com.l2jfrozen.AchievementEngine.Condition;
  950. +
  951. +/**
  952. + * @author Matim
  953. + * @version 1.0
  954. + */
  955. +public class Adena extends Condition
  956. +{
  957. +        public Adena(Object value)
  958. +        {
  959. +                super(value);
  960. +        }
  961. +
  962. +        @Override
  963. +        public boolean meetConditionRequirements(L2PcInstance player)
  964. +        {
  965. +                if (getValue() == null)
  966. +                {
  967. +                        return false;
  968. +                }
  969. +                               long val = Integer.parseInt(getValue().toString());
  970. +                              
  971. +                               if (player.getInventory().getAdena() >= val)
  972. +                                       return true;
  973. +                return false;
  974. +        }
  975. +}
  976. \ No newline at end of file
  977. Index: head-src/com/l2jfrozen/AchievementEngine/Stats.java
  978. ===================================================================
  979. --- head-src/com/l2jfrozen/AchievementEngine/Stats.java (revision 0)
  980. +++ head-src/com/l2jfrozen/AchievementEngine/Stats.java (revision 0)
  981. @@ -0,0 +1,89 @@
  982. +/*
  983. + * This program is free software: you can redistribute it and/or modify it under
  984. + * the terms of the GNU General Public License as published by the Free Software
  985. + * Foundation, either version 3 of the License, or (at your option) any later
  986. + * version.
  987. + *
  988. + * This program is distributed in the hope that it will be useful, but WITHOUT
  989. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  990. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  991. + * details.
  992. + *
  993. + * You should have received a copy of the GNU General Public License along with
  994. + * this program. If not, see <http://www.gnu.org/licenses/>.
  995. + */
  996. +package com.l2jfrozen.AchievementEngine;
  997. +
  998. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  999. +import com.l2jfrozen.AchievementEngine.StatsCondition;
  1000. +
  1001. +/**
  1002. + * @author Matim
  1003. + * @version 1.0
  1004. +*/
  1005. +public class Stats extends StatsCondition
  1006. +{
  1007. +        public Stats(Object value, StatsConditionType type)
  1008. +        {
  1009. +                super(value, type);
  1010. +        }
  1011. +
  1012. +        @Override
  1013. +        public boolean meetConditionRequirements(L2PcInstance player)
  1014. +        {
  1015. +                if (getValue() == null)
  1016. +                {
  1017. +                        return false;
  1018. +                }
  1019. +                
  1020. +                int val = Integer.parseInt(getValue().toString());
  1021. +                
  1022. +                switch (getType())
  1023. +                {
  1024. +                        case MAX_HP:
  1025. +                                if (player.getMaxHp() >= val)
  1026. +                                {
  1027. +                                        return true;
  1028. +                                }
  1029. +                                break;
  1030. +                                
  1031. +                        case MAX_CP:
  1032. +                                if (player.getMaxCp() >= val)
  1033. +                                {
  1034. +                                        return true;
  1035. +                                }
  1036. +                                break;
  1037. +                                
  1038. +                        case MAX_MP:
  1039. +                                if (player.getMaxMp() >= val)
  1040. +                                {
  1041. +                                        return true;
  1042. +                                }
  1043. +                                break;
  1044. +                                
  1045. +                        case MIN_PK_COUNT:
  1046. +                                if (player.getPkKills() >= val)
  1047. +                                {
  1048. +                                        return true;
  1049. +                                }
  1050. +                                break;
  1051. +                              
  1052. +                        case MIN_PVP_COUNT:
  1053. +                                if (player.getPvpKills() >= val)
  1054. +                                {
  1055. +                                        return true;
  1056. +                                }
  1057. +                                break;
  1058. +                                
  1059. +                        case MIN_KARMA:
  1060. +                               if (player.getKarma() >= val)
  1061. +                               {
  1062. +                                        return true;
  1063. +                                }
  1064. +                                break;
  1065. +                                
  1066. +                }
  1067. +                
  1068. +                return false;
  1069. +        }
  1070. +}
  1071. \ No newline at end of file
  1072. Index: head-src/com/l2jfrozen/AchievementEngine/Status.java
  1073. ===================================================================
  1074. --- head-src/com/l2jfrozen/AchievementEngine/Status.java        (revision 0)
  1075. +++ head-src/com/l2jfrozen/AchievementEngine/Status.java        (revision 0)
  1076. @@ -0,0 +1,93 @@
  1077. +/*
  1078. + * This program is free software: you can redistribute it and/or modify it under
  1079. + * the terms of the GNU General Public License as published by the Free Software
  1080. + * Foundation, either version 3 of the License, or (at your option) any later
  1081. + * version.
  1082. + *
  1083. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1084. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1085. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1086. + * details.
  1087. + *
  1088. + * You should have received a copy of the GNU General Public License along with
  1089. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1090. + */
  1091. +package com.l2jfrozen.AchievementEngine;
  1092. +
  1093. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  1094. +import com.l2jfrozen.AchievementEngine.StatusCondition;
  1095. +
  1096. +/**
  1097. + * @author Matim
  1098. + * @version 1.0
  1099. + */
  1100. +public class Status extends StatusCondition
  1101. +{
  1102. +        public Status(Object value, StatusConditionType type)
  1103. +        {
  1104. +                super(value, type);
  1105. +        }
  1106. +
  1107. +        @Override
  1108. +        public boolean meetConditionRequirements(L2PcInstance player)
  1109. +        {
  1110. +                if (getValue() == null)
  1111. +                {
  1112. +                        return false;
  1113. +                }
  1114. +                
  1115. +                switch (getType())
  1116. +                {
  1117. +                        case MUST_BE_NOBLE:
  1118. +                                if (player.isNoble())
  1119. +                                {
  1120. +                                        return true;
  1121. +                                }
  1122. +                                break;
  1123. +                                
  1124. +                        case MUST_BE_HERO:
  1125. +                                if (player.isHero())
  1126. +                                {
  1127. +                                        return true;
  1128. +                                }
  1129. +                                break;
  1130. +                                
  1131. +                        case MUST_BE_MARRIED:
  1132. +                                if (player.isMarried())
  1133. +                                {
  1134. +                                        return true;
  1135. +                                }
  1136. +                                break;
  1137. +                                
  1138. +                        case MUST_BE_ACADEMY_MEMBER:
  1139. +                                if (player.isAcademyMember())
  1140. +                                {
  1141. +                                        return true;
  1142. +                                }
  1143. +                                break;
  1144. +                                
  1145. +                        case MUST_BE_MAGE:
  1146. +                               if (player.isMageClass())
  1147. +                                {
  1148. +                                        return true;
  1149. +                                }
  1150. +                                break;
  1151. +                                
  1152. +                                
  1153. +                        case HAS_COMMON_CRAFT:
  1154. +                                if (player.hasCommonCraft())
  1155. +                                {
  1156. +                                       return true;
  1157. +                                }
  1158. +                                break;
  1159. +                                
  1160. +                        case HAS_DWARVEN_CRAFT:
  1161. +                                if (player.hasCommonCraft())
  1162. +                                {
  1163. +                                        return true;
  1164. +                                }
  1165. +                                break;
  1166. +                } //TODO CLASS ID
  1167. +                return false;
  1168. +        }
  1169. +}
  1170. \ No newline at end of file
  1171. Index: head-src/com/l2jfrozen/AchievementEngine/Clan.java
  1172. ===================================================================
  1173. --- head-src/com/l2jfrozen/AchievementEngine/Clan.java  (revision 0)
  1174. +++ head-src/com/l2jfrozen/AchievementEngine/Clan.java  (revision 0)
  1175. @@ -0,0 +1,69 @@
  1176. +package com.l2jfrozen.AchievementEngine;
  1177. +
  1178. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  1179. +import com.l2jfrozen.AchievementEngine.ClanCondition;
  1180. +
  1181. +/**
  1182. + * @author Matim
  1183. + * @version 1.0
  1184. + */
  1185. +public class Clan extends ClanCondition
  1186. +{
  1187. +        public Clan(Object value, ClanConditionType type)
  1188. +        {
  1189. +                super(value, type);
  1190. +        }
  1191. +
  1192. +        @Override
  1193. +       public boolean meetConditionRequirements(L2PcInstance player)
  1194. +        {
  1195. +                if (getValue() == null)
  1196. +                {
  1197. +                        return false;
  1198. +                }
  1199. +                
  1200. +            if (player.getClan() != null)
  1201. +                {
  1202. +                        int val = Integer.parseInt(getValue().toString());
  1203. +                        
  1204. +                        switch (getType())
  1205. +                        {
  1206. +                                case MIN_CLAN_LEVEL:
  1207. +                                        if (player.getClan().getLevel() >= val)
  1208. +                                        {
  1209. +                                                return true;
  1210. +                                        }
  1211. +                                    break;
  1212. +                                    
  1213. +                                case MIN_CLAN_MEMBERS_COUNT:
  1214. +                                       if (player.getClan().getMembersCount() >= val)
  1215. +                                        {
  1216. +                                                return true;
  1217. +                                        }
  1218. +                                    break;
  1219. +                                    
  1220. +                                case MUST_BE_CLAN_LEADER:
  1221. +                                        if (player.isClanLeader())
  1222. +                                        {
  1223. +                                                return true;
  1224. +                                        }
  1225. +                                    break;
  1226. +                                    
  1227. +                                case CRP_AMMOUNT:
  1228. +                                        if (player.getClan().getReputationScore() >= val)
  1229. +                                        {
  1230. +                                                return true;
  1231. +                                        }
  1232. +                                       break;
  1233. +                                        
  1234. +                                case IS_CASTLE_LORD:
  1235. +                                        if (player.isCastleLord(val))
  1236. +                                        {
  1237. +                                                return true;
  1238. +                                        }
  1239. +                                        break;
  1240. +                        }
  1241. +                }
  1242. +                return false;
  1243. +        }
  1244. +}
  1245. \ No newline at end of file
  1246. Index: head-src/com/l2jfrozen/AchievementEngine/Level.java
  1247. ===================================================================
  1248. --- head-src/com/l2jfrozen/AchievementEngine/Level.java (revision 0)
  1249. +++ head-src/com/l2jfrozen/AchievementEngine/Level.java (revision 0)
  1250. @@ -0,0 +1,44 @@
  1251. +/*
  1252. + * This program is free software: you can redistribute it and/or modify it under
  1253. + * the terms of the GNU General Public License as published by the Free Software
  1254. + * Foundation, either version 3 of the License, or (at your option) any later
  1255. + * version.
  1256. + *
  1257. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1258. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1259. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1260. + * details.
  1261. + *
  1262. + * You should have received a copy of the GNU General Public License along with
  1263. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1264. + */
  1265. +package com.l2jfrozen.AchievementEngine;
  1266. +
  1267. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  1268. +import com.l2jfrozen.AchievementEngine.Condition;
  1269. +
  1270. +/**
  1271. + * @author Matim
  1272. + * @version 1.0
  1273. + */
  1274. +public class Level extends Condition
  1275. +{
  1276. +        public Level(Object value)
  1277. +        {
  1278. +               super(value);
  1279. +        }
  1280. +        
  1281. +        @Override
  1282. +        public boolean meetConditionRequirements(L2PcInstance player)
  1283. +        {
  1284. +                if (getValue() == null)
  1285. +                {
  1286. +                        return false;
  1287. +                }
  1288. +                               int val = Integer.parseInt(getValue().toString());
  1289. +                                  
  1290. +                                   if (player.getLevel() >= val)
  1291. +                                          return true;
  1292. +                return false;
  1293. +        }
  1294. +}
  1295. Create gameserver/model/actor/instance/L2AchievementsInstance.java
  1296. ### Eclipse Workspace Patch 1.0
  1297. #P L2jFrozen_GameServer
  1298. Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2AchievementsInstance.java
  1299. ===================================================================
  1300. --- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2AchievementsInstance.java  (revision 0)
  1301. +++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2AchievementsInstance.java  (revision 0)
  1302. @@ -0,0 +1,277 @@
  1303. +package com.l2jfrozen.gameserver.model.actor.instance;
  1304. +
  1305. +import java.util.StringTokenizer;
  1306. +
  1307. +import javolution.text.TextBuilder;
  1308. +
  1309. +import com.l2jfrozen.gameserver.model.L2World;
  1310. +import com.l2jfrozen.gameserver.model.entity.Announcements;
  1311. +import com.l2jfrozen.AchievementEngine.AchievementsManager;
  1312. +import com.l2jfrozen.AchievementEngine.Achievement;
  1313. +import com.l2jfrozen.AchievementEngine.Condition;
  1314. +import com.l2jfrozen.gameserver.model.Inventory;
  1315. +import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
  1316. +import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
  1317. +
  1318. +/**
  1319. + * @author Matim
  1320. + * @version 1.0
  1321. + */
  1322. +@SuppressWarnings("unused")
  1323. +public class L2AchievementsInstance extends L2FolkInstance
  1324. +{
  1325. +        public L2AchievementsInstance(int objectId, L2NpcTemplate template)
  1326. +        {
  1327. +                super(objectId, template);
  1328. +        }
  1329. +        
  1330. +        @Override
  1331. +        public void onBypassFeedback(L2PcInstance player, String command)
  1332. +        {
  1333. +                if (player == null || player.getLastFolkNPC() == null || player.getLastFolkNPC().getObjectId() != this.getObjectId())
  1334. +                {
  1335. +                        return;
  1336. +                }
  1337. +                if (command.startsWith("showMyAchievements"))
  1338. +                {                      
  1339. +                        player.getAchievemntData();
  1340. +                        showMyAchievements(player);
  1341. +                }
  1342. +                else if (command.startsWith("achievementInfo"))
  1343. +                {                      
  1344. +                        StringTokenizer st = new StringTokenizer(command, " ");
  1345. +                       st.nextToken();
  1346. +                        int id = Integer.parseInt(st.nextToken());
  1347. +                        
  1348. +                        showAchievementInfo(id, player);
  1349. +               }
  1350. +                else if (command.startsWith("topList"))
  1351. +                {                      
  1352. +                        showTopListWindow(player);
  1353. +                }
  1354. +                else if (command.startsWith("showMainWindow"))
  1355. +                {
  1356. +                        showChatWindow(player, 0);
  1357. +                }
  1358. +                else if (command.startsWith("getReward"))
  1359. +                {
  1360. +                        StringTokenizer st = new StringTokenizer(command, " ");
  1361. +                        st.nextToken();
  1362. +                        int id = Integer.parseInt(st.nextToken());
  1363. +                        AchievementsManager.getInstance().rewardForAchievement(id, player);
  1364. +                        player.saveAchievementData(id);
  1365. +                        showMyAchievements(player);
  1366. +  
  1367. +                }
  1368. +                else if (command.startsWith ("showMyStats"))
  1369. +                {
  1370. +                        showMyStatsWindow(player);
  1371. +                }
  1372. +                else if (command.startsWith("showHelpWindow"))
  1373. +                {
  1374. +                        showHelpWindow(player);
  1375. +                }
  1376. +        }
  1377. +
  1378. +        @Override
  1379. +        public void showChatWindow(L2PcInstance player, int val)
  1380. +        {
  1381. +                TextBuilder tb = new TextBuilder();
  1382. +                tb.append("<html><title>Achievements Manager</title><body><center><br>");
  1383. +                tb.append("Hello <font color=\"LEVEL\">" + player.getName() + "</font><br>Are you looking for challenge?");
  1384. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1385. +                tb.append("<button value=\"My Achievements\" action=\"bypass -h npc_%objectId%_showMyAchievements\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");
  1386. +                tb.append("<button value=\"Statistics\" action=\"bypass -h npc_%objectId%_showMyStats\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");
  1387. +                tb.append("<button value=\"Top List\" action=\"bypass -h npc_%objectId%_topList\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");
  1388. +                tb.append("<button value=\"Help\" action=\"bypass -h npc_%objectId%_showHelpWindow\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");
  1389. +                
  1390. +                NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1391. +                msg.setHtml(tb.toString());
  1392. +                msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1393. +        
  1394. +                player.sendPacket(msg);
  1395. +        }
  1396. +        
  1397. +        private void showMyAchievements(L2PcInstance player)
  1398. +        {
  1399. +                TextBuilder tb = new TextBuilder();
  1400. +                tb.append("<html><title>Achievements Manager</title><body><br>");
  1401. +                
  1402. +                tb.append("<center><font color=\"LEVEL\">My achievements</font>:</center><br>");
  1403. +                
  1404. +                if (AchievementsManager.getInstance().getAchievementList().isEmpty())
  1405. +                {
  1406. +                       tb.append("There are no Achievements created yet!");
  1407. +                }
  1408. +                else
  1409. +                {
  1410. +                        int i = 0;
  1411. +                        
  1412. +                        tb.append("<table width=270 border=0 bgcolor=\"33FF33\">");
  1413. +                        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>");
  1414. +                        tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1415. +                        
  1416. +                        for (Achievement a: AchievementsManager.getInstance().getAchievementList().values())
  1417. +                        {
  1418. +                                tb.append(getTableColor(i));
  1419. +                                tb.append("<tr><td width=270 align=\"left\">" + a.getName() + "</td><td width=50 align=\"right\"><a action=\"bypass -h npc_%objectId%_achievementInfo "
  1420. +                                + a.getID() + "\">info</a></td><td width=200 align=\"center\">" + getStatusString(a.getID(), player) + "</td></tr></table>");
  1421. +                                i++;
  1422. +                        }
  1423. +                        
  1424. +                        tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1425. +                        tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></center>");
  1426. +                }
  1427. +                
  1428. +                NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1429. +                msg.setHtml(tb.toString());
  1430. +                msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1431. +        
  1432. +                player.sendPacket(msg);
  1433. +        }
  1434. +        
  1435. +        private void showAchievementInfo(int achievementID, L2PcInstance player)
  1436. +        {
  1437. +                Achievement a = AchievementsManager.getInstance().getAchievementList().get(achievementID);
  1438. +                
  1439. +                TextBuilder tb = new TextBuilder();
  1440. +                tb.append("<html><title>Achievements Manager</title><body><br>");
  1441. +                
  1442. +                tb.append("<table width=270 border=0 bgcolor=\"33FF33\">");
  1443. +                tb.append("<tr><td width=270 align=\"center\">" + a.getName() + "</td></tr></table><br>");
  1444. +                tb.append("<center>Status: " + getStatusString(achievementID, player));
  1445. +                
  1446. +                if (a.meetAchievementRequirements(player) && !player.getCompletedAchievements().contains(achievementID))
  1447. +                {
  1448. +                        tb.append("<button value=\"Receive Reward!\" action=\"bypass -h npc_%objectId%_getReward " + a.getID() + "\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");                      
  1449. +                }
  1450. +                
  1451. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1452. +                
  1453. +                tb.append("<table width=270 border=0 bgcolor=\"33FF33\">");
  1454. +                tb.append("<tr><td width=270 align=\"center\">Description</td></tr></table><br>");
  1455. +                tb.append(a.getDescription());
  1456. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1457. +                
  1458. +                tb.append("<table width=270 border=0 bgcolor=\"33FF33\">");
  1459. +                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>");
  1460. +                tb.append(getConditionsStatus(achievementID, player));
  1461. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1462. +                tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMyAchievements\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></center>");
  1463. +                
  1464. +                NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1465. +                msg.setHtml(tb.toString());
  1466. +                msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1467. +        
  1468. +                player.sendPacket(msg);
  1469. +        }
  1470. +        
  1471. +        private void showMyStatsWindow(L2PcInstance player)
  1472. +        {
  1473. +                TextBuilder tb = new TextBuilder();
  1474. +                tb.append("<html><title>Achievements Manager</title><body><center><br>");
  1475. +                tb.append("Check your <font color=\"LEVEL\">Achievements </font>statistics:");
  1476. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1477. +                
  1478. +                player.getAchievemntData();
  1479. +                int completedCount = player.getCompletedAchievements().size();
  1480. +              
  1481. +                tb.append("You have completed: " + completedCount + "/<font color=\"LEVEL\">" + AchievementsManager.getInstance().getAchievementList().size() + "</font>");
  1482. +                
  1483. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1484. +                tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></center>");
  1485. +                
  1486. +                NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1487. +                msg.setHtml(tb.toString());
  1488. +                msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1489. +        
  1490. +                player.sendPacket(msg);
  1491. +        }
  1492. +        
  1493. +        private void showTopListWindow(L2PcInstance player)
  1494. +        {
  1495. +                TextBuilder tb = new TextBuilder();
  1496. +                tb.append("<html><title>Achievements Manager</title><body><center><br>");
  1497. +                tb.append("Check your <font color=\"LEVEL\">Achievements </font>Top List:");
  1498. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1499. +                
  1500. +               tb.append("Not implemented yet!");
  1501. +                
  1502. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1503. +                tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></center>");
  1504. +                
  1505. +                NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1506. +                msg.setHtml(tb.toString());
  1507. +                msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1508. +        
  1509. +                player.sendPacket(msg);
  1510. +        }
  1511. +        
  1512. +        private void showHelpWindow(L2PcInstance player)
  1513. +        {
  1514. +                TextBuilder tb = new TextBuilder();
  1515. +                tb.append("<html><title>Achievements Manager</title><body><center><br>");
  1516. +                tb.append("Achievements  <font color=\"LEVEL\">Help </font>page:");
  1517. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>");
  1518. +                
  1519. +                tb.append("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");
  1520. +                tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1521. +                tb.append("<font color=\"FF0000\">Not Completed</font> - you did not meet the achivement requirements.<br>");
  1522. +                tb.append("<font color=\"LEVEL\">Get Reward</font> - you may receive reward, click info.<br>");
  1523. +                tb.append("<font color=\"5EA82E\">Completed</font> - achievement completed, reward received.<br>");
  1524. +                
  1525. +               tb.append("Achievements Engine by <font color=\"LEVEL\">Matim</font>");
  1526. +               tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>");
  1527. +                tb.append("<center><button value=\"Back\" action=\"bypass -h npc_%objectId%_showMainWindow\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></center>");
  1528. +                
  1529. +                NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  1530. +                msg.setHtml(tb.toString());
  1531. +                msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  1532. +        
  1533. +                player.sendPacket(msg);
  1534. +        }
  1535. +        
  1536. +        private String getStatusString(int achievementID, L2PcInstance player)
  1537. +        {
  1538. +                if (player.getCompletedAchievements().contains(achievementID))
  1539. +                {
  1540. +                        return "<font color=\"5EA82E\">Completed</font>";
  1541. +                }
  1542. +                               if (AchievementsManager.getInstance().getAchievementList().get(achievementID).meetAchievementRequirements(player))
  1543. +                               {
  1544. +                                       return "<font color=\"LEVEL\">Get Reward</font>";
  1545. +                               }
  1546. +                               return "<font color=\"FF0000\">Not Completed</font>";
  1547. +        }
  1548. +        
  1549. +        private String getTableColor(int i)
  1550. +        {
  1551. +                if (i % 2 == 0)
  1552. +                        return "<table width=270 border=0 bgcolor=\"444444\">";
  1553. +                               return "<table width=270 border=0>";
  1554. +        }
  1555. +        
  1556. +        private String getConditionsStatus(int achievementID, L2PcInstance player)
  1557. +        {
  1558. +                int i = 0;
  1559. +                String s = "</center>";
  1560. +                Achievement a = AchievementsManager.getInstance().getAchievementList().get(achievementID);
  1561. +                String completed = "<font color=\"5EA82E\">Completed</font></td></tr></table>";
  1562. +                String notcompleted = "<font color=\"FF0000\">Not Completed</font></td></tr></table>";
  1563. +                
  1564. +                for (Condition c: a.getConditions())
  1565. +                {
  1566. +                        s+= getTableColor(i);
  1567. +                        s+= "<tr><td width=270 align=\"left\">Level</td><td width=50 align=\"right\">" + c.getValue() + "</td><td width=200 align=\"center\">";
  1568. +                        i++;
  1569. +                        
  1570. +                        if (c.meetConditionRequirements(player))
  1571. +                                s+= completed;
  1572. +                        else
  1573. +                                s+= notcompleted;
  1574. +                }
  1575. +                return s;
  1576. +        }
  1577. +}
  1578. \ No newline at end of file
  1579. Create achievements.sql
  1580. ### Eclipse Workspace Patch 1.0
  1581. #P L2jFrozen_DataPack
  1582. Index: sql/achievements.sql
  1583. ===================================================================
  1584. --- sql/achievements.sql        (revision 0)
  1585. +++ sql/achievements.sql        (revision 0)
  1586. @@ -0,0 +1,4 @@
  1587. +CREATE TABLE IF NOT EXISTS `achievements` (
  1588. +  `owner_id` INT,
  1589. +  PRIMARY KEY (`owner_id`)
  1590. +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  1591. \ No newline at end of file
  1592.  
  1593. Now make gameserver/config/achievements.xml
  1594. +  <list>
  1595. +  <achievement id="1" name="Hero" description="Gain Hero!" reward="57,20000" repeatable="false" mustBeHero="true"/>
  1596. +  <achievement id="2" name="Nobless" description="Gain Nobless!" reward="57,10000" repeatable="false" mustBeNoble="true"/>        
  1597. +  </list>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement