Skip to content

Commit

Permalink
New entity base + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timmybo5 committed Jun 20, 2021
1 parent b45e8dd commit 0a226b6
Show file tree
Hide file tree
Showing 81 changed files with 3,259 additions and 1,430 deletions.
24 changes: 12 additions & 12 deletions code/ExamplePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ public override void Respawn()

SupressPickupNotices = true;

Inventory.Add( new SWB_CSS.Knife() );
Inventory.Add( new SWB_CSS.GrenadeHE() );

Inventory.Add( new SWB_CSS.Deagle() );

Inventory.Add( new SWB_CSS.Super90() );
Inventory.Add( new SWB_CSS.M249() );

Inventory.Add( new SWB_CSS.AK47() );
Inventory.Add( new SWB_CSS.M4A1() );
Inventory.Add( new SWB_CSS.Deagle() );
Inventory.Add( new SWB_CSS.Knife() );

// Inventory.Add( new SWB_CSS.DeagleDual() );
// Inventory.Add( new SWB_CSS.AK47Dual() );

GiveAmmo( AmmoType.SMG, 100 );
GiveAmmo( AmmoType.Pistol, 60 );
GiveAmmo( AmmoType.Revolver, 60 );
GiveAmmo( AmmoType.Rifle, 60 );
GiveAmmo( AmmoType.Shotgun, 60 );
Inventory.Add( new SWB_CSS.M249() );
Inventory.Add( new SWB_CSS.AWP() );

//Inventory.Add( new SWB_CSS.M249HE() );
//Inventory.Add( new SWB_CSS.DeagleDual() );
//Inventory.Add( new SWB_CSS.AK47Dual() );

SupressPickupNotices = false;
}
Expand Down
165 changes: 83 additions & 82 deletions code/swb_base/PlayerBase.Ammo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,87 @@

namespace SWB_Base
{
public enum AmmoType
{
Pistol,
Revolver,
Shotgun,
SMG,
Rifle,
Sniper,
LMG,
Crossbow,
RPG,
Explosive,
}

public enum InfiniteAmmoType
{
normal,
clip,
reserve
}

partial class PlayerBase
{

[Net]
public List<int> Ammo { get; set; } = new();

public void ClearAmmo()
{
Ammo.Clear();
}

public int AmmoCount( AmmoType type )
{
var iType = (int)type;
if ( Ammo == null ) return 0;
if ( Ammo.Count <= iType ) return 0;

return Ammo[(int)type];
}

public bool SetAmmo( AmmoType type, int amount )
{
var iType = (int)type;
if ( !Host.IsServer ) return false;
if ( Ammo == null ) return false;

while ( Ammo.Count <= iType )
{
Ammo.Add( 0 );
}

Ammo[(int)type] = amount;
return true;
}

public bool GiveAmmo( AmmoType type, int amount )
{
if ( !Host.IsServer ) return false;
if ( Ammo == null ) return false;

SetAmmo( type, AmmoCount( type ) + amount );
return true;
}

public int TakeAmmo( AmmoType type, int amount )
{
if ( Ammo == null ) return 0;

var available = AmmoCount( type );
amount = Math.Min( available, amount );

SetAmmo( type, available - amount );

return amount;
}

public bool HasAmmo( AmmoType type )
{
return AmmoCount( type ) > 0;
}
}
public enum AmmoType
{
Pistol,
Revolver,
Shotgun,
SMG,
Rifle,
Sniper,
LMG,
Crossbow,
RPG,
Explosive,
Grenade
}

public enum InfiniteAmmoType
{
normal,
clip,
reserve
}

partial class PlayerBase
{

[Net]
public List<int> Ammo { get; set; } = new();

public void ClearAmmo()
{
Ammo.Clear();
}

public int AmmoCount( AmmoType type )
{
var iType = (int)type;
if ( Ammo == null ) return 0;
if ( Ammo.Count <= iType ) return 0;

return Ammo[(int)type];
}

public bool SetAmmo( AmmoType type, int amount )
{
var iType = (int)type;
if ( !Host.IsServer ) return false;
if ( Ammo == null ) return false;

while ( Ammo.Count <= iType )
{
Ammo.Add( 0 );
}

Ammo[(int)type] = amount;
return true;
}

public bool GiveAmmo( AmmoType type, int amount )
{
if ( !Host.IsServer ) return false;
if ( Ammo == null ) return false;

SetAmmo( type, AmmoCount( type ) + amount );
return true;
}

public int TakeAmmo( AmmoType type, int amount )
{
if ( Ammo == null ) return 0;

var available = AmmoCount( type );
amount = Math.Min( available, amount );

SetAmmo( type, available - amount );

return amount;
}

public bool HasAmmo( AmmoType type )
{
return AmmoCount( type ) > 0;
}
}
}
106 changes: 53 additions & 53 deletions code/swb_base/PlayerBase.Ragdoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,65 @@

