Skip to content

Commit

Permalink
draft: chaos
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Jun 21, 2024
1 parent 8afd465 commit c5e4637
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: caf8976215a2fea43905fbca9883432f, type: 3}
m_Name: GamePlayGridConfig
m_EditorClassIdentifier:
UseSeed: 0
Seed: 1292257153
GridWidthX: 6
GridWidthZ: 6
UseSeed: 1
Seed: 135631194
GridWidthX: 5
GridWidthZ: 5
AmountOfRooms: 2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
<Enemies>k__BackingField:
- Enemy: {fileID: 2514419866930457234, guid: 86a0d3ee5ff10dd4b93454ad023e838c, type: 3}
Count: 0
Count: 4
- Enemy: {fileID: 7480288689146226739, guid: 2c5efd8328b8ecd4b83cbacb8142ac3e, type: 3}
Count: 20
Count: 2
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ MonoBehaviour:
- Item: {fileID: 1402688592469580382, guid: 18fad5aa543620b449decf03a229c586, type: 3}
Count: 2
- Item: {fileID: 3783921441781814114, guid: 5924d3f50fb1bb146897ba52aa3d7a49, type: 3}
Count: 2
Count: 3
- Item: {fileID: 7560215300223784918, guid: 59f68fe0a7bd5554baaf1d43a0849f57, type: 3}
Count: 2
50 changes: 32 additions & 18 deletions aplib.net-demo/Assets/Testing/AplibTests/GameplayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ public IEnumerator RealisticGameplayCanWinTheGame()

Action mark = new(_ => Debug.Log("MARK"));
Action mark2 = new(_ => Debug.Log("MARK2"));
Tactic markT = new PrimitiveTactic(mark, _ => true);
Tactic markT2 = new PrimitiveTactic(mark2, _ => true);
Goal markGoal = new(mark.Lift(), _ => false);
Goal markGoal2 = new(mark2.Lift(), _ => false);
bool smort = true;
Expand All @@ -318,7 +320,7 @@ public IEnumerator RealisticGameplayCanWinTheGame()

Action useEquippedItemAction = new(beliefSet =>
{
Debug.Log("Using item");
// Debug.Log("Using item");
beliefSet.Inventory.Observation.ActivateItem();
});
bool hasNotYetUsedEquippedItem = true;
Expand Down Expand Up @@ -443,34 +445,46 @@ public IEnumerator RealisticGameplayCanWinTheGame()

Tactic useRagePotionIfUseful = FirstOf(guard:
beliefSet => beliefSet.DetermineEnemyToFocus(out float enemyDistance) != null
&& enemyDistance < 5
&& enemyDistance < 7
&& beliefSet.Inventory.Observation.ContainsItem<RagePotion>(),
useRagePotion);

Action aimAndHitEnemy = new(beliefSet =>
{
Transform playerRotation = beliefSet.PlayerRotation.Observation.transform;
Vector3 enemyPosition = beliefSet.DetermineEnemyToFocus(out _).transform.position;
playerRotation.transform.LookAt(enemyPosition); // Weapon viewpoint should be set to player rotation in editor
beliefSet.MeleeWeapon.Observation.UseWeapon();
});
Action aimAtEnemy = new(beliefSet =>
{
Transform playerRotation = beliefSet.PlayerRotation.Observation.transform;
Vector3 enemyPosition = beliefSet.DetermineEnemyToFocus(out _).transform.position;
playerRotation.transform.LookAt(enemyPosition); // Weapon viewpoint should be set to player rotation in editor
Debug.Log($"Aiming at enemy {Time.time}");
});
PrimitiveTactic aimAtEnemyWhenNotAimedYet = new(aimAtEnemy, beliefSet =>
{
AbstractEnemy enemyToFocus = beliefSet.DetermineEnemyToFocus(out float distance);
Transform playerTransform = beliefSet.PlayerRigidBody.Observation.transform;
if (Physics.Raycast(playerTransform.position, playerTransform.forward, out RaycastHit hitInfo, distance,
LayerMask.GetMask("PlayerSelf", "Ignore Raycast")))
Transform playerRotation = beliefSet.PlayerRotation.Observation.transform;
Ray ray = new(playerTransform.position, playerRotation.forward);
Debug.DrawRay(playerTransform.position, playerRotation.forward, Color.green); // TODO remove

if (Physics.Raycast(ray, out RaycastHit hitInfo, distance,
~LayerMask.GetMask("PlayerSelf", "Ignore Raycast")))
{
AbstractEnemy hitEnemy = hitInfo.collider.GetComponent<AbstractEnemy>();
return hitEnemy != null && hitEnemy == enemyToFocus;
var res = hitEnemy == null || hitEnemy != enemyToFocus;
// Debug.LogError($"Aiming at enemy? {!res} {Time.time}");
return res;
}
return false;
return true;
});

