public static void AirPollutionGenerators(User user) { for (var i = 0; i < 50; i++) { WorldObjectManager.ForceAdd(ServiceHolder <IWorldObjectManager> .Obj.GetTypeFromName("AirPollutionGeneratorObject"), user, World.GetTopGroundPos(World.GetRandomLandPos().XZ) + Vector3i.Up, Quaternion.Identity); } }
public static void RestoreWorldObjectBlock(Type type, Vector3i position, IWorldEditBlockData blockData, UserSession session) { if (blockData == null) { return; } WorldEditWorldObjectBlockData worldObjectBlockData = (WorldEditWorldObjectBlockData)blockData; ClearWorldObjectPlace(worldObjectBlockData.WorldObjectType, position, worldObjectBlockData.Rotation, session); WorldObject worldObject = null; try { worldObject = WorldObjectManager.ForceAdd(worldObjectBlockData.WorldObjectType, session.User, position, worldObjectBlockData.Rotation, true); } catch (Exception e) { Log.WriteException(e); } if (worldObject == null) { Log.WriteErrorLineLoc($"Unable spawn WorldObject {worldObjectBlockData.WorldObjectType} at {position}"); return; } if (worldObject.HasComponent <StorageComponent>() && worldObjectBlockData.Components.ContainsKey(typeof(StorageComponent))) { StorageComponent storageComponent = worldObject.GetComponent <StorageComponent>(); List <InventoryStack> inventoryStacks; object component = worldObjectBlockData.Components[typeof(StorageComponent)]; if (component is JArray) { JArray jArray = (JArray)component; inventoryStacks = jArray.ToObject <List <InventoryStack> >(); } else { inventoryStacks = (List <InventoryStack>)component; } foreach (InventoryStack stack in inventoryStacks) { if (stack.ItemType == null) { continue; } Result result = storageComponent.Inventory.TryAddItems(stack.ItemType, stack.Quantity); if (result.Failed) { session.Player.ErrorLocStr(result.Message.Trim()); try { storageComponent.Inventory.AddItems(stack.GetItemStack()); } catch (InvalidOperationException) { /*Already show error to user*/ } } } } if (worldObject.HasComponent <CustomTextComponent>() && worldObjectBlockData.Components.ContainsKey(typeof(CustomTextComponent))) { CustomTextComponent textComponent = worldObject.GetComponent <CustomTextComponent>(); textComponent.TextData.Text = (string)worldObjectBlockData.Components[typeof(CustomTextComponent)]; } }
public override void OnAreaValid(GameActionPack pack, Player player, Vector3i position, Quaternion rotation) { var deed = PropertyManager.FindConnectedDeedOrCreate(player.User, position.XZ); foreach (var plotPosition in PlotUtil.GetAllPropertyPos(position, virtualOccupancy)) { if (!this.IsPlotAuthorized(plotPosition, player.User, out var canClaimPlot)) { return; } if (canClaimPlot) { pack.ClaimProperty(deed, player.User, player.User.Inventory, plotPosition, requirePapers: false); } } if (!pack.EarlyResult) { return; } pack.AddPostEffect(() => { var camp = WorldObjectManager.ForceAdd(typeof(CampsiteObject), player.User, position, rotation, false); var stockpile = WorldObjectManager.ForceAdd(typeof(TinyStockpileObject), player.User, position + rotation.RotateVector(Vector3i.Right * 3), rotation, false); player.User.OnWorldObjectPlaced.Invoke(camp); player.User.Markers.Add(camp.Position3i + Vector3i.Up, camp.UILinkContent(), false); var storage = camp.GetComponent <PublicStorageComponent>(); var changeSet = new InventoryChangeSet(storage.Inventory); PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x => changeSet.AddItems(x.Key, x.Value, storage.Inventory)); //If we're running a settlement system, create the homestead item now and fill it with homestead-specific claim papers. if (SettlementPluginConfig.Obj.SettlementSystemEnabled) { var marker = WorldObjectManager.ForceAdd(typeof(HomesteadMarkerObject), player.User, position + rotation.RotateVector(new Vector3i(3, 0, 3)), rotation, false); var markerComp = marker.GetComponent <SettlementMarkerComponent>(); markerComp.Settlement.Citizenship.AddSpawnedClaims(this.bonusPapers); markerComp.UpdateSpawnedClaims(); } else { //For the old system, add the papers to the tent. if (this.bonusPapers > 0) { changeSet.AddItems(typeof(PropertyClaimItem), this.bonusPapers); } } changeSet.Apply(); }); }