Jump to content

Acis Faction System [Unlimited Factions]


Recommended Posts

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 by AccessDenied
  • Upvote 2
Link to comment
Share on other sites

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

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

Factions on enum.

+   public Collection<L2PcInstance> getFactionPlayers(int id)
+   {
+       Map<Integer, L2PcInstance> players = new ConcurrentHashMap<>();

NONONONONONONONO

Edited by Tryskell
Link to comment
Share on other sites

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

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 by Tryskell
Link to comment
Share on other sites

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 by An4rchy
Link to comment
Share on other sites

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

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 by `Son
Link to comment
Share on other sites

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

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 by AccessDenied
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.



  • Posts

    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/hood-services https://campsite.bio/utchihaamkt  
    • Server Rates: » Xp 500x. » Sp 500x. » Aden 500x. » Drop 1x. » PartyXp 2x. » PartySp 2x. » Starting character level -61. Enchant rates: » Safe enchant +4. » Blessed and simple scrolls max enchant (+16). » Crystal scrolls max enchant (+20). » Simple enchant scrolls chance – 65%. » Blessed enchant scrolls chance – 100%. » Crystal enchant scrolls chance – 50% Augmentations: » Mid life stone skill chance – 5%. » High life stone skill chance – 10%. » Top life stone skill chance – 20%. » Augments 1+1 Unique features: » Main town – Giran » Automatic-Manual Potions. » Working 2 castle sieges. (Giran-Aden) » SPS cancel lasts 10 seconds and than buffs come back. » Stackable scrolls, lifestones, book of giants. » Unique pvp zone » More then 11 active raid bosses. » Wedding system. » Unique farming areas. » Npc skill enchanter. » Full npc buffer with auto buff. » Max count of buffs – 55. » Max subclasses – 4. » Free and no quest class change. » Free and no quest sub class. » Raid boss drop nobless item. » No weight limit. » Unique protection anti-hwy armor for archers/daggers etc. » Ingame password change. » Top pvp/pk/online ranks NPC. » Unique monsters & NPC. » Interlude retail skills. » Server up-time [24/7] [99]%. » Perfect class balance (all class can kill all class depending on players skill and setup knowledge,gear,augmentations). » Announcements on double kills triple kills etc. » Announcements on Grand Boss death , with the name of the killer as well as clan name of the player. » Information Npc in game with all servers infromations. Custom server gear : 1). Titanium Armor Lv.1 2). Epic Armor Lv.2 3). Epic Weapons-Kamikaze-Black S grade (Same Stats) 4). Demonic-Angelic Wings-Baium Hair-Custom Accessories (SameStats) 5). Custom Fighter/Mage tattoo Lv1-Lv2-Lv3 6). Shirt (STR,CON,INT +1) 7). Custom Shields Server Commands: .tvtjoin .tvtleave – Join or leave tvt event. .ctfjoin .ctfleave – Join or leave ctf event. .dmjoin .dmleave – Join of leave dm event. .online – current online players count. .repair – repairs stuck character in world. .menu – opens online menu panel. .exit – PVP zone exit in case you are bullied. .changepassword - Opens online menu then u can change ur password in game. .farm - Enable/disable autofarm Event system: » TVT event » CTF event » DM event » Tournament Event » Party Zone » Unique event shop. Olympiad game: » Retail olympiad game. » Competition period [1] week. » Olympiad start time [18:00] end [00:00] GMT+2. » New Heroes every Sunday.
    • Tomorrow grand opening lests go 🙂 
    • New season of Warfire X150 has been postponed to September 28th.
  • Topics

×
×
  • Create New...