Skip to content

Commit

Permalink
v4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
timmybo5 committed Aug 8, 2022
1 parent c992cdd commit 9805983
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 48 deletions.
8 changes: 2 additions & 6 deletions code/swb_base/CarriableBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Sandbox;
using Sandbox.UI;
using System;

namespace SWB_Base
{
Expand All @@ -16,8 +14,6 @@ public override void Spawn()
{
base.Spawn();

MoveType = MoveType.Physics;
CollisionGroup = CollisionGroup.Interactive;
PhysicsEnabled = true;
UsePhysicsCollision = true;
EnableHideInFirstPerson = true;
Expand Down Expand Up @@ -76,7 +72,7 @@ public virtual void OnCarryStart(Entity carrier)

SetParent(carrier, true);
Owner = carrier;
MoveType = MoveType.None;
PhysicsEnabled = false;
EnableAllCollisions = false;
EnableDrawing = false;
}
Expand All @@ -87,7 +83,7 @@ public virtual void OnCarryDrop(Entity dropper)

SetParent(null);
Owner = null;
MoveType = MoveType.Physics;
PhysicsEnabled = true;
EnableDrawing = true;
EnableAllCollisions = true;
}
Expand Down
44 changes: 32 additions & 12 deletions code/swb_base/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ partial class ViewModelBase : BaseViewModel
private WeaponBase weapon;

private float animSpeed;
private float fovSpeed;
private float playerFOVSpeed;

// Target animation values
private Vector3 targetVectorPos;
private Vector3 targetVectorRot;
private float targetFOV;
private float targetPlayerFOV = -1;
private float targetWeaponFOV = -1;
private float playerFOV = -1;

// Finalized animation values
private Vector3 finalVectorPos;
private Vector3 finalVectorRot;
private float finalFOV;
private float finalPlayerFOV;
private float finalWeaponFOV;

// Sway
private Rotation lastEyeRot;
Expand All @@ -38,16 +41,23 @@ partial class ViewModelBase : BaseViewModel
public ViewModelBase(WeaponBase weapon)
{
this.weapon = weapon;
finalFOV = weapon.FOV;
}

