Skip to content

Commit

Permalink
add health attribute for beast werewolf form
Browse files Browse the repository at this point in the history
- balance form action attributes
  • Loading branch information
Cheaterpaul committed Feb 24, 2021
1 parent a19b014 commit a7c0d9a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 42 deletions.
32 changes: 22 additions & 10 deletions src/main/java/de/teamlapen/werewolves/config/BalanceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public static class Skills {
public final ForgeConfigSpec.DoubleValue beast_form_speed_amount;
public final ForgeConfigSpec.DoubleValue beast_form_armor;
public final ForgeConfigSpec.DoubleValue beast_form_armor_toughness;
public final ForgeConfigSpec.DoubleValue beast_form_health;

public final ForgeConfigSpec.BooleanValue survival_form_enabled;
public final ForgeConfigSpec.IntValue survival_form_cooldown;
Expand Down Expand Up @@ -168,21 +169,32 @@ public static class Skills {

public Skills(ForgeConfigSpec.Builder builder) {
builder.push("werewolf_form");

builder.push("human_form");
this.human_form_enabled = builder.define("human_form_enabled", true);
this.beast_form_enabled = builder.define("beast_form_enabled", true);
this.survival_form_enabled = builder.define("survival_form_enabled", true);
this.human_form_cooldown = builder.comment("In seconds").defineInRange("human_form_cooldown", 0, 0, 10000);
this.human_form_speed_amount = builder.defineInRange("human_form_speed_amount", 0.2, 0, 5);
this.human_form_armor = builder.defineInRange("human_form_armor", 5, 0, 20.0);
this.human_form_armor_toughness = builder.defineInRange("human_form_armor_toughness", 2, 0, 10.0);
builder.pop();

builder.push("beast_form");
this.beast_form_enabled = builder.define("beast_form_enabled", true);
this.beast_form_cooldown = builder.comment("In seconds").defineInRange("beast_form_cooldown", 0, 0, 10000);
this.beast_form_speed_amount = builder.defineInRange("beast_form_speed_amount", 0.4, 0, 5);
this.beast_form_armor = builder.defineInRange("beast_form_armor", 20, 0, 20.0);
this.beast_form_armor_toughness = builder.defineInRange("beast_form_armor_toughness", 8, 0, 10.0);
this.beast_form_health = builder.defineInRange("beast_form_health", 4.0, 0.0, 20.0);
builder.pop();

builder.push("survival_form");
this.survival_form_enabled = builder.define("survival_form_enabled", true);
this.survival_form_cooldown = builder.comment("In seconds").defineInRange("survival_form_cooldown", 0, 0, 10000);
this.human_form_speed_amount = builder.defineInRange("human_form_speed_amount", 0.5, 0, 5);
this.beast_form_speed_amount = builder.defineInRange("beast_form_speed_amount", 0.5, 0, 5);
this.survival_form_speed_amount = builder.defineInRange("survival_form_speed_amount", 0.5, 0, 5);
this.human_form_armor = builder.defineInRange("human_form_armor", 5.0, 0, 10.0);
this.beast_form_armor = builder.defineInRange("beast_form_armor", 5.0, 0, 10.0);
this.survival_form_armor = builder.defineInRange("survival_form_armor", 5.0, 0, 10.0);
this.human_form_armor_toughness = builder.defineInRange("human_form_armor_toughness", 5.0, 0, 10.0);
this.beast_form_armor_toughness = builder.defineInRange("beast_form_armor_toughness", 5.0, 0, 10.0);
this.survival_form_armor_toughness = builder.defineInRange("survival_form_armor_toughness", 5.0, 0, 10.0);
this.survival_form_armor = builder.defineInRange("survival_form_armor", 16, 0, 20.0);
this.survival_form_armor_toughness = builder.defineInRange("survival_form_armor_toughness", 6, 0, 10.0);
builder.pop();

this.werewolf_form_time_limit = builder.comment("Time a player can stay in werewolf form", "In seconds").defineInRange("werewolf_form_time_limit", 50, 1, Long.MAX_VALUE);
builder.pop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import de.teamlapen.vampirism.api.entity.player.skills.ISkill;
import de.teamlapen.werewolves.config.WerewolvesConfig;
import de.teamlapen.werewolves.player.WerewolfForm;
import de.teamlapen.werewolves.player.skill.SimpleWerewolfSkill;
import de.teamlapen.werewolves.player.skill.ActionSkill;
import de.teamlapen.werewolves.player.skill.SimpleWerewolfSkill;
import de.teamlapen.werewolves.player.werewolf.WerewolfPlayer;
import de.teamlapen.werewolves.util.REFERENCE;
import net.minecraft.entity.ai.attributes.AttributeModifier;
Expand Down Expand Up @@ -65,7 +64,7 @@ static void registerWerewolfSkills(IForgeRegistry<ISkill> registry) {
registry.register(new SimpleWerewolfSkill.AttributeSkill("health", true, HEALTH_SKILL, Attributes.MAX_HEALTH, AttributeModifier.Operation.ADDITION, player -> WerewolvesConfig.BALANCE.SKILLS.health_amount.get()));
registry.register(new SimpleWerewolfSkill("health_reg", true));
registry.register(new SimpleWerewolfSkill.AttributeSkill("damage", true, DAMAGE_SKILL, Attributes.ATTACK_DAMAGE, AttributeModifier.Operation.ADDITION, player -> WerewolvesConfig.BALANCE.SKILLS.damage_amount.get()));
registry.register(new SimpleWerewolfSkill.AttributeSkill("resistance", true, RESISTANCE_SKILL, Attributes.ARMOR, AttributeModifier.Operation.ADDITION, player -> WerewolvesConfig.BALANCE.SKILLS.resistance_amount.get()));
registry.register(new SimpleWerewolfSkill("resistance"));
registry.register(new SimpleWerewolfSkill("health_after_kill"));
registry.register(new SimpleWerewolfSkill("stun_bite"));
registry.register(new SimpleWerewolfSkill("bleeding_bite"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.teamlapen.werewolves.player.werewolf.actions;

import de.teamlapen.werewolves.config.WerewolvesConfig;
import de.teamlapen.werewolves.core.WerewolfSkills;
import de.teamlapen.werewolves.player.WerewolfForm;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
Expand All @@ -11,9 +12,10 @@ public class BeastWerewolfFormAction extends WerewolfFormAction {

public BeastWerewolfFormAction() {
super(WerewolfForm.BEAST);
attributes.add(new Modifier(Attributes.ARMOR, UUID.fromString("0b281a87-829f-4d98-9a3b-116549cfdd57"), "beast_form_armor", WerewolvesConfig.BALANCE.SKILLS.beast_form_armor::get, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.MAX_HEALTH, UUID.fromString("5b99db11-01cf-4430-bf41-ff6adc11ccb0"), "beast_form_health", WerewolvesConfig.BALANCE.SKILLS.beast_form_health::get, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.ARMOR, UUID.fromString("0b281a87-829f-4d98-9a3b-116549cfdd57"), "beast_form_armor", () -> WerewolvesConfig.BALANCE.SKILLS.beast_form_armor.get() * 0.8, WerewolvesConfig.BALANCE.SKILLS.beast_form_armor::get, WerewolfSkills.resistance, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.ARMOR_TOUGHNESS, UUID.fromString("f47e2130-39c4-496f-8d47-572abdc03920"), "beast_form_armor_toughness", WerewolvesConfig.BALANCE.SKILLS.beast_form_armor_toughness::get, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.MOVEMENT_SPEED, UUID.fromString("e9748d20-a9a5-470c-99a4-44167df71aa5"), "beast_form_speed_amount", WerewolvesConfig.BALANCE.SKILLS.beast_form_speed_amount::get, AttributeModifier.Operation.MULTIPLY_TOTAL));
attributes.add(new Modifier(Attributes.MOVEMENT_SPEED, UUID.fromString("e9748d20-a9a5-470c-99a4-44167df71aa5"), "beast_form_speed_amount", () -> WerewolvesConfig.BALANCE.SKILLS.beast_form_speed_amount.get() * 0.8, WerewolvesConfig.BALANCE.SKILLS.beast_form_speed_amount::get, WerewolfSkills.speed, AttributeModifier.Operation.MULTIPLY_TOTAL));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.teamlapen.werewolves.player.werewolf.actions;

import de.teamlapen.werewolves.config.WerewolvesConfig;
import de.teamlapen.werewolves.core.WerewolfSkills;
import de.teamlapen.werewolves.player.WerewolfForm;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
Expand All @@ -11,9 +12,9 @@ public class HumanWerewolfFormAction extends WerewolfFormAction {

public HumanWerewolfFormAction() {
super(WerewolfForm.HUMAN);
attributes.add(new Modifier(Attributes.ARMOR, UUID.fromString("9fe8cf0f-e3d1-47f6-ba69-db13920640e1"), "human_form_armor", WerewolvesConfig.BALANCE.SKILLS.human_form_armor::get, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.ARMOR, UUID.fromString("9fe8cf0f-e3d1-47f6-ba69-db13920640e1"), "human_form_armor", () -> WerewolvesConfig.BALANCE.SKILLS.human_form_armor.get() * 0.8, WerewolvesConfig.BALANCE.SKILLS.human_form_armor::get, WerewolfSkills.resistance, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.ARMOR_TOUGHNESS, UUID.fromString("ae1e52d0-5982-4657-8260-345460e6e02d"), "human_form_armor_toughness", WerewolvesConfig.BALANCE.SKILLS.human_form_armor_toughness::get, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.MOVEMENT_SPEED, UUID.fromString("f30e65e0-69b0-430c-ae94-8086a7870e63"), "human_form_speed_amount", WerewolvesConfig.BALANCE.SKILLS.human_form_speed_amount::get, AttributeModifier.Operation.MULTIPLY_TOTAL));
attributes.add(new Modifier(Attributes.MOVEMENT_SPEED, UUID.fromString("f30e65e0-69b0-430c-ae94-8086a7870e63"), "human_form_speed_amount", () -> WerewolvesConfig.BALANCE.SKILLS.human_form_speed_amount.get() * 0.8, WerewolvesConfig.BALANCE.SKILLS.human_form_speed_amount::get, WerewolfSkills.speed, AttributeModifier.Operation.MULTIPLY_TOTAL));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,18 @@
import de.teamlapen.werewolves.config.WerewolvesConfig;
import de.teamlapen.werewolves.core.WerewolfSkills;
import de.teamlapen.werewolves.player.WerewolfForm;
import de.teamlapen.werewolves.player.werewolf.WerewolfPlayer;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
import net.minecraft.entity.player.PlayerEntity;
import org.apache.commons.lang3.tuple.Triple;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;

import static de.teamlapen.werewolves.player.ModPlayerEventHandler.CLAWS;

public class SurvivalWerewolfFormAction extends WerewolfFormAction {

public SurvivalWerewolfFormAction() {
super(WerewolfForm.SURVIVALIST);
attributes.add(new Modifier(Attributes.ARMOR, UUID.fromString("d45bf864-acab-4fb9-9440-0319483e7fdb"), "survival_form_armor", WerewolvesConfig.BALANCE.SKILLS.survival_form_armor::get, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.ARMOR, UUID.fromString("d45bf864-acab-4fb9-9440-0319483e7fdb"), "survival_form_armor", () -> WerewolvesConfig.BALANCE.SKILLS.survival_form_armor.get() * 0.8, WerewolvesConfig.BALANCE.SKILLS.survival_form_armor::get, WerewolfSkills.resistance, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.ARMOR_TOUGHNESS, UUID.fromString("ad6a329c-5ca0-4b7b-8bd5-f3f17f3fba00"), "survival_form_armor_toughness", WerewolvesConfig.BALANCE.SKILLS.survival_form_armor_toughness::get, AttributeModifier.Operation.ADDITION));
attributes.add(new Modifier(Attributes.MOVEMENT_SPEED, UUID.fromString("429ac45a-05e7-4102-b506-e1f1a3a6aca9"), "survival_form_armor_speed", WerewolvesConfig.BALANCE.SKILLS.survival_form_speed_amount::get, AttributeModifier.Operation.MULTIPLY_TOTAL));
attributes.add(new Modifier(Attributes.MOVEMENT_SPEED, UUID.fromString("429ac45a-05e7-4102-b506-e1f1a3a6aca9"), "survival_form_armor_speed", () -> WerewolvesConfig.BALANCE.SKILLS.survival_form_speed_amount.get() * 0.8, WerewolvesConfig.BALANCE.SKILLS.survival_form_speed_amount::get, WerewolfSkills.speed, AttributeModifier.Operation.MULTIPLY_TOTAL));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.teamlapen.vampirism.api.entity.player.actions.IActionHandler;
import de.teamlapen.vampirism.api.entity.player.actions.ILastingAction;
import de.teamlapen.vampirism.api.entity.player.skills.ISkill;
import de.teamlapen.werewolves.config.WerewolvesConfig;
import de.teamlapen.werewolves.core.ModBiomes;
import de.teamlapen.werewolves.player.IWerewolfPlayer;
Expand All @@ -12,15 +13,13 @@
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
import net.minecraft.entity.player.PlayerEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nonnull;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;

public abstract class WerewolfFormAction extends DefaultWerewolfAction implements ILastingAction<IWerewolfPlayer> {
private static final Logger LOGGER = LogManager.getLogger();
private static final Set<WerewolfFormAction> ALL_ACTION = new HashSet<>();


Expand All @@ -45,19 +44,27 @@ protected static class Modifier {
public final Attribute attribute;
public final UUID uuid;
public final String name;
public final Supplier<Double> value;
public final Function<WerewolfPlayer, Double> value;
public final AttributeModifier.Operation operation;

public Modifier(Attribute attribute, UUID uuid, String name, Supplier<Double> value, AttributeModifier.Operation operation) {
public Modifier(Attribute attribute, UUID uuid, String name, Supplier<Double> valueFunction, AttributeModifier.Operation operation) {
this(attribute, uuid, name, player -> valueFunction.get(), operation);
}

public Modifier(Attribute attribute, UUID uuid, String name, Supplier<Double> valueFunction, Supplier<Double> extendedValueFunction, ISkill extendedSkill, AttributeModifier.Operation operation) {
this(attribute, uuid, name, player -> player.getSkillHandler().isSkillEnabled(extendedSkill) ? extendedValueFunction.get() : valueFunction.get(), operation);
}

public Modifier(Attribute attribute, UUID uuid, String name, Function<WerewolfPlayer, Double> valueFunction, AttributeModifier.Operation operation) {
this.attribute = attribute;
this.uuid = uuid;
this.name = name;
this.value = value;
this.value = valueFunction;
this.operation = operation;
}

public AttributeModifier create(){
return new AttributeModifier(uuid, name, value.get(), operation);
public AttributeModifier create(WerewolfPlayer player) {
return new AttributeModifier(uuid, name, value.apply(player), operation);
}
}

Expand All @@ -74,7 +81,7 @@ public WerewolfFormAction(@Nonnull WerewolfForm form) {
protected boolean activate(IWerewolfPlayer werewolfPlayer) {
((WerewolfPlayer) werewolfPlayer).setForm(this, this.form);
((WerewolfPlayer) werewolfPlayer).activateWerewolfForm();
this.applyModifier(werewolfPlayer.getRepresentingPlayer());
this.applyModifier(((WerewolfPlayer) werewolfPlayer));
return true;
}

Expand All @@ -88,7 +95,7 @@ public void onActivatedClient(IWerewolfPlayer werewolfPlayer) {
public void onDeactivated(IWerewolfPlayer werewolfPlayer) {
((WerewolfPlayer) werewolfPlayer).setForm(this, WerewolfForm.NONE);
((WerewolfPlayer) werewolfPlayer).deactivateWerewolfForm();
this.removeModifier(werewolfPlayer.getRepresentingPlayer());
this.removeModifier(((WerewolfPlayer) werewolfPlayer));
}

@Override
Expand All @@ -104,16 +111,18 @@ public boolean onUpdate(IWerewolfPlayer werewolfPlayer) {
return ++((WerewolfPlayer) werewolfPlayer).getSpecialAttributes().werewolfTime > WerewolvesConfig.BALANCE.SKILLS.werewolf_form_time_limit.get() * 20;
}

public void applyModifier(PlayerEntity player) {
public void applyModifier(WerewolfPlayer werewolf) {
PlayerEntity player = werewolf.getRepresentingPlayer();
for (Modifier attribute : this.attributes) {
ModifiableAttributeInstance ins = player.getAttribute(attribute.attribute);
if (ins != null && ins.getModifier(attribute.uuid) == null) {
ins.applyPersistentModifier(attribute.create());
ins.applyPersistentModifier(attribute.create(werewolf));
}
}
}

public void removeModifier(PlayerEntity player){
public void removeModifier(WerewolfPlayer werewolf) {
PlayerEntity player = werewolf.getRepresentingPlayer();
for (Modifier attribute : this.attributes) {
ModifiableAttributeInstance ins = player.getAttribute(attribute.attribute);
if (ins != null) {
Expand Down

0 comments on commit a7c0d9a

Please sign in to comment.