Skip to content

Commit

Permalink
Added Riot Shield
Browse files Browse the repository at this point in the history
  • Loading branch information
Odex64 committed Jun 8, 2024
1 parent 79986a6 commit 1ba8891
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 22 deletions.
Binary file modified Content/Data/Images/Weapons/Melee/RiotShieldD.xnb
Binary file not shown.
Binary file modified Content/Data/Images/Weapons/Melee/RiotShieldDHold.xnb
Binary file not shown.
Binary file modified Content/Data/Images/Weapons/Melee/RiotShieldDebris1.xnb
Binary file not shown.
1 change: 0 additions & 1 deletion Content/Data/Images/Weapons/Melee/RiotShieldDebris2.xnb

This file was deleted.

Binary file modified Content/Data/Images/Weapons/Melee/RiotShieldM.xnb
Binary file not shown.
Binary file modified Content/Data/Images/Weapons/Melee/RiotShieldS.xnb
Binary file not shown.
25 changes: 13 additions & 12 deletions Content/Data/Weapons/weapons.sfdx
Original file line number Diff line number Diff line change
Expand Up @@ -2956,18 +2956,19 @@ Tile(WpnSwitchblade)
mass = 2.5 kg;
}
}
//Tile(WpnRiotShield)
//{
// tileTexture = RiotShieldM;
// pickupType = instant;
// pickupRange = 10.0;
// absorbProjectile = false;
// projectileHit = false;
// impactEffect = ImpactDefault;
// impactSound = WeaponBounce;
// missileDamageMax = 17|17;
// fixture(){ collisionPoints = (-8.5, -3.5), (7.5, -3.5), (7.5, 6.5), (-8.5, 6.5); mass = 2.5kg; }
//}

Tile(WpnRiotShield)
{
tileTexture = RiotShieldM;
pickupType = instant;
pickupRange = 10.0;
absorbProjectile = false;
projectileHit = false;
impactEffect = ImpactDefault;
impactSound = WeaponBounce;
missileDamageMax = 17 | 17;
fixture(){ collisionPoints = (-8.5, -3.5), (7.5, -3.5), (7.5, 6.5), (-8.5, 6.5); mass = 2.5kg; }
}

// disable editorEnabled again
defaultTile(default_tile)
Expand Down
99 changes: 94 additions & 5 deletions SFR/Fighter/PlayerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SFR.Misc;
using SFR.Objects;
using SFR.Weapons;
using SFR.Weapons.Melee;
using SFR.Weapons.Rifles;
using Player = SFD.Player;

Expand Down Expand Up @@ -250,17 +251,51 @@ private static void Update(float ms, float realMs, Player __instance)
extendedPlayer.GenericJetpack?.Update(ms, extendedPlayer);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.IsInDeflectBulletFrameWindow), MethodType.Getter)]
private static bool IsInDeflectBulletFrameWindow(Player __instance, ref bool __result)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield)
{
__result = true;
return false;
}

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.CanBeCaughtByGrab))]
private static bool CanBeCaughtByGrab(Player other, Player __instance, ref bool __result)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield)
{
__result = __instance.LastDirectionX == other.LastDirectionX;
return false;
}

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.Movement), MethodType.Setter)]
private static bool SetPlayerMovement(PlayerMovement value, Player __instance)
{
var extendedPlayer = __instance.GetExtension();
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield)
{
__instance.Walking = true;
}

return !extendedPlayer.AdrenalineBoost || __instance.CurrentAction is not PlayerAction.MeleeAttack1 and not PlayerAction.MeleeAttack2 || __instance.Movement == PlayerMovement.Idle || value != PlayerMovement.Idle;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.Jump), [])]
private static bool CanJump(Player __instance)
private static bool Jump(Player __instance)
{
var extendedModifiers = __instance.m_modifiers.GetExtension();
if (extendedModifiers.JumpHeightModifier != 1f)
Expand All @@ -273,14 +308,61 @@ private static bool CanJump(Player __instance)
return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.JumpAttack))]
private static bool JumpAttack(Player __instance)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield) return false;

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.TakeCover))]
private static bool TakeCover(Player __instance)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield) return false;

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.CanRoll))]
private static bool CanRoll(Player __instance)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield) return false;

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.CanCrouch))]
private static bool CanCrouch(Player __instance)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield) return false;

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.CanBlock))]
private static bool CanBlock(Player __instance)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield) return false;

