[FSOD] SpecificHeal Fix

Posts 1–2 of 2 · Page 1 of 1
[FSOD] SpecificHeal Fix
As you may know, SpecificHeal doesn't work too nice when it comes to the maximum health of a monster, and will just keep healing away well over the monster's max health. I actually made the SpecificHeal behaviour a long time ago, and as it was rushed and untested, it ended up just healing way too much. This behaviour is also untested but SHOULD work. Notify me if there are any bugs.

This is also a very simple fix and is surprisingly not fixed in a lot of Fabiano servers, probably due to the lack of SpecificHeal behaviours. Anyway, simply replace the entire 'SpecificHeal.cs' file with the following code:

 
Replace SpecificHeal.cs with this

Code:
#region


using System;
using System.Linq;
using wServer.networking.svrPackets;
using wServer.realm;
using wServer.realm.entities;

#endregion

namespace wServer.logic.behaviors
{
    public class SpecificHeal : Behavior
    {
        //State storage: cooldown timer

        private readonly string group;
        private readonly int amount;
        private readonly double range;
        private Cooldown coolDown;

        public SpecificHeal(double range, int amount, string group, Cooldown coolDown = new Cooldown())
        {
            this.range = (float) range;
            this.amount = amount;
            this.group = group;
            this.coolDown = coolDown.Normalize();
        }

        protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
        {
            state = 0;
        }

        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool = (int) state;

            if (cool <= 0)
            {
                if (group == "Self")
                {
                    Enemy entity = host as Enemy;
		    int newHp = entity.HP + amount;
		    if (newHp <= entity.ObjectDesc.MaxHP)
		    {
			     entity.HP = entity.HP + amount;
			     entity.UpdateCount++;
			     entity.Owner.BroadcastPacket(new ShowEffectPacket
			     {
				     EffectType = EffectType.Potion,
				     TargetId = entity.Id,
				     Color = new ARGB(0xffffffff)
			     }, null);
			     entity.Owner.BroadcastPacket(new NotificationPacket
			     {
				     ObjectId = entity.Id,
				     Text = "{\"key\":\"blank\",\"tokens\":{\"data\":\"+" + amount + "\"}}",
				     Color = new ARGB(0xff00ff00)
			     }, null);
		    }
		    else
		    {
			     int defecitToMaxHp = Convert.ToInt32(entity.ObjectDesc.MaxHP) - entity.HP;
			     if (defecitToMaxHp <= 0)
			     {
			     }
			     else
			     {
				     entity.HP = entity.HP + defecitToMaxHp;
				     entity.UpdateCount++;
				     entity.Owner.BroadcastPacket(new ShowEffectPacket
				     {
					     EffectType = EffectType.Potion,
					     TargetId = entity.Id,
					     Color = new ARGB(0xffffffff)
				     }, null);
				     entity.Owner.BroadcastPacket(new NotificationPacket
				     {
					     ObjectId = entity.Id,
					     Text = "{\"key\":\"blank\",\"tokens\":{\"data\":\"+" + amount + "\"}}",
					     Color = new ARGB(0xff00ff00)
					     }, null);
				     }
			}
                }
                else
                {
                    foreach (Enemy entity in host.GetNearestEntitiesByGroup(range, group).OfType<Enemy>())
                    {
                    	int newHp = entity.HP + amount;
			if (newHp <= entity.ObjectDesc.MaxHP)
			{
				entity.HP = entity.HP + amount;
				entity.UpdateCount++;
				entity.Owner.BroadcastPacket(new ShowEffectPacket
				{
					EffectType = EffectType.Potion,
					TargetId = entity.Id,
					Color = new ARGB(0xffffffff)
				}, null);
				entity.Owner.BroadcastPacket(new NotificationPacket
				{
					ObjectId = entity.Id,
					Text = "{\"key\":\"blank\",\"tokens\":{\"data\":\"+" + amount + "\"}}",
					Color = new ARGB(0xff00ff00)
				}, null);
			}
			else
			{
				int defecitToMaxHp = Convert.ToInt32(entity.ObjectDesc.MaxHP) - entity.HP;
				if (defecitToMaxHp <= 0)
				{
				}
				else
				{
					entity.HP = entity.HP + defecitToMaxHp;
					entity.UpdateCount++;
					entity.Owner.BroadcastPacket(new ShowEffectPacket
					{
						EffectType = EffectType.Potion,
						TargetId = entity.Id,
						Color = new ARGB(0xffffffff)
					}, null);
					entity.Owner.BroadcastPacket(new NotificationPacket
					{
						ObjectId = entity.Id,
						Text = "{\"key\":\"blank\",\"tokens\":{\"data\":\"+" + amount + "\"}}",
						Color = new ARGB(0xff00ff00)
					}, null);
				}
			}
                    }
                }
                cool = coolDown.Next(Random);
            }
            else
                cool -= time.thisTickTimes;

            state = cool;
        }
    }
}


Edit: tried to fix spacing, definitely better than before, but still a bit off
Saved me some time when doing tomb bosses, the only thing I had to do was add a trail effect whenever the heal is not on self. Other than that, it works great.
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us