Skip to content

Commit

Permalink
1.1.62.918
Browse files Browse the repository at this point in the history
  • Loading branch information
SphereII committed Dec 1, 2024
1 parent 646bca9 commit 89b552c
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 126 deletions.
1 change: 1 addition & 0 deletions Mods/0-SCore/0-SCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<Compile Include="Harmony\ItemActions\DurabilityAffectsDamage.cs" />
<Compile Include="Harmony\ItemActions\ItemActionHandleBreakItem.cs" />
<Compile Include="Harmony\ItemActions\ItemActionMelee.cs" />
<Compile Include="Harmony\ItemActions\ItemActionRepairLimiter.cs" />
<Compile Include="Harmony\ItemActions\ItemClass.cs" />
<Compile Include="Harmony\Menu_ClearCache.cs" />
<Compile Include="Harmony\MiniTurret\shouldIgnoreTarget.cs" />
Expand Down
3 changes: 2 additions & 1 deletion Mods/0-SCore/Config/Localization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,5 @@ challengeObjectiveWearTags,"Wear with tag(s) "
challengeObjectiveGatherTags,"Gather items with the tag(s)"
challengeObjectiveOnCVar,"Get CVar"
challengeObjectiveOnBlockUpgrade,"Upgrade Block"
challengeObjectiveCraftWithTags,"Craft with tags"
challengeObjectiveCraftWithTags,"Craft with tags"
repair_limit_reached,"Repair Reached For This Item."
2 changes: 1 addition & 1 deletion Mods/0-SCore/Features/Caves/Scripts/SCoreCavesUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using UnityEngine;
using System;
using System.Collections.Generic;
Expand Down
77 changes: 77 additions & 0 deletions Mods/0-SCore/Harmony/ItemActions/ItemActionRepairLimiter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using HarmonyLib;
using UnityEngine;

namespace Harmony.ItemActions {
public class ItemActionRepairLimiter {
private static int _limitRepairProperty = -1;

private static int GetRepairLimit(ItemValue itemValue) {
if (!itemValue.ItemClass.Properties.Contains("RepairLimit")) return -1;

// Check if RepairLimit is an array or not, and if so, expect a value for each quality level.
var repairLimitValue = itemValue.ItemClass.Properties.GetStringValue("RepairLimit");
if ( repairLimitValue.Contains(','))
{
var quality = itemValue.Quality;
var index = 0;
if (quality > 0)
index = quality - 1;
if (repairLimitValue.Length >= index)
{
return int.Parse(repairLimitValue.Split(',')[index]);
}
Log.Out($"Item {itemValue.ItemClass.GetItemName()}: Invalid repair limit: {repairLimitValue} for Quality Level {quality}");
return -1;
}

if (StringParsers.TryParseSInt32(repairLimitValue, out var result))
return result;
return -1;
}
private static int GetCurrentMetaData(ItemValue itemValue, string key) {
var valueObj = itemValue.GetMetadata(key);
if (valueObj is int obj) return obj;
return 0;
}
private static int GetCurrentRepairLimit(XUiC_ItemStack stack) {
if (stack.ItemStack == null || stack.ItemStack.IsEmpty()) return -1;
var itemValue = stack.ItemStack.itemValue;
if ( itemValue == null ) return -1;

// Look for the property on the item.
if (!itemValue.ItemClass.Properties.Contains("RepairLimit")) return -1;
return GetCurrentMetaData(itemValue, "CurrentRepairLimit");
}

[HarmonyPatch(typeof(ItemActionEntryRepair))]
[HarmonyPatch("OnActivated")]
public class ItemActionRepairLimiterItemActionEntryRepair {
public static bool Prefix(ItemActionEntryRepair __instance) {
// Don't bother checking empty stacks
var xui = __instance.ItemController.xui;
var stack = (XUiC_ItemStack)__instance.ItemController;
// If it's -1, then it doesn't have a repair limit.
var currentRepair = GetCurrentRepairLimit(stack);
if (currentRepair == -1) return true;

// Look for the property on the item, checking for quality.
var itemValue = stack.ItemStack.itemValue;
var repairLimit = GetRepairLimit(itemValue);

if ( repairLimit == -1) return true;
QuestEventManager.Current.RepairItem += RepairItem;
if (currentRepair < repairLimit) return true;
GameManager.ShowTooltip(xui.playerUI.entityPlayer, Localization.Get("repair_limit_reached"));
return false;

}

private static void RepairItem(ItemValue itemValue) {
var currentRepair = GetCurrentMetaData(itemValue, "CurrentRepairLimit");
currentRepair++;
itemValue.SetMetadata("CurrentRepairLimit", currentRepair, TypedMetadataValue.TypeTag.Integer);
QuestEventManager.Current.RepairItem -= RepairItem;
}
}
}
}
2 changes: 1 addition & 1 deletion Mods/0-SCore/ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<Description value="SCore Mod" />
<DisplayName value="0-SCore" />
<Website value="" />
<Version value="1.1.54.933" />
<Version value="1.1.62.918" />
</xml>
4 changes: 2 additions & 2 deletions Mods/0-SCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
// [assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("20.0.*")]

