Implemented forced fight, updated attack range to be closer to player.
This commit is contained in:
@@ -145,7 +145,7 @@ public class Controls : MonoBehaviour
|
||||
switch (target.tag.Split(':')[1])
|
||||
{
|
||||
case "Enemy":
|
||||
fight.GetComponent<Fight>().startFight(worldGen.GetComponent<WorldGenerator>().getCurrentTile(), target, player);
|
||||
fight.GetComponent<Fight>().startFight(worldGen.GetComponent<WorldGenerator>().getCurrentTile(), target, player, true);
|
||||
break;
|
||||
case "Tree":
|
||||
player.GetComponent<PlayerGameObject>().getPlayer().getStat("TreeCount").changeAmount(1);
|
||||
|
||||
@@ -14,12 +14,16 @@ public class Fight : MonoBehaviour
|
||||
GameObject player;
|
||||
System.Random rand = new System.Random();
|
||||
UIHandler uihandler;
|
||||
bool isFleeable = true;
|
||||
public bool isFightActive = false;
|
||||
|
||||
public void startFight(GameObject tile, GameObject enemy, GameObject player)
|
||||
public void startFight(GameObject tile, GameObject enemy, GameObject player, bool isFleeable)
|
||||
{
|
||||
isFightActive = true;
|
||||
this.tile = tile;
|
||||
this.enemy = enemy;
|
||||
this.player = player;
|
||||
this.isFleeable = isFleeable;
|
||||
enemy.GetComponent<Enemy>().scaleEnemy(player.GetComponent<PlayerGameObject>());
|
||||
enemy.transform.rotation = Quaternion.Euler(0, GameObject.Find("Main Camera").transform.rotation.y, 0);
|
||||
|
||||
@@ -31,6 +35,7 @@ public class Fight : MonoBehaviour
|
||||
|
||||
private void endFight()
|
||||
{
|
||||
isFightActive = false;
|
||||
uihandler.closeFight();
|
||||
}
|
||||
|
||||
@@ -42,7 +47,7 @@ public class Fight : MonoBehaviour
|
||||
switch (index)
|
||||
{
|
||||
case 1:
|
||||
if (rand.Next(1, 11) <= 3)
|
||||
if (rand.Next(1, 11) <= 3 && isFleeable)
|
||||
{
|
||||
escapedSuccesfully = true;
|
||||
endFight();
|
||||
@@ -50,7 +55,14 @@ public class Fight : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("escapeFail"));
|
||||
if (isFleeable)
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("escapeFail"));
|
||||
}
|
||||
else
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("escapeFailForced"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
|
||||
@@ -19,9 +19,7 @@ namespace Assets.Scripts.InteractableObjects
|
||||
bool isJumping;
|
||||
Stopwatch jumpTimer;
|
||||
bool followsPlayer;
|
||||
bool isAttacking;
|
||||
bool isAttackOnCooldown;
|
||||
Stopwatch attackTimer;
|
||||
Fight fight;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -30,33 +28,14 @@ namespace Assets.Scripts.InteractableObjects
|
||||
jumpTimer = new Stopwatch();
|
||||
jumpTimer.Start();
|
||||
followsPlayer = false;
|
||||
isAttacking = false;
|
||||
isAttackOnCooldown = false;
|
||||
attackTimer = new Stopwatch();
|
||||
fight = GameObject.Find("Fight").GetComponent<Fight>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(fight.isFightActive) return;
|
||||
Jump();
|
||||
if (isAttacking)
|
||||
{
|
||||
Attack();
|
||||
}
|
||||
}
|
||||
|
||||
void Attack()
|
||||
{
|
||||
if (!isAttackOnCooldown)
|
||||
{
|
||||
attackTimer.Start();
|
||||
isAttackOnCooldown = true;
|
||||
}
|
||||
if (attackTimer.ElapsedMilliseconds >= 2000)
|
||||
{
|
||||
attackTimer.Reset();
|
||||
isAttackOnCooldown = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Jump()
|
||||
@@ -95,16 +74,12 @@ namespace Assets.Scripts.InteractableObjects
|
||||
|
||||
public void HandleAttack()
|
||||
{
|
||||
isAttacking = true;
|
||||
//Create attack logic here
|
||||
//TODO: Force Fight start
|
||||
}
|
||||
|
||||
public void handleFollow(bool isFollowing)
|
||||
{
|
||||
followsPlayer = isFollowing;
|
||||
isAttacking = false;
|
||||
attackTimer.Reset();
|
||||
isAttackOnCooldown = false;
|
||||
}
|
||||
|
||||
public void HandleDetection()
|
||||
|
||||
@@ -253,7 +253,7 @@ namespace Assets.Scripts.Player
|
||||
switch (col.name)
|
||||
{
|
||||
case "AttackRange":
|
||||
enemy.HandleAttack();
|
||||
GameObject.Find("Fight").GetComponent<Fight>().startFight(worldGenerator.GetComponent<WorldGenerator>().getCurrentTile(), col.gameObject.transform.parent.gameObject, gameObject, false);
|
||||
break;
|
||||
case "DetectionRange":
|
||||
enemy.HandleDetection();
|
||||
|
||||
Reference in New Issue
Block a user