public override void PostCameraSetup(ref CameraSetup camSetup)
{
base.PostCameraSetup(ref camSetup);

camSetup.FieldOfView = weapon.FOV;
if (playerFOV == -1)
{
playerFOV = camSetup.FieldOfView;
finalPlayerFOV = camSetup.FieldOfView;
targetWeaponFOV = weapon.FOV;
finalWeaponFOV = weapon.FOV;
}

Rotation = camSetup.Rotation;
Position = camSetup.Position;

if (weapon.IsDormant) return;
if (Owner != null && Owner.Health <= 0)
{
Expand All @@ -58,13 +68,15 @@ public override void PostCameraSetup(ref CameraSetup camSetup)
// Smoothly transition the vectors with the target values
finalVectorPos = finalVectorPos.LerpTo(targetVectorPos, animSpeed * RealTime.Delta);
finalVectorRot = finalVectorRot.LerpTo(targetVectorRot, animSpeed * RealTime.Delta);
finalFOV = MathX.LerpTo(finalFOV, targetFOV, fovSpeed * animSpeed * RealTime.Delta);
finalPlayerFOV = MathX.LerpTo(finalPlayerFOV, targetPlayerFOV, playerFOVSpeed * animSpeed * RealTime.Delta);
finalWeaponFOV = MathX.LerpTo(finalWeaponFOV, targetWeaponFOV, playerFOVSpeed * animSpeed * RealTime.Delta);
animSpeed = 10 * weapon.WalkAnimationSpeedMod;

// Change the angles and positions of the viewmodel with the new vectors
Rotation *= Rotation.From(finalVectorRot.x, finalVectorRot.y, finalVectorRot.z);
Position += finalVectorPos.z * Rotation.Up + finalVectorPos.y * Rotation.Forward + finalVectorPos.x * Rotation.Right;
camSetup.FieldOfView = finalFOV;
camSetup.FieldOfView = finalPlayerFOV;
camSetup.ViewModel.FieldOfView = finalWeaponFOV;

// I'm sure there's something already that does this for me, but I spend an hour
// searching through the wiki and a bunch of other garbage and couldn't find anything...
Expand All @@ -74,7 +86,8 @@ public override void PostCameraSetup(ref CameraSetup camSetup)
// Initialize the target vectors for this frame
targetVectorPos = new Vector3(weapon.ViewModelOffset.Pos);
targetVectorRot = new Vector3(MathUtil.ToVector3(weapon.ViewModelOffset.Angle));
targetFOV = weapon.FOV;
targetPlayerFOV = playerFOV;
targetWeaponFOV = weapon.FOV;

// Model editor
if (Owner is PlayerBase player && (player.IsModelEditing() || player.IsAttachmentEditing()))
Expand Down Expand Up @@ -194,16 +207,23 @@ private void HandleIronAnimation(ref CameraSetup camSetup)
animSpeed = 10 * weapon.WalkAnimationSpeedMod * speedMod;
targetVectorPos += weapon.ZoomAnimData.Pos;
targetVectorRot += MathUtil.ToVector3(weapon.ZoomAnimData.Angle);
targetFOV = weapon.ZoomFOV;
fovSpeed = weapon.ZoomInFOVSpeed;

if (weapon.ZoomPlayerFOV > 0)
targetPlayerFOV = weapon.ZoomPlayerFOV;

if (weapon.ZoomWeaponFOV > 0)
targetWeaponFOV = weapon.ZoomWeaponFOV;

playerFOVSpeed = weapon.ZoomInFOVSpeed;
}
else
{
zoomTime = 0;
targetWeaponFOV = weapon.FOV;

if (finalFOV != weapon.FOV)
if (finalPlayerFOV != weapon.ZoomPlayerFOV)
{
fovSpeed = weapon.ZoomOutFOVSpeed;
playerFOVSpeed = weapon.ZoomOutFOVSpeed;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions code/swb_base/WeaponBase.Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public virtual void Attack(ClipInfo clipInfo, bool isPrimary)
/// <param name="clipInfo">Attack information</param>
/// <param name="isPrimary">If this is the primary attack</param>
/// <param name="delay">Bullet firing delay</param>
async Task AsyncAttack(ClipInfo clipInfo, bool isPrimary, float delay)
public virtual async Task AsyncAttack(ClipInfo clipInfo, bool isPrimary, float delay)
{
if (GetAvailableAmmo() <= 0) return;

Expand Down Expand Up @@ -239,7 +239,7 @@ public virtual void AttackSecondary()
public virtual TraceResult TraceBullet(Vector3 start, Vector3 end, float radius = 2.0f)
{
var startsInWater = SurfaceUtil.IsPointWater(start);
List<string> withoutTags = new();
List<string> withoutTags = new() { "trigger" };

if (startsInWater)
withoutTags.Add("water");
Expand Down
9 changes: 4 additions & 5 deletions code/swb_base/WeaponBase.Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ public override void Spawn()
public virtual void Start()
{
// Initialize physics
MoveType = MoveType.Physics;
PhysicsEnabled = true;
UsePhysicsCollision = true;
SetupPhysicsFromModel(PhysicsMotionType.Dynamic);
PhysicsGroup.AddVelocity(StartVelocity * Speed);
Velocity = StartVelocity * Speed;
PhysicsBody.GravityEnabled = UseGravity;

// Delete entity
Expand All @@ -46,10 +45,10 @@ protected override void OnPhysicsCollision(CollisionEventData eventData)
{
base.OnPhysicsCollision(eventData);

if (IsSticky && eventData.Entity.IsValid())
if (IsSticky && eventData.Other.Entity.IsValid())
{
Velocity = Vector3.Zero;
Parent = eventData.Entity;
Parent = eventData.Other.Entity;
}
}

Expand Down Expand Up @@ -135,7 +134,7 @@ public override void Attack(ClipInfo clipInfo, bool isPrimary)
}
}

async Task AsyncAttack(ClipInfo clipInfo, bool isPrimary, float delay)
public override async Task AsyncAttack(ClipInfo clipInfo, bool isPrimary, float delay)
{
if (GetAvailableAmmo() <= 0) return;

Expand Down
11 changes: 7 additions & 4 deletions code/swb_base/WeaponBase.Var.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ public partial class WeaponBase
/// <summary>Should the barrel smoke after heavy weapon usage?</summary>
public virtual bool BarrelSmoking => true;

/// <summary>Default FOV</summary>
public virtual int FOV => 65;
/// <summary>Default weapon FOV</summary>
public virtual int FOV => 75;

/// <summary>FOV while zooming</summary>
public virtual int ZoomFOV => 65;
/// <summary>Weapon FOV while zooming</summary>
public virtual int ZoomWeaponFOV => -1;

/// <summary>Player FOV while zooming</summary>
public virtual int ZoomPlayerFOV => -1;

/// <summary>FOV zoom in speed</summary>
public virtual int ZoomInFOVSpeed => 1;
Expand Down
23 changes: 23 additions & 0 deletions code/swb_base/WeaponBaseAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Sandbox;

/**
* Unfinished, some asset features missing that would make the base clutered.
* Waiting until they improve the asset system.
*/

namespace SWB_Base;

[GameResource("SWB Weapon", "swb", "A weapon on the Simple Weapon Base.", Icon = "military_tech")]
public class WeaponBaseAsset : GameResource
{
[Property] public float DrawTime { get; set; } = 0.5f;
[Property] public float ReloadTime { get; set; } = 1f;
[Property] public float ReloadEmptyTime { get; set; } = -1f;
[Property] public float BoltBackTime { get; set; } = -1f;
[Property] public float BoltBackEjectDelay { get; set; } = 0f;
[Property] public string ReloadAnim { get; set; } = "reload";
[Property] public string ReloadEmptyAnim { get; set; } = "reload_empty";
[Property] public string DrawAnim { get; set; } = "deploy";
[Property] public string DrawEmptyAnim { get; set; } = "";
[Property] public string BoltBackAnim { get; set; } = "boltback";
}
6 changes: 3 additions & 3 deletions code/swb_base/entities/explosives/Grenade.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sandbox;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Sandbox;

/*
* High explosive grenade
Expand All @@ -27,7 +27,7 @@ public override void Start()

protected override void OnPhysicsCollision(CollisionEventData eventData)
{
if (eventData.Entity is not PlayerBase && eventData.Speed > 50 && !string.IsNullOrEmpty(BounceSound))
if (eventData.Other.Entity is not PlayerBase && eventData.Speed > 50 && !string.IsNullOrEmpty(BounceSound))
PlaySound(BounceSound);
}

Expand Down
19 changes: 12 additions & 7 deletions code/swb_base/entities/explosives/Rocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,31 @@ public override void Start()

for (int i = 0; i < RocketEffects.Count; i++)
{
rocketParticles.Add(Particles.Create(RocketEffects[i], this, null, true));
rocketParticles.Add(Particles.Create(RocketEffects[i], this, true));
}
}

protected override void OnPhysicsCollision(CollisionEventData eventData)
{
if (eventData.Entity == Owner) return;
if (eventData.Other.Entity == Owner) return;

Explode();
}

public override void Tick()
{
var inWater = SurfaceUtil.IsPointWater(Position);

// Rocket flight
var downForce = Rotation.Down * 4;
var random = new Random();
var timeSinceMod = (int)Math.Max(0, Inaccuracy * timeSince);
var sideForce = Rotation.Left * (random.Next(0, timeSinceMod) * 2 - timeSinceMod);
if (!inWater)
{
var downForce = Rotation.Down * 4;
var random = new Random();
var timeSinceMod = (int)Math.Max(0, Inaccuracy * timeSince);
var sideForce = Rotation.Left * (random.Next(0, timeSinceMod) * 2 - timeSinceMod);

Velocity += downForce + sideForce;
Velocity += (downForce + sideForce) * 20;
}

// Update sound
rocketLoopSound.SetPosition(Position);
Expand Down
18 changes: 15 additions & 3 deletions code/swb_base/obsolete/controllers/PlayerWalkController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


using Sandbox;

/* Result from Pain Day 4, this will be here temporarily until it is clear how templates work */
Expand Down Expand Up @@ -155,7 +155,7 @@ public override void Simulate()

// if ( underwater ) do underwater movement

if (AutoJump ? Input.Down(InputButton.Jump) : Input.Pressed(InputButton.Jump))
if ((AutoJump || Swimming) ? Input.Down(InputButton.Jump) : Input.Pressed(InputButton.Jump))
{
CheckJumpButton();
}
Expand Down Expand Up @@ -436,7 +436,19 @@ public virtual void CheckJumpButton()
// swimming, not jumping
ClearGroundEntity();

Velocity = Velocity.WithZ(100);
var jumpLedge = false;

var startPos = Pawn.EyePosition;

var tr = Trace.Ray( startPos, startPos + Pawn.EyeRotation.Forward * 1000 )
.Ignore(Pawn)
.Run();


if ( tr.Entity == null || tr.Entity.ClassName != "func_water" )
jumpLedge = true;

Velocity = Velocity.WithZ( jumpLedge ? 350 : 100 );

// play swimming sound
// if ( player->m_flSwimSoundTime <= 0 )
Expand Down
4 changes: 2 additions & 2 deletions code/swb_base/ui/SniperScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public override void Tick()
rotateTransform.AddRotation(0, 0, lensRotation);
this.Style.Transform = rotateTransform;
*/
Style.Dirty();
//Style.Dirty();
*/
}
}
}
8 changes: 4 additions & 4 deletions code/swb_base/util/ScreenUtil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Sandbox;
using System;
using System;
using Sandbox;

namespace SWB_Base
{
Expand Down Expand Up @@ -40,8 +40,8 @@ public static void Shake(To to, ScreenShake screenShake)

public static void Shake(ScreenShake screenShake)
{

Shake(screenShake.Length, screenShake.Delay, screenShake.Size, screenShake.Rotation);
if (screenShake != null)
Shake(screenShake.Length, screenShake.Delay, screenShake.Size, screenShake.Rotation);
}

public static void ShakeAt(Vector3 origin, float radius = 0, float delay = 0, float speed = 0, float size = 0, float rotation = 0)
Expand Down

0 comments on commit 9805983

Please sign in to comment.