diff --git a/Assets/Prefab/Items.meta b/Assets/Prefab/Items.meta new file mode 100644 index 00000000..97850262 --- /dev/null +++ b/Assets/Prefab/Items.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 89412f229cb2738409fadd58645601f8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefab/Items/Tower.prefab b/Assets/Prefab/Items/Tower.prefab new file mode 100644 index 00000000..5217e25c --- /dev/null +++ b/Assets/Prefab/Items/Tower.prefab @@ -0,0 +1,126 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4774919592469818776 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5262522953580885794} + - component: {fileID: 9126517344989362311} + - component: {fileID: 6432002706622696525} + - component: {fileID: 8015579614070857994} + - component: {fileID: 5879628246065515362} + m_Layer: 0 + m_Name: Tower + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5262522953580885794 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4774919592469818776} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0, y: 0, z: 0} + m_LocalScale: {x: 0.3, y: 0.3, z: 0.3} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &9126517344989362311 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4774919592469818776} + m_Mesh: {fileID: 688505742851261164, guid: a6c1d0254e365a4489cf81b74d608b43, type: 3} +--- !u!23 &6432002706622696525 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4774919592469818776} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 8720b7cac4364f14f961a3b6968c9beb, type: 2} + 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: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!114 &8015579614070857994 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4774919592469818776} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5db196e1099b97246bde07a348189567, type: 3} + m_Name: + m_EditorClassIdentifier: + _weapon: + name: Tower + icon: {fileID: 4774919592469818776} + objectToThrow: {fileID: 4746165193704193263, guid: 4e7523811a052fd46acf941fc69c8c98, + type: 3} + VFXGameObject: {fileID: 2957420090356197408, guid: 5d1244f7b80cadd428a70173a01ce889, + type: 3} + manaCost: 0 + damage: 10 + speed: 10 + disnatce: 10 + reloadTime: 3 + shots: 3 + shotSound: {fileID: 8300000, guid: 9ea918c6c23577f4e885a8490d2f2046, type: 3} + hitSound: {fileID: 8300000, guid: 6c42231c18643dc4d9d8f8d15bc4735b, type: 3} +--- !u!136 &5879628246065515362 +CapsuleCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4774919592469818776} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + m_Radius: 31.906784 + m_Height: 63.813572 + m_Direction: 1 + m_Center: {x: 0, y: 0, z: 0} diff --git a/Assets/Prefab/Items/Tower.prefab.meta b/Assets/Prefab/Items/Tower.prefab.meta new file mode 100644 index 00000000..a6984fb6 --- /dev/null +++ b/Assets/Prefab/Items/Tower.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0dbed8f974ba44a42af9d8fcae504ce0 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/1/Pillar 01.FBX b/Assets/Resources/1/Pillar 01.FBX new file mode 100644 index 00000000..a5f6a631 --- /dev/null +++ b/Assets/Resources/1/Pillar 01.FBX @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37ff580b2ac54350270f8fdd11d105d68b35b02b990899ad64863f566bed2e4d +size 182837 diff --git a/Assets/Resources/1/Pillar 01.FBX.meta b/Assets/Resources/1/Pillar 01.FBX.meta new file mode 100644 index 00000000..dcb3738f --- /dev/null +++ b/Assets/Resources/1/Pillar 01.FBX.meta @@ -0,0 +1,102 @@ +fileFormatVersion: 2 +guid: a6c1d0254e365a4489cf81b74d608b43 +ModelImporter: + serializedVersion: 20200 + internalIDToNameTable: [] + externalObjects: {} + materials: + materialImportMode: 2 + materialName: 0 + materialSearch: 1 + materialLocation: 1 + animations: + legacyGenerateAnimations: 4 + bakeSimulation: 0 + resampleCurves: 1 + optimizeGameObjects: 0 + motionNodeName: + rigImportErrors: + rigImportWarnings: + animationImportErrors: + animationImportWarnings: + animationRetargetingWarnings: + animationDoRetargetingWarnings: 0 + importAnimatedCustomProperties: 0 + importConstraints: 0 + animationCompression: 1 + animationRotationError: 0.5 + animationPositionError: 0.5 + animationScaleError: 0.5 + animationWrapMode: 0 + extraExposedTransformPaths: [] + extraUserProperties: [] + clipAnimations: [] + isReadable: 0 + meshes: + lODScreenPercentages: [] + globalScale: 1 + meshCompression: 0 + addColliders: 0 + useSRGBMaterialColor: 1 + sortHierarchyByName: 1 + importVisibility: 1 + importBlendShapes: 1 + importCameras: 1 + importLights: 1 + fileIdsGeneration: 2 + swapUVChannels: 0 + generateSecondaryUV: 0 + useFileUnits: 1 + keepQuads: 0 + weldVertices: 1 + bakeAxisConversion: 0 + preserveHierarchy: 0 + skinWeightsMode: 0 + maxBonesPerVertex: 4 + minBoneWeight: 0.001 + meshOptimizationFlags: -1 + indexFormat: 0 + secondaryUVAngleDistortion: 8 + secondaryUVAreaDistortion: 15.000001 + secondaryUVHardAngle: 88 + secondaryUVMarginMethod: 1 + secondaryUVMinLightmapResolution: 40 + secondaryUVMinObjectScale: 1 + secondaryUVPackMargin: 4 + useFileScale: 1 + tangentSpace: + normalSmoothAngle: 60 + normalImportMode: 0 + tangentImportMode: 3 + normalCalculationMode: 4 + legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0 + blendShapeNormalImportMode: 1 + normalSmoothingSource: 0 + referencedClips: [] + importAnimation: 1 + humanDescription: + serializedVersion: 3 + human: [] + skeleton: [] + armTwist: 0.5 + foreArmTwist: 0.5 + upperLegTwist: 0.5 + legTwist: 0.5 + armStretch: 0.05 + legStretch: 0.05 + feetSpacing: 0 + globalScale: 1 + rootMotionBoneName: + hasTranslationDoF: 0 + hasExtraRoot: 0 + skeletonHasParents: 1 + lastHumanDescriptionAvatarSource: {instanceID: 0} + autoGenerateAvatarMappingIfUnspecified: 1 + animationType: 2 + humanoidOversampling: 1 + avatarSetup: 0 + addHumanoidExtraRootOnlyWhenUsingAvatar: 1 + additionalBone: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Data/FieldData.asset b/Assets/Resources/Data/FieldData.asset index 5b978a42..d6d8ff53 100644 --- a/Assets/Resources/Data/FieldData.asset +++ b/Assets/Resources/Data/FieldData.asset @@ -14,8 +14,6 @@ MonoBehaviour: m_EditorClassIdentifier: width: 25 height: 50 - defaultColor: {r: 1, g: 1, b: 1, a: 1} - touchedColor: {r: 1, g: 0, b: 1, a: 1} hexCaptureManaCost: 10 cellPrefab: {fileID: 1661242500252451528, guid: bcea5b4a96735bd4b936f8f3fefcc688, type: 3} @@ -23,24 +21,28 @@ MonoBehaviour: type: 3} CoordinatesCanvas: {fileID: 4726489279989878083, guid: f31e0880dd078104bb31dc0fd7ef9f19, type: 3} - DefaultTexture: {fileID: 2800000, guid: 983242f4b4db7a841af48234cf0021b8, type: 3} colors: - _unitColor: 2 _texture: {fileID: 2800000, guid: 983242f4b4db7a841af48234cf0021b8, type: 3} _vfxPrefab: {fileID: 0} + _buildinTexture: {fileID: 0} - _unitColor: 0 _texture: {fileID: 2800000, guid: 0298dfcb0756f534a9a125d510461c7a, type: 3} _vfxPrefab: {fileID: 8021195855904498788, guid: 2f6d0540c8fd7bb46b356ff86962379c, type: 3} + _buildinTexture: {fileID: 2800000, guid: 0298dfcb0756f534a9a125d510461c7a, type: 3} - _unitColor: 1 _texture: {fileID: 2800000, guid: 3b75368df991b164583e8cede390e24e, type: 3} _vfxPrefab: {fileID: 442387583353148024, guid: 53959bc898e9a644daad0282881d596a, type: 3} + _buildinTexture: {fileID: 2800000, guid: 3b75368df991b164583e8cede390e24e, type: 3} - _unitColor: 3 _texture: {fileID: 2800000, guid: 1a76a79d5a83143479c76f4f37c4b896, type: 3} _vfxPrefab: {fileID: 5732852186060375560, guid: 54d847a18c62f57479c53469d4398ceb, type: 3} + _buildinTexture: {fileID: 2800000, guid: 1a76a79d5a83143479c76f4f37c4b896, type: 3} - _unitColor: 4 _texture: {fileID: 2800000, guid: 779719648deedb4478ddebb3b81751ef, type: 3} _vfxPrefab: {fileID: 1651852338557341938, guid: fa6c1fc3da7c8d24c85a88b00cf598d4, type: 3} + _buildinTexture: {fileID: 2800000, guid: 779719648deedb4478ddebb3b81751ef, type: 3} diff --git a/Assets/Resources/Data/ItemData.asset b/Assets/Resources/Data/ItemData.asset index c3613682..7270ebb4 100644 --- a/Assets/Resources/Data/ItemData.asset +++ b/Assets/Resources/Data/ItemData.asset @@ -13,12 +13,26 @@ MonoBehaviour: m_Name: ItemData m_EditorClassIdentifier: itemInfos: - - prefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893, - type: 3} + - prefab: {fileID: 919132149155446097, guid: 4166c606d638610418dc9ead794d697b, type: 3} isInstantUse: 0 type: Tower icon: {fileID: 21300000, guid: 543c4732bd2d47a41bdbbf2156eb358c, type: 3} - spawnablePrefab: {fileID: 1175122412763585952, guid: ca39954219550f949aeeecf95f25f3d1, + spawnablePrefab: {fileID: 4774919592469818776, guid: 0dbed8f974ba44a42af9d8fcae504ce0, type: 3} + values: + - prefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893, + type: 3} + isInstantUse: 1 + type: AttackBonus + icon: {fileID: 21300000, guid: caf8bc0311dd2fc4ca1528a82a063754, type: 3} + spawnablePrefab: {fileID: 0} + values: 030000000f000000 + - prefab: {fileID: 8639522512577941448, guid: 7b6a7f64e52da514d88aa97ad8f863df, + type: 3} + isInstantUse: 1 + type: DefenceBonus + icon: {fileID: 21300000, guid: 35be128594dcdce48b5d8e5317b38ed9, type: 3} + spawnablePrefab: {fileID: 0} + values: 0a0000001e000000 fromTimeSpawn: 3 toTimeSpawn: 10 diff --git a/Assets/Scripts/Controller/GameInit.cs b/Assets/Scripts/Controller/GameInit.cs index 09cb7fa2..9d80907c 100644 --- a/Assets/Scripts/Controller/GameInit.cs +++ b/Assets/Scripts/Controller/GameInit.cs @@ -1,13 +1,16 @@ using System; using System.Collections.Generic; +using System.Timers; using CamControl; using Chars; +using DefaultNamespace; using GameUI; using HexFiled; using Items; using Units; using UnityEngine; using Weapons; +using Object = UnityEngine.Object; using Random = UnityEngine.Random; namespace Controller @@ -16,16 +19,18 @@ namespace Controller { public GameInit(Controllers controllers, Data.Data data) { + + new GameObject("Timer").AddComponent(); + var hexGrid = new HexGrid(data.FieldData); new MusicController(); MusicController.Instance.SetMusicData(data.MusicData); controllers.Add(hexGrid); - List types = - new List() { typeof(Tower) }; - ItemFabric itemFabric = new ItemFabric(data.ItemsData, types); + + ItemFabric itemFabric = new ItemFabric(data.ItemsData, SetUpItems()); controllers.Add(itemFabric); - + UIController uiController = new UIController(data.UIData); uiController.Spawn(); //TODO при паузе Dotween ругается Unit player; @@ -35,7 +40,8 @@ namespace Controller if (unit.isPlayer) { player = new Unit(unit, JsonUtility.FromJson(data.ChosenWeapon), hexGrid); - PlayerControl playerControl = new PlayerControl(player, uiController.PlayerControlView, uiController.PlayerInventoryView); + PlayerControl playerControl = new PlayerControl(player, uiController.PlayerControlView, + uiController.PlayerInventoryView); controllers.Add(playerControl); CameraControl cameraControl = new CameraControl(Camera.main, data.CameraData); @@ -46,7 +52,8 @@ namespace Controller } else { - var enemy = new Unit(unit, data.WeaponsData.WeaponsList[Random.Range(0,data.WeaponsData.WeaponsList.Count - 1)], hexGrid); + var enemy = new Unit(unit, + data.WeaponsData.WeaponsList[Random.Range(0, data.WeaponsData.WeaponsList.Count - 1)], hexGrid); var enemyController = new EnemyController(unit, enemy); controllers.Add(enemyController); units.Add(enemy); @@ -62,9 +69,11 @@ namespace Controller hexGrid.OnHexPainted += paintedController.SetHexColors; hexGrid.OnHexPainted += itemFabric.UpdateCellToOpenList; - } - - + + private List SetUpItems() + { + return new List() { typeof(Tower), typeof(AttackBonus), typeof(DefenceBonus) }; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Data/ItemsData.cs b/Assets/Scripts/Data/ItemsData.cs index d348a801..a03a2374 100644 --- a/Assets/Scripts/Data/ItemsData.cs +++ b/Assets/Scripts/Data/ItemsData.cs @@ -27,6 +27,8 @@ namespace Data [SerializeField] private string type; [SerializeField] private Sprite icon; [SerializeField] private GameObject spawnablePrefab; + [SerializeField] private int[] values; + [SerializeField][Range(0,1)] private float spawnChance; public GameObject Prefab => prefab; public string Type => type; @@ -35,5 +37,7 @@ namespace Data public GameObject SpawnablePrefab => spawnablePrefab; public bool IsInstanceUse => isInstantUse; + public int[] Values => values; + public float SpawnChance => spawnChance; } } \ No newline at end of file diff --git a/Assets/Scripts/DirectionHelper.cs b/Assets/Scripts/DirectionHelper.cs new file mode 100644 index 00000000..d3fbaeb6 --- /dev/null +++ b/Assets/Scripts/DirectionHelper.cs @@ -0,0 +1,50 @@ +using System; +using HexFiled; +using UnityEngine; + +namespace DefaultNamespace +{ + public static class DirectionHelper + { + public static Vector3 DirectionTo(Vector3 a, Vector3 b) + { + return (b - a).normalized; + } + + public static HexDirection VectorToDirection(Vector2 dir) + { + if (dir.x >= 0 && dir.y <= 1 && dir.x <= 1 && dir.y >= 0.5) + { + return HexDirection.NE; + } + + if (Math.Abs(dir.x - 1f) < 0.2 && dir.y <= 0.5 && dir.y >= -0.5) + { + return HexDirection.E; + } + + if (dir.x <= 1 && dir.y <= -0.5 && dir.x >= 0 && dir.y >= -1) + { + return HexDirection.SE; + } + + if (dir.x <= 0 && dir.y >= -1 && dir.x >= -1 && dir.y <= -0.5) + { + return HexDirection.SW; + } + + if (Math.Abs(dir.x - (-1f)) < 0.2 && dir.y >= -0.5 && dir.y <= 0.5) + { + return HexDirection.W; + } + + if (dir.x >= -1 && dir.y >= 0.5 && dir.x <= 0 && dir.y <= 1) + { + return HexDirection.NW; + } + + return HexDirection.W; + } + + } +} \ No newline at end of file diff --git a/Assets/Scripts/DirectionHelper.cs.meta b/Assets/Scripts/DirectionHelper.cs.meta new file mode 100644 index 00000000..da1a9a74 --- /dev/null +++ b/Assets/Scripts/DirectionHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fc19bb5576de42c89aa7aae62e2c3552 +timeCreated: 1641323470 \ No newline at end of file diff --git a/Assets/Scripts/GameUI/GameMenuView.cs b/Assets/Scripts/GameUI/GameMenuView.cs index a5dac732..fb578a20 100644 --- a/Assets/Scripts/GameUI/GameMenuView.cs +++ b/Assets/Scripts/GameUI/GameMenuView.cs @@ -32,12 +32,14 @@ public class GameMenuView : MonoBehaviour private void ShowMenu() { + DOTween.PauseAll(); menu.SetActive(true); Time.timeScale = 0f; } private void HideMenu() { + DOTween.PlayAll(); Time.timeScale = 1f; menu.SetActive(false); } diff --git a/Assets/Scripts/GameUI/PlayerInventoryView.cs b/Assets/Scripts/GameUI/PlayerInventoryView.cs index f706d0f7..bcefeaa5 100644 --- a/Assets/Scripts/GameUI/PlayerInventoryView.cs +++ b/Assets/Scripts/GameUI/PlayerInventoryView.cs @@ -46,6 +46,7 @@ public class PlayerInventoryView : MonoBehaviour var button = _freeButtons.Dequeue(); _dictionary.Add(item, button); button.gameObject.SetActive(true); + button.image.sprite = item.Icon; button.onClick.AddListener(() => { if (item.IsInstantUse) @@ -59,6 +60,7 @@ public class PlayerInventoryView : MonoBehaviour item.Invoke(SwitchButton); OnItemInvoked?.Invoke(item); } + }); diff --git a/Assets/Scripts/HexFiled/CellColor.cs b/Assets/Scripts/HexFiled/CellColor.cs index bedd2d8d..5c5b85ec 100644 --- a/Assets/Scripts/HexFiled/CellColor.cs +++ b/Assets/Scripts/HexFiled/CellColor.cs @@ -9,10 +9,14 @@ namespace HexFiled [SerializeField] private UnitColor _unitColor; [SerializeField] private Texture _texture; [SerializeField] private GameObject _vfxPrefab; + [SerializeField] private Texture _buildinTexture; public UnitColor UnitColor => _unitColor; public Texture Texture => _texture; + public Texture BuildingTexture => _buildinTexture; public GameObject VFXPrefab => _vfxPrefab; + + public bool Equals(CellColor obj) { diff --git a/Assets/Scripts/HexFiled/HexCell.cs b/Assets/Scripts/HexFiled/HexCell.cs index 08d482a7..9bc4c105 100644 --- a/Assets/Scripts/HexFiled/HexCell.cs +++ b/Assets/Scripts/HexFiled/HexCell.cs @@ -16,7 +16,6 @@ namespace HexFiled private Item _item; private UnitColor _color; private MeshRenderer _renderer; - private Dictionary _cellColor; public UnitColor Color => _color; @@ -39,11 +38,7 @@ namespace HexFiled { return neighbors.ToList(); } - - public void SetDictionary(Dictionary colors) - { - _cellColor = colors; - } + public HexCell GetNeighbor(HexDirection direction) { @@ -61,15 +56,15 @@ namespace HexFiled if (color == _color) return; if (color == UnitColor.GREY) { - _renderer.material.mainTexture = _cellColor[color].Texture; + _renderer.material.mainTexture = HexGrid.Colors[color].Texture; _color = color; return; } - _renderer.material.mainTexture = _cellColor[color].Texture; + _renderer.material.mainTexture = HexGrid.Colors[color].Texture; _color = color; - Instantiate(_cellColor[color].VFXPrefab, transform); + Instantiate(HexGrid.Colors[color].VFXPrefab, transform); onHexPainted?.Invoke(this); } } diff --git a/Assets/Scripts/HexFiled/HexGrid.cs b/Assets/Scripts/HexFiled/HexGrid.cs index 3a8c861e..3e1c872c 100644 --- a/Assets/Scripts/HexFiled/HexGrid.cs +++ b/Assets/Scripts/HexFiled/HexGrid.cs @@ -17,15 +17,17 @@ namespace HexFiled private HexCell[] _cells; private Canvas _gridCanvas; private GameObject _baseGameObject; - private Dictionary _colors; - private float _hexDistance; + private static Dictionary _colors; + private static float _hexDistance; private int _hexCaptureCost; - public float HexDistance => _hexDistance; + public static float HexDistance => _hexDistance; public Action OnHexPainted; public Action OnGridLoaded; public int HexCaptureCost => _hexCaptureCost; + public static Dictionary Colors => _colors; + public HexGrid(FieldData fieldData) { _hexCaptureCost = fieldData.hexCaptureManaCost; @@ -63,7 +65,6 @@ namespace HexFiled position.z = z * (HexMetrics.outerRadius * 1.5f); var cellGO = Object.Instantiate(_cellPrefab); HexCell cell = _cells[i] = cellGO.GetComponent(); - cell.SetDictionary(_colors); cell.PaintHex(UnitColor.GREY); cell.transform.SetParent(_baseGameObject.transform, false); cell.transform.localPosition = position; diff --git a/Assets/Scripts/Items/AttackBonus.cs b/Assets/Scripts/Items/AttackBonus.cs new file mode 100644 index 00000000..24099838 --- /dev/null +++ b/Assets/Scripts/Items/AttackBonus.cs @@ -0,0 +1,28 @@ +using System; +using Data; +using HexFiled; + +namespace Items +{ + public class AttackBonus : Item + { + public AttackBonus(ItemInfo data) : base(data) + { + } + + public override void Invoke(Action item) + { + throw new NotImplementedException(); + } + + public override void InstanceInvoke() + { + Unit.SetAttackBonus(Data.Values[0], Data.Values[1]); + } + + public override void PlaceItem(HexCell cell) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Items/AttackBonus.cs.meta b/Assets/Scripts/Items/AttackBonus.cs.meta new file mode 100644 index 00000000..707f2fe6 --- /dev/null +++ b/Assets/Scripts/Items/AttackBonus.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2b016eba27de41629261b965b3e2be0c +timeCreated: 1641382290 \ No newline at end of file diff --git a/Assets/Scripts/Items/DefenceBonus.cs b/Assets/Scripts/Items/DefenceBonus.cs new file mode 100644 index 00000000..e7082f94 --- /dev/null +++ b/Assets/Scripts/Items/DefenceBonus.cs @@ -0,0 +1,28 @@ +using System; +using Data; +using HexFiled; + +namespace Items +{ + public class DefenceBonus : Item + { + public DefenceBonus(ItemInfo data) : base(data) + { + } + + public override void Invoke(Action item) + { + throw new NotImplementedException(); + } + + public override void InstanceInvoke() + { + Unit.SetDefenceBonus(Data.Values[0], Data.Values[1]); + } + + public override void PlaceItem(HexCell cell) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Items/DefenceBonus.cs.meta b/Assets/Scripts/Items/DefenceBonus.cs.meta new file mode 100644 index 00000000..6b32f816 --- /dev/null +++ b/Assets/Scripts/Items/DefenceBonus.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c518da097b3645c491c6a4cc61b3d493 +timeCreated: 1641382317 \ No newline at end of file diff --git a/Assets/Scripts/Items/Item.cs b/Assets/Scripts/Items/Item.cs index b199fb3a..db5f7953 100644 --- a/Assets/Scripts/Items/Item.cs +++ b/Assets/Scripts/Items/Item.cs @@ -15,6 +15,7 @@ namespace Items protected Action OnItemUsed; public bool IsInstantUse => Data.IsInstanceUse; + public Sprite Icon => Data.Icon; protected Item(ItemInfo data) { Data = data; diff --git a/Assets/Scripts/Items/ItemFabric.cs b/Assets/Scripts/Items/ItemFabric.cs index c2cf635e..78e2dc56 100644 --- a/Assets/Scripts/Items/ItemFabric.cs +++ b/Assets/Scripts/Items/ItemFabric.cs @@ -49,13 +49,17 @@ namespace Items .ToList(); time = Time.time; var cell = _openList[Random.Range(0, _openList.Count - 1)]; - + while (closedList.Contains(cell) || cell.Item != null) { cell = _openList[Random.Range(0, _openList.Count - 1)]; } - - var type = _itemTypes[Random.Range(0, _itemTypes.Count - 1)]; + + var type = GetWeightedType(); + while (type == null) + { + type = GetWeightedType(); + } var info = _itemInfos[type.ToString().Replace("Items.", "")]; var obj = (Item)Activator.CreateInstance(type, info); @@ -67,5 +71,20 @@ namespace Items _spawnTime = Random.Range(_data.SpawnTime.from, _data.SpawnTime.to); } } + + private Type GetWeightedType() + { + float randomNum = Random.Range(1, 101)/100f; + List possibleTypes = new List(); + + _itemTypes.ForEach(type => + { + if (_itemInfos[type.ToString().Replace("Items.", "")].SpawnChance >= randomNum) + { + possibleTypes.Add(type); + } + }); + return possibleTypes.Count > 0 ? possibleTypes[Random.Range(0, possibleTypes.Count - 1)] : null; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Items/Tower.cs b/Assets/Scripts/Items/Tower.cs index 1e94ead3..800f6b95 100644 --- a/Assets/Scripts/Items/Tower.cs +++ b/Assets/Scripts/Items/Tower.cs @@ -22,12 +22,14 @@ namespace Items public override void InstanceInvoke() { - throw new System.NotImplementedException(); + Unit.UseItem(this); } public override void PlaceItem(HexCell cell) { - Object.Instantiate(Data.SpawnablePrefab, cell.transform.position, Quaternion.identity); + Unit.UseItem(this); + var obj = Object.Instantiate(Data.SpawnablePrefab, cell.transform.position, Quaternion.identity); + obj.AddComponent().SetUp(Unit.Color); OnItemUsed?.Invoke(this); } } diff --git a/Assets/Scripts/TimerHelper.cs b/Assets/Scripts/TimerHelper.cs new file mode 100644 index 00000000..06e9af0b --- /dev/null +++ b/Assets/Scripts/TimerHelper.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections; +using UnityEngine; + +namespace DefaultNamespace +{ + public class TimerHelper : MonoBehaviour + { + private static TimerHelper _instance; + + public static TimerHelper Instance => _instance; + + private void Start() + { + if (_instance == null) + _instance = this; + else + { + Destroy(this); + } + } + + public void StartTimer(Action action, int time) + { + StartCoroutine(Timer(action, time)); + } + + IEnumerator Timer(Action action, int time) + { + yield return new WaitForSeconds(time); + action.Invoke(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/TimerHelper.cs.meta b/Assets/Scripts/TimerHelper.cs.meta new file mode 100644 index 00000000..65624b24 --- /dev/null +++ b/Assets/Scripts/TimerHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 031d061e6f684c0d992624e679d1a311 +timeCreated: 1641383305 \ No newline at end of file diff --git a/Assets/Scripts/Units/PlayerControl.cs b/Assets/Scripts/Units/PlayerControl.cs index b8e53e39..57c8c95b 100644 --- a/Assets/Scripts/Units/PlayerControl.cs +++ b/Assets/Scripts/Units/PlayerControl.cs @@ -1,6 +1,7 @@ using System; using Controller; using Data; +using DefaultNamespace; using DG.Tweening; using HexFiled; using Items; @@ -85,8 +86,8 @@ namespace Chars if (!_unit.IsBusy && _moveJoystick.Direction != Vector2.zero) { - - _unit.Move(VectorToDirection(_moveJoystick.Direction.normalized)); + _placeJoystick.gameObject.SetActive(false); + _unit.Move(DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized)); } if (!_unit.IsBusy && _attackJoystick.isPressed) @@ -97,46 +98,12 @@ namespace Chars if (!_unit.IsBusy && _placeJoystick.isPressed) { - _placeDirection = VectorToDirection(_placeJoystick.Direction.normalized); + _placeDirection = DirectionHelper.VectorToDirection(_placeJoystick.Direction.normalized); _cellToPlace = _unit.PlaceItemAim(_placeDirection); } } - private static HexDirection VectorToDirection(Vector2 dir) - { - if (dir.x >= 0 && dir.y <= 1 && dir.x <= 1 && dir.y >= 0.5) - { - return HexDirection.NE; - } - - if (Math.Abs(dir.x - 1f) < 0.2 && dir.y <= 0.5 && dir.y >= -0.5) - { - return HexDirection.E; - } - - if (dir.x <= 1 && dir.y <= -0.5 && dir.x >= 0 && dir.y >= -1) - { - return HexDirection.SE; - } - - if (dir.x <= 0 && dir.y >= -1 && dir.x >= -1 && dir.y <= -0.5) - { - return HexDirection.SW; - } - - if (Math.Abs(dir.x - (-1f)) < 0.2 && dir.y >= -0.5 && dir.y <= 0.5) - { - return HexDirection.W; - } - - if (dir.x >= -1 && dir.y >= 0.5 && dir.x <= 0 && dir.y <= 1) - { - return HexDirection.NW; - } - - return HexDirection.W; - } - + public void Execute() { diff --git a/Assets/Scripts/Units/Unit.cs b/Assets/Scripts/Units/Unit.cs index 035eb8b3..08df4777 100644 --- a/Assets/Scripts/Units/Unit.cs +++ b/Assets/Scripts/Units/Unit.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Chars; using Data; +using DefaultNamespace; using DG.Tweening; using HexFiled; using Items; @@ -33,12 +34,14 @@ namespace Units private BarCanvas _barCanvas; private bool _isHardToCapture; private bool _isCapturing; + private int _attackBonus; + private int _defenceBonus; public bool IsBusy => _isBusy; - public GameObject PlayerInstance => _instance; public UnitView UnitView => _unitView; public bool IsAlive => _isAlive; + public UnitColor Color => _data.color; public int InventoryCapacity => _data.inventoryCapacity; public Action OnItemPickUp; @@ -53,6 +56,28 @@ namespace Units _isCapturing = false; } + public void SetAttackBonus(int duration, int value) + { + TimerHelper.Instance.StartTimer(StopAttackBonus, duration); + _weapon.SetModifiedDamage(value); + } + + private void StopAttackBonus() + { + _weapon.SetModifiedDamage(0); + } + + public void SetDefenceBonus(int duration, int value) + { + TimerHelper.Instance.StartTimer(StopDefenceBonus, duration); + _defenceBonus = value; + } + + private void StopDefenceBonus() + { + _defenceBonus = 0; + } + public void Move(HexDirection direction) { if (!_cell.GetNeighbor(direction) || _isBusy) return; @@ -159,13 +184,22 @@ namespace Units UpdateBarCanvas(); } - public void PickUpItem(Item item) + public bool PickUpItem(ItemView itemView) { if (_inventory.Count < _data.inventoryCapacity) { + var item = itemView.PickUp(this); _inventory.Add(item); OnItemPickUp.Invoke(item); + return true; } + + return false; + } + + public void UseItem(Item item) + { + _inventory.Remove(item); } private void MoveEnd() { @@ -213,7 +247,7 @@ namespace Units ball.AddComponent().SetWeapon(_weapon); ball.transform.DOMove( new Vector3(_direction.normalized.x, - 0, _direction.normalized.y) * _weapon.disnatce * _hexGrid.HexDistance + + 0, _direction.normalized.y) * _weapon.disnatce * HexGrid.HexDistance + _instance.transform.position + new Vector3(0, 2, 0), _weapon.speed) .SetEase(Ease.Linear) @@ -290,12 +324,21 @@ namespace Units private void Damage(int dmg) { - if (_hp - dmg <= 0f) + + if (_defenceBonus == 0 && _hp - dmg <= 0f) { Death(); } - _hp -= dmg; + if (_defenceBonus > 0) + { + _defenceBonus -= dmg; + } + else + { + _hp -= dmg; + } + UpdateBarCanvas(); } } diff --git a/Assets/Scripts/Units/Views/UnitView.cs b/Assets/Scripts/Units/Views/UnitView.cs index e8bcc7c6..eea60bda 100644 --- a/Assets/Scripts/Units/Views/UnitView.cs +++ b/Assets/Scripts/Units/Views/UnitView.cs @@ -39,6 +39,7 @@ public class UnitView : MonoBehaviour public GameObject BarCanvas => barCanvas; public GameObject AimCanvas => aimCanvas; + public UnitColor Color => _unit.Color; public void SetUp(Stack shots, Weapon weapon, Action regenMana, int manaRegen, Action captureHex, Unit unit) @@ -126,16 +127,15 @@ public class UnitView : MonoBehaviour WeaponView weaponView = other.GetComponent(); if (weaponView != null) { - OnHit?.Invoke(weaponView.Weapon.damage); + OnHit?.Invoke(weaponView.Weapon.modifiedDamage); other.transform.DOKill(); Destroy(other.gameObject); } ItemView itemView = other.GetComponent(); - if (itemView != null) + if (itemView != null && _unit.PickUpItem(itemView)) { - _unit.PickUpItem(itemView.PickUp(_unit)); Destroy(itemView.gameObject); } } diff --git a/Assets/Scripts/Weapons/Weapon.cs b/Assets/Scripts/Weapons/Weapon.cs index 904bf1ee..c602d385 100644 --- a/Assets/Scripts/Weapons/Weapon.cs +++ b/Assets/Scripts/Weapons/Weapon.cs @@ -10,7 +10,7 @@ namespace Weapons public GameObject icon; public GameObject objectToThrow; public GameObject VFXGameObject; - public int manaCost; + public int modifiedDamage; public int damage; public float speed; public int disnatce; @@ -18,5 +18,10 @@ namespace Weapons public int shots; public AudioClip shotSound; public AudioClip hitSound; + + public void SetModifiedDamage(int bonus) + { + modifiedDamage = damage + bonus; + } } } \ No newline at end of file diff --git a/Assets/TowerView.cs b/Assets/TowerView.cs new file mode 100644 index 00000000..add12d41 --- /dev/null +++ b/Assets/TowerView.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using DefaultNamespace; +using DG.Tweening; +using HexFiled; +using Units; +using UnityEngine; +using Weapons; + +public class TowerView : MonoBehaviour +{ + private UnitColor _color; + private GameObject _target; + [SerializeField] private Weapon weapon; + + + public void SetUp(UnitColor unitColor) + { + _color = unitColor; + GetComponent().material.mainTexture = HexGrid.Colors[unitColor].BuildingTexture; + } + + private void OnCollisionEnter(Collision collision) + { + var unit = collision.gameObject.GetComponent(); + if (unit != null && unit.Color != _color) + { + _target = unit.gameObject; + StartCoroutine(Shot()); + } + } + + private void OnCollisionExit(Collision other) + { + if (_target == other.gameObject) + { + _target = null; + } + } + + private IEnumerator Shot() + { + while (_target != null) + { + yield return new WaitForSecondsRealtime(weapon.reloadTime); + + var direction = DirectionHelper.DirectionTo(transform.position, _target.transform.position); + var ball = Instantiate(weapon.objectToThrow, + transform.forward + transform.position + new Vector3(0, 2), + Quaternion.FromToRotation(transform.position, _target.transform.position)); + + MusicController.Instance.AddAudioSource(ball); + MusicController.Instance.PlayAudioClip(weapon.shotSound, ball); + + ball.AddComponent().SetWeapon(weapon); + ball.transform.DOMove( + new Vector3(direction.x, + 0, direction.z) * weapon.disnatce * HexGrid.HexDistance + + transform.position + new Vector3(0, 2, 0), + weapon.speed) + .SetEase(Ease.Linear) + .OnComplete(() => Destroy(ball)); + } + } +} \ No newline at end of file diff --git a/Assets/TowerView.cs.meta b/Assets/TowerView.cs.meta new file mode 100644 index 00000000..c2be4c30 --- /dev/null +++ b/Assets/TowerView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5db196e1099b97246bde07a348189567 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: