Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Faction System for aCis requested by Paranoic and Ipotonic
- At net.sf.l2j.gameserver.model.L2World find:
- private final Map<Integer, L2PcInstance> _players = new ConcurrentHashMap<>();
- Add bellow:
- private final Map<String, L2PcInstance> _evils = new ConcurrentHashMap<>();
- private final Map<String, L2PcInstance> _goods = new ConcurrentHashMap<>();
- Find:
- public Collection<L2Object> getObjects()
- {
- return _objects.values();
- }
- Add bellow:
- public Collection<L2PcInstance> getAllgoodPlayers()
- {
- return _goods.values();
- }
- public Collection<L2PcInstance> getAllevilPlayers()
- {
- return _evils.values();
- }
- public int getAllgoodPlayersCount()
- {
- return _goods.size();
- }
- public int getAllevilPlayersCount()
- {
- return _evils.size();
- }
- Find:
- public void addPlayer(L2PcInstance cha)
- {
- _players.putIfAbsent(cha.getObjectId(), cha);
- }
- Change to:
- public void addPlayer(L2PcInstance cha)
- {
- if (Config.FACTION.ENABLED)
- {
- if (cha.isEvil())
- {
- _evils.putIfAbsent(cha.getName().toLowerCase(), cha);
- }
- _goods.putIfAbsent(cha.getName().toLowerCase(), cha);
- }
- _players.putIfAbsent(cha.getObjectId(), cha);
- }
- Go at net.sf.l2j.gameserver.model.actor.instance.L2PcInstance
- find:
- private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=? WHERE obj_id=?";
- Change to:
- private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=?,evil=?,good=? WHERE obj_id=?";
- find:
- private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level FROM characters WHERE obj_id=?";
- change to:
- private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,evil,good FROM characters WHERE obj_id=?";
- find:
- private boolean _hero = false;
- add bellow:
- private boolean _isgood = false;
- private boolean _isevil = false;
- find:
- public void updatePvPFlag(int value)
- add bellow:
- if (isgood() || isevil())
- return;
- find:
- player.setNoble(rset.getInt("nobless") == 1, false);
- add bellow:
- player.setGood((rset.getInt("good") == 1) ? true : false);
- player.setEvil((rset.getInt("evil") == 1) ? true : false);
- find:
- statement.setLong(49, getDeathPenaltyBuffLevel());
- change to:
- statement.setInt(50, isGood() ? 1 : 0);
- statement.setInt(51, isEvil() ? 1 : 0);
- statement.setInt(52, getObjectId());
- find:
- public void doAttack(L2Character target)
- add bellow:
- if (Config.FACTION_ENABLE_FACTION)
- {
- if (this instanceof L2PcInstance && target instanceof L2PcInstance)
- {
- if (isEvil() && target.getActingPlayer().isGood())
- return;
- if (isGood() && target.getActingPlayer().isEvil())
- return;
- }
- }
- find:
- public void doCast(L2Skill skill)
- add bellow:
- if (Config.FACTION_ENABLE)
- {
- L2Object target = getActingPlayer().getTarget();
- if (target !=null && target instanceof L2PcInstance)
- {
- if (getActingPlayer().isEvil() && target.isEvil() && skill.isOffensive())
- {
- return;
- }
- if (getActingPlayer().isGood() && target.isGood() && skill.isOffensive())
- {
- return;
- }
- }
- }
- Somewhere add:
- public boolean isGood()
- {
- return _isgood;
- }
- public boolean isEvil()
- {
- return _isevil;
- }
- public void setGood(boolean value)
- {
- _isgood = value;
- }
- public void setEvil(boolean value)
- {
- _isevil = value;
- }
- At Config.java
- Add somewhere the variables:
- public static boolean FACTION_ENABLE_FACTION;
- public static int PRIMAR_X;
- public static int PRIMAR_Y;
- public static int PRIMAR_Z;
- public static int GOODX;
- public static int GOODY;
- public static int GOODZ;
- public static int EVILX;
- public static int EVILY;
- public static int EVILZ;
- public static String FACTION_NAME_TEAM_GOOD;
- public static String FACTION_NAME_TEAM_EVIL;
- public static int FACTION_COLOR_NAME_GOOD;
- public static int FACTION_COLOR_NAME_EVIL;
- Find:
- STARTING_ADENA = players.getProperty("StartingAdena", 100);
- Add bellow:
- FACTION_ENABLE_FACTION = players.getProperty("EnableFaction", false);
- PRIMAR_X = players.getProperty("PrimarBaseX", 139990);
- PRIMAR_Y = players.getProperty("PrimarBaseY", -124423);
- PRIMAR_Z = players.getProperty("PrimarBaseZ", -1903);
- GOODX = players.getProperty("GoodBaseX", -84318);
- GOODY = players.getProperty("GoodBaseY", 244579);
- GOODZ = players.getProperty("GoodBaseZ", -3730);
- EVILX = players.getProperty("EvilBaseX", -44836);
- EVILY = players.getProperty("EvilBaseY", -112524);
- EVILZ = players.getProperty("EvilBaseZ", -235);
- FACTION_NAME_TEAM_GOOD = players.getProperty("NameTeamGood", "Angels");
- FACTION_NAME_TEAM_EVIL = players.getProperty("NameTeamEvil", "Demons");
- FACTION_COLOR_NAME_GOOD = Integer.decode("0x" + players.getProperty("ColorNameGood", "00FF00"));
- FACTION_COLOR_NAME_EVIL = Integer.decode("0x" + players.getProperty("ColorNameEvil", "00FF00"));
- At CharacterCreate.java
- Add:
- if (Config.FACTION_ENABLE_FACTION)
- {
- newChar.setXYZ(Config.PRIMAR_X, Config.PRIMAR_Y, Config.PRIMAR_Z);
- }
- At instances create a new class with name L2FactionInstance
- and add this code:
- package net.sf.l2j;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.StringTokenizer;
- import java.util.logging.Logger;
- import net.sf.l2j.commons.random.Rnd;
- import net.sf.l2j.gameserver.ai.CtrlIntention;
- import net.sf.l2j.gameserver.model.L2World;
- import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
- import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.network.serverpackets.MyTargetSelected;
- import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
- import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;
- public class L2FactionInstance extends L2NpcInstance
- {
- public L2FactionInstance(int objectId, NpcTemplate template)
- {
- super(objectId, template);
- }
- private final static Logger _log = Logger.getLogger(L2FactionInstance.class.getName());
- @Override
- public void onBypassFeedback(L2PcInstance player, String command)
- {
- player.sendPacket(ActionFailed.STATIC_PACKET);
- StringTokenizer st = new StringTokenizer(command, " ");
- String actualCommand = st.nextToken();
- @SuppressWarnings("unused")
- String val = "";
- if (st.countTokens() >= 1)
- {
- val = st.nextToken();
- }
- else if (actualCommand.equalsIgnoreCase("setgood"))
- {
- setTarget(player);
- if (player.isGood())
- {
- player.sendMessage("You already are in " + Config.FACTION_NAME_TEAM_GOOD + " faction ");
- player.sendPacket(new ActionFailed());
- }
- else
- {
- if (player.isEvil())
- {
- player.sendMessage("You cant change faction.");
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else
- {
- int getevils = L2World.getInstance().getAllevilPlayers().size();
- int getgoods = L2World.getInstance().getAllgoodPlayers().size();
- if (getgoods > getevils)
- {
- player.sendMessage("You Cant Use " + Config.FACTION_NAME_TEAM_GOOD + " Faction because Online number of " + Config.FACTION_NAME_TEAM_EVIL + " is smaller.");
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else
- {
- player.setGood(true);
- Connection connection = null;
- try
- {
- connection = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement = connection.prepareStatement("SELECT obj_Id FROM characters where char_name=?");
- statement.setString(1, player.getName());
- ResultSet rset = statement.executeQuery();
- int objId = 0;
- if (rset.next())
- {
- objId = rset.getInt(1);
- }
- rset.close();
- statement.close();
- if (objId == 0)
- {
- connection.close();
- return;
- }
- statement = connection.prepareStatement("UPDATE characters SET good=1 WHERE obj_Id=?");
- statement.setInt(1, objId);
- statement.execute();
- statement.close();
- connection.close();
- }
- catch (Exception e)
- {
- _log.info("could not set good status of char:");
- }
- finally
- {
- try
- {
- connection.close();
- }
- catch (Exception e)
- {
- }
- }
- if (player.isGood())
- {
- player.broadcastUserInfo();
- player.sendMessage("You Are fighiting Now for" + Config.FACTION_NAME_TEAM_GOOD + " Faction ");
- player.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_GOOD);
- player.teleToLocation(Config.GOODX, Config.GOODY, Config.GOODZ);
- player.setTitle(Config.FACTION_NAME_TEAM_GOOD);
- }
- }
- }
- }
- }
- else if (actualCommand.equalsIgnoreCase("setevil"))
- {
- setTarget(player);
- if (player.isEvil())
- {
- player.sendMessage("You already are in " + Config.FACTION_NAME_TEAM_EVIL + " faction ");
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else
- {
- if (player.isGood())
- {
- player.sendMessage("You Cant Change Faction.");
- player.sendPacket(new ActionFailed());
- }
- else
- {
- int getevils = L2World.getInstance().getAllevilPlayers().size();
- int getgoods = L2World.getInstance().getAllgoodPlayers().size();
- if (getevils > getgoods)
- {
- player.sendMessage("You Cant Use " + Config.FACTION_NAME_TEAM_EVIL + " Faction because Online number of " + Config.FACTION_NAME_TEAM_EVIL + " is smaller.");
- player.sendPacket(new ActionFailed());
- }
- else
- {
- player.setEvil(true);
- Connection connection = null;
- try
- {
- connection = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement = connection.prepareStatement("SELECT obj_Id FROM characters where char_name=?");
- statement.setString(1, player.getName());
- ResultSet rset = statement.executeQuery();
- int objId = 0;
- if (rset.next())
- {
- objId = rset.getInt(1);
- }
- rset.close();
- statement.close();
- if (objId == 0)
- {
- connection.close();
- return;
- }
- statement = connection.prepareStatement("UPDATE characters SET evil=1 WHERE obj_Id=?");
- statement.setInt(1, objId);
- statement.execute();
- statement.close();
- connection.close();
- }
- catch (Exception e)
- {
- _log.info("could not set evil status of char:");
- }
- finally
- {
- try
- {
- connection.close();
- }
- catch (Exception e)
- {
- }
- }
- if (player.isEvil())
- {
- player.broadcastUserInfo();
- player.sendMessage("You Are fighiting Now for " + Config.FACTION_NAME_TEAM_EVIL + " Faction ");
- player.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_EVIL);
- player.teleToLocation(Config.EVILX, Config.EVILY, Config.EVILZ);
- player.setTitle(Config.FACTION_NAME_TEAM_EVIL);
- }
- }
- }
- }
- }
- else if (actualCommand.equalsIgnoreCase("setnobless"))
- {
- L2PcInstance activeChar = player;
- if (activeChar.isNoble())
- activeChar.sendMessage("You Are Already A Noblesse!.");
- else
- {
- activeChar.setNoble(true, true);
- activeChar.sendMessage("You Are Now a Noble,You Are Granted With Noblesse Status , And Noblesse Skills.");
- activeChar.broadcastUserInfo();
- activeChar.getInventory().addItem("Tiara", 7694, 1, activeChar, null);
- }
- }
- else
- {
- super.onBypassFeedback(player, command);
- }
- }
- @Override
- public String getHtmlPath(int npcId, int val)
- {
- return "data/html/mods/faction/main.htm";
- }
- }
- At Enterworld.java add somewhere the following:
- if (activeChar.isEvil() && Config.FACTION_ENABLE_FACTION)
- {
- activeChar.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_EVIL);
- activeChar.sendMessage("Welcome " + activeChar.getName() + " u are fighting for " + Config.FACTION_NAME_TEAM_EVIL + " Faction");
- }
- if (activeChar.isEvil() && Config.FACTION_ENABLE_FACTION)
- {
- activeChar.teleToLocation(Config.EVILX, Config.EVILY, Config.EVILZ, true);
- activeChar.sendMessage("You have been teleported Back to your Faction Base");
- }
- if (activeChar.isGood() && Config.FACTION_ENABLE_FACTION)
- {
- activeChar.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_GOOD);
- activeChar.sendMessage("Welcome " + activeChar.getName() + " u are fighting for " + Config.FACTION_NAME_TEAM_GOOD + " Faction");
- }
- if (activeChar.isGood() && Config.FACTION_ENABLE_FACTION)
- {
- activeChar.teleToLocation(Config.GOODX, Config.GOODY, Config.GOODZ, true);
- activeChar.sendMessage("You have been teleported Back to your Faction Base");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement