Advertisement
Guest User

access legs !!!

a guest
Jul 2nd, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.40 KB | None | 0 0
  1. Faction System for aCis requested by Paranoic and Ipotonic
  2.  
  3.  
  4. At net.sf.l2j.gameserver.model.L2World find:
  5.  
  6. private final Map<Integer, L2PcInstance> _players = new ConcurrentHashMap<>();
  7.  
  8. Add bellow:
  9.  
  10. private final Map<String, L2PcInstance> _evils = new ConcurrentHashMap<>();
  11. private final Map<String, L2PcInstance> _goods = new ConcurrentHashMap<>();
  12.  
  13. Find:
  14.  
  15. public Collection<L2Object> getObjects()
  16. {
  17.     return _objects.values();
  18. }
  19.  
  20. Add bellow:
  21.  
  22. public Collection<L2PcInstance> getAllgoodPlayers()
  23. {
  24.     return _goods.values();
  25. }
  26.      
  27. public Collection<L2PcInstance> getAllevilPlayers()
  28. {              
  29.     return _evils.values();
  30. }
  31.  
  32. public int getAllgoodPlayersCount()
  33. {
  34.     return _goods.size();
  35. }
  36.      
  37. public int getAllevilPlayersCount()
  38. {
  39.     return _evils.size();
  40. }
  41.  
  42. Find:
  43.  
  44. public void addPlayer(L2PcInstance cha)
  45. {
  46.    _players.putIfAbsent(cha.getObjectId(), cha);
  47. }
  48.  
  49. Change to:
  50.  
  51. public void addPlayer(L2PcInstance cha)
  52.     {
  53.         if (Config.FACTION.ENABLED)
  54.         {
  55.             if (cha.isEvil())
  56.             {
  57.                 _evils.putIfAbsent(cha.getName().toLowerCase(), cha);
  58.             }
  59.            
  60.             _goods.putIfAbsent(cha.getName().toLowerCase(), cha);
  61.            
  62.         }
  63.         _players.putIfAbsent(cha.getObjectId(), cha);
  64.     }
  65.  
  66. Go at net.sf.l2j.gameserver.model.actor.instance.L2PcInstance
  67.  
  68.  
  69. find:
  70.  
  71. 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=?";
  72.  
  73. Change to:
  74.  
  75. 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=?";
  76.  
  77. find:
  78.  
  79. 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=?";
  80.  
  81. change to:
  82.  
  83. 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=?";
  84.  
  85. find:
  86.  
  87. private boolean _hero = false;
  88.  
  89. add bellow:
  90.  
  91. private boolean _isgood = false;
  92. private boolean _isevil = false;
  93.  
  94. find:
  95.  
  96. public void updatePvPFlag(int value)
  97.  
  98. add bellow:
  99.  
  100. if (isgood() || isevil())
  101.   return;
  102.  
  103. find:
  104.  
  105. player.setNoble(rset.getInt("nobless") == 1, false);
  106.  
  107. add bellow:
  108.  
  109. player.setGood((rset.getInt("good") == 1) ? true : false);
  110. player.setEvil((rset.getInt("evil") == 1) ? true : false);
  111.  
  112. find:
  113.  
  114. statement.setLong(49, getDeathPenaltyBuffLevel());
  115.  
  116. change to:
  117.  
  118. statement.setInt(50, isGood() ? 1 : 0);
  119. statement.setInt(51, isEvil() ? 1 : 0);
  120. statement.setInt(52, getObjectId());
  121.  
  122. find:
  123.  
  124. public void doAttack(L2Character target)
  125.  
  126. add bellow:
  127.  
  128. if (Config.FACTION_ENABLE_FACTION)
  129. {
  130.     if (this instanceof L2PcInstance && target instanceof L2PcInstance)
  131.     {
  132.         if (isEvil() && target.getActingPlayer().isGood())
  133.             return;
  134.                
  135.         if (isGood() && target.getActingPlayer().isEvil())
  136.             return;
  137.     }
  138. }
  139.  
  140. find:
  141.  
  142. public void doCast(L2Skill skill)
  143.  
  144. add bellow:
  145.  
  146. if (Config.FACTION_ENABLE)
  147. {
  148.     L2Object target = getActingPlayer().getTarget();
  149.            
  150.     if (target !=null && target instanceof L2PcInstance)
  151.     {
  152.         if (getActingPlayer().isEvil() && target.isEvil() && skill.isOffensive())
  153.         {
  154.             return;
  155.         }
  156.         if (getActingPlayer().isGood() && target.isGood() && skill.isOffensive())
  157.         {
  158.             return;
  159.         }
  160.     }
  161. }
  162.  
  163. Somewhere add:
  164.  
  165. public boolean isGood()
  166. {
  167.     return _isgood;
  168. }
  169.          
  170. public boolean isEvil()
  171. {
  172.     return _isevil;
  173. }
  174.        
  175. public void setGood(boolean value)
  176. {
  177.     _isgood = value;
  178. }
  179.        
  180. public void setEvil(boolean value)
  181. {
  182.     _isevil = value;
  183. }
  184.  
  185. At Config.java
  186.  
  187.  
  188. Add somewhere the variables:
  189.  
  190. public static boolean FACTION_ENABLE_FACTION;
  191. public static int PRIMAR_X;
  192. public static int PRIMAR_Y;
  193. public static int PRIMAR_Z;
  194. public static int GOODX;
  195. public static int GOODY;
  196. public static int GOODZ;
  197. public static int EVILX;
  198. public static int EVILY;
  199. public static int EVILZ;
  200. public static String FACTION_NAME_TEAM_GOOD;
  201. public static String FACTION_NAME_TEAM_EVIL;
  202. public static int FACTION_COLOR_NAME_GOOD;
  203. public static int FACTION_COLOR_NAME_EVIL;
  204.  
  205. Find:
  206.  
  207. STARTING_ADENA = players.getProperty("StartingAdena", 100);
  208.  
  209. Add bellow:
  210.  
  211.     FACTION_ENABLE_FACTION = players.getProperty("EnableFaction", false);
  212.     PRIMAR_X = players.getProperty("PrimarBaseX", 139990);
  213.     PRIMAR_Y = players.getProperty("PrimarBaseY", -124423);
  214.     PRIMAR_Z = players.getProperty("PrimarBaseZ", -1903);
  215.     GOODX = players.getProperty("GoodBaseX", -84318);
  216.     GOODY = players.getProperty("GoodBaseY", 244579);
  217.     GOODZ = players.getProperty("GoodBaseZ", -3730);
  218.     EVILX = players.getProperty("EvilBaseX", -44836);
  219.     EVILY = players.getProperty("EvilBaseY", -112524);
  220.     EVILZ = players.getProperty("EvilBaseZ", -235);
  221.     FACTION_NAME_TEAM_GOOD = players.getProperty("NameTeamGood", "Angels");
  222.     FACTION_NAME_TEAM_EVIL = players.getProperty("NameTeamEvil", "Demons");
  223.     FACTION_COLOR_NAME_GOOD =  Integer.decode("0x" + players.getProperty("ColorNameGood", "00FF00"));
  224.     FACTION_COLOR_NAME_EVIL =  Integer.decode("0x" + players.getProperty("ColorNameEvil", "00FF00"));
  225.  
  226. At CharacterCreate.java
  227.  
  228.  
  229. Add:
  230.  
  231. if (Config.FACTION_ENABLE_FACTION)
  232. {
  233.     newChar.setXYZ(Config.PRIMAR_X, Config.PRIMAR_Y, Config.PRIMAR_Z);
  234. }
  235.  
  236. At instances create a new class with name L2FactionInstance
  237.  
  238. and add this code:
  239.  
  240. package net.sf.l2j;
  241.  
  242. import java.sql.Connection;
  243. import java.sql.PreparedStatement;
  244. import java.sql.ResultSet;
  245. import java.util.StringTokenizer;
  246. import java.util.logging.Logger;
  247.  
  248. import net.sf.l2j.commons.random.Rnd;
  249. import net.sf.l2j.gameserver.ai.CtrlIntention;
  250. import net.sf.l2j.gameserver.model.L2World;
  251. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  252. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  253. import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  254. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  255. import net.sf.l2j.gameserver.network.serverpackets.MyTargetSelected;
  256. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  257. import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  258. import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;
  259.  
  260.  
  261.  
  262. public class L2FactionInstance extends L2NpcInstance
  263. {
  264.  
  265.     public L2FactionInstance(int objectId, NpcTemplate template)
  266.     {
  267.         super(objectId, template);
  268.     }
  269.  
  270.     private final static Logger _log = Logger.getLogger(L2FactionInstance.class.getName());
  271.  
  272.     @Override
  273.     public void onBypassFeedback(L2PcInstance player, String command)
  274.     {
  275.         player.sendPacket(ActionFailed.STATIC_PACKET);
  276.         StringTokenizer st = new StringTokenizer(command, " ");
  277.         String actualCommand = st.nextToken();
  278.         @SuppressWarnings("unused")
  279.         String val = "";
  280.         if (st.countTokens() >= 1)
  281.         {
  282.             val = st.nextToken();
  283.     }
  284.  
  285.         else if (actualCommand.equalsIgnoreCase("setgood"))
  286.         {
  287.            
  288.         setTarget(player);
  289.        
  290.             if (player.isGood())
  291.             {
  292.                 player.sendMessage("You already are in " + Config.FACTION_NAME_TEAM_GOOD + " faction ");
  293.                 player.sendPacket(new ActionFailed());
  294.             }
  295.             else
  296.             {
  297.                 if (player.isEvil())
  298.                 {
  299.                     player.sendMessage("You cant change faction.");
  300.                     player.sendPacket(ActionFailed.STATIC_PACKET);
  301.                 }
  302.                 else
  303.                 {
  304.                     int getevils = L2World.getInstance().getAllevilPlayers().size();
  305.                     int getgoods = L2World.getInstance().getAllgoodPlayers().size();
  306.                     if (getgoods > getevils)
  307.                     {
  308.                         player.sendMessage("You Cant Use " + Config.FACTION_NAME_TEAM_GOOD + " Faction because Online number of " + Config.FACTION_NAME_TEAM_EVIL + " is smaller.");
  309.                         player.sendPacket(ActionFailed.STATIC_PACKET);
  310.                     }
  311.                     else
  312.                     {
  313.                     player.setGood(true);
  314.                     Connection connection = null;
  315.                         try
  316.                         {
  317.                             connection = L2DatabaseFactory.getInstance().getConnection();
  318.                             PreparedStatement statement = connection.prepareStatement("SELECT obj_Id FROM characters where char_name=?");
  319.                             statement.setString(1, player.getName());
  320.                             ResultSet rset = statement.executeQuery();
  321.                             int objId = 0;
  322.                         if (rset.next())
  323.                             {
  324.                                 objId = rset.getInt(1);
  325.                             }
  326.                             rset.close();
  327.                             statement.close();
  328.                             if (objId == 0)
  329.                             {
  330.                                 connection.close();
  331.                                 return;
  332.                             }
  333.                             statement = connection.prepareStatement("UPDATE characters SET good=1 WHERE obj_Id=?");
  334.                         statement.setInt(1, objId);
  335.                             statement.execute();
  336.                             statement.close();
  337.                             connection.close();
  338.                         }
  339.                         catch (Exception e)
  340.                         {
  341.                             _log.info("could not set good status of char:");
  342.                         }
  343.                         finally
  344.                         {
  345.                             try
  346.                             {
  347.                                 connection.close();
  348.                             }
  349.                             catch (Exception e)
  350.                             {
  351.                             }
  352.                         }
  353.                    
  354.                         if (player.isGood())
  355.                         {
  356.                             player.broadcastUserInfo();
  357.                             player.sendMessage("You Are fighiting Now for" + Config.FACTION_NAME_TEAM_GOOD + " Faction ");
  358.                             player.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_GOOD);
  359.                             player.teleToLocation(Config.GOODX, Config.GOODY, Config.GOODZ);
  360.                             player.setTitle(Config.FACTION_NAME_TEAM_GOOD);
  361.                         }
  362.                     }
  363.                 }
  364.         }
  365.         }
  366.         else if (actualCommand.equalsIgnoreCase("setevil"))
  367.         {
  368.             setTarget(player);
  369.             if (player.isEvil())
  370.             {
  371.                 player.sendMessage("You already are in " + Config.FACTION_NAME_TEAM_EVIL + " faction ");
  372.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  373.             }
  374.             else
  375.             {
  376.                 if (player.isGood())
  377.                 {
  378.                     player.sendMessage("You Cant Change Faction.");
  379.                     player.sendPacket(new ActionFailed());
  380.                 }
  381.                 else
  382.                 {
  383.                     int getevils = L2World.getInstance().getAllevilPlayers().size();
  384.                     int getgoods = L2World.getInstance().getAllgoodPlayers().size();
  385.                     if (getevils > getgoods)
  386.                     {
  387.                         player.sendMessage("You Cant Use " + Config.FACTION_NAME_TEAM_EVIL + " Faction because Online number of " + Config.FACTION_NAME_TEAM_EVIL + " is smaller.");
  388.                         player.sendPacket(new ActionFailed());
  389.                     }
  390.                     else
  391.                     {
  392.                         player.setEvil(true);
  393.                         Connection connection = null;
  394.                         try
  395.                         {
  396.                             connection = L2DatabaseFactory.getInstance().getConnection();
  397.                             PreparedStatement statement = connection.prepareStatement("SELECT obj_Id FROM characters where char_name=?");
  398.                             statement.setString(1, player.getName());
  399.                             ResultSet rset = statement.executeQuery();
  400.                             int objId = 0;
  401.                             if (rset.next())
  402.                         {
  403.                                 objId = rset.getInt(1);
  404.                         }
  405.                             rset.close();
  406.                             statement.close();
  407.                             if (objId == 0)
  408.                             {
  409.                                 connection.close();
  410.                                 return;
  411.                             }
  412.                             statement = connection.prepareStatement("UPDATE characters SET evil=1 WHERE obj_Id=?");
  413.                             statement.setInt(1, objId);
  414.                             statement.execute();
  415.                             statement.close();
  416.                             connection.close();
  417.                         }
  418.                         catch (Exception e)
  419.                         {
  420.                             _log.info("could not set evil status of char:");
  421.                         }
  422.                         finally
  423.                         {
  424.                             try
  425.                             {
  426.                                 connection.close();
  427.                             }
  428.                             catch (Exception e)
  429.                             {
  430.                             }
  431.                         }
  432.                    
  433.                         if (player.isEvil())
  434.                         {
  435.                             player.broadcastUserInfo();
  436.                             player.sendMessage("You Are fighiting Now for " + Config.FACTION_NAME_TEAM_EVIL + " Faction ");
  437.                             player.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_EVIL);
  438.                             player.teleToLocation(Config.EVILX, Config.EVILY, Config.EVILZ);
  439.                             player.setTitle(Config.FACTION_NAME_TEAM_EVIL);
  440.                         }
  441.                     }
  442.                 }
  443.             }
  444.         }
  445.         else if (actualCommand.equalsIgnoreCase("setnobless"))
  446.         {
  447.        
  448.             L2PcInstance activeChar = player;
  449.             if (activeChar.isNoble())
  450.                 activeChar.sendMessage("You Are Already A Noblesse!.");
  451.             else
  452.             {
  453.                 activeChar.setNoble(true, true);
  454.                 activeChar.sendMessage("You Are Now a Noble,You Are Granted With Noblesse Status , And Noblesse Skills.");
  455.                 activeChar.broadcastUserInfo();
  456.                 activeChar.getInventory().addItem("Tiara", 7694, 1, activeChar, null);
  457.             }
  458.         }
  459.         else
  460.         {
  461.             super.onBypassFeedback(player, command);
  462.         }
  463.     }
  464.    
  465.     @Override
  466.     public String getHtmlPath(int npcId, int val)
  467.     {
  468.         return "data/html/mods/faction/main.htm";
  469.     }
  470.  
  471. }
  472.  
  473. At Enterworld.java add somewhere the following:
  474.  
  475. if (activeChar.isEvil() && Config.FACTION_ENABLE_FACTION)
  476.                 {
  477.                     activeChar.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_EVIL);
  478.                     activeChar.sendMessage("Welcome " + activeChar.getName() + " u are fighting for " + Config.FACTION_NAME_TEAM_EVIL + "  Faction");
  479.             }
  480.                
  481.                 if (activeChar.isEvil() && Config.FACTION_ENABLE_FACTION)
  482.                 {
  483.                     activeChar.teleToLocation(Config.EVILX, Config.EVILY, Config.EVILZ, true);
  484.                     activeChar.sendMessage("You have been teleported Back to your Faction Base");
  485.                 }
  486.  
  487.                 if (activeChar.isGood() && Config.FACTION_ENABLE_FACTION)
  488.                 {
  489.                     activeChar.getAppearance().setNameColor(Config.FACTION_COLOR_NAME_GOOD);
  490.                     activeChar.sendMessage("Welcome " + activeChar.getName() + " u are fighting for " + Config.FACTION_NAME_TEAM_GOOD + " Faction");
  491.                 }
  492.                
  493.                 if (activeChar.isGood() && Config.FACTION_ENABLE_FACTION)
  494.                 {
  495.                     activeChar.teleToLocation(Config.GOODX, Config.GOODY, Config.GOODZ, true);
  496.                     activeChar.sendMessage("You have been teleported Back to your Faction Base");
  497.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement