private bool TryPlaceObject(Player player, Vector3i position, Quaternion rotation, out bool canOwn) { this.bonusPapers = 0; if (!this.TryPlaceObjectOnSolidGround(player, position, rotation)) { canOwn = false; return(false); } canOwn = true; foreach (var pos in PlotUtil.GetAllPropertyPos(position, virtualOccupancy)) { var plot = PropertyManager.GetPlot(pos); if (plot == null || plot.DeedId == Guid.Empty) { continue; // Unowned plot. } if (plot.Owners == player.User) { this.bonusPapers++; continue; } // Already claimed, increase amount of bonus papers. canOwn = false; var result = ServiceHolder <IAuthManager> .Obj.IsAuthorized(plot.Position, player.User, AccessType.ConsumerAccess, null); if (!result.Success) { player.Error(result.Message); return(false); } } return(true); }
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(); }); }
public static void Selclaim(User user) { try { Vector3i pos = user.Position.Round; Vector2i claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ); UserSession session = WorldEditManager.GetUserSession(user); session.SetFirstPosition(claimPos.X_Z(pos.Y - 1)); session.SetSecondPosition(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y - 1)); user.Player.MsgLoc($"First Position set to {session.Selection.min}"); user.Player.MsgLoc($"Second Position set to {session.Selection.max}"); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Expclaim(User user, string args = "1") { try { UserSession session = WorldEditManager.GetUserSession(user); if (!session.Selection.IsSet()) { throw new WorldEditCommandException("Please set both points first!"); } Direction direction = WorldEditUtils.ParseDirectionAndAmountArgs(user, args, out int amount); if (direction == Direction.Unknown || direction == Direction.None || direction == Direction.Up || direction == Direction.Down) { throw new WorldEditCommandException("Unable to determine direction"); } WorldRange range = session.Selection; Vector3i pos = default; if (range.min.y <= range.max.y) { pos.y = range.min.y; } else { pos.y = range.max.y; } switch (direction) { case Direction.Left: case Direction.Back: if (range.min.x <= range.max.x) { pos.x = range.min.x; } else { pos.x = range.max.x; } if (range.min.z <= range.max.z) { pos.z = range.min.z; } else { pos.z = range.max.z; } break; case Direction.Right: case Direction.Forward: if (range.min.x <= range.max.x) { pos.x = range.max.x; } else { pos.x = range.min.x; } if (range.min.z <= range.max.z) { pos.z = range.max.z; } else { pos.z = range.min.z; } break; } pos += direction.ToVec() * (PlotUtil.PropertyPlotLength - 1) * amount; Vector2i claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ); range.ExtendToInclude(claimPos.X_Z(pos.Y)); range.ExtendToInclude(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y)); session.SetSelection(range); user.Player.MsgLoc($"First Position now at {session.Selection.min}"); user.Player.MsgLoc($"Second Position now at {session.Selection.max}"); } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }