|
|
@@ -7,31 +7,34 @@ using TMPro;
|
|
|
|
|
|
public class RockRoller : Enemy
|
|
|
{
|
|
|
- public int hitTime = 1;
|
|
|
- public int curHitTime = 0;
|
|
|
+ private int hitTime = 1;
|
|
|
+ private int curHitTime = 0;
|
|
|
public RockAttackTrigger attackTrigger0;
|
|
|
public AttackTrigger attackEnemyTrigger0;
|
|
|
- public List<TargetType> initialTargetTypes = new List<TargetType>();
|
|
|
-
|
|
|
+ private List<TargetType> initialTargetTypes = new List<TargetType>();
|
|
|
public GameObject stone;
|
|
|
- public string smallStone;
|
|
|
+ public string smallStoneE;
|
|
|
+ public string smallStoneC;
|
|
|
public float baseRotateSpeed = 90f;
|
|
|
public float rotateMul = 1f;
|
|
|
- private float rotateDirection = -1f;
|
|
|
+ public float rotateDirection = -1f;
|
|
|
private float dieTime = 0.1f;
|
|
|
private float deathTimer = 0f;
|
|
|
private bool isDying;
|
|
|
private bool isFalled = false;
|
|
|
public Enemy owner;
|
|
|
|
|
|
- private bool isGather = false;
|
|
|
+ public bool isGather = false;
|
|
|
public float gatherTime = 1f;
|
|
|
private float gatherTimer = 0f;
|
|
|
|
|
|
- private bool isWeak = false;
|
|
|
+ public bool isWeak = false;
|
|
|
public float weakTime = 1f;
|
|
|
private float weakTimer = 0f;
|
|
|
+
|
|
|
public float addForce = 1f;
|
|
|
+ public float addRushForceMul = 2;
|
|
|
+ public float RushSpeedMul = 2;
|
|
|
|
|
|
public SpriteRenderer RockSpriterRenderer;
|
|
|
public List<Sprite> spriteList = new List<Sprite>();
|
|
|
@@ -46,7 +49,17 @@ public class RockRoller : Enemy
|
|
|
|
|
|
public GameObject smoke;
|
|
|
|
|
|
- public float smallStoneFoece = 20f;
|
|
|
+ public bool isBounce =false;
|
|
|
+ public bool isLeft = false;
|
|
|
+ public int bounceTime = 3;
|
|
|
+ private int curBounceTime = 0;
|
|
|
+ public Vector3 forceLeftDirection;
|
|
|
+ public Vector3 forceRightDirection;
|
|
|
+ public float decrease = 0.75f;
|
|
|
+ public float forceMul = 50;
|
|
|
+
|
|
|
+ //public float RushTime = 5f;
|
|
|
+ //public float RushTimer = 0f;
|
|
|
public override void Init()
|
|
|
{
|
|
|
base.Init();
|
|
|
@@ -94,7 +107,7 @@ public class RockRoller : Enemy
|
|
|
{
|
|
|
stone = gameObject;
|
|
|
}
|
|
|
- enemyStr = $"Prefab/Enemy/{smallStone}";
|
|
|
+ enemyStr = $"Prefab/Enemy/{smallStoneE}";
|
|
|
}
|
|
|
private void InitializeSpriter()
|
|
|
{
|
|
|
@@ -145,14 +158,11 @@ public class RockRoller : Enemy
|
|
|
curHitTime = 0;
|
|
|
stone.SetActive(true);
|
|
|
smoke.SetActive(false);
|
|
|
- if (state == CharacterState.None)
|
|
|
- {
|
|
|
- ChangeState(CharacterState.Idle);
|
|
|
- }
|
|
|
+ ChangeState(CharacterState.Idle);
|
|
|
if (attackEnemyTrigger0 != null)
|
|
|
attackEnemyTrigger0.gameObject.SetActive(false);
|
|
|
if (attackTrigger0 != null)
|
|
|
- attackTrigger0.gameObject.SetActive(true);
|
|
|
+ attackTrigger0.gameObject.SetActive(false);
|
|
|
changeSpriter(0);
|
|
|
changeScale(0);
|
|
|
ResetTargetTypes();
|
|
|
@@ -281,14 +291,9 @@ public class RockRoller : Enemy
|
|
|
if (owner != null && curHitTime >= hitTime)
|
|
|
{
|
|
|
PlayBreakEff();
|
|
|
- owner.gameObject.SetActive(false);
|
|
|
- if (isBig)
|
|
|
- {
|
|
|
- SpawnSmallStones();
|
|
|
- }
|
|
|
+ ChangeState(CharacterState.Die);
|
|
|
curHitTime = 0;
|
|
|
}
|
|
|
-
|
|
|
isDying = false;
|
|
|
}
|
|
|
|
|
|
@@ -297,25 +302,26 @@ public class RockRoller : Enemy
|
|
|
attackEnemyTrigger0.gameObject.SetActive(false);
|
|
|
ResetTargetTypes();
|
|
|
|
|
|
- SingleEnemyConfig cfgEnemy = GameManager.instance.allCfgData.CfgEnemy.Get("小滚石怪");
|
|
|
+ SingleEnemyConfig cfgEnemy = GameManager.instance.allCfgData.CfgEnemy.Get(smallStoneC);
|
|
|
|
|
|
// 生成第一个小石头
|
|
|
GameObject stone1 = Util.Instantiate(enemyStr, transform.position - new Vector3(0, 0, 0), active: true);
|
|
|
ConfigureSmallStone(stone1, cfgEnemy);
|
|
|
- SmallStoneForce(stone1, new Vector3(-1, 1.2f, 0), smallStoneFoece);
|
|
|
+ stone1.GetComponent<RockRoller>().isBounce = true;
|
|
|
+ stone1.GetComponent<RockRoller>().isLeft = true;
|
|
|
|
|
|
// 生成第二个小石头
|
|
|
GameObject stone2 = Util.Instantiate(enemyStr, transform.position - new Vector3(0, 0, 0), active: true);
|
|
|
ConfigureSmallStone(stone2, cfgEnemy);
|
|
|
- SmallStoneForce(stone2, new Vector3(1, 1.2f, 0), smallStoneFoece);
|
|
|
+ stone2.GetComponent<RockRoller>().isBounce = true;
|
|
|
+ stone2.GetComponent<RockRoller>().isLeft = false;
|
|
|
|
|
|
isFalled = false;
|
|
|
}
|
|
|
|
|
|
- private void SmallStoneForce(GameObject stone, Vector3 forceDirection, float forceMul)
|
|
|
+ private void SmallStoneForce(RockRoller Roller, Vector3 forceDirection, float forceMul)
|
|
|
{
|
|
|
- Rigidbody rockRb = stone.GetComponent<Rigidbody>();
|
|
|
- RockRoller Roller = stone.GetComponent<RockRoller>();
|
|
|
+ Rigidbody rockRb = Roller.gameObject.GetComponent<Rigidbody>();
|
|
|
Roller.ChangeState(CharacterState.Fall);
|
|
|
rockRb.AddForce(forceDirection * forceMul, ForceMode.Impulse);
|
|
|
}
|
|
|
@@ -324,10 +330,6 @@ public class RockRoller : Enemy
|
|
|
RockRoller rock = stoneObj.GetComponent<RockRoller>();
|
|
|
if (rock != null)
|
|
|
{
|
|
|
- Debug.Log(cfgEnemy.AttackMarch[0]);
|
|
|
- Debug.Log(cfgEnemy.AttackSummon);
|
|
|
- Debug.Log(cfgEnemy.MinMoveSpeed);
|
|
|
- Debug.Log(cfgEnemy.MaxMoveSpeed);
|
|
|
rock.attackTrigger0.attackMethod.attackInfo.damage = cfgEnemy.AttackMarch[0];
|
|
|
rock.attackEnemyTrigger0.attackMethod.attackInfo.damage = cfgEnemy.AttackSummon;
|
|
|
rock.owner.moveSpeed = Random.Range(cfgEnemy.MinMoveSpeed, cfgEnemy.MaxMoveSpeed);
|
|
|
@@ -340,7 +342,6 @@ public class RockRoller : Enemy
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
ExitCurrentState();
|
|
|
EnterNewState(newState);
|
|
|
}
|
|
|
@@ -368,6 +369,9 @@ public class RockRoller : Enemy
|
|
|
case CharacterState.Idle:
|
|
|
EnterIdleState();
|
|
|
break;
|
|
|
+ case CharacterState.Run:
|
|
|
+ EnterRunState();
|
|
|
+ break;
|
|
|
case CharacterState.Rush:
|
|
|
EnterRushState();
|
|
|
break;
|
|
|
@@ -385,40 +389,70 @@ public class RockRoller : Enemy
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void EnterIdleState()
|
|
|
{
|
|
|
- rotateDirection = -1f;
|
|
|
+
|
|
|
rb.velocity = Vector3.zero;
|
|
|
if (attackEnemyTrigger0 != null) attackEnemyTrigger0.gameObject.SetActive(false);
|
|
|
if (attackTrigger0 != null) attackTrigger0.gameObject.SetActive(false);
|
|
|
smoke.SetActive(false);
|
|
|
}
|
|
|
-
|
|
|
+ private void EnterRunState()
|
|
|
+ {
|
|
|
+ rb.velocity = Vector3.zero;
|
|
|
+ rotateDirection = -1f;
|
|
|
+ }
|
|
|
private void EnterRushState()
|
|
|
{
|
|
|
rb.velocity = Vector3.zero;
|
|
|
if (attackEnemyTrigger0 != null) attackEnemyTrigger0.gameObject.SetActive(false);
|
|
|
if (attackTrigger0 != null) attackTrigger0.gameObject.SetActive(true);
|
|
|
- smoke.SetActive(true);
|
|
|
+ rotateDirection = -1f;
|
|
|
}
|
|
|
|
|
|
private void EnterRiseState()
|
|
|
{
|
|
|
+ rb.velocity = Vector3.zero;
|
|
|
isGather = true;
|
|
|
gatherTimer = 0f;
|
|
|
- smoke.SetActive(false);
|
|
|
+ smoke.SetActive(true);
|
|
|
+ isBounce = false;
|
|
|
+ attackTrigger0.rockCollisionProtect = false;
|
|
|
+ beSearchTrigger.gameObject.SetActive(false);
|
|
|
}
|
|
|
|
|
|
private void EnterFallState()
|
|
|
{
|
|
|
+ beSearchTrigger.gameObject.SetActive(true);
|
|
|
rotateDirection = 1f;
|
|
|
+ if (isBounce && isLeft)
|
|
|
+ {
|
|
|
+ rotateDirection = 1f;
|
|
|
+ }
|
|
|
+ else if (isBounce)
|
|
|
+ {
|
|
|
+ rotateDirection = -1f;
|
|
|
+ }
|
|
|
weakTimer = 0f;
|
|
|
smoke.SetActive(false);
|
|
|
+ if (isBounce)
|
|
|
+ {
|
|
|
+ curBounceTime += 1;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ curBounceTime = 0;
|
|
|
+ }
|
|
|
+ if (attackEnemyTrigger0 != null) attackEnemyTrigger0.gameObject.SetActive(false);
|
|
|
+ if (attackTrigger0 != null) attackTrigger0.gameObject.SetActive(false);
|
|
|
}
|
|
|
|
|
|
private void EnterDieState()
|
|
|
{
|
|
|
+ if (isBig)
|
|
|
+ {
|
|
|
+ SpawnSmallStones();
|
|
|
+ }
|
|
|
isDie = true;
|
|
|
dieKeepTime = totalDieKeepTime;
|
|
|
if (GameManager.instance.gameType != GameType.GameEnd)
|
|
|
@@ -437,14 +471,58 @@ public class RockRoller : Enemy
|
|
|
deathTimer = 0f;
|
|
|
if (owner != null) owner.attributeStatus.hitState = 0;
|
|
|
smoke.SetActive(false);
|
|
|
+ isBounce = false;
|
|
|
+ curBounceTime = 0;
|
|
|
}
|
|
|
|
|
|
+ public override bool GetAttack()
|
|
|
+ {
|
|
|
+ List<Character> list =searchTrigger.GetAllTargets(attackController.targetTypes, attackController.curAttackMethod.canHitFly);
|
|
|
+ if (list.Count >= 1)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
public override void OnState()
|
|
|
{
|
|
|
+ bool isAttack = GetAttack();
|
|
|
switch (state)
|
|
|
{
|
|
|
case CharacterState.Idle:
|
|
|
- ChangeState(CharacterState.Rise);
|
|
|
+ if (isBounce && curBounceTime < bounceTime - 1)
|
|
|
+ {
|
|
|
+ if (isLeft)
|
|
|
+ {
|
|
|
+ SmallStoneForce(this, forceLeftDirection, forceMul * (Mathf.Pow(decrease, curBounceTime)));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SmallStoneForce(this, forceRightDirection, forceMul * (Mathf.Pow(decrease, curBounceTime)));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else if (curBounceTime == bounceTime - 1)
|
|
|
+ {
|
|
|
+ ChangeState(CharacterState.Fall);
|
|
|
+ isBounce = false;
|
|
|
+ curBounceTime = 0;
|
|
|
+ isWeak = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ChangeState(CharacterState.Run);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CharacterState.Run:
|
|
|
+ if (isAttack)
|
|
|
+ {
|
|
|
+ ChangeState(CharacterState.Rise);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Run();
|
|
|
+ }
|
|
|
break;
|
|
|
case CharacterState.Rise:
|
|
|
HandleRiseState();
|
|
|
@@ -457,6 +535,9 @@ public class RockRoller : Enemy
|
|
|
break;
|
|
|
case CharacterState.SpecialStatus_BlowUp:
|
|
|
attributeStatus.SpecialStateEffect(SpecialState.BlownUp);
|
|
|
+ Vector3 velocity = rb.velocity;
|
|
|
+ velocity.y += extraFallGravity * Time.deltaTime;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
case CharacterState.Die:
|
|
|
dieKeepTime -= Time.deltaTime;
|
|
|
@@ -491,7 +572,15 @@ public class RockRoller : Enemy
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ private void Run()
|
|
|
+ {
|
|
|
+ Vector3 velocity = rb.velocity;
|
|
|
+ if (Mathf.Abs(velocity.x) < moveSpeed)
|
|
|
+ {
|
|
|
+ velocity.x += addForce;
|
|
|
+ }
|
|
|
+ rb.velocity = velocity;
|
|
|
+ }
|
|
|
private void HandleRiseState()
|
|
|
{
|
|
|
if (isGather && gatherTimer < gatherTime)
|
|
|
@@ -500,7 +589,6 @@ public class RockRoller : Enemy
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Debug.Log("gatherFinsh");
|
|
|
isGather = false;
|
|
|
ChangeState(CharacterState.Rush);
|
|
|
}
|
|
|
@@ -509,15 +597,22 @@ public class RockRoller : Enemy
|
|
|
private void HandleRushState()
|
|
|
{
|
|
|
Vector3 velocity = rb.velocity;
|
|
|
- if (Mathf.Abs(velocity.x) < moveSpeed)
|
|
|
+ if (Mathf.Abs(velocity.x) < moveSpeed*RushSpeedMul)
|
|
|
{
|
|
|
- velocity.x += addForce;
|
|
|
+ velocity.x += addForce * addRushForceMul;
|
|
|
}
|
|
|
rb.velocity = velocity;
|
|
|
+ //if (RushTimer < RushTime)
|
|
|
+ //{
|
|
|
+ // RushTimer += Time.deltaTime;
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
private void HandleFallState()
|
|
|
{
|
|
|
+ Vector3 velocity = rb.velocity;
|
|
|
+ velocity.y += extraFallGravity * Time.deltaTime;
|
|
|
+ rb.velocity = velocity;
|
|
|
if (!foot.TrigGround)
|
|
|
{
|
|
|
isWeak = true;
|
|
|
@@ -525,8 +620,16 @@ public class RockRoller : Enemy
|
|
|
|
|
|
if (isWeak && weakTimer < weakTime && foot.TrigGround)
|
|
|
{
|
|
|
- rb.velocity = Vector3.zero;
|
|
|
- weakTimer += Time.deltaTime;
|
|
|
+ if (isBounce)
|
|
|
+ {
|
|
|
+ ChangeState(CharacterState.Idle);
|
|
|
+ isWeak = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rb.velocity = Vector3.zero;
|
|
|
+ weakTimer += Time.deltaTime;
|
|
|
+ }
|
|
|
}
|
|
|
else if (weakTimer >= weakTime)
|
|
|
{
|
|
|
@@ -539,5 +642,7 @@ public class RockRoller : Enemy
|
|
|
{
|
|
|
EnemyCreater.instance.OnEnemyRecycle(this);
|
|
|
ResetState();
|
|
|
+ isBounce = false;
|
|
|
+ curBounceTime = 0;
|
|
|
}
|
|
|
}
|