Files
zzz_REBIRTH__Utils/Harmony/Harmony_GameUtils.cs
2025-06-04 16:44:53 +09:30

61 lines
2.9 KiB
C#

using System.Diagnostics;
namespace Harmony.GameUtilsPatches
{
[HarmonyPatch(typeof(GameUtils))]
[HarmonyPatch("collectHarvestedItem")]
public class collectHarvestedItem
{
private static bool Prefix(GameUtils __instance, ItemActionData _actionData, ItemValue _iv, int _count, float _prob, bool _bScaleCountOnDamage,
ref GameRandom ___random
)
{
//Log.Out("GameUtilsHarmony-collectHarvestedItem itemName: " + _iv.ItemClass.GetItemName());
bool downgradeBlock = RebirthVariables.customReplantTrees;
if (downgradeBlock && _iv.ItemClass.GetItemName().Contains("treePlanted"))
{
return false;
}
if (___random == null)
{
___random = GameRandomManager.Instance.CreateGameRandom();
___random.SetSeed((int)Stopwatch.GetTimestamp());
}
if (_bScaleCountOnDamage)
{
float num = (float)_actionData.attackDetails.damageMax / (float)_count;
int num2 = (int)((Utils.FastMin(_actionData.attackDetails.damageTotalOfTarget, (float)_actionData.attackDetails.damageMax) - (float)_actionData.attackDetails.damageGiven) / num + 0.5f);
int num3 = Mathf.Min((int)(_actionData.attackDetails.damageTotalOfTarget / num + 0.5f), _count);
int b = _count;
_count = num3 - num2;
if (_actionData.attackDetails.damageTotalOfTarget > (float)_actionData.attackDetails.damageMax)
{
_count = Mathf.Min(_count, b);
}
}
if (___random.RandomFloat <= _prob && _count > 0)
{
ItemStack itemStack = new ItemStack(_iv, _count);
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_actionData.invData.holdingEntity as EntityPlayerLocal);
EntityPlayerLocal player = (EntityPlayerLocal)_actionData.invData.holdingEntity;
if (player != null)
{
int randomInt = RebirthUtilities.GetQualityFromLootstage(player);
itemStack.itemValue.Quality = (ushort)randomInt;
}
if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack))
{
GameManager.Instance.ItemDropServer(new ItemStack(_iv, itemStack.count), GameManager.Instance.World.GetPrimaryPlayer().GetDropPosition(), new Vector3(0.5f, 0.5f, 0.5f), GameManager.Instance.World.GetPrimaryPlayerId(), 60f, false);
}
uiforPlayer.entityPlayer.Progression.AddLevelExp((int)(itemStack.itemValue.ItemClass.MadeOfMaterial.Experience * (float)_count), "_xpFromHarvesting", global::Progression.XPTypes.Harvesting, true);
}
return false;
}
}
}