namespace SWB_Base
{
partial class PlayerBase
{
// TODO - make ragdolls one per entity
// TODO - make ragdolls dissapear after a load of seconds
static EntityLimit RagdollLimit = new EntityLimit { MaxTotal = 20 };
partial class PlayerBase
{
// TODO - make ragdolls one per entity
// TODO - make ragdolls dissapear after a load of seconds
static EntityLimit RagdollLimit = new EntityLimit { MaxTotal = 20 };

[ClientRpc]
void BecomeRagdollOnClient( Vector3 force, int forceBone )
{
// TODO - lets not make everyone write this shit out all the time
// maybe a CreateRagdoll<T>() on ModelEntity?
var ent = new ModelEntity();
ent.Position = Position;
ent.Rotation = Rotation;
ent.MoveType = MoveType.Physics;
ent.UsePhysicsCollision = true;
ent.SetInteractsAs( CollisionLayer.Debris );
ent.SetInteractsWith( CollisionLayer.WORLD_GEOMETRY );
ent.SetInteractsExclude( CollisionLayer.Player | CollisionLayer.Debris );
[ClientRpc]
void BecomeRagdollOnClient( Vector3 force, int forceBone )
{
// TODO - lets not make everyone write this shit out all the time
// maybe a CreateRagdoll<T>() on ModelEntity?
var ent = new ModelEntity();
ent.Position = Position;
ent.Rotation = Rotation;
ent.MoveType = MoveType.Physics;
ent.UsePhysicsCollision = true;
ent.SetInteractsAs( CollisionLayer.Debris );
ent.SetInteractsWith( CollisionLayer.WORLD_GEOMETRY );
ent.SetInteractsExclude( CollisionLayer.Player | CollisionLayer.Debris );

ent.SetModel( GetModelName() );
ent.CopyBonesFrom( this );
ent.TakeDecalsFrom( this );
ent.SetRagdollVelocityFrom( this );
ent.DeleteAsync( 20.0f );
ent.SetModel( GetModelName() );
ent.CopyBonesFrom( this );
ent.TakeDecalsFrom( this );
ent.SetRagdollVelocityFrom( this );
ent.DeleteAsync( 20.0f );

// Copy the clothes over
foreach ( var child in Children )
{
if ( child is ModelEntity e )
{
var model = e.GetModelName();
if ( model != null && !model.Contains( "clothes" ) ) // Uck we 're better than this, entity tags, entity type or something?
continue;
// Copy the clothes over
foreach ( var child in Children )
{
if ( child is ModelEntity e )
{
var model = e.GetModelName();
if ( model != null && !model.Contains( "clothes" ) ) // Uck we 're better than this, entity tags, entity type or something?
continue;

var clothing = new ModelEntity();
clothing.SetModel( model );
clothing.SetParent( ent, true );
}
}
var clothing = new ModelEntity();
clothing.SetModel( model );
clothing.SetParent( ent, true );
}
}

ent.PhysicsGroup.AddVelocity( force );
ent.PhysicsGroup.AddVelocity( force );

if ( forceBone >= 0 )
{
var body = ent.GetBonePhysicsBody( forceBone );
if ( body != null )
{
body.ApplyForce( force * 1000 );
}
else
{
ent.PhysicsGroup.AddVelocity( force );
}
}
if ( forceBone >= 0 )
{
var body = ent.GetBonePhysicsBody( forceBone );
if ( body != null )
{
body.ApplyForce( force * 1000 );
}
else
{
ent.PhysicsGroup.AddVelocity( force );
}
}

Corpse = ent;
Corpse = ent;

RagdollLimit.Watch( ent );
}
}
RagdollLimit.Watch( ent );
}
}
}
Loading

0 comments on commit 0a226b6

Please # to comment.