瀏覽代碼

Settings and errors fixed

Axel Nordh 4 年之前
父節點
當前提交
d7c386206e

+ 6 - 0
.editorconfig

@@ -0,0 +1,6 @@
+root=true
+
+[*.cs]
+dotnet_diagnostic.IDE0051.severity = none
+dotnet_diagnostic.IDE0055.severity = none
+dotnet_diagnostic.IDE0044.severity = none

+ 4 - 2
.vscode/settings.json

@@ -50,7 +50,6 @@
     "temp/": true,
     "Temp/": true
   },
-  "editor.codeLens": false,
 
   "sonarlint.connectedMode.project": {
     "connectionId": "RPG-FIGHT-CON-ID",
@@ -60,6 +59,9 @@
     "sonarlint.ls.javaHome": "C:\\Program Files\\Java\\jdk-14.0.2",
     "sonarqube-rules-synchroniser.Sonarqube-projectkey": "RPG-FIGHT",
     "sonarqube-rules-synchroniser.Sonarqube-token": "e9d671ab4c1eccfe367249f2975425ca924ffcfd",
-    "sonarqube-rules-synchroniser.Sonarqube-url": "nordh.xyz:12366"
+    "sonarqube-rules-synchroniser.Sonarqube-url": "nordh.xyz:12366",
+    "omnisharp.analyzeOpenDocumentsOnly": false,
+    "omnisharp.enableRoslynAnalyzers": false,
+
 
 }

+ 20 - 26
Assets/CameraManager.cs

@@ -1,52 +1,46 @@
-using System.Collections;
-using System.Collections.Generic;
 using Cinemachine;
 using UnityEngine;
 
