Browse Source

Summon amount limits and new ability

TfT_02 11 năm trước cách đây
mục cha
commit
c31281971c

+ 1 - 1
src/main/java/com/gmail/nossr50/config/Config.java

@@ -498,8 +498,8 @@ public class Config extends AutoUpdateConfigLoader {
     public int getTamingCOTWCost(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Amount"); }
     public int getTamingCOTWAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Summon_Amount"); }
     public int getTamingCOTWLength(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ ".Summon_Length"); }
+    public int getTamingCOTWMaxAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ ".Summon_Max_Amount"); }
     public double getTamingCOTWRange() { return config.getDouble("Skills.Taming.Call_Of_The_Wild.Range", 40.0D); }
-    public int getTamingCOTWMaxAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ "_MaxAmount"); }
 
     /* Woodcutting */
     public boolean getWoodcuttingDoubleDropsEnabled(TreeSpecies species) { return config.getBoolean("Double_Drops.Woodcutting." + StringUtils.getPrettyTreeSpeciesString(species).replace(" ", "_")); }

+ 1 - 0
src/main/java/com/gmail/nossr50/datatypes/skills/SecondaryAbility.java

@@ -71,6 +71,7 @@ public enum SecondaryAbility {
     SHARPENED_CLAWS,
     SHOCK_PROOF,
     THICK_FUR,
+    PUMMEL,
 
     /* Unarmed */
     BLOCK_CRACKER,

+ 1 - 1
src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java

@@ -48,7 +48,7 @@ public enum SkillType {
     SALVAGE(SalvageManager.class, Color.ORANGE, ImmutableList.of(SecondaryAbility.ADVANCED_SALVAGE, SecondaryAbility.ARCANE_SALVAGE)),
     SMELTING(SmeltingManager.class, Color.YELLOW, ImmutableList.of(SecondaryAbility.FLUX_MINING, SecondaryAbility.FUEL_EFFICIENCY, SecondaryAbility.SECOND_SMELT)),
     SWORDS(SwordsManager.class, Color.fromRGB(178, 34, 34), AbilityType.SERRATED_STRIKES, ToolType.SWORD, ImmutableList.of(SecondaryAbility.BLEED, SecondaryAbility.COUNTER)),
-    TAMING(TamingManager.class, Color.PURPLE, ImmutableList.of(SecondaryAbility.BEAST_LORE, SecondaryAbility.CALL_OF_THE_WILD, SecondaryAbility.ENVIROMENTALLY_AWARE, SecondaryAbility.FAST_FOOD, SecondaryAbility.GORE, SecondaryAbility.HOLY_HOUND, SecondaryAbility.SHARPENED_CLAWS, SecondaryAbility.SHOCK_PROOF, SecondaryAbility.THICK_FUR)),
+    TAMING(TamingManager.class, Color.PURPLE, ImmutableList.of(SecondaryAbility.BEAST_LORE, SecondaryAbility.CALL_OF_THE_WILD, SecondaryAbility.ENVIROMENTALLY_AWARE, SecondaryAbility.FAST_FOOD, SecondaryAbility.GORE, SecondaryAbility.HOLY_HOUND, SecondaryAbility.SHARPENED_CLAWS, SecondaryAbility.SHOCK_PROOF, SecondaryAbility.THICK_FUR, SecondaryAbility.PUMMEL)),
     UNARMED(UnarmedManager.class, Color.BLACK, AbilityType.BERSERK, ToolType.FISTS, ImmutableList.of(SecondaryAbility.BLOCK_CRACKER, SecondaryAbility.DEFLECT, SecondaryAbility.DISARM, SecondaryAbility.IRON_ARM, SecondaryAbility.IRON_GRIP)),
     WOODCUTTING(WoodcuttingManager.class, Color.OLIVE, AbilityType.TREE_FELLER, ToolType.AXE, ImmutableList.of(SecondaryAbility.LEAF_BLOWER, SecondaryAbility.WOODCUTTING_DOUBLE_DROPS));
 

+ 0 - 16
src/main/java/com/gmail/nossr50/skills/taming/Taming.java

@@ -1,12 +1,8 @@
 package com.gmail.nossr50.skills.taming;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.bukkit.EntityEffect;
 import org.bukkit.entity.AnimalTamer;
 import org.bukkit.entity.EntityType;
-import org.bukkit.entity.LivingEntity;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Tameable;
 import org.bukkit.entity.Wolf;
@@ -16,8 +12,6 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
 import com.gmail.nossr50.locale.LocaleLoader;
 
 public class Taming {
-    private static List<TrackedTamingEntity> trackedEntities = new ArrayList<TrackedTamingEntity>();
-
     public static int environmentallyAwareUnlockLevel = AdvancedConfig.getInstance().getEnviromentallyAwareUnlock();
     public static int holyHoundUnlockLevel            = AdvancedConfig.getInstance().getHolyHoundUnlock();
 
@@ -81,14 +75,4 @@ public class Taming {
                 return "";
         }
     }
-
-    protected static void addToTracker(LivingEntity livingEntity) {
-        TrackedTamingEntity trackedEntity = new TrackedTamingEntity(livingEntity);
-
-        trackedEntities.add(trackedEntity);
-    }
-
-    protected static void removeFromTracker(TrackedTamingEntity trackedEntity) {
-        trackedEntities.remove(trackedEntity);
-    }
 }

+ 66 - 4
src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java

@@ -1,5 +1,9 @@
 package com.gmail.nossr50.skills.taming;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
 import org.bukkit.Location;
 import org.bukkit.Sound;
 import org.bukkit.entity.Entity;
@@ -20,12 +24,14 @@ import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
 import com.gmail.nossr50.datatypes.skills.SkillType;
 import com.gmail.nossr50.datatypes.skills.XPGainReason;
 import com.gmail.nossr50.events.fake.FakeEntityTameEvent;
+import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityWeightedActivationCheckEvent;
 import com.gmail.nossr50.locale.LocaleLoader;
 import com.gmail.nossr50.runnables.skills.BleedTimerTask;
 import com.gmail.nossr50.skills.SkillManager;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.StringUtils;
+import com.gmail.nossr50.util.player.UserManager;
 import com.gmail.nossr50.util.skills.ParticleEffectUtils;
 import com.gmail.nossr50.util.skills.SkillUtils;
 
@@ -34,6 +40,8 @@ public class TamingManager extends SkillManager {
         super(mcMMOPlayer, SkillType.TAMING);
     }
 
+    private static HashMap<EntityType, List<TrackedTamingEntity>> summonedEntities = new HashMap<EntityType, List<TrackedTamingEntity>>();
+
     public boolean canUseThickFur() {
         return getSkillLevel() >= Taming.thickFurUnlockLevel && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.THICK_FUR);
     }
