public static bool AttackEnemyInRange(ActorBehaviour abMe, long targetId) { ActorBehaviour abEnemy = GameRoomManager.Instance.RoomLogic.ActorManager.GetActor(targetId); if (abEnemy == null) { // 优先找指定的敌人,如果没有找到,则搜索射程以内的敌人(从近到远) abEnemy = abMe.FindEnemyInRange(); } if (abEnemy != null) { if (abMe.IsEnemyInRange(abEnemy)) { if (abMe.CalcDistance(abEnemy) < 18f * abMe.ShootingRange) { // 敌人进入射程,进入攻击状态. 注意:这时候的敌人,可能不是之前要打的敌人 abMe.IsCounterAttack = false; // 这是主动攻击, 不是反击, 记录在自己身上, Stop的时候用 abMe.StateMachine.TriggerTransition(StateEnum.FIGHT, abEnemy.CellIndex, abEnemy.ActorId, abMe.AttackDuration); CmdAttack.TryCommand(); return(true); } } } return(false); }
/// <summary> /// 与敌人的距离 /// </summary> /// <param name="abEnemy"></param> /// <returns></returns> public float CalcDistance(ActorBehaviour abEnemy) { Vector2 enemy = new Vector2(abEnemy.CurrentPosition.x, abEnemy.CurrentPosition.z); Vector2 me = new Vector2(CurrentPosition.x, CurrentPosition.z); float distance = Vector2.Distance(enemy, me); return(distance); }
public bool IsEnemyInRange(ActorBehaviour abEnemy) { if (abEnemy == null) { return(false); } List <HexCell> cellsInRange = GameRoomManager.Instance.HexmapHelper.GetCellsInRange(HexUnit.Location, (int)ShootingRange); if (cellsInRange.Contains(abEnemy.HexUnit.Location)) { return(true); } return(false); }
public override void Enter() { _enemyActorId = 0; isRest = false; ActorBehaviour abEnemy = GameRoomManager.Instance.RoomLogic.ActorManager.GetActor(Owner.TargetActorId); if (abEnemy != null && _actorBehaviour.IsEnemyInRange(abEnemy)) { _enemyActorId = abEnemy.ActorId; FightStart output = new FightStart() { RoomId = GameRoomManager.Instance.RoomId, OwnerId = _actorBehaviour.OwnerId, ActorId = _actorBehaviour.ActorId, TargetId = abEnemy.ActorId, // SkillId }; GameRoomManager.Instance.SendMsg(ROOM.FightStart, output.ToByteArray()); } else { // 如果没有找到敌人, 休息 Owner.TriggerTransition(StateEnum.IDLE); } }
public bool LoadBuffer(byte[] bytes, int size, RoomLogic roomLogic) { MemoryStream ms = new MemoryStream(bytes); BinaryReader br = new BinaryReader(ms); int version = br.ReadInt32(); int actorCount = br.ReadInt32(); if (actorCount < 0 || actorCount > 9999) { ServerRoomManager.Instance.Log($"ActorManager - LoadBuffer Error - count of actors is invalid: {actorCount} - should between:{0}~{9999}"); return(false); } AllActors.Clear(); for (int i = 0; i < actorCount; ++i) { int index = br.ReadInt32(); if (index != i) { ServerRoomManager.Instance.Log($"ActorManager - LoadBuffer Error - actor index is not valid:{index}- should between:{0}~{actorCount}"); return(false); } ActorBehaviour ab = new ActorBehaviour(); ab.LoadBuffer(br, version); if (ab.CellIndex == 0) { Debug.LogError("ActorManager LoadBuffer Error - CellIndex is lost!!!"); continue; } AddActor(ab, roomLogic); } ServerRoomManager.Instance.Log($"ActorManager LoadBuffer OK - Count of Actors :{AllActors.Count}"); //单元个数 return(true); }
public void AddActor(ActorBehaviour ab, HexUnit hu) { ab.Init(hu); _allActors.Add(ab.ActorId, ab); }
private const float TIME_SUPPLY = 10f; // 间隔一定时间,恢复AmmoBase public ActorGuardState(StateMachineActor owner, ActorBehaviour ab) : base(owner) { _actorBehaviour = ab; }
public ActorHarvestState(StateMachineActor owner, ActorBehaviour ab) : base(owner) { _actorBehaviour = ab; }
public void AddActor(ActorBehaviour ab, RoomLogic roomLogic) { AllActors[ab.ActorId] = ab; ab.Init(roomLogic); }
public ActorDelayFightState(StateMachineActor owner, ActorBehaviour ab) : base(owner) { _actorBehaviour = ab; }