L2JMobius

Free Users => Shares/Contributions => Committed User Contributions => Topic started by: AnsS on January 06, 2021, 10:50:37 PM

Title: Reputation gained by clan members leveling
Post by: AnsS on January 06, 2021, 10:50:37 PM
Add reputation score by clan member leveling up.
Information from https://l2wiki.com/classic/Clans_-_Clan_Reputation website.

Code: [Select]
diff --git a/dist/game/config/Feature.ini b/dist/game/config/Feature.ini
index da06353..ff90913 100644
--- a/dist/game/config/Feature.ini
+++ b/dist/game/config/Feature.ini
@@ -163,12 +163,54 @@ FestivalOfDarknessWin = 200
 # Reputation score gained for per hero clan members.
 HeroPoints = 1000
 
-# Minimum Reputation score gained after completing 2nd class transfer under Academy.
+# Minimum Reputation score gained after completing 2nd class transfer under Academy - not used in classic.
 CompleteAcademyMinPoints = 190
 
-# Maximum Reputation score gained after completing 2nd class transfer under Academy.
+# Maximum Reputation score gained after completing 2nd class transfer under Academy - not used in classic.
 CompleteAcademyMaxPoints = 650
 
+# Reputation score gained after level obtained (20-25)
+LevelUp20And25ReputationScore = 4
+
+# Reputation score gained after level obtained (26-30)
+LevelUp26And30ReputationScore = 8
+
+# Reputation score gained after level obtained (31-35)
+LevelUp31And35ReputationScore = 12
+
+# Reputation score gained after level obtained (36-40)
+LevelUp36And40ReputationScore = 16
+
+# Reputation score gained after level obtained (41-45)
+LevelUp41And45ReputationScore = 25
+
+# Reputation score gained after level obtained (46-50)
+LevelUp46And50ReputationScore = 30
+
+# Reputation score gained after level obtained (51-55)
+LevelUp51And55ReputationScore = 35
+
+# Reputation score gained after level obtained (56-60)
+LevelUp56And60ReputationScore = 40
+
+# Reputation score gained after level obtained (61-65)
+LevelUp61And65ReputationScore = 54
+
+# Reputation score gained after level obtained (66-70)
+LevelUp66And70ReputationScore = 63
+
+# Reputation score gained after level obtained (71-75)
+LevelUp71And75ReputationScore = 75
+
+# Reputation score gained after level obtained (76-80)
+LevelUp76And80ReputationScore = 90
+
+# Reputation score gained after level obtained (81+)
+LevelUp81PlusReputationScore = 120
+
+# Reputation score gained after level obtained multiplier
+LevelObtainedReputationScoreMultiplier = 1.0
+
 # Reputation score gained per killed ballista.
 KillBallistaPoints = 500
 
diff --git a/java/org/l2jmobius/Config.java b/java/org/l2jmobius/Config.java
index 5a104fd..363252b 100644
--- a/java/org/l2jmobius/Config.java
+++ b/java/org/l2jmobius/Config.java
@@ -391,6 +391,20 @@ public class Config
  public static int REPUTATION_SCORE_PER_KILL;
  public static int JOIN_ACADEMY_MIN_REP_SCORE;
  public static int JOIN_ACADEMY_MAX_REP_SCORE;
+ public static int LVL_UP_20_AND_25_REP_SCORE;
+ public static int LVL_UP_26_AND_30_REP_SCORE;
+ public static int LVL_UP_31_AND_35_REP_SCORE;
+ public static int LVL_UP_36_AND_40_REP_SCORE;
+ public static int LVL_UP_41_AND_45_REP_SCORE;
+ public static int LVL_UP_46_AND_50_REP_SCORE;
+ public static int LVL_UP_51_AND_55_REP_SCORE;
+ public static int LVL_UP_56_AND_60_REP_SCORE;
+ public static int LVL_UP_61_AND_65_REP_SCORE;
+ public static int LVL_UP_66_AND_70_REP_SCORE;
+ public static int LVL_UP_71_AND_75_REP_SCORE;
+ public static int LVL_UP_76_AND_80_REP_SCORE;
+ public static int LVL_UP_81_PLUS_REP_SCORE;
+ public static double LVL_OBTAINED_REP_SCORE_MULTIPLIER;
  public static int CLAN_LEVEL_6_COST;
  public static int CLAN_LEVEL_7_COST;
  public static int CLAN_LEVEL_8_COST;
@@ -1484,6 +1498,20 @@ public class Config
  REPUTATION_SCORE_PER_KILL = Feature.getInt("ReputationScorePerKill", 1);
  JOIN_ACADEMY_MIN_REP_SCORE = Feature.getInt("CompleteAcademyMinPoints", 190);
  JOIN_ACADEMY_MAX_REP_SCORE = Feature.getInt("CompleteAcademyMaxPoints", 650);
+ LVL_UP_20_AND_25_REP_SCORE = Feature.getInt("LevelUp20And25ReputationScore", 4);
+ LVL_UP_26_AND_30_REP_SCORE = Feature.getInt("LevelUp26And30ReputationScore", 8);
+ LVL_UP_31_AND_35_REP_SCORE = Feature.getInt("LevelUp31And35ReputationScore", 12);
+ LVL_UP_36_AND_40_REP_SCORE = Feature.getInt("LevelUp36And40ReputationScore", 16);
+ LVL_UP_41_AND_45_REP_SCORE = Feature.getInt("LevelUp41And45ReputationScore", 25);
+ LVL_UP_46_AND_50_REP_SCORE = Feature.getInt("LevelUp46And50ReputationScore", 30);
+ LVL_UP_51_AND_55_REP_SCORE = Feature.getInt("LevelUp51And55ReputationScore", 35);
+ LVL_UP_56_AND_60_REP_SCORE = Feature.getInt("LevelUp56And60ReputationScore", 40);
+ LVL_UP_61_AND_65_REP_SCORE = Feature.getInt("LevelUp61And65ReputationScore", 54);
+ LVL_UP_66_AND_70_REP_SCORE = Feature.getInt("LevelUp66And70ReputationScore", 63);
+ LVL_UP_71_AND_75_REP_SCORE = Feature.getInt("LevelUp71And75ReputationScore", 75);
+ LVL_UP_76_AND_80_REP_SCORE = Feature.getInt("LevelUp76And80ReputationScore", 90);
+ LVL_UP_81_PLUS_REP_SCORE = Feature.getInt("LevelUp81PlusReputationScore", 120);
+ LVL_OBTAINED_REP_SCORE_MULTIPLIER = Feature.getDouble("LevelObtainedReputationScoreMultiplier", 1.0d);
  CLAN_LEVEL_6_COST = Feature.getInt("ClanLevel6Cost", 5000);
  CLAN_LEVEL_7_COST = Feature.getInt("ClanLevel7Cost", 10000);
  CLAN_LEVEL_8_COST = Feature.getInt("ClanLevel8Cost", 20000);
diff --git a/java/org/l2jmobius/gameserver/model/actor/stat/PlayableStat.java b/java/org/l2jmobius/gameserver/model/actor/stat/PlayableStat.java
index b021688..a04537e 100644
--- a/java/org/l2jmobius/gameserver/model/actor/stat/PlayableStat.java
+++ b/java/org/l2jmobius/gameserver/model/actor/stat/PlayableStat.java
@@ -25,11 +25,16 @@ import org.l2jmobius.gameserver.data.xml.impl.SkillTreeData;
 import org.l2jmobius.gameserver.model.actor.Playable;
 import org.l2jmobius.gameserver.model.actor.instance.PetInstance;
 import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+import org.l2jmobius.gameserver.model.clan.Clan;
+import org.l2jmobius.gameserver.model.clan.ClanMember;
 import org.l2jmobius.gameserver.model.events.EventDispatcher;
 import org.l2jmobius.gameserver.model.events.impl.creature.player.OnPlayableExpChanged;
 import org.l2jmobius.gameserver.model.events.returns.TerminateReturn;
 import org.l2jmobius.gameserver.model.items.Weapon;
+import org.l2jmobius.gameserver.model.variables.PlayerVariables;
+import org.l2jmobius.gameserver.network.SystemMessageId;
 import org.l2jmobius.gameserver.network.serverpackets.ExNewSkillToLearnByLevelUp;
+import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
 
 public class PlayableStat extends CreatureStat
 {
@@ -83,14 +88,25 @@ public class PlayableStat extends CreatureStat
  {
  addLevel((byte) (level - getLevel()));
  }
-
- if ((getLevel() > oldLevel) && getActiveChar().isPlayer())
+
+ byte newLevel = getLevel();
+ if ((newLevel > oldLevel) && getActiveChar().isPlayer())
  {
  final PlayerInstance player = getActiveChar().getActingPlayer();
  if (SkillTreeData.getInstance().hasAvailableSkills(player, player.getClassId()))
  {
  getActiveChar().sendPacket(ExNewSkillToLearnByLevelUp.STATIC_PACKET);
  }
+
+ // Check last rewarded level - prevent reputation farming via deleveling
+ int lastPledgedLevel = player.getVariables().getInt(PlayerVariables.LAST_PLEDGE_REPUTATION_LEVEL, 0);
+ if (lastPledgedLevel < newLevel)
+ {
+ int leveledUpCount = newLevel - lastPledgedLevel;
+ addReputationToClanBasedOnLevel(player, leveledUpCount);
+
+ player.getVariables().set(PlayerVariables.LAST_PLEDGE_REPUTATION_LEVEL, (int) newLevel);
+ }
  }
 
  return true;
@@ -254,4 +270,95 @@ public class PlayableStat extends CreatureStat
  final Weapon weapon = getActiveChar().getActiveWeaponItem();
  return weapon != null ? weapon.getBaseAttackAngle() : super.getPhysicalAttackAngle();
  }
+
+ private void addReputationToClanBasedOnLevel(PlayerInstance player, int leveledUpCount)
+ {
+ Clan clan = player.getClan();
+ if (clan == null)
+ {
+ return;
+ }
+
+ if (clan.getLevel() < 3) // When a character from clan level 3 or above increases its level, CRP are added
+ {
+ return;
+ }
+
+ int reputation = 0;
+ for (int i = 0; i < leveledUpCount; i++)
+ {
+ int level = player.getLevel() - i;
+ if (level >= 20 && level <= 25)
+ {
+ reputation += Config.LVL_UP_20_AND_25_REP_SCORE;
+ }
+ else if (level >= 26 && level <= 30)
+ {
+ reputation += Config.LVL_UP_26_AND_30_REP_SCORE;
+ }
+ else if (level >= 31 && level <= 35)
+ {
+ reputation += Config.LVL_UP_31_AND_35_REP_SCORE;
+ }
+ else if (level >= 36 && level <= 40)
+ {
+ reputation += Config.LVL_UP_36_AND_40_REP_SCORE;
+ }
+ else if (level >= 41 && level <= 45)
+ {
+ reputation += Config.LVL_UP_41_AND_45_REP_SCORE;
+ }
+ else if (level >= 46 && level <= 50)
+ {
+ reputation += Config.LVL_UP_46_AND_50_REP_SCORE;
+ }
+ else if (level >= 51 && level <= 55)
+ {
+ reputation += Config.LVL_UP_51_AND_55_REP_SCORE;
+ }
+ else if (level >= 56 && level <= 60)
+ {
+ reputation += Config.LVL_UP_56_AND_60_REP_SCORE;
+ }
+ else if (level >= 61 && level <= 65)
+ {
+ reputation += Config.LVL_UP_61_AND_65_REP_SCORE;
+ }
+ else if (level >= 66 && level <= 70)
+ {
+ reputation += Config.LVL_UP_66_AND_70_REP_SCORE;
+ }
+ else if (level >= 71 && level <= 75)
+ {
+ reputation += Config.LVL_UP_71_AND_75_REP_SCORE;
+ }
+ else if (level >= 76 && level <= 80)
+ {
+ reputation += Config.LVL_UP_76_AND_80_REP_SCORE;
+ }
+ else if (level >= 81 && level <= 120)
+ {
+ reputation += Config.LVL_UP_81_PLUS_REP_SCORE;
+ }
+ }
+
+ if (reputation == 0)
+ {
+ return;
+ }
+
+ reputation = (int) Math.ceil(reputation * Config.LVL_OBTAINED_REP_SCORE_MULTIPLIER);
+
+ clan.addReputationScore(reputation, true);
+
+ for (ClanMember member : clan.getMembers())
+ {
+ if (member.isOnline())
+ {
+ final SystemMessage sm = new SystemMessage(SystemMessageId.YOUR_CLAN_HAS_ADDED_S1_POINT_S_TO_ITS_CLAN_REPUTATION);
+ sm.addInt(reputation);
+ member.getPlayerInstance().sendPacket(sm);
+ }
+ }
+ }
 }
diff --git a/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java b/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java
index 7a40a78..b64b6ff 100644
--- a/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java
+++ b/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java
@@ -63,6 +63,7 @@ public class PlayerVariables extends AbstractVariables
  public static final String FORTUNE_TELLING_BLACK_CAT_VARIABLE = "FortuneTellingBlackCat";
  public static final String DELUSION_RETURN = "DELUSION_RETURN";
  public static final String HUNTING_ZONE_RESET_TIME = "HUNTING_ZONE_RESET_TIME_";
+ public static final String LAST_PLEDGE_REPUTATION_LEVEL = "LAST_PLEDGE_REPUTATION_LEVEL";
 
  private final int _objectId;
 
Title: Re: Reputation gained by clan members leveling
Post by: Mobius on January 06, 2021, 11:02:11 PM
This can become exploitable.
Unless you find a smart way to check levels.
Title: Re: Reputation gained by clan members leveling
Post by: AnsS on January 06, 2021, 11:43:45 PM
You was so fast :)
I edited my post, I fixed multiple lvling in same time not added reputation for all levels.

I mentioned it can be tricked via deleveling :( Should I save to database the highest lvl?
You mean other exploit possibility?
Title: Re: Reputation gained by clan members leveling
Post by: Mobius on January 07, 2021, 12:44:22 AM
Save on a player variable the last level rewarded.

Something like.
Code: [Select]
if (player.getVariables().getInt(PlayerVariables.LAST_PLEDGE_REPUTATION_LEVEL, 0) < player.getLevel())
{
player.getVariables().set(PlayerVariables.LAST_PLEDGE_REPUTATION_LEVEL, player.getLevel());
// Do stuff.
}
Title: Re: Reputation gained by clan members leveling
Post by: AnsS on January 07, 2021, 12:34:01 PM
Thank you for mentioning PlayerVariables, I edited my first post with the modifications.
Title: Re: Reputation gained by clan members leveling
Post by: Mobius on January 18, 2021, 05:29:05 PM
Committed with https://bitbucket.org/MobiusDev/l2j_mobius/commits/97eb0bfa47b9b05367f2162c41b508698751a5c1
Thanks :D