// Return value: // - null = continue with default behaviour of hammer hit // - anything else: prevent default behaviour. private object HandleDowngradeRequest(BasePlayer player, Crafter crafter) { float lastRequest = lastHammerHit[player]; if (Time.time - lastRequest > Constants.HammerConfirmTime) // Confirm the downgrade { string message = Lang.Translate(player, "hp-message", crafter.Recycler.Health(), crafter.Recycler.MaxHealth()); message += "\n\n" + Lang.Translate(player, "hammer-confirm-downgrade"); lastHammerHit[player] = Time.time; player.ShowScreenMessage(message, Constants.HammerConfirmTime); return(true); } lastHammerHit[player] = 0; // Reset time CrafterManager.DestroyCrafter(crafter, true, false); FxManager.PlayFx(crafter.Position, Constants.UpgradeMetalFxPrefab); player.HideScreenMessage(); foreach (var itemAmount in UpgradeCost) { player.GiveItem(ItemManager.CreateByItemID(itemAmount.itemid, (int)itemAmount.amount)); } // Refund codelock if one is attached if (crafter.CodeLock != null) { var item = ItemManager.Create(ItemManager.FindItemDefinition("lock.code")); player.GiveItem(item); } return(true); }
void OnEntityKill(BaseNetworkable entity) { if (!serverInitialized) // Check if server is initialized. This hook tends to call on startup before OnServerInitialized has been called. { return; } var researchTable = entity as ResearchTable; if (researchTable != null) { upgradeableEntities.Remove(researchTable); } var recycler = entity as Recycler; if (recycler == null) { return; } var crafter = CrafterManager.GetCrafter(recycler); if (crafter == null) { return; } CrafterManager.DestroyCrafter(crafter, false, false); }