Skip to content

Commit

Permalink
[HS-1470] Implement support for no heal, no hp/mp regen, no mp decrea…
Browse files Browse the repository at this point in the history
…se conditions

* Fix bug with Disoriented (cut / paste fail)

* Add DirectHeal / DirectDamage to be used by scripting, which will take new conditions into
  account
  • Loading branch information
baughj committed Aug 4, 2024
1 parent f8a0d37 commit 2db88aa
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Hybrasyl.Tests/Hybrasyl.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0-release-24373-02" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.5" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.20">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
12 changes: 6 additions & 6 deletions hybrasyl/Hybrasyl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@
<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Discord.Net.Webhook" Version="3.15.3" />
<PackageReference Include="Google.Protobuf" Version="3.27.2" />
<PackageReference Include="Google.Protobuf" Version="3.28.0-rc1" />
<PackageReference Include="Grpc" Version="2.46.6" />
<PackageReference Include="Grpc.Tools" Version="2.65.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Hybrasyl.Xml" Version="0.9.4" />
<PackageReference Include="Humanizer.Core" Version="3.0.0-beta.54" />
<PackageReference Include="Hybrasyl.Xml" Version="0.9.4.1" />
<PackageReference Include="MoonSharp" Version="2.0.0" />
<PackageReference Include="MSBuildGitHash" Version="2.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NCalcSync" Version="5.1.0" />
<PackageReference Include="NCalcSync" Version="5.2.0" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog" Version="4.0.2-dev-02220" />
<PackageReference Include="Serilog.Enrichers.ExceptionData" Version="1.0.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand All @@ -75,7 +75,7 @@
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.ServiceModel.Primitives" Version="8.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.0-preview.6.24327.7" />
</ItemGroup>

<ItemGroup>
Expand Down
92 changes: 79 additions & 13 deletions hybrasyl/Objects/ConditionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public bool CastingAllowed
{
get
{
var conditionCheck = Asleep || Frozen || Comatose;
var conditionCheck = Asleep || Stunned || Comatose;

if (User != null)
conditionCheck = conditionCheck || Flags.HasFlag(PlayerFlags.ProhibitCast);
Expand All @@ -71,7 +71,7 @@ public bool MovementAllowed
{
get
{
var conditionCheck = Asleep || Frozen || Paralyzed || Comatose;
var conditionCheck = Asleep || Stunned || Rooted || Comatose;
return !conditionCheck;
}
}
Expand Down Expand Up @@ -99,15 +99,15 @@ public bool Alive
}
}

public bool Frozen
public bool Stunned
{
get => Conditions.HasFlag(CreatureCondition.Freeze);
get => Conditions.HasFlag(CreatureCondition.Stun);
set
{
if (value == false)
Conditions &= ~CreatureCondition.Freeze;
Conditions &= ~CreatureCondition.Stun;
else
Conditions |= CreatureCondition.Freeze;
Conditions |= CreatureCondition.Stun;
}
}

Expand All @@ -119,19 +119,19 @@ public bool Asleep
if (value == false)
Conditions &= ~CreatureCondition.Sleep;
else
Conditions |= CreatureCondition.Freeze;
Conditions |= CreatureCondition.Stun;
}
}

public bool Paralyzed
public bool Rooted
{
get => Conditions.HasFlag(CreatureCondition.Paralyze);
get => Conditions.HasFlag(CreatureCondition.Root);
set
{
if (value == false)
Conditions &= ~CreatureCondition.Paralyze;
Conditions &= ~CreatureCondition.Root;
else
Conditions |= CreatureCondition.Paralyze;
Conditions |= CreatureCondition.Root;
}
}

Expand Down Expand Up @@ -225,9 +225,9 @@ public bool Disoriented
set
{
if (value == false)
Conditions &= ~CreatureCondition.Invulnerable;
Conditions &= ~CreatureCondition.Disoriented;
else
Conditions |= CreatureCondition.Invulnerable;
Conditions |= CreatureCondition.Disoriented;
}
}

Expand Down Expand Up @@ -360,6 +360,72 @@ public bool IsEquipmentChangeProhibited
}
}

public bool IsHpIncreaseProhibited
{
get => User != null && Conditions.HasFlag(CreatureCondition.ProhibitHpIncrease);
set
{
if (User == null) return;
if (value == false)
Conditions &= CreatureCondition.ProhibitHpIncrease;
else
Conditions |= CreatureCondition.ProhibitHpIncrease;
}
}

