AccessDenied Posted January 17, 2017 Share Posted January 17, 2017 (edited) Well i had 30 minute free so i coded a faction for aCis, in which you can set unlimited factions no just 2. The code contain the Npc Instance, exceptions and stuff like that. I will update the code more soon.. Ps. i havent tested or idk if it works in some part so if you want apply the patch and write me.. Code here Update 2.0 Code Update 3.0 Code (Optimized code, fixed some things, added reward with no config yet) 18/1/2016 Sql files: /* MySQL Data Transfer Source Host: localhost Source Database: acis Target Host: localhost Target Database: acis Date: 17/1/2017 6:47:13 μμ */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for faction -- ---------------------------- DROP TABLE IF EXISTS `faction`; CREATE TABLE `faction` ( `factionId` int(5) DEFAULT NULL, `factionName` text, `factionPos` text, `factionColor` text ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records -- ---------------------------- INSERT INTO `faction` VALUES ('1', 'Angels', '555;555;5555', 00FF00); INSERT INTO `faction` VALUES ('2', 'Demons', '5125;51251;512', FF0000); /* MySQL Data Transfer Source Host: localhost Source Database: acis Target Host: localhost Target Database: acis Date: 17/1/2017 6:48:01 μμ */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for characters -- ---------------------------- DROP TABLE IF EXISTS `characters`; CREATE TABLE `characters` ( `account_name` varchar(45) DEFAULT NULL, `obj_Id` int(10) unsigned NOT NULL DEFAULT '0', `char_name` varchar(35) NOT NULL, `level` tinyint(3) unsigned DEFAULT NULL, `maxHp` mediumint(8) unsigned DEFAULT NULL, `curHp` mediumint(8) unsigned DEFAULT NULL, `maxCp` mediumint(8) unsigned DEFAULT NULL, `curCp` mediumint(8) unsigned DEFAULT NULL, `maxMp` mediumint(8) unsigned DEFAULT NULL, `curMp` mediumint(8) unsigned DEFAULT NULL, `face` tinyint(3) unsigned DEFAULT NULL, `hairStyle` tinyint(3) unsigned DEFAULT NULL, `hairColor` tinyint(3) unsigned DEFAULT NULL, `sex` tinyint(3) unsigned DEFAULT NULL, `heading` mediumint(9) DEFAULT NULL, `x` mediumint(9) DEFAULT NULL, `y` mediumint(9) DEFAULT NULL, `z` mediumint(9) DEFAULT NULL, `exp` bigint(20) unsigned DEFAULT '0', `expBeforeDeath` bigint(20) unsigned DEFAULT '0', `sp` int(10) unsigned NOT NULL DEFAULT '0', `karma` int(10) unsigned DEFAULT NULL, `pvpkills` smallint(5) unsigned DEFAULT NULL, `pkkills` smallint(5) unsigned DEFAULT NULL, `clanid` int(10) unsigned DEFAULT NULL, `race` tinyint(3) unsigned DEFAULT NULL, `classid` tinyint(3) unsigned DEFAULT NULL, `base_class` tinyint(3) unsigned NOT NULL DEFAULT '0', `deletetime` bigint(20) DEFAULT NULL, `cancraft` tinyint(3) unsigned DEFAULT NULL, `title` varchar(16) DEFAULT NULL, `rec_have` tinyint(3) unsigned NOT NULL DEFAULT '0', `rec_left` tinyint(3) unsigned NOT NULL DEFAULT '0', `accesslevel` mediumint(9) DEFAULT '0', `online` tinyint(3) unsigned DEFAULT NULL, `onlinetime` int(11) DEFAULT NULL, `char_slot` tinyint(3) unsigned DEFAULT NULL, `lastAccess` bigint(20) unsigned DEFAULT NULL, `clan_privs` mediumint(8) unsigned DEFAULT '0', `wantspeace` tinyint(3) unsigned DEFAULT '0', `isin7sdungeon` tinyint(3) unsigned NOT NULL DEFAULT '0', `punish_level` tinyint(3) unsigned NOT NULL DEFAULT '0', `punish_timer` int(10) unsigned NOT NULL DEFAULT '0', `power_grade` tinyint(3) unsigned DEFAULT NULL, `nobless` tinyint(3) unsigned NOT NULL DEFAULT '0', `hero` tinyint(3) unsigned NOT NULL DEFAULT '0', `subpledge` smallint(6) NOT NULL DEFAULT '0', `last_recom_date` bigint(20) unsigned NOT NULL DEFAULT '0', `lvl_joined_academy` tinyint(3) unsigned NOT NULL DEFAULT '0', `apprentice` int(10) unsigned NOT NULL DEFAULT '0', `sponsor` int(10) unsigned NOT NULL DEFAULT '0', `varka_ketra_ally` tinyint(4) NOT NULL DEFAULT '0', `clan_join_expiry_time` bigint(20) unsigned NOT NULL DEFAULT '0', `clan_create_expiry_time` bigint(20) unsigned NOT NULL DEFAULT '0', `death_penalty_level` smallint(5) unsigned NOT NULL DEFAULT '0', `factionid` int(5) DEFAULT '0', PRIMARY KEY (`obj_Id`), KEY `clanid` (`clanid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Npc Html (for test): <html><head><body><center> <font color=AAAAAA>Faction Manager</font><br> <br> Welcome, which path are you gonna follow? <button value="Angels" action="bypass -h npc_%objectId%_1" back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df" width=125 height=21> <button value="Demons" action="bypass -h npc_%objectId%_2" back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df" width=125 height=21> <font color="cc9900"><img src="L2UI_CH3.herotower_deco" width=256 height=32></font><br1> </center> </body> </head> </html> Edited January 18, 2017 by AccessDenied 2 Link to comment Share on other sites More sharing options...
Sdw Posted January 17, 2017 Share Posted January 17, 2017 Time to check some Java 8 stuff Link to comment Share on other sites More sharing options...
AccessDenied Posted January 17, 2017 Author Share Posted January 17, 2017 Time to check some Java 8 stuff I work in java 7 since i use l2jfreya from 2009 maybe you're right but ill update it anyway. In which part you refer to ? Link to comment Share on other sites More sharing options...
MarGaZeaS Posted January 17, 2017 Share Posted January 17, 2017 i will test. thanks for share. +1 :) Link to comment Share on other sites More sharing options...
AccessDenied Posted January 17, 2017 Author Share Posted January 17, 2017 i will test. thanks for share. +1 :) np, anything u find report it here. I'll update it and add dynamic html faction show and reward via xmllization. Link to comment Share on other sites More sharing options...
Tryskell Posted January 17, 2017 Share Posted January 17, 2017 (edited) Factions on enum. + public Collection<L2PcInstance> getFactionPlayers(int id) + { + Map<Integer, L2PcInstance> players = new ConcurrentHashMap<>(); NONONONONONONONO Edited January 17, 2017 by Tryskell Link to comment Share on other sites More sharing options...
AccessDenied Posted January 17, 2017 Author Share Posted January 17, 2017 Factions on enum. + public Collection<L2PcInstance> getFactionPlayers(int id) + { + Map<Integer, L2PcInstance> players = new ConcurrentHashMap<>(); NONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONO How u suggest it? Link to comment Share on other sites More sharing options...
Tryskell Posted January 17, 2017 Share Posted January 17, 2017 (edited) How u suggest it? Use .stream().filter( or at least a basic List<L2PcInstance>. About Faction enum, I did similar thing for SevenSigns (and I do whenever I can now) public enum CabalType { NORMAL("No Cabal", "No Cabal"), DUSK("dusk", "Revolutionaries of Dusk"), DAWN("dawn", "Lords of Dawn"); private final String _shortName; private final String _fullName; private CabalType(String shortName, String fullName) { _shortName = shortName; _fullName = fullName; } public String getShortName() { return _shortName; } public String getFullName() { return _fullName; } public static final CabalType VALUES[] = values(); } which avoid a lot of idiot methods like (or getFactionName, or whatever generic) + public Location getFactionLocation(L2PcInstance player) + { + int factionId = player.getFactionId(); + Location loc = null; + + for (FactionHolder faction : factions.values()) + { + if (faction.getFactionId() == factionId) + { + loc = faction.getFactionLoc(); + } + } + + return loc; + } Edited January 17, 2017 by Tryskell Link to comment Share on other sites More sharing options...
An4rchy Posted January 17, 2017 Share Posted January 17, 2017 (edited) I work in java 7 since i use l2jfreya from 2009 maybe you're right but ill update it anyway. In which part you refer to ? First thing I noticed, you can avoid all this: private static class TeleToBase implements Runnable { L2PcInstance _player = null; public TeleToBase(L2PcInstance player) { _player = player; } @Override public void run() { if (_player !=null) { Faction.getInstance().teleToBase(_player); _player.sendMessage("Have a nice gameplay!"); } } } using a lambda expression: ThreadPoolManager.getInstance().scheduleGeneral(() -> player.teleToLocation(x, y, z), 5000); Since you use a singleton on Faction, you should load the factions in a constructor, that's the whole point. Plus, in loadFaction() method, if (result.next()) should be while (result.next()). But you should use xml for the factions' data. + public void teleToBase(L2PcInstance player) + { + int factionId = player.getFactionId(); + + for (FactionHolder faction : factions.values()) + { + if (faction.getFactionId() == factionId) + { + Location loc = faction.getFactionLoc(); + player.teleToLocation(loc, 0); + } + } + } Can be done: + public void teleToBase(L2PcInstance player) + { + if (factions.containsKey(player.getFactionId()) + player.teleToLocation(factions.get(player.getFactionId()).getFactionLoc(), 0); + } Same thing for onPlayerEnter() and getFactionLocation() (here again you can avoid 2 methods to get the faction's location by making a getFaction() method that can be used in many instances) method. On L2FactionInstance, after calling player.setFactionId(), you should store the player in database because in some cases (critical error, dc) the faction he chose isn't going to be saved and he will have to choose again. Use player.store(). Edited January 17, 2017 by An4rchy Link to comment Share on other sites More sharing options...
MarGaZeaS Posted January 18, 2017 Share Posted January 18, 2017 make with config for 3.0 update :) Link to comment Share on other sites More sharing options...
AccessDenied Posted January 18, 2017 Author Share Posted January 18, 2017 First thing I noticed, you can avoid all this: private static class TeleToBase implements Runnable { L2PcInstance _player = null; public TeleToBase(L2PcInstance player) { _player = player; } @Override public void run() { if (_player !=null) { Faction.getInstance().teleToBase(_player); _player.sendMessage("Have a nice gameplay!"); } } } using a lambda expression: ThreadPoolManager.getInstance().scheduleGeneral(() -> player.teleToLocation(x, y, z), 5000); Since you use a singleton on Faction, you should load the factions in a constructor, that's the whole point. Plus, in loadFaction() method, if (result.next()) should be while (result.next()). But you should use xml for the factions' data. + public void teleToBase(L2PcInstance player) + { + int factionId = player.getFactionId(); + + for (FactionHolder faction : factions.values()) + { + if (faction.getFactionId() == factionId) + { + Location loc = faction.getFactionLoc(); + player.teleToLocation(loc, 0); + } + } + } Can be done: + public void teleToBase(L2PcInstance player) + { + if (factions.containsKey(player.getFactionId()) + player.teleToLocation(factions.get(player.getFactionId()).getFactionLoc(), 0); + } Same thing for onPlayerEnter() and getFactionLocation() (here again you can avoid 2 methods to get the faction's location by making a getFaction() method that can be used in many instances) method. On L2FactionInstance, after calling player.setFactionId(), you should store the player in database because in some cases (critical error, dc) the faction he chose isn't going to be saved and he will have to choose again. Use player.store(). I know i'll change it in V3.0 but im used in Java 7 since i work as i mentionted in old freya revision since 2010 make with config for 3.0 update :) Configurations such as? Cause the configs are pretty much those in navicat. Color, name, location e.t.c the only config ill add will be for reward Link to comment Share on other sites More sharing options...
Hater’ Posted January 18, 2017 Share Posted January 18, 2017 make with config for 3.0 update :) You don't deserve aCis. Link to comment Share on other sites More sharing options...
`Son Posted January 18, 2017 Share Posted January 18, 2017 (edited) Is this code tested? Loading Factions from db it will load just the first result from ResultSet. Change if(rs.next()) to while(rs.next()) Edited January 18, 2017 by `Son Link to comment Share on other sites More sharing options...
An4rchy Posted January 18, 2017 Share Posted January 18, 2017 I know i'll change it in V3.0 but im used in Java 7 since i work as i mentionted in old freya revision since 2010 It's not just about the Java 8 I mentioned, you can improve your code in numerous ways, not only those I mentioned. Gl. Link to comment Share on other sites More sharing options...
AccessDenied Posted January 18, 2017 Author Share Posted January 18, 2017 (edited) Is this code tested? Loading Factions from db it will load just the first result from ResultSet. Change if(rs.next()) to while(rs.next()) You just proved that you skipped the 3 lines i wrote. I said the code is not tested so please write me problems e.t.c to update it.. Also yes i saw that it load only 1 faction cause i added if instead of while. ill update it tomorrow along with reward. It's not just about the Java 8 I mentioned, you can improve your code in numerous ways, not only those I mentioned. Gl. I know i could even make it Runnable and no make new class but the lamba expression is exclusively in j8 which i dont use. Habbit But ill change it tomorrow along with 1-2 mistakes i did Edited January 18, 2017 by AccessDenied Link to comment Share on other sites More sharing options...
Recommended Posts