using Eco.Gameplay.Interactions; using Eco.Gameplay.Items; using Eco.Gameplay.Objects; using Eco.Gameplay.Players; using Eco.Gameplay.Systems.Chat; using Eco.Mods.TechTree; using Eco.Shared.Math; using Eco.Shared.Networking; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Kirthos.Mods { class RubbleUtils { public static void PickUpRubble(User user, int range = 10, int qty = 20) { try { VerifyCarry(user.Inventory.Carried, user, range, qty); } catch(Exception) { } } private static void PickRubble(User user, int range, int qty) where T : RubbleObject { Type firstItemGet = null; Type itemType = null; int count = user.Inventory.Carried.Stacks.First().Quantity; if (count >= qty) return; foreach (RubbleObject obj in NetObjectManager.GetObjectsOfType()) { if (obj.IsBreakable) { continue; } if (Vector3.Distance(user.Position, obj.Position) < range) { if (firstItemGet == null) { firstItemGet = obj.GetType(); if (firstItemGet.ToString().Contains("StoneRubbleSet")) { itemType = typeof(StoneItem); } else if (firstItemGet.ToString().Contains("CoalRubbleSet")) { itemType = typeof(CoalItem); } else if (firstItemGet.ToString().Contains("CopperOreRubbleSet")) { itemType = typeof(CopperOreItem); } else if (firstItemGet.ToString().Contains("GoldOreRubbleSet")) { itemType = typeof(GoldOreItem); } else if (firstItemGet.ToString().Contains("IronOreRubbleSet")) { itemType = typeof(IronOreItem); } } if (itemType == typeof(StoneItem) && !obj.GetType().ToString().Contains("StoneRubbleSet")) { continue; } else if (itemType == typeof(CoalItem) && !obj.GetType().ToString().Contains("CoalRubbleSet")) { continue; } else if (itemType == typeof(CopperOreItem) && !obj.GetType().ToString().Contains("CopperOreRubbleSet")) { continue; } else if (itemType == typeof(GoldOreItem) && !obj.GetType().ToString().Contains("GoldOreRubbleSet")) { continue; } else if (itemType == typeof(IronOreItem) && !obj.GetType().ToString().Contains("IronOreRubbleSet")) { continue; } if (obj.AuthorizedToInteract(user)) { if (obj.TryPickup(user.Inventory).IsSuccess) { count++; if (count >= qty) break; } } } } } private static void VerifyCarry(LimitedInventory carry, User user, int range, int qty) { if (carry.IsEmpty) { PickRubble(user, range, qty); } else { Item itemCarried = carry.Stacks.First().Item; if (itemCarried is StoneItem) { PickRubble>(user, range, qty); } else if (itemCarried is CoalItem) { PickRubble>(user, range, qty); } else if (itemCarried is CopperOreItem) { PickRubble>(user, range, qty); } else if (itemCarried is GoldOreItem) { PickRubble>(user, range, qty); } else if (itemCarried is IronOreItem) { PickRubble>(user, range, qty); } } } public static void BreakBigRubble(Vector3i blockPosition, int percent) { Random rng = new Random(); if (rng.Next(100) < percent) { foreach (RubbleObject obj in NetObjectManager.GetObjectsOfType()) { if (!obj.IsBreakable) { continue; } if (Vector3.Distance(blockPosition, obj.Position) < 1) { obj.Breakup(); } } } } } }