dymek1984 Posted August 21, 2012 Posted August 21, 2012 I am looking for achievement engine for l2j. already found a whole lot of java and. xml. Html miss only, if someone has and can put a link I will be grateful
0 dymek1984 Posted August 22, 2012 Author Posted August 22, 2012 i found this: http://pastebin.com/3vLUrLjU L2AchievementManagerInstance Index: java/com/l2jserver/gameserver/model/actor/instance/L2AchievementsManagerInstance.java =================================================================== --- java/com/l2jserver/gameserver/model/actor/instance/L2AchievementsManagerInstance.java (revision 0) +++ java/com/l2jserver/gameserver/model/actor/instance/L2AchievementsManagerInstance.java (revision 0) @@ -0,0 +1,283 @@ +package com.l2jserver.gameserver.model.actor.instance; + +import java.util.StringTokenizer; + +import javolution.text.TextBuilder; + +import com.l2jserver.gameserver.model.L2ItemInstance; +import com.l2jserver.gameserver.model.L2World; +import com.l2jserver.gameserver.model.actor.L2Npc; +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.AchievementsManager; +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Achievement; +import com.l2jserver.gameserver.model.entity.AchievmentsEngine.base.Condition; +import com.l2jserver.gameserver.model.itemcontainer.Inventory; +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage; +import com.l2jserver.gameserver.templates.chars.L2NpcTemplate; + +/** + * @author Matim + * @version 1.0 + */ +@SuppressWarnings("unused") +public class L2AchievementsManagerInstance extends L2Npc +{ + public L2AchievementsManagerInstance(int objectId, L2NpcTemplate template) + { + super(objectId, template); + } + + @Override + public void onBypassFeedback(L2PcInstance player, String command) + { + if (player == null || player.getLastFolkNPC() == null || player.getLastFolkNPC().getObjectId() != this.getObjectId()) + { + return; + } + if (command.startsWith("showMyAchievements")) + { + player.getAchievemntData(); + showMyAchievements(player); + } + else if (command.startsWith("achievementInfo")) + { + StringTokenizer st = new StringTokenizer(command, " "); + st.nextToken(); + int id = Integer.parseInt(st.nextToken()); + + showAchievementInfo(id, player); + } + else if (command.startsWith("topList")) + { + showTopListWindow(player); + } + else if (command.startsWith("showMainWindow")) + { + showChatWindow(player, 0); + } + else if (command.startsWith("getReward")) + { + StringTokenizer st = new StringTokenizer(command, " "); + st.nextToken(); + int id = Integer.parseInt(st.nextToken()); + AchievementsManager.getInstance().rewardForAchievement(id, player); + player.saveAchievementData(id); + showMyAchievements(player); + } + else if (command.startsWith ("showMyStats")) + { + showMyStatsWindow(player); + } + else if (command.startsWith("showHelpWindow")) + { + showHelpWindow(player); + } + } + + @Override + public void showChatWindow(L2PcInstance player, int val) + { + TextBuilder tb = new TextBuilder(); + tb.append("<html><title>Achievements Manager</title><body><center><br>"); + tb.append("Hello <font color=\"LEVEL\">" + player.getName() + "</font><br>Are you looking for challenge?"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>"); + 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\">"); + 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\">"); + 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\">"); + 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\">"); + + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId()); + msg.setHtml(tb.toString()); + msg.replace("%objectId%", String.valueOf(this.getObjectId())); + + player.sendPacket(msg); + } + + private void showMyAchievements(L2PcInstance player) + { + TextBuilder tb = new TextBuilder(); + tb.append("<html><title>Achievements Manager</title><body><br>"); + + tb.append("<center><font color=\"LEVEL\">My achievements</font>:</center><br>"); + + if (AchievementsManager.getInstance().getAchievementList().isEmpty()) + { + tb.append("There are no Achievements created yet!"); + } + else + { + int i = 0; + + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">"); + 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>"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>"); + + for (Achievement a: AchievementsManager.getInstance().getAchievementList().values()) + { + tb.append(getTableColor(i)); + tb.append("<tr><td width=270 align=\"left\">" + a.getName() + "</td><td width=50 align=\"right\"><a action=\"bypass -h npc_%objectId%_achievementInfo " + + a.getID() + "\">info</a></td><td width=200 align=\"center\">" + getStatusString(a.getID(), player) + "</td></tr></table>"); + i++; + } + + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + 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>"); + } + + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId()); + msg.setHtml(tb.toString()); + msg.replace("%objectId%", String.valueOf(this.getObjectId())); + + player.sendPacket(msg); + } + + private void showAchievementInfo(int achievementID, L2PcInstance player) + { + Achievement a = AchievementsManager.getInstance().getAchievementList().get(achievementID); + + TextBuilder tb = new TextBuilder(); + tb.append("<html><title>Achievements Manager</title><body><br>"); + + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">"); + tb.append("<tr><td width=270 align=\"center\">" + a.getName() + "</td></tr></table><br>"); + tb.append("<center>Status: " + getStatusString(achievementID, player)); + + if (a.meetAchievementRequirements(player) && !player.getCompletedAchievements().contains(achievementID)) + { + 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\">"); + } + + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">"); + tb.append("<tr><td width=270 align=\"center\">Description</td></tr></table><br>"); + tb.append(a.getDescription()); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">"); + 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>"); + tb.append(getConditionsStatus(achievementID, player)); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + 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>"); + + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId()); + msg.setHtml(tb.toString()); + msg.replace("%objectId%", String.valueOf(this.getObjectId())); + + player.sendPacket(msg); + } + + private void showMyStatsWindow(L2PcInstance player) + { + TextBuilder tb = new TextBuilder(); + tb.append("<html><title>Achievements Manager</title><body><center><br>"); + tb.append("Check your <font color=\"LEVEL\">Achievements </font>statistics:"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>"); + + player.getAchievemntData(); + int completedCount = player.getCompletedAchievements().size(); + + tb.append("You have completed: " + completedCount + "/<font color=\"LEVEL\">" + AchievementsManager.getInstance().getAchievementList().size() + "</font>"); + + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + 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>"); + + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId()); + msg.setHtml(tb.toString()); + msg.replace("%objectId%", String.valueOf(this.getObjectId())); + + player.sendPacket(msg); + } + + private void showTopListWindow(L2PcInstance player) + { + TextBuilder tb = new TextBuilder(); + tb.append("<html><title>Achievements Manager</title><body><center><br>"); + tb.append("Check your <font color=\"LEVEL\">Achievements </font>Top List:"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>"); + + tb.append("Not implemented yet!"); + + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + 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>"); + + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId()); + msg.setHtml(tb.toString()); + msg.replace("%objectId%", String.valueOf(this.getObjectId())); + + player.sendPacket(msg); + } + + private void showHelpWindow(L2PcInstance player) + { + TextBuilder tb = new TextBuilder(); + tb.append("<html><title>Achievements Manager</title><body><center><br>"); + tb.append("Achievements <font color=\"LEVEL\">Help </font>page:"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>"); + + 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"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + tb.append("<font color=\"FF0000\">Not Completed</font> - you did not meet the achivement requirements.<br>"); + tb.append("<font color=\"LEVEL\">Get Reward</font> - you may receive reward, click info.<br>"); + tb.append("<font color=\"5EA82E\">Completed</font> - achievement completed, reward received.<br>"); + + tb.append("Achievements Engine by <font color=\"LEVEL\">Matim</font>"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + 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>"); + + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId()); + msg.setHtml(tb.toString()); + msg.replace("%objectId%", String.valueOf(this.getObjectId())); + + player.sendPacket(msg); + } + + private String getStatusString(int achievementID, L2PcInstance player) + { + if (player.getCompletedAchievements().contains(achievementID)) + { + return "<font color=\"5EA82E\">Completed</font>"; + } + else + { + if (AchievementsManager.getInstance().getAchievementList().get(achievementID).meetAchievementRequirements(player)) + { + return "<font color=\"LEVEL\">Get Reward</font>"; + } + else + { + return "<font color=\"FF0000\">Not Completed</font>"; + } + } + } + + private String getTableColor(int i) + { + if (i % 2 == 0) + return "<table width=270 border=0 bgcolor=\"444444\">"; + else + return "<table width=270 border=0>"; + } + + private String getConditionsStatus(int achievementID, L2PcInstance player) + { + int i = 0; + String s = "</center>"; + Achievement a = AchievementsManager.getInstance().getAchievementList().get(achievementID); + String completed = "<font color=\"5EA82E\">Completed</font></td></tr></table>"; + String notcompleted = "<font color=\"FF0000\">Not Completed</font></td></tr></table>"; + + for (Condition c: a.getConditions()) + { + s+= getTableColor(i); + s+= "<tr><td width=270 align=\"left\">Level</td><td width=50 align=\"right\">" + c.getValue() + "</td><td width=200 align=\"center\">"; + i++; + + if (c.meetConditionRequirements(player)) + s+= completed; + else + s+= notcompleted; + } + return s; + } +} for L2PcInstance +private List<Integer> _completedAchievements = new FastList<Integer>(); + + public boolean readyAchievementsList() + { + if (_completedAchievements.isEmpty()) + return false; + else + return true; + } + + public void saveAchievemntData() + { + + } + + public void getAchievemntData() + { + Connection con = null; + try + { + PreparedStatement statement; + PreparedStatement insertStatement; + ResultSet rs; + con = L2DatabaseFactory.getInstance().getConnection(); + + statement = con.prepareStatement("SELECT * from achievements WHERE owner_id=" + getObjectId()); + + rs = statement.executeQuery(); + + String values = "owner_id"; + String in = Integer.toString(getObjectId()); + String questionMarks = in; + int ilosc = AchievementsManager.getInstance().getAchievementList().size(); + + if (rs.next()) + { + _completedAchievements.clear(); + for (int i=1; i <=ilosc; i++) + { + int a = rs.getInt("a" + i); + + if (!_completedAchievements.contains(i)) + if (a == 1) + _completedAchievements.add(i); + } + } + else + { + //Player hasnt entry in database, means we have to create it. + + for (int i=1; i <=ilosc; i++) + { + values += ", a" + i; + questionMarks += ", 0"; + } + + String s = "INSERT INTO achievements(" + values + ") VALUES (" + questionMarks + ")"; + insertStatement = con.prepareStatement(s); + + insertStatement.execute(); + insertStatement.close(); + } + } + catch (SQLException e) + { + _log.warning("[ACHIEVEMENTS ENGINE GETDATA]" + e); + } + finally + { + L2DatabaseFactory.close(con); + } + } + + public void saveAchievementData(int achievementID) + { + Connection con = null; + try + { + con = L2DatabaseFactory.getInstance().getConnection(); + Statement statement = con.createStatement(); + statement.executeUpdate("UPDATE achievements SET a" + achievementID + "=1 WHERE owner_id=" + getObjectId()); + statement.close(); + + if (!_completedAchievements.contains(achievementID)) + _completedAchievements.add(achievementID); + } + catch (SQLException e) + { + _log.warning("[ACHIEVEMENTS SAVE GETDATA]" + e); + } + finally + { + L2DatabaseFactory.close(con); + } + } + + public List<Integer> getCompletedAchievements() + { + return _completedAchievements; + } + everything seems fine, but when I talk with the NPC and give "My achievements" nothing happens
0 vampir Posted August 22, 2012 Posted August 22, 2012 0 errors? also debug bypass to know where error is exactly
0 dymek1984 Posted August 22, 2012 Author Posted August 22, 2012 bypass looks good. have changed a little html + private void showMyAchievements(L2PcInstance player) + { + TextBuilder tb = new TextBuilder(); + tb.append("<html><title>Achievements Manager</title><body><br>"); + + tb.append("<center><font color=\"LEVEL\">My achievements</font>:</center><br>"); + + NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId()); + msg.setHtml(tb.toString()); + msg.replace("%objectId%", String.valueOf(this.getObjectId())); + + player.sendPacket(msg); + } Edit: changed html to that and when i press my achievements i see html (ofc just simple message "achievements manager and my achievements, nothing else) maybe is something wrong in here: if (AchievementsManager.getInstance().getAchievementList().isEmpty()) + { + tb.append("There are no Achievements created yet!"); + } + else + { + int i = 0; + + tb.append("<table width=270 border=0 bgcolor=\"33FF33\">"); + 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>"); + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1\"><br>"); + + for (Achievement a: AchievementsManager.getInstance().getAchievementList().values()) + { + tb.append(getTableColor(i)); + tb.append("<tr><td width=270 align=\"left\">" + a.getName() + "</td><td width=50 align=\"right\"><a action=\"bypass -h npc_%objectId%_achievementInfo " + + a.getID() + "\">info</a></td><td width=200 align=\"center\">" + getStatusString(a.getID(), player) + "</td></tr></table>"); + i++; + } + + tb.append("<br><img src=\"l2ui.squaregray\" width=\"270\" height=\"1s\"><br>"); + 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>"); + } ? Edit: it looks like inside html code is broken cuz npc not show me. ;/
0 vampir Posted August 23, 2012 Posted August 23, 2012 i cant see anything wrong in the file, debug it as i wrote before.
Question
dymek1984
I am looking for achievement engine for l2j. already found a whole lot of java and. xml. Html miss only, if someone has and can put a link I will be grateful
6 answers to this question
Recommended Posts