fix: Cleans up code with feeding pets and adds batch coin flips random check (#1717)

This commit is contained in:
Kamron Batman 2024-04-04 15:09:15 -07:00 • committed by GitHub
parent 183f6fa4ac
commit 29ea813242
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 186 additions and 128 deletions

View file

@ -173,6 +173,8 @@ namespace Server.Mobiles
}
public const int MaxLoyalty = 100;
public const int LoyaltyIncreasePerFood = 10;
public const int MaxLoyaltyIncrease = MaxLoyalty / LoyaltyIncreasePerFood;
public const int MaxOwners = 5;
@ -4180,91 +4182,87 @@ namespace Server.Mobiles
public virtual bool CheckFeed(Mobile from, Item dropped)
{
if (!IsDeadPet && Controlled && (ControlMaster == from || IsPetFriend(from)))
if (IsDeadPet || !Controlled || (ControlMaster != from && !IsPetFriend(from)))
{
if (CheckFoodPreference(dropped))
return false;
}
if (!CheckFoodPreference(dropped))
{
return false;
}
var amount = dropped.Amount;
if (amount > 0)
{
int stamGain = dropped switch
{
var amount = dropped.Amount;
Gold => amount - 50,
_ => amount * 15 - 50
};
if (amount > 0)
if (stamGain > 0)
{
Stam += stamGain;
// 64 food = 3,640 steps
StaminaSystem.RegenSteps(this as IHasSteps, stamGain * 4);
}
if (Core.SE)
{
m_Loyalty = MaxLoyalty;
}
else if (m_Loyalty < MaxLoyalty)
{
// 50% chance to increase 10 loyalty per food
m_Loyalty = Math.Min(MaxLoyalty, Utility.CoinFlips(amount, MaxLoyaltyIncrease) * 10);
}
/* if (happier )*/
// looks like in OSI pets say they are happier even if they are at maximum loyalty
SayTo(from, 502060); // Your pet looks happier.
if (Body.IsAnimal)
{
Animate(3, 5, 1, true, false, 0);
}
else if (Body.IsMonster)
{
Animate(17, 5, 1, true, false, 0);
}
if (IsBondable && !IsBonded)
{
var master = m_ControlMaster;
if (master != null && master == from) // So friends can't start the bonding process
{
int stamGain = dropped switch
if (MinTameSkill <= 29.1 || master.Skills.AnimalTaming.Base >= MinTameSkill ||
OverrideBondingReqs() ||
Core.ML && master.Skills.AnimalTaming.Value >= MinTameSkill)
{
Gold => amount - 50,
_ => amount * 15 - 50
};
if (stamGain > 0)
{
Stam += stamGain;
// 64 food = 3,640 steps
StaminaSystem.RegenSteps(this as IHasSteps, stamGain * 4);
}
if (Core.SE)
{
if (m_Loyalty < MaxLoyalty)
if (BondingBegin == DateTime.MinValue)
{
m_Loyalty = MaxLoyalty;
BondingBegin = Core.Now;
}
else if (BondingBegin + BondingDelay <= Core.Now)
{
IsBonded = true;
BondingBegin = DateTime.MinValue;
from.SendLocalizedMessage(1049666); // Your pet has bonded with you!
}
}
else
else if (Core.ML)
{
for (var i = 0; i < amount; ++i)
{
if (m_Loyalty < MaxLoyalty && Utility.RandomBool())
{
m_Loyalty += 10;
}
}
// Your pet cannot form a bond with you until your animal taming ability has risen.
from.SendLocalizedMessage(1075268);
}
/* if (happier )*/
// looks like in OSI pets say they are happier even if they are at maximum loyalty
SayTo(from, 502060); // Your pet looks happier.
if (Body.IsAnimal)
{
Animate(3, 5, 1, true, false, 0);
}
else if (Body.IsMonster)
{
Animate(17, 5, 1, true, false, 0);
}
if (IsBondable && !IsBonded)
{
var master = m_ControlMaster;
if (master != null && master == from) // So friends can't start the bonding process
{
if (MinTameSkill <= 29.1 || master.Skills.AnimalTaming.Base >= MinTameSkill ||
OverrideBondingReqs() ||
Core.ML && master.Skills.AnimalTaming.Value >= MinTameSkill)
{
if (BondingBegin == DateTime.MinValue)
{
BondingBegin = Core.Now;
}
else if (BondingBegin + BondingDelay <= Core.Now)
{
IsBonded = true;
BondingBegin = DateTime.MinValue;
from.SendLocalizedMessage(1049666); // Your pet has bonded with you!
}
}
else if (Core.ML)
{
// Your pet cannot form a bond with you until your animal taming ability has risen.
from.SendLocalizedMessage(1075268);
}
}
}
dropped.Delete();
return true;
}
}
dropped.Delete();
return true;
}
return false;