Skip to content
Merged
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
11 changes: 11 additions & 0 deletions Game.Server/AI_BaseNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,20 @@ public static ReadOnlySpan<char> GetActivityName(Activity actID) {
DEFINE.FIELD(nameof(DidDeathCleanup), FieldType.Boolean),
DEFINE.OUTPUT(nameof(OnDeath), "OnDeath", eventFuncs),
DEFINE.OUTPUT(nameof(OnDenyCommanderUse), "OnDenyCommanderUse", eventFuncs),

DEFINE.INPUTFUNC(FieldType.Integer, "SetHealth", nameof(InputSetHealth), (INPUTFUNCPTR)((self, data) => ((AI_BaseNPC)self).InputSetHealth(data))),
]);
public override DataMap? GetDataDescMap() => DataDesc;

public void InputSetHealth(InputData inputdata) {
int newHealth = inputdata.Value.Int();
int delta = Math.Abs(GetHealth() - newHealth);
if (newHealth > GetHealth())
TakeHealth(delta, DamageType.Generic);
else if (newHealth < GetHealth())
TakeDamage(new TakeDamageInfo(this, this, delta, DamageType.Generic));
}

[NetworkVar("m_bPerformAvoidance")]
public partial bool PerformAvoidance { get; set; }
[NetworkVar("m_bIsMoving")]
Expand Down
7 changes: 7 additions & 0 deletions Game.Server/BaseCombatCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public BaseCombatCharacter() {

public bool ForceServerRagdoll;

public override int TakeHealth(float health, DamageType damageType) {
if (m_takedamage == 0)
return 0;

return base.TakeHealth(health, damageType);
}

public virtual Source.Common.Mathematics.QAngle BodyAngles() => GetAbsAngles();

public virtual Vector3 BodyDirection2D() {
Expand Down
2 changes: 1 addition & 1 deletion Game.Server/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ public float HealthFraction() {
return fraction;
}

public int TakeHealth(float health, DamageType damageType) {
public virtual int TakeHealth(float health, DamageType damageType) {
if (Edict() == null || (Damage)m_takedamage < Damage.Yes)
return 0;

Expand Down
1 change: 1 addition & 0 deletions Game.Server/FuncBreak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Game.Server;
[LinkEntityToClass("func_breakable")]
public class Breakable : BaseEntity, IBreakableWithPropData
{
// todo: SetHealth/AddHealth/RemoveHealth inputs, they need UpdateHealth, OnHealthChanged and Break ported first
public void SetDmgModBullet(float dmgMod) => DmgModBullet = dmgMod;
public void SetDmgModClub(float dmgMod) => DmgModClub = dmgMod;
public void SetDmgModExplosive(float dmgMod) => DmgModExplosive = dmgMod;
Expand Down
35 changes: 35 additions & 0 deletions Game.Server/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ public void SetArmorValue(int value) {
}
}

public static readonly new DataMap DataDesc = new(typeof(BasePlayer), BaseCombatCharacter.DataDesc, [
DEFINE<BasePlayer>.INPUTFUNC(FieldType.Integer, "SetHealth", nameof(InputSetHealth), (INPUTFUNCPTR)((self, data) => ((BasePlayer)self).InputSetHealth(data))),
]);
public override DataMap? GetDataDescMap() => DataDesc;

public override int TakeHealth(float health, DamageType damageType) {
if (m_takedamage != 0) {
DamageType bitsDmgTimeBased = g_pGameRules.Damage_GetTimeBased();
bitsDamageType &= ~(damageType & ~bitsDmgTimeBased);
}

return base.TakeHealth(health, damageType);
}

public void InputSetHealth(InputData inputdata) {
int newHealth = inputdata.Value.Int();
int delta = Math.Abs(GetHealth() - newHealth);
if (newHealth > GetHealth())
TakeHealth(delta, DamageType.Generic);
else if (newHealth < GetHealth()) {
int armor = ArmorValue;
ArmorValue = 0;
TakeDamage(new TakeDamageInfo(this, this, delta, DamageType.Generic));
ArmorValue = armor;
}
}

static InlineArray1024<char> InfoBuffer;

public ReadOnlySpan<char> GetInfo(ReadOnlySpan<char> name) {
Expand Down Expand Up @@ -696,6 +723,14 @@ public void UnforceButtons(InButtons buttons) {
AfButtonForced &= ~buttons;
}

public void DisableButtons(InButtons buttons) {
AfButtonDisabled |= buttons;
}

public void EnableButtons(InButtons buttons) {
AfButtonDisabled &= ~buttons;
}

public bool GamePaused;

public virtual void EquipSuit(bool playEffects = false) {
Expand Down
1 change: 1 addition & 0 deletions Game.Server/Props.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void ParsePropData() { }
[NetworkName("CBreakableProp")]
public partial class BreakableProp : BaseProp, IBreakableWithPropData, IPlayerPickupVPhysics
{
// todo: SetHealth/AddHealth/RemoveHealth inputs, they need UpdateHealth, OnHealthChanged and Break ported first
[NetworkTable]
public static readonly new NetworkProp[] Props = [
];
Expand Down
168 changes: 165 additions & 3 deletions Game.Server/SceneEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ public struct SpeakEventSound
DEFINE.INPUTFUNC(FieldType.Float, "PitchShift", nameof(InputPitchShiftPlayback), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputPitchShiftPlayback(data))),
DEFINE.INPUTFUNC(FieldType.Void, "StopWaitingForActor", nameof(InputStopWaitingForActor), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputStopWaitingForActor(data))),
DEFINE.INPUTFUNC(FieldType.Integer, "Trigger", nameof(InputTriggerEvent), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputTriggerEvent(data))),
// todo: InterjectResponse input, it needs the response system (CAI_BaseActor::SpeakFindResponse/SpeakDispatchResponse) ported first
#if GMOD_DLL
DEFINE.INPUTFUNC(FieldType.String, "SetTarget1", nameof(InputSetTarget1), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputSetTarget1(data))),
DEFINE.INPUTFUNC(FieldType.String, "SetTarget2", nameof(InputSetTarget2), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputSetTarget2(data))),
DEFINE.INPUTFUNC(FieldType.String, "SetTarget3", nameof(InputSetTarget3), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputSetTarget3(data))),
DEFINE.INPUTFUNC(FieldType.String, "SetTarget4", nameof(InputSetTarget4), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputSetTarget4(data))),
#endif

DEFINE.KEYFIELD(nameof(PlayerDeathBehavior), FieldType.Integer, "onplayerdeath"),
DEFINE.INPUTFUNC(FieldType.Void, "ScriptPlayerDeath", nameof(InputScriptPlayerDeath), (INPUTFUNCPTR)((self, data) => ((SceneEntity)self).InputScriptPlayerDeath(data))),
Expand Down Expand Up @@ -718,7 +725,151 @@ public override void UpdateOnRemove() {
GetSceneManager()?.RemoveSceneEntity(this);
}

ChoreoScene? GenerateSceneForSound(BaseFlex? flexActor, ReadOnlySpan<char> soundname) => throw new NotImplementedException();
ChoreoScene? GenerateSceneForSound(BaseFlex? flexActor, ReadOnlySpan<char> soundname) {
float duration = GetSoundDuration(soundname, flexActor != null ? flexActor.GetModelName() : null);
if (duration <= 0.0f) {
Warning($"CSceneEntity::GenerateSceneForSound: Couldn't determine duration of {soundname}\n");
return null;
}

ChoreoScene scene = new(this);
scene.SetPrintFunc(Scene_Printf);

ChoreoActor actor = scene.AllocActor();
ChoreoChannel channel = scene.AllocChannel();
ChoreoEvent ev = scene.AllocEvent();

actor.SetName("!self");
actor.SetActive(true);

channel.SetName(SceneFile);
channel.SetActor(actor);

actor.AddChannel(channel);

ev.SetType(EventType.Speak);
ev.SetName(soundname);
ev.SetParameters(soundname);
ev.SetStartTime(0.0f);
ev.SetUsingRelativeTag(false);
ev.SetEndTime(duration);
ev.SnapTimes();

channel.AddEvent(ev);

ev.SetChannel(channel);
ev.SetActor(actor);

return scene;
}

public void PrecacheScene(ChoreoScene scene) {
Assert(scene != null);

for (int i = 0; i < scene.GetNumEvents(); i++) {
ChoreoEvent? ev = scene.GetEvent(i);
if (ev == null)
continue;

switch (ev.GetType()) {
default:
break;
case EventType.Speak:
PrecacheScriptSound(ev.GetParameters());
// todo: precache the close caption token sound of CC_MASTER events with slaves once ChoreoEvent has close captions
break;
case EventType.SubScene:
if (!scene.IsSubScene()) {
ChoreoScene? subscene = ev.GetSubScene();
if (subscene == null) {
subscene = LoadScene(ev.GetParameters(), this);
if (subscene == null)
break;
subscene.SetSubScene(true);
ev.SetSubScene(subscene);

PrecacheScene(subscene);
}
}
break;
}
}
}

public override void OnRestore() {
base.OnRestore();

if (Pitch < SCENE_MIN_PITCH || Pitch > SCENE_MAX_PITCH)
Pitch = 1.0f;

if (!IsPlayingBack)
return;

if (Scene == null) {
Scene = LoadScene(SceneFile, this);
if (Scene == null) {
SceneMissing = true;
return;
}

OnLoaded();

if (ShouldNetwork())
SceneStringIndex = g_pStringTableClientSideChoreoScenes!.AddString(IsServer(), SceneFile);

UpdateTransmitState();
}

SceneMissing = false;

for (int i = 0; i < Scene.GetNumActors(); i++) {
BaseFlex? testActor = FindNamedActor(i);
if (testActor == null)
continue;

if (testActor.MyCombatCharacterPointer() == null)
continue;

testActor.StartChoreoScene(Scene);
}

TimeUnit_t dt = SCENE_THINK_INTERVAL;

bool paused = Paused;

Paused = false;

Scene.ResetSimulation(true, (float)(CurrentTime - SCENE_THINK_INTERVAL), (float)CurrentTime);
Scene.SetTime(CurrentTime - SCENE_THINK_INTERVAL);

SetCurrentTime(CurrentTime, true);

SetRestoring(true);

DoThink(dt);

SetRestoring(false);

if (paused)
PausePlayback();

NetworkProp().NetworkStateForceUpdate();
}

