|
@@ -23,13 +23,26 @@ import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
+import javolution.util.FastList;
|
|
|
|
+import javolution.util.FastMap;
|
|
|
|
+
|
|
import com.l2jserver.Config;
|
|
import com.l2jserver.Config;
|
|
import com.l2jserver.L2DatabaseFactory;
|
|
import com.l2jserver.L2DatabaseFactory;
|
|
|
|
+import com.l2jserver.gameserver.cache.HtmCache;
|
|
|
|
+import com.l2jserver.gameserver.datatables.CharNameTable;
|
|
|
|
+import com.l2jserver.gameserver.datatables.CharTemplateTable;
|
|
import com.l2jserver.gameserver.datatables.ClanTable;
|
|
import com.l2jserver.gameserver.datatables.ClanTable;
|
|
|
|
+import com.l2jserver.gameserver.datatables.NpcTable;
|
|
|
|
+import com.l2jserver.gameserver.instancemanager.CastleManager;
|
|
import com.l2jserver.gameserver.model.L2Clan;
|
|
import com.l2jserver.gameserver.model.L2Clan;
|
|
import com.l2jserver.gameserver.model.L2ItemInstance;
|
|
import com.l2jserver.gameserver.model.L2ItemInstance;
|
|
import com.l2jserver.gameserver.model.L2World;
|
|
import com.l2jserver.gameserver.model.L2World;
|
|
@@ -39,41 +52,37 @@ import com.l2jserver.gameserver.model.olympiad.Olympiad;
|
|
import com.l2jserver.gameserver.network.SystemMessageId;
|
|
import com.l2jserver.gameserver.network.SystemMessageId;
|
|
import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
|
|
import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
|
|
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
|
|
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
|
|
|
|
+import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
|
|
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
|
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
|
import com.l2jserver.gameserver.network.serverpackets.UserInfo;
|
|
import com.l2jserver.gameserver.network.serverpackets.UserInfo;
|
|
import com.l2jserver.gameserver.templates.StatsSet;
|
|
import com.l2jserver.gameserver.templates.StatsSet;
|
|
-
|
|
|
|
-import javolution.util.FastMap;
|
|
|
|
|
|
+import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
|
|
|
|
+import com.l2jserver.util.StringUtil;
|
|
|
|
|
|
public class Hero
|
|
public class Hero
|
|
{
|
|
{
|
|
private static Logger _log = Logger.getLogger(Hero.class.getName());
|
|
private static Logger _log = Logger.getLogger(Hero.class.getName());
|
|
|
|
|
|
- private static final String GET_HEROES = "SELECT heroes.charId, "
|
|
|
|
- + "characters.char_name, heroes.class_id, heroes.count, heroes.played "
|
|
|
|
- +"FROM heroes, characters WHERE characters.charId = heroes.charId "
|
|
|
|
- +"AND heroes.played = 1";
|
|
|
|
- private static final String GET_ALL_HEROES = "SELECT heroes.charId, "
|
|
|
|
- + "characters.char_name, heroes.class_id, heroes.count, heroes.played "
|
|
|
|
- +"FROM heroes, characters WHERE characters.charId = heroes.charId";
|
|
|
|
|
|
+ private static final String GET_HEROES = "SELECT heroes.charId, " + "characters.char_name, heroes.class_id, heroes.count, heroes.played " + "FROM heroes, characters WHERE characters.charId = heroes.charId " + "AND heroes.played = 1";
|
|
|
|
+ private static final String GET_ALL_HEROES = "SELECT heroes.charId, " + "characters.char_name, heroes.class_id, heroes.count, heroes.played " + "FROM heroes, characters WHERE characters.charId = heroes.charId";
|
|
private static final String UPDATE_ALL = "UPDATE heroes SET played = 0";
|
|
private static final String UPDATE_ALL = "UPDATE heroes SET played = 0";
|
|
private static final String INSERT_HERO = "INSERT INTO heroes VALUES (?,?,?,?)";
|
|
private static final String INSERT_HERO = "INSERT INTO heroes VALUES (?,?,?,?)";
|
|
- private static final String UPDATE_HERO = "UPDATE heroes SET count = ?, "
|
|
|
|
- +"played = ?" + " WHERE charId = ?";
|
|
|
|
- private static final String GET_CLAN_ALLY = "SELECT characters.clanid "
|
|
|
|
- +"AS clanid, coalesce(clan_data.ally_Id, 0) AS allyId FROM characters "
|
|
|
|
- +"LEFT JOIN clan_data ON clan_data.clan_id = characters.clanid "
|
|
|
|
- +"WHERE characters.charId = ?";
|
|
|
|
- private static final String GET_CLAN_NAME = "SELECT clan_name FROM clan_data "
|
|
|
|
- +"WHERE clan_id = (SELECT clanid FROM characters WHERE char_name = ?)";
|
|
|
|
|
|
+ private static final String UPDATE_HERO = "UPDATE heroes SET count = ?, " + "played = ?" + " WHERE charId = ?";
|
|
|
|
+ private static final String GET_CLAN_ALLY = "SELECT characters.clanid " + "AS clanid, coalesce(clan_data.ally_Id, 0) AS allyId FROM characters " + "LEFT JOIN clan_data ON clan_data.clan_id = characters.clanid " + "WHERE characters.charId = ?";
|
|
|
|
+ private static final String GET_CLAN_NAME = "SELECT clan_name FROM clan_data " + "WHERE clan_id = (SELECT clanid FROM characters WHERE char_name = ?)";
|
|
// delete hero items
|
|
// delete hero items
|
|
- private static final String DELETE_ITEMS = "DELETE FROM items WHERE item_id IN "
|
|
|
|
- + "(6842, 6611, 6612, 6613, 6614, 6615, 6616, 6617, 6618, 6619, 6620, 6621, 9388, 9389, 9390) "
|
|
|
|
- + "AND owner_id NOT IN (SELECT charId FROM characters WHERE accesslevel > 0)";
|
|
|
|
|
|
+ private static final String DELETE_ITEMS = "DELETE FROM items WHERE item_id IN " + "(6842, 6611, 6612, 6613, 6614, 6615, 6616, 6617, 6618, 6619, 6620, 6621, 9388, 9389, 9390) " + "AND owner_id NOT IN (SELECT charId FROM characters WHERE accesslevel > 0)";
|
|
|
|
|
|
private static Map<Integer, StatsSet> _heroes;
|
|
private static Map<Integer, StatsSet> _heroes;
|
|
private static Map<Integer, StatsSet> _completeHeroes;
|
|
private static Map<Integer, StatsSet> _completeHeroes;
|
|
|
|
|
|
|
|
+ private static Map<Integer, StatsSet> _herocounts;
|
|
|
|
+ private static Map<Integer, List<StatsSet>> _herofights;
|
|
|
|
+ private static List<StatsSet> _fights;
|
|
|
|
+
|
|
|
|
+ private static Map<Integer, List<StatsSet>> _herodiary;
|
|
|
|
+ private static List<StatsSet> _diary;
|
|
|
|
+
|
|
public static final String COUNT = "count";
|
|
public static final String COUNT = "count";
|
|
public static final String PLAYED = "played";
|
|
public static final String PLAYED = "played";
|
|
public static final String CLAN_NAME = "clan_name";
|
|
public static final String CLAN_NAME = "clan_name";
|
|
@@ -81,6 +90,10 @@ public class Hero
|
|
public static final String ALLY_NAME = "ally_name";
|
|
public static final String ALLY_NAME = "ally_name";
|
|
public static final String ALLY_CREST = "ally_crest";
|
|
public static final String ALLY_CREST = "ally_crest";
|
|
|
|
|
|
|
|
+ public static final int ACTION_RAID_KILLED = 1;
|
|
|
|
+ public static final int ACTION_HERO_GAINED = 2;
|
|
|
|
+ public static final int ACTION_CASTLE_TAKEN = 3;
|
|
|
|
+
|
|
public static Hero getInstance()
|
|
public static Hero getInstance()
|
|
{
|
|
{
|
|
return SingletonHolder._instance;
|
|
return SingletonHolder._instance;
|
|
@@ -96,6 +109,10 @@ public class Hero
|
|
_heroes = new FastMap<Integer, StatsSet>();
|
|
_heroes = new FastMap<Integer, StatsSet>();
|
|
_completeHeroes = new FastMap<Integer, StatsSet>();
|
|
_completeHeroes = new FastMap<Integer, StatsSet>();
|
|
|
|
|
|
|
|
+ _herofights = new FastMap<Integer, List<StatsSet>>();
|
|
|
|
+ _herocounts = new FastMap<Integer, StatsSet>();
|
|
|
|
+ _herodiary = new FastMap<Integer, List<StatsSet>>();
|
|
|
|
+
|
|
Connection con = null;
|
|
Connection con = null;
|
|
Connection con2 = null;
|
|
Connection con2 = null;
|
|
|
|
|
|
@@ -121,6 +138,9 @@ public class Hero
|
|
hero.set(COUNT, rset.getInt(COUNT));
|
|
hero.set(COUNT, rset.getInt(COUNT));
|
|
hero.set(PLAYED, rset.getInt(PLAYED));
|
|
hero.set(PLAYED, rset.getInt(PLAYED));
|
|
|
|
|
|
|
|
+ loadFights(charId);
|
|
|
|
+ loadDiary(charId);
|
|
|
|
+
|
|
statement2 = con2.prepareStatement(GET_CLAN_ALLY);
|
|
statement2 = con2.prepareStatement(GET_CLAN_ALLY);
|
|
statement2.setInt(1, charId);
|
|
statement2.setInt(1, charId);
|
|
rset2 = statement2.executeQuery();
|
|
rset2 = statement2.executeQuery();
|
|
@@ -219,7 +239,9 @@ public class Hero
|
|
{
|
|
{
|
|
_log.warning("Hero System: Couldnt load Heroes");
|
|
_log.warning("Hero System: Couldnt load Heroes");
|
|
if (Config.DEBUG)
|
|
if (Config.DEBUG)
|
|
|
|
+ {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
finally
|
|
finally
|
|
{
|
|
{
|
|
@@ -237,11 +259,438 @@ public class Hero
|
|
_log.info("Hero System: Loaded " + _completeHeroes.size() + " all time Heroes.");
|
|
_log.info("Hero System: Loaded " + _completeHeroes.size() + " all time Heroes.");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private String calcFightTime(long FightTime)
|
|
|
|
+ {
|
|
|
|
+ String format = String.format("%%0%dd", 2);
|
|
|
|
+ FightTime = FightTime / 1000;
|
|
|
|
+ String seconds = String.format(format, FightTime % 60);
|
|
|
|
+ String minutes = String.format(format, (FightTime % 3600) / 60);
|
|
|
|
+ String time = minutes + ":" + seconds;
|
|
|
|
+ return time;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void loadDiary(int charId)
|
|
|
|
+ {
|
|
|
|
+ _diary = new FastList<StatsSet>();
|
|
|
|
+
|
|
|
|
+ int diaryentries = 0;
|
|
|
|
+ Connection con = null;
|
|
|
|
+ PreparedStatement statement;
|
|
|
|
+ ResultSet rset;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
|
+ statement = con.prepareStatement("SELECT * FROM heroes_diary WHERE charId=? ORDER BY time ASC");
|
|
|
|
+ statement.setInt(1, charId);
|
|
|
|
+ rset = statement.executeQuery();
|
|
|
|
+
|
|
|
|
+ while (rset.next())
|
|
|
|
+ {
|
|
|
|
+ StatsSet _diaryentry = new StatsSet();
|
|
|
|
+
|
|
|
|
+ long time = rset.getLong("time");
|
|
|
|
+ int action = rset.getInt("action");
|
|
|
|
+ int param = rset.getInt("param");
|
|
|
|
+
|
|
|
|
+ String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(time));
|
|
|
|
+ _diaryentry.set("date", date);
|
|
|
|
+
|
|
|
|
+ if (action == ACTION_RAID_KILLED)
|
|
|
|
+ {
|
|
|
|
+ L2NpcTemplate template = NpcTable.getInstance().getTemplate(param);
|
|
|
|
+ if (template != null)
|
|
|
|
+ {
|
|
|
|
+ _diaryentry.set("action", template.getName() + " was defeated");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if (action == ACTION_HERO_GAINED)
|
|
|
|
+ {
|
|
|
|
+ _diaryentry.set("action", "Gained Hero status");
|
|
|
|
+ }
|
|
|
|
+ else if (action == ACTION_CASTLE_TAKEN)
|
|
|
|
+ {
|
|
|
|
+ Castle castle = CastleManager.getInstance().getCastleById(param);
|
|
|
|
+ if(castle != null)
|
|
|
|
+ {
|
|
|
|
+ _diaryentry.set("action", castle.getName()+" Castle was successfuly taken");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ _diary.add(_diaryentry);
|
|
|
|
+ diaryentries++;
|
|
|
|
+ }
|
|
|
|
+ rset.close();
|
|
|
|
+ statement.close();
|
|
|
|
+
|
|
|
|
+ _herodiary.put(charId, _diary);
|
|
|
|
+
|
|
|
|
+ _log.info("Hero System: Loaded " + diaryentries + " diary entries for Hero: " + CharNameTable.getInstance().getNameById(charId));
|
|
|
|
+ }
|
|
|
|
+ catch (SQLException e)
|
|
|
|
+ {
|
|
|
|
+ _log.warning("Hero System: Couldnt load Hero Diary for CharId: " + charId);
|
|
|
|
+ if (Config.DEBUG)
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ finally
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ con.close();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void loadFights(int charId)
|
|
|
|
+ {
|
|
|
|
+ _fights = new FastList<StatsSet>();
|
|
|
|
+
|
|
|
|
+ StatsSet _herocountdata = new StatsSet();
|
|
|
|
+
|
|
|
|
+ Calendar _data = Calendar.getInstance();
|
|
|
|
+ _data.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
+ _data.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
+ _data.set(Calendar.MINUTE, 0);
|
|
|
|
+ _data.set(Calendar.MILLISECOND, 0);
|
|
|
|
+
|
|
|
|
+ long from = _data.getTimeInMillis();
|
|
|
|
+ int numberoffights = 0;
|
|
|
|
+ int _victorys = 0;
|
|
|
|
+ int _losses = 0;
|
|
|
|
+ int _draws = 0;
|
|
|
|
+
|
|
|
|
+ Connection con = null;
|
|
|
|
+ PreparedStatement statement;
|
|
|
|
+ ResultSet rset;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
|
+ statement = con.prepareStatement("SELECT * FROM olympiad_fights WHERE (charOneId=? OR charTwoId=?) AND start<? ORDER BY start ASC");
|
|
|
|
+ statement.setInt(1, charId);
|
|
|
|
+ statement.setInt(2, charId);
|
|
|
|
+ statement.setLong(3, from);
|
|
|
|
+ rset = statement.executeQuery();
|
|
|
|
+
|
|
|
|
+ while (rset.next())
|
|
|
|
+ {
|
|
|
|
+ int charOneId = rset.getInt("charOneId");
|
|
|
|
+ int charOneClass = rset.getInt("charOneClass");
|
|
|
|
+ int charTwoId = rset.getInt("charTwoId");
|
|
|
|
+ int charTwoClass = rset.getInt("charTwoClass");
|
|
|
|
+ int winner = rset.getInt("winner");
|
|
|
|
+ long start = rset.getLong("start");
|
|
|
|
+ int time = rset.getInt("time");
|
|
|
|
+ int classed = rset.getInt("classed");
|
|
|
|
+
|
|
|
|
+ if (charId == charOneId)
|
|
|
|
+ {
|
|
|
|
+ String name = CharNameTable.getInstance().getNameById(charTwoId);
|
|
|
|
+ String cls = CharTemplateTable.getInstance().getClassNameById(charTwoClass);
|
|
|
|
+ if(name != null && cls != null)
|
|
|
|
+ {
|
|
|
|
+ StatsSet fight = new StatsSet();
|
|
|
|
+ fight.set("oponent", name);
|
|
|
|
+ fight.set("oponentclass", cls);
|
|
|
|
+
|
|
|
|
+ fight.set("time", calcFightTime(time));
|
|
|
|
+ String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
|
|
|
|
+ fight.set("start", date);
|
|
|
|
+
|
|
|
|
+ fight.set("classed", classed);
|
|
|
|
+ if (winner == 1)
|
|
|
|
+ {
|
|
|
|
+ fight.set("result", "<font color=\"00ff00\">victory</font>");
|
|
|
|
+ _victorys++;
|
|
|
|
+ }
|
|
|
|
+ else if (winner == 2)
|
|
|
|
+ {
|
|
|
|
+ fight.set("result", "<font color=\"ff0000\">loss</font>");
|
|
|
|
+ _losses++;
|
|
|
|
+ }
|
|
|
|
+ else if (winner == 0)
|
|
|
|
+ {
|
|
|
|
+ fight.set("result", "<font color=\"ffff00\">draw</font>");
|
|
|
|
+ _draws++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _fights.add(fight);
|
|
|
|
+
|
|
|
|
+ numberoffights++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if (charId == charTwoId)
|
|
|
|
+ {
|
|
|
|
+ String name = CharNameTable.getInstance().getNameById(charOneId);
|
|
|
|
+ String cls = CharTemplateTable.getInstance().getClassNameById(charOneClass);
|
|
|
|
+ if(name != null && cls != null)
|
|
|
|
+ {
|
|
|
|
+ StatsSet fight = new StatsSet();
|
|
|
|
+ fight.set("oponent", name);
|
|
|
|
+ fight.set("oponentclass", cls);
|
|
|
|
+
|
|
|
|
+ fight.set("time", calcFightTime(time));
|
|
|
|
+ String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
|
|
|
|
+ fight.set("start", date);
|
|
|
|
+
|
|
|
|
+ fight.set("classed", classed);
|
|
|
|
+ if (winner == 1)
|
|
|
|
+ {
|
|
|
|
+ fight.set("result", "<font color=\"ff0000\">loss</font>");
|
|
|
|
+ _losses++;
|
|
|
|
+ }
|
|
|
|
+ else if (winner == 2)
|
|
|
|
+ {
|
|
|
|
+ fight.set("result", "<font color=\"00ff00\">victory</font>");
|
|
|
|
+ _victorys++;
|
|
|
|
+ }
|
|
|
|
+ else if (winner == 0)
|
|
|
|
+ {
|
|
|
|
+ fight.set("result", "<font color=\"ffff00\">draw</font>");
|
|
|
|
+ _draws++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _fights.add(fight);
|
|
|
|
+
|
|
|
|
+ numberoffights++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rset.close();
|
|
|
|
+ statement.close();
|
|
|
|
+
|
|
|
|
+ _herocountdata.set("victory", _victorys);
|
|
|
|
+ _herocountdata.set("draw", _draws);
|
|
|
|
+ _herocountdata.set("loss", _losses);
|
|
|
|
+
|
|
|
|
+ _herocounts.put(charId, _herocountdata);
|
|
|
|
+ _herofights.put(charId, _fights);
|
|
|
|
+
|
|
|
|
+ _log.info("Hero System: Loaded " + numberoffights + " fights for Hero: " + CharNameTable.getInstance().getNameById(charId));
|
|
|
|
+ }
|
|
|
|
+ catch (SQLException e)
|
|
|
|
+ {
|
|
|
|
+ _log.warning("Hero System: Couldnt load Hero fights history for CharId: " + charId);
|
|
|
|
+ if (Config.DEBUG)
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ finally
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ con.close();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public Map<Integer, StatsSet> getHeroes()
|
|
public Map<Integer, StatsSet> getHeroes()
|
|
{
|
|
{
|
|
return _heroes;
|
|
return _heroes;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public int getHeroByClass(int classid)
|
|
|
|
+ {
|
|
|
|
+ if (!_heroes.isEmpty())
|
|
|
|
+ {
|
|
|
|
+ for (Integer heroId : _heroes.keySet())
|
|
|
|
+ {
|
|
|
|
+ StatsSet hero = _heroes.get(heroId);
|
|
|
|
+ if (hero.getInteger(Olympiad.CLASS_ID) == classid)
|
|
|
|
+ {
|
|
|
|
+ return heroId;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void resetData()
|
|
|
|
+ {
|
|
|
|
+ _herodiary.clear();
|
|
|
|
+ _herofights.clear();
|
|
|
|
+ _herocounts.clear();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void showHeroDiary(L2PcInstance activeChar, int heroclass, int charid, int page)
|
|
|
|
+ {
|
|
|
|
+ final int perpage = 10;
|
|
|
|
+
|
|
|
|
+ if (_herodiary.containsKey(charid))
|
|
|
|
+ {
|
|
|
|
+ List<StatsSet> _mainlist = _herodiary.get(charid);
|
|
|
|
+ NpcHtmlMessage DiaryReply = new NpcHtmlMessage(5);
|
|
|
|
+ final String htmContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(),"data/html/olympiad/herodiary.htm");
|
|
|
|
+ if (htmContent != null)
|
|
|
|
+ {
|
|
|
|
+ DiaryReply.setHtml(htmContent);
|
|
|
|
+ DiaryReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));
|
|
|
|
+
|
|
|
|
+ if (!_mainlist.isEmpty())
|
|
|
|
+ {
|
|
|
|
+ FastList<StatsSet> _list = FastList.newInstance();
|
|
|
|
+ _list.addAll(_mainlist);
|
|
|
|
+ Collections.reverse(_list);
|
|
|
|
+
|
|
|
|
+ boolean color = true;
|
|
|
|
+ final StringBuilder fList = new StringBuilder(500);
|
|
|
|
+ int counter = 0;
|
|
|
|
+ int breakat = 0;
|
|
|
|
+ for (int i = ((page - 1) * perpage); i < _list.size(); i++)
|
|
|
|
+ {
|
|
|
|
+ breakat = i;
|
|
|
|
+ StatsSet _diaryentry = _list.get(i);
|
|
|
|
+ StringUtil.append(fList, "<tr><td>");
|
|
|
|
+ if (color)
|
|
|
|
+ {
|
|
|
|
+ StringUtil.append(fList, "<table width=270 bgcolor=\"131210\">");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ StringUtil.append(fList, "<table width=270>");
|
|
|
|
+ }
|
|
|
|
+ StringUtil.append(fList, "<tr><td width=270><font color=\"LEVEL\">" + _diaryentry.getString("date") + ":xx</font></td></tr>");
|
|
|
|
+ StringUtil.append(fList, "<tr><td width=270>" + _diaryentry.getString("action") + "</td></tr>");
|
|
|
|
+ StringUtil.append(fList, "<tr><td> </td></tr></table>");
|
|
|
|
+ StringUtil.append(fList, "</td></tr>");
|
|
|
|
+ color = !color;
|
|
|
|
+ counter++;
|
|
|
|
+ if (counter >= perpage)
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (breakat < (_list.size() - 1))
|
|
|
|
+ {
|
|
|
|
+ DiaryReply.replace("%buttprev%", "<button value=\"Prev\" action=\"bypass _diary?class=" + heroclass + "&page=" + (page + 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ DiaryReply.replace("%buttprev%", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (page > 1)
|
|
|
|
+ {
|
|
|
|
+ DiaryReply.replace("%buttnext%", "<button value=\"Next\" action=\"bypass _diary?class=" + heroclass + "&page=" + (page - 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ DiaryReply.replace("%buttnext%", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DiaryReply.replace("%list%", fList.toString());
|
|
|
|
+
|
|
|
|
+ FastList.recycle(_list);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ DiaryReply.replace("%list%", "");
|
|
|
|
+ DiaryReply.replace("%buttprev%", "");
|
|
|
|
+ DiaryReply.replace("%buttnext%", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ activeChar.sendPacket(DiaryReply);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void showHeroFights(L2PcInstance activeChar, int heroclass, int charid, int page)
|
|
|
|
+ {
|
|
|
|
+ final int perpage = 20;
|
|
|
|
+ int _win = 0;
|
|
|
|
+ int _loss = 0;
|
|
|
|
+ int _draw = 0;
|
|
|
|
+
|
|
|
|
+ if (_herofights.containsKey(charid))
|
|
|
|
+ {
|
|
|
|
+ List<StatsSet> _list = _herofights.get(charid);
|
|
|
|
+
|
|
|
|
+ NpcHtmlMessage FightReply = new NpcHtmlMessage(5);
|
|
|
|
+ final String htmContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(),"data/html/olympiad/herohistory.htm");
|
|
|
|
+ if (htmContent != null)
|
|
|
|
+ {
|
|
|
|
+ FightReply.setHtml(htmContent);
|
|
|
|
+ FightReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));
|
|
|
|
+
|
|
|
|
+ if (!_list.isEmpty())
|
|
|
|
+ {
|
|
|
|
+ if (_herocounts.containsKey(charid))
|
|
|
|
+ {
|
|
|
|
+ StatsSet _herocount = _herocounts.get(charid);
|
|
|
|
+ _win = _herocount.getInteger("victory");
|
|
|
|
+ _loss = _herocount.getInteger("loss");
|
|
|
|
+ _draw = _herocount.getInteger("draw");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ boolean color = true;
|
|
|
|
+ final StringBuilder fList = new StringBuilder(500);
|
|
|
|
+ int counter = 0;
|
|
|
|
+ int breakat = 0;
|
|
|
|
+ for (int i = ((page - 1) * perpage); i < _list.size(); i++)
|
|
|
|
+ {
|
|
|
|
+ breakat = i;
|
|
|
|
+ StatsSet fight = _list.get(i);
|
|
|
|
+ StringUtil.append(fList, "<tr><td>");
|
|
|
|
+ if (color)
|
|
|
|
+ {
|
|
|
|
+ StringUtil.append(fList, "<table width=270 bgcolor=\"131210\">");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ StringUtil.append(fList, "<table width=270>");
|
|
|
|
+ }
|
|
|
|
+ StringUtil.append(fList, "<tr><td width=220><font color=\"LEVEL\">" + fight.getString("start") + "</font> " + fight.getString("result") + "</td><td width=50 align=right>" + (fight.getInteger("classed") > 0 ? "<font color=\"FFFF99\">cls</font>" : "<font color=\"999999\">non-cls<font>") + "</td></tr>");
|
|
|
|
+ StringUtil.append(fList, "<tr><td width=220>vs " + fight.getString("oponent") + " (" + fight.getString("oponentclass") + ")</td><td width=50 align=right>(" + fight.getString("time") + ")</td></tr>");
|
|
|
|
+ StringUtil.append(fList, "<tr><td colspan=2> </td></tr></table>");
|
|
|
|
+ StringUtil.append(fList, "</td></tr>");
|
|
|
|
+ color = !color;
|
|
|
|
+ counter++;
|
|
|
|
+ if (counter >= perpage)
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (breakat < (_list.size() - 1))
|
|
|
|
+ {
|
|
|
|
+ FightReply.replace("%buttprev%", "<button value=\"Prev\" action=\"bypass _match?class=" + heroclass + "&page=" + (page + 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ FightReply.replace("%buttprev%", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (page > 1)
|
|
|
|
+ {
|
|
|
|
+ FightReply.replace("%buttnext%", "<button value=\"Next\" action=\"bypass _match?class=" + heroclass + "&page=" + (page - 1) + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ FightReply.replace("%buttnext%", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FightReply.replace("%list%", fList.toString());
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ FightReply.replace("%list%", "");
|
|
|
|
+ FightReply.replace("%buttprev%", "");
|
|
|
|
+ FightReply.replace("%buttnext%", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FightReply.replace("%win%", String.valueOf(_win));
|
|
|
|
+ FightReply.replace("%draw%", String.valueOf(_draw));
|
|
|
|
+ FightReply.replace("%loos%", String.valueOf(_loss));
|
|
|
|
+
|
|
|
|
+ activeChar.sendPacket(FightReply);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public synchronized void computeNewHeroes(List<StatsSet> newHeroes)
|
|
public synchronized void computeNewHeroes(List<StatsSet> newHeroes)
|
|
{
|
|
{
|
|
updateHeroes(true);
|
|
updateHeroes(true);
|
|
@@ -255,7 +704,9 @@ public class Hero
|
|
L2PcInstance player = L2World.getInstance().getPlayer(name);
|
|
L2PcInstance player = L2World.getInstance().getPlayer(name);
|
|
|
|
|
|
if (player == null)
|
|
if (player == null)
|
|
|
|
+ {
|
|
continue;
|
|
continue;
|
|
|
|
+ }
|
|
try
|
|
try
|
|
{
|
|
{
|
|
player.setHero(false);
|
|
player.setHero(false);
|
|
@@ -263,13 +714,15 @@ public class Hero
|
|
for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++)
|
|
for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++)
|
|
{
|
|
{
|
|
L2ItemInstance equippedItem = player.getInventory().getPaperdollItem(i);
|
|
L2ItemInstance equippedItem = player.getInventory().getPaperdollItem(i);
|
|
- if (equippedItem != null && equippedItem.isHeroItem())
|
|
|
|
|
|
+ if ((equippedItem != null) && equippedItem.isHeroItem())
|
|
|
|
+ {
|
|
player.getInventory().unEquipItemInSlotAndRecord(i);
|
|
player.getInventory().unEquipItemInSlotAndRecord(i);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
for (L2ItemInstance item : player.getInventory().getAvailableItems(false, false))
|
|
for (L2ItemInstance item : player.getInventory().getAvailableItems(false, false))
|
|
{
|
|
{
|
|
- if (item != null && item.isHeroItem())
|
|
|
|
|
|
+ if ((item != null) && item.isHeroItem())
|
|
{
|
|
{
|
|
player.destroyItem("Hero", item, null, true);
|
|
player.destroyItem("Hero", item, null, true);
|
|
InventoryUpdate iu = new InventoryUpdate();
|
|
InventoryUpdate iu = new InventoryUpdate();
|
|
@@ -298,7 +751,7 @@ public class Hero
|
|
{
|
|
{
|
|
int charId = hero.getInteger(Olympiad.CHAR_ID);
|
|
int charId = hero.getInteger(Olympiad.CHAR_ID);
|
|
|
|
|
|
- if (_completeHeroes != null && _completeHeroes.containsKey(charId))
|
|
|
|
|
|
+ if ((_completeHeroes != null) && _completeHeroes.containsKey(charId))
|
|
{
|
|
{
|
|
StatsSet oldHero = _completeHeroes.get(charId);
|
|
StatsSet oldHero = _completeHeroes.get(charId);
|
|
int count = oldHero.getInteger(COUNT);
|
|
int count = oldHero.getInteger(COUNT);
|
|
@@ -323,13 +776,17 @@ public class Hero
|
|
|
|
|
|
_heroes.clear();
|
|
_heroes.clear();
|
|
_heroes.putAll(heroes);
|
|
_heroes.putAll(heroes);
|
|
|
|
+
|
|
heroes.clear();
|
|
heroes.clear();
|
|
|
|
|
|
updateHeroes(false);
|
|
updateHeroes(false);
|
|
|
|
|
|
- for (StatsSet hero : _heroes.values())
|
|
|
|
|
|
+ for(Integer charid : _heroes.keySet())
|
|
{
|
|
{
|
|
- String name = hero.getString(Olympiad.CHAR_NAME);
|
|
|
|
|
|
+ StatsSet hero = _heroes.get(charid);
|
|
|
|
+ String name = hero.getString(Olympiad.CHAR_NAME);
|
|
|
|
+ // String name = hero.getString(Olympiad.CHAR_NAME);
|
|
|
|
+ // int charid = hero.getInteger(Olympiad.CHAR_ID);
|
|
|
|
|
|
L2PcInstance player = L2World.getInstance().getPlayer(name);
|
|
L2PcInstance player = L2World.getInstance().getPlayer(name);
|
|
|
|
|
|
@@ -349,9 +806,18 @@ public class Hero
|
|
player.sendPacket(new ExBrExtraUserInfo(player));
|
|
player.sendPacket(new ExBrExtraUserInfo(player));
|
|
player.broadcastUserInfo();
|
|
player.broadcastUserInfo();
|
|
|
|
|
|
|
|
+ // Set Gained hero and reload data
|
|
|
|
+ setHeroGained(player.getCharId());
|
|
|
|
+ loadFights(player.getCharId());
|
|
|
|
+ loadDiary(player.getCharId());
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+ // Set Gained hero and reload data
|
|
|
|
+ setHeroGained(charid);
|
|
|
|
+ loadFights(charid);
|
|
|
|
+ loadDiary(charid);
|
|
|
|
+
|
|
Connection con = null;
|
|
Connection con = null;
|
|
|
|
|
|
try
|
|
try
|
|
@@ -400,6 +866,9 @@ public class Hero
|
|
|
|
|
|
public void updateHeroes(boolean setDefault)
|
|
public void updateHeroes(boolean setDefault)
|
|
{
|
|
{
|
|
|
|
+ //_herofights = new FastMap<Integer, List<StatsSet>>();
|
|
|
|
+ //_herocounts = new FastMap<Integer, StatsSet>();
|
|
|
|
+
|
|
Connection con = null;
|
|
Connection con = null;
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -418,7 +887,7 @@ public class Hero
|
|
{
|
|
{
|
|
StatsSet hero = _heroes.get(heroId);
|
|
StatsSet hero = _heroes.get(heroId);
|
|
|
|
|
|
- if (_completeHeroes == null || !_completeHeroes.containsKey(heroId))
|
|
|
|
|
|
+ if ((_completeHeroes == null) || !_completeHeroes.containsKey(heroId))
|
|
{
|
|
{
|
|
statement = con.prepareStatement(INSERT_HERO);
|
|
statement = con.prepareStatement(INSERT_HERO);
|
|
statement.setInt(1, heroId);
|
|
statement.setInt(1, heroId);
|
|
@@ -486,7 +955,9 @@ public class Hero
|
|
{
|
|
{
|
|
_log.warning("Hero System: Couldnt update Heroes");
|
|
_log.warning("Hero System: Couldnt update Heroes");
|
|
if (Config.DEBUG)
|
|
if (Config.DEBUG)
|
|
|
|
+ {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
finally
|
|
finally
|
|
{
|
|
{
|
|
@@ -501,6 +972,92 @@ public class Hero
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void setHeroGained(int charId)
|
|
|
|
+ {
|
|
|
|
+ setDiaryData(charId, ACTION_HERO_GAINED, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setRBkilled(int charId, int npcId)
|
|
|
|
+ {
|
|
|
|
+ setDiaryData(charId, ACTION_RAID_KILLED, npcId);
|
|
|
|
+
|
|
|
|
+ L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
|
|
|
|
+
|
|
|
|
+ if (_herodiary.containsKey(charId) && (template != null))
|
|
|
|
+ {
|
|
|
|
+ // Get Data
|
|
|
|
+ List<StatsSet> _list = _herodiary.get(charId);
|
|
|
|
+ // Clear old data
|
|
|
|
+ _herodiary.remove(charId);
|
|
|
|
+ // Prepare new data
|
|
|
|
+ StatsSet _diaryentry = new StatsSet();
|
|
|
|
+ String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
|
|
|
|
+ _diaryentry.set("date", date);
|
|
|
|
+ _diaryentry.set("action", template.getName() + " was defeated");
|
|
|
|
+ // Add to old list
|
|
|
|
+ _list.add(_diaryentry);
|
|
|
|
+ // Put new list into diary
|
|
|
|
+ _herodiary.put(charId, _list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setCastleTaken(int charId, int castleId)
|
|
|
|
+ {
|
|
|
|
+ setDiaryData(charId, ACTION_CASTLE_TAKEN, castleId);
|
|
|
|
+
|
|
|
|
+ Castle castle = CastleManager.getInstance().getCastleById(castleId);
|
|
|
|
+
|
|
|
|
+ if (_herodiary.containsKey(charId) && (castle != null))
|
|
|
|
+ {
|
|
|
|
+ // Get Data
|
|
|
|
+ List<StatsSet> _list = _herodiary.get(charId);
|
|
|
|
+ // Clear old data
|
|
|
|
+ _herodiary.remove(charId);
|
|
|
|
+ // Prepare new data
|
|
|
|
+ StatsSet _diaryentry = new StatsSet();
|
|
|
|
+ String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
|
|
|
|
+ _diaryentry.set("date", date);
|
|
|
|
+ _diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
|
|
|
|
+ // Add to old list
|
|
|
|
+ _list.add(_diaryentry);
|
|
|
|
+ // Put new list into diary
|
|
|
|
+ _herodiary.put(charId, _list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setDiaryData(int charId, int action, int param)
|
|
|
|
+ {
|
|
|
|
+ Connection con = null;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
|
+ PreparedStatement statement = con.prepareStatement("INSERT INTO heroes_diary (charId, time, action, param) values(?,?,?,?)");
|
|
|
|
+ statement.setInt(1, charId);
|
|
|
|
+ statement.setLong(2, System.currentTimeMillis());
|
|
|
|
+ statement.setInt(3, action);
|
|
|
|
+ statement.setInt(4, param);
|
|
|
|
+ statement.execute();
|
|
|
|
+ statement.close();
|
|
|
|
+ }
|
|
|
|
+ catch (SQLException e)
|
|
|
|
+ {
|
|
|
|
+ if (_log.isLoggable(Level.SEVERE))
|
|
|
|
+ {
|
|
|
|
+ _log.log(Level.SEVERE, "SQL exception while saving DiaryData.", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ finally
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ con.close();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void deleteItemsInDb()
|
|
private void deleteItemsInDb()
|
|
{
|
|
{
|
|
Connection con = null;
|
|
Connection con = null;
|