Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.mojang.authlib.GameProfile;
import gg.norisk.ffa.server.mechanics.KitEditor;
import gg.norisk.ffa.server.mechanics.SoupHealing;
import gg.norisk.ffa.server.mechanics.TeamNerf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -13,17 +16,15 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity {
public ServerPlayerEntityMixin(World world, BlockPos blockPos, float f, GameProfile gameProfile) {
super(world, blockPos, f, gameProfile);
}

@Inject(
method = "swingHand",
at = @At("HEAD")
)
@Inject(method = "swingHand", at = @At("HEAD"))
public void onSwing(Hand hand, CallbackInfo ci) {
if (!KitEditor.INSTANCE.isUHC()) {
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
Expand All @@ -33,4 +34,18 @@ public void onSwing(Hand hand, CallbackInfo ci) {
}
}
}

@Inject(method = "attack", at = @At("HEAD"))
public void onAttack(Entity target, CallbackInfo ci) {
if (target instanceof PlayerEntity) {
TeamNerf.INSTANCE.onAttack(this, (PlayerEntity) target);
}
}

@Inject(method = "getDamageAgainst", at = @At("RETURN"), cancellable = true)
public void onGetDamageAgainst(Entity target, float baseDamage, DamageSource damageSource, CallbackInfoReturnable<Float> cir) {
if (target instanceof ServerPlayerEntity) {
cir.setReturnValue(TeamNerf.INSTANCE.getDamageAgainst((PlayerEntity) target, cir.getReturnValue()));
}
}
}
2 changes: 2 additions & 0 deletions ffa-server/src/main/kotlin/gg/norisk/ffa/server/FFAServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import gg.norisk.ffa.server.mechanics.Bounty
import gg.norisk.ffa.server.mechanics.CombatTag
import gg.norisk.ffa.server.mechanics.KillManager
import gg.norisk.ffa.server.mechanics.KitEditor
import gg.norisk.ffa.server.mechanics.TeamNerf
import gg.norisk.ffa.server.selector.SelectorServerManager
import gg.norisk.ffa.server.world.MapPlacer
import gg.norisk.ffa.server.world.WorldManager
Expand All @@ -35,6 +36,7 @@ object FFAServer : ModInitializer {
CombatTag.init()
KillManager.init()
InvseeCommand.init()
TeamNerf.init()
}

const val FFA_KEY = "hero-ffa"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gg.norisk.ffa.server.mechanics

import net.minecraft.entity.player.PlayerEntity
import net.silkmc.silk.core.task.mcCoroutineTask
import kotlin.math.pow
import kotlin.time.DurationUnit
import kotlin.time.toDuration

object TeamNerf {
val hits: MutableMap<PlayerEntity, MutableMap<PlayerEntity, Long>> = mutableMapOf()

fun init() {
mcCoroutineTask(sync = true, client = false, period = 1.toDuration(DurationUnit.SECONDS)) {
hits.forEach {
val player = it.key
if (!player.isAlive) {
hits.remove(player)
return@forEach
}
val hitMap = it.value
hitMap.forEach { target, time ->
if (!target.isAlive || player.world != target.world || player.distanceTo(target) > 20) {
hitMap.remove(target)
}
}
}
}
}

fun onAttack(player: PlayerEntity, target: PlayerEntity) {
if (player == target) {
return
}
if (!hits.contains(player)) {
hits[player] = mutableMapOf()
}
val hits = hits[player]!!
hits[target] = System.currentTimeMillis()
}

fun getDamageAgainst(target: PlayerEntity, damage: Float): Float {
val hits = hits[target] ?: mapOf()
var teamSize = 0
for (hit in hits) {
if (hit.value + 1000*10 > System.currentTimeMillis()) {
teamSize++
}
}
return if (teamSize > 1) damage * teamSize.toFloat().pow(-0.8f) else damage
}
}