public float GetProgress(IPandaQuest quest, Colony colony) { if (BlocksGoal == 0) { return(1); } var itemsPlaced = 0; foreach (var p in colony.Owners) { var ps = PlayerState.GetPlayerState(p); if (ps.ItemsPlaced.TryGetValue(ItemId.GetItemId(BlockName), out itemsPlaced) && itemsPlaced > 0) { break; } } if (itemsPlaced == 0) { return(0); } else if (itemsPlaced == BlocksGoal) { return(1); } else { return(itemsPlaced / BlocksGoal); } }
public static void ChangeBlocksForPos(Vector3Int pos, string blockType = null, IConnectedBlockCalculationType calculationType = null) { if (World.TryGetTypeAt(pos, out ItemTypes.ItemType itemTypeAtPos) && BlockLookup.ContainsKey(itemTypeAtPos.Name)) { if (blockType == null && BlockLookup.TryGetValue(itemTypeAtPos.Name, out var connectedBlockAtPos)) { blockType = connectedBlockAtPos.ConnectedBlock.BlockType; if (ConnectedBlockCalculator.CalculationTypes.TryGetValue(connectedBlockAtPos.ConnectedBlock.CalculationType, out var connectedBlockCalculationType)) { calculationType = connectedBlockCalculationType; } else { return; } } if (calculationType != null && TryGetChangedBlockTypeAtPosition(pos, blockType, calculationType, out var newBlock) && newBlock.ConnectedBlock.AutoChange) { ServerManager.TryChangeBlock(pos, ItemId.GetItemId(newBlock.name)); } } }
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) { 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 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 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 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 static bool GetBestWeapon(NPC.NPCBase npc, int limit) { var hasItem = false; try { if (npc != null) { var inv = ColonistInventory.Get(npc); var stock = npc.Colony.Stockpile; hasItem = !inv.Weapon.IsEmpty(); IWeapon bestWeapon = null; if (hasItem) { bestWeapon = WeaponFactory.WeaponLookup[inv.Weapon.Id]; } foreach (var wep in WeaponFactory.WeaponLookup.Values.Where(w => w as IPlayerMagicItem == null && w is WeaponMetadata weaponMetadata && weaponMetadata.ItemType != null).Cast <WeaponMetadata>()) { if (stock.Contains(wep.ItemType.ItemIndex) && bestWeapon == null || stock.Contains(wep.ItemType.ItemIndex) && bestWeapon != null && bestWeapon.Damage.TotalDamage() < wep.Damage.TotalDamage() && stock.AmountContained(ItemId.GetItemId(bestWeapon.name)) > limit) { bestWeapon = wep; } } if (bestWeapon != null) { var wepId = ItemId.GetItemId(bestWeapon.name); if (hasItem && inv.Weapon.Id != wepId || !hasItem) { hasItem = true; stock.TryRemove(wepId); if (!inv.Weapon.IsEmpty()) { stock.Add(inv.Weapon.Id); } inv.Weapon = new ItemState { Id = wepId, Durability = bestWeapon.WepDurability }; } } } } catch (Exception ex) { APILogger.LogError(ex); } return(hasItem); }
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 TrainTransport(Vector3 position, AnimationManager.AnimatedObject animatedObject, ICSType trainType) { _meshedVehicleDescription = new MeshedVehicleDescription(new ClientMeshedObject(animatedObject.ObjType), trainType.TrainConfiguration.playerSeatOffset, trainType.TrainConfiguration.AllowPlayerToEditBlocksWhileRiding); _animatedObject = animatedObject; Position = position; TrainType = trainType; _trainId = ItemId.GetItemId(trainType.name); _idealHeightFromTrack = TrainType.TrainConfiguration.IdealHeightFromTrack; Delay = TrainType.TrainConfiguration.MoveTimePerBlockMs; ManaCostPerBlock = TrainType.TrainConfiguration.EnergyCostPerBlock; }
public static void ChangeBlocksForPos(Vector3Int pos, string blockType, IConnectedBlockCalculationType calculationType) { if (World.TryGetTypeAt(pos, out ItemTypes.ItemType itemTypeAtPos) && BlockLookup.TryGetValue(itemTypeAtPos.Name, out var existingBlock) && existingBlock.ConnectedBlock.BlockType == blockType) { if (calculationType != null && TryGetChangedBlockTypeAtPosition(pos, blockType, calculationType, out var newBlock) && newBlock.ConnectedBlock.AutoChange) { ServerManager.TryChangeBlock(pos, (ushort)ItemId.GetItemId(newBlock.name)); } } }
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 string GetRewardText(IPandaQuest quest, Colony colony, Players.Player player) { var formatStr = QuestingSystem.LocalizationHelper.LocalizeOrDefault(LocalizationKey, player); var item = ItemId.GetItemId(RecipeKey); if (formatStr.Count(c => c == '{') == 1) { return(string.Format(QuestingSystem.LocalizationHelper.LocalizeOrDefault(LocalizationKey, player), LocalizationHelper.LocalizeOrDefault(RecipeKey, player))); } else { return(formatStr); } }
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")); }
private static void OnClicked(Players.Player sender, PlayerClickedData data) { if (data == null || data.TypeSelected == default(ushort) || data.ConsumedType != PlayerClickedData.EConsumedType.Not || data.IsHoldingButton || (data.ClickType != PlayerClickedData.EClickType.Right || data.OnBuildCooldown) || (data.HitType != PlayerClickedData.EHitType.Block || !TrainTypes.TryGetValue(ItemId.GetItemId(data.TypeSelected), out var cSType) || !sender.Inventory.TryRemove(data.TypeSelected, 1, -1, true))) { return; } data.ConsumedType = PlayerClickedData.EConsumedType.UsedAsTool; CreateTrain(cSType, data.GetExactHitPositionWorld()); }
public string GetObjectiveProgressText(IPandaQuest quest, Colony colony, Players.Player player) { var formatStr = LocalizationHelper.LocalizeOrDefault(LocalizationKey, player); var ps = PlayerState.GetPlayerState(player); var itemsPlaced = 0; ps.ItemsPlaced.TryGetValue(ItemId.GetItemId(BlockName), out itemsPlaced); if (formatStr.Count(c => c == '{') == 3) { return(string.Format(LocalizationHelper.LocalizeOrDefault(LocalizationKey, player), itemsPlaced, BlocksGoal, BlockName)); } else { return(formatStr); } }
private static void CleanupJob(IIterationType iterationType, IAreaJob areaJob, ConstructionJobInstance job, ArchitectIterator bpi, int prvX, int prvY, int prvZ) { if (_needsChunkLoaded.Contains(bpi)) { _needsChunkLoaded.Remove(bpi); } if (bpi.PreviousPosition != Pipliz.Vector3Int.invalidPos && prvX <= bpi.BuilderSchematic.XMax && prvY <= bpi.BuilderSchematic.YMax && prvZ <= bpi.BuilderSchematic.ZMax && !bpi.BuilderSchematic.Blocks[prvX, prvY, prvZ].BlockID.Contains("bedend")) { ServerManager.TryChangeBlock(bpi.PreviousPosition, ItemId.GetItemId(bpi.BuilderSchematic.Blocks[prvX, prvY, prvZ].BlockID).Id, new BlockChangeRequestOrigin(job.Owner), ESetBlockFlags.DefaultAudio); } SchematicReader.SaveSchematic(areaJob.Owner, bpi.BuilderSchematic); AreaJobTracker.RemoveJob(areaJob); }
public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData) { //Only launch on RIGHT click if (player == null || playerClickData.ClickType != PlayerClickedData.EClickType.Right || playerClickData.HitType != PlayerClickedData.EHitType.Block || player.ActiveColony == null) { return; } var voxel = playerClickData.GetVoxelHit(); var itemHit = ItemId.GetItemId(voxel.TypeHit); if (StorageFactory.CrateTypes.ContainsKey(itemHit.Name) && StorageFactory.CrateLocations.TryGetValue(player.ActiveColony, out var positions) && positions.ContainsKey(voxel.BlockHit)) { LastCrateClick[player] = voxel.BlockHit; NetworkMenuManager.SendServerPopup(player, MainMenu(player)); } }
private static bool MoveNext(IIterationType iterationType, IAreaJob areaJob, ConstructionJobInstance job, ArchitectIterator bpi, int prvX, int prvY, int prvZ) { if (bpi.PreviousPosition != Pipliz.Vector3Int.invalidPos && prvX <= bpi.BuilderSchematic.XMax && prvY <= bpi.BuilderSchematic.YMax && prvZ <= bpi.BuilderSchematic.ZMax && !bpi.BuilderSchematic.Blocks[prvX, prvY, prvZ].BlockID.Contains("bedend")) { ServerManager.TryChangeBlock(bpi.PreviousPosition, ItemId.GetItemId(bpi.BuilderSchematic.Blocks[prvX, prvY, prvZ].BlockID).Id, new BlockChangeRequestOrigin(job.Owner), ESetBlockFlags.DefaultAudio); } if (!bpi.MoveNext()) { CleanupJob(iterationType, areaJob, job, bpi, prvX, prvY, prvZ); return(false); } return(true); }
public static void OnNPCCraftedRecipe(IJob job, Recipe recipe, List <RecipeResult> results) { foreach (var item in results) { if (CraftObjectivesByItem.TryGetValue(ItemId.GetItemId(item.Type), out var craftObjectives)) { foreach (var objective in craftObjectives) { if (!objective.CurrentCraftCount.TryGetValue(job.Owner.ColonyID, out var count)) { objective.CurrentCraftCount[job.Owner.ColonyID] = 0; count = 0; } objective.CurrentCraftCount[job.Owner.ColonyID] = count + item.Amount; } } } }
public static void ConnectedBlockInfo(Players.Player player, PlayerClickedData playerClickData) { //Only launch on RIGHT click if (player == null || playerClickData.ClickType != PlayerClickedData.EClickType.Right || player.ActiveColony == null) { return; } if (playerClickData.HitType == PlayerClickedData.EHitType.Block && ItemTypes.IndexLookup.TryGetIndex(GameLoader.NAMESPACE + ".ConnectedBlockTool", out var toolItem) && playerClickData.TypeSelected == toolItem && ConnectedBlockSystem.BlockLookup.TryGetValue(ItemId.GetItemId(playerClickData.GetVoxelHit().TypeHit), out var cSType)) { PandaChat.Send(player, "Side Hit: " + playerClickData.GetVoxelHit().SideHit); PandaChat.Send(player, "Connected Sides: " + string.Join(", ", cSType.ConnectedBlock.Connections.Select(c => c.ToString()).ToArray())); PandaChat.Send(player, "Origin Sides: " + string.Join(", ", cSType.ConnectedBlock.Origin.Select(c => c.ToString()).ToArray())); PandaChat.Send(player, "BlockRotationDegrees: " + cSType.ConnectedBlock.BlockRotationDegrees.ToString()); PandaChat.Send(player, "RotationAxis: " + cSType.ConnectedBlock.RotationAxis.ToString()); } }
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 string GetObjectiveProgressText(IPandaQuest quest, Colony colony, Players.Player player) { var formatStr = QuestingSystem.LocalizationHelper.LocalizeOrDefault(LocalizationKey, player); int itemCount = 0; var item = ItemId.GetItemId(ItemName); if (colony.Stockpile.Contains(item)) { itemCount = colony.Stockpile.Items[item]; } if (formatStr.Count(c => c == '{') == 3) { return(string.Format(QuestingSystem.LocalizationHelper.LocalizeOrDefault(LocalizationKey, player), itemCount, GoalCount, LocalizationHelper.LocalizeOrDefault(ItemName, player))); } else { return(formatStr); } }
public void OnTryChangeBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData) { if (tryChangeBlockData.PlayerClickedData != null && tryChangeBlockData.PlayerClickedData.HitType != Shared.PlayerClickedData.EHitType.Block) { return; } if (callbacks.TryGetValue(tryChangeBlockData.TypeOld.Name, out var holdingType)) { var holdingItem = ItemId.GetItemId(tryChangeBlockData.PlayerClickedData.TypeSelected).Name; if (!holdingType.TryGetValue(holdingItem, out var replacements) && !holdingType.TryGetValue(ColonyBuiltIn.ItemTypes.AIR, out replacements)) { return; } else { tryChangeBlockData.InventoryItemResults = replacements.Values.Select(s => new InventoryItem(s.Name, s.Amount)).ToList(); } } }
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 float GetProgress(IPandaQuest quest, Colony colony) { if (GoalCount == 0) { return(1); } var item = ItemId.GetItemId(ItemName); int itemCount = 0; if (colony.Stockpile.Contains(item)) { itemCount = colony.Stockpile.Items[item]; } if (itemCount == 0) { return(0); } return(itemCount / GoalCount); }
public static void OnPlayerClicked(Players.Player player, PlayerClickedData playerClickData) { if (playerClickData.ClickType == PlayerClickedData.EClickType.Right && playerClickData.HitType == PlayerClickedData.EHitType.Block && ItemTypes.TryGetType(playerClickData.GetVoxelHit().TypeHit, out ItemTypes.ItemType itemHit)) { var baseType = itemHit.GetRootParentType(); if (baseType.Categories != null && baseType.Categories.Count != 0 && baseType.Categories.Contains("door", StringComparer.CurrentCultureIgnoreCase)) { ushort replacement = ColonyBuiltIn.ItemTypes.AIR; if (itemHit.Name == baseType.RotatedXMinus) { replacement = ItemId.GetItemId(baseType.RotatedZMinus); } else if (itemHit.Name == baseType.RotatedZMinus) { replacement = ItemId.GetItemId(baseType.RotatedXMinus); } else if (itemHit.Name == baseType.RotatedXPlus) { replacement = ItemId.GetItemId(baseType.RotatedZPlus); } else if (itemHit.Name == baseType.RotatedZPlus) { replacement = ItemId.GetItemId(baseType.RotatedXPlus); } if (replacement != ColonyBuiltIn.ItemTypes.AIR) { ServerManager.TryChangeBlock(playerClickData.GetVoxelHit().BlockHit, replacement, new BlockChangeRequestOrigin(player)); } } } }
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); }