public bool IsMpIncreaseProhibited
{
get => User != null && Conditions.HasFlag(CreatureCondition.ProhibitMpIncrease);
set
{
if (User == null) return;
if (value == false)
Conditions &= CreatureCondition.ProhibitMpIncrease;
else
Conditions |= CreatureCondition.ProhibitMpIncrease;
}
}

public bool IsMpDecreaseProhibited
{
get => User != null && Conditions.HasFlag(CreatureCondition.ProhibitMpDecrease);
set
{
if (User == null) return;
if (value == false)
Conditions &= CreatureCondition.ProhibitMpDecrease;
else
Conditions |= CreatureCondition.ProhibitMpDecrease;
}
}

public bool IsHpRegenProhibited
{
get => User != null && Conditions.HasFlag(CreatureCondition.ProhibitHpRegen);
set
{
if (User == null) return;
if (value == false)
Conditions &= CreatureCondition.ProhibitHpRegen;
else
Conditions |= CreatureCondition.ProhibitHpRegen;
}
}

public bool IsMpRegenProhibited
{
get => User != null && Conditions.HasFlag(CreatureCondition.ProhibitMpRegen);
set
{
if (User == null) return;
if (value == false)
Conditions &= CreatureCondition.ProhibitMpRegen;
else
Conditions |= CreatureCondition.ProhibitMpRegen;
}
}


public bool NoFlags => Flags == PlayerFlags.Alive;

public void ClearFlags()
Expand Down
11 changes: 5 additions & 6 deletions hybrasyl/Objects/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,8 @@ public virtual void Motion(byte motion, short speed)

public virtual void Heal(double heal, Creature source = null, Castable castable = null)
{
if (Condition.IsHpIncreaseProhibited)
return;
var bonusHeal = heal * Stats.BaseInboundHealModifier + (heal * source?.Stats.BaseOutboundHealModifier ?? 0.0);
heal += bonusHeal;

Expand All @@ -982,7 +984,7 @@ public virtual void Heal(double heal, Creature source = null, Castable castable

public virtual void RegenerateMp(double mp, Creature regenerator = null)
{
if (AbsoluteImmortal)
if (AbsoluteImmortal || Condition.IsMpIncreaseProhibited)
return;

if (Stats.Mp == Stats.MaximumMp || mp > Stats.MaximumMp)
Expand Down Expand Up @@ -1176,7 +1178,7 @@ public virtual void Damage(double damage, ElementType element = ElementType.None
{
case DamageType.Physical when AbsoluteImmortal || PhysicalImmortal || Condition.IsInvulnerable:
case DamageType.Magical when AbsoluteImmortal || MagicalImmortal || Condition.IsInvulnerable:
case DamageType.Direct when AbsoluteImmortal || Condition.IsInvulnerable:
case DamageType.Direct when AbsoluteImmortal:
damageEvent.Applied = false;
return;
}
Expand Down Expand Up @@ -1261,10 +1263,7 @@ public virtual void Damage(double damage, ElementType element = ElementType.None
});
}

if ((MagicalImmortal && damageType != DamageType.Magical) ||
(PhysicalImmortal && damageType != DamageType.Physical) ||
!AbsoluteImmortal)
Stats.Hp = (int)Stats.Hp - normalized < 0 ? 0 : Stats.Hp - normalized;
Stats.Hp = (int)Stats.Hp - normalized < 0 ? 0 : Stats.Hp - normalized;

SendDamageUpdate(this);

Expand Down
7 changes: 6 additions & 1 deletion hybrasyl/Objects/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,9 @@ public bool ProcessCastingCost(Castable castable, Creature target, out string me
// Check that all requirements are met first. Note that a spell cannot be cast if its HP cost would result
// in the caster's HP being reduced to zero.

if (Condition.IsMpDecreaseProhibited)
cost.Mp = 0;

if (cost.Hp >= Stats.Hp)
message = "You lack the required vitality.";

Expand Down Expand Up @@ -2627,7 +2630,9 @@ public override void Damage(double damage, ElementType element = ElementType.Non
public override void Heal(double heal, Creature source = null, Castable castable = null)
{
base.Heal(heal, source, castable);
if (this is User) UpdateAttributes(StatUpdateFlags.Current);
if (Condition.IsHpIncreaseProhibited)
SendSystemMessage("You cannot currently receive healing.");
UpdateAttributes(StatUpdateFlags.Current);
}

private bool CheckCastableRestriction(EquipmentRestriction restriction, out string message)
Expand Down
Loading

0 comments on commit 2db88aa

Please sign in to comment.