public void Run() { var pi = CommandManager.Instance.CurrentExecuter; if (pi == null || !pi.CurrentActor) { string msg = $"没有选中任何部队!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); return; } var avMe = CommandManager.Instance.CurrentExecuter.CurrentActor; if (avMe == null) { return; } var currentCell = avMe.HexUnit.Location; var resType = currentCell.Res.ResType; int resAmount = currentCell.Res.GetAmount(resType); float durationTime = resAmount * 3.0f; if (resAmount <= 0) { string msg = $"本地没有任何资源,请去其他地方采集!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Warning); return; } // 看看行动点够不够 if (!CmdAttack.IsActionPointGranted()) { string msg = "行动点数不够, 本操作无法执行! "; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); Debug.Log("CmdHarvest Run Error - " + msg); return; } { HarvestStart output = new HarvestStart() { RoomId = avMe.RoomId, OwnerId = avMe.OwnerId, ActorId = avMe.ActorId, CellIndex = avMe.CellIndex, ResType = (int)resType, ResRemain = resAmount, DurationTime = durationTime, }; GameRoomManager.Instance.SendMsg(ROOM.HarvestStart, output.ToByteArray()); CmdAttack.SendAiStateHigh(avMe.OwnerId, avMe.ActorId, StateEnum.HARVEST, 0, 0, durationTime, durationTime); // 消耗行动点 CmdAttack.TryCommand(); } }
public void Run() { // 看看行动点够不够 if (!CmdAttack.IsActionPointGranted()) { string msg = "行动点数不够, 本操作无法执行! "; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); Debug.Log("CmdAbandonCity Run Error - " + msg); Stop(); return; } string title = "提示"; string content = "你要废弃这座城市吗?"; UIManager.Instance.MessageBox(title, content, (int)PanelMessageBox.BUTTON.YES | (int)PanelMessageBox.BUTTON.NO, OnConfirm); }
private void OnFightStopReply(byte[] bytes) { FightStopReply input = FightStopReply.Parser.ParseFrom(bytes); if (input.ActorId != ActorId) { return; // 不是自己,略过 } if (!input.Ret) { GameRoomManager.Instance.Log($"ActorBehaviour OnFightStopReply Error - {input.ErrMsg}"); return; } // 每次攻击都要消耗行动点和弹药基数, 所以需要每一轮攻击都判断行动点和弹药基数是否足够 // 如果在战斗中才进行下次进攻的判定, 否则战斗结束 if (input.FightAgain && AmmoBase > 0 && CmdAttack.IsActionPointGranted()) { // 弹药基数足够, 可以再打一轮, 要用 [延迟攻击] 的状态, 时间也要把 [攻击持续时间] & [攻击间隔] 算在一起 StateMachine.TriggerTransition(StateEnum.DELAYFIGHT, 0, input.TargetId, AttackDuration + AttackInterval, AttackDuration + AttackInterval); long roomId = input.RoomId; long ownerId = input.OwnerId; long actorId = input.ActorId; int commandId = (int)CommandManager.CommandID.Attack; int actionPointCost = CommandManager.Instance.Commands[CommandManager.CommandID.Attack].ActionPointCost; CmdAttack.TryCommand(roomId, ownerId, actorId, commandId, actionPointCost); } else if (!input.IsEnemyDead && !IsCounterAttack) { // 我方战斗结束, 如果这时候敌人没死, (我不是处于反击状态), 敌人反击一次 var abTarget = GameRoomManager.Instance.RoomLogic.ActorManager.GetActor(input.TargetId); if (abTarget != null) { abTarget.IsCounterAttack = true; // 这是反击, 不是主动攻击, 记录在自己身上, Stop的时候用 // 反击的时候, 不需要行动点的允许, 直接就可以打 abTarget.IsCounterAttack = true; // 这是反击, 不是主动攻击, 记录在自己身上, Stop的时候用 abTarget.StateMachine.TriggerTransition(StateEnum.FIGHT, 0, input.ActorId, abTarget.AttackDuration); GameRoomManager.Instance.Log("ActorBehaviour OnFightStopReply - 敌人反击"); } } GameRoomManager.Instance.Log($"ActorBehaviour OnFightStopReply - Ammo:{AmmoBase}/{AmmoBaseMax}"); }
public override void Tick() { if (timeSpan < TIME_DELAY) { timeSpan += Time.deltaTime; return; } timeSpan = 0; // 1-恢复[弹药基数AmmoBase] if (Owner.GetLastedTime() >= TIME_SUPPLY) { Owner.RestartTime(); if (_actorBehaviour.AmmoBase < _actorBehaviour.AmmoBaseMax) { _actorBehaviour.AmmoBase++; AmmoSupply output = new AmmoSupply() { RoomId = _actorBehaviour.RoomId, OwnerId = _actorBehaviour.OwnerId, ActorId = _actorBehaviour.ActorId, AmmoBase = _actorBehaviour.AmmoBase, }; GameRoomManager.Instance.SendMsg(ROOM.AmmoSupply, output.ToByteArray()); } } // 2-寻找附近的敌人, 如果有, 且自己弹药满仓, 且自己行动点足够, 且敌人活着, 就干他 // (因为本状态下可以恢复弹药,所以如果只要弹药有1就攻击的话,显得拖拖拉拉) var abEnemy = _actorBehaviour.FindEnemyInRange(); if (abEnemy != null && _actorBehaviour.AmmoBase == _actorBehaviour.AmmoBaseMax && CmdAttack.IsActionPointGranted() && !abEnemy.IsDead) { _actorBehaviour.IsCounterAttack = false; // 这是主动攻击, 不是反击, 记录在自己身上, Stop的时候用 _actorBehaviour.StateMachine.TriggerTransition(StateEnum.FIGHT, 0, abEnemy.ActorId, _actorBehaviour.AttackDuration); } }
private void DoMove(PickInfo piTarget) { // 看看行动点够不够 if (!CmdAttack.IsActionPointGranted()) { string msg = "行动点数不够, 本操作无法执行! "; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); Debug.Log("CmdMarch DoMove Error - " + msg); return; } var pi = CommandManager.Instance.CurrentExecuter; if (pi == null || !pi.CurrentActor) { string msg = $"没有选中任何部队!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); Debug.Log("CmdMarch DoMove Error - " + msg); return; } var avMe = CommandManager.Instance.CurrentExecuter.CurrentActor; if (avMe == null) { return; } HexCell cellTarget = piTarget.CurrentCell; if (!cellTarget) { return; } { var currentCell = avMe.HexUnit.Location; GameRoomManager.Instance.HexmapHelper.hexGrid.FindPath(currentCell, cellTarget, avMe.HexUnit); var hexmapHelper = GameRoomManager.Instance.HexmapHelper; if (!hexmapHelper.hexGrid.HasPath) { return; } // TroopMove output = new TroopMove() // { // RoomId = GameRoomManager.Instance.RoomId, // OwnerId = GameRoomManager.Instance.CurrentPlayer.TokenId, // ActorId = av.ActorId, // PosFromX = av.PosX, // PosFromZ = av.PosZ, // PosToX = cellTarget.coordinates.X, // PosToZ = cellTarget.coordinates.Z, // }; // GameRoomManager.Instance.SendMsg(ROOM.TroopMove, output.ToByteArray()); HexCell newCell = hexmapHelper.hexGrid.GetCell(currentCell.coordinates.X, currentCell.coordinates.Z); HexCell newCell2 = hexmapHelper.hexGrid.GetCell(currentCell.Position); if (newCell.Position != currentCell.Position) { Debug.LogWarning($"OhNo Hexmap!!! - Orgin<{currentCell.coordinates.X},{currentCell.coordinates.Z}> - New<{newCell.coordinates.X},{newCell.coordinates.Z}>"); } if (newCell2.Position != currentCell.Position) { Debug.LogWarning($"OhNo Hexmap 2!!! - Orgin<{currentCell.coordinates.X},{currentCell.coordinates.Z}> - New2<{newCell2.coordinates.X},{newCell2.coordinates.Z}>"); } Debug.Log($"CmdMarch DoMove - From<{avMe.PosX},{avMe.PosZ}> - Dest<{cellTarget.coordinates.X},{cellTarget.coordinates.Z}>"); CmdAttack.SendAiStateHigh(avMe.OwnerId, avMe.ActorId, StateEnum.WALK, cellTarget.Index); } }
public void Run() { var pi = CommandManager.Instance.CurrentExecuter; if (pi == null || !pi.CurrentActor) { string msg = $"没有选中任何部队!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log("CmdBuildCity Error - " + msg); return; } long creatorId = 0; var av = pi.CurrentActor; if (av != null) { creatorId = av.ActorId; } else { string msg = "没有找到开拓者,无法创建城市!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log("CmdBuildCity Error - " + msg); return; } UrbanCity city = GameRoomManager.Instance.RoomLogic.UrbanManager.CreateCityHere(av.HexUnit.Location); if (city == null) { string msg = "这个位置无法创建城市!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log("CmdBuildCity Error - " + msg); return; } // 看看行动点够不够 if (!CmdAttack.IsActionPointGranted()) { string msg = "行动点数不够, 本操作无法执行! "; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); Debug.Log("CmdBuildCity Run Error - " + msg); return; } { CityAdd output = new CityAdd() { RoomId = city.RoomId, OwnerId = city.OwnerId, CityId = city.CityId, PosX = city.PosX, PosZ = city.PosZ, CellIndex = city.CellIndex, CityName = city.CityName, CitySize = city.CitySize, CreatorId = creatorId, }; GameRoomManager.Instance.SendMsg(ROOM.CityAdd, output.ToByteArray()); GameRoomManager.Instance.Log("AskBuildCity - 申请创建城市..."); // 消耗行动点 CmdAttack.TryCommand(); } }