protected IEnumerator AddBattery(TechType techType, float setCharge = 0f) { if (techType == TechType.None) { yield break; } TaskResult <GameObject> result = new TaskResult <GameObject>(); yield return(AddInventoryAsync(techType, result)); //IBattery component = result.Get().GetComponent<IBattery>(); GameObject resultObject = result.Get(); if (resultObject != null && resultObject.TryGetComponent <IBattery>(out IBattery component)) { if (setCharge == 0f) { component.charge = 0f; } // if the passed value for charge is less than or equal to 1, use it as a multiplier else if (setCharge <= 1f) { component.charge = component.capacity * Mathf.Clamp01(setCharge); } else { component.charge = setCharge; } InventoryPatches.ResetBatteryCache(); } yield break; }
protected override IEnumerator PostPatchSetup() { yield return(base.PostPatchSetup()); BatteryCharger.compatibleTech.Add(this.TechType); InventoryPatches.AddChipRecharge(this.TechType); yield break; }
public void OnCraftEnd(TechType craftedTechType) { (int discharges, bool bDestroy)returnValue = GetChipData(craftedTechType); if (returnValue.discharges < 1) { Log.LogError($"DiverPerimeterDefenceBehaviour.OnCraftEnd(): craftedTechType of {craftedTechType.AsString()} returned invalid data! This is not a chip."); return; } this.techType = craftedTechType; this._maxDischarges = returnValue.discharges; this.bDestroyWhenEmpty = returnValue.bDestroy; TechType battery = InventoryPatches.GetCachedBattery(); float cachedCharge = InventoryPatches.GetCachedCharge(); Log.LogDebug($"DiverPerimeterDefenceBehaviour.OnCraftEnd({craftedTechType.AsString()}): battery = {battery.AsString()}, cachedCharge = {cachedCharge}"); if (battery != TechType.None) { if (cachedCharge >= 0f) { if (cachedCharge <= 1f) { this.charge = this.capacity * cachedCharge; } else { this.charge = cachedCharge; } } CoroutineHost.StartCoroutine(AddBattery(battery, 0f)); } else { this.charge = this.capacity; } Log.LogDebug($"DiverPerimeterDefenceBehaviour.OnCraftEnd({craftedTechType.AsString()}): completed"); }