Territory war timers

Issue #42 new
DoctorVal created an issue

i think there is a logic mistake when territory war load time for next week and territory wars occurs every week instead of 2 weeks cycle

http://prntscr.com/ckhbma

Comments (4)

  1. Avanael

    This is because the next date is not being set at the end of territory war. Instead it's being set the next time TerritoryWarSuperClass.java is called and it's not happening until server restart. For many servers, daily restart is a common thing in which case the code sets the date on the next weekend and thus the before check, where 2 weeks are added in advance, never happens.

    Here's how I fixed it (censored my server in the comments there, so don't mind it.. it's how I document anything I change within a commit):

    diff --git a/dist/game/data/scripts/quests/TerritoryWarScripts/TerritoryWarSuperClass.java b/dist/game/data/scripts/quests/TerritoryWarScripts/TerritoryWarSuperClass.java
    index 93ecfe2..6a110bb 100644
    --- a/dist/game/data/scripts/quests/TerritoryWarScripts/TerritoryWarSuperClass.java
    +++ b/dist/game/data/scripts/quests/TerritoryWarScripts/TerritoryWarSuperClass.java
    @@ -22,7 +22,6 @@
     import java.util.HashMap;
     import java.util.Map;
    
    -import com.l2jserver.gameserver.instancemanager.GlobalVariablesManager;
     import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
     import com.l2jserver.gameserver.instancemanager.TerritoryWarManager.TerritoryNPCSpawn;
     import com.l2jserver.gameserver.model.L2Object;
    @@ -76,33 +75,9 @@
                addSkillSeeId(36590);
    
                // Calculate next TW date
    -           final Calendar cal = Calendar.getInstance();
    -           
    -           final long nextSiegeDate = GlobalVariablesManager.getInstance().getLong(TerritoryWarManager.GLOBAL_VARIABLE, 0);
    -           if (nextSiegeDate > System.currentTimeMillis())
    -           {
    -               cal.setTimeInMillis(nextSiegeDate);
    -           }
    -           else
    -           {
    -               // Let's check if territory war date was in the past
    -               if (cal.before(Calendar.getInstance()))
    -               {
    -                   cal.setTimeInMillis(System.currentTimeMillis());
    -               }
    -
    -               boolean hasOwnedCastle = CastleManager.getInstance().hasOwnedCastle();
    -               cal.set(Calendar.DAY_OF_WEEK, hasOwnedCastle ? Calendar.SATURDAY : Calendar.SUNDAY);
    -               cal.set(Calendar.HOUR_OF_DAY, hasOwnedCastle ? 20 : 22);
    -               cal.set(Calendar.MINUTE, 0);
    -               cal.set(Calendar.SECOND, 0);
    -               if (cal.before(Calendar.getInstance()))
    -               {
    -                   cal.add(Calendar.WEEK_OF_YEAR, 2);
    -               }
    -               GlobalVariablesManager.getInstance().set(TerritoryWarManager.GLOBAL_VARIABLE, cal.getTimeInMillis());
    -           }
    -           TerritoryWarManager.getInstance().setTWStartTimeInMillis(cal.getTimeInMillis());
    -           _log.info(getClass().getSimpleName() + ": Siege date: " + cal.getTime());
    +           // L2XXXX Custom: Repositioned Code for next TW date to TerritoryWarManager
    +           TerritoryWarManager.getInstance().setNextTWDate();
    +           _log.info(getClass().getSimpleName() + ": Siege date: " + TerritoryWarManager.getInstance().getTWStart().getTime());
            }
        }
    
    diff --git a/src/main/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java b/src/main/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java
    index d439089..4ed876c 100644
    --- a/src/main/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java
    +++ b/src/main/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java
    @@ -1119,10 +1119,45 @@
                }
            }
            // change next TW date
    +       // L2XXXX Custom: Added missing set next date after TW ends
    +       setNextTWDate();
            SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.TERRITORY_WAR_HAS_ENDED);
            Broadcast.toAllOnlinePlayers(sm);
        }
    
    +   /*
    +    * L2XXXX Custom: Repositioned code for next TW date from TerritoryWarSuperClass
    +    */
    +   public void setNextTWDate()
    +   {
    +       final Calendar cal = Calendar.getInstance();
    +       
    +       final long nextSiegeDate = GlobalVariablesManager.getInstance().getLong(GLOBAL_VARIABLE, 0);
    +       if (nextSiegeDate > System.currentTimeMillis())
    +       {
    +           cal.setTimeInMillis(nextSiegeDate);
    +       }
    +       else
    +       {
    +           // Let's check if territory war date was in the past
    +           if (cal.before(Calendar.getInstance()))
    +           {
    +               cal.setTimeInMillis(System.currentTimeMillis());
    +           }
    +           
    +           boolean hasOwnedCastle = CastleManager.getInstance().hasOwnedCastle();
    +           cal.set(Calendar.DAY_OF_WEEK, hasOwnedCastle ? Calendar.SATURDAY : Calendar.SUNDAY);
    +           cal.set(Calendar.HOUR_OF_DAY, hasOwnedCastle ? 20 : 22);
    +           cal.set(Calendar.MINUTE, 0);
    +           cal.set(Calendar.SECOND, 0);
    +           if (cal.before(Calendar.getInstance()))
    +           {
    +               cal.add(Calendar.WEEK_OF_YEAR, 2);
    +           }
    +           GlobalVariablesManager.getInstance().set(GLOBAL_VARIABLE, cal.getTimeInMillis());
    +       }
    +       setTWStartTimeInMillis(cal.getTimeInMillis());
    +   }
    +   
        protected boolean updatePlayerTWStateFlags(boolean clear)
        {
            Quest twQuest = QuestManager.getInstance().getQuest(qn);
    
  2. ShinichiYao

    should it be also castle owned checked?

        public void setNextTWDate()
        {
            final Calendar cal = Calendar.getInstance();
    
            final long nextSiegeDate = GlobalVariablesManager.getInstance().getLong(GLOBAL_VARIABLE, 0);
            if (nextSiegeDate > System.currentTimeMillis())
            {
                cal.setTimeInMillis(nextSiegeDate);
            }
            else
            {
                // Let's check if territory war date was in the past
                if (cal.before(Calendar.getInstance()))
                {
                    cal.setTimeInMillis(System.currentTimeMillis());
                }
    
                boolean hasOwnedCastle = CastleManager.getInstance().hasOwnedCastle();
                cal.set(Calendar.DAY_OF_WEEK, hasOwnedCastle ? Calendar.SATURDAY : Calendar.SUNDAY);
                cal.set(Calendar.HOUR_OF_DAY, hasOwnedCastle ? 20 : 22);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                if (cal.before(Calendar.getInstance()))
                {
                    cal.add(Calendar.WEEK_OF_YEAR, 2);
                }
                GlobalVariablesManager.getInstance().set(GLOBAL_VARIABLE, cal.getTimeInMillis());
            }
            setTWStartTimeInMillis(cal.getTimeInMillis());
        }
    
  3. Avanael

    You're right.. I didn't think of that, because I deleted that part of code.. I feel stupid right now :P I'm glad you catched that, edited my previous post, thanks.

  4. Log in to comment