Skip to content

Commit

Permalink
Merge pull request crashkonijn#30 from crashkonijn/release/2.1.0
Browse files Browse the repository at this point in the history
Release/2.1.0
  • Loading branch information
crashkonijn authored May 16, 2023
2 parents f83a4f9 + b81a671 commit 32c2fc0
Show file tree
Hide file tree
Showing 80 changed files with 1,043 additions and 419 deletions.
13 changes: 0 additions & 13 deletions Demo/Assets/Demos/Complex/Classes/WorldKeys.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Demo/Assets/Demos/Complex/Classes/WorldKeys.cs.meta

This file was deleted.

49 changes: 25 additions & 24 deletions Demo/Assets/Demos/Complex/Factories/Extensions/ActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
using CrashKonijn.Goap.Resolver;
using Demos.Complex.Actions;
using Demos.Complex.Behaviours;
using Demos.Complex.Classes;
using Demos.Complex.Classes.Items;
using Demos.Complex.Classes.Sources;
using Demos.Complex.Interfaces;
using Demos.Complex.Targets;
using Demos.Complex.WorldKeys;
using Demos.Shared.Actions;

namespace Demos.Complex.Factories.Extensions
Expand All @@ -16,58 +17,58 @@ public static class ActionExtensions
public static void AddWanderAction(this GoapSetBuilder builder)
{
builder.AddAction<WanderAction>()
.SetTarget(Targets.WanderTarget)
.AddEffect(WorldKeys.IsWandering, true);
.SetTarget<WanderTarget>()
.AddEffect<IsWandering>(true);
}

public static void AddPickupItemAction<T>(this GoapSetBuilder builder)
where T : IHoldable
where T : class, IHoldable
{
builder.AddAction<PickupItemAction<T>>()
.SetTarget<T>(Targets.ClosestTarget)
.AddEffect<T>(WorldKeys.IsHolding, true)
.AddCondition<T>(WorldKeys.IsInWorld, Comparison.GreaterThanOrEqual, 1);
.SetTarget<ClosestTarget<T>>()
.AddEffect<IsHolding<T>>(true)
.AddCondition<IsInWorld<T>>(Comparison.GreaterThanOrEqual, 1);
}

public static void AddGatherItemAction<TGatherable, TRequired>(this GoapSetBuilder builder)
where TGatherable : ItemBase, IGatherable
where TRequired : IHoldable
{
builder.AddAction<GatherItemAction<TGatherable>>()
.SetTarget<TGatherable>(Targets.ClosestSourceTarget)
.AddEffect<TGatherable>(WorldKeys.IsInWorld, true)
.AddCondition<TRequired>(WorldKeys.IsHolding, Comparison.GreaterThanOrEqual, 1);
.SetTarget<ClosestSourceTarget<TGatherable>>()
.AddEffect<IsInWorld<TGatherable>>(true)
.AddCondition<IsHolding<TRequired>>(Comparison.GreaterThanOrEqual, 1);
}

public static void AddGatherItemSlowAction<TGatherable>(this GoapSetBuilder builder)
where TGatherable : ItemBase, IGatherable
{
builder.AddAction<GatherItemAction<TGatherable>>()
.SetTarget<TGatherable>(Targets.ClosestSourceTarget)
.AddEffect<TGatherable>(WorldKeys.IsInWorld, true)
.SetTarget<ClosestSourceTarget<TGatherable>>()
.AddEffect<IsInWorld<TGatherable>>(true)
.SetBaseCost(3);
}

