void CollectionAndReportMarineStates(int ReportId, CodeBattle.Observer.ReportEnum ReportType) { CodeBattle.Observer.MarineReport.Builder rb = new CodeBattle.Observer.MarineReport.Builder(); rb.Report = ReportType; rb.ReporterId = ReportId; foreach(object _m in marines.Values) { Marine m = (Marine)(_m); if (m.status == CodeBattle.Status.Dead) continue; CodeBattle.Observer.MarineStatus.Builder msb = new CodeBattle.Observer.MarineStatus.Builder(); msb.Id = m.id; msb.Status = m.status; CodeBattle.Vector2.Builder vb = new CodeBattle.Vector2.Builder(); vb.X = m.transform.position.x; vb.Z = m.transform.position.z; msb.Position = vb.BuildPartial(); rb.AddMarines(msb); } CodeBattle.Observer.Cmd.Builder cmdBuilder = new CodeBattle.Observer.Cmd.Builder(); cmdBuilder.Cmd_ = CodeBattle.Observer.CmdEnum.marinereport; cmdBuilder.Mrt = rb.BuildPartial(); CodeBattle.Observer.Cmd cmd = cmdBuilder.BuildPartial(); byte[] Data = AddLengthHeader( CmdSerialize(cmd) ); SockSend(Data); }
void OperateMarine(CodeBattle.Marine marine) { Marine MarineScript = (Marine)marines[marine.Id]; if (MarineScript.status == CodeBattle.Status.Dead) { return; }; MarineScript.status = marine.Status; MarineScript.hp = marine.Hp; if (marine.Status == CodeBattle.Status.Run) { MarineScript.SetTargetPosition(marine.TargetPosition.X, marine.TargetPosition.Z); } else if (marine.Status == CodeBattle.Status.GunAttack) { MarineScript.SetGunShootPosition(marine.TargetPosition.X, marine.TargetPosition.Z); CollectionAndReportMarineStates(marine.Id, CodeBattle.Observer.ReportEnum.gunattack); } else if (marine.Status == CodeBattle.Status.Flares) { CollectionAndReportMarineStates(marine.Id, CodeBattle.Observer.ReportEnum.flares); StartCoroutine( MarineFlaresReport(marine.Id) ); } }
byte[] CmdSerialize(CodeBattle.Observer.Cmd cmd) { byte[] buffer = new byte[cmd.SerializedSize]; CodedOutputStream stream = CodedOutputStream.CreateInstance(buffer); cmd.WriteTo(stream); return buffer; }