public override InteractResult OnActLeft(InteractionContext context) { if (context.HasBlock && context.Block.Is <Minable>()) { var user = context.Player.User; var item = context.Block is IRepresentsItem?Item.Get((IRepresentsItem)context.Block) : null; var totalDamageToTarget = user.BlockHitCache.MemorizeHit(context.Block.GetType(), context.BlockPosition.Value, this.Tier.GetCurrentValue(context.Player.User) * this.Damage); if (context.Block.Get <Minable>().Hardness <= totalDamageToTarget) { var result = AtomicActions.DeleteBlockNow(this.CreateMultiblockContext(context), spawnRubble: false); //Spawn the rubble if needed if (result.Success) { var forced = context.Player.User.Talentset.HasTalent(typeof(MiningLuckyBreakTalent)) ? 4 : -1; if (RubbleObject.TrySpawnFromBlock(context.Player, context.Block.GetType(), context.BlockPosition.Value, forced)) { var addition = item != null ? " " + item.UILink() : string.Empty; this.AddExperience(user, 1f, new LocString(Localizer.Format("mining") + addition)); user.UserUI.OnCreateRubble.Invoke(item.DisplayName.NotTranslated); user.BlockHitCache.ForgetHit(context.BlockPosition.Value); } } return((InteractResult)result); } else { return((InteractResult)AtomicActions.UseToolNow(this.CreateMultiblockContext(context))); } } else if (context.Target is RubbleObject) { var rubble = (RubbleObject)context.Target; if (rubble.IsBreakable) { using var pack = new GameActionPack(); pack.UseTool(this.CreateMultiblockContext(context)); pack.AddPostEffect(() => rubble.Breakup(context.Player)); return((InteractResult)pack.TryPerform(false)); } return(InteractResult.NoOp); } if (context.Target is WorldObject) { return(this.BasicToolOnWorldObjectCheck(context)); } return(base.OnActLeft(context)); }
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(); }); }