public void SyncState(GCPlayerCmd cmd) { if (state == State.InGame) { var cmds = cmd.Result.Split(' '); var c0 = cmds[0]; Debug.Log("sync state " + c0); if (c0 == "InitID") { myId = System.Convert.ToInt32(cmds[1]); } else if (c0 == "AddPlayer") { AddPlayer(cmds); } else if (c0 == "Move")//id 0 1 2 3 { SyncMove(cmds); } else if (c0 == "NewTurn") { SyncPos(cmds); } } }
public async Task GameStart() //游戏开始 { await _messageQueue; Console.WriteLine($"GameStart RoomID : {Id}"); var cmd = GCPlayerCmd.CreateBuilder(); //发送GameStart消息给所有玩家 cmd.Result = "GameStart"; BroadcastToAll(cmd); var cmd1 = GCPlayerCmd.CreateBuilder(); //第一手,放入玩家的唯一ID cmd1.Result = string.Format("NewTurn {0} {1}", curTurn, players[0].Id); BroadcastToAll(cmd1); //try //{ // var cmd1 = GCPlayerCmd.CreateBuilder(); // string str = "Position"; // foreach (var p in players) // { // str = $"{str} {p.Id} {p.playerState.px} {p.playerState.py} {p.playerState.hp}"; // } // cmd1.Result = str; // BroadcastToAll(cmd1); //} //catch (Exception e) //{ // Console.WriteLine(e); //} //RunTask(UpdateWorld); }
public override void Revive(GCPlayerCmd gc) { var ai = GetComponent <AIBase>().GetAI(); ai.ChangeStateForce(AIStateEnum.IDLE); attr.IsDead = false; }
public void MsgHandler(GCPlayerCmd cmd) { if (msgFunction == "") { throw new Exception("msgFunction is null"); } else { luaManager.CallFunction(msgFunction, cmd); } //switch (cmds[0]) //{ // case "Init": // Debug.Log("Init:" + myId); // myId = Convert.ToInt32(cmds[1]); // break; // case "GameStart": // gameState = GameState.InGame; // Logic.Instance.GameStart(); // break; // case "NewTurn": // Logic.Instance.NewTurn(cmds); // break; // case "MakeMove": // Logic.Instance.UpdateMove(cmds); // break; // default: // break; //} }
//MakeMove 0 public async Task MakeMove(int id, CGPlayerCmd cmd) //有玩家走了一步,更新数据,广播给所有玩家,开始下一手 { await _messageQueue; var pos = Convert.ToInt32(cmd.Cmd.Split(' ')[1]); chessState[pos] = id; curTurn++; var playerWho = curTurn % 2; var p = players[playerWho]; var cmd2 = GCPlayerCmd.CreateBuilder(); cmd2.Result = string.Format("MakeMove {0} {1}", id, pos); BroadcastToAll(cmd2); if (CheckWin()) { await GameOver(); } else { var cmd3 = GCPlayerCmd.CreateBuilder(); cmd3.Result = string.Format("NewTurn {0} {1}", curTurn, p.Id); BroadcastToAll(cmd3); } }
public override void Revive(GCPlayerCmd gc) { //throw new NotImplementedException(); var ai = GetComponent <AIBase>().GetAI(); ai.ChangeStateForce(AIStateEnum.IDLE); attr.IsDead = false; }
public void DoNetworkDamage(GCPlayerCmd cmd) { var eid = cmd.DamageInfo.Enemy; var attacker = ObjectManager.objectManager.GetPlayer(cmd.DamageInfo.Attacker); if (attacker != null) { gameObject.GetComponent <MyAnimationEvent>().OnHit(attacker, cmd.DamageInfo.Damage, cmd.DamageInfo.IsCritical); } }
public override void InitSync(AvatarInfo info) { if (info != null) { var gc = GCPlayerCmd.CreateBuilder(); gc.AvatarInfo = info; var cmd = gc.Build(); NetworkAttribute(cmd); } }
public static void DoNetworkDamage(GameObject me, GCPlayerCmd cmd) { var eid = cmd.DamageInfo.Enemy; //var enemy = ObjectManager.objectManager.GetPlayer(cmd.DamageInfo.Enemy); //if (enemy != null) { var dinfo = cmd.DamageInfo; //gameObject.GetComponent<MyAnimationEvent>().OnHit(attacker, cmd.DamageInfo.Damage, cmd.DamageInfo.IsCritical, cmd.DamageInfo.IsStaticShoot); me.GetComponent <NpcAttribute>().DoHurt(dinfo.Damage, dinfo.IsCritical, dinfo.IsStaticShoot); } }
private void InitPlayerId() //初始化客户端Player的ID,为每个Actor的专属ID,由ActorManager统一管理 { var cmd = GCPlayerCmd.CreateBuilder(); cmd.Result = string.Format("Init {0}", Id); ServerBundle bundle; var bytes = ServerBundle.sendImmediateError(cmd, 0, 0, out bundle); ServerBundle.ReturnBundle(bundle); agent.SendBytes(bytes); }
public void NetworkBuff(GCPlayerCmd cmd) { var sk = Util.GetSkillData(cmd.BuffInfo.SkillId, 1); var skConfig = SkillLogic.GetSkillInfo(sk); var evt = skConfig.GetEvent(cmd.BuffInfo.EventId); if (evt != null) { var pos = cmd.BuffInfo.AttackerPosList; var px = pos [0] / 100.0f; var py = pos [1] / 100.0f; var pz = pos [2] / 100.0f; gameObject.GetComponent <BuffComponent>().AddBuff(evt.affix, new Vector3(px, py, pz)); } }
/// <summary> /// 其它玩家复活立即切换状态,重置HP /// 设置RebornShader /// </summary> /// <param name="cmd"></param> /// <returns></returns> public IEnumerator NetworkRevive(GCPlayerCmd cmd) { var ainfo = cmd.AvatarInfo; Log.Sys("Revive"); var np = NetworkUtil.FloatPos(ainfo.X, ainfo.Y, ainfo.Z); Util.ForceResetPos(this.GetComponent <Rigidbody>(), np); var nr = Quaternion.Euler(new Vector3(0, ainfo.Dir, 0)); this.GetComponent <Rigidbody>().MoveRotation(nr); SetHPNet(HP_Max); ReviveAI(); //StartCoroutine(SetRebornShader()); yield return(null); }
public static void DoNetworkAttack(GameObject gameObject, GCPlayerCmd proto) { var sk = proto.SkillAction; var cmd = new SkillCMD(); cmd.skillId = sk.SkillId; cmd.skillLevel = sk.SkillLevel; cmd.staticShoot = sk.IsStaticShoot; cmd.targetPos = NetworkUtil.FloatPos(sk.X, sk.Y, sk.Z); cmd.dir = sk.Dir; cmd.skillAction = sk; cmd.runFrame = sk.RunFrame; cmd.proto = proto; Log.GUI("Other Player Attack LogicCommand"); gameObject.GetComponent <LogicCommand>().PushCommand(cmd); }
public void Dead(GCPlayerCmd cmd) { var pa = ObjectManager.objectManager.GetPlayer(cmd.DamageInfo.Attacker); var pb = ObjectManager.objectManager.GetPlayer(cmd.DamageInfo.Enemy); Log.Sys("DeadMsg: " + pa + " pb " + pb); if (pa != null && pb != null) { var aname = pa.GetComponent <NpcAttribute>().userName; var bname = pb.GetComponent <NpcAttribute>().userName; var killInfo = string.Format("[ff1010]{0}[-]击杀了[10ff10]{1}[-],获得了[ff1010]{2}[-]杀", aname, bname, cmd.AvatarInfo.ContinueKilled); Util.ShowMsg(killInfo); if (cmd.AvatarInfo.ContinueKilled > 0) { PlayerKillSound(cmd.AvatarInfo.ContinueKilled); } var myId = NetMatchScene.Instance.myId; if (cmd.DamageInfo.Attacker == myId) { var js = new JSONClass(); js.Add("totalKill", new JSONData(1)); if (cmd.AvatarInfo.ContinueKilled == 3) { js.Add("threeKill", new JSONData(1)); } else if (cmd.AvatarInfo.ContinueKilled == 4) { js.Add("fourKill", new JSONData(1)); } else if (cmd.AvatarInfo.ContinueKilled == 5) { js.Add("fiveKill", new JSONData(1)); } RecordData.UpdateRecord(js); } else if (cmd.DamageInfo.Enemy == myId) { var js = new JSONClass(); js.Add("dieNum", new JSONData(1)); RecordData.UpdateRecord(js); } } }
private async Task GameOver() { await _messageQueue; if (!isGameOver) { isGameOver = true; var cmd = GCPlayerCmd.CreateBuilder(); cmd.Result = "GameOver"; BroadcastToAll(cmd); foreach (var p in players) { await p.SetRoom(null); } ActorManager.Instance.RemoveActor(Id); //删除该房间 } }
private void SyncWorldState()//同步状态给所有玩家: { //玩家位置同步更新 var cmd1 = GCPlayerCmd.CreateBuilder(); string str = "Position"; foreach (var p in players) { str = $"{str} {p.Id} {p.playerState.px} {p.playerState.py} {p.playerState.hp}"; } cmd1.Result = str; BroadcastToAll(cmd1); //技能位置同步 var cmd2 = GCPlayerCmd.CreateBuilder(); var str2 = "Bullet"; foreach (var bulletPair in bulletMap) { str2 = $"{str2} {bulletPair.Value.id} {bulletPair.Value.px} {bulletPair.Value.py}"; } cmd2.Result = str2; BroadcastToAll(cmd2); }
public abstract void Dead(GCPlayerCmd cmd);
public abstract void NetworkAttack(GCPlayerCmd sk);
public override void Dead(GCPlayerCmd cmd) { MobaUtil.Dead(gameObject); }
public override void DoNetworkDamage(GCPlayerCmd cmd) { MobaUtil.DoNetworkDamage(gameObject, cmd); }
public override void NetworkAttribute(GCPlayerCmd cmd) { var info = cmd.EntityInfo; SyncAttribute(info); }
public override void NetworkRemoveBuff(GCPlayerCmd cmd) { }
public override void NetworkBuff(GCPlayerCmd gc) { }
public override void NetworkAttack(GCPlayerCmd proto) { MobaUtil.DoNetworkAttack(gameObject, proto); }
public override void NetworkAttribute(GCPlayerCmd cmd) { var info = cmd.AvatarInfo; if (attr == null) { attr = GetComponent <NpcAttribute>(); } Log.Net("MySelfSync: " + info); if (info == null) { Debug.LogError("NetMatchInfo is Null "); return; } NetworkMove(info); //服务器通知瞬间传送位置 if (info.ResetPos) { if (aiBase != null) { aiBase.GetAI().ChangeState(AIStateEnum.IDLE); } var netPos = MobaUtil.FloatPos(info); transform.position = netPos; positions.Clear(); } if (info.HasTeamColor) { attr.SetTeamColorNet(info.TeamColor); curInfo.TeamColor = info.TeamColor; } if (info.HasIsMaster) { attr.SetIsMasterNet(info.IsMaster); curInfo.IsMaster = info.IsMaster; } var dataChanged = false; var skillCount = curInfo.KillCount; if (info.HasKillCount) { skillCount = info.KillCount; curInfo.KillCount = info.KillCount; dataChanged = true; } var deadCount = curInfo.DeadCount; if (info.HasDeadCount) { deadCount = info.DeadCount; curInfo.DeadCount = info.DeadCount; dataChanged = true; } var secondaryAttackCount = curInfo.SecondaryAttackCount; if (info.HasSecondaryAttackCount) { secondaryAttackCount = info.SecondaryAttackCount; curInfo.SecondaryAttackCount = info.SecondaryAttackCount; dataChanged = true; } if (info.HasScore) { curInfo.Score = info.Score; dataChanged = true; } if (dataChanged) { var sid = attr.GetNetView().GetServerID(); ScoreManager.Instance.NetSyncScore(sid, curInfo.Score, sid, skillCount, deadCount, secondaryAttackCount); } if (info.HasContinueKilled) { curInfo.ContinueKilled = info.ContinueKilled; if (curInfo.ContinueKilled > 0) { } } if (info.HasPlayerModelInGame && curInfo.PlayerModelInGame != info.PlayerModelInGame) { curInfo.PlayerModelInGame = info.PlayerModelInGame; GetComponent <MobaModelLoader>().LoadModel(curInfo.PlayerModelInGame); var unitData = Util.GetUnitData(true, curInfo.PlayerModelInGame, 0); attr.SetObjUnitData(unitData); SkillDataController.skillDataController.InitSkillShotAfterSelectSkill(curInfo.PlayerModelInGame); } if (info.HasHP) { curInfo.HP = info.HP; attr.SetHPNet(info.HP); } if (info.HasLevel) { curInfo.Level = info.Level; attr.ChangeLevel(info.Level); } if (info.HasState) { curInfo.State = info.State; } }
public override void NetworkAttack(GCPlayerCmd cmd) { MobaUtil.DoNetworkAttack(gameObject, cmd); }
public override void Revive(GCPlayerCmd gc) { throw new NotImplementedException(); }
public void SyncAttribute(GCPlayerCmd cmd) { var info = cmd.EntityInfo; SyncAttribute(info); }
public override void NetworkRemoveBuff(GCPlayerCmd cmd) { throw new NotImplementedException(); }
public abstract void NetworkRemoveBuff(GCPlayerCmd cmd);