public static void AddCreateItemAction<T>(this GoapSetBuilder builder)
where T : ItemBase, ICreatable
{
var action = builder.AddAction<CreateItemAction<T>>()
.SetTarget<Anvil>(Targets.ClosestTarget)
.AddEffect<T>(WorldKeys.CreatedItem, true);
.SetTarget<ClosestTarget<Anvil>>()
.AddEffect<CreatedItem<T>>(true);

if (typeof(T) == typeof(Axe))
{
action
.AddCondition<Iron>(WorldKeys.IsHolding, Comparison.GreaterThanOrEqual, 1)
.AddCondition<Wood>(WorldKeys.IsHolding, Comparison.GreaterThanOrEqual, 2);
.AddCondition<IsHolding<Iron>>(Comparison.GreaterThanOrEqual, 1)
.AddCondition<IsHolding<Wood>>(Comparison.GreaterThanOrEqual, 2);
return;
}

if (typeof(T) == typeof(Pickaxe))
{
action
.AddCondition<Iron>(WorldKeys.IsHolding, Comparison.GreaterThanOrEqual, 2)
.AddCondition<Wood>(WorldKeys.IsHolding, Comparison.GreaterThanOrEqual, 1);
.AddCondition<IsHolding<Iron>>(Comparison.GreaterThanOrEqual, 2)
.AddCondition<IsHolding<Wood>>(Comparison.GreaterThanOrEqual, 1);
return;
}

Expand All @@ -77,17 +78,17 @@ public static void AddCreateItemAction<T>(this GoapSetBuilder builder)
public static void AddHaulItemAction(this GoapSetBuilder builder)
{
builder.AddAction<HaulItemAction>()
.SetTarget(Targets.TransformTarget)
.AddEffect(WorldKeys.ItemsOnFloor, false)
.AddCondition(WorldKeys.ItemsOnFloor, Comparison.GreaterThanOrEqual, 1);
.SetTarget<TransformTarget>()
.AddEffect<ItemsOnFloor>(false)
.AddCondition<ItemsOnFloor>(Comparison.GreaterThanOrEqual, 1);
}

public static void AddEatAction(this GoapSetBuilder builder)
{
builder.AddAction<EatAction>()
.SetTarget(Targets.TransformTarget)
.AddEffect(WorldKeys.IsHungry, false)
.AddCondition<IEatable>(WorldKeys.IsHolding, Comparison.GreaterThanOrEqual, 1);
.SetTarget<TransformTarget>()
.AddEffect<IsHungry>(false)
.AddCondition<IsHolding<IEatable>>(Comparison.GreaterThanOrEqual, 1);
}
}
}
14 changes: 7 additions & 7 deletions Demo/Assets/Demos/Complex/Factories/Extensions/GoalExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CrashKonijn.Goap.Classes.Builders;
using CrashKonijn.Goap.Resolver;
using Demos.Complex.Classes;
using Demos.Complex.Goals;
using Demos.Complex.Interfaces;
using Demos.Complex.WorldKeys;
using Demos.Shared.Goals;

namespace Demos.Complex.Factories.Extensions
Expand All @@ -12,40 +12,40 @@ public static class GoalExtensions
public static void AddWanderGoal(this GoapSetBuilder builder)
{
builder.AddGoal<WanderGoal>()
.AddCondition(WorldKeys.IsWandering, Comparison.GreaterThanOrEqual, 1);
.AddCondition<IsWandering>(Comparison.GreaterThanOrEqual, 1);
}

public static void AddCreateItemGoal<T>(this GoapSetBuilder builder)
where T : ICreatable
{
builder.AddGoal<CreateItemGoal<T>>()
.AddCondition<T>(WorldKeys.CreatedItem, Comparison.GreaterThanOrEqual, 1);
.AddCondition<CreatedItem<T>>(Comparison.GreaterThanOrEqual, 1);
}

public static void AddCleanItemsGoal(this GoapSetBuilder builder)
{
builder.AddGoal<CleanItemsGoal>()
.AddCondition(WorldKeys.ItemsOnFloor, Comparison.SmallerThanOrEqual, 0);
.AddCondition<ItemsOnFloor>(Comparison.SmallerThanOrEqual, 0);
}

public static void AddFixHungerGoal(this GoapSetBuilder builder)
{
builder.AddGoal<FixHungerGoal>()
.AddCondition(WorldKeys.IsHungry, Comparison.SmallerThanOrEqual, 0);
.AddCondition<IsHungry>(Comparison.SmallerThanOrEqual, 0);
}

public static void AddGatherItemGoal<T>(this GoapSetBuilder builder)
where T : IGatherable
{
builder.AddGoal<GatherItemGoal<T>>()
.AddCondition<T>(WorldKeys.IsInWorld, Comparison.GreaterThanOrEqual, 1);
.AddCondition<IsInWorld<T>>(Comparison.GreaterThanOrEqual, 1);
}

