public ItemId PreformAction(Colony colony, RoamingJobState state) { var retval = ItemId.GetItemId(GameLoader.NAMESPACE + ".Repairing"); if (!colony.OwnerIsOnline() && SettlersConfiguration.OfflineColonies || colony.OwnerIsOnline()) { if (state.GetActionEnergy(MachineConstants.REPAIR) < .75f) { var repaired = false; var requiredForFix = new List <InventoryItem>(); var stockpile = colony.Stockpile; requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.PLANKS.Name, 1)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERNAILS.Name, 1)); if (state.GetActionEnergy(MachineConstants.REPAIR) < .10f) { requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.IRONWROUGHT.Name, 1)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERPARTS.Name, 4)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.IRONRIVET.Name, 1)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERTOOLS.Name, 1)); } else if (state.GetActionEnergy(MachineConstants.REPAIR) < .30f) { requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.IRONWROUGHT.Name, 1)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERPARTS.Name, 2)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERTOOLS.Name, 1)); } else if (state.GetActionEnergy(MachineConstants.REPAIR) < .50f) { requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERPARTS.Name, 1)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERTOOLS.Name, 1)); } if (stockpile.Contains(requiredForFix)) { stockpile.TryRemove(requiredForFix); repaired = true; } else { foreach (var item in requiredForFix) { if (!stockpile.Contains(item)) { retval = ItemId.GetItemId(item.Type); break; } } } if (repaired) { state.ResetActionToMaxLoad(MachineConstants.REPAIR); } } } return(retval); }
public void DoWork(Colony colony, RoamingJobState state) { if (_nextWorkTime < TimeCycle.TotalHours) { var fuel = state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill"); var durability = state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair"); if (fuel > 0 && durability > 0) { state.SubtractFromActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill", .2f); state.SubtractFromActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair", .05f); if (World.TryGetTypeAt(state.Position, out ItemTypes.ItemType itemType) && itemType.Name == GameLoader.NAMESPACE + ".GoldCubeUnlit") { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".GoldCube").Id); } } else { if (World.TryGetTypeAt(state.Position, out ItemTypes.ItemType itemType) && itemType.Name == GameLoader.NAMESPACE + ".GoldCube") { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".GoldCubeUnlit").Id); } } _nextWorkTime = TimeCycle.TotalHours + 1; } }
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 void DoWork(Colony colony, RoamingJobState state) { state.InitializeActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill", 0); if (state.NextTimeForWork < Time.SecondsSinceStartDouble) { var energy = state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill"); if (energy > .90) { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".TankFull")); } else if (energy > .75) { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".TankThreeQuarter")); } else if (energy > .50) { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".TankHalf")); } else if (energy > .25) { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".TankQuarter")); } else { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".ManaTank")); } state.NextTimeForWork = Time.SecondsSinceStartDouble + 10; } }
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 static bool GetPadAt(Vector3Int pos, out RoamingJobState state) { try { if (pos != null) { lock (RoamingJobManager.Objectives) { foreach (var kvp in RoamingJobManager.Objectives) { foreach (var p in kvp.Value) { if (p.Value.TryGetValue(pos, out var roamingJobState)) { if (roamingJobState.RoamObjective == SettlersBuiltIn.ItemTypes.TELEPORTPAD) { state = p.Value[pos]; return(true); } } } } } } } catch (Exception ex) { SettlersLogger.LogError(ex); } state = null; return(false); }
public ItemId PreformAction(Colony colony, RoamingJobState state) { var retval = ItemId.GetItemId(Nach0Config.IndicatorTypePrefix + "Clean"); if (colony.OwnerIsOnline()) { if (state.GetActionEnergy(ToiletConstants.CLEAN) < .75f) { var repaired = false; var requiredForClean = new List <InventoryItem>(); var returnedFromClean = new List <InventoryItem>(); var stockpile = colony.Stockpile; int itemReqMult = 1; if (state.GetActionEnergy(ToiletConstants.CLEAN) < .50f) { itemReqMult++; } if (state.GetActionEnergy(ToiletConstants.CLEAN) < .30f) { itemReqMult++; } if (state.GetActionEnergy(ToiletConstants.CLEAN) < .10f) { itemReqMult++; } requiredForClean.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.BUCKETWATER.Name, 1 * itemReqMult)); returnedFromClean.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.BUCKETEMPTY.Name, 1 * itemReqMult)); if (stockpile.Contains(requiredForClean)) { stockpile.TryRemove(requiredForClean); repaired = true; stockpile.Add(returnedFromClean); } else { foreach (var item in requiredForClean) { if (!stockpile.Contains(item)) { retval = ItemId.GetItemId(item.Type); break; } } } if (repaired) { state.ResetActionToMaxLoad(ToiletConstants.CLEAN); } } } return(retval); }
public static ItemId Reload(Colony colony, RoamingJobState machineState) { if (colony.OwnerIsOnline()) { machineState.ResetActionToMaxLoad(MachineConstants.RELOAD); } return(ItemId.GetItemId(GameLoader.NAMESPACE + ".Reload")); }
public static ItemId Repair(Colony colony, RoamingJobState machineState) { var retval = ItemId.GetItemId(GameLoader.NAMESPACE + ".Repairing"); try { if (machineState.GetActionEnergy(MachineConstants.REPAIR) < .75f && TurretSettings.ContainsKey(machineState.RoamObjective)) { var repaired = false; var requiredForFix = new List <InventoryItem>(); var stockpile = colony.Stockpile; foreach (var durability in TurretSettings[machineState.RoamObjective] .RequiredForFix.OrderByDescending(s => s.Key)) { if (machineState.GetActionEnergy(MachineConstants.REPAIR) < durability.Key) { requiredForFix = durability.Value; break; } } if (stockpile.Contains(requiredForFix)) { stockpile.TryRemove(requiredForFix); repaired = true; } else { foreach (var item in requiredForFix) { if (!stockpile.Contains(item) && item.Type != 0) { retval = ItemId.GetItemId(item.Type); break; } } } if (repaired) { machineState.ResetActionToMaxLoad(MachineConstants.REPAIR); } } } catch (Exception ex) { SettlersLogger.LogError(ex); } return(retval); }
public static ItemId Repair(Colony colony, RoamingJobState machineState) { var retval = ItemId.GetItemId(GameLoader.NAMESPACE + ".Repairing"); if (colony.OwnerIsOnline() && machineState.GetActionEnergy(MachineConstants.REPAIR) < .75f) { var repaired = false; var requiredForFix = new List <InventoryItem>(); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERTOOLS.Name, 1)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERPARTS.Name, 1)); if (machineState.GetActionEnergy(MachineConstants.REPAIR) < .10f) { requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERPARTS.Name, 4)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.PLANKS.Name, 1)); } else if (machineState.GetActionEnergy(MachineConstants.REPAIR) < .30f) { requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERPARTS.Name, 3)); } else if (machineState.GetActionEnergy(MachineConstants.REPAIR) < .50f) { requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COPPERPARTS.Name, 2)); } if (colony.Stockpile.Contains(requiredForFix)) { colony.Stockpile.TryRemove(requiredForFix); repaired = true; } else { foreach (var item in requiredForFix) { if (!colony.Stockpile.Contains(item)) { retval = ItemId.GetItemId(item.Type); break; } } } if (repaired) { machineState.ResetActionToMaxLoad(MachineConstants.REPAIR); } } return(retval); }
public ItemId PreformAction(Colony player, RoamingJobState state) { var items = state.TempValues.GetOrDefault <List <InventoryItem> >("MinedItems", new List <InventoryItem>()); foreach (var item in items) { player.Stockpile.Add(item); } items.Clear(); state.ResetActionToMaxLoad(MachineConstants.INVENTORY); state.TempValues.Set("MinedItems", items); return(ItemId.GetItemId(GameLoader.NAMESPACE + ".Inventory")); }
public void DoWork(Colony colony, RoamingJobState machineState) { if ((!colony.OwnerIsOnline() && SettlersConfiguration.OfflineColonies) || colony.OwnerIsOnline()) { if (machineState.GetActionEnergy(MachineConstants.REPAIR) > 0 && machineState.GetActionEnergy(MachineConstants.REFUEL) > 0 && machineState.NextTimeForWork < Time.SecondsSinceStartDouble) { machineState.SubtractFromActionEnergy(MachineConstants.REPAIR, 0.02f); machineState.SubtractFromActionEnergy(MachineConstants.REFUEL, 0.05f); if (World.TryGetTypeAt(machineState.Position.Add(0, -1, 0), out ItemTypes.ItemType itemBelow) && itemBelow.CustomDataNode != null && itemBelow.CustomDataNode.TryGetAs("minerIsMineable", out bool minable) && minable) { var itemList = itemBelow.OnRemoveItems; if (itemList != null && itemList.Count > 0) { var mineTime = itemBelow.CustomDataNode.GetAsOrDefault("minerMiningTime", machineState.RoamingJobSettings.WorkTime); machineState.NextTimeForWork = mineTime + Time.SecondsSinceStartDouble; for (var i = 0; i < itemList.Count; i++) { if (Random.NextDouble() <= itemList[i].chance) { colony.Stockpile.Add(itemList[i].item); } } AudioManager.SendAudio(machineState.Position.Vector, GameLoader.NAMESPACE + ".MiningMachineAudio"); Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(mineTime, itemList.FirstOrDefault().item.Type)); } else { machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(machineState.RoamingJobSettings.WorkTime, ColonyBuiltIn.ItemTypes.ERRORIDLE.Name)); } } else { machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(machineState.RoamingJobSettings.WorkTime, ColonyBuiltIn.ItemTypes.ERRORIDLE.Name)); } } } }
public static void DoWork(Colony colony, RoamingJobState machineState) { if (!SettlersConfiguration.TeleportPadsRequireMachinists) { return; } if (_paired.ContainsKey(machineState.Position) && GetPadAt(_paired[machineState.Position], out var ms) && machineState.GetActionEnergy(MachineConstants.REPAIR) > 0 && machineState.GetActionEnergy(MachineConstants.REFUEL) > 0 && machineState.NextTimeForWork < Time.SecondsSinceStartDouble) { machineState.SubtractFromActionEnergy(MachineConstants.REPAIR, 0.01f); machineState.SubtractFromActionEnergy(MachineConstants.REFUEL, 0.05f); machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; } }
public ItemId PreformAction(Colony colony, RoamingJobState state) { var retval = ItemId.GetItemId(GameLoader.NAMESPACE + ".Repairing"); if (state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair") < .50f) { var repaired = false; var requiredForFix = new List <InventoryItem>(); var stockpile = colony.Stockpile; requiredForFix.Add(new InventoryItem(SettlersBuiltIn.ItemTypes.ADAMANTINE.Id)); requiredForFix.Add(new InventoryItem(SettlersBuiltIn.ItemTypes.MAGICWAND.Id)); requiredForFix.Add(new InventoryItem(ColonyBuiltIn.ItemTypes.COATEDPLANKS.Id)); requiredForFix.Add(new InventoryItem(SettlersBuiltIn.ItemTypes.REFINEDEMERALD.Id)); requiredForFix.Add(new InventoryItem(SettlersBuiltIn.ItemTypes.REFINEDSAPPHIRE.Id)); requiredForFix.Add(new InventoryItem(SettlersBuiltIn.ItemTypes.REFINEDRUBY.Id)); if (stockpile.Contains(requiredForFix)) { stockpile.TryRemove(requiredForFix); repaired = true; } else { foreach (var item in requiredForFix) { if (!stockpile.Contains(item)) { retval = ItemId.GetItemId(item.Type); break; } } } if (repaired) { state.ResetActionToMaxLoad(GameLoader.NAMESPACE + ".ManaMachineRepair"); } } return(retval); }
public void DoWork(Colony colony, RoamingJobState toiletState) { if (colony.OwnerIsOnline()) { if (toiletState.GetActionEnergy(ToiletConstants.CLEAN) > 0 && toiletState.NextTimeForWork < Pipliz.Time.SecondsSinceStartDouble) { if (TimeCycle.IsDay) { toiletState.SubtractFromActionEnergy(ToiletConstants.CLEAN, 0.05f); } else { toiletState.SubtractFromActionEnergy(ToiletConstants.CLEAN, 0.02f); } toiletState.NextTimeForWork = toiletState.RoamingJobSettings.WorkTime + Pipliz.Time.SecondsSinceStartDouble; } } }
public void DoWork(Colony colony, RoamingJobState state) { if (_nextWorkTime < TimeCycle.TotalHours) { var fuel = state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill"); var durability = state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair"); if (!ColonyManagement.DecorHappiness.DecorBonuses.ContainsKey(colony)) { ColonyManagement.DecorHappiness.DecorBonuses.Add(colony, new Dictionary <string, float>()); } if (fuel > 0 && durability > 0) { ColonyManagement.DecorHappiness.DecorBonuses[colony][nameof(GoldCube)] = 10f; state.SubtractFromActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill", .2f); state.SubtractFromActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair", .05f); if (World.TryGetTypeAt(state.Position, out ItemTypes.ItemType itemType) && itemType.Name == GameLoader.NAMESPACE + ".GoldCubeUnlit") { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".GoldCube").Id); } } else { if (ColonyManagement.DecorHappiness.DecorBonuses[colony].ContainsKey(nameof(GoldCube))) { ColonyManagement.DecorHappiness.DecorBonuses[colony].Remove(nameof(GoldCube)); } if (World.TryGetTypeAt(state.Position, out ItemTypes.ItemType itemType) && itemType.Name == GameLoader.NAMESPACE + ".GoldCube") { ServerManager.TryChangeBlock(state.Position, ItemId.GetItemId(GameLoader.NAMESPACE + ".GoldCubeUnlit").Id); } } _nextWorkTime = TimeCycle.TotalHours + 1; } }
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 static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d) { if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled) { return; } if (d.TypeNew.ItemIndex == Item.ItemIndex && d.TypeOld.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id) { var ps = PlayerState.GetPlayerState(d.RequestOrigin.AsPlayer); var ms = new RoamingJobState(d.Position, d.RequestOrigin.AsPlayer.ActiveColony, Item.name); if (ps.TeleporterPlaced == Vector3Int.invalidPos) { ps.TeleporterPlaced = d.Position; PandaChat.Send(d.RequestOrigin.AsPlayer, _localizationHelper, "PlaceAnotherTeleporter", ChatColor.orange); } else { if (GetPadAt(ps.TeleporterPlaced, out var machineState)) { _paired[ms.Position] = machineState.Position; _paired[machineState.Position] = ms.Position; PandaChat.Send(d.RequestOrigin.AsPlayer, _localizationHelper, "TeleportersLinked", ChatColor.orange); ps.TeleporterPlaced = Vector3Int.invalidPos; } else { ps.TeleporterPlaced = d.Position; PandaChat.Send(d.RequestOrigin.AsPlayer, _localizationHelper, "PlaceAnotherTeleporter", ChatColor.orange); } } } }
public ItemId PreformAction(Colony colony, RoamingJobState state) { return(Turret.Reload(colony, state)); }
public void DoWork(Colony c, RoamingJobState state) { Turret.DoWork(c, state); }
public static void DoWork(Colony colony, RoamingJobState machineState) { try { if (TurretSettings.ContainsKey(machineState.RoamObjective) && machineState.GetActionEnergy(MachineConstants.REPAIR) > 0 && machineState.GetActionEnergy(MachineConstants.REFUEL) > 0 && machineState.NextTimeForWork < Time.SecondsSinceStartDouble) { var stockpile = colony.Stockpile; machineState.SubtractFromActionEnergy(MachineConstants.REPAIR, TurretSettings[machineState.RoamObjective].DurabilityPerDoWork); machineState.SubtractFromActionEnergy(MachineConstants.REFUEL, TurretSettings[machineState.RoamObjective].FuelPerDoWork); if (machineState.GetActionEnergy(MachineConstants.RELOAD) > 0) { var totalDamage = TurretSettings[machineState.RoamObjective].TotalDamage; var monster = MonsterTracker.Find(machineState.Position.Add(0, 1, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(1, 0, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(-1, 0, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, -1, 0), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, 0, 1), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster == null) { monster = MonsterTracker.Find(machineState.Position.Add(0, 0, -1), TurretSettings[machineState.RoamObjective].Range, totalDamage); } if (monster != null) { machineState.SubtractFromActionEnergy(MachineConstants.RELOAD, TurretSettings[machineState.RoamObjective].AmmoValue); if (World.TryGetTypeAt(machineState.Position.Add(0, 1, 0), out ushort above) && above == ColonyBuiltIn.ItemTypes.AIR.Id) { Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(TurretSettings[machineState.RoamObjective].WorkTime, TurretSettings[machineState.RoamObjective].Ammo.FirstOrDefault().Type)); } if (TurretSettings[machineState.RoamObjective].OnShootAudio != null) { AudioManager.SendAudio(machineState.Position.Vector, TurretSettings[machineState.RoamObjective].OnShootAudio); } if (TurretSettings[machineState.RoamObjective].OnHitAudio != null) { AudioManager.SendAudio(monster.PositionToAimFor, TurretSettings[machineState.RoamObjective].OnHitAudio); } TurretSettings[machineState.RoamObjective] .ProjectileAnimation .SendMoveToInterpolated(machineState.Position.Vector, monster.PositionToAimFor); ServerManager.SendParticleTrail(machineState.Position.Vector, monster.PositionToAimFor, 2); monster.OnHit(totalDamage, machineState, ModLoader.OnHitData.EHitSourceType.Misc); } } machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; } } catch (Exception ex) { SettlersLogger.LogError(ex, $"Turret shoot for {machineState.RoamObjective}"); } }
public void DoWork(Colony colony, RoamingJobState machineState) { if (machineState.NextTimeForWork < Time.SecondsSinceStartDouble && machineState.GetActionEnergy(MachineConstants.REPAIR) > 0 && machineState.GetActionEnergy(MachineConstants.REFUEL) > 0) { machineState.SubtractFromActionEnergy(MachineConstants.REPAIR, 0.02f); machineState.SubtractFromActionEnergy(MachineConstants.REFUEL, 0.05f); if (World.TryGetTypeAt(machineState.Position.Add(0, -1, 0), out ItemTypes.ItemType itemBelow) && itemBelow.CustomDataNode != null && itemBelow.CustomDataNode.TryGetAs("minerIsMineable", out bool minable) && minable) { var itemList = itemBelow.OnRemoveItems; if (itemList != null && itemList.Count > 0) { var mineTime = itemBelow.CustomDataNode.GetAsOrDefault("minerMiningTime", machineState.RoamingJobSettings.WorkTime); machineState.NextTimeForWork = mineTime + Time.SecondsSinceStartDouble; var items = machineState.TempValues.GetOrDefault <List <InventoryItem> >("MinedItems", new List <InventoryItem>()); int remainingItems = Math.RoundToInt(machineState.GetActionEnergy(MachineConstants.INVENTORY) / .05f) - items.Count; if (remainingItems != 0) { for (var i = 0; i < itemList.Count; i++) { if (Random.NextDouble() <= itemList[i].chance) { if (remainingItems != 0) { items.Add(itemList[i].item); remainingItems--; machineState.SubtractFromActionEnergy(MachineConstants.INVENTORY, .05f); } } } } machineState.TempValues.Set("MinedItems", items); if (remainingItems != 0) { AudioManager.SendAudio(machineState.Position.Vector, GameLoader.NAMESPACE + ".MiningMachineAudio"); Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(mineTime, itemList.FirstOrDefault().item.Type)); } else { machineState.SetActionEnergy(MachineConstants.INVENTORY, 0); Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(mineTime, GameLoader.NAMESPACE + ".Inventory", true, false)); } } else { machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(machineState.RoamingJobSettings.WorkTime, ColonyBuiltIn.ItemTypes.ERRORIDLE.Name)); } } else { machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; Indicator.SendIconIndicatorNear(machineState.Position.Add(0, 1, 0).Vector, new IndicatorState(machineState.RoamingJobSettings.WorkTime, ColonyBuiltIn.ItemTypes.ERRORIDLE.Name)); } } }
public ItemId PreformAction(Colony colony, RoamingJobState state) { return(GateLever.Repair(colony, state)); }
public void DoWork(Colony colony, RoamingJobState state) { GateLever.DoWork(colony, state); }
public static void DoWork(Colony colony, RoamingJobState machineState) { if (machineState.GetActionEnergy(MachineConstants.REPAIR) > 0 && machineState.GetActionEnergy(MachineConstants.RELOAD) > 0 && machineState.GetActionEnergy(MachineConstants.REFUEL) > 0 && machineState.NextTimeForWork < Time.SecondsSinceStartDouble) { if (!machineState.TempValues.Contains(DoorOpen)) { machineState.TempValues.Set(DoorOpen, false); } if (!_gatePositions.ContainsKey(colony)) { _gatePositions.Add(colony, new Dictionary <Vector3Int, GateState>()); } var moveGates = new Dictionary <GateState, Vector3Int>(); bool bossesEnabled = ColonyState.GetColonyState(colony).BossesEnabled; foreach (var gate in _gatePositions[colony]) { if (gate.Value.State == GatePosition.MovingClosed || gate.Value.State == GatePosition.MovingOpen) { continue; } if (World.TryGetTypeAt(gate.Key, out ushort gateType)) { if (gate.Value.Orientation == VoxelSide.None) { if (gateType == GateItemXN.ItemIndex) { gate.Value.Orientation = VoxelSide.xMin; } else if (gateType == GateItemXP.ItemIndex) { gate.Value.Orientation = VoxelSide.xPlus; } else if (gateType == GateItemZN.ItemIndex) { gate.Value.Orientation = VoxelSide.zMin; } else if (gateType == GateItemZP.ItemIndex) { gate.Value.Orientation = VoxelSide.zPlus; } } if (gateType != GateItem.ItemIndex && gateType != GateItemXN.ItemIndex && gateType != GateItemXP.ItemIndex && gateType != GateItemZN.ItemIndex && gateType != GateItemZP.ItemIndex) { switch (gate.Value.Orientation) { case VoxelSide.xMin: ServerManager.TryChangeBlock(gate.Key, GateItemXN.ItemIndex); break; case VoxelSide.xPlus: ServerManager.TryChangeBlock(gate.Key, GateItemXP.ItemIndex); break; case VoxelSide.zMin: ServerManager.TryChangeBlock(gate.Key, GateItemZN.ItemIndex); break; case VoxelSide.zPlus: ServerManager.TryChangeBlock(gate.Key, GateItemZP.ItemIndex); break; default: ServerManager.TryChangeBlock(gate.Key, GateItemXN.ItemIndex); break; } } } if (bossesEnabled) { if (TimeCycle.IsDay && !MonsterManager.BossActive && gate.Value.State == GatePosition.Open) { continue; } } else if (TimeCycle.IsDay && gate.Value.State == GatePosition.Open) { continue; } if (bossesEnabled) { if ((!TimeCycle.IsDay || MonsterManager.BossActive) && gate.Value.State == GatePosition.Closed) { continue; } } else if (!TimeCycle.IsDay && gate.Value.State == GatePosition.Closed) { continue; } var dis = UnityEngine.Vector3.Distance(machineState.Position.Vector, gate.Key.Vector); if (dis <= 21) { var offset = 2; if (bossesEnabled) { if (!TimeCycle.IsDay || MonsterManager.BossActive) { offset = -2; } } else if (!TimeCycle.IsDay) { offset = -2; } moveGates.Add(gate.Value, gate.Key.Add(0, offset, 0)); } } foreach (var mkvp in moveGates) { if (_gatePositions[colony].ContainsKey(mkvp.Key.Position)) { _gatePositions[colony].Remove(mkvp.Key.Position); } } foreach (var mkvp in moveGates) { _gatePositions[colony].Add(mkvp.Value, mkvp.Key); ServerManager.TryChangeBlock(mkvp.Key.Position, ColonyBuiltIn.ItemTypes.AIR.Id); var newOffset = -1; if (bossesEnabled) { if (!TimeCycle.IsDay || MonsterManager.BossActive) { newOffset = 1; } } else if (!TimeCycle.IsDay) { newOffset = 1; } var newPos = mkvp.Value.Add(0, newOffset, 0).Vector; switch (mkvp.Key.Orientation) { case VoxelSide.xMin: _gateXMinusItemObjSettings.SendMoveToInterpolated(mkvp.Key.Position.Vector, newPos, TravelTime); break; case VoxelSide.xPlus: _gateXPlusItemObjSettings.SendMoveToInterpolated(mkvp.Key.Position.Vector, newPos, TravelTime); break; case VoxelSide.zMin: _gateZMinusItemObjSettings.SendMoveToInterpolated(mkvp.Key.Position.Vector, newPos, TravelTime); break; case VoxelSide.zPlus: _gateZPlusItemObjSettings.SendMoveToInterpolated(mkvp.Key.Position.Vector, newPos, TravelTime); break; default: _gateXMinusItemObjSettings.SendMoveToInterpolated(mkvp.Key.Position.Vector, newPos, TravelTime); break; } var moveState = GatePosition.MovingClosed; if (bossesEnabled) { if (TimeCycle.IsDay && !MonsterManager.BossActive) { moveState = GatePosition.MovingOpen; } } else if (TimeCycle.IsDay) { moveState = GatePosition.MovingOpen; } mkvp.Key.State = moveState; mkvp.Key.Position = mkvp.Value; var thread = new Thread(() => { Thread.Sleep(8000); var state = GatePosition.Closed; if (bossesEnabled) { if (TimeCycle.IsDay && !MonsterManager.BossActive) { state = GatePosition.Open; } } else if (TimeCycle.IsDay) { state = GatePosition.Open; } mkvp.Key.State = state; ThreadManager.InvokeOnMainThread(() => { switch (mkvp.Key.Orientation) { case VoxelSide.xMin: ServerManager.TryChangeBlock(mkvp.Value, GateItemXN.ItemIndex); break; case VoxelSide.xPlus: ServerManager.TryChangeBlock(mkvp.Value, GateItemXP.ItemIndex); break; case VoxelSide.zMin: ServerManager.TryChangeBlock(mkvp.Value, GateItemZN.ItemIndex); break; case VoxelSide.zPlus: ServerManager.TryChangeBlock(mkvp.Value, GateItemZP.ItemIndex); break; default: ServerManager.TryChangeBlock(mkvp.Value, GateItemXN.ItemIndex); break; } }); }); thread.IsBackground = true; thread.Start(); } if (moveGates.Count > 0) { AudioManager.SendAudio(machineState.Position.Vector, GameLoader.NAMESPACE + ".GateLeverMachineAudio"); machineState.SubtractFromActionEnergy(MachineConstants.REPAIR, 0.01f); machineState.SubtractFromActionEnergy(MachineConstants.REFUEL, 0.03f); } machineState.NextTimeForWork = machineState.RoamingJobSettings.WorkTime + Time.SecondsSinceStartDouble; } }
public void DoWork(Colony colony, RoamingJobState state) { state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaTankRefill"); state.GetActionEnergy(GameLoader.NAMESPACE + ".ManaMachineRepair"); }
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); }
public ItemId PreformAction(Colony player, RoamingJobState state) { return(ItemId.GetItemId(GameLoader.NAMESPACE + ".Waiting")); }