[assembly: AssemblyVersion("1.1.54.0933")]
[assembly: AssemblyFileVersion("1.1.54.0933")]
[assembly: AssemblyVersion("1.1.62.0918")]
[assembly: AssemblyFileVersion("1.1.62.0918")]
22 changes: 21 additions & 1 deletion Mods/0-SCore/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,28 @@ Direct Download to the 0-SCore.zip available on gitlab mirror: https://github.co
### Change Logs

[ Change Log ]
Version: 1.1.54.933
Version: 1.1.62.918
[ Repair Counter ]
- Added a new Harmony patch to monitor how often an item can be repaired, before blocking the repair.
- This only works on Items, repaired through ItemActionEntryRepair.
- Two formats are supported:
- Comma delimited value. This will allow you to adjust max repairs based on quality
- For non-quality items, or to simplify, a single value can be used for all teirs.

<append xpath="/items/item[@name='meleeToolRepairT0StoneAxe']">
<!-- The first value is quality 1. The last value is quality 6 -->
<property name="RepairLimit" value="1,2,3,4,5,6" />
</append>

<append xpath="/items/item[@name='meleeToolRepairT0TazasStoneAxe']">
<property name="RepairLimit" value="5" />
</append>
- Localization Key is: repair_limit_reached

[ Block Spawn Cube 2SDX ]
- Adjusted the code again to try to spawn just a single entity.

Version: 1.1.54.933
[ Fire Manager ]
- Fixed the laws of physics or whatever laws there are that govern how fire spreads.
- Fire now spreads.
Expand Down
Binary file modified Mods/0-SCore/SCore.dll
Binary file not shown.
Binary file modified Mods/0-SCore/SCore.pdb
Binary file not shown.
96 changes: 48 additions & 48 deletions Mods/0-SCore/Scripts/Blocks/BlockSpawnCube2SDX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,48 @@ public override void OnBlockAdded(WorldBase _world, Chunk _chunk, Vector3i _bloc
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer) return;
if (GameManager.Instance.IsEditMode()) return;

var entityId = -1;
var text = PathingCubeParser.GetValue(_signText, "ec");
if (string.IsNullOrEmpty(text))
{
var group = PathingCubeParser.GetValue(_signText, "eg");
if (string.IsNullOrEmpty(group))
{
if (string.IsNullOrEmpty(_entityGroup))
return;
group = _entityGroup;
}
var ClassID = 0;
entityId = EntityGroups.GetRandomFromGroup(group, ref ClassID);
if (entityId == 0) // Invalid group.
return;
}
else
{
entityId = text.GetHashCode();
}

// Match the rotation, and create the stub for the entity
var entityCreationData = new EntityCreationData();
entityCreationData.id = -1;
entityCreationData.entityClass = entityId;
entityCreationData.pos = _blockPos.ToVector3() + new Vector3(0.5f, 0.25f, 0.5f);

// We need to check if this is a block entity or not, and match the rotation of the entity to the block, in case its a model preview.
var rotation = new Vector3(0f, (float)(45f * (_blockValue.rotation & 3)), 0f);
var blockEntity = _chunk.GetBlockEntity(_blockPos);
if (blockEntity != null && blockEntity.bHasTransform)
rotation = blockEntity.transform.rotation.eulerAngles;

entityCreationData.rot = rotation;
_chunk.AddEntityStub(entityCreationData);

// We'll use the Meta value as the spawn counter.
_blockValue.meta = 1;
GameManager.Instance.World.SetBlockRPC(_blockPos, _blockValue);
// var entityId = -1;
// var text = PathingCubeParser.GetValue(_signText, "ec");
// if (string.IsNullOrEmpty(text))
// {
// var group = PathingCubeParser.GetValue(_signText, "eg");
// if (string.IsNullOrEmpty(group))
// {
// if (string.IsNullOrEmpty(_entityGroup))
// return;
// group = _entityGroup;
// }
// var ClassID = 0;
// entityId = EntityGroups.GetRandomFromGroup(group, ref ClassID);
// if (entityId == 0) // Invalid group.
// return;
// }
// else
// {
// entityId = text.GetHashCode();
// }
//
// // Match the rotation, and create the stub for the entity
// var entityCreationData = new EntityCreationData();
// entityCreationData.id = -1;
// entityCreationData.entityClass = entityId;
// entityCreationData.pos = _blockPos.ToVector3() + new Vector3(0.5f, 0.25f, 0.5f);
//
// // We need to check if this is a block entity or not, and match the rotation of the entity to the block, in case its a model preview.
// var rotation = new Vector3(0f, (float)(45f * (_blockValue.rotation & 3)), 0f);
// var blockEntity = _chunk.GetBlockEntity(_blockPos);
// if (blockEntity != null && blockEntity.bHasTransform)
// rotation = blockEntity.transform.rotation.eulerAngles;
//
// entityCreationData.rot = rotation;
// _chunk.AddEntityStub(entityCreationData);
//
// // We'll use the Meta value as the spawn counter.
// _blockValue.meta = 1;
// GameManager.Instance.World.SetBlockRPC(_blockPos, _blockValue);

// Set up the tick delay to be pretty short, as we'll just destroy the block anyway.
if ( _maxSpawned > 0)
//if ( _maxSpawned > 0)
_world.GetWBT().AddScheduledBlockUpdate(0, _blockPos, blockID, (ulong)1UL);
}

Expand Down Expand Up @@ -153,12 +153,12 @@ public override bool UpdateTick(WorldBase _world, int _clrIdx, Vector3i _blockPo
{
size = multiBlockPos.dim;
}
if (GameManager.Instance.World
.GetEntitiesInBounds(null, new Bounds(_blockPos.ToVector3(), size)).Count > _maxSpawned)
{
DestroySelf(_blockPos, _blockValue);
return false;
}
// if (GameManager.Instance.World
// .GetEntitiesInBounds(null, new Bounds(_blockPos.ToVector3(), size)).Count > _maxSpawned)
// {
// DestroySelf(_blockPos, _blockValue);
// return false;
// }
if (_blockValue.meta >= _maxSpawned)
{
DestroySelf(_blockPos, _blockValue);
Expand Down Expand Up @@ -225,11 +225,11 @@ public override bool UpdateTick(WorldBase _world, int _clrIdx, Vector3i _blockPo
var entity = EntityFactory.CreateEntity(entityId, transformPos, rotation) as EntityAlive;
if (entity == null)
{
Log.Out($"No entity created: {_signText}");
// Log.Out($"No entity created: {_signText}");
return false;
}
entity.SetSpawnerSource(EnumSpawnerSource.StaticSpawner);
Debug.Log($"Spawning: {entity.entityId} :: {_blockPos}");
// Debug.Log($"Spawning: {entity.entityId} :: {_blockPos}");
GameManager.Instance.World.SpawnEntityInWorld(entity);

ApplySignData(entity, _blockPos);
Expand Down
82 changes: 11 additions & 71 deletions Mods/SphereII Winter Project/Harmony/PrefabInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ public class SphereII_WinterProject

public static string modFolder;

public class SphereIIWinterProjectInit : IModApi
{
public class SphereIIWinterProjectInit : IModApi {
private GlobalSnow _globalSnow;
private EntityPlayerLocal _player;

public void InitMod(Mod _modInstance)
{
public void InitMod(Mod _modInstance) {
Log.Out(" Loading Patch: " + GetType());

// Reduce extra logging stuff
Expand All @@ -41,101 +39,43 @@ public void InitMod(Mod _modInstance)
RegisterEvents();

}

// [HarmonyPatch(typeof(global::EntityAlive))]
// [HarmonyPatch("playStepSound")]
// public class EntityAliveplayStepSound
// {
// private static EntityPlayerLocal _player;
//
// public static void Postfix(global::EntityAlive __instance)
// {
// if (__instance is EntityPlayerLocal) return;
// var snow = GlobalSnow.instance;
// if (snow == null) return;
//
// //var position = __instance.transform.InverseTransformDirection(__instance.position);
//
//
// if ( _player == null )
// _player = GameManager.Instance.World.GetPrimaryPlayer();
//
// var position = _player.playerCamera.transform.InverseTransformPoint(__instance.position);
// Debug.Log($"Setting Footprint at :{position} towards: {__instance.moveDirection}");
// snow.FootprintAt(position, __instance.moveDirection);
//
// }
// }


private void RegisterEvents()
{

private void RegisterEvents() {
ModEvents.GameUpdate.RegisterHandler(UpdateSnow);
}

private void InitGlobalSnow()
{
private void InitGlobalSnow() {
_player = GameManager.Instance.World.GetPrimaryPlayer();

// Asset Bundles are defined in GlobalSnow.ReadFromModlet(), triggered from GlobalSnow.LoadResources.
_globalSnow = _player.playerCamera.gameObject.GetOrAddComponent<GlobalSnow>();

// Let the game handle the snow particles
_globalSnow.snowfall = true;

_globalSnow.snowAmount = 1f;

// Let the game handle its own frost
_globalSnow.cameraFrost = false;

// cover the ground a bit more.
_globalSnow.groundCoverage = 0.45f;
_globalSnow.groundCoverage = 0.50f;

_globalSnow.slopeThreshold = 0.9f;

// Foot prints will only appear at a certain depth of snow amount.
_globalSnow.footprints = true;
_globalSnow.groundCheck = GROUND_CHECK.CharacterController;
_globalSnow.characterController = _player.RootTransform.GetComponent<CharacterController>();

}

private void UpdateSnow()
{
private void UpdateSnow() {
if (_globalSnow == null)
InitGlobalSnow();

// if (_globalSnow == null) return;
//
// // Give a bonus if we are in a snowy area, so we can layer everything in a fine dust.
// if (_player.biomeStandingOn?.m_SpectrumName == "snow")
// _globalSnow.snowAmount += 0.5f;

}

// [HarmonyPatch(typeof(GameManager))]
// [HarmonyPatch("PlayerSpawnedInWorld")]
// public class CloneCameraPlayer
// {
// public static void Postfix()
// {
// var entityPlayer = GameManager.Instance.World.GetPrimaryPlayer();
// if (entityPlayer == null) return;
// var settings = entityPlayer.playerCamera.gameObject.GetOrAddComponent<GlobalSnow>();
// settings.snowAmount = 0.70f;
// settings.cameraFrost = false;
// settings.groundCoverage = 0.45f;
// //settings.footprints = true;
//
// //settings.groundCheck = GROUND_CHECK.RayCast;
// //settings.characterController = entityPlayer.PhysicsTransform.GetComponent<CharacterController>();
// //settings.footprintsObscurance = 0.3f;
// //settings.footprintsScale = 10;
//
//
//
// }
// }
}

[HarmonyPatch(typeof(DynamicPrefabDecorator))]
Expand Down
Loading

0 comments on commit 89b552c

Please sign in to comment.