diff --git a/src/ZoneServer/World/Actors/Characters/Character.cs b/src/ZoneServer/World/Actors/Characters/Character.cs index 0d2d659c9..c2cc358ec 100644 --- a/src/ZoneServer/World/Actors/Characters/Character.cs +++ b/src/ZoneServer/World/Actors/Characters/Character.cs @@ -779,7 +779,13 @@ public void Heal(float hpAmount, float spAmount) PiercingHeart_Debuff.TryApply(this, ref hpAmount); this.ModifyHpSafe(hpAmount, out var hp, out var priority); + if (hpAmount > 0) + { + Send.ZC_HEAL_INFO(this, hpAmount, this.Hp, HealType.Hp); + } this.Properties.Modify(PropertyName.SP, spAmount); + if (spAmount > 0) + Send.ZC_HEAL_INFO(this, spAmount, this.Sp, HealType.Sp); Send.ZC_UPDATE_ALL_STATUS(this, priority); } diff --git a/system/scripts/zone/items/instant_heal.cs b/system/scripts/zone/items/instant_heal.cs new file mode 100644 index 000000000..ecdcf8c4f --- /dev/null +++ b/system/scripts/zone/items/instant_heal.cs @@ -0,0 +1,117 @@ +//--- Melia Script ---------------------------------------------------------- +// Instant Heal Items +//--- Description ----------------------------------------------------------- +// Item scripts for instant healing potions (HP, SP, Stamina). +//--------------------------------------------------------------------------- + +using System; +using Melia.Shared.Game.Const; +using Melia.Zone.Scripting; +using Melia.Zone.World.Actors.Characters; +using Melia.Zone.World.Actors.CombatEntities.Components; +using Melia.Zone.World.Items; +using Yggdrasil.Util; + +public class InstantHealItemScript : GeneralScript +{ + /// + /// Instantly restores HP. Supports HP potion bonus modifiers (HPPotion_BM). + /// + /// The character that used the item. + /// The item that was used. + /// Unused. + /// Base HP heal amount (or min if numArg2 is set). + /// Max HP heal amount for random range (0 = no range). + /// + [ScriptableFunction] + public ItemUseResult SCR_USE_ITEM_AddHP1(Character character, Item item, string strArg, float numArg1, float numArg2) + { + var hpHeal = (int)numArg1; + if (numArg2 != 0) + hpHeal = RandomProvider.Get().Next((int)numArg1, (int)numArg2); + + if (character.Properties.TryGetFloat(PropertyName.HPPotion_BM, out var hpPotionBM) && hpPotionBM > 0) + hpHeal = (int)MathF.Floor(hpHeal * (1 + hpPotionBM / 100)); + + character.Heal(hpHeal, 0); + + return ItemUseResult.Okay; + } + + /// + /// Instantly restores SP. Supports SP potion bonus modifiers (SPPotion_BM). + /// Curse debuffs prevent SP recovery. + /// + /// The character that used the item. + /// The item that was used. + /// Unused. + /// Base SP heal amount (or min if numArg2 is set). + /// Max SP heal amount for random range (0 = no range). + /// + [ScriptableFunction] + public ItemUseResult SCR_USE_ITEM_AddSP1(Character character, Item item, string strArg, float numArg1, float numArg2) + { + var spHeal = (int)numArg1; + if (numArg2 != 0) + spHeal = RandomProvider.Get().Next((int)numArg1, (int)numArg2); + + if (character.Properties.TryGetFloat(PropertyName.SPPotion_BM, out var spPotionBM) && spPotionBM > 0) + spHeal = (int)MathF.Floor(spHeal * (1 + spPotionBM / 100)); + + character.Heal(0, spHeal); + + return ItemUseResult.Okay; + } + + /// + /// Instantly restores stamina. Supports stamina potion bonus modifiers (STAPotion_BM). + /// + /// The character that used the item. + /// The item that was used. + /// Unused. + /// Base stamina amount in whole numbers (multiplied by 1000 internally). + /// Max stamina amount for random range (0 = no range). + /// + [ScriptableFunction] + public ItemUseResult SCR_USE_ITEM_AddSTA1(Character character, Item item, string strArg, float numArg1, float numArg2) + { + var stamina = (int)numArg1 * 1000; + var staminaMax = (int)numArg2 * 1000; + if (staminaMax != 0) + stamina = RandomProvider.Get().Next(stamina, staminaMax); + + if (character.Properties.TryGetFloat(PropertyName.STAPotion_BM, out var staminaPotionBM) && staminaPotionBM > 0) + stamina = (int)MathF.Floor(stamina * (1 + staminaPotionBM / 100)); + + character.ModifyStamina(stamina); + + return ItemUseResult.Okay; + } + + /// + /// Instantly restores both HP and SP. Supports both HP and SP potion bonus modifiers. + /// Curse debuffs prevent SP recovery. + /// + /// The character that used the item. + /// The item that was used. + /// Unused. + /// Min amount for random range. + /// Max amount for random range. + /// + [ScriptableFunction] + public ItemUseResult SCR_USE_ITEM_AddHPSP1(Character character, Item item, string strArg, float numArg1, float numArg2) + { + var hpPoint = RandomProvider.Get().Next((int)numArg1, (int)numArg2); + var spPoint = RandomProvider.Get().Next((int)numArg1, (int)numArg2) / 2; + + if (character.Properties.TryGetFloat(PropertyName.SPPotion_BM, out var spPotionBM) && spPotionBM > 0) + spPoint = (int)MathF.Floor(spPoint * (1 + spPotionBM / 100)); + + if (character.Properties.TryGetFloat(PropertyName.HPPotion_BM, out var hpPotionBM) && hpPotionBM > 0) + hpPoint = (int)MathF.Floor(hpPoint * (1 + hpPotionBM / 100)); + + character.Heal(hpPoint, spPoint); + + return ItemUseResult.Okay; + } +}