-public class CameraManager : MonoBehaviour
-{
+public class CameraManager : MonoBehaviour {
     private CinemachineVirtualCamera activeCam;
 
     private static CameraManager instance;
 
-    public static CameraManager getInstance()
-    {
+    public static CameraManager GetInstance() {
         return instance;
     }
 
-    private void Start()
-    {
+    private void Start() {
         instance = this;
     }
 
-    private void Update()
-    {
-        if (Input.GetAxis("Mouse ScrollWheel") != 0f)
-        {
-            CinemachineComponentBase componentBase = activeCam.GetCinemachineComponent(CinemachineCore.Stage.Body);
-            if (componentBase is CinemachineFramingTransposer)
-            {
-                float m_CameraDistance = (componentBase as CinemachineFramingTransposer).m_CameraDistance;
-                if (m_CameraDistance <= 1 && Input.GetAxis("Mouse ScrollWheel") > 0)
-                {
+    private void Update() {
+        if (Input.GetAxis("Mouse ScrollWheel") != 0f) {
+            CinemachineComponentBase componentBase =
+                activeCam.GetCinemachineComponent(CinemachineCore.Stage.Body);
+            if (componentBase is CinemachineFramingTransposer) {
+                float m_CameraDistance =
+                    (componentBase as CinemachineFramingTransposer)
+                        .m_CameraDistance;
+                if (
+                    m_CameraDistance <= 1 &&
+                    Input.GetAxis("Mouse ScrollWheel") > 0
+                ) {
                     m_CameraDistance = 1f;
-                }
-                else
-                {
+                } else {
                     m_CameraDistance -= Input.GetAxis("Mouse ScrollWheel") * 10;
                 }
-                (componentBase as CinemachineFramingTransposer).m_CameraDistance = m_CameraDistance;
+                (componentBase as CinemachineFramingTransposer)
+                    .m_CameraDistance = m_CameraDistance;
             }
         }
     }
 
-    private void Awake()
-    {
+    private void Awake() {
         activeCam = GetComponentInChildren<CinemachineVirtualCamera>();
     }
 
-    public void focusOnGameObject(GameObject gameObject)
-    {
+    public void FocusOnGameObject(GameObject gameObject) {
         activeCam.Follow = gameObject.transform;
     }
 }

+ 2 - 4
Assets/Scripts/Creatures/Actions/AttackAction.cs

@@ -2,12 +2,10 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
-public class AttackAction : Action
-{
+public class AttackAction : Action {
     Creature target;
 
-    public AttackAction(Creature target)
-    {
+    public AttackAction(Creature target) {
         this.target = target;
     }
 }

+ 3 - 6
Assets/Scripts/Creatures/Actions/MoveAction.cs

@@ -2,18 +2,15 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
-public class MoveAction : Action
-{
+public class MoveAction : Action {
     Sprite startPosition;
     Sprite targetPosition;
 
-    public void setStartPosition(Sprite startSprite)
-    {
+    public void SetStartPosition(Sprite startSprite) {
         startPosition = startSprite;
     }
 
-    public void setTargetPosition(Sprite targetSprite)
-    {
+    public void SetTargetPosition(Sprite targetSprite) {
         targetPosition = targetSprite;
     }
 }

+ 19 - 28
Assets/Scripts/Creatures/Creature.cs

@@ -4,8 +4,7 @@ using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;
 
-public class Creature : MonoBehaviour
-{
+public class Creature : MonoBehaviour {
 
     [SerializeField] Sprite creatureImage;
     [SerializeField] bool humanControlled;
@@ -26,63 +25,55 @@ public class Creature : MonoBehaviour
 
     public int Init { get => init; set => init = value; }
 
-    private void Start()
-    {
+    private void Start() {
         canvasGroup = GetComponent<CanvasGroup>();
         rectTransform = GetComponent<RectTransform>();
     }
 
-    public int getInit()
-    {
+    public int GetInit() {
         return Init;
     }
 
-    public void rollInit()
-    {
+    public void RollInit() {
         Init = Random.Range(0, 100 - dex);
     }
 
-    public Sprite getSprite()
-    {
+    public Sprite GetSprite() {
         return creatureImage;
     }
 
-    public bool isHumanControlled()
-    {
+    public bool IsHumanControlled() {
         return humanControlled;
     }
 
-    public void setFirstAction(Action action)
-    {
+    public void SetFirstAction(Action action) {
         firstAction = action;
     }
 
-    public void setSecondAction(Action action)
-    {
+    public void SetSecondAction(Action action) {
         secondAction = action;
     }
 
-    internal List<Creature> enemiesInSquareNextToCreature(Creature creature, List<Creature> combatants)
-    {
-        List<Creature> enemiesClose = new List<Creature>();
-        foreach (Creature c in combatants)
-        {
-            Vector3 distance = c.getCurrentPosition() - creature.getCurrentPosition();
-            if (c.name != creature.name && distance.x <= 1 && distance.x >= -1 && distance.y <= 1 && distance.y >= -1)
-            {
+    internal List<Creature> EnemiesInSquareNextToCreature(Creature creature, List<Creature> combatants) {
+        List<Creature> enemiesClose = new();
+        foreach (Creature c in combatants) {
+            Vector3 distance = c.GetCurrentPosition() - creature.GetCurrentPosition();
+            if (c.name != creature.name && distance.x <= 1 && distance.x >= -1 && distance.y <= 1 && distance.y >= -1) {
                 enemiesClose.Add(c);
             }
         }
         return enemiesClose;
     }
 
-    internal void setPositionInGrid(Vector3Int vector3Int)
-    {
+    internal void SetPositionInGrid(Vector3Int vector3Int) {
         currentPos = vector3Int;
     }
 
-    public Vector3Int getCurrentPosition()
-    {
+    public Vector3Int GetCurrentPosition() {
         return currentPos;
     }
+
+    public bool HasFirstAction() {
+        return firstAction != null;
+    }
 }

+ 1 - 1
Assets/Scripts/Creatures/GenerateSkeletonScript.cs

@@ -20,6 +20,6 @@ public class GenerateSkeletonScript : MonoBehaviour {
         mousePos.z = Camera.main.transform.position.z + Camera.main.nearClipPlane;
         generatedSkelleton.transform.position = mousePos;
 
-        generatedSkelleton.GetComponent<NewSkeletonSpriteScript>().isDragged(true);
+        generatedSkelleton.GetComponent<NewSkeletonSpriteScript>().IsDragged(true);
     }
 }

+ 20 - 12
Assets/Scripts/Creatures/Skeleton.cs

@@ -2,24 +2,32 @@ using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 
-namespace RPG_Fight_Test.Assets.Scripts.Creatures
-{
-    public class Skeleton : Creature
-    {
-        private void Start()
-        {
+namespace RPG_Fight_Test.Assets.Scripts.Creatures {
+    public class Skeleton : Creature {
+        private void Start() {
             Dex = Random.Range(0, 20);
         }
 
-        public void decideActions(List<Creature> combatants)
-        {
-            List<Creature> closeEnemies = enemiesInSquareNextToCreature(this, combatants);
+        public void DecideActions(List<Creature> combatants) {
+            List<Creature> closeEnemies = EnemiesInSquareNextToCreature(this, combatants);
 
             Debug.Log("Number of close enemies " + closeEnemies.Count);
-            if (closeEnemies.Count > 0)
-            {
-                setFirstAction(new AttackAction(closeEnemies[0]));
+            if (closeEnemies.Count > 0) {
+                if (!HasFirstAction()) {
+                    SetFirstAction(new AttackAction(closeEnemies[0]));
+                } else {
+                    SetSecondAction(new AttackAction(closeEnemies[0]));
+                }
+            } else {
+                /*if (shouldMove())
+                {
+                    setFirstAction(new MoveAction());
+                }*/
             }
         }
+
+        public void ShowInfo() {
+
+        }
     }
 }

+ 2 - 2
Assets/Scripts/Die.cs

@@ -3,12 +3,12 @@ using System;
 internal class Die {
 
     int sides;
-    Random rnd = new Random();
+    Random rnd = new();
     Die(int sides) {
         this.sides = sides;
     }
 
-    public int rollDie() {
+    public int RollDie() {
         return rnd.Next(1, sides);
     }
 

+ 24 - 39
Assets/Scripts/GameManagerScript.cs

@@ -8,8 +8,7 @@ using UnityEngine.Tilemaps;
 using UnityEngine.UI;
 
 
-public class GameManagerScript : MonoBehaviour
-{
+public class GameManagerScript : MonoBehaviour {
     CinemachineBrain camBrain;
 
     RoundManager roundManager;
@@ -22,87 +21,73 @@ public class GameManagerScript : MonoBehaviour
     [SerializeField] Grid grid;
     [SerializeField] Tilemap tileMap;
 
-    List<Creature> combatants = new List<Creature>();
+    List<Creature> combatants = new();
 
     static GameManagerScript instance;
-    public static GameManagerScript getInstance()
-    {
+    public static GameManagerScript GetInstance() {
         return instance;
     }
 
-    private void Start()
-    {
+    private void Start() {
         instance = this;
         combatants.AddRange(enemies.Select(e => e.GetComponent<Creature>()));
         combatants.AddRange(humans.Select(h => h.GetComponent<Creature>()));
     }
 
-    private void Awake()
-    {
-        if (camBrain == null)
-        {
+    private void Awake() {
+        if (camBrain == null) {
             camBrain = Camera.main.GetComponent<CinemachineBrain>();
         }
 
-        if (roundManager == null)
-        {
+        if (roundManager == null) {
             roundManager = GameObject.Find("RoundManager").GetComponent<RoundManager>();
         }
     }
 
-    public CinemachineVirtualCamera getActiveCamera()
-    {
+    public CinemachineVirtualCamera GetActiveCamera() {
         CinemachineVirtualCamera cam = camBrain.ActiveVirtualCamera as CinemachineVirtualCamera;
 
         return cam;
     }
 
-    internal void rollInitiative()
-    {
-        combatants.ForEach(creature =>
-        {
-            creature.rollInit();
+    internal void RollInitiative() {
+        combatants.ForEach(creature => {
+            creature.RollInit();
         });
 
-        combatants.Sort((x, y) => x.getInit().CompareTo(y.getInit()));
-        clearInitPanel();
-        buildInitPanel();
-        roundManager.startFirstRound(combatants);
+        combatants.Sort((x, y) => x.GetInit().CompareTo(y.GetInit()));
+        ClearInitPanel();
+        BuildInitPanel();
+        roundManager.StartFirstRound(combatants);
     }
 
-    private void clearInitPanel()
-    {
+    private void ClearInitPanel() {
         int children = initPanel.transform.childCount;
-        for (int i = children - 1; i >= 0; i--)
-        {
+        for (int i = children - 1; i >= 0; i--) {
             GameObject.Destroy(initPanel.transform.GetChild(i).gameObject);
         }
     }
 
-    public void showInitPanel(Boolean show)
-    {
+    public void ShowInitPanel(Boolean show) {
         initPanel.SetActive(show);
     }
 
-    internal void buildInitPanel()
-    {
+    internal void BuildInitPanel() {
         initPanel.SetActive(true);
-        combatants.ForEach(c =>
-        {
+        combatants.ForEach(c => {
             GameObject creturePanel = GameObject.Instantiate(initCreaturePanel, Vector3.zero, Quaternion.identity);
             creturePanel.transform.localScale = new Vector3(1, 1, 1);
             creturePanel.transform.SetParent(initPanel.transform);
-            creturePanel.GetComponent<InitCreaturePanelScript>().setImage(c.GetComponent<Creature>().getSprite());
+            creturePanel.GetComponent<InitCreaturePanelScript>().SetImage(c.GetComponent<Creature>().GetSprite());
 
-            Debug.Log(c.name + " init: " + c.GetComponent<Creature>().getInit() + " Dex " + c.GetComponent<Creature>().Dex + " pos: " + grid.WorldToCell(c.transform.localPosition));
+            Debug.Log(c.name + " init: " + c.GetComponent<Creature>().GetInit() + " Dex " + c.GetComponent<Creature>().Dex + " pos: " + grid.WorldToCell(c.transform.localPosition));
 
-            c.setPositionInGrid(grid.WorldToCell(c.transform.localPosition));
+            c.SetPositionInGrid(grid.WorldToCell(c.transform.localPosition));
         });
 
     }
 
-    public List<Creature> getCombatants()
-    {
+    public List<Creature> GetCombatants() {
         return combatants;
     }
 }

+ 1 - 1
Assets/Scripts/NewSkeletonSpriteScript.cs

@@ -13,7 +13,7 @@ public class NewSkeletonSpriteScript : MonoBehaviour {
         }
     }
 
-    internal void isDragged(bool value) {
+    internal void IsDragged(bool value) {
         dragged = value;
     }
 }

+ 3 - 6
Assets/Scripts/Panels/InitPanel/InitCreaturePanelScript.cs

@@ -3,17 +3,14 @@ using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
-public class InitCreaturePanelScript : MonoBehaviour
-{
+public class InitCreaturePanelScript : MonoBehaviour {
     private Image creatureImage;
 
-    private void Awake()
-    {
+    private void Awake() {
         creatureImage = GetComponent<Image>();
     }
 
-    public void setImage(Sprite sprite)
-    {
+    public void SetImage(Sprite sprite) {
         creatureImage.sprite = sprite;
     }
 }

+ 4 - 7
Assets/Scripts/Panels/StartFightPanel/StartFightScript.cs

@@ -4,18 +4,15 @@ using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
-public class StartFightScript : MonoBehaviour
-{
+public class StartFightScript : MonoBehaviour {
     [SerializeField] Button startFightButton;
 
-    void Start()
-    {
+    void Start() {
         startFightButton.onClick.AddListener(StartFightAction);
     }
 
-    private void StartFightAction()
-    {
-        GameManagerScript.getInstance().rollInitiative();
+    private void StartFightAction() {
+        GameManagerScript.GetInstance().RollInitiative();
         gameObject.SetActive(false);
     }
 }

+ 9 - 16
Assets/Scripts/RoundManager.cs

@@ -5,29 +5,22 @@ using System.Linq;
 using RPG_Fight_Test.Assets.Scripts.Creatures;
 using UnityEngine;
 
-public class RoundManager : MonoBehaviour
-{
+public class RoundManager : MonoBehaviour {
     private List<Creature> combatants;
     int round;
-    internal void startFirstRound(List<Creature> combatants)
-    {
+    internal void StartFirstRound(List<Creature> combatants) {
         this.combatants = combatants;
         round = 1;
-        makeDecisions();
+        MakeDecisions();
     }
 
-    private void makeDecisions()
-    {
-        foreach (Creature creature in combatants)
-        {
-            if (creature.isHumanControlled())
-            {
-                CameraManager.getInstance().focusOnGameObject(creature.gameObject);
+    private void MakeDecisions() {
+        foreach (Creature creature in combatants) {
+            if (creature.IsHumanControlled()) {
+                CameraManager.GetInstance().FocusOnGameObject(creature.gameObject);
                 // Wait for human decision
-            }
-            else
-            {
-                ((Skeleton)creature).decideActions(combatants);
+            } else {
+                ((Skeleton)creature).DecideActions(combatants);
                 // AI make decision
             }
         }

+ 1 - 1
Assets/Scripts/Weapon.cs

@@ -24,7 +24,7 @@ internal class Weapon {
     DAMAGE_TYPE damageType;
     WEAPON_TYPE weaponType;
 
-    public Die getAttackDie() {
+    public Die GetAttackDie() {
         return attackDie;
     }
 

+ 17 - 0
omnisharp.json

@@ -0,0 +1,17 @@
+
+{
+    "FormattingOptions": {
+        "NewLinesForBracesInLambdaExpressionBody": false,
+        "NewLinesForBracesInAnonymousMethods": false,
+        "NewLinesForBracesInAnonymousTypes": false,
+        "NewLinesForBracesInControlBlocks": false,
+        "NewLinesForBracesInTypes": false,
+        "NewLinesForBracesInMethods": false,
+        "NewLinesForBracesInProperties": false,
+        "NewLinesForBracesInObjectCollectionArrayInitializers": false,
+        "NewLinesForBracesInAccessors": false,
+        "NewLineForElse": false,
+        "NewLineForCatch": false,
+        "NewLineForFinally": false
+    }
+}