async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (!eventArgs.User.TryGetComponent <InventoryComponent>(out var userInv)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-inventory-message")))); return(false); } if (!eventArgs.User.TryGetComponent <MindComponent>(out var userMindComponent)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-mind-message")))); return(false); } var userMind = userMindComponent.Mind; if (userMind == null) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-user-mind-message")))); return(false); } if (!eventArgs.Using.TryGetComponent <UplinkComponent>(out var victimUplink)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-message")))); return(false); } if (!eventArgs.Using.TryGetComponent <TraitorDeathMatchReliableOwnerTagComponent>(out var victimPDAOwner)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-owner-message")))); return(false); } if (victimPDAOwner.UserId == userMind.UserId) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-pda-different-user-message")))); return(false); } var userPDAEntity = userInv.GetSlotItem(EquipmentSlotDefines.Slots.IDCARD)?.Owner; UplinkComponent?userUplink = null; if (userPDAEntity != null) { if (userPDAEntity.TryGetComponent <UplinkComponent>(out var userUplinkComponent)) { userUplink = userUplinkComponent; } } if (userUplink == null) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-no-pda-in-pocket-message")))); return(false); } // We have finally determined both PDA components. FINALLY. var userAccount = userUplink.UplinkAccount; var victimAccount = victimUplink.UplinkAccount; if (userAccount == null) { // This shouldn't even BE POSSIBLE in the actual mode this is meant for. // Advanced Syndicate anti-tampering technology. // Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-tampering-detected")); // if (eventArgs.User.TryGetComponent<DamagableComponent>(out var userDamagable)) // userDamagable.ChangeDamage(DamageType.Shock, 9001, true, null); // ...So apparently, "it probably shouldn't kill people for a mistake". // :( // Give boring error message instead. Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-user-no-uplink-account-message")))); return(false); } if (victimAccount == null) { Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-main-message", ("secondMessage", Loc.GetString("traitor-death-match-redemption-component-interact-using-victim-no-uplink-account-message")))); return(false); } // 4 is the per-PDA bonus amount. var accounts = Owner.EntityManager.EntitySysManager.GetEntitySystem <UplinkAccountsSystem>(); var transferAmount = victimAccount.Balance + 4; accounts.SetBalance(victimAccount, 0); accounts.AddToBalance(userAccount, transferAmount); victimUplink.Owner.Delete(); Owner.PopupMessage(eventArgs.User, Loc.GetString("traitor-death-match-redemption-component-interact-using-success-message", ("tcAmount", transferAmount))); return(true); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { Rustle(); return(_secretStash.TryHideItem(eventArgs.User, eventArgs.Using)); }
public override async Task <bool> InteractUsing(InteractUsingEventArgs eventArgs) { return(TryInsertBullet(eventArgs)); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { return(TryInsertAmmo(eventArgs.User, eventArgs.Using)); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { return(InsertBulb(eventArgs.Using)); }
public async Task <bool> InteractUsing(InteractUsingEventArgs eventArgs) { var user = eventArgs.User; var usingItem = eventArgs.Using; if (usingItem == null || usingItem.Deleted || !ActionBlockerSystem.CanInteract(user)) { return(false); } if (usingItem.TryGetComponent(out SeedComponent? seeds)) { if (Seed == null) { if (seeds.Seed == null) { user.PopupMessageCursor(Loc.GetString("The packet seems to be empty. You throw it away.")); usingItem.Delete(); return(false); } user.PopupMessageCursor(Loc.GetString("You plant the {0} {1}.", seeds.Seed.SeedName, seeds.Seed.SeedNoun)); Seed = seeds.Seed; Dead = false; Age = 1; Health = Seed.Endurance; _lastCycle = _gameTiming.CurTime; usingItem.Delete(); CheckLevelSanity(); UpdateSprite(); return(true); } user.PopupMessageCursor(Loc.GetString("The {0} already has seeds in it!", Owner.Name)); return(false); } if (usingItem.HasComponent <HoeComponent>()) { if (WeedLevel > 0) { user.PopupMessageCursor(Loc.GetString("You remove the weeds from the {0}.", Owner.Name)); user.PopupMessageOtherClients(Loc.GetString("{0} starts uprooting the weeds.", user.Name)); WeedLevel = 0; UpdateSprite(); } else { user.PopupMessageCursor(Loc.GetString("This plot is devoid of weeds! It doesn't need uprooting.")); } return(true); } if (usingItem.TryGetComponent(out SolutionContainerComponent? solution) && solution.CanRemoveSolutions) { var amount = 5f; var sprayed = false; if (usingItem.TryGetComponent(out SprayComponent? spray)) { sprayed = true; amount = 1f; EntitySystem.Get <AudioSystem>().PlayFromEntity(spray.SpraySound, usingItem, AudioHelpers.WithVariation(0.125f)); } var chemAmount = ReagentUnit.New(amount); var split = solution.Solution.SplitSolution(chemAmount <= solution.Solution.TotalVolume ? chemAmount : solution.Solution.TotalVolume); user.PopupMessageCursor(Loc.GetString(sprayed ? $"You spray {Owner.Name} with {usingItem.Name}." : $"You transfer {split.TotalVolume.ToString()}u to {Owner.Name}")); _solutionContainer?.TryAddSolution(split); SkipAging++; // We're forcing an update cycle, so one age hasn't passed. ForceUpdate = true; Update(); return(true); } if (usingItem.HasComponent <PlantSampleTakerComponent>()) { if (Seed == null) { user.PopupMessageCursor(Loc.GetString("There is nothing to take a sample of!")); return(false); } if (Sampled) { user.PopupMessageCursor(Loc.GetString("This plant has already been sampled.")); return(false); } if (Dead) { user.PopupMessageCursor(Loc.GetString("This plant is dead.")); return(false); } var seed = Seed.SpawnSeedPacket(user.Transform.Coordinates); seed.RandomOffset(0.25f); user.PopupMessageCursor(Loc.GetString($"You take a sample from the {Seed.DisplayName}.")); Health -= (_random.Next(3, 5) * 10); if (_random.Prob(0.3f)) { Sampled = true; } // Just in case. CheckLevelSanity(); SkipAging++; // We're forcing an update cycle, so one age hasn't passed. ForceUpdate = true; Update(); return(true); } if (usingItem.HasComponent <BotanySharpComponent>()) { return(DoHarvest(user)); } return(false); }
public async Task <bool> InteractUsing(InteractUsingEventArgs eventArgs) { return(TryInsertBullet(eventArgs.User, eventArgs.Using)); }
public override bool InteractUsing(InteractUsingEventArgs eventArgs) { // Insert magazine if (eventArgs.Using.TryGetComponent(out RangedMagazineComponent magazineComponent)) { if ((MagazineTypes & magazineComponent.MagazineType) == 0) { Owner.PopupMessage(eventArgs.User, Loc.GetString("Wrong magazine type")); return(false); } if (magazineComponent.Caliber != _caliber) { Owner.PopupMessage(eventArgs.User, Loc.GetString("Wrong caliber")); return(false); } if (_magNeedsOpenBolt && !BoltOpen) { Owner.PopupMessage(eventArgs.User, Loc.GetString("Need to open bolt first")); return(false); } if (_magazineContainer.ContainedEntity == null) { if (_soundMagInsert != null) { EntitySystem.Get <AudioSystem>().PlayAtCoords(_soundMagInsert, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2)); } Owner.PopupMessage(eventArgs.User, Loc.GetString("Magazine inserted")); _magazineContainer.Insert(eventArgs.Using); Dirty(); UpdateAppearance(); return(true); } Owner.PopupMessage(eventArgs.User, Loc.GetString("Already holding a magazine")); return(false); } // Insert 1 ammo if (eventArgs.Using.TryGetComponent(out AmmoComponent ammoComponent)) { if (!BoltOpen) { Owner.PopupMessage(eventArgs.User, Loc.GetString("Cannot insert ammo while bolt is closed")); return(false); } if (ammoComponent.Caliber != _caliber) { Owner.PopupMessage(eventArgs.User, Loc.GetString("Wrong caliber")); return(false); } if (_chamberContainer.ContainedEntity == null) { Owner.PopupMessage(eventArgs.User, Loc.GetString("Ammo inserted")); _chamberContainer.Insert(eventArgs.Using); Dirty(); UpdateAppearance(); return(true); } Owner.PopupMessage(eventArgs.User, Loc.GetString("Chamber full")); return(false); } return(false); }
public OnDoorPryEvent(InteractUsingEventArgs args) { Args = args; }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (!HasBoard && eventArgs.Using.TryGetComponent <MachineBoardComponent>(out var machineBoard)) { if (eventArgs.Using.TryRemoveFromContainer()) { // Valid board! _boardContainer.Insert(eventArgs.Using); // Setup requirements and progress... ResetProgressAndRequirements(machineBoard); if (Owner.TryGetComponent <AppearanceComponent>(out var appearance)) { appearance.SetData(MachineFrameVisuals.State, 2); } if (Owner.TryGetComponent(out ConstructionComponent construction)) { // So prying the components off works correctly. construction.ResetEdge(); } return(true); } } else if (HasBoard) { if (eventArgs.Using.TryGetComponent <MachinePartComponent>(out var machinePart)) { if (!Requirements.ContainsKey(machinePart.PartType)) { return(false); } if (_progress[machinePart.PartType] != Requirements[machinePart.PartType] && eventArgs.Using.TryRemoveFromContainer() && _partContainer.Insert(eventArgs.Using)) { _progress[machinePart.PartType]++; return(true); } } if (eventArgs.Using.TryGetComponent <StackComponent>(out var stack)) { var type = (StackType)stack.StackType; if (!MaterialRequirements.ContainsKey(type)) { return(false); } if (_materialProgress[type] == MaterialRequirements[type]) { return(false); } var needed = MaterialRequirements[type] - _materialProgress[type]; var count = stack.Count; if (count < needed && stack.Split(count, Owner.Transform.Coordinates, out var newStack)) { _materialProgress[type] += count; return(true); } if (!stack.Split(needed, Owner.Transform.Coordinates, out newStack)) { return(false); } if (!_partContainer.Insert(newStack)) { return(false); } _materialProgress[type] += needed; return(true); } foreach (var(compName, info) in ComponentRequirements) { if (_componentProgress[compName] >= info.Amount) { continue; } var registration = _componentFactory.GetRegistration(compName); if (!eventArgs.Using.HasComponent(registration.Type)) { continue; } if (!eventArgs.Using.TryRemoveFromContainer() || !_partContainer.Insert(eventArgs.Using)) { continue; } _componentProgress[compName]++; return(true); } } return(false); }
public BeforeDoorPryEvent(InteractUsingEventArgs args) { Args = args; }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (!Powered) { Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-no-power")); return(false); } if (_broken) { Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-broken")); return(false); } if (_entities.GetComponent <HandsComponent>(eventArgs.User).GetActiveHand?.Owner is not { Valid: true } itemEntity) { eventArgs.User.PopupMessage(Loc.GetString("microwave-component-interact-using-no-active-hand")); return(false); } if (_entities.TryGetComponent <SolutionTransferComponent?>(itemEntity, out var attackPourable)) { var solutionsSystem = EntitySystem.Get <SolutionContainerSystem>(); if (!solutionsSystem.TryGetDrainableSolution(itemEntity, out var attackSolution)) { return(false); } if (!solutionsSystem.TryGetSolution(Owner, SolutionName, out var solution)) { return(false); } //Get transfer amount. May be smaller than _transferAmount if not enough room var realTransferAmount = FixedPoint2.Min(attackPourable.TransferAmount, solution.AvailableVolume); if (realTransferAmount <= 0) //Special message if container is full { Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-container-full")); return(false); } //Move units from attackSolution to targetSolution var removedSolution = EntitySystem.Get <SolutionContainerSystem>() .Drain(itemEntity, attackSolution, realTransferAmount); if (!EntitySystem.Get <SolutionContainerSystem>().TryAddSolution(Owner, solution, removedSolution)) { return(false); } Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-transfer-success", ("amount", removedSolution.TotalVolume))); return(true); } if (!_entities.TryGetComponent(itemEntity, typeof(ItemComponent), out var food)) { Owner.PopupMessage(eventArgs.User, "microwave-component-interact-using-transfer-fail"); return(false); } var ent = food.Owner; //Get the entity of the ItemComponent. _storage.Insert(ent); _uiDirty = true; return(true); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (!eventArgs.User.TryGetComponent <InventoryComponent>(out var userInv)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"USER PDA OUT OF RANGE (0039)\"")); return(false); } if (!eventArgs.User.TryGetComponent <MindComponent>(out var userMindComponent)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"AUTHENTICATION FAILED (0045)\"")); return(false); } var userMind = userMindComponent.Mind; if (userMind == null) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"AUTHENTICATION FAILED (0052)\"")); return(false); } if (!eventArgs.Using.TryGetComponent <PDAComponent>(out var victimPDA)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"GIVEN PDA IS NOT A PDA (0058)\"")); return(false); } if (!eventArgs.Using.TryGetComponent <TraitorDeathMatchReliableOwnerTagComponent>(out var victimPDAOwner)) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"GIVEN PDA HAS NO OWNER (0064)\"")); return(false); } if (victimPDAOwner.UserId == userMind.UserId) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"GIVEN PDA OWNED BY USER (0070)\"")); return(false); } var userPDAEntity = userInv.GetSlotItem(EquipmentSlotDefines.Slots.IDCARD)?.Owner; PDAComponent?userPDA = null; if (userPDAEntity != null) { if (userPDAEntity.TryGetComponent <PDAComponent>(out var userPDAComponent)) { userPDA = userPDAComponent; } } if (userPDA == null) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"NO USER PDA IN IDCARD POCKET (0083)\"")); return(false); } // We have finally determined both PDA components. FINALLY. var userAccount = userPDA.SyndicateUplinkAccount; var victimAccount = victimPDA.SyndicateUplinkAccount; if (userAccount == null) { // This shouldn't even BE POSSIBLE in the actual mode this is meant for. // Advanced Syndicate anti-tampering technology. // Owner.PopupMessage(eventArgs.User, Loc.GetString("Tampering detected.")); // if (eventArgs.User.TryGetComponent<DamagableComponent>(out var userDamagable)) // userDamagable.ChangeDamage(DamageType.Shock, 9001, true, null); // ...So apparently, "it probably shouldn't kill people for a mistake". // :( // Give boring error message instead. Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"USER PDA HAS NO UPLINK ACCOUNT (0102)\"")); return(false); } if (victimAccount == null) { Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine buzzes, and displays: \"GIVEN PDA HAS NO UPLINK ACCOUNT (0108)\"")); return(false); } // 4 is the per-PDA bonus amount. var transferAmount = victimAccount.Balance + 4; victimAccount.ModifyAccountBalance(0); userAccount.ModifyAccountBalance(userAccount.Balance + transferAmount); victimPDA.Owner.Delete(); Owner.PopupMessage(eventArgs.User, Loc.GetString("The machine plays a happy little tune, and displays: \"SUCCESS: {0} TC TRANSFERRED\"", transferAmount)); return(true); }
public override bool InteractUsing(InteractUsingEventArgs eventArgs) { return(TryInsertBullet(eventArgs)); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { var user = eventArgs.User; var usingItem = eventArgs.Using; if (usingItem == null || usingItem.Deleted || !EntitySystem.Get <ActionBlockerSystem>().CanInteract(user)) { return(false); } if (usingItem.TryGetComponent(out SeedComponent? seeds)) { if (Seed == null) { if (seeds.Seed == null) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-seed-packet-message")); usingItem.QueueDelete(); return(false); } user.PopupMessageCursor(Loc.GetString("plant-holder-component-plant-success-message", ("seedName", seeds.Seed.SeedName), ("seedNoun", seeds.Seed.SeedNoun))); Seed = seeds.Seed; Dead = false; Age = 1; Health = Seed.Endurance; _lastCycle = _gameTiming.CurTime; usingItem.QueueDelete(); CheckLevelSanity(); UpdateSprite(); return(true); } user.PopupMessageCursor(Loc.GetString("plant-holder-component-already-seeded-message", ("name", Owner.Name))); return(false); } if (usingItem.HasTag("Hoe")) { if (WeedLevel > 0) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-weeds-message", ("name", Owner.Name))); user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-weeds-others-message", ("otherName", user.Name))); WeedLevel = 0; UpdateSprite(); } else { user.PopupMessageCursor(Loc.GetString("plant-holder-component-no-weeds-message")); } return(true); } if (usingItem.HasTag("Shovel")) { if (Seed != null) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-plant-message", ("name", Owner.Name))); user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-plant-others-message", ("name", user.Name))); RemovePlant(); } else { user.PopupMessageCursor(Loc.GetString("plant-holder-component-no-plant-message")); } return(true); } if (usingItem.TryGetComponent(out ISolutionInteractionsComponent? solution) && solution.CanDrain) { var amount = ReagentUnit.New(5); var sprayed = false; if (usingItem.TryGetComponent(out SprayComponent? spray)) { sprayed = true; amount = ReagentUnit.New(1); if (!string.IsNullOrEmpty(spray.SpraySound)) { SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound, usingItem, AudioHelpers.WithVariation(0.125f)); } } var split = solution.Drain(amount); if (split.TotalVolume == 0) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-message", ("owner", usingItem))); return(true); } user.PopupMessageCursor(Loc.GetString(sprayed ? "plant-holder-component-spray-message" : "plant-holder-component-transfer-message", ("owner", Owner), ("amount", split.TotalVolume))); _solutionContainer?.TryAddSolution(split); ForceUpdateByExternalCause(); return(true); } if (usingItem.HasTag("PlantSampleTaker")) { if (Seed == null) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-nothing-to-sample-message")); return(false); } if (Sampled) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-already-sampled-message")); return(false); } if (Dead) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-dead-plant-message")); return(false); } var seed = Seed.SpawnSeedPacket(user.Transform.Coordinates); seed.RandomOffset(0.25f); user.PopupMessageCursor(Loc.GetString("plant-holder-component-take-sample-message", ("seedName", Seed.DisplayName))); Health -= (_random.Next(3, 5) * 10); if (_random.Prob(0.3f)) { Sampled = true; } // Just in case. CheckLevelSanity(); ForceUpdateByExternalCause(); return(true); } if (usingItem.HasTag("BotanySharp")) { return(DoHarvest(user)); } if (usingItem.HasComponent <ProduceComponent>()) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-compost-message", ("owner", Owner), ("usingItem", usingItem))); user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-compost-others-message", ("user", user), ("usingItem", usingItem), ("owner", Owner))); if (usingItem.TryGetComponent(out SolutionContainerComponent? solution2)) { // This deliberately discards overfill. _solutionContainer?.TryAddSolution(solution2.SplitSolution(solution2.Solution.TotalVolume)); ForceUpdateByExternalCause(); } usingItem.QueueDelete(); return(true); } return(false); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { return(await TryToggleAnchor(eventArgs.User, eventArgs.Using)); }
public bool InteractUsing(InteractUsingEventArgs eventArgs) { return(InsertBulb(eventArgs.Using)); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { var user = eventArgs.User; var usingItem = eventArgs.Using; if (usingItem == null || usingItem.Deleted || !ActionBlockerSystem.CanInteract(user)) { return(false); } if (usingItem.TryGetComponent(out SeedComponent? seeds)) { if (Seed == null) { if (seeds.Seed == null) { user.PopupMessageCursor(Loc.GetString("The packet seems to be empty. You throw it away.")); usingItem.Delete(); return(false); } user.PopupMessageCursor(Loc.GetString("You plant the {0} {1}.", seeds.Seed.SeedName, seeds.Seed.SeedNoun)); Seed = seeds.Seed; Dead = false; Age = 1; Health = Seed.Endurance; _lastCycle = _gameTiming.CurTime; usingItem.Delete(); CheckLevelSanity(); UpdateSprite(); return(true); } user.PopupMessageCursor(Loc.GetString("The {0} already has seeds in it!", Owner.Name)); return(false); } if (usingItem.HasTag("Hoe")) { if (WeedLevel > 0) { user.PopupMessageCursor(Loc.GetString("You remove the weeds from the {0}.", Owner.Name)); user.PopupMessageOtherClients(Loc.GetString("{0} starts uprooting the weeds.", user.Name)); WeedLevel = 0; UpdateSprite(); } else { user.PopupMessageCursor(Loc.GetString("This plot is devoid of weeds! It doesn't need uprooting.")); } return(true); } if (usingItem.HasTag("Shovel")) { if (Seed != null) { user.PopupMessageCursor(Loc.GetString("You remove the plant from the {0}.", Owner.Name)); user.PopupMessageOtherClients(Loc.GetString("{0} removes the plant.", user.Name)); RemovePlant(); } else { user.PopupMessageCursor(Loc.GetString("There is no plant to remove.")); } return(true); } if (usingItem.TryGetComponent(out ISolutionInteractionsComponent? solution) && solution.CanDrain) { var amount = ReagentUnit.New(5); var sprayed = false; if (usingItem.TryGetComponent(out SprayComponent? spray)) { sprayed = true; amount = ReagentUnit.New(1); if (!string.IsNullOrEmpty(spray.SpraySound)) { SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound, usingItem, AudioHelpers.WithVariation(0.125f)); } } var split = solution.Drain(amount); if (split.TotalVolume == 0) { user.PopupMessageCursor(Loc.GetString("{0:TheName} is empty!", usingItem)); return(true); } user.PopupMessageCursor(Loc.GetString( sprayed ? "You spray {0:TheName}" : "You transfer {1}u to {0:TheName}", Owner, split.TotalVolume)); _solutionContainer?.TryAddSolution(split); ForceUpdateByExternalCause(); return(true); } if (usingItem.HasTag("PlantSampleTaker")) { if (Seed == null) { user.PopupMessageCursor(Loc.GetString("There is nothing to take a sample of!")); return(false); } if (Sampled) { user.PopupMessageCursor(Loc.GetString("This plant has already been sampled.")); return(false); } if (Dead) { user.PopupMessageCursor(Loc.GetString("This plant is dead.")); return(false); } var seed = Seed.SpawnSeedPacket(user.Transform.Coordinates); seed.RandomOffset(0.25f); user.PopupMessageCursor(Loc.GetString($"You take a sample from the {Seed.DisplayName}.")); Health -= (_random.Next(3, 5) * 10); if (_random.Prob(0.3f)) { Sampled = true; } // Just in case. CheckLevelSanity(); ForceUpdateByExternalCause(); return(true); } if (usingItem.HasTag("BotanySharp")) { return(DoHarvest(user)); } if (usingItem.HasComponent <ProduceComponent>()) { user.PopupMessageCursor(Loc.GetString("You compost {1:theName} into {0:theName}.", Owner, usingItem)); user.PopupMessageOtherClients(Loc.GetString("{0:TheName} composts {1:theName} into {2:theName}.", user, usingItem, Owner)); if (usingItem.TryGetComponent(out SolutionContainerComponent? solution2)) { // This deliberately discards overfill. _solutionContainer?.TryAddSolution(solution2.SplitSolution(solution2.Solution.TotalVolume)); ForceUpdateByExternalCause(); } usingItem.Delete(); return(true); } return(false); }
async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { var user = eventArgs.User; var usingItem = eventArgs.Using; if ((!_entMan.EntityExists(usingItem) ? EntityLifeStage.Deleted : _entMan.GetComponent <MetaDataComponent>(usingItem).EntityLifeStage) >= EntityLifeStage.Deleted) { return(false); } var botanySystem = EntitySystem.Get <BotanySystem>(); if (_entMan.TryGetComponent(usingItem, out SeedComponent? seeds)) { if (Seed == null) { var protoMan = IoCManager.Resolve <IPrototypeManager>(); if (!protoMan.TryIndex <SeedPrototype>(seeds.SeedName, out var seed)) { return(false); } user.PopupMessageCursor(Loc.GetString("plant-holder-component-plant-success-message", ("seedName", seed.SeedName), ("seedNoun", seed.SeedNoun))); Seed = seed; Dead = false; Age = 1; Health = Seed.Endurance; _lastCycle = _gameTiming.CurTime; _entMan.QueueDeleteEntity(usingItem); CheckLevelSanity(); UpdateSprite(); return(true); } user.PopupMessageCursor(Loc.GetString("plant-holder-component-already-seeded-message", ("name", _entMan.GetComponent <MetaDataComponent>(Owner).EntityName))); return(false); } var tagSystem = EntitySystem.Get <TagSystem>(); if (tagSystem.HasTag(usingItem, "Hoe")) { if (WeedLevel > 0) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-weeds-message", ("name", _entMan.GetComponent <MetaDataComponent>(Owner).EntityName))); user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-weeds-others-message", ("otherName", _entMan.GetComponent <MetaDataComponent>(user).EntityName))); WeedLevel = 0; UpdateSprite(); } else { user.PopupMessageCursor(Loc.GetString("plant-holder-component-no-weeds-message")); } return(true); } if (tagSystem.HasTag(usingItem, "Shovel")) { if (Seed != null) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-plant-message", ("name", _entMan.GetComponent <MetaDataComponent>(Owner).EntityName))); user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-plant-others-message", ("name", _entMan.GetComponent <MetaDataComponent>(user).EntityName))); RemovePlant(); } else { user.PopupMessageCursor(Loc.GetString("plant-holder-component-no-plant-message")); } return(true); } var solutionSystem = EntitySystem.Get <SolutionContainerSystem>(); if (solutionSystem.TryGetDrainableSolution(usingItem, out var solution) && solutionSystem.TryGetSolution(Owner, SoilSolutionName, out var targetSolution) && _entMan.TryGetComponent(usingItem, out SprayComponent? spray)) { var amount = FixedPoint2.New(1); var targetEntity = Owner; var solutionEntity = usingItem; SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem, AudioHelpers.WithVariation(0.125f)); var split = solutionSystem.Drain(solutionEntity, solution, amount); if (split.TotalVolume == 0) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-message", ("owner", usingItem))); return(true); } user.PopupMessageCursor(Loc.GetString("plant-holder-component-spray-message", ("owner", Owner), ("amount", split.TotalVolume))); solutionSystem.TryAddSolution(targetEntity, targetSolution, split); ForceUpdateByExternalCause(); return(true); } if (tagSystem.HasTag(usingItem, "PlantSampleTaker")) { if (Seed == null) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-nothing-to-sample-message")); return(false); } if (Sampled) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-already-sampled-message")); return(false); } if (Dead) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-dead-plant-message")); return(false); } var seed = botanySystem.SpawnSeedPacket(Seed, _entMan.GetComponent <TransformComponent>(user).Coordinates); seed.RandomOffset(0.25f); user.PopupMessageCursor(Loc.GetString("plant-holder-component-take-sample-message", ("seedName", Seed.DisplayName))); Health -= (_random.Next(3, 5) * 10); if (_random.Prob(0.3f)) { Sampled = true; } // Just in case. CheckLevelSanity(); ForceUpdateByExternalCause(); return(true); } if (_entMan.HasComponent <SharpComponent>(usingItem)) { return(DoHarvest(user)); } if (_entMan.TryGetComponent <ProduceComponent?>(usingItem, out var produce)) { user.PopupMessageCursor(Loc.GetString("plant-holder-component-compost-message", ("owner", Owner), ("usingItem", usingItem))); user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-compost-others-message", ("user", user), ("usingItem", usingItem), ("owner", Owner))); if (solutionSystem.TryGetSolution(usingItem, produce.SolutionName, out var solution2)) { // This deliberately discards overfill. solutionSystem.TryAddSolution(usingItem, solution2, solutionSystem.SplitSolution(usingItem, solution2, solution2.TotalVolume)); ForceUpdateByExternalCause(); } _entMan.QueueDeleteEntity(usingItem); return(true); } return(false); }
public abstract Task <bool> InteractUsing(InteractUsingEventArgs eventArgs);
bool IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { return(TryToggleAnchor(eventArgs.User, eventArgs.Using)); }