You are very welcome. Here is the fixes I have done to get Eating/Drinking working. I also added the ability for the pet to regenerate Energy slowly when the pet is sleeping.
All modifications will be inside:
private void Update()
{
[ . . . ]
}
To fix Drinking - Look for:
else if (action == Action.Drink)
{
if (entity.Hydration.Level >= 1)
{
SetBehaviour(BaseNpc.Behaviour.Idle);
action = Action.Idle;
return;
}
float distance = Vector3.Distance(transform.position, targetPos);
if (distance < 1)
{
SetBehaviour(BaseNpc.Behaviour.Eat);
entity.Hydration.Level += 0.005f;
entity.Hydration.Level = Mathf.Clamp01(entity.Hydration.Level);
}
else UpdateDestination(targetPos, distance > 5);
}
Alter the code to match my Commited Changes below:
else if (action == Action.Drink)
{
if (entity.Hydration.Level >= 1)
{
SetBehaviour(BaseNpc.Behaviour.Idle);
action = Action.Idle;
return;
}
float distance = Vector3.Distance(transform.position, targetPos);
if (distance <= 2) // ChaoticDev [Changed]
{
SetBehaviour(BaseNpc.Behaviour.Eat);
entity.Hydration.Level += 0.00003f; // ChaoticDev [Changed]
entity.Hydration.Level = Mathf.Clamp01(entity.Hydration.Level);
}
else
{
UpdateDestination(targetPos, distance > 5);
}
}
To fix Eating - Look for:
if ((action == Action.Eat || entity.Energy.Level < 0.25f) && targetEnt != owner.player)
{
SetBehaviour(BaseNpc.Behaviour.Eat);
if (distance <= attackRange)
{
entity.FoodTarget = targetEnt;
if (distance <= 2)
entity.Eat();
}
else UpdateDestination(targetEnt.transform.position, distance > 5);
}
Alter the code to match my Commited Changes below:
if ((action == Action.Eat || entity.Energy.Level < 0.25f) && targetEnt != owner.player)
{
SetBehaviour(BaseNpc.Behaviour.Eat);
if (distance <= 2) // ChaoticDev [Changed]
{
entity.FoodTarget = targetEnt;
if (distance <= 2) {
entity.Eat();
}
}
else UpdateDestination(targetEnt.transform.position, distance > 5);
}
Thats it! You now have working Eating and Drinking for your pets.
Now if you want my added feature of having the Pet's Energy gradually increase while they sleep, you can look for the following:
else if (action == Action.Sleep)
{
StopMoving();
SetBehaviour(BaseNpc.Behaviour.Sleep);
entity.health += 0.003f;
entity.health = Mathf.Clamp(entity.health, 0, entity.MaxHealth());
entity.Sleep += 0.003f;
entity.Sleep = Mathf.Clamp01(entity.Sleep);
}
Alter the code to match my Commited Changes below:
else if (action == Action.Sleep)
{
StopMoving();
SetBehaviour(BaseNpc.Behaviour.Sleep);
entity.health += 0.00003f; // ChaoticDev [Changed] to be a gradual increase.
entity.health = Mathf.Clamp(entity.health, 0, entity.MaxHealth());
entity.Sleep += 0.00003f; // ChaoticDev [Changed] to be a gradual increase.
entity.Sleep = Mathf.Clamp01(entity.Sleep);
// ChaoticDev [Added]
entity.Energy.Level += 0.00003f;
entity.Energy.Level = Mathf.Clamp01(entity.Energy.Level);
// End
}
All Done!
Merged postOh and just to touch on what some other people have been requesting to be fixed, is the animal still attacks the owner after taming it. I have created a small workaround for this too. I will now share it with you and everyone.
Inside:
private void TryGetNewPet(BaseNpc npcPet)
{
[ . . . ]
}
Look for:
UserMessage(player, "petSet");
Just under that, add the following like so:
// ChaoticDev [Added]
component.npcAi.action = Action.Sleep;
UserMessage(player, "Please run away from your pet for 5 to 10 seconds so they can calm down.\n\nIf you don't do this they will continue to attack you.\n\nAfter running away and giving your pet time to calm down, you can wake your pet back up and they will begin to follow you.");
// End
Example would be:
UserMessage(player, "petSet");
// ChaoticDev [Added]
component.npcAi.action = Action.Sleep;
UserMessage(player, "Please run away from your pet for 5 to 10 seconds so they can calm down.\n\nIf you don't do this they will continue to attack you.\n\nAfter running away and giving your pet time to calm down, you can wake your pet back up and they will begin to follow you.");
// End