Autor Tema: [EVENTO] Arena Event (2vs2)  (Leído 2288 veces)

Julio 22, 2015, 03:03:30 pm

Desconectado Danarys

  • Vips
  • Usuario
  • *
  • Mensajes: 220
  • Karma: 0
  • Sexo: Femenino
Evento aautomatico pvp

Código: You are not allowed to view links. Register or Login
em attackrequest
procura por isso
if (target instanceof L2PcInstance
&& ((L2PcInstance)target).getAppearance().getInvisible()
&& !activeChar.isGM())
return;
troca por isso
if (target instanceof L2PcInstance) {
L2PcInstance player = (L2PcInstance)target;
if (player.getAppearance().getInvisible() && !activeChar.isGM()
|| player.isInArenaEvent() && !activeChar.isInArenaEvent()
|| !player.isInArenaEvent() && activeChar.isInArenaEvent()) {
getClient().sendPacket(ActionFailed.STATIC_PACKET);
return;
}
}

Index: datapack/data/html/default/93001.htm
===================================================================
--- datapack/data/html/default/93001.htm (revision 0)
+++ datapack/data/html/default/93001.htm (working copy)
@@ -0,0 +1,8 @@
+<html>
+<body>
+<center>
+<tr><td><font color="FF44FF">Event Arena Manager</font></tr></td><br>
+<br>
+<button value="Event" action="bypass -h npc_%objectId%_Quest 8010_ArenaEvent" width=75 height=21 back="L2UI_ch3.Btn1_normalOn" fore="L2UI_ch3.Btn1_normal">
+</body>
+</html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/1.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/1.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/1.htm (working copy)
@@ -0,0 +1,7 @@
+<html><body>Event Arena Manager:<br>
+Explain Event .... bla bla bla bla bla <br>
+bla bla bla bla bla bla bla bla bla bla <br>
+<a action="bypass -h Quest 8010_ArenaEvent 1">Register</a><br>
+<a action="bypass -h Quest 8010_ArenaEvent 2">Unregister</a><br>
+<a action="bypass -h Quest 8010_ArenaEvent 3">I want observe</a><br>
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/__init__.py
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/__init__.py (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/__init__.py (working copy)
@@ -0,0 +1,58 @@
+# Author Alisson Oliveira
+import sys
+from com.l2jfrozen.gameserver.model.quest        import State
+from com.l2jfrozen.gameserver.model.quest        import QuestState
+from com.l2jfrozen.gameserver.model.quest.jython import QuestJython as JQuest
+from com.l2jfrozen.gameserver.model.entity.event import EvtArenaManager as Event
+from java.util import Map
+
+qn = "8010_ArenaEvent"
+NPCID = 93001
+initialhtml = "1.htm"
+
+class Quest (JQuest) :
+    def __init__(self, id, name, descr): JQuest.__init__(self, id, name, descr)
+   
+    def onEvent(self,event,st):
+        player = st.getPlayer()
+        html = initialhtml
+        if event == "1":
+           party = player.getParty()
+           if not player.isNoble(): return "only-noble.htm"
+           if not party: return "no-party.htm"
+           if not party.isLeader(player): return "no-leader.htm"
+           if party.getMemberCount() != 2: return "only-two.htm"
+           assist = party.getPartyMembers()[1] # get the last player in party
+           if not assist.isNoble(): return "only-noble.htm"
+           if Event.getInstance().register(player, assist):
+              return "registered.htm"
+        elif event == "2":
+           if Event.getInstance().remove(player):
+              return "unregistered.htm"
+        elif event == "3":
+           fights = Event.getInstance().getFights()
+           html = "<html><body>Event Arena Manager:<br> <br> Fights: <br>"
+           if len(fights) == 0:
+              html += "No fights going on right now<br></body></html>"
+           else:
+              for id in fights.keySet():
+                 html += "<a action=\"bypass -h Quest "+ qn +" 4_"+str(id)+"\">"+fights.get(id)+"</a><br><br>"
+              html += "</body></html>"
+           return html
+        elif event.startswith("4_"):
+           if not Event.getInstance().isRegistered(player):
+              arenaId = int(event.replace("4_",""))
+              Event.getInstance().addSpectator(player, arenaId)           
+        return "default.htm"
+   
+    def onTalk (self, npc, player):
+        return initialhtml 
+         
+QUEST = Quest(-1, qn, "custom")
+CREATED     = State('Start', QUEST)
+STARTED     = State('Started', QUEST)
+
+QUEST.setInitialState(CREATED)
+
+QUEST.addStartNpc(NPCID)
+QUEST.addTalkId(NPCID)
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/default.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/default.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/default.htm (working copy)
@@ -0,0 +1,3 @@
+<html><body>Event Arena Manager:<br>
+I have nothing to say to you!
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/no-leader.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/no-leader.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/no-leader.htm (working copy)
@@ -0,0 +1,4 @@
+<html><body>Event Arena Manager:<br>
+Only party leader can do this <br>
+bla bla bla bla bla bla bla bla bla bla <br>
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/no-party.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/no-party.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/no-party.htm (working copy)
@@ -0,0 +1,4 @@
+<html><body>Event Arena Manager:<br>
+You're not in party <br>
+bla bla bla bla bla bla bla bla bla bla <br>
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/only-noble.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/only-noble.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/only-noble.htm (working copy)
@@ -0,0 +1,3 @@
+<html><body>Event Arena Manager:<br>
+Only nobless can participate <br>
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/only-two.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/only-two.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/only-two.htm (working copy)
@@ -0,0 +1,4 @@
+<html><body>Event Arena Manager:<br>
+You must be in party with only Two members <br>
+bla bla bla bla bla bla bla bla bla bla <br>
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/registered.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/registered.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/registered.htm (working copy)
@@ -0,0 +1,4 @@
+<html><body>Event Arena Manager:<br>
+You're registered successful <br>
+bla bla bla bla bla bla bla bla bla bla <br>
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts/custom/8010_ArenaEvent/unregistered.htm
===================================================================
--- datapack/data/scripts/custom/8010_ArenaEvent/unregistered.htm (revision 0)
+++ datapack/data/scripts/custom/8010_ArenaEvent/unregistered.htm (working copy)
@@ -0,0 +1,4 @@
+<html><body>Event Arena Manager:<br>
+You're unregistered successful <br>
+bla bla bla bla bla bla bla bla bla bla <br>
+</body></html>
\ No newline at end of file
Index: datapack/data/scripts.cfg
===================================================================
--- datapack/data/scripts.cfg (revision 938)
+++ datapack/data/scripts.cfg (working copy)
@@ -43,6 +43,7 @@
 custom/8871_gve/__init__.py
 custom/6666_NoblessTrader/__init__.py
 custom/6667_ClanManager/__init__.py
+custom/8010_ArenaEvent/__init__.py
 
 # quests
 quests/SagasSuperclass/__init__.py
Index: gameserver/config/frozen/arena.properties
===================================================================
--- gameserver/config/frozen/arena.properties (revision 0)
+++ gameserver/config/frozen/arena.properties (working copy)
@@ -0,0 +1,24 @@
+# Arena Event
+ArenaEventEnabled = True
+
+# Arenas Location
+# e.g: 149360, 46594, -3415; x, y, z; x1, y1, z1
+ArenasLoc = 149360, 46594, -3415;
+
+# item to give to winners
+ArenaRewardId = 57
+
+# Count of item to give to winners
+ArenaRewardCount = 2000000
+
+# If False Players cannot use grade S
+ArenaAllowS = False
+
+# Time between check players status [in seconds]
+ArenaBattleCheckInterval = 15
+
+# Time between Call registered players [in seconds]
+ArenaBattleCallInterval = 60
+
+# Time to start battle after players are called [in seconds]
+ArenaBattleWaitInterval = 20
\ No newline at end of file
Index: gameserver/head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (working copy)
@@ -454,11 +454,11 @@
  public List<String> active_boxes_characters = new ArrayList<String>();
 
  /** UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,str=?,con=?,dex=?,_int=?,men=?,wit=? ,face=?,hairStyle=?,hairColor =?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have =?,rec_left=?,clanid=?,maxload =?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs =?,wantspeace=?,base_class =?,onlinetime=?,in_jail=?,jail_timer=?,newbie=?,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=?,good=?,evil=?,gve_kills=? WHERE obj_id=?. */
- private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,str=?,con=?,dex=?,_int=?,men=?,wit=?,face=?,hairStyle=?,hairColor=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,maxload=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,newbie=?,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=?,pc_point=?,name_color=?,title_color=?,aio=?,aio_end=? WHERE obj_id=?";
+ private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,str=?,con=?,dex=?,_int=?,men=?,wit=?,face=?,hairStyle=?,hairColor=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,maxload=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,newbie=?,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=?,pc_point=?,name_color=?,title_color=?,aio=?,aio_end=?,arena_wins=?,arena_defeats=? WHERE obj_id=?";
 
  /** SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, acc, crit, evasion, mAtk, mDef, mSpd, pAtk, pDef, pSpd, runSpd, walkSpd, str, con, dex, _int, men, wit, face, hairStyle, hairColor, sex, heading, x, y, z, movement_multiplier, attack_speed_multiplier, colRad, colHeight, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, maxload, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, in_jail, jail_timer, newbie, 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,good,evil,gve_kills FROM characters WHERE obj_id=?. */
  //private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, acc, crit, evasion, mAtk, mDef, mSpd, pAtk, pDef, pSpd, runSpd, walkSpd, str, con, dex, _int, men, wit, face, hairStyle, hairColor, sex, heading, x, y, z, movement_multiplier, attack_speed_multiplier, colRad, colHeight, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, maxload, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, in_jail, jail_timer, newbie, 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,pc_point,banchat_time,name_color,title_color,first_log,aio,aio_end FROM characters WHERE obj_id=?";
- private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, acc, crit, evasion, mAtk, mDef, mSpd, pAtk, pDef, pSpd, runSpd, walkSpd, str, con, dex, _int, men, wit, face, hairStyle, hairColor, sex, heading, x, y, z, movement_multiplier, attack_speed_multiplier, colRad, colHeight, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, maxload, 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,"+/* in_jail, jail_timer,*/ "newbie, 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,pc_point"+/*,banchat_time*/",name_color,title_color,first_log,aio,aio_end FROM characters WHERE obj_id=?";
+ private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, acc, crit, evasion, mAtk, mDef, mSpd, pAtk, pDef, pSpd, runSpd, walkSpd, str, con, dex, _int, men, wit, face, hairStyle, hairColor, sex, heading, x, y, z, movement_multiplier, attack_speed_multiplier, colRad, colHeight, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, maxload, 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,"+/* in_jail, jail_timer,*/ "newbie, 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,pc_point"+/*,banchat_time*/",name_color,title_color,first_log,aio,aio_end,arena_wins,arena_defeats FROM characters WHERE obj_id=?";
 
  /** The Constant STATUS_DATA_GET. */
  private static final String STATUS_DATA_GET = "SELECT hero, noble, donator, hero_end_date FROM characters_custom_data WHERE obj_Id = ?";
@@ -4249,6 +4249,8 @@
 
  /** The _moving task defined. */
  private Boolean _movingTaskDefined = false;
+
+ private boolean inArenaEvent = false;
 
  /**
  * MoveOnAttack Task.
@@ -10132,6 +10134,8 @@
  player.setDeathPenaltyBuffLevel(rset.getInt("death_penalty_level"));
                 player.setAio(rset.getInt("aio") == 1 ? true : false);
                 player.setAioEndTime(rset.getLong("aio_end"));
+                player.setArenaWins(rset.getInt("arena_wins"));
+                player.setArenaDefeats(rset.getInt("arena_defeats"));
  // Add the L2PcInstance object in _allObjects
  //L2World.getInstance().storeObject(player);
 
@@ -10217,6 +10221,8 @@
  return player;
  }
 
+
+
  /**
  * Gets the mail.
  *
@@ -10614,8 +10620,10 @@
 
          statement.setInt(60, isAio() ? 1 : 0);
          statement.setLong(61, getAioEndTime());
+         statement.setInt(62, arenaWins);
+         statement.setInt(63, arenaDefeats);
                       
-         statement.setInt(62, getObjectId());
+         statement.setInt(64, getObjectId());
         
  //statement.setLong(58, getChatBanTimer());
 
@@ -19642,5 +19650,32 @@
  }
 
  }
+
+ public void setInArenaEvent(boolean val) {
+ inArenaEvent = val;
+ }
 
+ public boolean isInArenaEvent() {
+ return inArenaEvent;
+ }
+
+ private int arenaDefeats;
+ private int arenaWins;
+
+ public void increaseArenaDefeats() {
+ arenaDefeats++;
+ }
+
+ public void increaseArenaWins() {
+ arenaWins++;
+ }
+
+ private void setArenaDefeats(int val) {
+ arenaDefeats = val;
+ }
+
+ private void setArenaWins(int val) {
+ arenaWins = val;
+ }
+
 }
Index: gameserver/head-src/com/l2jfrozen/gameserver/model/entity/event/EvtArenaManager.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/model/entity/event/EvtArenaManager.java (revision 0)
+++ gameserver/head-src/com/l2jfrozen/gameserver/model/entity/event/EvtArenaManager.java (working copy)
@@ -0,0 +1,464 @@
+package com.l2jfrozen.gameserver.model.entity.event;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import com.l2jfrozen.Config;
+import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jfrozen.gameserver.network.serverpackets.InventoryUpdate;
+import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
+import com.l2jfrozen.gameserver.templates.L2Item;
+import com.l2jfrozen.util.L2FastList;
+import com.l2jfrozen.util.random.Rnd;
+
+/**
+ * Event Arena Manager.
+ *
+ *
+ * This Event works only in pairs. Two players must to do a party and the leader register in the event
+ * if any member of party already registered, then the registrations fails. Only leader can removes
+ * from event. anyone can see the battles except the registered player in event.
+ * The battle only finish when only one party keep alive. In the end of each battle, winners earn a reward.
+ *
+ * The event is open all the time. have a little interval between call of battles of 1 minute
+ *
+ * @author Alisson Oliveira
+ *
+ */
+public class EvtArenaManager implements Runnable {
+
+ // list of participants
+ private List<Pair> registered;
+ // number of Arenas
+ private int free =  Config.ARENA_EVENT_COUNT;
+ // Arenas
+ private Arena[] arenas = new Arena[Config.ARENA_EVENT_COUNT];
+ // list of fights going on
+ private Map<Integer, String> fights = new FastMap<Integer, String>(Config.ARENA_EVENT_COUNT);
+
+ public EvtArenaManager() {
+ registered = new L2FastList<Pair>();
+ int[] coord;
+ for(int i=0; i < Config.ARENA_EVENT_COUNT; i++) {
+ coord = Config.ARENA_EVENT_LOCS[i];
+ arenas[i] = new Arena(i, coord[0], coord[1], coord[2]);
+ }
+ System.out.println("Initialized Arena Event");
+ }
+
+
+ public static EvtArenaManager getInstance() {
+ return SingletonHolder.INSTANCE;
+ }
+
+ public boolean register(L2PcInstance player, L2PcInstance assist) {
+ for(Pair p : registered) {
+ if(p.getLeader() == player || p.getAssist() == player) {
+ player.sendMessage("You Already registered");
+ return false;
+ } else if (p.getLeader() == assist || p.getAssist() == assist) {
+ player.sendMessage("Your Partner Already registered");
+ return false;
+ }
+ }
+ if(!Config.ARENA_ALLOW_S) {
+ checkItems(player);
+ checkItems(assist);
+ }
+ return registered.add(new Pair(player, assist));
+ }
+
+ private void checkItems(L2PcInstance player){
+ L2ItemInstance item;
+ int slot;
+ for(int i=1; i < 15; i++){
+ item = player.getInventory().getPaperdollItem(i);
+ if(item==null)
+ continue;
+ if(item.getItem().getItemGrade() == L2Item.CRYSTAL_S){
+ slot = item.getItem().getBodyPart();
+ switch(item.getEquipSlot()) {
+ case 1:
+ slot = L2Item.SLOT_L_EAR;
+ break;
+ case 2:
+ slot = L2Item.SLOT_R_EAR;
+ break;
+ case 4:
+ slot = L2Item.SLOT_L_FINGER;
+ break;
+ case 5:
+ slot = L2Item.SLOT_R_FINGER;
+ break;
+ default:
+ break;
+ }
+
+ L2ItemInstance[] items = player.getInventory().unEquipItemInBodySlotAndRecord(slot);
+     InventoryUpdate iu = new InventoryUpdate();
+     iu.addItems(Arrays.asList(items));
+     player.sendPacket(iu);
+ }
+ }
+ player.sendPacket(new ItemList(player, true));
+ player.broadcastUserInfo();
+ }
+
+ public boolean isRegistered(L2PcInstance player) {
+ for(Pair p : registered) {
+ if(p.getLeader() == player || p.getAssist() == player) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void addSpectator(L2PcInstance spec, int arenaId) {
+ Arena arena = getArena(arenaId);
+ if(arena != null)
+ arena.addSpectator(spec);
+ }
+
+ private Arena getArena(int id) {
+ for(Arena arena : arenas) {
+ if(arena.id == id) {
+ return arena;
+ }
+ }
+ return null;
+ }
+
+ public Map<Integer, String> getFights() {
+ return fights;
+ }
+
+ public boolean remove(L2PcInstance player) {
+ for(Pair p : registered) {
+ if(p.getLeader() == player) {
+ registered.remove(p);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized void run() {
+ // while server is running
+ while(true) {
+ // if no have participants or arenas are busy wait 1 minute
+ if(registered.size() < 2 || free == 0) {
+ try {
+ Thread.sleep(Config.ARENA_CALL_INTERVAL);
+ } catch (InterruptedException e) {
+ if(Config.ENABLE_ALL_EXCEPTIONS)
+ e.printStackTrace();
+ }
+ continue;
+ }
+ List<Pair> opponents = selectOpponents();
+ if(opponents != null && opponents.size() == 2) {
+ Thread T = new Thread(new EvtArenaTask(opponents));
+ T.setDaemon(true);
+ T.start();
+ }
+ //wait 1 minute for not stress server
+ try {
+ Thread.sleep(Config.ARENA_CALL_INTERVAL);
+ } catch (InterruptedException e) {
+ if(Config.ENABLE_ALL_EXCEPTIONS)
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private List<Pair> selectOpponents() {
+ List<Pair> opponents = new FastList<Pair>();
+ Pair pairOne=null, pairTwo=null;
+ int tries = 3;
+ do {
+ int first = 0, second = 0;
+ if(getRegisteredCount() < 2)
+ return opponents;
+
+ if(pairOne == null) {
+ first = Rnd.get(getRegisteredCount());
+ pairOne = registered.get(first);
+ if(pairOne.check()) {
+ opponents.add(0,pairOne);
+ registered.remove(first);
+ } else {
+ pairOne = null;
+ registered.remove(first);
+ return null;
+ }
+
+ }
+ if(pairTwo == null) {
+ second = Rnd.get(getRegisteredCount());
+ pairTwo = registered.get(second);
+ if(pairTwo.check()){
+ opponents.add(1, pairTwo);
+ registered.remove(second);
+ } else {
+ pairTwo = null;
+ registered.remove(second);
+ return null;
+ }
+
+ }
+ } while ((pairOne == null || pairTwo == null) && --tries > 0);
+ return opponents;
+ }
+
+ public int getRegisteredCount() {
+ return registered.size();
+ }
+
+ private class Pair {
+ private L2PcInstance leader, assist;
+
+ public Pair(L2PcInstance leader, L2PcInstance assist) {
+ this.leader = leader;
+ this.assist = assist;
+ }
+
+ public L2PcInstance getAssist() {
+ return assist;
+ }
+
+ public L2PcInstance getLeader() {
+ return leader;
+ }
+
+ /*
+ * This method send messages to player, but not implement the remotion.
+ * must be removed from caller
+ *
+ */
+ public boolean check(){
+ if((leader == null || leader.isOnline()==0) && (assist != null && assist.isOnline()==1)) {
+ assist.sendMessage("ArenaEventManager: You participation in Event was Canceled");
+ return false;
+ } else if( (assist == null || assist.isOnline()==0) && (leader != null && leader.isOnline()==1)) {
+ leader.sendMessage("ArenaEventManager: You participation in Event was Canceled");
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isAlive() {
+ if((leader == null || leader.isOnline()==0) && (assist==null || assist.isOnline()==0)){
+ return false;
+ } else if((leader == null || leader.isOnline()==0)) {
+ return !assist.isDead();
+ } else if((assist == null || assist.isOnline()==0)) {
+ return !leader.isDead();
+ }
+ return !(leader.isDead() && assist.isDead());
+ }
+
+ public void teleportTo(int x, int y, int z) {
+ if(leader != null) {
+ leader.restoreCP();
+ leader.restoreHPMP();
+ leader.teleToLocation(x, y, z);
+ }
+ if(assist != null) {
+ assist.restoreCP();
+ assist.restoreHPMP();
+ assist.teleToLocation(x, y, z);
+ }
+ }
+
+ public void rewards() {
+ if(leader != null) {
+ leader.getInventory().addItem("Arena_Event", Config.ARENA_REWARD_ID, Config.ARENA_REWARD_COUNT, leader, null);
+ leader.sendPacket( new ItemList(leader, true));
+ leader.increaseArenaWins();
+ }
+ if(assist != null) {
+ assist.getInventory().addItem("Arena_Event",  Config.ARENA_REWARD_ID, Config.ARENA_REWARD_COUNT, assist, null);
+ assist.sendPacket( new ItemList(assist, true));
+ assist.increaseArenaWins();
+ }
+ sendMessage("Arena Event Manager: You Win!!!");
+ }
+
+ public void setInEvent(boolean val) {
+ if(leader != null)
+ leader.setInArenaEvent(val);
+ if(assist != null)
+ assist.setInArenaEvent(val);
+ }
+
+ public void revive() {
+ if(leader != null)
+ leader.doRevive();
+ if(assist != null)
+ assist.doRevive();
+ }
+
+ public void setImobilised(boolean val) {
+ if(leader != null) {
+ leader.setIsInvul(val);
+ leader.setIsImobilised(val);
+ }
+ if(assist != null) {
+ assist.setIsInvul(val);
+ assist.setIsImobilised(val);
+ }
+ }
+
+ public void sendMessage(String msg) {
+ if(leader != null){
+ leader.sendMessage(msg);
+ }
+ if(assist != null) {
+ assist.sendMessage(msg);
+ }
+ }
+
+ public void removeEffects() {
+ if(leader != null) {
+ leader.stopAllEffects();
+ }
+ if(assist != null) {
+ assist.stopAllEffects();
+ }
+ }
+
+ public void increasedefeats() {
+ if(leader != null)
+ leader.increaseArenaDefeats();
+ if(assist != null)
+ assist.increaseArenaDefeats();
+ }
+ }
+
+ private class EvtArenaTask implements Runnable {
+
+ private final Pair pairOne;
+ private final Pair pairTwo;
+ private final int pOneX, pOneY, pOneZ, pTwoX, pTwoY, pTwoZ;
+ private Arena arena;
+
+ public EvtArenaTask(List<Pair> opponents) {
+ pairOne = opponents.get(0);
+ pairTwo = opponents.get(1);
+ L2PcInstance leader = pairOne.getLeader();
+ pOneX = leader.getX();
+ pOneY = leader.getY();
+ pOneZ = leader.getZ();
+ leader = pairTwo.getLeader();
+ pTwoX = leader.getX();
+ pTwoY = leader.getY();
+ pTwoZ = leader.getZ();
+ }
+
+ @Override
+ public void run() {
+ free--;
+ portPairsToArena();
+ pairOne.sendMessage("The battle starts in 20 seconds");
+ pairTwo.sendMessage("The battle starts in 20 seconds");
+ try {
+ Thread.sleep(Config.ARENA_WAIT_INTERVAL);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ pairOne.sendMessage("The battle starts now");
+ pairTwo.sendMessage("The battle starts now");
+ pairOne.setImobilised(false);
+ pairTwo.setImobilised(false);
+
+ while(check()) {
+ // check players status each  seconds
+ try {
+ Thread.sleep(Config.ARENA_CHECK_INTERVAL);
+ } catch (InterruptedException e) {
+ if(Config.ENABLE_ALL_EXCEPTIONS)
+ e.printStackTrace();
+ break;
+ }
+ }
+ finishDuel();
+ free++;
+ }
+
+ private void finishDuel() {
+ fights.remove(arena.id);
+ rewardWinner();
+ pairOne.revive();
+ pairTwo.revive();
+ pairOne.teleportTo(pOneX, pOneY, pOneZ);
+ pairTwo.teleportTo(pTwoX, pTwoY, pTwoZ);
+ pairOne.setInEvent(false);
+ pairTwo.setInEvent(false);
+ arena.setFree(true);
+ }
+
+ private void rewardWinner() {
+ if(pairOne.isAlive() && !pairTwo.isAlive()){
+ pairOne.rewards();
+ pairTwo.increasedefeats();
+ } else if(pairTwo.isAlive() && !pairOne.isAlive()){
+ pairTwo.rewards();
+ pairOne.increasedefeats();
+ }
+ }
+
+ private boolean check() {
+ return (pairOne.isAlive() && pairTwo.isAlive());
+ }
+
+ private void portPairsToArena() {
+ for(Arena arena : arenas) {
+ if(arena.isFree) {
+ this.arena = arena;
+ arena.setFree(false);
+ pairOne.teleportTo(arena.x - 300, arena.y, arena.z);
+ pairTwo.teleportTo(arena.x + 300, arena.y, arena.z);
+ pairOne.removeEffects();
+ pairTwo.removeEffects();
+ pairOne.setImobilised(true);
+ pairTwo.setImobilised(true);
+ pairOne.setInEvent(true);
+ pairTwo.setInEvent(true);
+ fights.put(this.arena.id, pairOne.getLeader().getName() +" vs "+ pairTwo.getLeader().getName());
+ break;
+ }
+ }
+ }
+ }
+
+ private class Arena {
+ protected int x, y, z;
+ protected boolean isFree = true;
+ private int id;
+
+ public Arena(int id, int x, int y, int z) {
+ this.id = id;
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public void setFree(boolean val) {
+ isFree = val;
+ }
+
+ public void addSpectator(L2PcInstance spec) {
+ spec.enterObserverMode(x, y, z);
+ }
+ }
+
+ private static class SingletonHolder {
+ protected static final EvtArenaManager INSTANCE = new EvtArenaManager();
+ }
+}
Index: gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/Action.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/Action.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/Action.java (working copy)
@@ -89,12 +89,14 @@
  }
 
  // Only GMs can directly interact with invisible characters
- if (obj instanceof L2PcInstance
- && (((L2PcInstance)obj).getAppearance().getInvisible())
- && !activeChar.isGM())
- {
- getClient().sendPacket(ActionFailed.STATIC_PACKET);
- return;
+ if (obj instanceof L2PcInstance) {
+ L2PcInstance player = (L2PcInstance)obj;
+ if (player.getAppearance().getInvisible() && !activeChar.isGM()
+ || player.isInArenaEvent() && !activeChar.isInArenaEvent()
+ || !player.isInArenaEvent() && activeChar.isInArenaEvent()) {
+ getClient().sendPacket(ActionFailed.STATIC_PACKET);
+ return;
+ }
  }
 
  // Check if the target is valid, if the player haven't a shop or isn't the requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...)
Index: gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/Logout.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/Logout.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/Logout.java (working copy)
@@ -43,6 +43,12 @@
 
  if (player == null)
  return;
+
+ if (player.isInArenaEvent()) {
+ player.sendMessage("You cannot logou while in Arena Event");
+ player.sendPacket(ActionFailed.STATIC_PACKET);
+ return;
+ }
 
  if (player.isInFunEvent() && !player.isGM())
  {
Index: gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/UseItem.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/UseItem.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/UseItem.java (working copy)
@@ -33,6 +33,7 @@
 import com.l2jfrozen.gameserver.model.L2Object;
 import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
 import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jfrozen.gameserver.model.entity.event.EvtArenaManager;
 import com.l2jfrozen.gameserver.network.SystemMessageId;
 import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
 import com.l2jfrozen.gameserver.network.serverpackets.EtcStatusUpdate;
@@ -155,6 +156,12 @@
  // Items that cannot be used
  if(itemId == 57)
  return;
+
+ if(!Config.ARENA_ALLOW_S && item.getItem().getItemGrade() == L2Item.CRYSTAL_S &&
+ (activeChar.isInArenaEvent() || EvtArenaManager.getInstance().isRegistered(activeChar))){
+ activeChar.sendMessage("Event Arena Manager: Items Grade S cannot be used in Arena Event");
+ return;
+ }
 
  if((itemId == 5858) && (ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()) == null))
  {
Index: gameserver/head-src/com/l2jfrozen/gameserver/network/serverpackets/Die.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/network/serverpackets/Die.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/gameserver/network/serverpackets/Die.java (working copy)
@@ -63,7 +63,7 @@
  _canTeleport = !((TvT.is_started() && player._inEventTvT)
  || (DM.is_started() && player._inEventDM)
  || (CTF.is_started() && player._inEventCTF)
- || player.isInFunEvent()
+ || player.isInFunEvent() || player.isInArenaEvent()
  || player.isPendingRevive());
  }
  _charObjId = cha.getObjectId();
Index: gameserver/head-src/com/l2jfrozen/gameserver/network/L2GameClient.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/network/L2GameClient.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/gameserver/network/L2GameClient.java (working copy)
@@ -842,6 +842,10 @@
  L2PcInstance player = L2GameClient.this.getActiveChar();
  if (player != null) // this should only happen on connection loss
  {
+ if(player.isInArenaEvent()){
+ player.increaseArenaDefeats();
+ player.setXYZ(82698, 148638, -3473);
+ }
  // we store all data from players who are disconnected while in an event in order to restore it in the next login
  if(player.atEvent)
  {
Index: gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java (working copy)
@@ -118,6 +118,7 @@
 import com.l2jfrozen.gameserver.model.entity.Announcements;
 import com.l2jfrozen.gameserver.model.entity.Hero;
 import com.l2jfrozen.gameserver.model.entity.MonsterRace;
+import com.l2jfrozen.gameserver.model.entity.event.EvtArenaManager;
 import com.l2jfrozen.gameserver.model.entity.event.manager.EventManager;
 import com.l2jfrozen.gameserver.model.entity.olympiad.Olympiad;
 import com.l2jfrozen.gameserver.model.entity.sevensigns.SevenSigns;
@@ -166,6 +167,9 @@
  // Local Constants
  final String LOG_FOLDER = "log";
 
+ // Load GameServer Configs
+ Config.load();
+
  // Create log folder
  File logFolder = new File(Config.DATAPACK_ROOT, LOG_FOLDER);
  logFolder.mkdir();
@@ -184,9 +188,6 @@
  // Print L2jfrozen's Logo
  L2Frozen.info();
 
- // Load GameServer Configs
- Config.load();
-
  Util.printSection("Database");
  L2DatabaseFactory.getInstance();
  _log.info("L2DatabaseFactory: loaded.");
@@ -546,6 +547,10 @@
  else
  _log.info("All events are Disabled.");
 
+ if(Config.ARENA_EVENT_ENABLED) {
+ ThreadPoolManager.getInstance().scheduleGeneral(EvtArenaManager.getInstance(), 60000);
+ }
+
  if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
  OfflineTradeTable.restoreOfflineTraders();
 
Index: gameserver/head-src/com/l2jfrozen/Config.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/Config.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/Config.java (working copy)
@@ -616,8 +616,58 @@
  public static int FS_PARTY_MEMBER_COUNT;
  public static boolean ALLOW_QUAKE_SYSTEM;
  public static boolean ENABLE_ANTI_PVP_FARM_MSG;
+
+ public static boolean ARENA_EVENT_ENABLED;
+
+ public static int ARENA_EVENT_COUNT;
+
+ public static int[][] ARENA_EVENT_LOCS;
+
+ public static int ARENA_REWARD_ID;
+
+ public static int ARENA_REWARD_COUNT;
+
+ public static boolean ARENA_ALLOW_S;
+
+ public static int ARENA_CHECK_INTERVAL;
+
+ public static int ARENA_CALL_INTERVAL;
+
+ public static int ARENA_WAIT_INTERVAL;
 
 
+ public static void loadArenaConfig() {
+ try {
+ Properties  arenaSettings = new Properties();
+ InputStream is = new FileInputStream(new File(FService.EVENT_ARENA_FILE));
+ arenaSettings.load(is);
+ is.close();
+
+ ARENA_EVENT_ENABLED = Boolean.parseBoolean(arenaSettings.getProperty("ArenaEventEnabled", "false"));
+ if(ARENA_EVENT_ENABLED) {
+ String[] arenaLocs = arenaSettings.getProperty("ArenasLoc","").split(";");
+ String[] locSplit = null;
+ ARENA_EVENT_COUNT = arenaLocs.length;
+ ARENA_EVENT_LOCS = new int[ARENA_EVENT_COUNT][3];
+ for(int i=0; i < ARENA_EVENT_COUNT; i++) {
+ locSplit = arenaLocs[i].split(",");
+ for(int j=0; j < 3; j++) {
+ ARENA_EVENT_LOCS[i][j] = Integer.parseInt(locSplit[j].trim());
+ }
+ }
+ ARENA_REWARD_ID = Integer.parseInt(arenaSettings.getProperty("ArenaRewardId","57"));
+ ARENA_REWARD_COUNT = Integer.parseInt(arenaSettings.getProperty("ArenaRewardCount", "1"));
+ ARENA_ALLOW_S = Boolean.parseBoolean(arenaSettings.getProperty("ArenaAllowS","false"));
+ ARENA_CHECK_INTERVAL = Integer.parseInt(arenaSettings.getProperty("ArenaBattleCheckInterval","15"))*1000;
+ ARENA_CALL_INTERVAL = Integer.parseInt(arenaSettings.getProperty("ArenaBattleCallInterval","60"))*1000;
+ ARENA_WAIT_INTERVAL = Integer.parseInt(arenaSettings.getProperty("ArenaBattleWaitInterval","20"))*1000;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
  //============================================================
  public static void loadOtherConfig()
  {
@@ -4436,6 +4486,7 @@
 
  // Load network
  loadServerConfig();
+ loadArenaConfig();
 
  // Load system
  loadIdFactoryConfig();
Index: gameserver/head-src/com/l2jfrozen/FService.java
===================================================================
--- gameserver/head-src/com/l2jfrozen/FService.java (revision 938)
+++ gameserver/head-src/com/l2jfrozen/FService.java (working copy)
@@ -71,6 +71,7 @@
  public static final String EVENT_TVT_FILE = "./config/frozen/tvt.properties";
  public static final String EVENT_TW_FILE = "./config/frozen/tw.properties";
  public static final String IRC_FILE = "./config/frozen/irc.properties";
+ public static final String EVENT_ARENA_FILE = "./config/frozen/arena.properties";
 
  //fun -- events
  public static final String AWAY_FILE = "./config/fun/away.properties";

You are not allowed to view links. Register or Login

Abril 17, 2017, 06:03:03 am
Respuesta #1

Desconectado nortim

  • Usuario
  • *
  • Mensajes: 6
  • Karma: 0
poderia adapta-lo para que anuncie com intervalo de tempo, igual do tvt, exemplo: 2 em 2 horas..