#if GMOD_DLL
void SetTargetFromInput(ref string? target, ref EHANDLE handle, in InputData inputdata) {
ReadOnlySpan<char> value = inputdata.Value.String();
target = value.IsEmpty ? null : new string(value);
ActorList.Clear();
NetworkProp().NetworkStateForceUpdate();
handle.Set(FindNamedTarget(target, false));
}

public void InputSetTarget1(InputData inputdata) => SetTargetFromInput(ref Target1, ref HTarget1, in inputdata);
public void InputSetTarget2(InputData inputdata) => SetTargetFromInput(ref Target2, ref HTarget2, in inputdata);
public void InputSetTarget3(InputData inputdata) => SetTargetFromInput(ref Target3, ref HTarget3, in inputdata);
public void InputSetTarget4(InputData inputdata) => SetTargetFromInput(ref Target4, ref HTarget4, in inputdata);
#endif

public override void Activate() {
if (Generated && Scene == null)
Expand Down Expand Up @@ -1330,8 +1481,19 @@ public virtual void PitchShiftPlayback(float fPitch) {
}

public virtual void QueueResumePlayback() {
if (!string.IsNullOrEmpty(ResumeSceneFile))
throw new NotImplementedException();
if (!string.IsNullOrEmpty(ResumeSceneFile)) {
bool startedScene = false;

if (!stristr(ResumeSceneFile, ".vcd").IsEmpty)
startedScene = InstancedScriptedScene(null, ResumeSceneFile, ref WaitingForThisResumeScene, 0, false) != 0;

// todo: if no scene started, find a response for the first actor (CAI_BaseActor::SpeakFindResponse) and play it, once the response system is ported

if (startedScene)
WaitingForResumeScene = true;
else
ResumePlayback();
}
else
ResumePlayback();
}
Expand Down
47 changes: 47 additions & 0 deletions Game.Server/TriggerPlayerMovement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Source.Common;
using Source.Common.Engine;
using Source;
using Game.Shared;
using System.Numerics;
Expand All @@ -17,6 +18,10 @@ public enum SF
{
MoveAutoDisable = 0x80, // disable auto movement
AutoDuck = 0x800, // Duck automatically
#if GMOD_DLL
AutoWalk = 0x1000,
DisableJump = 0x2000,
#endif
}

//-----------------------------------------------------------------------------
Expand All @@ -32,14 +37,32 @@ public override void Spawn() {
base.Spawn();

InitTrigger();

#if GMOD_DLL
if (HasSpawnFlags(SF.AutoDuck) || HasSpawnFlags(SF.AutoWalk) || HasSpawnFlags(SF.DisableJump)) {
ClientSidePredicted = true;
SetTransmitState(EdictFlags.PVSCheck);
}
#endif
}

#if GMOD_DLL
public override void UpdateOnRemove() {
EndTouchOnAllTouchers();
base.UpdateOnRemove();
}
#endif

// UNDONE: This will not support a player touching more than one of these
// UNDONE: Do we care? If so, ref count automovement in the player?
public override void StartTouch(BaseEntity? other) {
if (other == null || !PassesTriggerFilters(other))
return;

#if GMOD_DLL
base.StartTouch(other);
#endif

BasePlayer? player = ToBasePlayer(other);

if (player == null)
Expand All @@ -48,12 +71,26 @@ public override void StartTouch(BaseEntity? other) {
if (HasSpawnFlags(SF.AutoDuck))
player.ForceButtons(InButtons.Duck);

#if GMOD_DLL
if (HasSpawnFlags(SF.AutoWalk)) {
player.ForceButtons(InButtons.Walk);
player.DisableButtons(InButtons.Speed);
}

if (HasSpawnFlags(SF.DisableJump))
player.DisableButtons(InButtons.Jump);
#endif

// UNDONE: Currently this is the only operation this trigger can do
if (HasSpawnFlags(SF.MoveAutoDisable))
player.Local.AllowAutoMovement = false;
}

public override void EndTouch(BaseEntity? other) {
#if GMOD_DLL
base.EndTouch(other);
#endif

if (other == null || !PassesTriggerFilters(other))
return;

Expand All @@ -65,6 +102,16 @@ public override void EndTouch(BaseEntity? other) {
if (HasSpawnFlags(SF.AutoDuck))
player.UnforceButtons(InButtons.Duck);

#if GMOD_DLL
if (HasSpawnFlags(SF.AutoWalk)) {
player.UnforceButtons(InButtons.Walk);
player.EnableButtons(InButtons.Speed);
}

if (HasSpawnFlags(SF.DisableJump))
player.EnableButtons(InButtons.Jump);
#endif

if (HasSpawnFlags(SF.MoveAutoDisable))
player.Local.AllowAutoMovement = true;
}
Expand Down
Loading
Loading