protected override void WriteBoard(PacketWriter stream) { // players byte count = 0; int countPos = stream.Position++; ArenaClient.ForEach(c => { if (c.GMTeamID >= TeamIdent.GMPlayer) { WritePlayer(c, stream); count++; } }); stream.Edit(countPos, count); // spectators count = 0; countPos = stream.Position++; ArenaClient.ForEach(c => { if (c.GMTeamID == TeamIdent.GMSpectator) { WritePlayer(c, stream); count++; } }); stream.Edit(countPos, count); }
private AliceClient( Guid aliceId, RoundState roundState, ArenaClient arenaClient, SmartCoin coin, OwnershipProof ownershipProof, IEnumerable <Credential> issuedAmountCredentials, IEnumerable <Credential> issuedVsizeCredentials, bool isPayingZeroCoordinationFee) { var roundParameters = roundState.CoinjoinState.Parameters; AliceId = aliceId; RoundId = roundState.Id; ArenaClient = arenaClient; SmartCoin = coin; OwnershipProof = ownershipProof; FeeRate = roundParameters.MiningFeeRate; CoordinationFeeRate = roundParameters.CoordinationFeeRate; IssuedAmountCredentials = issuedAmountCredentials; IssuedVsizeCredentials = issuedVsizeCredentials; MaxVsizeAllocationPerAlice = roundParameters.MaxVsizeAllocationPerAlice; ConfirmationTimeout = roundParameters.ConnectionConfirmationTimeout / 2; IsPayingZeroCoordinationFee = isPayingZeroCoordinationFee; }
public void RespawnClient(ArenaClient client) { if (Phase < GamePhase.Fight) { return; } Vec3f nextStand = Stands[0].Stand.Position; // find player closest to next stand IEnumerable <Vec3f> positions = StandingPlayers.Select(p => p.Character.GetPosition()); if (!Vec3f.FindClosest(Stands[0].Stand.Position, positions, out Vec3f best)) { return; } // two closest respawns to player IEnumerable <Vec3f> x = Scenario.Respawns.OrderBy(p => p.GetDistance(best)).Take(2); // closest of the two respawns to next stand if (!Vec3f.FindClosest(best, x, out Vec3f result)) { return; } var npc = SpawnCharacter(client, World, result, 100); npc.DropUnconscious(); }
void OnHit(NPCInst attacker, NPCInst target, int damage) { if (!IsActive || ActiveMode.Phase < GamePhase.Fight) { return; } if (attacker.IsPlayer) { if (target.IsPlayer) { return; } ArenaClient player = (ArenaClient)attacker.Client; player.GMScore += damage / 10.0f; if (target.HP <= 0) { player.GMKills++; player.GMScore += 5; } } else if (target.IsPlayer) { ArenaClient player = (ArenaClient)target.Client; if (target.HP <= 1) { player.GMDeaths++; if (players.TrueForAll(p => !p.IsCharacter || p.Character.IsDead || p.Character.IsUnconscious)) { HordeFadeOut(false); } } } }
protected virtual NPCInst SpawnCharacter(ArenaClient client, WorldInst world, PosAng spawnPoint) { // only spawn if player has joined the game mode and chosen a class if (client == null || !client.GMJoined || client.GMClass == null) { return(null); } // get rid of old character if there is one client.KillCharacter(); NPCInst npc = CreateNPC(client.GMClass, (int)client.GMTeamID, client.CharInfo); npc.Spawn(world, spawnPoint.Position, spawnPoint.Angles); client.SetControl(npc); // start the warm up phase as soon as the first player joins if (Phase == GamePhase.None && players.Count(p => p.IsCharacter) == 1) { SetPhase(GamePhase.WarmUp); phaseTimer.SetInterval(Scenario.WarmUpDuration); phaseTimer.SetCallback(Fight); phaseTimer.Restart(); } return(npc); }
public void JoinTeam(ArenaClient client, int index) { if (Phase == GamePhase.FadeOut) { return; } if (index < 0 || index >= teams.Count) { return; } var team = teams[index]; if (client.TDMTeam == team) { return; } if (client.TDMTeam != null) { client.KillCharacter(); client.TDMTeam.Players.Remove(client); client.GMClass = null; } client.TDMTeam = team; team.Players.Add(client); client.SetTeamID((TeamIdent)index); }
void SelectClass(int index) { if (!HordeMode.IsActive || PlayerInfo.HeroInfo.TeamID < TeamIdent.GMSpectator || GameMode.ActiveMode.Phase == GamePhase.FadeOut) { Close(); return; } if (!HordeMode.ActiveMode.Scenario.PlayerClasses.TryGet(index, out NPCClass classDef)) { return; } if (classDef == NPCClass.Hero) { Close(); return; } if (!lockTimer.IsReady) { return; } var stream = ArenaClient.GetStream(ScriptMessages.ModeClassSelect); stream.Write((byte)index); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable); NPCClass.Hero = classDef; Close(); }
public static void DuelWin(ArenaClient winner) { if (!winner.IsDueling) { return; } var stream = ArenaClient.GetStream(ScriptMessages.DuelWin); stream.Write((ushort)winner.Character.ID); winner.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered); if (winner.DuelEnemy.IsConnected) { winner.DuelEnemy.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered); } winner.DuelEnemy.DuelDeaths++; winner.DuelEnemy.DuelScore--; winner.DuelKills++; winner.DuelScore += 2; winner.DuelEnemy.DuelEnemy = null; winner.DuelEnemy = null; }
void SelectTeam(int index) { if (!TDMMode.IsActive) { return; } var teams = TDMMode.ActiveMode.Scenario.Teams; if (index < 0 || index >= teams.Length) { return; } if ((int)PlayerInfo.HeroInfo.TeamID == index) { MenuClassSelect.Instance.Open(); Close(); return; } if (!lockTimer.IsReady) { return; } var stream = ArenaClient.GetStream(ScriptMessages.TDMTeamSelect); stream.Write((byte)index); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable); }
void Spectate() { var stream = ArenaClient.GetScriptMessageStream(); stream.Write((byte)ScriptMessages.SpectateTeam); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable); Close(); }
void Join() { if (PlayerInfo.HeroInfo.TeamID != GameModes.TeamIdent.FFAPlayer) { ArenaClient.SendJoinGameMessage(); } Close(); }
void Spectate() { if (PlayerInfo.HeroInfo.TeamID != GameModes.TeamIdent.FFASpectator) { ArenaClient.SendSpectateMessage(); } Close(); }
protected override NPCInst SpawnCharacter(ArenaClient client, WorldInst world, PosAng spawnPoint) { NPCInst pc = base.SpawnCharacter(client, world, spawnPoint); pc.AllowHitTarget.Add(OnAllowHit); pc.DropUnconsciousOnDeath = true; pc.UnconsciousDuration = -1; return(pc); }
void Spectate() { if (PlayerInfo.HeroInfo.TeamID != TeamIdent.GMSpectator) { var stream = ArenaClient.GetStream(ScriptMessages.ModeSpectate); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered); } Close(); }
void Join() { if (PlayerInfo.HeroInfo.TeamID < TeamIdent.GMPlayer) { var stream = ArenaClient.GetStream(ScriptMessages.BRJoin); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable); } Close(); }
static void SendRequest(ArenaClient requester, ArenaClient target) { var stream = ArenaClient.GetScriptMessageStream(); stream.Write((byte)ScriptMessages.DuelRequest); stream.Write((ushort)requester.Character.ID); stream.Write((ushort)target.Character.ID); requester.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable); target.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable); }
protected void SetPhase(GamePhase phase) { this.Phase = phase; Log.Logger.Log("Set Phase " + phase); // send phase update to clients var stream = ArenaClient.GetStream(ScriptMessages.ModePhase); stream.Write((byte)Phase); ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered)); }
void FFAStart() { if (ArenaClient.FFAJoined) { FreeModeMenu.Instance.Open(); return; } ArenaClient.SendSpectateMessage(); Close(); }
public override void OnSuicide(ArenaClient client) { if (Phase < GamePhase.Fight) { return; } client.GMScore--; client.GMDeaths++; client.TDMTeam.Score--; }
public async Task SignTransactionAsync() { WabiSabiConfig config = new(); Round round = WabiSabiFactory.CreateRound(config); using Key key1 = new(); Alice alice1 = WabiSabiFactory.CreateAlice(key: key1); round.Alices.Add(alice1); using Key key2 = new(); Alice alice2 = WabiSabiFactory.CreateAlice(key: key2); round.Alices.Add(alice2); var coinjoin = round.Coinjoin; using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(config, round); var mockRpc = new Mock <IRPCClient>(); await using var coordinator = new ArenaRequestHandler(config, new Prison(), arena, mockRpc.Object); var rnd = new InsecureRandom(); var amountClient = new WabiSabiClient(round.AmountCredentialIssuerParameters, 2, rnd, 4300000000000ul); var weightClient = new WabiSabiClient(round.WeightCredentialIssuerParameters, 2, rnd, 2000ul); var apiClient = new ArenaClient(amountClient, weightClient, coordinator); round.SetPhase(Phase.TransactionSigning); // No inputs in the CoinJoin. await Assert.ThrowsAsync <ArgumentException>(async() => await apiClient.SignTransactionAsync(round.Id, alice1.Coins.ToArray(), new BitcoinSecret(key1, Network.Main), coinjoin)); coinjoin.Inputs.Add(alice1.Coins.First().Outpoint); // Trying to sign coins those are not in the CoinJoin. await Assert.ThrowsAsync <InvalidOperationException>(async() => await apiClient.SignTransactionAsync(round.Id, alice2.Coins.ToArray(), new BitcoinSecret(key2, Network.Main), coinjoin)); coinjoin.Inputs.Add(alice2.Coins.First().Outpoint); // Trying to sign coins with the wrong secret. await Assert.ThrowsAsync <InvalidOperationException>(async() => await apiClient.SignTransactionAsync(round.Id, alice1.Coins.ToArray(), new BitcoinSecret(key2, Network.Main), coinjoin)); Assert.False(round.Coinjoin.HasWitness); await apiClient.SignTransactionAsync(round.Id, alice1.Coins.ToArray(), new BitcoinSecret(key1, Network.Main), coinjoin); Assert.True(round.Coinjoin.Inputs.Where(i => alice1.Coins.Select(c => c.Outpoint).Contains(i.PrevOut)).All(i => i.HasWitScript())); await apiClient.SignTransactionAsync(round.Id, alice2.Coins.ToArray(), new BitcoinSecret(key2, Network.Main), coinjoin); Assert.True(round.Coinjoin.Inputs.Where(i => alice2.Coins.Select(c => c.Outpoint).Contains(i.PrevOut)).All(i => i.HasWitScript())); }
public async Task <ArenaClient> CreateArenaClientAsync(WabiSabiHttpApiClient wabiSabiHttpApiClient) { var rounds = (await wabiSabiHttpApiClient.GetStatusAsync(RoundStateRequest.Empty, CancellationToken.None)).RoundStates; var round = rounds.First(x => x.CoinjoinState is ConstructionState); var insecureRandom = new InsecureRandom(); var arenaClient = new ArenaClient( round.CreateAmountCredentialClient(insecureRandom), round.CreateVsizeCredentialClient(insecureRandom), wabiSabiHttpApiClient); return(arenaClient); }
public void Join(ArenaClient client) { if (Phase != GamePhase.WarmUp) { return; } players.Add(client); client.GMClass = BRScenario.StartClass; SpawnCharacter(client, World, Randomizer.Get(Scenario.Spawnpoints)); }
public override void Close() { base.Close(); arrow.Hide(); var stream = ArenaClient.GetScriptMessageStream(); stream.Write((byte)ScriptMessages.TOTeamCount); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable); TeamMode.OnPhaseChange -= TOPhaseChanged; }
protected virtual void Start(GameScenario scenario) { this.Scenario = scenario; var stream = ArenaClient.GetStream(ScriptMessages.ModeStart); stream.Write(scenario.Name); ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered)); Phase = GamePhase.None; phaseTimer.Stop(); }
public static void SendRequest(NPCInst target) { if (!requestTime.IsReady) { return; } var stream = ArenaClient.GetScriptMessageStream(); stream.Write((byte)ScriptMessages.DuelRequest); stream.Write((ushort)target.ID); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Unreliable); }
void GameModeStart() { if (ArenaClient.GMJoined) { GameMode.ActiveMode.OpenJoinMenu(); return; } var stream = ArenaClient.GetStream(ScriptMessages.ModeSpectate); ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered); Close(); }
public override void OnSuicide(ArenaClient client) { if (Phase < GamePhase.Fight) { return; } client.GMDeaths++; if (players.TrueForAll(p => !p.IsCharacter || p.Character.IsDead || p.Character.IsUnconscious)) { HordeFadeOut(false); } }
public override bool Leave(ArenaClient client) { if (!base.Leave(client)) { return(false); } if (client.TDMTeam != null) { client.TDMTeam.Players.Remove(client); client.TDMTeam = null; } return(true); }
protected virtual NPCInst InitialSpawnClient(ArenaClient client, bool inSpawnWorld) { NPCInst npc; if (inSpawnWorld && SpawnWorld != null) { npc = SpawnCharacter(client, SpawnWorld, Scenario.SpawnWorldPos, Scenario.SpawnWorldRange); } else { npc = SpawnCharacter(client, World, Scenario.SpawnPos, Scenario.SpawnRange); } return(npc); }
static void DuelEnd(ArenaClient client) { if (!client.IsDueling) { return; } var stream = ArenaClient.GetScriptMessageStream(); stream.Write((byte)ScriptMessages.DuelEnd); client.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered); client.DuelEnemy.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered); client.DuelEnemy.DuelEnemy = null; client.DuelEnemy = null; }