private object OnRecycleItem(Recycler recycler, Item item) { if (CrafterManager.ContainsRecycler(recycler)) { // Prevent recycling return(true); } return(null); }
private object OnHammerHit(BasePlayer player, HitInfo info) { var entity = info.HitEntity as BaseCombatEntity; var recycler = entity as Recycler; var researchTable = entity as ResearchTable; if (entity == null || (recycler == null && researchTable == null)) { return(null); } Func <string> hpMessage = () => { return(Lang.Translate(player, "hp-message", entity.Health(), entity.MaxHealth())); }; // Don't allow upgrading/downgrading/repairing if there's less than 8 seconds since the entity was attacked. if (entity.SecondsSinceAttacked < 8) { if (recycler != null && CrafterManager.ContainsRecycler(recycler)) { // Show hp info if repairing is blocked. player.ShowScreenMessage(hpMessage(), 2); } return(null); } if (!lastHammerHit.ContainsKey(player)) { lastHammerHit[player] = 0; } ((DecayEntity)entity).DecayTouch(); // Reset decay // Make sure entity is full health, otherwise repair. if (entity.Health() < entity.MaxHealth()) { if (recycler == null) { return(null); } if (!CrafterManager.ContainsRecycler(recycler)) { return(null); } if (Time.time - lastHammerHit[player] > Constants.HammerConfirmTime) { player.ShowScreenMessage(hpMessage() + "\n\n" + Lang.Translate(player, "hit-again-to-repair"), Constants.HammerConfirmTime); lastHammerHit[player] = Time.time; return(true); } lastHammerHit[player] = Time.time; player.HideScreenMessage(); entity.DoRepair(player); player.ShowScreenMessage(hpMessage(), 2); // Reset last hammer hit so that the player won't accidentally downgrade/upgrade with the next hammer hit. if (entity.Health() >= entity.MaxHealth()) { lastHammerHit[player] = 0; } return(true); } // Only allow upgrading/downgrading if we have building permission. if (player.IsBuildingBlocked(entity.ServerPosition, entity.ServerRotation, entity.bounds)) { if (recycler != null && CrafterManager.ContainsRecycler(recycler)) // Only show hp info if this is a crafter { // Show hp info if building blocked. player.ShowScreenMessage(hpMessage(), 2); } return(null); } // Check permission and if the entity owner is the current player. if (!permission.UserHasPermission(player.UserIDString, Constants.UsePermission) || entity.OwnerID != player.userID) { if (recycler != null && CrafterManager.ContainsRecycler(recycler)) { player.ShowScreenMessage(hpMessage(), 2); } return(null); } if (researchTable != null) // Upgrade to crafter (if less than 10 minutes since placement) { if (!upgradeableEntities.Contains(researchTable)) { return(null); } return(HandleUpgradeRequest(player, researchTable)); } var crafter = CrafterManager.GetCrafter(recycler); if (crafter == null) { return(null); } if (DateTime.UtcNow - crafter.CreationTime > TimeSpan.FromSeconds(Constants.TimeToUpgrade)) { player.ShowScreenMessage(hpMessage(), 2); return(null); } // Check if player has authed on potential codelock. if (!crafter.PlayerCanAccess(player)) { crafter.PlayLockedSound(); return(true); } return(HandleDowngradeRequest(player, crafter)); }