/// <summary> /// 请求创建一只部队 /// </summary> /// <param name="cell"></param> /// <param name="actorInfoId"></param> /// <returns></returns> public bool AskCreateUnit(HexCell cell, int actorInfoId) { if (cell.Unit != null) { string msg = $"当前位置有一支部队,请把该部队移走,然后再生产部队!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Warning); return(false); } var actorInfoTable = CsvDataManager.Instance.GetTable("actor_info"); string artPrefab = actorInfoTable.GetValue(actorInfoId, "ArtPrefab"); ActorAdd output = new ActorAdd() { RoomId = GameRoomManager.Instance.RoomId, OwnerId = GameRoomManager.Instance.CurrentPlayer.TokenId, ActorId = GameUtils.Utils.GuidToLongId(), PosX = cell.coordinates.X, PosZ = cell.coordinates.Z, Orientation = Random.Range(0f, 360f), Species = artPrefab, // 预制件的名字 CellIndex = cell.Index, ActorInfoId = actorInfoId, }; GameRoomManager.Instance.SendMsg(ROOM.ActorAdd, output.ToByteArray()); return(true); }
public override async Task <GetActorByIdResponse> GetActorsId(ActorId actorId, ServerCallContext context) { try { var actor = await _actor.GetActorId(actorId.Id); if (actor is null) { throw new Exception("Ne moze pronaci glumca"); } ActorAdd act = _mapper.Map <Actor, ActorAdd>(actor); return(new GetActorByIdResponse() { Actor = act }); } catch (Exception e) { _logger.LogError(e, "ERROR"); return(new GetActorByIdResponse() { Actor = null }); } }
public override async Task <ActorsMessageResponse> PostActor(ActorAdd request, ServerCallContext context) { try { var actor = _mapper.Map <ActorAdd, Actor>(request); var response = await _actor.AddActor(actor); if (!response) { throw new Exception("Ne moze da doda glumca"); } return(new ActorsMessageResponse() { Poruka = "Uspesno dodato", Signal = true }); } catch (Exception e) { _logger.LogError(e, "ERROR"); return(new ActorsMessageResponse() { Poruka = "Doslo je do greske", Signal = false }); } }
public override async Task <GetActorsResponse> GetActors(ActorEmpty a, ServerCallContext context) { try { var actors = await _actor.GetAll(); if (actors is null) { throw new Exception("Neuspesno uzeti glumci!"); } List <ActorAdd> actorsAdd = new List <ActorAdd>(); foreach (var actor in actors) { ActorAdd act = _mapper.Map <Actor, ActorAdd>(actor); actorsAdd.Add(act); } return(new GetActorsResponse() { Actors = { actorsAdd } }); } catch (Exception e) { _logger.LogError(e, "ERROR"); return(new GetActorsResponse() { }); } }
private void OnActorAdd(SocketAsyncEventArgs args, byte[] bytes) { ActorAdd input = ActorAdd.Parser.ParseFrom(bytes); // 这条消息是在房间内部接收的,所以要判断这条消息是否属于这个房间。如果放在外部判断,可以通过外部的函数找到该房间,然后直接调用该房间的函数 // 放在哪里都可以,目前放在这里是因为可以测试一下,同一条消息,多个函数注册是否会有BUG if (input.RoomId != _roomId) { return; } var piir = GetPlayerInRoom(input.OwnerId); if (piir == null) { ActorAddReply output = new ActorAddReply() { Ret = false, }; ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.ActorAddReply, output.ToByteArray()); ServerRoomManager.Instance.Log($"MSG: ActorAdd - Player not found in server! Id:{input.OwnerId}"); // 当前玩家不在本本战场! } else { if (input.CellIndex == 0) { Debug.LogError("OnActorAdd F**k!!! Actor position is lost!!!"); } ActorBehaviour ab = new ActorBehaviour() { RoomId = input.RoomId, OwnerId = input.OwnerId, ActorId = input.ActorId, PosX = input.PosX, PosZ = input.PosZ, CellIndex = input.CellIndex, Orientation = input.Orientation, Species = input.Species, ActorInfoId = input.ActorInfoId, }; ab.LoadFromTable(); ActorManager.AddActor(ab, this); // 转发给房间内的所有玩家 ActorAddReply output = new ActorAddReply() { RoomId = ab.RoomId, OwnerId = ab.OwnerId, ActorId = ab.ActorId, Orientation = ab.Orientation, PosX = ab.PosX, PosZ = ab.PosZ, CellIndex = ab.CellIndex, Species = ab.Species, ActorInfoId = ab.ActorInfoId, Name = ab.Name, Hp = ab.Hp, HpMax = ab.HpMax, AttackPower = ab.AttackPower, DefencePower = ab.DefencePower, Speed = ab.Speed, FieldOfVision = ab.FieldOfVision, ShootingRange = ab.ShootingRange, AttackDuration = ab.AttackDuration, AttackInterval = ab.AttackInterval, AmmoBase = ab.AmmoBase, AmmoBaseMax = ab.AmmoBaseMax, Ret = true, }; BroadcastMsg(ROOM_REPLY.ActorAddReply, output.ToByteArray()); } }