public ItemId PreformAction(Colony colony, RoamingJobState machineState) { if (machineState.GetActionEnergy(MachineConstants.REFUEL) < .75f) { var stockpile = colony.Stockpile; foreach (var item in FuelValues) { while ((stockpile.AmountContained(item.Key) > 100 || item.Key == ColonyBuiltIn.ItemTypes.FIREWOOD || item.Key == ColonyBuiltIn.ItemTypes.COALORE) && machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { stockpile.TryRemove(item.Key); machineState.AddToActionEmergy(MachineConstants.REFUEL, item.Value); } } if (machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { return(FuelValues.First().Key); } } return(ObjectiveLoadEmptyIcon); }
public static ItemId Refuel(Colony colony, RoamingJobState machineState) { if (machineState.GetActionEnergy(MachineConstants.REFUEL) < .75f) { RoamingJobState paired = null; if (_paired.ContainsKey(machineState.Position)) { GetPadAt(_paired[machineState.Position], out paired); } var stockpile = colony.Stockpile; while (stockpile.TryRemove(SettlersBuiltIn.ItemTypes.MANA) && machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { machineState.AddToActionEmergy(MachineConstants.REFUEL, 0.20f); if (paired != null) { paired.AddToActionEmergy(MachineConstants.REFUEL, 0.20f); } } if (machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { return(SettlersBuiltIn.ItemTypes.MANA); } } return(ItemId.GetItemId(GameLoader.NAMESPACE + ".Refuel")); }
public ItemId PreformAction(Colony colony, RoamingJobState state) { var retval = ItemId.GetItemId(GameLoader.NAMESPACE + ".Refuel"); if (state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill") < .70f) { var requiredForFix = new List <InventoryItem>(); var stockpile = colony.Stockpile; var energy = state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill"); var maxMana = RoamingJobState.GetActionsMaxEnergy(GameLoader.NAMESPACE + ".ManaTankRefill", colony, state.RoamingJobSettings.ObjectiveCategory); var manaCost = (int)System.Math.Round((maxMana - energy) / .02, 0); requiredForFix.Add(new InventoryItem(SettlersBuiltIn.ItemTypes.MANA.Id, manaCost)); if (stockpile.TryRemove(requiredForFix)) { state.ResetActionToMaxLoad(GameLoader.NAMESPACE + ".ManaTankRefill"); } else { foreach (var item in requiredForFix) { if (!stockpile.Contains(item)) { retval = ItemId.GetItemId(item.Type); break; } } } } return(retval); }
public static ItemId Reload(Colony colony, RoamingJobState machineState) { var retval = ItemId.GetItemId(GameLoader.NAMESPACE + ".Reload"); try { if (TurretSettings.ContainsKey(machineState.RoamObjective) && machineState.GetActionEnergy(MachineConstants.RELOAD) < .75f) { var stockpile = colony.Stockpile; while (stockpile.Contains(TurretSettings[machineState.RoamObjective].Ammo) && machineState.GetActionEnergy(MachineConstants.RELOAD) <= RoamingJobState.GetActionsMaxEnergy(MachineConstants.RELOAD, colony, MachineConstants.MECHANICAL)) { if (stockpile.TryRemove(TurretSettings[machineState.RoamObjective].Ammo)) { machineState.AddToActionEmergy(MachineConstants.RELOAD, TurretSettings[machineState.RoamObjective].AmmoReloadValue); if (TurretSettings[machineState.RoamObjective].Ammo.Any(itm => itm.Type == ColonyBuiltIn.ItemTypes.GUNPOWDERPOUCH)) { stockpile.Add(ColonyBuiltIn.ItemTypes.LINENPOUCH); } } } if (machineState.GetActionEnergy(MachineConstants.RELOAD) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.RELOAD, colony, MachineConstants.MECHANICAL)) { retval = ItemId.GetItemId(TurretSettings[machineState.RoamObjective].Ammo.FirstOrDefault(ammo => !stockpile.Contains(ammo)).Type); } } } catch (Exception ex) { SettlersLogger.LogError(ex); } return(retval); }
public void DoWork(Colony colony, RoamingJobState state) { var soundUpdate = state.TempValues.GetOrDefault("SoundUpdate", Time.SecondsSinceStartDouble); if (soundUpdate < Time.SecondsSinceStartDouble) { AudioManager.SendAudio(state.Position.Vector, "Pandaros.Settlers.ManaPump"); state.TempValues.Set("SoundUpdate", Time.SecondsSinceStartDouble + 16); } if (state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair") > 0 && state.NextTimeForWork < TimeCycle.TotalTime.Value.TotalMinutes && RoamingJobManager.Objectives.TryGetValue(colony, out var catDic) && catDic.TryGetValue(state.RoamingJobSettings.ObjectiveCategory, out var locDic)) { List <RoamingJobState> manaTanks = new List <RoamingJobState>(); HashSet <Vector3Int> exploredPos = new HashSet <Vector3Int>(); foreach (var side in _applicableBlockSides) { var offset = state.Position.GetBlockOffset(side); if (locDic.TryGetValue(offset, out var roamingJobState) && roamingJobState.RoamingJobSettings.ItemIndex.Name == SettlersBuiltIn.ItemTypes.MANATANK) { manaTanks.Add(roamingJobState); } } if (manaTanks.Count > 0) { foreach (var side in _applicableBlockSides) { var offset = state.Position.GetBlockOffset(side); Queue <Vector3Int> explore = new Queue <Vector3Int>(); explore.Enqueue(offset); var maxMana = RoamingJobState.GetActionsMaxEnergy(GameLoader.NAMESPACE + ".ManaTankRefill", colony, state.RoamingJobSettings.ObjectiveCategory); // walk mana pipes and find machines while (explore.Count > 0) { offset = explore.Dequeue(); foreach (var exploreSide in _applicableBlockSides) { var exploreOffset = offset.GetBlockOffset(exploreSide); if (!exploredPos.Contains(exploreOffset) && World.TryGetTypeAt(exploreOffset, out ItemTypes.ItemType exploredItem)) { if (API.Items.ItemCache.CSItems.TryGetValue(exploredItem.Name, out var csExploredItem) && csExploredItem.ConnectedBlock != null && csExploredItem.ConnectedBlock.BlockType == "ManaPipe") { explore.Enqueue(exploreOffset); exploredPos.Add(exploreOffset); if (locDic.TryGetValue(exploreOffset, out var exploredJobState)) { var existingEnergyDeficit = maxMana - exploredJobState.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill"); foreach (var tank in manaTanks) { var energy = tank.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill"); if (energy >= existingEnergyDeficit) { tank.SubtractFromActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill", existingEnergyDeficit); exploredJobState.ResetActionToMaxLoad(GameLoader.NAMESPACE + ".ManaTankRefill"); break; } else { tank.SubtractFromActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill", energy); existingEnergyDeficit = existingEnergyDeficit - energy; } state.SubtractFromActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair", .001f); } } } } } } } } state.NextTimeForWork = TimeCycle.TotalTime.Value.TotalMinutes + 10; } }
public TransportManager.ETransportUpdateResult Update() { if (_removed) { return(TransportManager.ETransportUpdateResult.Remove); } var currentPositionInt = new Pipliz.Vector3Int(Position); var heightFromTrack = _idealHeightFromTrack; if (TrackPosition == Pipliz.Vector3Int.zero) { for (int i = -1; i > _idealHeightFromTrack * -1; i--) { var trackPos = currentPositionInt.Add(0, i, 0); if (World.TryGetTypeAt(trackPos, out ItemTypes.ItemType possibleTrack) && ConnectedBlockSystem.BlockLookup.TryGetValue(possibleTrack.Name, out var track) && track.ConnectedBlock.CalculationType == _trackCalculationType.name && TrainType.ConnectedBlock.BlockType == track.ConnectedBlock.BlockType) { heightFromTrack = i * -1; TrackPosition = trackPos; break; } } } if (heightFromTrack != _idealHeightFromTrack) { Position = currentPositionInt.Add(0, heightFromTrack, 0).Vector; _meshedVehicleDescription.Object.SendMoveToInterpolated(Position, Quaternion.identity, (float)GetDelayMillisecondsToNextUpdate() / 1000f, _animatedObject.ObjSettings); } else if (TrackPosition != Pipliz.Vector3Int.zero) { bool moved = false; ICSType trainStation = null; if (_trainMoveTime < TimeCycle.TotalHours) { if (_minStopNextTime < TimeCycle.TotalHours) { foreach (var stationSide in _trackCalculationType.AvailableBlockSides) { var stationCheck = TrackPosition.GetBlockOffset(stationSide); if (World.TryGetTypeAt(stationCheck, out ItemTypes.ItemType possibleStation) && ItemCache.CSItems.TryGetValue(possibleStation.Name, out var station) && station.TrainStationSettings != null && station.TrainStationSettings.BlockType == TrainType.ConnectedBlock.BlockType) { trainStation = station; foreach (var kvp in RoamingJobManager.Objectives.Values) { if (kvp.TryGetValue(trainStation.TrainStationSettings.ObjectiveCategory, out var locDic) && locDic.TryGetValue(stationCheck, out var roamingJobState)) { var manaNeeded = RoamingJobState.GetActionsMaxEnergy(TrainType.TrainConfiguration.EnergyActionEnergyName, roamingJobState.Colony, TrainType.TrainConfiguration.RoamingJobCategory) - _energy; var existing = roamingJobState.GetActionEnergy(TrainType.TrainConfiguration.EnergyActionEnergyName); bool isWorked = true; try { if (roamingJobState.Colony.JobFinder.JobsData != null) { foreach (var job in roamingJobState.Colony.JobFinder.JobsData.OpenJobs) { try { if (job != null && job.GetJobLocation() == stationCheck) { isWorked = false; break; } } catch { } } } } catch (Exception ex) { if (roamingJobState.Colony.JobFinder == null) { APILogger.Log("roamingJobState.Colony.JobFinder == null"); } if (roamingJobState.Colony.JobFinder.JobsData == null) { APILogger.Log("roamingJobState.Colony.JobFinder.JobsData == null"); } if (roamingJobState.Colony.JobFinder.JobsData.OpenJobs == null) { APILogger.Log("roamingJobState.Colony.JobFinder.JobsData.OpenJobs == null"); } APILogger.LogError(ex); } if (!isWorked) { Indicator.SendIconIndicatorNear(stationCheck.Add(0, 1, 0).Vector, new IndicatorState(10, "npcicon", true, false)); } else if (existing > 0) { if (existing >= manaNeeded) { roamingJobState.SubtractFromActionEnergy(TrainType.TrainConfiguration.EnergyActionEnergyName, manaNeeded); _energy = RoamingJobState.GetActionsMaxEnergy(TrainType.TrainConfiguration.EnergyActionEnergyName, roamingJobState.Colony, TrainType.TrainConfiguration.RoamingJobCategory); roamingJobState.SubtractFromActionEnergy(TrainType.TrainConfiguration.DurabilityActionEnergyName, .01f); } else { roamingJobState.SubtractFromActionEnergy(TrainType.TrainConfiguration.EnergyActionEnergyName, existing); _energy += existing; roamingJobState.SubtractFromActionEnergy(TrainType.TrainConfiguration.DurabilityActionEnergyName, .01f); } Indicator.SendIconIndicatorNear(stationCheck.Add(0, 1, 0).Vector, new IndicatorState(10, TrainType.TrainConfiguration.EnergyType)); _minStopNextTime = TimeCycle.TotalHours + 2; _trainMoveTime = TimeCycle.TotalHours + 1; existing = roamingJobState.GetActionEnergy(TrainType.TrainConfiguration.EnergyActionEnergyName); } else { Indicator.SendIconIndicatorNear(stationCheck.Add(0, 1, 0).Vector, new IndicatorState(10, TrainType.TrainConfiguration.EnergyType, true, false)); } break; } } } } } if (trainStation == null && _energy > 0) { foreach (var side in _trackCalculationType.AvailableBlockSides) { var searchSide = TrackPosition.GetBlockOffset(side); var proposePos = currentPositionInt.GetBlockOffset(side).Vector; if (World.TryGetTypeAt(searchSide, out ItemTypes.ItemType possibleTrack) && ConnectedBlockSystem.BlockLookup.TryGetValue(possibleTrack.Name, out var track) && track.ConnectedBlock.CalculationType == _trackCalculationType.name && TrainType.ConnectedBlock.BlockType == track.ConnectedBlock.BlockType && proposePos != _prevPosition) { _prevPosition = Position; TrackPosition = searchSide; Position = currentPositionInt.GetBlockOffset(side).Vector; _meshedVehicleDescription.Object.SendMoveToInterpolated(Position, Quaternion.identity, (float)GetDelayMillisecondsToNextUpdate() / 1000f, _animatedObject.ObjSettings); _energy -= ManaCostPerBlock; if (_energy < 0) { _energy = 0; } ChunkQueue.QueueBannerBox(TrackPosition.Add(-30, -30, -30).ToChunk(), TrackPosition.Add(30, 30, 30).ToChunk()); moved = true; break; } } } } if (!moved) { _meshedVehicleDescription.Object.SendMoveToInterpolated(Position, Quaternion.identity, (float)GetDelayMillisecondsToNextUpdate() / 1000f, _animatedObject.ObjSettings); } if (!moved && _energy > 0) { _prevPosition = Vector3.zero; } if (!moved && _energy <= 0) { _trainMoveTime = 0; Indicator.SendIconIndicatorNear(new Pipliz.Vector3Int(Position).Add(0, 2, 0).Vector, new IndicatorState((float)GetDelayMillisecondsToNextUpdate() / 1000f, TrainType.TrainConfiguration.EnergyType, true, false)); } } return(TransportManager.ETransportUpdateResult.KeepUpdating); }