public override void BlockInteraction(Vector3i pos, Quaternion rot, VehicleComponent vehicle, Inventory inv = null) { if (inv == null) { return; } foreach (var offset in area) { SeedItem seed = inv.GroupedStacks.Where(x => x.Item is SeedItem).First().Item as SeedItem; var targetPos = (rot.RotateVector(offset) + pos).XYZi; Result authResult = AuthManager.IsAuthorized(targetPos, vehicle.Driver.User); if (authResult.Success) { if (World.GetBlock(targetPos + Vector3i.Down).Is <Tilled>() && World.GetBlock(targetPos).Is <Empty>()) { var changes = new InventoryChangeSet(inv, vehicle.Driver.User); changes.RemoveItem(seed.Type); IAtomicAction plantAction = PlayerActions.Plant.CreateAtomicAction(vehicle.Driver, targetPos, seed.Species); if (new MultiAtomicAction(changes, plantAction).TryApply()) { var plant = EcoSim.PlantSim.SpawnPlant(seed.Species, targetPos); plant.Tended = true; } } } } }
public override void OnUsed(Player player, ItemStack itemStack) { player.SendTemporaryMessageLoc("111"); InventoryChangeSet changes = new InventoryChangeSet(player.User.Inventory, player.User); changes.AddItems <MYTurkeyBaitItem>(1); }
public override Result OnAreaValid(Player player, Vector3i position, Quaternion rotation) { Deed deed = PropertyManager.FindNearbyDeedOrCreate(player.User, position.XZ); foreach (var plot in WorldObject.GetOccupiedPropertyPositions(typeof(StarterCampObject), position, rotation)) { PropertyManager.Claim(deed.Id, player.User, player.User.Inventory, plot); } var camp = WorldObjectManager.TryToAdd(typeof(CampsiteObject), player.User, position, rotation, false); var stockpile = WorldObjectManager.TryToAdd(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()); player.User.Markers.Add(stockpile.Position3i + Vector3i.Up, stockpile.UILinkContent()); var storage = camp.GetComponent <PublicStorageComponent>(); var changeSet = new InventoryChangeSet(storage.Inventory); PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x => { changeSet.AddItems(x.Key, x.Value, storage.Inventory); }); changeSet.Apply(); return(Result.Succeeded); }
//[Serialized] private string description = "An Empty note. You can copy text from a sign to it or use /writenote to add text."; //[Serialized] private string name = "Empty Note"; //[Serialized] private bool empty = true; public override InteractResult OnActRight(InteractionContext context) { if (context.HasTarget && context.Target is WorldObject) { WorldObject wo = context.Target as WorldObject; if (wo.HasComponent <CustomTextComponent>()) { NoteItem noteItem = (NoteItem)Item.Create <NoteItem>(); noteItem.description = wo.GetComponent <CustomTextComponent>().Text; noteItem.owner = context.Player.User; InventoryChangeSet inventoryChange = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); inventoryChange.RemoveItem(typeof(EmptyNoteItem)); inventoryChange.AddItem(noteItem); if (inventoryChange.TryApply().Success) { return(InteractResult.Success); } else { return(InteractResult.Failure("Not enough room in inventory".ToLocString()));//ChatManager.ServerMessageToPlayer("Not enough room in inventory",context.Player.User); } } } return(base.OnActRight(context)); }
private void InventoryChanged(User obj) { Inventory inventory = GetComponent <PublicStorageComponent>().Storage; User owner = OwnerUser; User creator = Creator; if (owner == null && creator == null) { return; } if (owner == null) { owner = creator; } if (creator == null) { creator = owner; } if (!SkillUtils.UserHasSkill(owner, RequiredSkill, RequiredLevel) && (!SkillUtils.UserHasSkill(creator, RequiredSkill, RequiredLevel))) { if ((inventory.TotalNumberOfItems(typeof(RuinedCarcassItem)) == 0) && (!inventory.IsEmpty)) { InventoryChangeSet changes = new InventoryChangeSet(inventory); changes.Clear(); changes.AddItem <RuinedCarcassItem>(); Result result = changes.TryApply(); } } }
public override void OnUsed(Player player, ItemStack itemStack) { if (player.User.Skillset.HasSkill(this.SkillType)) { player.SendTemporaryErrorLoc(string.Format("You already know {0}.", this.Skill)); } else { using (var changes = InventoryChangeSet.New(new Inventory[] { player.User.Inventory, itemStack.Parent }.Distinct(), player.User)) { changes.ModifyStack(itemStack, -1); if (changes.TryApply()) { if (!this.Skill.IsDiscovered()) { ChatManager.ServerMessageToAllLoc(string.Format("{0} discovered {1}!", player.User.UILink(), this.Skill.UILink()), false, DefaultChatTags.Skills); } player.User.Skillset.LearnSkill(this.Skill.GetType()); player.SendTemporaryMessageLoc(string.Format("You have learned a new skill {0}!", this.Skill.UILink()), ChatCategory.Info); } else { player.SendTemporaryErrorLoc(string.Format("Could not learn {0}: more inventory space required.", this.Skill)); } } } }
public override IAtomicAction CreateLevelUpAction(Player player) { if (this.Level != 0 || this.HasGivenItems) { return(base.CreateLevelUpAction(player)); } InventoryChangeSet changeSet = InventoryChangeSet.New(player.User.Inventory, player.User); foreach (Tuple <Type, int> tuple in ItemsGiven) { changeSet.AddItems(tuple.Item1, tuple.Item2); } SimpleAtomicAction setHasGivenItems = new SimpleAtomicAction(() => this.HasGivenItems = true); return(new DecoratedResultAtomicAction(new MultiAtomicAction(changeSet, setHasGivenItems), (result) => { if (result.Success) { return result; } else { return Skill.CantCarry(ItemDescriptions()); } })); }
internal override IEnumerable <IAtomicAction> OnPickUp(Player player, InventoryChangeSet playerInvChanges) { foreach (var kvp in this.Inventory.TypeToCount) { playerInvChanges.MoveItems(kvp.Key, kvp.Value, this.Inventory, player.User.Inventory); } return(base.OnPickUp(player, playerInvChanges)); }
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(); }); }
// TODO: create atomic actions covering the case and utilize them. public override void BlockInteraction(Vector3i pos, Quaternion rot, VehicleComponent vehicle, Inventory inv = null) { if (inv == null) { return; } if (!this.enabled) { return; } foreach (var offset in area) { var stack = inv.GroupedStacks.Where(x => x.Item is SeedItem).FirstOrDefault(); if (stack == null) { return; } SeedItem seed = stack.Item as SeedItem; var targetPos = (rot.RotateVector(offset) + pos).XYZi; Result authResult = ServiceHolder <IAuthManager> .Obj.IsAuthorized(targetPos, vehicle.Driver.User, AccessType.ConsumerAccess, null); if (authResult.Success) { if (World.GetBlock(targetPos + Vector3i.Down).Is <Tilled>() && World.GetBlock(targetPos).Is <Empty>()) { var pack = new GameActionPack(); pack.AddGameAction(new PlantSeeds() { Species = seed.Species.GetType(), ActionLocation = targetPos, Citizen = vehicle.Driver.User, ToolUsed = this }); var changes = new InventoryChangeSet(inv, vehicle.Driver.User); changes.RemoveItem(seed.Type); pack.AddChangeSet(changes); if (pack.TryPerform()) { var plant = EcoSim.PlantSim.SpawnPlant(seed.Species, targetPos); plant.Tended = true; } } } } }
public override InteractResult OnActLeft(InteractionContext context) { if (context.HasBlock) { var block = World.GetBlock(context.BlockPosition.Value); if (block.Is <TreeDebris>()) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <WoodPulpItem>(3); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else { return(base.OnActLeft(context)); } }
public override void OnUsed(Player player, ItemStack itemStack) { if (player.User != sender && player.User != recipient) { ChatManager.ServerMessageToPlayer("You are not allowed to open this", player.User); return; } InventoryChangeSet inventoryChange = new InventoryChangeSet(player.User.Inventory, player.User); inventoryChange.ModifyStack(itemStack, contentquantity - 1, content); if (inventoryChange.TryApply().Success) { return; } else { ChatManager.ServerMessageToPlayer("Not enough room in inventory", player.User); } }
public override Result OnAreaValid(Player player, Vector3i position, Quaternion rotation) { Result authAtPosOne = AuthManager.IsAuthorized(position, player.User); Result authAtPosTwo = AuthManager.IsAuthorized((position + rotation.RotateVector(Vector3i.Right * 3)).Round, player.User); if (!authAtPosOne.Success) { return(authAtPosOne); } else if (!authAtPosTwo.Success) { return(authAtPosTwo); } Deed deed = PropertyManager.FindNearbyDeedOrCreate(player.User, position.XZ); var dist = position.XZ - World.GetPropertyPos(position.XZ) - (World.PropertyPlotLength / 2); if (dist.x == 0 || dist.y == 0) { dist = rotation.RotateVector(new Vector3i(1, 0, 1)).XZi; } dist = new Vector2i(Math.Sign(dist.x), Math.Sign(dist.y)); Vector2i.XYIter(2).ForEach(x => PropertyManager.Claim(deed.Id, player.User, position.XZ + (new Vector2i(dist.x * x.x, dist.y * x.y) * World.PropertyPlotLength))); var camp = WorldObjectManager.TryToAdd(typeof(CampsiteObject), player.User, position, rotation, false); var stockpile = WorldObjectManager.TryToAdd(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()); player.User.Markers.Add(stockpile.Position3i + Vector3i.Up, stockpile.UILinkContent()); var storage = camp.GetComponent <PublicStorageComponent>(); var changeSet = new InventoryChangeSet(storage.Inventory); PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x => { changeSet.AddItems(x.Key, x.Value, storage.Inventory); }); changeSet.Apply(); return(Result.Succeeded); }
public override InteractResult OnActLeft(InteractionContext context) { if (context.HasBlock) { var block = World.GetBlock(context.BlockPosition.Value); if (block.Is <TreeDebris>()) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <WoodPulpItem>(5); TreeUtils.GetPulpAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(WoodPulpCleanerSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else { return(base.OnActLeft(context)); } }
public static void WriteText(User user, string text) { //string onestringtext = string.Concat(text); NoteItem noteItem = (NoteItem)Item.Create <NoteItem>(); noteItem.description = text; noteItem.owner = user; InventoryChangeSet inventoryChange = new InventoryChangeSet(user.Inventory, user); inventoryChange.AddItem(noteItem); inventoryChange.RemoveItem(typeof(EmptyNoteItem)); if (inventoryChange.TryApply().Success) { return; } else { ChatManager.ServerMessageToPlayer("Not enough room in inventory", user); } }
public override InteractResult OnActLeft(InteractionContext context) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); Random r = new System.Random(); int MYpp = r.Next(100); if (context.HasBlock) { var block = World.GetBlock(context.BlockPosition.Value); if (block.Is <TreeDebris>()) { if (MYpp <= 4) { changes.AddItems <MYBeehiveItem>(1); changes.AddItems <WoodPulpItem>(4); } else if (MYpp <= 20) { changes.AddItems <MYPlumItem>(2); changes.AddItems <WoodPulpItem>(4); } else { changes.AddItems <WoodPulpItem>(5); } IAtomicAction lawAction = PlayerActions.PickUp.CreateAtomicAction(context.Player, Get <WoodPulpItem>(), context.BlockPosition.Value); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes, lawAction)); } else { return(InteractResult.NoOp); } } else { return(base.OnActLeft(context)); } }
public static void Seal(User user, string target) { UserIdType idtype; User targetuser = UserManager.FindUser(target, out idtype); if (idtype == UserIdType.Unknown) { ChatManager.ServerMessageToPlayer("User " + target + " not found", user); return; } if (!(user.Inventory.Toolbar.SelectedItem is NoteItem)) { ChatManager.ServerMessageToPlayer("No Note selected", user); return; } LetterItem letter = (LetterItem)Item.Create <LetterItem>(); letter.content = user.Inventory.Toolbar.SelectedItem; letter.contentquantity = user.Inventory.Toolbar.SelectedStack.Quantity; letter.recipient = targetuser; letter.sender = user; InventoryChangeSet inventoryChange = new InventoryChangeSet(user.Inventory, user); inventoryChange.RemoveItem(typeof(EnvelopeItem)); inventoryChange.ModifyStack(user.Inventory.Toolbar.SelectedStack, 1 - user.Inventory.Toolbar.SelectedStack.Quantity, letter); if (inventoryChange.TryApply().Success) { return; } else { ChatManager.ServerMessageToPlayer("Not enough Envelopes found", user); } }
public override InteractResult OnActLeft(InteractionContext context) { if (context.HasBlock) { var block = World.GetBlock(context.BlockPosition.Value); if (block.Is <TreeDebris>()) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); //TREE DEBRIS REWARDS (EcoSim.GetSpecies(block.Get <TreeDebris>().Species) as TreeSpecies).DebrisResources.ForEach(x => changes.AddItems(x.Key, x.Value.RandInt)); IAtomicAction lawAction = PlayerActions.PickUp.CreateAtomicAction(context.Player.User, Get <WoodPulpItem>(), context.BlockPosition.Value); var result = (InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, context.Player.User.Talentset.HasTalent(typeof(LoggingCleanupCrewTalent)) ? 1 : 3, null, changes, lawAction); if (result.IsSuccess) { this.AddExperience(context.Player.User, 0.1f, Localizer.DoStr("removing tree debris")); } return(result); } if (block.Is <Chopable>()) { var plant = EcoSim.PlantSim.GetPlant(context.BlockPosition.Value); if (plant != null) { return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false)); } } return(InteractResult.NoOp); } if (context.Target is WorldObject) { return(BasicToolOnWorldObjectCheck(context)); } return(base.OnActLeft(context)); }
internal IEnumerable <IAtomicAction> OnPickUp(Player player, InventoryChangeSet playerInvChanges) { yield return(new SimpleAtomicAction(() => WorldLayerSync.Obj.PreTickActions.Remove(this.LayerTick))); }
private bool TryDamageStump(INetObject damager, float amount, InteractionContext context) { if (this.Fallen && this.stumpHealth > 0) { List <IAtomicAction> actions = new List <IAtomicAction>(); if (damager is Player) { var action = PlayerActions.RemoveStump.CreateAtomicAction(((Player)damager).User, this); actions.Add(action); if (!action.CanApplyNonDisposing().Notify((Player)damager)) { // We only want to dispose the action if it is invalid. Othewise we want to keep it around to possibly apply later. action.Dispose(); return(false); } } this.stumpHealth = Mathf.Max(0, this.stumpHealth - amount); if (this.stumpHealth <= 0) { if (!new MultiAtomicAction(actions).TryApply().Success) { throw new Exception("Removing this stump was verified to be legal a moment ago, but is not anymore."); } if (World.GetBlock(this.Position.Round).GetType() == this.Species.BlockType) { World.DeleteBlock(this.Position.Round); } this.stumpHealth = 0; //give tree resources Player player = (Player)damager; if (player != null) { InventoryChangeSet changes = new InventoryChangeSet(player.User.Inventory, player.User); var trunkResources = this.Species.TrunkResources; if (trunkResources != null) { trunkResources.ForEach(x => changes.AddItems(x.Key, x.Value.RandInt)); } else { DebugUtils.Fail("Trunk resources missing for: " + this.Species.Name); } changes.TryApply(); } this.RPC("DestroyStump"); // Let another plant grow here EcoSim.PlantSim.UpRootPlant(this); } else { new MultiAtomicAction(actions).Dispose(); } this.Save(); this.CheckDestroy(); return(true); } else { return(false); } }
public override InteractResult OnActRight(InteractionContext context) { if (context.HasBlock) { var plant = EcoSim.PlantSim.GetPlant(context.BlockPosition.Value); var block = World.GetBlock(context.BlockPosition.Value); if (plant != null && plant is IHarvestable) { if (block is CornBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <CornItem>((4) + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); changes.AddItems <CornSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is TomatoesBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <TomatoItem>(4 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); changes.AddItems <TomatoSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is FireweedBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <FireweedShootsItem>(5 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(TundraTravellerSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is WheatBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <WheatItem>(5 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); changes.AddItems <WheatSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is BeansBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <BeansItem>(6 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(ForestForagerSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is HuckleberryBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <HuckleberriesItem>(5 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(ForestForagerSkill))); changes.AddItems <HuckleberrySeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(ForestForagerSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is BeetsBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <BeetItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); changes.AddItems <BeetSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is RiceBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <RiceItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is KelpBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <KelpItem>(1); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is PricklyPearBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <PricklyPearFruitItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); changes.AddItems <PricklyPearSeedItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } else if (block is FernBlock) { Result result = (plant as IHarvestable).TryHarvest(context.Player, true); if (result.Success) { InventoryChangeSet changes = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User); changes.AddItems <FiddleheadsItem>(3 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); changes.AddItems <FernSporeItem>(1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(GrasslandGathererSkill))); PlantUtils.GetPlantBlockAroundPoint(context.Player.User, context.BlockPosition.Value, 1 + SkillsUtil.GetSkillLevel(context.Player.User, typeof(FarmingRadiusSkill))); return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false, 3, null, changes)); } else { return(InteractResult.NoOp); } } } return(InteractResult.NoOp); } return(InteractResult.NoOp); }
public static void mint(User user, string action = "", string param = "", string arg = "") { /* * config[ "mint_daily" ] = mint_daily; * config[ "mint_max_per_day" ] = mint_max_per_day; */ Currency astr = EconomyManager.Currency.GetCurrency("Astrum"); switch (action) { case "status": string white = "#FFFFFF"; string green = "#44FF44"; string yellow = "#FFFF44"; string orange = "#FFCC44"; string red = "#FF4444"; string status = "<b>Mint Status Report</b>"; status += "<br> <color=#44FF44>*</color> <i>Mint Pool:</i> <b>"; if ((int)astr.GetAccount(" _MintPool").Val >= 8000) { status += "<color=" + green + ">" + (int)astr.GetAccount(" _MintPool").Val + "</color></b>"; } else if ((int)astr.GetAccount(" _MintPool").Val >= 4000) { status += "<color=" + yellow + ">" + (int)astr.GetAccount(" _MintPool").Val + "</color></b>"; } else if ((int)astr.GetAccount(" _MintPool").Val >= 2000) { status += "<color=" + orange + ">" + (int)astr.GetAccount(" _MintPool").Val + "</color></b>"; } else { status += "<color=" + red + ">" + (int)astr.GetAccount(" _MintPool").Val + "</color></b>"; } status += "<br> <color=#44FF44>*</color> <i>Treasury Balance:</i> <b>"; if ((int)astr.GetAccount(" _Treasury").Val >= 1500) { status += "<color=" + green + ">" + (int)astr.GetAccount(" _Treasury").Val + "</color></b>"; } else if ((int)astr.GetAccount(" _Treasury").Val >= 1000) { status += "<color=" + yellow + ">" + (int)astr.GetAccount(" _Treasury").Val + "</color></b>"; } else if ((int)astr.GetAccount(" _Treasury").Val >= 500) { status += "<color=" + orange + ">" + (int)astr.GetAccount(" _Treasury").Val + "</color></b>"; } else { status += "<color=" + red + ">" + (int)astr.GetAccount(" _Treasury").Val + "</color></b>"; } status += "<br><br> <color=#44FF44>*</color> <i>Max Minted/Day:</i> <b>"; status += "<color=" + white + ">" + config["mint_max_per_day"] + "</color></b>"; status += "<br> <color=#44FF44>*</color> <i>Minted Today:</i> - <b>"; status += "<color=" + white + ">" + minted_today + "</color></b>"; status += "<br> <color=#44FF44>*</color> <i>Available " + astr.UILink() + " Today:</i> <b>"; if ((config["mint_max_per_day"] - minted_today) >= (config["mint_max_per_day"] * 0.75)) { status += "<color=" + green + ">" + (config["mint_max_per_day"] - minted_today) + "</color></b>"; } else if ((config["mint_max_per_day"] - minted_today) >= (config["mint_max_per_day"] * 0.5)) { status += "<color=" + yellow + ">" + (config["mint_max_per_day"] - minted_today) + "</color></b>"; } else if ((config["mint_max_per_day"] - minted_today) >= (config["mint_max_per_day"] * 0.25)) { status += "<color=" + orange + ">" + (config["mint_max_per_day"] - minted_today) + "</color></b>"; } else { status += "<color=" + red + ">" + minted_today + "</color></b>"; } send_pm(status, user.Player, ChatCategory.Default, DefaultChatTags.Government); break; case "init": if (UserManager.IsAdmin(user)) { if (param != "") { if (astr.GetAccount(" _MintPool").Val == 0) { astr.GetAccount(" _MintPool").Val += int.Parse(param); astr.GetAccount(user.Name).Val -= int.Parse(param); send_msg( "<color=#88FF44>NOTICE:</color> " + "<color=#AAFF44>" + arg + "</color> <color=#44FF44>" + astr.UILink() + " " + "added to the mint pool, <color=#AAFF44>(PoolBalance: " + astr.GetAccount(" _MintPool").Val + ").</color>", ChatCategory.Default, DefaultChatTags.Government ); // save config save_config(); } else { send_pm( "<color=#FF6666>ERROR:</color> " + "<color=#FF4444>The mint pool has a non-zero balance, " + "you most likely meant to do <color=#FF6666>/mint add, [number]</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); } } else { send_pm( "<color=#FF6666>ERROR:</color> " + "<color=#FF4444>You must initialize the mint pool with an integer value.</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); } } break; case "add": if (UserManager.IsAdmin(user)) { if (param != "") { astr.GetAccount(" _MintPool").Val += int.Parse(param); astr.GetAccount(user.Name).Val -= int.Parse(param); send_msg( "<color=#88FF44>NOTICE:</color> " + "<color=#AAFF44>" + arg + "</color> <color=#44FF44>" + astr.UILink() + " " + "added to the mint pool. <color=#AAFF44>New balance: " + astr.GetAccount(" _MintPool").Val + "</color>", ChatCategory.Default, DefaultChatTags.Government ); // save config save_config(); } else { send_pm( "<color=#FF6666>ERROR:</color> " + "<color=#FF4444>You must initialize the mint pool with an integer value.</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); } } break; case "set": if (UserManager.IsAdmin(user)) { if (param == "mint_daily" || param == "mint_max_per_day") { config[param] = int.Parse(arg); send_pm( "<color=#44FF44>NOTE: " + param + " set to " + config[param] + ".</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); // save config save_config(); } } break; default: // load config //load_config(); if (minting.ContainsKey(user.Name)) { //DateTime last = minting[user.Name]; //DateTime now = new DateTime(); //TimeSpan t = last - now; //int delta = (24 - (int) t.TotalHours); //if (delta > 0) { /* * send_pm( * "<color=#FF4444>ERROR: You may only access the mint pool once per 24 hours.<br>" + * "more hours to <i>/mint</i> again.</color>", * " more hours to <i>/mint</i> again.</color>", * user.Player, ChatCategory.Default, DefaultChatTags.Government * ); */ send_pm( "<color=#FF4444>ERROR: You may only access the mint pool once per 24 hours.<br>" + "You must wait until the daily server restart at 12:00 PST/PDT (approx.), " + " before you can <i>/mint</i> again.</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); return; //} } if (minted_today >= config["mint_max_per_day"]) { send_pm( "<color=#FF4444>ERROR: Mint max-per-day has been reached, please try again tomorrow.</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); return; } ItemStack itemStack = user.Inventory.NonEmptyStacks.Where( stack => stack.Item.FriendlyName == "Gold Ore" ).FirstOrDefault(); if (itemStack != null) { bool refund = false; int items = 0; for (var i = 0; i < config["mint_daily"]; i++) { bool worked = user.Inventory.TryRemoveItem <GoldOreItem>(user); if (!worked) { // failed break; } items++; } float amount = (float)items; float val = amount * 10f; // checks if (items == 0) { send_pm( "<color=#FF4444>ERROR: You must mint something, get some GoldOre.</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); } else if (astr.GetAccount(" _MintPool").Val < val) { refund = true; send_pm( "<color=#FF4444>ERROR: The mint pool does not have enough " + astr.UILink() + " to cover that, (PoolBalance:" + astr.GetAccount(" _MintPool").Val + ").</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); } else { // award minted_today += (int)val; astr.GetAccount(" _MintPool").Val -= val; astr.GetAccount(user.Name).Val += val; minting[user.Name] = new DateTime(); send_msg( "<color=#AAFF44>NOTICE:</color> " + "<color=#44FF44>" + UserManager.UILink(user.Name) + " has converted " + "<color=#AAFF44>" + val + "</color> <color=#44FF44>" + astr.UILink() + " from the mint pool, <color=#AAFF44>(PoolBalance:" + astr.GetAccount(" _MintPool").Val + ").</color>", ChatCategory.Default, DefaultChatTags.Government ); // save config save_config(); } if (refund) { InventoryChangeSet changes = new InventoryChangeSet(user.Inventory, user); changes.AddItems <GoldOreItem>(items); } } else { // not enough send_pm( "<color=#FF4444>ERROR: You must mint <i>something</i>, go get some GoldOre.</color>", user.Player, ChatCategory.Default, DefaultChatTags.Government ); return; } break; } }