Пример #1
0
        public static bool PreAllowedToAdd(Equipment __instance, ref bool __result, string slot, Pickupable pickupable, bool verbose)
        {
            //Log.LogDebug($"EquipmentPatches.PreAllowedToAdd(): __result = {__result}, slot = '{slot}'");

            TechType objTechType = pickupable.GetTechType();
            //Log.LogDebug($"EquipmentPatches.PreAllowedToAdd(): objTechType = {objTechType.AsString()}");
            EquipmentType slotType = Equipment.GetSlotType(slot);

            if (slotType == EquipmentType.BatteryCharger && InventoryPatches.IsChip(objTechType))
            {
#if BELOWZERO
                EquipmentType eType = TechData.GetEquipmentType(objTechType);
#else
                EquipmentType eType = CraftData.GetEquipmentType(objTechType);
#endif
                if (eType == EquipmentType.Chip || eType == EquipmentType.BatteryCharger)
                {
#if false
                    Logger.Log("DEBUG: AllowedToAdd battery charger for " + objTechType.AsString(false));
#endif
                    bool result = ((IItemsContainer)__instance).AllowedToAdd(pickupable, verbose);
                    __result = result;
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        internal static bool PreCanSwitchOrSwap(uGUI_Equipment __instance, ref ItemAction __result, string slotB)
        {
            //Log.LogDebug($"uGUI_EquipmentPatches.PreCanSwitchOrSwap(): __result = {__result.ToString()}, slotB = {slotB}");

            if (!ItemDragManager.isDragging)
            {
                return(true);
            }
            InventoryItem draggedItem = ItemDragManager.draggedItem;

            if (draggedItem == null)
            {
                return(true);
            }
            Pickupable item = draggedItem.item;

            if (item == null)
            {
                return(true);
            }
            TechType techType = item.GetTechType();

            if (InventoryPatches.IsChip(techType))
            {
                if (Equipment.GetSlotType(slotB) == EquipmentType.BatteryCharger)
                {
                    Equipment     equipmentValue = __instance.equipment;
                    InventoryItem itemInSlot     = equipmentValue.GetItemInSlot(slotB);
                    if (itemInSlot == null)
                    {
#if DEBUG
                        Logger.Log("DEBUG: CanSwitchOrSwap returns SWITCH battery for " + techType.AsString(false));
#endif
                        __result = ItemAction.Switch;
                        return(false);
                    }
                    if (Inventory.CanSwap(draggedItem, itemInSlot))
                    {
#if DEBUG
                        Logger.Log("DEBUG: CanSwitchOrSwap returns SWAP battery for " + techType.AsString(false));
#endif
                        __result = ItemAction.Swap;
                        return(false);
                    }
#if DEBUG
                    Logger.Log("DEBUG: CanSwitchOrSwap returns NONE battery for " + techType.AsString(false));
#endif
                    __result = ItemAction.None;
                    return(false);
                }
            }

            return(true);
        }
Пример #3
0
        public static bool PreIItemsContainerAllowedToAdd(Pickupable pickupable, Equipment __instance, ref bool __result)
        {
            //Log.LogDebug($"PreIItemsContainerAllowedToAdd(): __instance.label = {__instance._label}, pickupable = {pickupable.ToString()}, __result = {__result}");
            TechType tt = pickupable.GetTechType();

            // IsRechargeableChip() is probably faster than a string.Contains() so we're doing that first, so that the slower check doesn't even happen if it's not needed.
            if (InventoryPatches.IsRechargeableChip(tt) && __instance._label.Contains("BatteryCharger"))
            {
                __result = true;
                return(false);
            }

            return(true);
        }
        internal static void PostCanBite(MeleeAttack __instance, ref bool __result, GameObject target)
        {
            //Log.LogDebug($"MeleeAttackPatches.PostCanBite(): __result = {__result}, target = {target.name}");
            if (__result) // No point doing anything if the game has already concluded that it can't bite!
            {
                //GameObject target = __instance.GetTarget(collider);
                if (target.TryGetComponent <Player>(out Player component))
                {
                    //TechType chipType = Main.GetModTechType("DiverPerimeterDefenceChipItem");
                    //Log.LogDebug($"MeleeAttackPatches.PostCanBite: Target is player, checking for discharge chip");
                    Equipment e = Inventory.main.equipment;
                    if (Main.chipSlots.Count < 1)
                    {
                        e.GetSlots(EquipmentType.Chip, Main.chipSlots);
                    }
                    foreach (string slot in Main.chipSlots)
                    {
                        TechType tt = e.GetTechTypeInSlot(slot);
                        //Log.LogDebug($"MeleeAttackPatches.PostCanBite: found TechType {tt.AsString()} in slot {slot}");
                        if (InventoryPatches.IsChip(tt))
                        {
                            InventoryItem item = e.GetItemInSlot(slot);
                            //Log.LogDebug($"MeleeAttackPatches.PostCanBite: Found discharge chip {tt.AsString()} in slot {slot}, checking for associated MonoBehaviour");

                            /*DiverPerimeterDefenceBehaviour behaviour = item.item.gameObject.GetComponent<DiverPerimeterDefenceBehaviour>();
                             *                          if (behaviour != null)*/
                            if (item.item.gameObject.TryGetComponent <DiverPerimeterDefenceBehaviour>(out DiverPerimeterDefenceBehaviour behaviour))
                            {
                                //Log.LogDebug($"MeleeAttackPatches.PostCanBite: MonoBehaviour found, calling Discharge()");
                                if (behaviour.Discharge(__instance.gameObject))
                                {
                                    //Log.LogDebug($"MeleeAttackPatches.PostCanBite: Discharge() returned true");
                                    __result = false;
                                    return;
                                }
                                else
                                {
                                    //Log.LogDebug($"MeleeAttackPatches.PostCanBite: Discharge() returned false");
                                }
                            }
                        }
                    }
                }
            }
        }