fix(trol): no food in two slots at once, and Pukeberries empty slots 4 and 5
Vanilla only checks its own three slots, so a meal still digesting in the 4th or 5th stomach was eaten again as new as soon as a vanilla slot freed up. The extra stomachs are now asked first, in both CanConsumeItem and EatFood. Pukeberries remove food through RemoveOneFood, which only picked from the vanilla three; slots 4 and 5 now join the same draw.
This commit is contained in:
parent
2f64bcfc38
commit
c4b119b406
1 changed files with 63 additions and 45 deletions
|
|
@ -31,7 +31,6 @@ namespace RacesOfValheim
|
||||||
return f.CanEatAgain();
|
return f.CanEatAgain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (foods.Count < 3) return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool state5 = BossProgressionManager.GetCurrentProgressionState() >= 6;
|
bool state5 = BossProgressionManager.GetCurrentProgressionState() >= 6;
|
||||||
|
|
@ -41,8 +40,13 @@ namespace RacesOfValheim
|
||||||
bool has5 = TrolFoodManager.ExtraFoods5.TryGetValue(player, out Player.Food food5) && food5 != null;
|
bool has5 = TrolFoodManager.ExtraFoods5.TryGetValue(player, out Player.Food food5) && food5 != null;
|
||||||
bool canEat5 = has5 && food5.m_time >= (food5.m_item.m_shared.m_foodBurnTime * 0.5f);
|
bool canEat5 = has5 && food5.m_time >= (food5.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||||
|
|
||||||
|
// The extra stomachs are asked BEFORE the free vanilla slot below. The other way round,
|
||||||
|
// a meal already sitting in slot 4 or 5 was eaten a second time as soon as one of the
|
||||||
|
// three vanilla slots emptied, and the same food showed up twice.
|
||||||
if (has4 && food4.m_item.m_shared.m_name == item.m_shared.m_name) return canEat4;
|
if (has4 && food4.m_item.m_shared.m_name == item.m_shared.m_name) return canEat4;
|
||||||
if (state5 && has5 && food5.m_item.m_shared.m_name == item.m_shared.m_name) return canEat5;
|
if (has5 && food5.m_item.m_shared.m_name == item.m_shared.m_name) return state5 && canEat5;
|
||||||
|
|
||||||
|
if (foods != null && foods.Count < 3) return true;
|
||||||
|
|
||||||
if (!has4 || canEat4) return true;
|
if (!has4 || canEat4) return true;
|
||||||
if (state5 && (!has5 || canEat5)) return true;
|
if (state5 && (!has5 || canEat5)) return true;
|
||||||
|
|
@ -71,32 +75,25 @@ namespace RacesOfValheim
|
||||||
[HarmonyPatch(typeof(Player), "EatFood")]
|
[HarmonyPatch(typeof(Player), "EatFood")]
|
||||||
public static class Trol_PlayerEatFood_Patch
|
public static class Trol_PlayerEatFood_Patch
|
||||||
{
|
{
|
||||||
private static bool CanEatNative(Player player, ItemDrop.ItemData item)
|
|
||||||
{
|
|
||||||
var foods = Traverse.Create(player).Field("m_foods").GetValue<List<Player.Food>>();
|
|
||||||
if (foods != null)
|
|
||||||
{
|
|
||||||
foreach (Player.Food food in foods)
|
|
||||||
{
|
|
||||||
if (food.m_item.m_shared.m_name == item.m_shared.m_name)
|
|
||||||
{
|
|
||||||
return food.CanEatAgain();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (foods.Count < 3) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Prefix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
public static bool Prefix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
||||||
{
|
{
|
||||||
if (__instance != Player.m_localPlayer || !TrolRace.IsTrol()) return true;
|
if (__instance != Player.m_localPlayer || !TrolRace.IsTrol()) return true;
|
||||||
|
|
||||||
// If Valheim's native system can eat it (meaning it's either going to fill one of the first 3 slots,
|
var foods = Traverse.Create(__instance).Field("m_foods").GetValue<List<Player.Food>>();
|
||||||
// or replace an already eaten flashing food), let the native system handle it completely!
|
|
||||||
if (CanEatNative(__instance, item))
|
// 1. Already in a vanilla slot: vanilla refreshes a flashing one. The rest it refuses
|
||||||
|
// silently (it calls CanEat with showMessages off), so the message is ours.
|
||||||
|
if (foods != null)
|
||||||
{
|
{
|
||||||
return true;
|
foreach (Player.Food f in foods)
|
||||||
|
{
|
||||||
|
if (f.m_item.m_shared.m_name != item.m_shared.m_name) continue;
|
||||||
|
if (f.CanEatAgain()) return true;
|
||||||
|
|
||||||
|
__instance.Message(MessageHud.MessageType.Center, "$msg_eatanother");
|
||||||
|
__result = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool state5 = BossProgressionManager.GetCurrentProgressionState() >= 6;
|
bool state5 = BossProgressionManager.GetCurrentProgressionState() >= 6;
|
||||||
|
|
@ -107,34 +104,24 @@ namespace RacesOfValheim
|
||||||
bool has5 = TrolFoodManager.ExtraFoods5.TryGetValue(__instance, out Player.Food food5) && food5 != null;
|
bool has5 = TrolFoodManager.ExtraFoods5.TryGetValue(__instance, out Player.Food food5) && food5 != null;
|
||||||
bool canEat5 = has5 && food5.m_time >= (food5.m_item.m_shared.m_foodBurnTime * 0.5f);
|
bool canEat5 = has5 && food5.m_time >= (food5.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||||
|
|
||||||
// 1. Is it already in native slots but NOT flashing? (If flashing, CanEatNative would have caught it)
|
// 2. Already in slot 4 or 5. Asked before the free vanilla slot in step 3: vanilla only
|
||||||
var foods = Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.Generic.List<Player.Food>>();
|
// looks at its own three, so it took a meal the Trol was still digesting in an extra
|
||||||
if (foods != null)
|
// stomach as a new one, and the same food sat in two slots at once.
|
||||||
{
|
|
||||||
foreach (Player.Food f in foods)
|
|
||||||
{
|
|
||||||
if (f.m_item.m_shared.m_name == item.m_shared.m_name)
|
|
||||||
{
|
|
||||||
__instance.Message(MessageHud.MessageType.Center, "$msg_eatanother");
|
|
||||||
__result = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Is it already in slot 4 or 5?
|
|
||||||
if (has4 && food4.m_item.m_shared.m_name == item.m_shared.m_name)
|
if (has4 && food4.m_item.m_shared.m_name == item.m_shared.m_name)
|
||||||
{
|
{
|
||||||
if (canEat4) { TrolFoodManager.SetExtraFood(__instance, item); ConsumeItemEffect(__instance, item); __result = true; return false; }
|
if (canEat4) { TrolFoodManager.SetExtraFood(__instance, item); ConsumeItemEffect(__instance, item); __result = true; return false; }
|
||||||
else { __instance.Message(MessageHud.MessageType.Center, "$msg_eatanother"); __result = false; return false; }
|
else { __instance.Message(MessageHud.MessageType.Center, "$msg_eatanother"); __result = false; return false; }
|
||||||
}
|
}
|
||||||
if (state5 && has5 && food5.m_item.m_shared.m_name == item.m_shared.m_name)
|
if (has5 && food5.m_item.m_shared.m_name == item.m_shared.m_name)
|
||||||
{
|
{
|
||||||
if (canEat5) { TrolFoodManager.SetExtraFood5(__instance, item); ConsumeItemEffect(__instance, item); __result = true; return false; }
|
if (state5 && canEat5) { TrolFoodManager.SetExtraFood5(__instance, item); ConsumeItemEffect(__instance, item); __result = true; return false; }
|
||||||
else { __instance.Message(MessageHud.MessageType.Center, "$msg_eatanother"); __result = false; return false; }
|
else { __instance.Message(MessageHud.MessageType.Center, "$msg_eatanother"); __result = false; return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Not in any slots. Try to fill an empty slot or replace a flashing one
|
// 3. A free vanilla slot takes it the vanilla way.
|
||||||
|
if (foods != null && foods.Count < 3) return true;
|
||||||
|
|
||||||
|
// 4. Not in any slot. Try to fill an empty extra slot or replace a flashing one
|
||||||
if (!has4 || canEat4)
|
if (!has4 || canEat4)
|
||||||
{
|
{
|
||||||
TrolFoodManager.SetExtraFood(__instance, item);
|
TrolFoodManager.SetExtraFood(__instance, item);
|
||||||
|
|
@ -222,6 +209,37 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pukeberries empty the extra stomachs too.
|
||||||
|
///
|
||||||
|
/// SE_Puke calls RemoveOneFood once a second, and vanilla only ever picks from its own three
|
||||||
|
/// slots - then returns false once they are empty and stops. Slots 4 and 5 never came up, so
|
||||||
|
/// a Trol could not get rid of a meal there by any means. They now go into the same random
|
||||||
|
/// draw as the other three, so the berries empty all five, one a second, as they do three.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "RemoveOneFood")]
|
||||||
|
public static class Trol_PlayerRemoveOneFood_Patch
|
||||||
|
{
|
||||||
|
public static bool Prefix(Player __instance, List<Player.Food> ___m_foods, ref bool __result)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer || !TrolRace.IsTrol()) return true;
|
||||||
|
|
||||||
|
var extra = new List<Dictionary<Player, Player.Food>>(2);
|
||||||
|
if (TrolFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food food4) && food4 != null) extra.Add(TrolFoodManager.ExtraFoods);
|
||||||
|
if (TrolFoodManager.ExtraFoods5.TryGetValue(__instance, out Player.Food food5) && food5 != null) extra.Add(TrolFoodManager.ExtraFoods5);
|
||||||
|
if (extra.Count == 0) return true;
|
||||||
|
|
||||||
|
int vanillaCount = ___m_foods != null ? ___m_foods.Count : 0;
|
||||||
|
int pick = Random.Range(0, vanillaCount + extra.Count);
|
||||||
|
if (pick < vanillaCount) return true; // one of vanilla's three, removed by vanilla
|
||||||
|
|
||||||
|
extra[pick - vanillaCount].Remove(__instance);
|
||||||
|
TrolFoodManager.SaveFood(__instance);
|
||||||
|
__result = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
|
[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
|
||||||
public static class Trol_PlayerGetTotalFoodValue_Patch
|
public static class Trol_PlayerGetTotalFoodValue_Patch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue