Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Body modifiers #14

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
292a405
New modifier page
Wunarg Dec 13, 2021
9d80317
Moved old body modifiers
Wunarg Dec 13, 2021
01f9076
Lightweight modifier
Wunarg Dec 13, 2021
27d8a35
Heavyweight design modifier
Wunarg Dec 13, 2021
7d8411f
Rebalanced old commented out modifier
Wunarg Dec 13, 2021
e71d9ce
Mushroom wood modifier
Wunarg Dec 13, 2021
0fc1d0f
Floaty Modifier
Wunarg Dec 13, 2021
8187462
Heavy weight modifier now also increases gravity to increase falling …
Wunarg Dec 13, 2021
79a45e1
Floaty cost comment
Wunarg Dec 13, 2021
261e197
Merge branch 'main' into Body-Modifiers
Wunarg Dec 14, 2021
e725033
Merge branch 'main' into Body-Modifiers
Wunarg Dec 22, 2021
08520af
Merge fixes
Wunarg Dec 22, 2021
3e71d84
Merge branch 'main' into Body-Modifiers
Wunarg Feb 28, 2022
3feceb8
Updated costs and everything
Wunarg Feb 28, 2022
c15c0af
Merge branch 'main' into Body-Modifiers
Wunarg May 22, 2022
326428a
Moved Body modifiers to seperate file
Wunarg May 22, 2022
fd86f84
Fixed a duplicate modifier
Wunarg May 22, 2022
b438674
Merge branch 'main' into Body-Modifiers
Wunarg Jun 17, 2022
7b05538
Fixed
Wunarg Jun 17, 2022
f113ddd
Merge branch 'main' into Body-Modifiers
Wunarg Jun 21, 2022
641b84f
Better text
Wunarg Jun 21, 2022
93d1c9f
Merge branch 'main' into Body-Modifiers
Wunarg Oct 16, 2022
c5b4ec2
Moved Mushroom glow and updated moved
Wunarg Oct 16, 2022
196635f
Commented out floaty
Wunarg Oct 16, 2022
ef516c5
Merge branch 'main' into Body-Modifiers
Wunarg Oct 16, 2022
8878580
Merge fix
Wunarg Oct 16, 2022
185033f
Fixed merge errors (was weird)
Wunarg Oct 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 244 additions & 0 deletions Content/Data/Modifications.Body.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
using TC2.Base.Components;

namespace TC2.Base
{
public sealed partial class ModInstance
{
private static void RegisterBodyModifications(ref List<Modification.Definition> definitions)
{
definitions.Add(Modification.Definition.New<Body.Data>
(
identifier: "body.bulk",
name: "Batch Production",
description: "More efficient manufacturing process by producing multiple items in bulk.",

validate: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
ref var batch_size = ref handle.GetData<int>();
batch_size = Maths.Clamp(batch_size, 1, 10);

return true;
},

#if CLIENT
draw_editor: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
ref var batch_size = ref handle.GetData<int>();
return GUI.SliderInt("##stuff", ref batch_size, 1, 10, "%d");
},
#endif

can_add: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
return !modifications.HasModification(handle);
},

apply_1: static (ref Modification.Context context, ref Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
ref readonly var recipe_old = ref context.GetRecipeOld();
ref var recipe_new = ref context.GetRecipeNew();

ref var batch_size = ref handle.GetData<int>();

recipe_new.min *= batch_size;
recipe_new.max *= batch_size;
recipe_new.step *= batch_size;

for (int i = 0; i < context.requirements_new.Length; i++)
{
ref var requirement = ref context.requirements_new[i];

if (requirement.type == Crafting.Requirement.Type.Resource)
{
ref var material = ref requirement.material.GetDefinition();
if (material.flags.HasAll(Material.Flags.Manufactured))
{
requirement.amount *= MathF.Pow(0.99f, batch_size - 1);
}
else
{
requirement.amount *= MathF.Pow(0.98f, batch_size - 1);
}
}
else if (requirement.type == Crafting.Requirement.Type.Work)
{
switch (requirement.work)
{
case Work.Type.Machining:
{
requirement.amount *= MathF.Pow(0.95f, batch_size - 1);
}
break;

case Work.Type.Smithing:
{
requirement.amount *= MathF.Pow(0.93f, batch_size - 1);
}
break;

case Work.Type.Assembling:
{
requirement.amount *= MathF.Pow(0.90f, batch_size - 1);
}
break;

default:
{
requirement.amount *= MathF.Pow(0.95f, batch_size - 1);
}
break;
}
}
}
}
));

definitions.Add(Modification.Definition.New<Body.Data>
(
identifier: "body.efficient_crafting",
category: "Body",
name: "Efficient Crafting",
description: "Rework the design to reduce material costs slightly.",

//This modifier is nearly always an option but only with many npcs or very high skills is this actually worth while since it ramps up crafting time a ton

apply_1: static (ref Modification.Context context, ref Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
foreach (ref var requirement in context.requirements_new)
{
if (requirement.type == Crafting.Requirement.Type.Resource)
{
requirement.amount *= 0.95f;
}
else if (requirement.type == Crafting.Requirement.Type.Work)
{
requirement.amount *= 1.50f;
requirement.difficulty += 3.00f;
}
}
}
));

definitions.Add(Modification.Definition.New<Body.Data>
(
identifier: "body.lightweight_design",
category: "Body",
name: "Lightweight Design",
description: "Redesign the object to have slightly less weight but be harder to produce",

can_add: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
return !modifications.HasModification(handle);
},

apply_1: static (ref Modification.Context context, ref Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
data.mass_multiplier *= 0.80f;
data.gravity *= 0.90f;
foreach (ref var requirement in context.requirements_new)
{
if (requirement.type == Crafting.Requirement.Type.Work)
{
requirement.amount *= 1.30f;
requirement.difficulty += 2.0f;
}
}
}
));

definitions.Add(Modification.Definition.New<Body.Data>
(
identifier: "body.heavyweight_design",
category: "Body",
name: "Heavyweight Design",
description: "Redesign the object to be a lot heavier",

apply_1: static (ref Modification.Context context, ref Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
data.mass_multiplier *= 2.00f;
data.gravity *= 1.10f;
//This modifier is mostly a negative but sometimes you may want to increase the weight of an object like,
//For example you can increase the weight of your own melee weapons to make them harder to grab for your opponents
foreach (ref var requirement in context.requirements_new)
{
if (requirement.type == Crafting.Requirement.Type.Work)
{
requirement.amount *= 1.10f;
}
}
}
));

definitions.Add(Modification.Definition.New<Body.Data>
(
identifier: "body.floaty",
category: "Body",
name: "Floaty",
description: "Makes the object fall slower",

can_add: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
return !modifications.HasModification(handle);
},

apply_1: static (ref Modification.Context context, ref Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
data.gravity *= 0.20f;
//Very fun modifer which makes an object behave very floaty
//TODO: should cost motion salt or some sort of gas, current cost is temporary
foreach (ref var requirement in context.requirements_new)
{
if (requirement.type == Crafting.Requirement.Type.Work)
{
requirement.amount *= 1.30f;
}
}
context.requirements_new.Add(Crafting.Requirement.Resource("chitin", 50));
//TODO: Cost should be equal to mass but i cannot access mass right now
}
));
Wunarg marked this conversation as resolved.
Show resolved Hide resolved

definitions.Add(Modification.Definition.New<Body.Data>
(
identifier: "body.mushroom_wood",
category: "Body",
name: "Mushroom Wood",
description: "Uses mushroom scraps as a wood replacement",

//the purpose of this modifier is to add another use to mushroom scraps AND to allow people to use spare mushrooms as wood
//this modifier is likely to be more usefull once buildings can be blueprinted

can_add: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
return context.requirements_new.Has(Crafting.Requirement.Resource("wood", 0.00f)) && !modifications.HasModification(handle);
},

apply_1: static (ref Modification.Context context, ref Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
var wood_amount = 0.00f;
foreach (ref var requirement in context.requirements_new)
{
if (requirement.type == Crafting.Requirement.Type.Work)
{
requirement.amount *= 0.70f;
requirement.difficulty += 1.00f;
//Mushroom scraps are faster to process but require you to be more experienced
//This is also fine balance wise since mushroom scraps are harder to get than wood
}
else if (requirement.type == Crafting.Requirement.Type.Resource)
{
ref var material = ref requirement.material.GetDefinition();
if (material.identifier == "wood")
{
wood_amount += requirement.amount;
requirement = default;
}
}
}
context.requirements_new.Add(Crafting.Requirement.Resource("mushroom", wood_amount));
}
));
}
}
}

110 changes: 0 additions & 110 deletions content/Data/Modifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,29 +169,6 @@ private static void RegisterModifications(ref List<Modification.Definition> defi
}
));

//definitions.Add(Modification.Definition.New<Body.Data> // Can be used on any recipe which results in a prefab
//(
// identifier: "body.efficient_crafting",
// name: "Efficient Crafting",
// description: "Rework the design to reduce material costs slightly.",

// apply_1: static (ref Modification.Context context, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
// {
// foreach (ref var requirement in context.requirements_new)
// {
// if (requirement.type == Crafting.Requirement.Type.Resource)
// {
// requirement.amount *= 0.80f;
// }
// else if (requirement.type == Crafting.Requirement.Type.Work)
// {
// requirement.amount *= 1.05f;
// requirement.difficulty += 2.50f;
// }
// }
// }
//));

definitions.Add(Modification.Definition.New<Fuse.Data>
(
identifier: "fuse.length",
Expand Down Expand Up @@ -406,93 +383,6 @@ private static void RegisterModifications(ref List<Modification.Definition> defi
}
}
));

definitions.Add(Modification.Definition.New<Body.Data>
(
identifier: "body.bulk",
name: "Batch Production",
description: "More efficient manufacturing process by producing multiple items in bulk.",

validate: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
ref var batch_size = ref handle.GetData<int>();
batch_size = Maths.Clamp(batch_size, 1, 10);

return true;
},

#if CLIENT
draw_editor: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
ref var batch_size = ref handle.GetData<int>();
return GUI.SliderInt("##stuff", ref batch_size, 1, 10, "%d");
},
#endif

can_add: static (ref Modification.Context context, in Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
return !modifications.HasModification(handle);
},

apply_1: static (ref Modification.Context context, ref Body.Data data, ref Modification.Handle handle, Span<Modification.Handle> modifications) =>
{
ref readonly var recipe_old = ref context.GetRecipeOld();
ref var recipe_new = ref context.GetRecipeNew();

ref var batch_size = ref handle.GetData<int>();

recipe_new.min *= batch_size;
recipe_new.max *= batch_size;
recipe_new.step *= batch_size;

for (int i = 0; i < context.requirements_new.Length; i++)
{
ref var requirement = ref context.requirements_new[i];

if (requirement.type == Crafting.Requirement.Type.Resource)
{
ref var material = ref requirement.material.GetDefinition();
if (material.flags.HasAll(Material.Flags.Manufactured))
{
requirement.amount *= MathF.Pow(0.99f, batch_size - 1);
}
else
{
requirement.amount *= MathF.Pow(0.98f, batch_size - 1);
}
}
else if (requirement.type == Crafting.Requirement.Type.Work)
{
switch (requirement.work)
{
case Work.Type.Machining:
{
requirement.amount *= MathF.Pow(0.95f, batch_size - 1);
}
break;

case Work.Type.Smithing:
{
requirement.amount *= MathF.Pow(0.93f, batch_size - 1);
}
break;

case Work.Type.Assembling:
{
requirement.amount *= MathF.Pow(0.90f, batch_size - 1);
}
break;

default:
{
requirement.amount *= MathF.Pow(0.95f, batch_size - 1);
}
break;
}
}
}
}
));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions content/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ protected override void OnRegister(ModContext context)
Modification.OnInitialize += RegisterMeleeModifications;
Modification.OnInitialize += RegisterDrillModifications;
Modification.OnInitialize += RegisterMedkitModifications;
Modification.OnInitialize += RegisterBodyModifications;
}

protected override void OnInitialize(ModContext context)
Expand Down