Skip to content

Commit 7fbbace

Browse files
code refactoring
1 parent 42fad34 commit 7fbbace

29 files changed

+58
-64
lines changed

Attributes/Health.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ public void TakeDamage(GameObject instigator, float damage) {
8181
}
8282
}
8383

84+
public void Heal(float healthPercentToRestore) {
85+
healthPoints.value = Mathf.Min(healthPoints.value + (MaxHealthPoints * healthPercentToRestore / 100), MaxHealthPoints);
86+
if (onHealthUpdate != null) {
87+
onHealthUpdate();
88+
}
89+
}
90+
91+
public object CaptureState() {
92+
return healthPoints.value;
93+
}
94+
95+
public void RestoreState(object state) {
96+
healthPoints.value = (float) state;
97+
if (healthPoints.value <= 0) {
98+
Die();
99+
}
100+
}
101+
84102
private void AwardExperience(GameObject instigator) {
85103
Experience experience = instigator.GetComponent<Experience>();
86104
if (experience == null) {
@@ -110,23 +128,5 @@ private void Die() {
110128
actionScheduler.CancelCurrentAction();
111129
IsDead = true;
112130
}
113-
114-
public void Heal(float healthPercentToRestore) {
115-
healthPoints.value = Mathf.Min(healthPoints.value + (MaxHealthPoints * healthPercentToRestore / 100), MaxHealthPoints);
116-
if (onHealthUpdate != null) {
117-
onHealthUpdate();
118-
}
119-
}
120-
121-
public object CaptureState() {
122-
return healthPoints.value;
123-
}
124-
125-
public void RestoreState(object state) {
126-
healthPoints.value = (float) state;
127-
if (healthPoints.value <= 0) {
128-
Die();
129-
}
130-
}
131131
}
132132
}

Combat/CombatTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RPG.Attributes;
2-
using RPG.UI;
2+
using RPG.Core;
33
using UnityEngine;
44

55
namespace RPG.Combat {

Combat/HealthPickup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@ private void OnTriggerEnter(Collider other) {
1414
}
1515
}
1616

17+
private void Pickup(Health health, GameObject healFX, float healthPercentToRestore, bool respawnable, float respawnTime) {
18+
Instantiate(healFX, health.transform);
19+
health.Heal(healthPercentToRestore);
20+
base.Pickup(respawnable, respawnTime);
21+
}
22+
1723
}
1824
}

Combat/PickupBase.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections;
22
using RPG.Attributes;
3+
using RPG.Core;
34
using RPG.Movement;
4-
using RPG.UI;
55
using UnityEngine;
66
using UnityEngine.Events;
77

@@ -33,18 +33,7 @@ private void ShowPickup(bool shouldShow) {
3333
}
3434
}
3535

36-
public void Pickup(Health health, GameObject healFX, float healthPercentToRestore, bool respawnable, float respawnTime) {
37-
Instantiate(healFX, health.transform);
38-
health.Heal(healthPercentToRestore);
39-
if (respawnable) {
40-
StartCoroutine(HideForSeconds(respawnTime));
41-
} else {
42-
Destroy(gameObject);
43-
}
44-
}
45-
46-
public void Pickup(Fighter fighter, WeaponConfig weapon, bool respawnable, float respawnTime) {
47-
fighter.EquipWeapon(weapon);
36+
public void Pickup(bool respawnable, float respawnTime) {
4837
if (respawnable) {
4938
StartCoroutine(HideForSeconds(respawnTime));
5039
} else {

Combat/WeaponConfig.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class WeaponConfig : ScriptableObject {
1717
private const string DESTORYING = "Destroying";
1818
private enum HAND { LEFT, RIGHT }
1919

20+
public float Range => weaponRange;
21+
public float Damage => weaponDamage;
22+
public float PercentageBous => percentageBonus;
23+
2024
public Transform GetTransform(Transform rightHand, Transform leftHand) {
2125
return hand == HAND.RIGHT ? rightHand : leftHand;
2226
}
@@ -58,11 +62,5 @@ public void LaunchProjectile(Transform rightHand, Transform leftHand, Health tar
5862
Projectile projectileInstance = Instantiate(projectile, GetTransform(rightHand, leftHand).position, Quaternion.identity);
5963
projectileInstance.SetTarget(target, instigator, calculatedDamage, updateUI);
6064
}
61-
62-
public float Range => weaponRange;
63-
64-
public float Damage => weaponDamage;
65-
66-
public float PercentageBous => percentageBonus;
6765
}
6866
}

Combat/WeaponPickup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ private void OnTriggerEnter(Collider other) {
1010
if (other.gameObject.CompareTag("Player")) {
1111
Pickup(other.GetComponent<Fighter>(), weapon, respawnable, respawnTime);
1212
}
13+
14+
}
15+
16+
public void Pickup(Fighter fighter, WeaponConfig weapon, bool respawnable, float respawnTime) {
17+
fighter.EquipWeapon(weapon);
18+
base.Pickup(respawnable, respawnTime);
1319
}
1420
}

Control/AIController.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ private void AggrevateNearbyEnemies() {
9292
continue;
9393
}
9494
ai.Aggrevate();
95-
9695
}
9796
}
9897

@@ -108,7 +107,7 @@ private void PatrolBehaviour() {
108107
Vector3 nextPosition = guardPosition.value;
109108

110109
if (patrolPath != null) {
111-
if (AtWayPoint()) {
110+
if (IsAtWayPoint()) {
112111
if (dwellTime < timeSinceLastWaypoint) {
113112
timeSinceLastWaypoint = 0f;
114113
CycleWaypoint();
@@ -121,7 +120,7 @@ private void PatrolBehaviour() {
121120
mover.StartMovement(nextPosition, patrolSpeedFraction);
122121
}
123122

124-
private bool AtWayPoint() {
123+
private bool IsAtWayPoint() {
125124
return IsTargetInRange(transform, GetCurrentWaypoint(), wayPointTolerance);
126125
}
127126

@@ -141,6 +140,5 @@ private void OnDrawGizmosSelected() {
141140
public void Aggrevate() {
142141
timeSinceAggrevated = 0;
143142
}
144-
145143
}
146144
}

Control/PlayerController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using RPG.Attributes;
3+
using RPG.Core;
34
using RPG.Movement;
4-
using RPG.UI;
55
using UnityEngine;
66
using UnityEngine.AI;
77
using UnityEngine.EventSystems;

UI/CursorType.cs renamed to Core/CursorType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RPG.UI {
1+
namespace RPG.Core {
22
public enum CursorType {
33
None,
44
Movement,

0 commit comments

Comments
 (0)