Advertisement
warc222

Faction system(Mr.Anonymous)

Sep 24th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.69 KB | None | 0 0
  1. EnterWolrd.java
  2. if(!activeChar.isEvil() && !activeChar.isGood())
  3. {
  4. activeChar.startParalyze();
  5. activeChar.setIsParalyzed(true);
  6. activeChar.ShowDestination();
  7. }
  8. //
  9.  
  10. Faction.java class
  11. /*
  12. * This program is free software: you can redistribute it and/or modify it under
  13. * the terms of the GNU General Public License as published by the Free Software
  14. * Foundation, either version 3 of the License, or (at your option) any later
  15. * version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but WITHOUT
  18. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  19. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU General Public License along with
  23. * this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. package net.sf.l2j.gameserver.model.entity.events;
  26.  
  27. import java.util.ArrayList;
  28. import java.util.Collection;
  29. import java.util.List;
  30.  
  31. import javolution.util.FastList;
  32.  
  33. import net.sf.l2j.gameserver.model.L2Object;
  34. import net.sf.l2j.gameserver.model.L2World;
  35. import net.sf.l2j.gameserver.model.actor.L2Character;
  36. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  37. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  38.  
  39. /**
  40. * @author Mr.Anonymous
  41. */
  42. public class Faction
  43. {
  44. private static final FastList<L2PcInstance> players = new FastList<L2PcInstance>();
  45. private final List<Integer> _pointsE = new ArrayList<Integer>();
  46. private final List<Integer> _pointsG = new ArrayList<Integer>();
  47. public static boolean isTeam = false;
  48.  
  49. final int[] points = {0};
  50.  
  51. private static int yes =0;
  52. private static int no =0;
  53.  
  54. public void setTeamsColors(L2PcInstance a)
  55. {
  56. final String Evil = "0033CC";
  57. final String Good = "FF6600";
  58. final String Normal = "FFFFFFFF";
  59.  
  60. if(a.isEvil())
  61. a.getAppearance().setNameColor(Integer.decode("0x"+Evil));
  62. else if(a.isGood())
  63. a.getAppearance().setNameColor(Integer.decode("0x"+Good));
  64. else
  65. a.getAppearance().setNameColor(Integer.decode("0x"+Normal));
  66.  
  67. a.broadcastUserInfo();
  68. }
  69.  
  70. public final boolean checkHit(L2Character attacker, L2Character target)
  71. {
  72. if (target == null)
  73. return false;
  74.  
  75. final L2PcInstance aPlayer = attacker.getActingPlayer();
  76. final L2PcInstance tPlayer = target.getActingPlayer();
  77.  
  78. if (aPlayer != null && tPlayer != null && aPlayer.isEvil() && tPlayer.isEvil() || aPlayer.isGood() && tPlayer.isGood())
  79. {
  80. isTeam = true;
  81. aPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  82. aPlayer.sendMessage("You can't attack your team!");
  83. return false;
  84. }
  85.  
  86. return true;
  87. }
  88.  
  89. public static boolean checkActions(L2Character attacker, L2Character target)
  90. {
  91. if (target == null)
  92. return false;
  93.  
  94. final L2PcInstance aPlayer = attacker.getActingPlayer();
  95. final L2PcInstance tPlayer = target.getActingPlayer();
  96.  
  97. if (aPlayer != null && tPlayer != null && aPlayer.isEvil() && tPlayer.isEvil() || aPlayer.isGood() && tPlayer.isGood())
  98. {
  99. isTeam = true;
  100. aPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  101. return false;
  102. }
  103.  
  104. return true;
  105. }
  106.  
  107. public static boolean checkActions(L2Object t,L2Character p)
  108. {
  109.  
  110. L2Character target = (L2Character) t;
  111.  
  112. if(target instanceof L2PcInstance && p.isEvil() && target.isEvil() || p.isGood() && target.isGood())
  113. {
  114. isTeam = true;
  115. p.sendPacket(ActionFailed.STATIC_PACKET);
  116. return false;
  117. }
  118. return true;
  119. }
  120.  
  121. public void checkPointsAndReward()
  122. {
  123. final int evilpoints = getEvilPoints();
  124. final int goodpoints = getEvilPoints();
  125. final Collection<L2PcInstance> allevils = L2World.getInstance().getAllEvils().values();
  126. final Collection<L2PcInstance> allgoods = L2World.getInstance().getAllGoods().values();
  127.  
  128. if(evilpoints > goodpoints)
  129. {
  130. for(L2PcInstance evils: allevils)
  131. {
  132. if(evils != null)
  133. evils.addItem("Reward", 57, 4, evils, false);
  134. evils.sendMessage("You have rewarded with 4 adena");
  135. }
  136.  
  137. }
  138. else if(evilpoints < goodpoints)
  139. {
  140. for(L2PcInstance goods: allgoods)
  141. {
  142. if(goods != null)
  143. goods.addItem("Reward", 57, 4, goods, false);
  144. goods.sendMessage("You have rewarded with 4 adena");
  145. }
  146. }
  147. }
  148.  
  149. public void AddPointToEvils()
  150. {
  151. for (int i = 0; i < points.length; i++)
  152. {
  153. if(!isTeam)
  154. _pointsE.add(points[i]);
  155. }
  156. }
  157.  
  158. public void AddPointToGoods()
  159. {
  160. for (int i = 0; i < points.length; i++)
  161. {
  162. if(!isTeam)
  163. _pointsG.add(points[i]);
  164. }
  165. }
  166.  
  167. public int getEvilPoints()
  168. {
  169. return _pointsE.size();
  170. }
  171.  
  172. public int getGoodPoints()
  173. {
  174. return _pointsG.size();
  175. }
  176.  
  177. public void RemovePointFromEvils()
  178. {
  179. _pointsE.remove(String.valueOf(points[1]));
  180. }
  181.  
  182. public void RemovePointFromGoods()
  183. {
  184. _pointsG.remove(String.valueOf(points[1]));
  185. }
  186.  
  187. public void clearEvilPoints()
  188. {
  189. _pointsE.clear();
  190. }
  191.  
  192. public void clearGoodPoints()
  193. {
  194. _pointsG.clear();
  195. }
  196.  
  197. public void clearBothTeamsPoints()
  198. {
  199. _pointsE.clear();
  200. _pointsG.clear();
  201. }
  202.  
  203. public void TeleAllEvils(final int x,final int y,final int z)
  204. {
  205. for(L2PcInstance ph: players)
  206. if(ph.isEvil())
  207. ph.teleToLocation(x, y, z);
  208. }
  209.  
  210. public void TeleAllGoods(final int x,final int y,final int z)
  211. {
  212. for(L2PcInstance ph: players)
  213. if(ph.isGood())
  214. ph.teleToLocation(x, y, z);
  215. }
  216.  
  217. public void setHeroAllEvils()
  218. {
  219. for(L2PcInstance ph: players)
  220. {
  221. if(ph.isEvil())
  222. ph.setHero(true);
  223. ph.broadcastUserInfo();
  224. }
  225. }
  226.  
  227. public void setHeroAllGoods()
  228. {
  229. for(L2PcInstance ph: players)
  230. {
  231. if(ph.isGood())
  232. ph.setHero(true);
  233. ph.broadcastUserInfo();
  234. }
  235. }
  236.  
  237. public void removeHeroFromAllEvils()
  238. {
  239. for(L2PcInstance ph: players)
  240. {
  241. if(ph.isEvil() && ph.isHero())
  242. ph.setHero(false);
  243. ph.broadcastUserInfo();
  244. }
  245. }
  246.  
  247. public void removeHeroFromAllGoods()
  248. {
  249. for(L2PcInstance ph: players)
  250. {
  251. if(ph.isGood() && ph.isHero())
  252. ph.setHero(false);
  253. ph.broadcastUserInfo();
  254. }
  255. }
  256.  
  257. public static void Vote(int yess,int noo)
  258. {
  259. yes = yes + yess;
  260. no = no + noo;
  261. }
  262.  
  263. public static int getVotes()
  264. {
  265. if(yes > 0 && yes > no)
  266. return yes;
  267.  
  268. return no;
  269. }
  270.  
  271. }
  272.  
  273. L2Character.java
  274.  
  275. boolean _isEvil = false;
  276. boolean _isGood = false;
  277.  
  278. public boolean isEvil()
  279. {
  280. return _isEvil;
  281. }
  282. public boolean isGood()
  283. {
  284. return _isGood;
  285. }
  286. public void setIsEvil(boolean j)
  287. {
  288. _isEvil = j;
  289. }
  290. public void setIsGood(boolean j)
  291. {
  292. _isGood = j;
  293. }
  294.  
  295. L2PcInstance.java
  296.  
  297.  
  298. boolean _isEvil = false;
  299. boolean _isGood = false;
  300.  
  301. @Override
  302. public boolean isEvil()
  303. {
  304. return _isEvil;
  305. }
  306. @Override
  307. public boolean isGood()
  308. {
  309. return _isGood;
  310. }
  311. @Override
  312. public void setIsEvil(boolean j)
  313. {
  314. _isEvil = j;
  315. }
  316. @Override
  317. public void setIsGood(boolean j)
  318. {
  319. _isGood = j;
  320. }
  321.  
  322. public void ShowDestination()
  323. {
  324. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  325. TextBuilder sb = new TextBuilder();
  326. sb.append("<html><title>Good Vs Evils</title><body>");
  327. sb.append("<center>");
  328. sb.append("<img src=\"l2ui_ch3.herotower_deco\" width=256 height=32><br>");
  329. sb.append("<br>");
  330. sb.append("Welcome " + getName() + "<br>");
  331. sb.append("<font color=\"999999\">Choose your destination </font><br>");
  332. sb.append("<font color=\"999999\">by pressing</font><br>");
  333. sb.append("<font color=\"999999\">.evil or .good and then you will be unparalysed</font><br>");
  334. sb.append("<br>");
  335. sb.append("<img src=\"l2ui_ch3.herotower_deco\" width=256 height=32><br>");
  336. sb.append("</center>");
  337. sb.append("</body></html>");
  338. html.setHtml(sb.toString());
  339. sendPacket(html);
  340. return;
  341. }
  342.  
  343. public void AddTheEvil()
  344. {
  345. Connection connection = null;
  346.  
  347. if(this.isGood())
  348. return;
  349.  
  350. try
  351. {
  352. connection = L2DatabaseFactory.getInstance().getConnection();
  353.  
  354. final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET evil=1 WHERE obj_id=?");
  355. statement.setInt(1, this.getObjectId());
  356. statement.execute();
  357. statement.close();
  358. this.setIsEvil(true);
  359. final long getExp = this.getStat().getExp();
  360. this.getStat().addExp(getExp + 6299994999L);
  361. this.stopParalyze(true);
  362. this.setIsParalyzed(false);
  363. this.updateNameTitleColor();
  364. this.sendPacket(new StatusUpdate(this));
  365. this.broadcastUserInfo();
  366. this.teleToLocation(getRandomSpawn()[0], getRandomSpawn()[1], getRandomSpawn()[2]);
  367. this.sendMessage("You are fighting with evils,you can't chance faction now this will be your final destination!");
  368.  
  369. }
  370. catch (Exception e)
  371. {
  372. if(Config.DEBUG)
  373. e.printStackTrace();
  374.  
  375. _log.log(Level.WARNING,"could not set evil stats to char:", e);
  376. }
  377. finally
  378. {
  379. L2DatabaseFactory.close(connection);
  380. }
  381. }
  382.  
  383. public void AddTheGood()
  384. {
  385. Connection connection = null;
  386.  
  387. if(this.isEvil())
  388. return;
  389.  
  390. try
  391. {
  392. connection = L2DatabaseFactory.getInstance().getConnection();
  393.  
  394. final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET good=1 WHERE obj_id=?");
  395. statement.setInt(1, this.getObjectId());
  396. statement.execute();
  397. statement.close();
  398. this.setIsGood(true);
  399. final long getExp = this.getStat().getExp();
  400. this.getStat().addExp(getExp + 6299994999L);
  401. this.stopParalyze(true);
  402. this.setIsParalyzed(false);
  403. this.updateNameTitleColor();
  404. this.sendPacket(new UserInfo(this));
  405. this.sendPacket(new StatusUpdate(this));
  406. this.broadcastUserInfo();
  407. this.teleToLocation(getRandomSpawn()[0], getRandomSpawn()[1], getRandomSpawn()[2]);
  408. this.sendMessage("You are fighting with goods,you can't chance faction now this will be your final destination!");
  409.  
  410. }
  411. catch (Exception e)
  412. {
  413. if(Config.DEBUG)
  414. e.printStackTrace();
  415.  
  416. _log.log(Level.WARNING,"could not set good stats to char:", e);
  417. }
  418. finally
  419. {
  420. L2DatabaseFactory.close(connection);
  421. }
  422. }
  423.  
  424. private final int[][] RandomSpawnE =
  425. {
  426. {-44678, -112589, -240},
  427. {-44538, -112587, -240},
  428. {-44632, -112630, -240},
  429. {-44674, -112559, -240},
  430. {-44548, -112567, -240},
  431. {-44632, -112630, -240},
  432. };
  433.  
  434. private final int[][] RandomSpawnG =
  435. {
  436. {111930, 220021, -3671},
  437. {111898, 219969, -3671},
  438. {111582, 219961, -3677},
  439. {111936, 220052, -3671},
  440. {111896, 219968, -3671},
  441. {111584, 219966, -3677},
  442. };
  443.  
  444. public final int[] getRandomSpawn()
  445. {
  446. final int[] getPosE = RandomSpawnE[Rnd.get(RandomSpawnE.length)];
  447. final int[] getPosG = RandomSpawnG[Rnd.get(RandomSpawnG.length)];
  448.  
  449. if(this.isEvil())
  450. return getPosE;
  451. else if(this.isGood())
  452. return getPosG;
  453. else
  454. return null;
  455. }
  456.  
  457. Faction.java (Voiced commands)
  458.  
  459. /*
  460. * This program is free software: you can redistribute it and/or modify it under
  461. * the terms of the GNU General Public License as published by the Free Software
  462. * Foundation, either version 3 of the License, or (at your option) any later
  463. * version.
  464. *
  465. * This program is distributed in the hope that it will be useful, but WITHOUT
  466. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  467. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  468. * details.
  469. *
  470. * You should have received a copy of the GNU General Public License along with
  471. * this program. If not, see <http://www.gnu.org/licenses/>.
  472. */
  473. package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
  474.  
  475. import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  476. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  477.  
  478. public class Faction implements IVoicedCommandHandler
  479. {
  480. private static String[] _voicedCommands =
  481. {
  482. "evil",
  483. "good"
  484. };
  485.  
  486. @Override
  487. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  488. {
  489. if(command.equalsIgnoreCase("evil"))
  490. {
  491. if(activeChar.isEvil())
  492. {
  493. activeChar.sendMessage("You are already evil");
  494. return false;
  495. }
  496. else if(activeChar.isGood())
  497. {
  498. activeChar.sendMessage("You can't change team");
  499. return false;
  500. }
  501. activeChar.AddTheEvil();
  502. }
  503. else if(command.equalsIgnoreCase("good"))
  504. {
  505. if(activeChar.isGood())
  506. {
  507. activeChar.sendMessage("You are already good");
  508. return false;
  509. }
  510. else if(activeChar.isEvil())
  511. {
  512. activeChar.sendMessage("You can't change team");
  513. return false;
  514. }
  515. activeChar.AddTheGood();
  516. }
  517. return true;
  518. }
  519.  
  520. @Override
  521. public String[] getVoicedCommandList()
  522. {
  523. return _voicedCommands;
  524. }
  525. }
  526.  
  527. CharacterCreat.java (now the random spawns when we create a character)
  528.  
  529.  
  530. private static final int[][] RandomSpawn =
  531. {
  532. {44521, 108628, -2038},
  533. {44512, 108671, -2038},
  534. {44538, 108589, -2038},
  535. {44464, 108608, -2038},
  536. {44609, 108632, -2038},
  537. {44585, 108636, -2038}
  538. };
  539.  
  540. public static int[] getRandom()
  541. {
  542. return RandomSpawn[Rnd.get(RandomSpawn.length)];
  543. }
  544.  
  545. find this: private void initNewChar(L2GameClient client, L2PcInstance newChar)
  546.  
  547. and add
  548.  
  549. final int X = getRandom()[0];
  550. final int Y = getRandom()[1];
  551. final int Z = getRandom()[2];
  552.  
  553. newChar.setXYZInvisible(X,Y,Z);
  554.  
  555. and now the sql:
  556.  
  557. go to characters.sql
  558. and add `evil` decimal(1,0) NOT NULL DEFAULT 0,
  559. `good` decimal(1,0) NOT NULL DEFAULT 0,
  560.  
  561. now the L2PcInstance.java sqls
  562.  
  563. // Character SQL String Definitions:
  564. private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date,evil,good) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  565. 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=?";
  566. 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=?";
  567.  
  568.  
  569. private boolean createDb()
  570. +statement.setInt(35, isEvil() ? 1 :0);
  571. +statement.setInt(36, isGood() ? 1 :0);
  572.  
  573. voide StoreCharBase
  574.  
  575. +statement.setInt(50, isEvil() ? 1 :0);
  576. +statement.setInt(51, isGood() ? 1 :0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement