Skip to content

Commit 0a68b08

Browse files
authored
Merge pull request #163 from marchc1/player-use
Player use & entity holding
2 parents 377dd6a + 8d6a9c3 commit 0a68b08

24 files changed

Lines changed: 2730 additions & 750 deletions

‎ENTITIES_COMPLETED.md‎

Lines changed: 708 additions & 708 deletions
Large diffs are not rendered by default.

‎Game.Client/C_BaseEntity.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ public C_BaseEntity() {
737737
public InlineArray32<ushort> OverrideSubMaterials;
738738
[NetworkName("m_iHealth")]
739739
public int Health;
740+
public int GetHealth() => Health;
741+
public int SetHealth(int amt) => Health = amt;
740742
[NetworkName("m_iMaxHealth")]
741743
public int MaxHealth;
742744
[NetworkName("m_spawnflags")]

‎Game.Client/C_BasePlayer.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public virtual float GetFOV() {
715715
public float VehicleViewFOV;
716716
public int VehicleViewSavedFrame;
717717

718-
public int GetHealth() => Health;
718+
719719
public bool IsSuitEquipped() => Local.WearingSuit;
720720

721721
public TimeUnit_t GetLaggedMovementValue() => LaggedMovementValue;

‎Game.Server/AI_BaseNPC.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5584,6 +5584,14 @@ public virtual Capability CapabilitiesGet() {
55845584
return capability;
55855585
}
55865586

5587+
public EntityCapabilities UsableNPCObjectCaps(EntityCapabilities baseCaps) {
5588+
if (IsAlive())
5589+
baseCaps |= EntityCapabilities.ImpulseUse;
5590+
return baseCaps;
5591+
}
5592+
5593+
public override EntityCapabilities ObjectCaps() => base.ObjectCaps() | EntityCapabilities.NotifyOnTransition;
5594+
55875595
public void NPCUse(BaseEntity? activator, BaseEntity? caller, UseType useType, float value) {
55885596
return;
55895597
}

‎Game.Server/AI_PlayerAlly.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ namespace Game.Server;
33
public class AI_PlayerAlly : AI_BaseActor
44
{
55
public override int SelectSchedule() => throw new NotImplementedException();
6+
7+
public override EntityCapabilities ObjectCaps() => UsableNPCObjectCaps(base.ObjectCaps());
68
}

‎Game.Server/BaseCombatWeapon.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public partial class BaseCombatWeapon : BaseAnimating
1616
{
1717
public static readonly ConVar weapon_showproficiency = new("weapon_showproficiency", "0");
1818

19+
public OutputEvent OnPlayerUse = new();
1920
public OutputEvent OnPlayerPickup = new();
2021
public OutputEvent OnNPCPickup = new();
2122
public OutputEvent OnCacheInteraction = new();
2223

2324
public static readonly new DataMap DataDesc = new(typeof(BaseCombatWeapon), BaseEntity.DataDesc, [
25+
DEFINE.OUTPUT(nameof(OnPlayerUse), "OnPlayerUse", eventFuncs),
2426
DEFINE.OUTPUT(nameof(OnPlayerPickup), "OnPlayerPickup", eventFuncs),
2527
DEFINE.OUTPUT(nameof(OnNPCPickup), "OnNPCPickup", eventFuncs),
2628
DEFINE.OUTPUT(nameof(OnCacheInteraction), "OnCacheInteraction", eventFuncs),
@@ -67,6 +69,30 @@ public static int GetAvailableWeaponsInBox(Span<BaseCombatWeapon?> list, in Vect
6769
return count;
6870
}
6971

72+
public override EntityCapabilities ObjectCaps() {
73+
EntityCapabilities caps = base.ObjectCaps();
74+
if (!IsFollowingEntity() && !HasSpawnFlags(SF_WEAPON_NO_PLAYER_PICKUP))
75+
caps |= EntityCapabilities.ImpulseUse;
76+
77+
return caps;
78+
}
79+
80+
public override void Use(BaseEntity? activator, BaseEntity? caller, UseType useType, float value) {
81+
BasePlayer? player = ToBasePlayer(activator);
82+
83+
if (player != null) {
84+
OnPlayerUse.FireOutput(activator, caller);
85+
86+
// Bump the weapon to try equipping it before picking it up physically. This is
87+
// important in a few spots in the game where the player could potentially +use pickup
88+
// and then THROW AWAY a vital weapon, rendering them unable to continue the game.
89+
if (player.BumpWeapon(this))
90+
OnPickedUp(player);
91+
else
92+
player.PickupObject(this);
93+
}
94+
}
95+
7096
public bool IsConstrained() => false;
7197

7298
public override bool IsWeapon() => true;

‎Game.Server/BaseEntity.cs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,6 +2262,15 @@ public void SetBlocksLOS(bool blocksLOS) {
22622262

22632263
public bool BlocksLOS() => !IsEFlagSet(EFL.DontBlockLOS);
22642264

2265+
public void SetAIWalkable(bool blocksLOS) {
2266+
if (blocksLOS)
2267+
RemoveEFlags(EFL.DontWalkOn);
2268+
else
2269+
AddEFlags(EFL.DontWalkOn);
2270+
}
2271+
2272+
public bool IsAIWalkable() => !IsEFlagSet(EFL.DontWalkOn);
2273+
22652274
public Vector3 AbsVelocity;
22662275
public QAngle AngVelocity;
22672276

@@ -2958,6 +2967,10 @@ public virtual void Use(BaseEntity? activator, BaseEntity? caller, UseType useTy
29582967
Parent.Get()?.Use(activator, caller, useType, value);
29592968
}
29602969

2970+
public bool IsFollowingEntity() => IsEffectActive(EntityEffects.BoneMerge) && (GetMoveType() == Source.MoveType.None) && GetMoveParent() != null;
2971+
2972+
public virtual bool OnControls(BaseEntity controls) => false;
2973+
29612974
public int ShouldToggle(UseType useType, int currentState) {
29622975
if (useType != UseType.Toggle && useType != UseType.Set) {
29632976
if ((currentState != 0 && useType == UseType.On) || (currentState == 0 && useType == UseType.Off))

‎Game.Server/FuncBreak.cs‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,49 @@
55
namespace Game.Server;
66

77
[LinkEntityToClass("func_breakable")]
8-
public class Breakable : BaseEntity, IBreakableWithPropData;
8+
public class Breakable : BaseEntity, IBreakableWithPropData
9+
{
10+
public void SetDmgModBullet(float dmgMod) => DmgModBullet = dmgMod;
11+
public void SetDmgModClub(float dmgMod) => DmgModClub = dmgMod;
12+
public void SetDmgModExplosive(float dmgMod) => DmgModExplosive = dmgMod;
13+
public float GetDmgModBullet() => DmgModBullet;
14+
public float GetDmgModClub() => DmgModClub;
15+
public float GetDmgModExplosive() => DmgModExplosive;
16+
public void SetExplosiveRadius(float radius) => ExplodeRadius = radius;
17+
public void SetExplosiveDamage(float damage) => ExplosionMagnitude = (int)damage;
18+
public float GetExplosiveRadius() => ExplodeRadius;
19+
public float GetExplosiveDamage() => ExplosionMagnitude;
20+
public void SetPhysicsDamageTable(ReadOnlySpan<char> tableName) => PhysicsDamageTableName = tableName.IsEmpty ? null : new(tableName);
21+
public ReadOnlySpan<char> GetPhysicsDamageTable() => PhysicsDamageTableName;
22+
public void SetBreakableModel(ReadOnlySpan<char> model) => BreakableModel = model.IsEmpty ? null : new(model);
23+
public ReadOnlySpan<char> GetBreakableModel() => BreakableModel;
24+
public void SetBreakableSkin(int skin) => BreakableSkin = skin;
25+
public int GetBreakableSkin() => BreakableSkin;
26+
public void SetBreakableCount(int count) => BreakableCount = count;
27+
public int GetBreakableCount() => BreakableCount;
28+
public void SetMaxBreakableSize(int size) => MaxBreakableSize = size;
29+
public int GetMaxBreakableSize() => MaxBreakableSize;
30+
public void SetPropDataBlocksLOS(bool blocksLOS) => SetBlocksLOS(blocksLOS);
31+
public void SetPropDataIsAIWalkable(bool blocksLOS) => SetAIWalkable(blocksLOS);
32+
public void SetBasePropData(ReadOnlySpan<char> propdata) => BasePropData = propdata.IsEmpty ? null : new(propdata);
33+
public ReadOnlySpan<char> GetBasePropData() => BasePropData;
34+
public void SetInteraction(PropDataInteractions interaction) => Interactions |= (1 << (int)interaction);
35+
public bool HasInteraction(PropDataInteractions interaction) => (Interactions & (1 << (int)interaction)) != 0;
36+
public void SetPhysicsMode(PhysicsMultiplayerMode mode) { }
37+
public PhysicsMultiplayerMode GetPhysicsMode() => PhysicsMultiplayerMode.Solid;
38+
public void SetMultiplayerBreakMode(MultiplayerBreak mode) { }
39+
public MultiplayerBreak GetMultiplayerBreakMode() => MultiplayerBreak.Default;
40+
41+
protected float DmgModBullet;
42+
protected float DmgModClub;
43+
protected float DmgModExplosive;
44+
protected string? PhysicsDamageTableName;
45+
protected string? BreakableModel;
46+
protected int BreakableSkin;
47+
protected int BreakableCount;
48+
protected int MaxBreakableSize;
49+
protected string? BasePropData;
50+
protected int Interactions;
51+
protected int ExplosionMagnitude;
52+
protected float ExplodeRadius;
53+
}

‎Game.Server/FuncTrackTrain.cs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public class FuncTrackTrain : BaseEntity
4040
public const int SF_TRACKTRAIN_USE_MAXSPEED_FOR_PITCH = 0x0100;
4141
public const int SF_TRACKTRAIN_UNBLOCKABLE_BY_PLAYER = 0x0200;
4242

43+
public const int TRAIN_ACTIVE = 0x80;
44+
public const int TRAIN_NEW = 0xc0;
45+
public const int TRAIN_OFF = 0x00;
46+
public const int TRAIN_NEUTRAL = 0x01;
47+
public const int TRAIN_SLOW = 0x02;
48+
public const int TRAIN_MEDIUM = 0x03;
49+
public const int TRAIN_FAST = 0x04;
50+
public const int TRAIN_BACK = 0x05;
51+
4352
const float TRAIN_MAXSPEED = 1000;
4453

4554
public static readonly SendTable DT_FuncTrackTrain = new(DT_BaseEntity, []);
@@ -890,7 +899,7 @@ public void SetControls(BaseEntity controls) {
890899
ControlMaxs = controls.WorldAlignMaxs() + offset;
891900
}
892901

893-
public bool OnControls(BaseEntity test) {
902+
public override bool OnControls(BaseEntity test) {
894903
Vector3 offset = test.GetLocalOrigin() - GetLocalOrigin();
895904

896905
if ((SpawnFlags & SF_TRACKTRAIN_NOCONTROL) != 0)

‎Game.Server/GarrysMod/GMOD_Player.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ public override void PlayerRunCommand(UserCmd ucmd, IMoveHelper moveHelper) {
113113
base.PlayerRunCommand(ucmd, moveHelper);
114114
}
115115

116+
public override void PickupObject(BaseEntity obj, bool limitMassAndSize = true) {
117+
HL2_PickupObject(obj, limitMassAndSize);
118+
}
119+
116120
public override void CheckChatText(ReadOnlySpan<char> text) {
117121
if (!stristr(text, "bloxwich").IsEmpty)
118122
AwardAchievement((int)GMODAchievementID.GMA_SAY_1, 1);

0 commit comments

Comments
 (0)