private static void Postfix(Character __instance)
        {
            ZNetView znetView = AccessTools.Field(typeof(Character), "m_nview").GetValue(__instance) as ZNetView;

            if (znetView.GetZDO() != null && !__instance.IsPlayer() && (!znetView.HasOwner() || znetView.IsOwner()) && __instance.GetHealth() == __instance.GetMaxHealth())
            {
                AccessTools.Method(typeof(Character), "SetupMaxHealth", null, null).Invoke(__instance, null);
            }
        }
示例#2
0
            static bool Prefix(Fireplace __instance, Humanoid user, bool hold, ref bool __result, ZNetView ___m_nview)
            {
                __result = false;
                if (!AllowByKey())
                {
                    return(true);
                }
                if (hold)
                {
                    return(false);
                }
                if (!___m_nview.HasOwner())
                {
                    ___m_nview.ClaimOwnership();
                }
                Inventory inventory = user.GetInventory();

                if (inventory == null)
                {
                    __result = true;
                    return(false);
                }
                if (!inventory.HaveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name) && (float)Mathf.CeilToInt(___m_nview.GetZDO().GetFloat("fuel", 0f)) < __instance.m_maxFuel)
                {
                    List <Container> nearbyContainers = GetNearbyContainers(__instance.transform.position);

                    foreach (Container c in nearbyContainers)
                    {
                        ItemDrop.ItemData item = c.GetInventory().GetItem(__instance.m_fuelItem.m_itemData.m_shared.m_name);
                        if (item != null)
                        {
                            if (fuelDisallowTypes.Value.Split(',').Contains(item.m_dropPrefab.name))
                            {
                                Dbgl($"container at {c.transform.position} has {item.m_stack} {item.m_dropPrefab.name} but it's forbidden by config");
                                continue;
                            }
                            Dbgl($"container at {c.transform.position} has {item.m_stack} {item.m_dropPrefab.name}, taking one");
                            c.GetInventory().RemoveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name, 1);
                            typeof(Container).GetMethod("Save", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(c, new object[] { });
                            typeof(Inventory).GetMethod("Changed", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(c.GetInventory(), new object[] { });
                            user.Message(MessageHud.MessageType.Center, Localization.instance.Localize("$msg_fireadding", new string[]
                            {
                                __instance.m_fuelItem.m_itemData.m_shared.m_name
                            }), 0, null);
                            inventory.RemoveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name, 1);
                            ___m_nview.InvokeRPC("AddFuel", new object[] { });
                            __result = true;
                            return(false);
                        }
                    }
                }
                return(true);
            }