using Entitas; using UnityEngine; using Game; /// /// 麻薯的管理 /// public class MasterSoulSystem : IExecuteSystem, IInitializeSystem { public static float ShakeTerm = 1.5f; //抖动周期 public static float ShakeDistance = 0.0625f; //抖动幅度 直径为2像素 public static float ShakeRate = (2 * Mathf.PI) / ShakeTerm; //sin抖动方程a值 public void Initialize() { } public void Execute() { var entity = Util.GetMasterSoul(); if (entity == null) { return; } CheckInit(entity); UpdateMove(entity); UpdateShootPre(entity); UpdateShoot(entity); } public void CheckInit(GameEntity entity) { var masterSoul = entity.masterSoul; } public void UpdateMove(GameEntity entity) { var master = Util.GetMaster(); var targetPos = master.Pos() + new Vector3(0.2f * (master.move.IsRight ? -1 : 1), 0, 0.2f); targetPos = new Vector3(targetPos.x, 0, targetPos.z); var nowPos = entity.Pos(); var distance = Vector3.Distance(targetPos, nowPos); if (distance > 5) { entity.SetPos(targetPos); return; } if (distance < 0.2f) { if (Util.EntityIsWalk(entity.ID())) { Util.EntityStopMove(entity.ID()); Util.SetMasterSoulDir(entity, Vector2.down); } return; } var masterSoul = entity.masterSoul; var moveSpeed = distance * distance * 4; var moveDir = (targetPos - nowPos).normalized; entity.move.MoveParam.MoveSpeedMax = moveSpeed; Util.EntityMove(entity.ID(), moveDir); Util.SetMasterSoulDir(entity, -new Vector2(moveDir.x, moveDir.z)); } public void UpdateShootPre(GameEntity entity) { var masterSoul = entity.masterSoul; var preList = masterSoul.ShootPreList; for (int i = preList.Count - 1; i >= 0; i--) { var info = preList[i]; info.TimeLeft -= Time.deltaTime; if (info.TimeLeft <= 0) { for (int j = 0; j < info.Count; j++) { masterSoul.ShootTargetQueue.Enqueue(info.Target); } preList.RemoveAt(i); } } } public void UpdateShoot(GameEntity entity) { var masterSoul = entity.masterSoul; if (masterSoul.ShootTimeLeft > 0) { masterSoul.ShootTimeLeft -= Time.deltaTime; return; } if (masterSoul.ShootTimeLeft < 0) { masterSoul.ShootTimeLeft = 0; } if (masterSoul.ShootTargetQueue.Count == 0) { return; } var targetId = masterSoul.ShootTargetQueue.Dequeue(); var target = Util.GetEntity(targetId); if (target == null) { return; } masterSoul.ShootTimeLeft = GameConst.MasterSoulShootTime; var pos = entity.view.PositionView; var posTarget = target.view.PositionLogic; var dir = posTarget - pos; Util.CreateSubEntity(0, entity.ID(), targetId, dir, pos); } }