@@ -539,12 +539,14 @@ static{
539539 return store. update(List . of(" monkeyCity" , " " + userID, " pvp" , " " + cityID, " core" ),core- > {
540540 if (core== null )
541541 core = new JSONObject (). put(" attacks" ,new JSONArray ()). put(" timeUntilPacifist" , 0 );
542+ long timeUntilPacifist = 0 ;
542543 for (var attack: Util . jIter(core. getJSONArray(" attacks" ))){
543544 if (attack. getJSONObject(" target" ). getInt(" userID" ) == userID){
544545 // ...
545546 }
546547 if (attack. getJSONObject(" sender" ). optInt(" userID" ) == userID){
547548 int status = attack. getInt(" status" );
549+ timeUntilPacifist = Math . max(timeUntilPacifist, 24l * 3600 * 1000 * 3 + System . currentTimeMillis() - attack. getLong(" timeLaunched" ));
548550 // if(status < AttackStatus.RESOLVED &&
549551 // attack.getLong("expireAt") < System.currentTimeMillis()){
550552 // attack.put("status",AttackStatus.RESOLVED);
@@ -553,7 +555,7 @@ static{
553555 // let clients to that
554556 }
555557 }
556- return core;
558+ return core. put( " timeUntilPacifist " , timeUntilPacifist) ;
557559 });
558560 }
559561 public JSONObject updatePVPCore (int userID , int cityID , UnaryOperator<JSONObject > update ){
@@ -725,13 +727,7 @@ static{
725727 <%!public JSONObject sendAttack(int userID, int cityID, JSONObject payload) {
726728 var sender = payload.getJSONObject("sender");
727729 var target = payload.getJSONObject("target");
728- updatePVPCore(userID, cityID, x->
729- x.put (
730- "timeUntilPacifist ", 24l *3600 *3 *1000 // no 1500 honor check(in client)
731- ).put (
732- "pacifist ", false
733- )
734- );
730+ exitPacifist(userID, cityID);
735731 addToQueue(userID, cityID, sender.getInt("cityLevel"), sender.getInt("honour"));
736732 long now = System .currentTimeMillis();
737733 payload.put("attackID", "" + ThreadLocalRandom .current().nextLong())
@@ -751,15 +747,28 @@ static{
751747 //update sender timeUntilPacifist?
752748 return new JSONObject ().put("success", true);
753749 }
750+ public JSONObject exitPacifist(int userID, int cityID){
751+ return updatePVPCore(userID, cityID, x->
752+ x.put (
753+ "timeUntilPacifist ", 24l *3600 *3 *1000 // no 1500 honor check(in client)
754+ ).put (
755+ "pacifist ", false
756+ )
757+ );
758+ }
754759 public JSONObject enterPacifist(int userID, int cityID){
755760 // literally do nothing??? this gets sent regardless of if the user clicks yes or no
761+ long timeUntilPacifist = getPVPCore(userID, cityID). getLong(" timeUntilPacifist" );
762+ if (timeUntilPacifist == 0 )
763+ updatePVPCore(userID, cityID, x- > x. put(" pacifist" , true ));
756764 return new JSONObject ();
757765 }
758766 public JSONObject quickMatch(int userID, int cityID, int level, int honor){
759767 return findMatch(userID, cityID, level, honor);
760768 }
761769 public JSONObject findMatch(int userID, int cityID, int level, int honor){
762770 addToQueue(userID, cityID, level, honor);
771+ exitPacifist(userID, cityID);
763772 List<JSONObject > candidates = new ArrayList<> ();
764773 store. update(List . of(" monkeyCity" ," pvp" ," " + cityID," queue" ),queue- > {
765774 if (queue== null )
@@ -770,7 +779,7 @@ static{
770779 var e = q. getJSONObject(i);
771780 int eLevel = e. getInt(" level" );
772781 int range = (int ) (Math . max(level,eLevel)* 0.25 ) + 1 ;
773- // TODO: pacifist mode should remove from queue
782+
774783 if (e. getInt(" userID" ) == userID || Math . abs(e. getInt(" level" ) - level) > range)
775784 continue ;
776785 candidates. add(e);
@@ -788,6 +797,8 @@ static{
788797 for (var e : candidates) {
789798 int eID = e. getInt(" userID" );
790799 var eCore = getPVPCore(eID, cityID);
800+ if (eCore. optBoolean(" pacifist" ))
801+ continue ;
791802 var eAttacks = eCore. getJSONArray(" attacks" );
792803 int nAttacks = (int ) Util . jStream(eAttacks)
793804 .filter(x - > x. getJSONObject(" target" ). getInt(" userID" ) == eID)
@@ -797,7 +808,6 @@ static{
797808 .filter(x - > x. getJSONObject(" target" ). getInt(" userID" ) == eID)
798809 .filter(x - > x. getJSONObject(" sender" ). getInt(" userID" ) == userID)
799810 .mapToLong(x - > x. getLong(" timeLaunched" )). max(). orElse(0 );
800- System . out. println(lastAttackedBy);
801811 if (nAttacks > 5 || System . currentTimeMillis() - lastAttackedBy < 24l * 3600 * 1000 )
802812 continue ;
803813 // TODO: only do this if attack actually sent
0 commit comments