Skip to content

Commit 35ad660

Browse files
committed
New damage & weapon system
1 parent c26c917 commit 35ad660

21 files changed

+235
-244
lines changed

AttkType.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public enum AttkType
2+
{
3+
none,
4+
slash,
5+
crush,
6+
pierce
7+
8+
}

Creatures/CreatureCurHpSpMpManager.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

Creatures/CreatureModifyableProperties.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
public class CreatureModifyableProperties : MonoBehaviour
99
{
1010
public Creature Creature { get; private set; }
11+
public Health Health { get; private set; }
1112
private void Awake()
1213
{
1314
Creature = GetComponent<Creature>();
15+
Health = GetComponent<Health>();
1416
}
1517

1618
/// <summary>

Creatures/Health.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class Health : MonoBehaviour
6+
{
7+
private Creature self;
8+
public int CurHP { get; private set; }
9+
10+
void Start()
11+
{
12+
self = GetComponent<Creature>();
13+
CurHP = self.MaxHealth;
14+
}
15+
16+
17+
public void TakeDamage(int amount)
18+
{
19+
if(amount > 0)
20+
Debug.Log(gameObject.name + " was damaged! (" + amount + "). Remainder " + (CurHP - amount) + ".");
21+
CurHP -= Mathf.Abs(amount);
22+
if (CurHP <= 0) Destroy(gameObject);
23+
}
24+
25+
26+
}

Creatures/Humanoid.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
public class Humanoid : Creature
66
{
7-
public GameObject leftHandEquip, rightHandEquip;
8-
97
#region Movement.
108
/// <summary>
119
/// Current acceleration/deceleration to 'dynamix max speed'.
@@ -45,17 +43,6 @@ void Update()
4543
SetCurSpdAccel(); // Calc and apply cur accel.
4644

4745
MoveHumanoid();
48-
49-
if(!InCombat)
50-
{
51-
leftHandEquip.SetActive(false);
52-
rightHandEquip.SetActive(false);
53-
}
54-
else
55-
{
56-
leftHandEquip.SetActive(true);
57-
rightHandEquip.SetActive(true);
58-
}
5946
}
6047

6148

Creatures/HumanoidAnim.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class HumanoidAnim : MonoBehaviour
88
private CharacterController cc;
99
private Animator anim;
1010

11+
public AttkType CurValidAttk { get; private set; }
12+
1113
private int combatRollState;
1214
private int jumpState;
1315
private int combatMoveState;
@@ -25,13 +27,14 @@ public class HumanoidAnim : MonoBehaviour
2527
private bool inRollState = false;
2628
private bool inSlideState = false;
2729
public bool InAttkState { get; private set; } = false;
28-
30+
private float defaultColliderHeight;
2931
// Start is called before the first frame update
3032
void Start()
3133
{
3234
cc = GetComponent<CharacterController>();
3335
anim = GetComponent<Animator>();
34-
36+
37+
defaultColliderHeight = cc.height;
3538

3639
combatRollState = Animator.StringToHash("Base Layer.Combat_Roll");
3740
jumpState = Animator.StringToHash("Base Layer.Jump");
@@ -43,8 +46,7 @@ void Start()
4346

4447
public float AttkRotationPenalty { get; private set; }
4548

46-
bool dd = false;
47-
int attkVariant = 1;
49+
4850

4951
AnimatorStateInfo prevState;
5052

@@ -87,7 +89,7 @@ public void UpateAnimator(
8789
anim.SetFloat("Vertical", vertical, .045f, Time.deltaTime);
8890
anim.SetInteger("RollDir", rollDir);
8991
anim.SetBool("InAttkState", InAttkState);
90-
cc.height = anim.GetFloat("Collider_Scale");
92+
cc.height = anim.GetFloat("Collider_Scale") * defaultColliderHeight;
9193
if (cc.height == 0) cc.height = 1f;
9294
cc.center = new Vector3(cc.center.x, cc.height * .6f, cc.center.z);
9395

@@ -126,8 +128,12 @@ void AttackAnim(AttkType requestedAttk)
126128
curAttk = AttkType.none;
127129

128130
anim.SetInteger("attkType", (int)curAttk);
131+
132+
// Update last type of attack.
133+
if (curAttk != AttkType.none)
134+
CurValidAttk = curAttk;
129135
}
130-
public enum AttkType { none, swing, overhead, lunge };
136+
131137
private AttkType quedAttk = AttkType.none;
132138
private AttkType curAttk = AttkType.none;
133139
private bool newAttkQued = false;

Creatures/HumanoidBasicEnemy.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,26 @@ void Start()
1616
humanoid.InCombat = false;
1717
}
1818

19-
// Update is called once per frame
19+
2020
void Update()
2121
{
2222
Vector3 MoveDir = target.transform.position - transform.position;
2323
humanoid.Rotate(MoveDir, 1);
2424
humanoid.SetMoveState(Humanoid.moveEnum.Walk);
25-
anim.UpateAnimator(humanoid.Grounded, false, humanoid.InCombat, humanoid.CurSpeed, false, MoveDir.x, MoveDir.z, HumanoidAnim.AttkType.none, false, 0, false);
25+
26+
AttkType attk = AttkType.none;
27+
if (Vector3.Distance(transform.position, target.transform.position) < 2)
28+
{
29+
humanoid.InCombat = true;
30+
attk = AttkType.crush;
31+
}
32+
else
33+
{
34+
humanoid.InCombat = false;
35+
}
36+
37+
38+
anim.UpateAnimator(humanoid.Grounded, false, humanoid.InCombat, humanoid.CurSpeed, false, MoveDir.x, MoveDir.z, attk, false, 0, false);
2639
}
2740
}
41+

Creatures/HumanoidEventHandler.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

Creatures/HumanoidPlayer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private void Start()
2121

2222

2323

24-
HumanoidAnim.AttkType RequestedAttack = HumanoidAnim.AttkType.none;
24+
AttkType RequestedAttack = AttkType.none;
2525
RollDir rollDir = RollDir.None;
2626
void Update()
2727
{
@@ -42,17 +42,17 @@ void Update()
4242

4343

4444

45-
RequestedAttack = HumanoidAnim.AttkType.none;
45+
RequestedAttack = AttkType.none;
4646
// Attack when attack button clicked.
4747
if (Input.GetAxis("Mouse ScrollWheel") > 0)
48-
RequestedAttack = HumanoidAnim.AttkType.lunge;
48+
RequestedAttack = AttkType.pierce;
4949

5050
// Attack when attack button clicked.
5151
else if (Input.GetAxis("Mouse ScrollWheel") < 0)
52-
RequestedAttack = HumanoidAnim.AttkType.overhead;
52+
RequestedAttack = AttkType.crush;
5353

5454
if (Input.GetButton("Fire1"))
55-
RequestedAttack = HumanoidAnim.AttkType.swing;
55+
RequestedAttack = AttkType.slash;
5656

5757

5858

Effects & Effector/BlockMoveEffect.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)