Skip to content

Commit

Permalink
Added LP and SP stealer spells
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrdacor committed Dec 18, 2020
1 parent 3b14006 commit 4c17da0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Ambermoon.Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static float Limit(float minValue, float value, float maxValue)
return Math.Max(minValue, Math.Min(value, maxValue));
}

public static uint Limit(uint minValue, uint value, uint maxValue)
{
return Math.Max(minValue, Math.Min(value, maxValue));
}

public static int Limit(int minValue, int value, int maxValue)
{
return Math.Max(minValue, Math.Min(value, maxValue));
Expand Down
38 changes: 32 additions & 6 deletions Ambermoon.Core/Battle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -937,17 +937,20 @@ void AttackAnimationFinished()

var spellInfo = SpellInfos.Entries[spell];

if (itemIndex == 0)
{
battleAction.Character.SpellPoints.CurrentValue = Math.Max(0, battleAction.Character.SpellPoints.CurrentValue - spellInfo.SP);

if (battleAction.Character is PartyMember partyMember)
layout.FillCharacterBars(game.SlotFromPartyMember(partyMember).Value, partyMember);
}

if (!CheckSpellCast(battleAction.Character, spellInfo))
{
EndCast();
return;
}

battleAction.Character.SpellPoints.CurrentValue -= spellInfo.SP;

if (battleAction.Character is PartyMember partyMember)
layout.FillCharacterBars(game.SlotFromPartyMember(partyMember).Value, partyMember);

if (spell != Spell.Firebeam &&
spell != Spell.Fireball &&
spell != Spell.Firestorm &&
Expand All @@ -960,7 +963,9 @@ void AttackAnimationFinished()
spell != Spell.DestroyUndead &&
spell != Spell.HolyWord &&
spell != Spell.MagicalProjectile &&
spell != Spell.MagicalArrows) // TODO: REMOVE. For now we only allow some spells for testing.
spell != Spell.MagicalArrows &&
spell != Spell.LPStealer &&
spell != Spell.SPStealer) // TODO: REMOVE. For now we only allow some spells for testing.
{
if (spell < Spell.Lame || spell > Spell.Drug)
break;
Expand Down Expand Up @@ -1459,6 +1464,9 @@ void HandleCharacterDeath(Character attacker, Character target, Action finishAct
}
}

/// <summary>
/// The boolean argument of the finish action means: NeedsClickAfterwards
/// </summary>
void ApplySpellEffect(Character caster, Character target, Spell spell, uint ticks, Action<bool> finishAction)
{
switch (spell)
Expand Down Expand Up @@ -1548,6 +1556,24 @@ void ApplySpellEffect(Character caster, Character target, Spell spell, uint tick
// Those deal half the caster level as damage.
DealDamage(Math.Max(1, (uint)caster.Level / 2), 0);
return;
case Spell.LPStealer:
{
DealDamage(caster.Level, 0);
caster.HitPoints.CurrentValue = Math.Min(caster.HitPoints.MaxValue, caster.HitPoints.CurrentValue +
Math.Min(caster.Level, caster.HitPoints.MaxValue - caster.HitPoints.CurrentValue));
if (caster is PartyMember castingMember)
layout.FillCharacterBars(game.SlotFromPartyMember(castingMember).Value, castingMember);
return;
}
case Spell.SPStealer:
// TODO: what happens if a monster wants to cast a spell afterwards but has not enough SP through SP stealer anymore?
target.SpellPoints.CurrentValue = (uint)Math.Max(0, (int)target.SpellPoints.CurrentValue - caster.Level);
caster.SpellPoints.CurrentValue += Math.Min(caster.Level, caster.SpellPoints.MaxValue - caster.SpellPoints.CurrentValue);
if (target is PartyMember targetMember)
layout.FillCharacterBars(game.SlotFromPartyMember(targetMember).Value, targetMember);
else if (caster is PartyMember castingMember)
layout.FillCharacterBars(game.SlotFromPartyMember(castingMember).Value, castingMember);
break;
// Winddevil: seen 10-15
// Windhowler: seen 35-46
default:
Expand Down
2 changes: 2 additions & 0 deletions Ambermoon.Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,8 @@ void ShowBattleWindow(Event nextEvent)
spell != Spell.HolyWord &&
spell != Spell.MagicalProjectile &&
spell != Spell.MagicalArrows &&
spell != Spell.LPStealer &&
spell != Spell.SPStealer &&
!(spell >= Spell.Lame && spell <= Spell.Drug))
pickedSpell = Spell.Iceball; // TODO
else
Expand Down
26 changes: 21 additions & 5 deletions Ambermoon.Core/Render/SpellAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ public void Play(Action finishAction)
case Spell.Windhowler:
case Spell.MagicalProjectile:
case Spell.MagicalArrows:
case Spell.LPStealer:
case Spell.SPStealer:
case Spell.GhostWeapon:
// Those spells use only the MoveTo method.
this.finishAction?.Invoke();
break;
case Spell.LPStealer:
case Spell.SPStealer:
case Spell.MonsterKnowledge:
case Spell.ShowMonsterLP:
case Spell.GhostWeapon:
case Spell.Blink:
case Spell.Flight:
return; // TODO
Expand Down Expand Up @@ -728,11 +728,27 @@ void PlayHolyLight()
case Spell.AntiMagicSphere:
case Spell.Hurry:
case Spell.MassHurry:
case Spell.LPStealer:
case Spell.SPStealer:
case Spell.MonsterKnowledge:
case Spell.ShowMonsterLP:
return; // TODO
case Spell.LPStealer:
case Spell.SPStealer:
{
// Note: The hurt animation comes first so we immediately call the passed finish action
// which will display the hurt animation.
finishAction?.Invoke(game.CurrentBattleTicks, true, false); // Play hurt animation but do not finish.
this.finishAction = () => finishAction?.Invoke(game.CurrentBattleTicks, false, true); // This is called after the animation to finish.

float endScale = renderView.GraphicProvider.GetMonsterRowImageScaleFactor((MonsterRow)(tile / 6));
game.AddTimedEvent(TimeSpan.FromMilliseconds(500), () =>
{
byte displayLayer = (byte)(fromMonster ? 255 : ((tile / 6) * 60 + 60));
AddAnimation(spell == Spell.LPStealer ? CombatGraphicIndex.BlueBeam : CombatGraphicIndex.GreenBeam, 1,
GetTargetPosition(tile), GetSourcePosition(), BattleEffects.GetFlyDuration((uint)tile, (uint)startPosition),
fromMonster ? 2.5f: endScale, fromMonster ? endScale : 2.5f, displayLayer);
});
break;
}
case Spell.MagicalProjectile:
case Spell.MagicalArrows:
{
Expand Down
2 changes: 1 addition & 1 deletion Ambermoon.Data.Common/CharacterValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CharacterValue
public uint MaxValue { get; set; }
public uint BonusValue { get; set; }
public uint Unknown { get; set; }
public uint TotalCurrentValue => CurrentValue + BonusValue;
public uint TotalCurrentValue => Util.Limit(0, CurrentValue + BonusValue, MaxValue);
}

[Serializable]
Expand Down

0 comments on commit 4c17da0

Please sign in to comment.