Action switchWeapon = new(beliefSet =>
{
beliefSet.EquipmentInventory.Observation.MoveNext();
Debug.Log($"Switch weapon! {Time.time}");
// Debug.Log($"Switch weapon! {Time.time}");
});
PrimitiveTactic equipCrossbow = new(switchWeapon,
beliefSet => beliefSet.EquipmentInventory.Observation.CurrentEquipment is MeleeWeapon);
Expand All @@ -490,31 +504,31 @@ public IEnumerator RealisticGameplayCanWinTheGame()
Action shootCrossbowAction = new(beliefSet =>
{
beliefSet.RangedWeapon.Observation.UseWeapon();
Debug.Log($"Shoot! {Time.time}");
// Debug.Log($"Shoot! {Time.time}");
});
Tactic shootEnemy = FirstOf(guard: beliefSet =>
{
AbstractEnemy enemyToFocus = beliefSet.DetermineEnemyToFocus(out float enemyDistance);
return enemyToFocus != null
&& beliefSet.AmmoCount > 0
&& enemyDistance > beliefSet.MeleeWeapon.Observation.Range
&& enemyDistance > 0 //beliefSet.MeleeWeapon.Observation.Range
&& (enemyToFocus is RangedEnemy || enemyToFocus is MeleeEnemy && beliefSet.AmmoCount > 3);
}, equipCrossbow, aimAtEnemyWhenNotAimedYet, approachEnemyToShoot, shootCrossbowAction.Lift());
}, equipCrossbow, aimAtEnemyWhenNotAimedYet, markT, approachEnemyToShoot, shootCrossbowAction.Lift());

Action swingBat = new(beliefSet =>
{
beliefSet.MeleeWeapon.Observation.UseWeapon();
Debug.Log($"Swing! {Time.time}");
// Debug.Log($"Swing! {Time.time}");
});
PrimitiveTactic approachEnemyToMelee = new(approachEnemyAction, beliefSet =>
{
_ = beliefSet.DetermineEnemyToFocus(out float distance);
return distance > beliefSet.MeleeWeapon.Observation.Range;
});

Tactic hitEnemy = FirstOf(equipBat, aimAtEnemyWhenNotAimedYet, approachEnemyToMelee, swingBat.Lift()); // TODO first equip bat
Tactic hitEnemy = FirstOf(equipBat, /*aimAtEnemyWhenNotAimedYet,*/ approachEnemyToMelee, aimAndHitEnemy.Lift() /*swingBat.Lift()*/);

Tactic reactToEnemyTactic = FirstOf(fetchPotionIfDistancedMelee, dodgeCrossbow, fetchAmmo, useRagePotionIfUseful, shootEnemy, hitEnemy);
Tactic reactToEnemyTactic = FirstOf(fetchPotionIfDistancedMelee, dodgeCrossbow, fetchAmmo, useRagePotionIfUseful, /*shootEnemy,*/ hitEnemy);
GoalStructure reactToEnemy = new Goal(reactToEnemyTactic, beliefSet => !beliefSet.AnyEnemyVisible);


Expand All @@ -526,12 +540,12 @@ public IEnumerator RealisticGameplayCanWinTheGame()
sideGoals: new (IGoalStructure, InterruptGuard)[]
{
// But, when an item can be picked up, do so
(fetchVisibleItemGoal, beliefSet =>
beliefSet.AnyItemIsVisible),
// (fetchVisibleItemGoal, beliefSet =>
// beliefSet.AnyItemIsVisible),

// But, when an enemy is visible, react to it
(reactToEnemy, beliefSet =>
beliefSet.AnyEnemyVisible),
// (reactToEnemy, beliefSet =>
// beliefSet.AnyEnemyVisible),

// But, when low on health and in possession of a healing potion, drink the potion
(restoreHealth, beliefSet =>
Expand Down

0 comments on commit c5e4637

Please sign in to comment.