return true;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(Player), nameof(Player.TestProjectileHit))]
private static void CanProjectileHit(ref bool __result, Player __instance)
{
if (!__result)
{
return;
}
if (!__result) return;

var extendedModifiers = __instance.m_modifiers.GetExtension();
if (extendedModifiers.BulletDodgeChance > 0 && Globals.Random.NextDouble() < extendedModifiers.BulletDodgeChance)
Expand Down Expand Up @@ -324,6 +406,13 @@ private static bool ActivateSprint(Player __instance, ref bool __result)
[HarmonyPatch(typeof(Player), nameof(Player.CanKick))]
private static bool CanKick(float timeOffset, Player __instance, ref bool __result)
{
object currentWeapon = __instance.GetCurrentWeapon();
if (currentWeapon is RiotShield)
{
__result = false;
return false;
}

var extendedPlayer = __instance.GetExtension();
__result = (__instance.CurrentAction == PlayerAction.Idle || __instance.CurrentAction == PlayerAction.HipFire && __instance.ThrowableIsActivated) && !(__instance.Diving && !extendedPlayer.AdrenalineBoost || extendedPlayer.GenericJetpack is not null && extendedPlayer.GenericJetpack.State != JetpackState.Idling || __instance.Rolling || __instance.Falling || __instance.Climbing || __instance.PreparingHipFire > 0f || __instance.FireSequence.KickCooldownTimer > 800f + timeOffset || __instance.TimeSequence.PostDropClimbAttackCooldown || __instance.StrengthBoostPreparing || __instance.SpeedBoostPreparing);
return false;
Expand Down
1 change: 1 addition & 0 deletions SFR/SFR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<Compile Include="Weapons\Melee\Blade.cs" />
<Compile Include="Weapons\Melee\Caber.cs" />
<Compile Include="Weapons\Melee\Crowbar.cs" />
<Compile Include="Weapons\Melee\RiotShield.cs" />
<Compile Include="Weapons\Melee\Greatsword.cs" />
<Compile Include="Weapons\Melee\Morningstar.cs" />
<Compile Include="Weapons\Melee\ParryingDagger.cs" />
Expand Down
7 changes: 4 additions & 3 deletions SFR/Weapons/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private static void LoadWeapons()

Weapons ??=
[
// Makeshifts
new(WeaponItemType.Melee, new Brick()), // 71
new(WeaponItemType.Melee, new Broom()), // 72
new(WeaponItemType.Melee, new CannonBall()), // 73
Expand All @@ -40,7 +41,7 @@ private static void LoadWeapons()
new(WeaponItemType.Melee, new ParryingDagger()), // 79
new(WeaponItemType.Melee, new Poleaxe()), // 80
new(WeaponItemType.Melee, new Rapier()), // 81
// new(WeaponItemType.Melee, new RiotShield()), // 82
new(WeaponItemType.Melee, new RiotShield()), // 82
new(WeaponItemType.Melee, new Sledgehammer()), // 83
new(WeaponItemType.Melee, new Switchblade()), // 84
new(WeaponItemType.Melee, new Scythe()), // 108
Expand Down Expand Up @@ -77,7 +78,7 @@ private static void LoadWeapons()
new(WeaponItemType.Powerup, new AdrenalineBoost()), // 103
new(WeaponItemType.InstantPickup, new Jetpack()), // 104
new(WeaponItemType.InstantPickup, new JetpackEditor()), // 105
new(WeaponItemType.InstantPickup, new Gunpack())
new(WeaponItemType.InstantPickup, new Gunpack()) // 106
];

foreach (var weapon in Weapons)
Expand Down Expand Up @@ -181,7 +182,7 @@ private static bool SpawnChance(ref Dictionary<int, int> __result)
{ 79, 8 }, //ParryingDagger
{ 80, 8 }, // Poleaxe
{ 81, 15 }, // Rapier
// { 82, 16 }, // RiotShield,
{ 82, 16 }, // RiotShield,
{ 83, 16 }, // Sledgehammer
{ 84, 18 }, // Switchblade
// { 85, 4 }, // UnkemptHarold
Expand Down
57 changes: 56 additions & 1 deletion SFR/Weapons/IExtendedWeapon.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SFD;
using SFD.Effects;
using SFD.Materials;
using SFD.Sounds;
using SFR.Fighter;
using SFR.Helper;
using SFR.Weapons.Melee;

namespace SFR.Weapons;

Expand Down Expand Up @@ -49,6 +56,54 @@ private static void GetDealtDamage(IEnumerable<ObjectData> objectsHitInMelee, Pl
}
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.HitByMelee))]
private static bool HitByMelee(Player hitBy, Player __instance)
{
object currentWeapon = __instance.GetCurrentWeapon();
bool canHit = __instance.LastDirectionX != hitBy.LastDirectionX || Math.Abs(__instance.Position.X - hitBy.Position.X) < 4f;

hitBy.GetAABBMeleeAttack(out var aabb, false);
var effectPosition = Converter.Box2DToWorld(new Vector2((hitBy.LastDirectionX == 1) ? aabb.upperBound.X : aabb.lowerBound.X, aabb.GetCenter().Y));
if (hitBy.LastDirectionX == 1 && effectPosition.X > __instance.Position.X)
{
effectPosition.X = __instance.Position.X;
}
else if (hitBy.LastDirectionX == -1 && effectPosition.X < __instance.Position.X)
{
effectPosition.X = __instance.Position.X;
}

if (canHit && currentWeapon is RiotShield && !hitBy.IsPerformingGrabAction)
{
EffectHandler.PlayEffect("Block", effectPosition, __instance.GameWorld);

var playerHitMaterial = __instance.GetPlayerHitMaterial();
var material = playerHitMaterial ?? __instance.GetCurrentMeleeWeaponInUse(false).Properties.WeaponMaterial;
Material.HandleMeleeVsMelee(hitBy.GetCurrentMeleeWeaponInUse(false).Properties.WeaponMaterial, material, PlayerHitAction.Punch, effectPosition, __instance.GameWorld);

return false;
}

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.HitByKick))]
private static bool HitByKick(Player hitBy, Player __instance)
{
object currentWeapon = __instance.GetCurrentWeapon();
bool canHit = __instance.LastDirectionX != hitBy.LastDirectionX || Math.Abs(__instance.Position.X - hitBy.Position.X) < 4f;

if (canHit && currentWeapon is RiotShield)
{
SoundHandler.PlaySound("MeleeBlock", __instance.Position, __instance.GameWorld);
return false;
}

return true;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(Player), nameof(Player.HitByMelee))]
private static void OnPlayerHit(Player hitBy, Player __instance)
Expand Down
104 changes: 104 additions & 0 deletions SFR/Weapons/Melee/RiotShield.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Microsoft.Xna.Framework;
using SFD;
using SFD.Effects;
using SFD.Materials;
using SFD.Objects;
using SFD.Sounds;
using SFD.Weapons;

namespace SFR.Weapons.Melee;

internal sealed class RiotShield : MWeapon
{
internal RiotShield()
{
MWeaponProperties weaponProperties = new(82, "RiotShield", 15f, 22f, "MeleeSwing", "MeleeHitBlunt", "HIT_B", "MeleeBlock", "HIT", "MeleeDraw", "WpnRiotShield", true, WeaponCategory.Melee, false)
{
MeleeWeaponType = MeleeWeaponTypeEnum.TwoHanded,
Handling = MeleeHandlingType.Custom,
WeaponMaterial = MaterialDatabase.Get("metal"),
DurabilityLossOnHitObjects = 4f,
DurabilityLossOnHitPlayers = 8f,
DurabilityLossOnHitBlockingPlayers = 4f,
ThrownDurabilityLossOnHitPlayers = 20f,
ThrownDurabilityLossOnHitBlockingPlayers = 10f,
DeflectionDuringBlock =
{
DeflectType = DeflectBulletType.Deflect,
DurabilityLoss = 4f
},
DeflectionOnAttack =
{
DeflectType = DeflectBulletType.Deflect,
DurabilityLoss = 4f
},
BreakDebris = ["MetalDebris00A", "RiotShieldDebris1"],
AI_DamageOutput = DamageOutputType.High,
VisualText = "Riot Shield"
};

MWeaponVisuals weaponVisuals = new()
{
AnimBlockUpper = "UpperBlockMelee2HSlow",
AnimFullJumpAttack = "FullJumpAttackMeleeSlow",
AnimCrouchUpper = "UpperCrouchMelee2H",
AnimJumpKickUpper = "UpperJumpKickMelee",

AnimRunUpper = "UpperRunMelee",
AnimMeleeAttack3 = "UpperMelee2H3Slow",
AnimDraw = "UpperDrawMeleeSheathed",
AnimIdleUpper = "UpperIdleRiotShield",
AnimJumpUpper = "UpperIdleRiotShield",
AnimJumpUpperFalling = "UpperIdleRiotShield",
AnimKickUpper = "UpperIdleRiotShield",
AnimStaggerUpper = "UpperStagger",
AnimWalkUpper = "UpperIdleRiotShield",
AnimFullLand = "FullLandMelee",
AnimToggleThrowingMode = "UpperToggleThrowing",
};
weaponVisuals.SetModelTexture("RiotShieldM");
weaponVisuals.SetDrawnTexture("RiotShieldD");
weaponVisuals.SetSheathedTexture("RiotShieldS");
weaponVisuals.SetThrowingTexture("RiotShieldD");

SetPropertiesAndVisuals(weaponProperties, weaponVisuals);
}

private RiotShield(MWeaponProperties weaponProperties, MWeaponVisuals weaponVisuals) => SetPropertiesAndVisuals(weaponProperties, weaponVisuals);

public override MWeapon Copy() => new RiotShield(Properties, Visuals)
{
Durability =
{
CurrentValue = Durability.CurrentValue
}
};

public override void OnThrowWeaponItem(Player player, ObjectWeaponItem thrownWeaponItem)
{
thrownWeaponItem.Body.SetAngularVelocity(thrownWeaponItem.Body.GetAngularVelocity() * 0.9f);
var linearVelocity = thrownWeaponItem.Body.GetLinearVelocity();
linearVelocity.X *= 0.6f;
linearVelocity.Y *= 0.6f;
thrownWeaponItem.Body.SetLinearVelocity(linearVelocity);
base.OnThrowWeaponItem(player, thrownWeaponItem);
}

public override void Destroyed(Player ownerPlayer)
{
SoundHandler.PlaySound("DestroyMetal", ownerPlayer.GameWorld);
EffectHandler.PlayEffect("DestroyMetal", ownerPlayer.Position, ownerPlayer.GameWorld);
Vector2 center = new(ownerPlayer.Position.X, ownerPlayer.Position.Y + 16f);
ownerPlayer.GameWorld.SpawnDebris(ownerPlayer.ObjectData, center, 8f, ["MetalDebris00A", "GreatswordDebris1"]);
}

public override bool CustomHandlingOnAttackKey(Player player, bool onKeyEvent)
{
if (onKeyEvent && player.CurrentAction is PlayerAction.Idle && !player.InAir)
{
player.CurrentAction = PlayerAction.MeleeAttack3;
}

return true;
}
}
Loading

0 comments on commit 1ba8891

Please sign in to comment.