public static void AddPickupItemGoal<T>(this GoapSetBuilder builder)
where T : IHoldable
{
builder.AddGoal<PickupItemGoal<T>>()
.AddCondition<T>(WorldKeys.IsHolding, Comparison.GreaterThanOrEqual, 1);
.AddCondition<IsHolding<T>>(Comparison.GreaterThanOrEqual, 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Demos.Complex.Classes;
using Demos.Complex.Interfaces;
using Demos.Complex.Sensors.Target;
using Demos.Complex.Targets;
using Demos.Shared.Sensors.Target;
using Demos.Simple.Sensors.Target;
using UnityEngine;
Expand All @@ -13,34 +14,34 @@ public static class TargetSensorExtensions
public static void AddWanderTargetSensor(this GoapSetBuilder builder)
{
builder.AddTargetSensor<WanderTargetSensor>()
.SetTarget(Targets.WanderTarget);
.SetTarget<WanderTarget>();
}

public static void AddTransformTargetSensor(this GoapSetBuilder builder)
{
builder.AddTargetSensor<TransformSensor>()
.SetTarget(Targets.TransformTarget);
.SetTarget<TransformTarget>();
}

public static void AddClosestItemTargetSensor<T>(this GoapSetBuilder builder)
where T : IHoldable
where T : class, IHoldable
{
builder.AddTargetSensor<ClosestItemSensor<T>>()
.SetTarget<T>(Targets.ClosestTarget);
.SetTarget<ClosestTarget<T>>();
}

public static void AddClosestObjectTargetSensor<T>(this GoapSetBuilder builder)
where T : MonoBehaviour
{
builder.AddTargetSensor<ClosestObjectSensor<T>>()
.SetTarget<T>(Targets.ClosestTarget);
.SetTarget<ClosestTarget<T>>();
}

public static void AddClosestSourceTargetSensor<T>(this GoapSetBuilder builder)
where T : IGatherable
{
builder.AddTargetSensor<ClosestSourceSensor<T>>()
.SetTarget<T>(Targets.ClosestSourceTarget);
.SetTarget<ClosestSourceTarget<T>>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CrashKonijn.Goap.Classes.Builders;
using Demos.Complex.Classes;
using Demos.Complex.Interfaces;
using Demos.Complex.Sensors.World;
using Demos.Complex.WorldKeys;

namespace Demos.Complex.Factories.Extensions
{
Expand All @@ -11,20 +11,20 @@ public static void AddIsHoldingSensor<THoldable>(this GoapSetBuilder builder)
where THoldable : IHoldable
{
builder.AddWorldSensor<IsHoldingSensor<THoldable>>()
.SetKey<THoldable>(WorldKeys.IsHolding);
.SetKey<IsHolding<THoldable>>();
}

public static void AddIsInWorldSensor<THoldable>(this GoapSetBuilder builder)
where THoldable : IHoldable
{
builder.AddWorldSensor<IsInWorldSensor<THoldable>>()
.SetKey<THoldable>(WorldKeys.IsInWorld);
.SetKey<IsInWorld<THoldable>>();
}

public static void AddItemOnFloorSensor(this GoapSetBuilder builder)
{
builder.AddWorldSensor<ItemOnFloorSensor>()
.SetKey(WorldKeys.ItemsOnFloor);
.SetKey<ItemsOnFloor>();
}
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/Targets.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/ClosestSourceTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CrashKonijn.Goap.Behaviours;
using Demos.Complex.Interfaces;

namespace Demos.Complex.Targets
{
public class ClosestSourceTarget<TGatherable> : TargetKeyBase
where TGatherable : IGatherable
{
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/ClosestSourceTarget.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/ClosestTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using CrashKonijn.Goap.Behaviours;

namespace Demos.Complex.Targets
{
public class ClosestTarget<TObject> : TargetKeyBase
where TObject : class
{
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/ClosestTarget.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/TransformTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using CrashKonijn.Goap.Behaviours;

namespace Demos.Complex.Targets
{
public class TransformTarget : TargetKeyBase
{
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/TransformTarget.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/WanderTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using CrashKonijn.Goap.Behaviours;

namespace Demos.Complex.Targets
{
public class WanderTarget : TargetKeyBase
{
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/Targets/WanderTarget.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/WorldKeys.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Demo/Assets/Demos/Complex/WorldKeys/CreatedItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CrashKonijn.Goap.Behaviours;
using Demos.Complex.Interfaces;

namespace Demos.Complex.WorldKeys
{
public class CreatedItem<TCreatable> : WorldKeyBase
where TCreatable : ICreatable
{
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/WorldKeys/CreatedItem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Demo/Assets/Demos/Complex/WorldKeys/IsHolding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CrashKonijn.Goap.Behaviours;
using Demos.Complex.Interfaces;

namespace Demos.Complex.WorldKeys
{
public class IsHolding<THoldable> : WorldKeyBase
where THoldable : IHoldable
{
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/WorldKeys/IsHolding.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Demo/Assets/Demos/Complex/WorldKeys/IsHungry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using CrashKonijn.Goap.Behaviours;

namespace Demos.Complex.WorldKeys
{
public class IsHungry : WorldKeyBase
{
}
}
3 changes: 3 additions & 0 deletions Demo/Assets/Demos/Complex/WorldKeys/IsHungry.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32c2fc0

Please sign in to comment.