From 35ed59b247a258417532994dcbdb4b0a5d1a2396 Mon Sep 17 00:00:00 2001 From: kabix09 Date: Wed, 4 Jan 2023 21:23:02 +0100 Subject: [PATCH] Thugs - behaviour fix Use pathfinding algorithm --- .../BossThug/ENG/BossThugDialPl.asset | 12 +- Assets/Resources/Enemies/Bat_0.prefab | 3 +- Assets/Resources/Mission/BarryBeer.meta | 8 + .../Mission/BarryBeer/BarryBeerDial.asset | 30 ++ .../BarryBeer/BarryBeerDial.asset.meta | 8 + .../Mission/BarryBeer/BarryBeerMission.asset | 38 ++ .../BarryBeer/BarryBeerMission.asset.meta | 8 + .../SampleScene/Enemies/BossThug.prefab | 11 +- .../Resources/SampleScene/Enemies/Thug.prefab | 85 ++-- .../SampleScene/Enemies/Thug.prefab.meta | 2 +- .../SampleScene/Enemies/Thug_old.prefab | 221 +++++++++++ .../SampleScene/Enemies/Thug_old.prefab.meta | 7 + .../Scripts/Enemies' Scprits/Cave/BossThug.cs | 4 +- Assets/Scripts/Enemies' Scprits/Enemy.cs | 8 + .../Enemies' Scprits/FollowingEnemy.cs | 9 +- .../FollowingPatrollingEnemy.cs | 9 - Assets/Scripts/NPCs' Scripts/NPCFollowing.cs | 4 + Assets/Scripts/Player.cs | 4 +- .../UI/Panel/ChestPanelController.cs | 8 +- Assets/Scripts/REFACTORING/Story/Thugs.meta | 8 + .../Story/Thugs/ThugNPCFollowing.cs | 367 ++++++++++++++++++ .../Story/Thugs/ThugNPCFollowing.cs.meta | 11 + Assets/Scripts/SceneManager/NPC/NPCManager.cs | 16 +- .../SceneManager/SaveDynamicObjects.cs | 4 +- 24 files changed, 817 insertions(+), 68 deletions(-) create mode 100644 Assets/Resources/Mission/BarryBeer.meta create mode 100644 Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset create mode 100644 Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset.meta create mode 100644 Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset create mode 100644 Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset.meta create mode 100644 Assets/Resources/SampleScene/Enemies/Thug_old.prefab create mode 100644 Assets/Resources/SampleScene/Enemies/Thug_old.prefab.meta create mode 100644 Assets/Scripts/REFACTORING/Story/Thugs.meta create mode 100644 Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs create mode 100644 Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs.meta diff --git a/Assets/Resources/Dialogue/BossThug/ENG/BossThugDialPl.asset b/Assets/Resources/Dialogue/BossThug/ENG/BossThugDialPl.asset index fd2244bd..3002d312 100644 --- a/Assets/Resources/Dialogue/BossThug/ENG/BossThugDialPl.asset +++ b/Assets/Resources/Dialogue/BossThug/ENG/BossThugDialPl.asset @@ -12,10 +12,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 06201cadd951bcc4db5fccaa01783060, type: 3} m_Name: BossThugDialPl m_EditorClassIdentifier: - SpeakerName: Boss Thug + SpeakerName: CurrentStep: 0 DialogueSteps: - - Header: Boss Thug + - Header: WasDisplayed: 0 ListOfSentences: - Sentence: Who are you? How did you get past my guards?! @@ -25,10 +25,10 @@ MonoBehaviour: EndOfDialogueStepAction: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 5598884596044988526, guid: df6c42c9616028a4badca81953f003ab, type: 3} - m_TargetAssemblyTypeName: NpcDialogueManager, Assembly-CSharp - m_MethodName: DialogueEndAction - m_Mode: 3 + - m_Target: {fileID: 0} + m_TargetAssemblyTypeName: BossThug, Assembly-CSharp + m_MethodName: ChanegStatusToAttack + m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine diff --git a/Assets/Resources/Enemies/Bat_0.prefab b/Assets/Resources/Enemies/Bat_0.prefab index fd7c3bb5..959886fd 100644 --- a/Assets/Resources/Enemies/Bat_0.prefab +++ b/Assets/Resources/Enemies/Bat_0.prefab @@ -176,6 +176,7 @@ MonoBehaviour: worldPosition: {x: 0, y: 0, z: 0} gridPosition: {x: 0, y: 0} isChasing: 0 + point: {x: 0, y: 0, z: 0} path: [] --- !u!114 &8184504007427166055 MonoBehaviour: @@ -194,6 +195,7 @@ MonoBehaviour: maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} health: 3 baseAttack: 1 + isKilled: 0 MinionName: Bat path: - {fileID: 0} @@ -213,6 +215,5 @@ MonoBehaviour: player: {fileID: 0} thrust: 5 knockTime: 0.2 - isKilled: 0 isKilled2: 0 expValue: 3 diff --git a/Assets/Resources/Mission/BarryBeer.meta b/Assets/Resources/Mission/BarryBeer.meta new file mode 100644 index 00000000..8b2095cf --- /dev/null +++ b/Assets/Resources/Mission/BarryBeer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bc0268700130f734d90d95939a9bba39 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset b/Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset new file mode 100644 index 00000000..e3f213e3 --- /dev/null +++ b/Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset @@ -0,0 +1,30 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67587597537a4344cad65ddbcebee119, type: 3} + m_Name: BarryBeerDial + m_EditorClassIdentifier: + SpeakerName: + CurrentStep: 0 + DialogueSteps: + - Header: + WasDisplayed: 0 + ListOfSentences: + - Sentence: Hiya, do you have any spare change? Friend? + Buttons: + - ButtonName: + Type: 0 + ButtonActions: + m_PersistentCalls: + m_Calls: [] + EndOfDialogueStepAction: + m_PersistentCalls: + m_Calls: [] diff --git a/Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset.meta b/Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset.meta new file mode 100644 index 00000000..0aabb8a3 --- /dev/null +++ b/Assets/Resources/Mission/BarryBeer/BarryBeerDial.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e4c21abf72e85a942a0f511315399465 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset b/Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset new file mode 100644 index 00000000..d4a12a8f --- /dev/null +++ b/Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset @@ -0,0 +1,38 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0a3bcdd1e2dba0c4791bcb151c0df6c1, type: 3} + m_Name: BarryBeerMission + m_EditorClassIdentifier: + MissionName: Barry Beer + PlayerTask: + id: 0 + title: Barry Beer + description: Get a beer for Barry and drink with him + difficulty: 0 + SpeakerName: + Status: 0 + CurrentStep: 0 + MissionStepsList: + - SpeakerName: + Status: 0 + DialogueStep: {fileID: 0} + MissionConditions: + Key: 0 + Value: + - Type: 0 + RequiredElements: + - RequiredAmount: 1 + RequiredObject: {fileID: 1684616857099464412, guid: 287d729bd2e4f6941bb93348574335b4, type: 3} + Reward: + Items: + - {fileID: 11400000, guid: 5018db07efd330846ab41d3ed70a3c08, type: 2} + Cash: 0 diff --git a/Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset.meta b/Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset.meta new file mode 100644 index 00000000..258276c3 --- /dev/null +++ b/Assets/Resources/Mission/BarryBeer/BarryBeerMission.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5a7c76db7c9c6874aa6cd13edd553c9a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/SampleScene/Enemies/BossThug.prefab b/Assets/Resources/SampleScene/Enemies/BossThug.prefab index 48e0a8e2..b43075a8 100644 --- a/Assets/Resources/SampleScene/Enemies/BossThug.prefab +++ b/Assets/Resources/SampleScene/Enemies/BossThug.prefab @@ -36,6 +36,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -2.5, y: 75, z: 10} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 @@ -51,6 +52,7 @@ SpriteRenderer: m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -171,6 +173,8 @@ MonoBehaviour: maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} health: 0 baseAttack: 1000 + isKilled: 0 + MinionName: target: {fileID: 0} chaseRadius: 7 attackRadius: 0.4 @@ -189,7 +193,6 @@ MonoBehaviour: player: {fileID: 0} thrust: 5 knockTime: 0.2 - isKilled: 0 isKilled2: 0 isPanelEnabled: 0 expValue: 0 @@ -215,7 +218,7 @@ MonoBehaviour: state: 0 --- !u!95 &-4365747932373452915 Animator: - serializedVersion: 3 + serializedVersion: 4 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} @@ -228,6 +231,7 @@ Animator: m_UpdateMode: 0 m_ApplyRootMotion: 0 m_LinearVelocityBlending: 0 + m_StabilizeFeet: 0 m_WarningMessage: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 @@ -252,6 +256,7 @@ MonoBehaviour: worldPosition: {x: 0, y: 0, z: 0} gridPosition: {x: 0, y: 0} isChasing: 0 + point: {x: 0, y: 0, z: 0} path: [] --- !u!114 &5598884596044988526 MonoBehaviour: @@ -307,5 +312,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a13ccc76cd22a814287fc3a36a9cac71, type: 3} m_Name: m_EditorClassIdentifier: - Name: + Name: BossThug State: 1 diff --git a/Assets/Resources/SampleScene/Enemies/Thug.prefab b/Assets/Resources/SampleScene/Enemies/Thug.prefab index ab57da3d..20c4edc4 100644 --- a/Assets/Resources/SampleScene/Enemies/Thug.prefab +++ b/Assets/Resources/SampleScene/Enemies/Thug.prefab @@ -14,7 +14,9 @@ GameObject: - component: {fileID: 4006076606190978597} - component: {fileID: 4006076606190978598} - component: {fileID: -5618304694998678869} - - component: {fileID: 4740118962389386185} + - component: {fileID: 473894148038517128} + - component: {fileID: 2516116800883374971} + - component: {fileID: 1447307453897843019} m_Layer: 0 m_Name: Thug m_TagString: Enemy @@ -32,6 +34,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 3.6720886, z: 10} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 @@ -47,6 +50,7 @@ SpriteRenderer: m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -136,7 +140,7 @@ BoxCollider2D: m_EdgeRadius: 0 --- !u!95 &4006076606190978598 Animator: - serializedVersion: 3 + serializedVersion: 4 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} @@ -149,6 +153,7 @@ Animator: m_UpdateMode: 0 m_ApplyRootMotion: 0 m_LinearVelocityBlending: 0 + m_StabilizeFeet: 0 m_WarningMessage: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 @@ -173,8 +178,9 @@ MonoBehaviour: worldPosition: {x: 0, y: 0, z: 0} gridPosition: {x: 0, y: 0} isChasing: 0 + point: {x: 0, y: 0, z: 0} path: [] ---- !u!114 &4740118962389386185 +--- !u!114 &473894148038517128 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -183,34 +189,59 @@ MonoBehaviour: m_GameObject: {fileID: 4006076606190978600} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 88d05133b4682194e90a88b0f3c16b70, type: 3} + m_Script: {fileID: 11500000, guid: a13ccc76cd22a814287fc3a36a9cac71, type: 3} + m_Name: + m_EditorClassIdentifier: + Name: + State: 1 +--- !u!114 &2516116800883374971 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 87a548368fe86f949bd65a67abfc3597, type: 3} + m_Name: + m_EditorClassIdentifier: + anim: {fileID: 4006076606190978598} + homePosition: {x: 0, y: 0, z: 0} + targetPosition: {fileID: 0} + agent: {fileID: 0} + isDuringFollowing: 0 + approaching: 0 + isAfterAction: 0 + chasingRadius: 6 + attackingRadius: 1.5 + hit: 0 + firstAttack: 0 + timerDmg: 0 + waitTime: 1 + timerHit: 0 + hitWaitTime: 0.55 + expValue: 0 + thrust: 0 + knockTime: 0 + isKilled2: 0 + isPanelEnabled: 1 +--- !u!114 &1447307453897843019 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a932b573f4bb557488543fea26124646, type: 3} m_Name: m_EditorClassIdentifier: moveSpeed: 2 enemyName: maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} health: 0 - baseAttack: 1 - target: {fileID: 4869648843286970699, guid: 4cb7163e44af59f4c9350005c199db3c, type: 3} - chaseRadius: 6 - attackRadius: 1 - homePosition: {fileID: 0} - speed: 2 - shouldRotate: 0 - dir: {x: 0, y: 0, z: 0} - whatisplayer: - serializedVersion: 2 - m_Bits: 0 - roundingDistance: 0 - anim: {fileID: 4006076606190978598} - other: {fileID: 0} - inRange: 0 - hit: 0 - player: {fileID: 4869648843286970700, guid: 4cb7163e44af59f4c9350005c199db3c, type: 3} - thrust: 0 - knockTime: 0 + baseAttack: 3.5 isKilled: 0 - isKilled2: 0 - isPanelEnabled: 1 - expValue: 2 - agent: {fileID: -5618304694998678869} + MinionName: diff --git a/Assets/Resources/SampleScene/Enemies/Thug.prefab.meta b/Assets/Resources/SampleScene/Enemies/Thug.prefab.meta index 8b3e57d4..fab0f8b1 100644 --- a/Assets/Resources/SampleScene/Enemies/Thug.prefab.meta +++ b/Assets/Resources/SampleScene/Enemies/Thug.prefab.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 849497c469efda3439ba1aba850fd8ea +guid: a8a6029f92cd668408041f9f76834c4f PrefabImporter: externalObjects: {} userData: diff --git a/Assets/Resources/SampleScene/Enemies/Thug_old.prefab b/Assets/Resources/SampleScene/Enemies/Thug_old.prefab new file mode 100644 index 00000000..cca02ae0 --- /dev/null +++ b/Assets/Resources/SampleScene/Enemies/Thug_old.prefab @@ -0,0 +1,221 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4006076606190978600 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4006076606190978603} + - component: {fileID: 4006076606190978602} + - component: {fileID: 4006076606190978596} + - component: {fileID: 4006076606190978597} + - component: {fileID: 4006076606190978598} + - component: {fileID: -5618304694998678869} + - component: {fileID: 4740118962389386185} + m_Layer: 0 + m_Name: Thug_old + m_TagString: Enemy + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4006076606190978603 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 3.6720886, z: 10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &4006076606190978602 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 3 + m_Sprite: {fileID: -5218287967814079876, guid: 784e15dc3223c6342bbbc79cb202ad71, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1.0625, y: 1.75} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!50 &4006076606190978596 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 1 + m_AngularDrag: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 4 +--- !u!61 &4006076606190978597 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: -0.44218445} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1.0625, y: 1.75} + newSize: {x: 1.0625, y: 1.75} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1.0625, y: 0.7334442} + m_EdgeRadius: 0 +--- !u!95 &4006076606190978598 +Animator: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_Enabled: 1 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 9100000, guid: d3ee7fa12d1293d4f86d1a73da19c0b8, type: 2} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_StabilizeFeet: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorControllerStateOnDisable: 0 +--- !u!114 &-5618304694998678869 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d622984048644f87804ad1a3f20aa23a, type: 3} + m_Name: + m_EditorClassIdentifier: + speed: 2 + currentPosition: + GCost: 0 + hCost: 0 + walkable: 0 + worldPosition: {x: 0, y: 0, z: 0} + gridPosition: {x: 0, y: 0} + isChasing: 0 + point: {x: 0, y: 0, z: 0} + path: [] +--- !u!114 &4740118962389386185 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4006076606190978600} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 88d05133b4682194e90a88b0f3c16b70, type: 3} + m_Name: + m_EditorClassIdentifier: + moveSpeed: 2 + enemyName: + maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} + health: 0 + baseAttack: 1 + isKilled: 0 + MinionName: + target: {fileID: 4869648843286970699, guid: 4cb7163e44af59f4c9350005c199db3c, type: 3} + chaseRadius: 6 + attackRadius: 1 + homePosition: {fileID: 0} + speed: 2 + shouldRotate: 0 + dir: {x: 0, y: 0, z: 0} + whatisplayer: + serializedVersion: 2 + m_Bits: 0 + roundingDistance: 0 + anim: {fileID: 4006076606190978598} + other: {fileID: 0} + inRange: 0 + hit: 0 + player: {fileID: 4869648843286970700, guid: 4cb7163e44af59f4c9350005c199db3c, type: 3} + thrust: 0 + knockTime: 0 + isKilled2: 0 + isPanelEnabled: 1 + expValue: 2 + agent: {fileID: -5618304694998678869} diff --git a/Assets/Resources/SampleScene/Enemies/Thug_old.prefab.meta b/Assets/Resources/SampleScene/Enemies/Thug_old.prefab.meta new file mode 100644 index 00000000..8b3e57d4 --- /dev/null +++ b/Assets/Resources/SampleScene/Enemies/Thug_old.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 849497c469efda3439ba1aba850fd8ea +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs b/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs index 9945c3d5..8bf3d30f 100644 --- a/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs +++ b/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs @@ -52,8 +52,8 @@ public class BossThug : MonoBehaviour void Update() { if ( - (npc1.GetComponent().health <= 0 && npc1.GetComponent().isKilled == 1) && - (npc2.GetComponent().health <= 0 && npc2.GetComponent().isKilled == 1) && + (npc1.GetComponent().health <= 0 && npc1.GetComponent().isKilled == 1) && + (npc2.GetComponent().health <= 0 && npc2.GetComponent().isKilled == 1) && state == BossThugEnum.Pending) { state = BossThugEnum.Talking; // UZUPELNIC DIALOG diff --git a/Assets/Scripts/Enemies' Scprits/Enemy.cs b/Assets/Scripts/Enemies' Scprits/Enemy.cs index 7b333bdf..1d31c469 100644 --- a/Assets/Scripts/Enemies' Scprits/Enemy.cs +++ b/Assets/Scripts/Enemies' Scprits/Enemy.cs @@ -10,6 +10,8 @@ public class Enemy : MonoBehaviour public float health; public float baseAttack; + public int isKilled; + public string MinionName; // var used for multiplied name - for mission poroggress (kill condition) private void Awake() @@ -33,4 +35,10 @@ public class Enemy : MonoBehaviour } } + public void SaveCheckpoint() + { + PlayerPrefs.SetInt(enemyName + "-S", isKilled); + PlayerPrefs.SetFloat(enemyName + "-S.health", health); + } + } diff --git a/Assets/Scripts/Enemies' Scprits/FollowingEnemy.cs b/Assets/Scripts/Enemies' Scprits/FollowingEnemy.cs index 76661984..bc50d2a8 100644 --- a/Assets/Scripts/Enemies' Scprits/FollowingEnemy.cs +++ b/Assets/Scripts/Enemies' Scprits/FollowingEnemy.cs @@ -35,7 +35,6 @@ public class FollowingEnemy : Enemy public float thrust; public float knockTime; - public int isKilled; //isKilled = 0 - mob ALIVE //isKilled = 1 - mob DEAD @@ -191,6 +190,8 @@ public class FollowingEnemy : Enemy if (collision.tag == "AttackHitbox") { + Debug.Log("Hit in - TriggerEnter2D"); + hit = true; } } @@ -250,10 +251,4 @@ public class FollowingEnemy : Enemy enemy.isKinematic = true; } } - - public void SaveCheckpoint() - { - PlayerPrefs.SetInt(enemyName + "-S", isKilled); - PlayerPrefs.SetFloat(enemyName + "-S.health", health); - } } diff --git a/Assets/Scripts/Enemies' Scprits/FollowingPatrollingEnemy.cs b/Assets/Scripts/Enemies' Scprits/FollowingPatrollingEnemy.cs index 871ed7c9..5b7c0867 100644 --- a/Assets/Scripts/Enemies' Scprits/FollowingPatrollingEnemy.cs +++ b/Assets/Scripts/Enemies' Scprits/FollowingPatrollingEnemy.cs @@ -34,7 +34,6 @@ public class FollowingPatrollingEnemy : Enemy public float thrust; public float knockTime; - public int isKilled; //isKilled = 0 - mob ALIVE //isKilled = 1 - mob DEAD @@ -146,7 +145,6 @@ public class FollowingPatrollingEnemy : Enemy } else { - Debug.Log("Change"); changeGoal(); } } @@ -229,14 +227,8 @@ public class FollowingPatrollingEnemy : Enemy } } - public void SaveCheckpoint() - { - PlayerPrefs.SetInt(enemyName + "-S", isKilled); - } - private void changeGoal() { - Debug.Log("changeGoal Goal"); if (currentPoint == path.Length - 1) { currentPoint = 0; @@ -247,6 +239,5 @@ public class FollowingPatrollingEnemy : Enemy currentPoint++; currentGoal = path[currentPoint]; } - Debug.Log(currentPoint); } } diff --git a/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs b/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs index 03395275..9b303d8d 100644 --- a/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs +++ b/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs @@ -142,6 +142,10 @@ public class NPCFollowing : MonoBehaviour { break; } + case NPCStateEnum.Attacking: + { + break; + } default: { Debug.Log("fancy text nie wiem co zrobic"); diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index c8c41386..c6c884e9 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -160,12 +160,12 @@ public class Player : MonoBehaviour defensePoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_DEFENSE_POINTS); - Debug.Log($"Minion Damage: {damage}; \nDefense: {PlayerPrefs.GetFloat("defenseValue")}"); + Debug.Log($"Minion Damage: {damage}; \n\tDefense: {PlayerPrefs.GetFloat("defenseValue")}"); damage = damage - PlayerPrefs.GetFloat("defenseValue"); damage = damage < 0 ? 0 : damage; - Debug.Log($"RealDamage: {damage}"); + Debug.Log($"\tRealDamage: {damage}"); currentHealth = PlayerPrefs.GetFloat("health"); currentHealth = currentHealth - damage; diff --git a/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs b/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs index 755b8679..0a1293c0 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs @@ -83,11 +83,11 @@ public class ChestPanelController : WarehousePanelController base.BuildPanelContent(elements); - Debug.Log("Build content"); - foreach (IndexValuePair element in elements) +/* Debug.Log("Build content"); +*/ foreach (IndexValuePair element in elements) { - Debug.Log($"key: {element.Key} - value: {element.Value} - type: {element.Value.EquipmentType}"); - ChildBoxList[element.Key].SetItem(new EquippableItem(element.Value)); +/* Debug.Log($"key: {element.Key} - value: {element.Value} - type: {element.Value.EquipmentType}"); +*/ ChildBoxList[element.Key].SetItem(new EquippableItem(element.Value)); } } } diff --git a/Assets/Scripts/REFACTORING/Story/Thugs.meta b/Assets/Scripts/REFACTORING/Story/Thugs.meta new file mode 100644 index 00000000..4c54aea3 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Story/Thugs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a45f30e3957407f48aeff3cb6aebea8f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs b/Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs new file mode 100644 index 00000000..677c3455 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs @@ -0,0 +1,367 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +[RequireComponent(typeof(NPC))] +[RequireComponent(typeof(Enemy))] +public class ThugNPCFollowing : MonoBehaviour +{ + public const string ACTION_KEY = "ATTACKING"; + + private Rigidbody2D myRigidbody; + public Animator anim; + + private Vector2 movement; + public bool shouldRotate; + public Vector3 dir; + + [Header("Following Logic")] + public Vector3 homePosition; + public Transform targetPosition; + + public AStarPathfindingAgent agent; + + public bool isDuringFollowing = false; // var is setted by trigger range + + //public GameObject player; + [Header("Core Logic")] + public bool approaching = false; + public bool isAfterAction = false; + public float chasingRadius = 6f; // radious where Npc start attacking ! ! ! + + [Header("Attacking Logic")] // TRASH - dupplicated from Following Enemy - move params to Enemy + public float attackingRadius = 1.5f; // radious where Npc start attacking ! ! ! + + public bool hit = false; + + public bool firstAttack = false; + + public float timerDmg = 0f; + public float waitTime = 1.0f; + + public float timerHit = 0f; + public float hitWaitTime = 0.55f; + + public float expValue; + public float thrust; + public float knockTime; + + //public int isKilled; - movet do Enemy + //isKilled = 0 - mob ALIVE + //isKilled = 1 - mob DEAD + + public int isKilled2; + + public bool isPanelEnabled = true; + + + + void Awake() + { + agent = GetComponent(); + + + homePosition = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z); + } + + // Start is called before the first frame update + void Start() + { + targetPosition = GameObject.FindWithTag("Player").transform; + + //Copy from Eollwoing + if (OnMapAppearanceMethod.IsNewGame()) + { + gameObject.GetComponent().isKilled = 0; + } + + if (gameObject.GetComponent().health <= 0) + gameObject.GetComponent().isKilled = 1; + else // Else read saved value + gameObject.GetComponent().isKilled = PlayerPrefs.GetInt(gameObject.GetComponent().enemyName + "-S"); + + + if (gameObject.GetComponent().isKilled == 1) + { + gameObject.SetActive(false); + gameObject.GetComponent().isKilled = 0; + } + + myRigidbody = GetComponent(); + anim = GetComponent(); + } + + // Update is called once per frame + public void Update() + { + // 0 Cofigure Animator + if (Vector2.Distance(targetPosition.position, transform.position) <= chasingRadius) + { + Debug.Log("Chase"); + dir = targetPosition.position - transform.position; + float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; + dir.Normalize(); + movement = dir; + anim.SetBool("isRunning", movement != Vector2.zero); + Debug.Log(shouldRotate); + if (shouldRotate) + { + anim.SetFloat("Xinfo", dir.x); + anim.SetFloat("Yinfo", dir.y); + } + } + + + // 1. Check range and decide which action do + // Following player detection + if (IsInChassingRadious()) + { + // 2'nd state alow us to brak going to hom,e action to follow player again + if (gameObject.GetComponent().State == NPCStateEnum.Pending || gameObject.GetComponent().State == NPCStateEnum.Walking) + { + approaching = true; + + gameObject.GetComponent().State = NPCStateEnum.Walking; + } + } else + { + // Turn around and go to home position + if (approaching) + { + approaching = false; + + gameObject.GetComponent().State = NPCStateEnum.Walking; + } + } + + // 2.Take action based on conditions around + HandleState(); + + // 3. + // COPIED FROM Following Enemy scripts + // Taking hit logic + timerHit += Time.deltaTime; + if (hit == true) + { + if (timerHit >= hitWaitTime) + { + + TakeDamage(PlayerPrefs.GetFloat("attackValue")); + hit = false; + timerHit = 0f; + TakeKnockback(); + } + } + + // Detecting "is alive" logic + if (gameObject.active == false) + { + gameObject.GetComponent().isKilled = 1; + PlayerPrefs.SetInt(gameObject.GetComponent().enemyName, gameObject.GetComponent().isKilled); + } + } + + public void CheckDistance() + { + StopAllCoroutines(); + + + // isDuringFollowing - avr is setted by trigger range + if (approaching && !IsInActionRadious()) + { + agent.FindPath(); + + StartCoroutine(agent.FollowPath()); + } + else if (approaching) + { + // in this script we set attacking mode + SetActionAfterMetConditions(); + + agent.path.Clear(); // if we are able to talgk we dont want go go further player + } + else if (!approaching) + { + if (Vector2.Distance(transform.position, homePosition) > 0.8f) // cont vale - path finding stop moving them before reachin position well.. + { + agent.point = homePosition; + + agent.FindPoint(); + + StartCoroutine(agent.FollowPath()); + } + else + { + gameObject.GetComponent().State = NPCStateEnum.Pending; + } + } + } + + + #region Taking damage from Player detection + + public void OnTriggerEnter2D(Collider2D collision) + { + // Hit logic + if (collision.gameObject.tag == "AttackHitbox" || collision.gameObject.tag == "PickaxeHitbox") + { + hit = true; + } + + } + + public void OnTriggerExit2D(Collider2D other) + { + // Hit logic + if (other.tag == "AttackHitbox" || other.tag == "PickaxeHitbox") + { + timerDmg = 0f; + + hit = false; + } + } + #endregion + + public void HandleState() + { + switch (gameObject.GetComponent().State) + { + case NPCStateEnum.Walking: + { + CheckDistance(); + break; + } + case NPCStateEnum.Talking: + { + TalkingAction(); + break; + } + case NPCStateEnum.Pending: + { + break; + } + case NPCStateEnum.Attacking: + { + AttackingAction(); + break; + } + default: + { + Debug.Log("Nieopisane zachowanie NPC ! ! !"); + break; + } + } + } + + public bool IsInChassingRadious() + { + if (Vector2.Distance(targetPosition.position, transform.position) >= chasingRadius) + return false; + + return true; + } + + public bool IsInActionRadious() + { + if (Vector2.Distance(targetPosition.position, transform.position) >= attackingRadius) + return false; + + return true; + } + + public void SetActionAfterMetConditions() + { + gameObject.GetComponent().State = NPCStateEnum.Attacking; + } + + public void TalkingAction() + { + // Not required in this script + } + + public void AttackingAction() + { + // if during Attacking mode player GO OUT of the attacking radious + if(!IsInActionRadious()) + { + gameObject.GetComponent().State = NPCStateEnum.Walking; + return; + } + + // Attacking logic + if (firstAttack == false) + { + if (timerDmg >= 0.15f) + { + firstAttack = true; + + GameObject.FindGameObjectWithTag("Player").GetComponent().TakeDamage( + gameObject.GetComponent().baseAttack, + isPanelEnabled + ); + + timerDmg = 0f; + } + } + if (timerDmg >= waitTime) + { + timerDmg = 0f; + + GameObject.FindGameObjectWithTag("Player").GetComponent().TakeDamage( + gameObject.GetComponent().baseAttack, + isPanelEnabled + ); + } + + timerDmg += Time.deltaTime; + + } + + #region dupplicated from Following :) + public void TakeDamage(float damage) + { + Debug.Log("TakeDamage"); + gameObject.GetComponent().health -= damage; + + if (gameObject.GetComponent().health <= 0) + { + gameObject.SetActive(false); + gameObject.GetComponent().isKilled = 1; + GameObject.FindGameObjectWithTag("Player").GetComponent().GetExp(expValue); + + // pass info about killing assigned enemy to mission manager listener + // pass enemy name from script NOT object name (thats allow to have many different objects variantsa with this same aggregate key (private name - not preffab name) ) + ConditionManager.Instance.UpdateKillCondition(gameObject.GetComponent().MinionName); + } + } + + public void TakeKnockback() + { + Rigidbody2D enemy = gameObject.GetComponent(); + Rigidbody2D player = GameObject.FindGameObjectWithTag("Player").GetComponent(); + + if (enemy != null) + { + enemy.isKinematic = false; + Vector2 difference = enemy.transform.position - player.transform.position; + difference = difference.normalized * thrust; + enemy.AddForce(difference, ForceMode2D.Impulse); + //StartCoroutine(KnockCo(enemy)); + } + } + #endregion + + public void AfterAction() + { + approaching = false; + isAfterAction = true; + //isDuringConversation = false; + //PlayerPrefs.SetInt(gameObject.name + ".FirstDialogue", System.Convert.ToInt32(isAfterAction)); + gameObject.GetComponent().State = NPCStateEnum.Walking; + } +} + diff --git a/Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs.meta b/Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs.meta new file mode 100644 index 00000000..bb65512c --- /dev/null +++ b/Assets/Scripts/REFACTORING/Story/Thugs/ThugNPCFollowing.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 87a548368fe86f949bd65a67abfc3597 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/NPC/NPCManager.cs b/Assets/Scripts/SceneManager/NPC/NPCManager.cs index c3359e7c..4b841fad 100644 --- a/Assets/Scripts/SceneManager/NPC/NPCManager.cs +++ b/Assets/Scripts/SceneManager/NPC/NPCManager.cs @@ -64,12 +64,16 @@ public class NPCManager : MonoBehaviour //Debug.Log("Thug Name: " + ThugClone.name + " Positions: " + ThugClone.transform.position.x + " + " + ThugClone.transform.position.y + " + " + ThugClone.transform.position.z); //Debug.Log("Thug Name: " + ThugClone.name + " Local Positions: " + ThugClone.transform.localPosition.x + " + " + ThugClone.transform.localPosition.y + " + " + ThugClone.transform.localPosition.z); - ThugClone.GetComponent().enemyName = thug.name; //delete and set in the controller todo? - ThugClone.GetComponent().isKilled = PlayerPrefs.HasKey(thug.name + "-S") ? PlayerPrefs.GetInt(thug.name + "-S") : 0; + ThugClone.GetComponent().Name = thug.name; + + ThugClone.GetComponent().enemyName = thug.name; //delete and set in the controller todo? + ThugClone.GetComponent().MinionName = "Thug"; + ThugClone.GetComponent().isKilled = PlayerPrefs.HasKey(thug.name + "-S") ? PlayerPrefs.GetInt(thug.name + "-S") : 0; + if (PlayerPrefs.HasKey(thug.name + "-S.health")) { - ThugClone.GetComponent().health = PlayerPrefs.GetFloat(thug.name + "-S.health"); + ThugClone.GetComponent().health = PlayerPrefs.GetFloat(thug.name + "-S.health"); } // Dont set up it manually, let allow logic in Following Enemy scriptmanage avaible itself @@ -85,8 +89,12 @@ public class NPCManager : MonoBehaviour BossThugClone.name = bossThug.name; BossThugClone.transform.SetParent(NPCCollection.transform); + + BossThugClone.GetComponent().Name = bossThug.name; + BossThugClone.GetComponent().enemyName = bossThug.name; //delete and set in the controller todo? - + BossThugClone.GetComponent().MinionName = "Thug"; + BossThugClone.SetActive(PlayerPrefs.HasKey(bossThug.name + "-S") ? !Convert.ToBoolean(PlayerPrefs.GetInt(bossThug.name + "-S")) : true); BossThugClone.GetComponent().isPanelEnabled = false; diff --git a/Assets/Scripts/SceneManager/SaveDynamicObjects.cs b/Assets/Scripts/SceneManager/SaveDynamicObjects.cs index 2f01250d..f6a33bcd 100644 --- a/Assets/Scripts/SceneManager/SaveDynamicObjects.cs +++ b/Assets/Scripts/SceneManager/SaveDynamicObjects.cs @@ -58,7 +58,7 @@ public class SaveDynamicObjects : MonoBehaviour if (ThugFromScene != null) { - ThugFromScene.GetComponent().SaveCheckpoint(); + ThugFromScene.GetComponent().SaveCheckpoint(); } else { @@ -79,7 +79,7 @@ public class SaveDynamicObjects : MonoBehaviour if (BossThugFromScene != null) { - BossThugFromScene.GetComponent().SaveCheckpoint(); + BossThugFromScene.GetComponent().SaveCheckpoint(); } else {