Gitlab to Gitea Migration
This commit is contained in:
154
KirthosMods/Utils/RubbleUtils.cs
Normal file
154
KirthosMods/Utils/RubbleUtils.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
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<T>(User user, int range, int qty) where T : RubbleObject
|
||||
{
|
||||
Type firstItemGet = null;
|
||||
Type itemType = null;
|
||||
int count = user.Inventory.Carried.Stacks.First<ItemStack>().Quantity;
|
||||
if (count >= qty)
|
||||
return;
|
||||
foreach (RubbleObject obj in NetObjectManager.GetObjectsOfType<T>())
|
||||
{
|
||||
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<RubbleObject>(user, range, qty);
|
||||
}
|
||||
else
|
||||
{
|
||||
Item itemCarried = carry.Stacks.First<ItemStack>().Item;
|
||||
if (itemCarried is StoneItem)
|
||||
{
|
||||
PickRubble<RubbleObject<StoneItem>>(user, range, qty);
|
||||
}
|
||||
else if (itemCarried is CoalItem)
|
||||
{
|
||||
PickRubble<RubbleObject<CoalItem>>(user, range, qty);
|
||||
}
|
||||
else if (itemCarried is CopperOreItem)
|
||||
{
|
||||
PickRubble<RubbleObject<CopperOreItem>>(user, range, qty);
|
||||
}
|
||||
else if (itemCarried is GoldOreItem)
|
||||
{
|
||||
PickRubble<RubbleObject<GoldOreItem>>(user, range, qty);
|
||||
}
|
||||
else if (itemCarried is IronOreItem)
|
||||
{
|
||||
PickRubble<RubbleObject<IronOreItem>>(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<RubbleObject>())
|
||||
{
|
||||
if (!obj.IsBreakable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (Vector3.Distance(blockPosition, obj.Position) < 1)
|
||||
{
|
||||
obj.Breakup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
KirthosMods/Utils/SkillsUtil.cs
Normal file
40
KirthosMods/Utils/SkillsUtil.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Eco.Gameplay.Players;
|
||||
using Eco.Gameplay.Skills;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Kirthos.Mods
|
||||
{
|
||||
class SkillsUtil
|
||||
{
|
||||
public static bool HasSkillLevel(User user, Type skillType, int level)
|
||||
{
|
||||
foreach(Skill skill in user.Skillset.Skills)
|
||||
{
|
||||
if (skill.Type == skillType)
|
||||
{
|
||||
if (skill.Level >= level)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int GetSkillLevel(User user, Type skillType)
|
||||
{
|
||||
foreach (Skill skill in user.Skillset.Skills)
|
||||
{
|
||||
if (skill.Type == skillType)
|
||||
{
|
||||
return skill.Level;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
KirthosMods/Utils/TreeUtils.cs
Normal file
47
KirthosMods/Utils/TreeUtils.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Eco.Gameplay.Items;
|
||||
using Eco.Gameplay.Players;
|
||||
using Eco.Mods.TechTree;
|
||||
using Eco.Shared.Math;
|
||||
using Eco.World;
|
||||
using Eco.World.Blocks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Kirthos.Mods
|
||||
{
|
||||
class TreeUtils
|
||||
{
|
||||
public static void GetPulpAroundPoint(User user, Vector3i position, int range)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = -range; i < range; i++)
|
||||
{
|
||||
for (int j = -range; j < range; j++)
|
||||
{
|
||||
if (i == 0 && j == 0) continue;
|
||||
Vector3i positionAbove = World.GetTopPos(new Vector2i(position.x + i, position.z + j)) + Vector3i.Up;
|
||||
Block blockAbove = World.GetBlockProbablyTop(positionAbove);
|
||||
if (blockAbove.Is<TreeDebris>())
|
||||
{
|
||||
if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
|
||||
{
|
||||
if (user.Inventory.TryAddItems<WoodPulpItem>(5))
|
||||
{
|
||||
World.DeleteBlock(positionAbove);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user