//Executing the namesake of the mod. //Function will confirm that all needs are met for swapping a lens. //Proper care needs to be taken here to never delete an "old lens", as the ALS has no //internal storage for oldLenses. //Must not have any mIssue or checkReady checks in this funtion; lest it become recursive/unreachable. private bool runSwapLens(LaserPowerTransmitter lpt) { if (lpt == null) { return(false); } ItemBase oldLens = lpt.GetLens(); bool hasLens = (oldLens != null); if (mbOnlySwap && !hasLens) { ++mnTrackLPTs; return(false); } if (hasLens) { if (oldLens.mnItemID == mStoredLenses.mnItemID) { ++mnTrackLPTs; return(false); } else { if (!CommunityUtil.GiveToSurrounding((MachineEntity)this, oldLens)) { Debug.LogWarning("[Auto Lens Swapper][issue] Could not find a surrounding machine to drop an old lens into! Lens was not removed."); mIssue = eIssues.Output; mLastLPT = lpt; return(false); } } } lpt.SwapLens(mTargetLens); AddLenses(-1); mrCurrentPower -= mrPowerPerSwap; ++mnTrackLPTs; ++mnTrackSwaps; MarkDirtyDelayed(); return(true); }
private bool TakeLensSurrounding() { ItemBase taken = CommunityUtil.TakeFromSurrounding((MachineEntity)this, mTargetLens); if (taken == null) { return(false); } if (taken.GetAmount() <= 0) { return(false); } if (taken.GetAmount() > getStorageAvailable()) { Debug.Log("[Auto Lens Swapper][info] 'Take Surrounding' took more than max_storage!\nNothing lost, but not intended!"); } AddLenses(taken.GetAmount()); MarkDirtyDelayed(); return(true); }