@@ -200,6 +208,26 @@ public class TamingManager extends SkillManager {
         owner.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
     }
 
+    public void pummel(LivingEntity target, Wolf wolf) {
+        double chance = 10 / activationChance;
+        SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(getPlayer(), SecondaryAbility.PUMMEL, chance);
+        mcMMO.p.getServer().getPluginManager().callEvent(event);
+        if ((event.getChance() * activationChance) <= Misc.getRandom().nextInt(activationChance)) {
+            return;
+        }
+
+        ParticleEffectUtils.playGreaterImpactEffect(target);
+        target.setVelocity(wolf.getLocation().getDirection().normalize().multiply(1.5D));
+
+        if (target instanceof Player) {
+            Player defender = (Player) target;
+
+            if (UserManager.getPlayer(defender).useChatNotifications()) {
+                defender.sendMessage("Wolf pummeled at you");
+            }
+        }
+    }
+
     /**
      * Handle the Call of the Wild ability.
      *
@@ -226,6 +254,10 @@ public class TamingManager extends SkillManager {
         int tamingCOTWLength = Config.getInstance().getTamingCOTWLength(type);
 
         for (int i = 0; i < amount; i++) {
+            if (!summonAmountCheck(type)) {
+                return;
+            }
+
             LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(location, type);
 
             FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player);
@@ -239,9 +271,7 @@ public class TamingManager extends SkillManager {
             ((Tameable) entity).setOwner(player);
             entity.setRemoveWhenFarAway(false);
 
-            if (tamingCOTWLength > 0) {
-                Taming.addToTracker(entity);
-            }
+            addToTracker(entity);
 
             switch (type) {
                 case OCELOT:
@@ -270,7 +300,6 @@ public class TamingManager extends SkillManager {
 
             if (Permissions.renamePets(player)) {
                 entity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type)));
-                entity.setCustomNameVisible(true);
             }
 
             ParticleEffectUtils.playCallOfTheWildEffect(entity);
@@ -304,4 +333,37 @@ public class TamingManager extends SkillManager {
 
         return true;
     }
+
+    private boolean summonAmountCheck(EntityType entityType) {
+        Player player = getPlayer();
+
+        int maxAmountSummons = Config.getInstance().getTamingCOTWMaxAmount(entityType);
+
+        if (maxAmountSummons <= 0) {
+            return true;
+        }
+
+        int summonAmount = summonedEntities.get(entityType).size();
+
+        if (summonAmount >= maxAmountSummons) {
+            player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.TooMany", maxAmountSummons));
+            return false;
+        }
+
+        return true;
+    }
+
+    protected static void addToTracker(LivingEntity livingEntity) {
+        TrackedTamingEntity trackedEntity = new TrackedTamingEntity(livingEntity);
+
+        if (!summonedEntities.containsKey(livingEntity.getType())) {
+            summonedEntities.put(livingEntity.getType(), new ArrayList<TrackedTamingEntity>());
+        }
+
+        summonedEntities.get(livingEntity.getType()).add(trackedEntity);
+    }
+
+    protected static void removeFromTracker(TrackedTamingEntity trackedEntity) {
+        summonedEntities.get(trackedEntity.getLivingEntity().getType()).remove(trackedEntity);
+    }
 }

+ 21 - 9
src/main/java/com/gmail/nossr50/skills/taming/TrackedTamingEntity.java

@@ -4,30 +4,43 @@ import java.util.UUID;
 
 import org.bukkit.Location;
 import org.bukkit.Sound;
+import org.bukkit.entity.AnimalTamer;
 import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.Tameable;
 import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
 import org.bukkit.scheduler.BukkitRunnable;
 
 import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.config.Config;
+import com.gmail.nossr50.datatypes.player.McMMOPlayer;
 import com.gmail.nossr50.util.Misc;
+import com.gmail.nossr50.util.player.UserManager;
 import com.gmail.nossr50.util.skills.CombatUtils;
 import com.gmail.nossr50.util.skills.ParticleEffectUtils;
 
 public class TrackedTamingEntity extends BukkitRunnable {
     private LivingEntity livingEntity;
     private UUID id;
-    private long timeStamp;
     private int length;
+    private Player owner;
 
     protected TrackedTamingEntity(LivingEntity livingEntity) {
         this.livingEntity = livingEntity;
         this.id = livingEntity.getUniqueId();
-        this.timeStamp = System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR;
 
-        this.length = Config.getInstance().getTamingCOTWLength(livingEntity.getType()) * Misc.TICK_CONVERSION_FACTOR;
+        AnimalTamer tamer = ((Tameable)livingEntity).getOwner();
 
-        this.runTaskLater(mcMMO.p, length);
+        if (tamer != null && tamer instanceof Player) {
+            this.owner = (Player) tamer;
+        }
+
+        int tamingCOTWLength = Config.getInstance().getTamingCOTWLength(livingEntity.getType());
+
+        if (tamingCOTWLength > 0) {
+            this.length = tamingCOTWLength * Misc.TICK_CONVERSION_FACTOR;
+            this.runTaskLater(mcMMO.p, length);
+        }
     }
 
     @Override
@@ -39,7 +52,10 @@ public class TrackedTamingEntity extends BukkitRunnable {
             CombatUtils.dealDamage(livingEntity, livingEntity.getMaxHealth(), DamageCause.SUICIDE, livingEntity);
         }
 
-        Taming.removeFromTracker(this);
+        McMMOPlayer mcMMOPlayer = UserManager.getPlayer(owner);
+        TamingManager tamingManager = mcMMOPlayer.getTamingManager();
+
+        tamingManager.removeFromTracker(this);
         this.cancel();
     }
 
@@ -50,8 +66,4 @@ public class TrackedTamingEntity extends BukkitRunnable {
     protected UUID getID() {
         return id;
     }
-
-    protected long getTimeStamp() {
-        return timeStamp;
-    }
 }

+ 1 - 0
src/main/java/com/gmail/nossr50/util/Permissions.java

@@ -184,6 +184,7 @@ public final class Permissions {
     /* TAMING */
     public static boolean callOfTheWild(Permissible permissible, EntityType type) { return permissible.hasPermission("mcmmo.ability.taming.callofthewild." + type.toString().toLowerCase()); }
     public static boolean renamePets(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.taming.callofthewild.renamepets"); }
+
     /* UNARMED */
     public static boolean berserk(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.unarmed.berserk"); }
 

+ 2 - 0
src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java

@@ -147,6 +147,8 @@ public final class CombatUtils {
             tamingManager.fastFoodService(wolf, event.getDamage());
         }
 
+        tamingManager.pummel(target, wolf);
+
         if (tamingManager.canUseSharpenedClaws()) {
             finalDamage += tamingManager.sharpenedClaws();
         }

+ 6 - 2
src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java

@@ -34,8 +34,12 @@ public final class ParticleEffectUtils {
             return;
         }
 
-        Location location = player.getEyeLocation();
-        World world = player.getWorld();
+        playSmokeEffect(player);
+    }
+
+    public static void playSmokeEffect(LivingEntity livingEntity) {
+        Location location = livingEntity.getEyeLocation();
+        World world = livingEntity.getWorld();
 
         // Have to do it this way, because not all block directions are valid for smoke
         world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH_EAST);

+ 4 - 0
src/main/resources/advanced.yml

@@ -520,6 +520,10 @@ Skills:
             # MaxHorseJumpStrength: The maximum jump strength a summoned horse can have
             MinHorseJumpStrength: 0.7
             MaxHorseJumpStrength: 2.0
+
+        Pummel:
+            # ChanceMax: Maximum chance of triggering pummel
+            Chance: 10.0
     #
     #  Settings for Unarmed
     ###

+ 4 - 0
src/main/resources/config.yml

@@ -354,21 +354,25 @@ Skills:
             # Item_Amount: Amount of items required to summon the pet
             # Summon_Amount: Amount of pets to summon when using Call Of The Wild
             # Summon_Length: Pets despawn when their summon life length expires
+            # Summon_Max_Amount: Maximum amount of pets that can be summoned at the same time
             Wolf:
                 Item_Material: BONE
                 Item_Amount: 10
                 Summon_Amount: 1
                 Summon_Length: 240
+                Summon_Max_Amount: 10
             Ocelot:
                 Item_Material: RAW_FISH
                 Item_Amount: 10
                 Summon_Amount: 1
                 Summon_Length: 240
+                Summon_Max_Amount: 10
             Horse:
                 Item_Material: APPLE
                 Item_Amount: 10
                 Summon_Amount: 1
                 Summon_Length: 240
+                Summon_Max_Amount: 10
 
             # Range to check for nearby pets when using Call Of The Wild, 0 will disable the check
             Range: 40.0

+ 1 - 0
src/main/resources/locale/locale_en_US.properties

@@ -364,6 +364,7 @@ Taming.Summon.Lifespan=[[YELLOW]] (Lifespan: {0}s)
 Taming.Summon.Fail.Ocelot=[[RED]]You have too many ocelots nearby to summon any more.
 Taming.Summon.Fail.Wolf=[[RED]]You have too many wolves nearby to summon any more.
 Taming.Summon.Fail.Horse=[[RED]]You have too many horses nearby to summon any more.
+Taming.Summon.Fail.TooMany=[[RED]]You have reached the maximum limit of pets to summon. [[YELLOW]]({0})
 Taming.Summon.Name.Format={0}''s {1}
 
 #UNARMED

+ 3 - 0
src/main/resources/plugin.yml

@@ -536,6 +536,7 @@ permissions:
             mcmmo.ability.taming.sharpenedclaws: true
             mcmmo.ability.taming.shockproof: true
             mcmmo.ability.taming.thickfur: true
+            mcmmo.ability.taming.pummel: true
     mcmmo.ability.taming.beastlore:
         description: Allows access to the Beast Lore ability
     mcmmo.ability.taming.callofthewild.*:
@@ -577,6 +578,8 @@ permissions:
         description: Allows access to the Shock Proof ability
     mcmmo.ability.taming.thickfur:
         description: Allows access to the Thick Fur ability
+    mcmmo.ability.taming.pummel:
+        description: Allows access to the Pummel ability
     mcmmo.ability.unarmed.*:
         default: false
         description: Allows access to all Unarmed abilities