public int GetGoldGainsFromKillData( MPPerkObject.MPPerkHandler killerPerkHandler, MPPerkObject.MPPerkHandler assistingHitterPerkHandler, MultiplayerClassDivisions.MPHeroClass victimClass, bool isAssist) { int num1; if (isAssist) { num1 = (killerPerkHandler != null ? killerPerkHandler.GetRewardedGoldOnAssist() : 0) + (assistingHitterPerkHandler != null ? assistingHitterPerkHandler.GetGoldOnAssist() : 0); } else { int num2 = this.ControlledAgent != null?MultiplayerClassDivisions.GetMPHeroClassForCharacter(this.ControlledAgent.Character).TroopCost : 0; num1 = killerPerkHandler != null?killerPerkHandler.GetGoldOnKill((float)num2, (float)victimClass.TroopCost) : 0; } if (num1 > 0) { GameNetwork.BeginModuleEventAsServer(this.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new TDMGoldGain(new List <KeyValuePair <ushort, int> >() { new KeyValuePair <ushort, int>((ushort)2048, num1) })); GameNetwork.EndModuleEventAsServer(); } return(num1); }
public void OnDuelStarted(Agent requesterAgent, Agent requesteeAgent) { switch (this.PlayerType) { case MissionRepresentativeBase.PlayerTypes.Client: if (this.IsMine) { Action duelStartedEvent = this.OnDuelStartedEvent; if (duelStartedEvent == null) { break; } duelStartedEvent(); break; } GameNetwork.BeginModuleEventAsServer(this.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new DuelStarted(requesterAgent, requesteeAgent)); GameNetwork.EndModuleEventAsServer(); break; case MissionRepresentativeBase.PlayerTypes.Server: Action duelStartedEvent1 = this.OnDuelStartedEvent; if (duelStartedEvent1 == null) { break; } duelStartedEvent1(); break; } }
private void OnAgentWentInOrRemoved(Agent agent, bool isAgentRemoved) { if (GameNetwork.IsServer) { this._agentTimers.Remove(agent); if (!isAgentRemoved) { MissionPeer missionPeer = agent.MissionPeer; NetworkCommunicator communicator = missionPeer != null?missionPeer.GetNetworkPeer() : (NetworkCommunicator)null; if (communicator != null && !communicator.IsServerPeer) { GameNetwork.BeginModuleEventAsServer(communicator); GameNetwork.WriteMessage((GameNetworkMessage) new SetBoundariesState(false)); GameNetwork.EndModuleEventAsServer(); } } } if (this.Mission.MainAgent != agent) { return; } this._mainAgentLeaveTimer = (MissionTimer)null; Action stopTime = this.StopTime; if (stopTime == null) { return; } stopTime(); }
public void HandleAgentVisualSpawning( NetworkCommunicator spawningNetworkPeer, AgentBuildData spawningAgentBuildData, int troopCountInFormation = 0) { MissionPeer component = spawningNetworkPeer.GetComponent <MissionPeer>(); component.HasSpawnedAgentVisuals = true; component.EquipmentUpdatingExpired = false; if (!this.IsGameModeHidingAllAgentVisuals) { GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new CreateAgentVisuals(spawningNetworkPeer, spawningAgentBuildData, component.SelectedTroopIndex, troopCountInFormation)); GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.ExcludeOtherTeamPlayers, spawningNetworkPeer); } else { if (spawningNetworkPeer.IsServerPeer) { return; } GameNetwork.BeginModuleEventAsServer(spawningNetworkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new CreateAgentVisuals(spawningNetworkPeer, spawningAgentBuildData, component.SelectedTroopIndex, troopCountInFormation)); GameNetwork.EndModuleEventAsServer(); } }
public override void HandleNewClientAfterLoadingFinished(NetworkCommunicator networkPeer) { VirtualPlayer virtualPlayer1 = networkPeer.VirtualPlayer; GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new InitializeLobbyPeer(networkPeer, virtualPlayer1.Id, virtualPlayer1.BannerCode, virtualPlayer1.BodyProperties, virtualPlayer1.ChosenBadgeIndex, -1)); GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.AddToMissionRecord | GameNetwork.EventBroadcastFlags.DontSendToPeers); foreach (NetworkCommunicator networkPeer1 in GameNetwork.NetworkPeers) { if (networkPeer1.IsSynchronized || networkPeer1 == networkPeer) { if (networkPeer1 != networkPeer && networkPeer1 != GameNetwork.MyPeer) { GameNetwork.BeginModuleEventAsServer(networkPeer1); GameNetwork.WriteMessage((GameNetworkMessage) new InitializeLobbyPeer(networkPeer, virtualPlayer1.Id, virtualPlayer1.BannerCode, virtualPlayer1.BodyProperties, virtualPlayer1.ChosenBadgeIndex, -1)); GameNetwork.EndModuleEventAsServer(); } VirtualPlayer virtualPlayer2 = networkPeer1.VirtualPlayer; if (!networkPeer.IsServerPeer) { GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new InitializeLobbyPeer(networkPeer1, virtualPlayer2.Id, virtualPlayer2.BannerCode, virtualPlayer2.BodyProperties, virtualPlayer2.ChosenBadgeIndex, -1)); GameNetwork.EndModuleEventAsServer(); } } } }
public override void HandleNewClientConnect(PlayerConnectionInfo playerConnectionInfo) { NetworkCommunicator networkPeer = playerConnectionInfo.NetworkPeer; if (networkPeer.IsServerPeer) { return; } GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new MultiplayerOptionsInitial()); GameNetwork.EndModuleEventAsServer(); GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new MultiplayerOptionsImmediate()); GameNetwork.EndModuleEventAsServer(); if (BannerlordNetwork.LobbyMissionType != LobbyMissionType.Custom) { return; } bool inMission = false; string map = ""; string gameType = ""; if (GameNetwork.IsDedicatedServer && Mission.Current != null || !GameNetwork.IsDedicatedServer) { inMission = true; MultiplayerOptions.Instance.GetOptionFromOptionType(MultiplayerOptions.OptionType.Map).GetValue(out map); MultiplayerOptions.Instance.GetOptionFromOptionType(MultiplayerOptions.OptionType.GameType).GetValue(out gameType); } GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new InitializeCustomGameMessage(inMission, gameType, map)); GameNetwork.EndModuleEventAsServer(); }
private static void ServerSendMessageToEveryone(NetworkCommunicator networkPeer, string message) { foreach (NetworkCommunicator communicator in GameNetwork.NetworkPeers.Where <NetworkCommunicator>((Func <NetworkCommunicator, bool>)(x => !x.IsServerPeer && x.IsSynchronized && x != networkPeer))) { GameNetwork.BeginModuleEventAsServer(communicator); GameNetwork.WriteMessage((GameNetworkMessage) new NetworkMessages.FromServer.PlayerMessageAll(networkPeer, message)); GameNetwork.EndModuleEventAsServer(); } }
private bool ServerPrepareAndSendMessage( NetworkCommunicator fromPeer, bool toTeamOnly, string message) { if (fromPeer.IsMuted) { GameNetwork.BeginModuleEventAsServer(fromPeer); GameNetwork.WriteMessage((GameNetworkMessage) new NetworkMessages.FromServer.ServerMessage("str_multiplayer_muted_message", true)); GameNetwork.EndModuleEventAsServer(); return(true); } if (!GameNetwork.IsDedicatedServer && fromPeer != GameNetwork.MyPeer && !this._mutedPlayers.Contains(fromPeer.VirtualPlayer.Id)) { MissionPeer component1 = GameNetwork.MyPeer.GetComponent <MissionPeer>(); if (component1 == null) { return(false); } bool flag; if (toTeamOnly) { if (component1 == null) { return(false); } MissionPeer component2 = fromPeer.GetComponent <MissionPeer>(); if (component2 == null) { return(false); } flag = component1.Team == component2.Team; } else { flag = true; } if (flag) { this.OnPlayerMessageReceived(fromPeer, message, toTeamOnly); } } if (toTeamOnly) { ChatBox.ServerSendMessageToTeam(fromPeer, message); } else { ChatBox.ServerSendMessageToEveryone(fromPeer, message); } return(true); }
private void SendExistingObjectsToPeer(NetworkCommunicator peer) { long stateStartTimeInTicks = 0; if (this.CurrentMultiplayerState != MissionLobbyComponent.MultiplayerGameState.WaitingFirstPlayers) { stateStartTimeInTicks = this._timerComponent.GetCurrentTimerStartTime().NumberOfTicks; } GameNetwork.BeginModuleEventAsServer(peer); GameNetwork.WriteMessage((GameNetworkMessage) new MissionStateChange(this.CurrentMultiplayerState, stateStartTimeInTicks)); GameNetwork.EndModuleEventAsServer(); this.SendPeerInformationsToPeer(peer); }
public int GetGoldGainsFromAllyDeathReward(int baseAmount) { if (baseAmount > 0 && !this.Peer.Communicator.IsServerPeer && this.Peer.Communicator.IsConnectionActive) { GameNetwork.BeginModuleEventAsServer(this.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new TDMGoldGain(new List <KeyValuePair <ushort, int> >() { new KeyValuePair <ushort, int>((ushort)2048, baseAmount) })); GameNetwork.EndModuleEventAsServer(); } return(baseAmount); }
private static void ServerSendMessageToTeam(NetworkCommunicator networkPeer, string message) { MissionPeer missionPeer = networkPeer.GetComponent <MissionPeer>(); if (missionPeer.Team == null) { return; } foreach (NetworkCommunicator communicator in GameNetwork.NetworkPeers.Where <NetworkCommunicator>((Func <NetworkCommunicator, bool>)(x => !x.IsServerPeer && x.IsSynchronized && x != networkPeer && x.GetComponent <MissionPeer>().Team == missionPeer.Team))) { GameNetwork.BeginModuleEventAsServer(communicator); GameNetwork.WriteMessage((GameNetworkMessage) new NetworkMessages.FromServer.PlayerMessageTeam(networkPeer, message)); GameNetwork.EndModuleEventAsServer(); } }
private void RejectPollStartServer( NetworkCommunicator pollCreatorPeer, MultiplayerPollComponent.PollRejectReason rejectReason) { if (pollCreatorPeer.IsMine) { this.RejectPollStartServer(rejectReason.ToString()); } else { GameNetwork.BeginModuleEventAsServer(pollCreatorPeer); GameNetwork.WriteMessage((GameNetworkMessage) new RejectPollStart(rejectReason.ToString())); GameNetwork.EndModuleEventAsServer(); } }
private void SendNotificationToPeer( NetworkCommunicator peer, MultiplayerGameNotificationsComponent.MultiplayerNotificationEnum message, int param1 = -1, int param2 = -1) { if (peer.IsServerPeer) { this.ShowNotification(message, param1, param2); } else { GameNetwork.BeginModuleEventAsServer(peer); GameNetwork.WriteMessage((GameNetworkMessage) new NotificationMessage((int)message, param1, param2)); GameNetwork.EndModuleEventAsServer(); } }
public int GetGoldGainsFromObjectiveAssist( GameEntity objectiveMostParentEntity, float contributionRatio, bool isCompleted) { int num = (int)((double)contributionRatio * (double)this.GetTotalGoldDistributionForDestructable(objectiveMostParentEntity)); if (num > 0 && !this.Peer.Communicator.IsServerPeer && this.Peer.Communicator.IsConnectionActive) { GameNetwork.BeginModuleEventAsServer(this.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new TDMGoldGain(new List <KeyValuePair <ushort, int> >() { new KeyValuePair <ushort, int>(isCompleted ? (ushort)512 : (ushort)1024, num) })); GameNetwork.EndModuleEventAsServer(); } return(num); }
protected override void HandleNewClientAfterSynchronized(NetworkCommunicator networkPeer) { networkPeer.AddComponent <FlagDominationMissionRepresentative>(); if (this.UseGold() && !this.RoundController.IsRoundInProgress) { this.ChangeCurrentGoldForPeer(networkPeer.GetComponent <MissionPeer>(), 300); this._gameModeFlagDominationClient?.OnGoldAmountChangedForRepresentative((MissionRepresentativeBase)networkPeer.GetComponent <FlagDominationMissionRepresentative>(), 300); } if (this.AllCapturePoints == null || networkPeer.IsServerPeer) { return; } foreach (FlagCapturePoint flagCapturePoint in this.AllCapturePoints.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => !cp.IsDeactivated))) { GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationCapturePointMessage(flagCapturePoint.FlagIndex, this._capturePointOwners[flagCapturePoint.FlagIndex])); GameNetwork.EndModuleEventAsServer(); } }
private void SendPeerInformationsToPeer(NetworkCommunicator peer) { foreach (NetworkCommunicator networkPeer in GameNetwork.NetworkPeers) { if (networkPeer.IsSynchronized) { MissionPeer component = networkPeer.GetComponent <MissionPeer>(); GameNetwork.BeginModuleEventAsServer(peer); GameNetwork.WriteMessage((GameNetworkMessage) new KillDeathCountChange(component.GetNetworkPeer(), (NetworkCommunicator)null, component.KillCount, component.AssistCount, component.DeathCount, component.Score)); GameNetwork.EndModuleEventAsServer(); if (component.BotsUnderControlAlive != 0 || component.BotsUnderControlTotal != 0) { GameNetwork.BeginModuleEventAsServer(peer); GameNetwork.WriteMessage((GameNetworkMessage) new BotsControlledChange(component.GetNetworkPeer(), component.BotsUnderControlAlive, component.BotsUnderControlTotal)); GameNetwork.EndModuleEventAsServer(); } } } }
protected override void HandleLateNewClientAfterLoadingFinished(NetworkCommunicator networkPeer) { if (!this.GameModeBaseClient.IsGameModeUsingGold) { return; } foreach (NetworkCommunicator networkPeer1 in GameNetwork.NetworkPeers) { if (networkPeer1 != networkPeer) { MissionRepresentativeBase component = networkPeer1.GetComponent <MissionRepresentativeBase>(); if (component != null) { GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new SyncGoldsForSkirmish(component.Peer, component.Gold)); GameNetwork.EndModuleEventAsServer(); } } } }
public void SyncHealthToClients() { if (this.SyncToAllClients && (!this.Agent.IsMount || this.Agent.RiderAgent != null)) { GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new SetAgentHealth(this.Agent, (int)this.Agent.Health)); GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None); } else { NetworkCommunicator networkCommunicator; if (!this.Agent.IsMount) { MissionPeer missionPeer = this.Agent.MissionPeer; networkCommunicator = missionPeer != null?missionPeer.GetNetworkPeer() : (NetworkCommunicator)null; } else { Agent riderAgent = this.Agent.RiderAgent; if (riderAgent == null) { networkCommunicator = (NetworkCommunicator)null; } else { MissionPeer missionPeer = riderAgent.MissionPeer; networkCommunicator = missionPeer != null?missionPeer.GetNetworkPeer() : (NetworkCommunicator)null; } } NetworkCommunicator communicator = networkCommunicator; if (communicator == null || communicator.IsServerPeer) { return; } GameNetwork.BeginModuleEventAsServer(communicator); GameNetwork.WriteMessage((GameNetworkMessage) new SetAgentHealth(this.Agent, (int)this.Agent.Health)); GameNetwork.EndModuleEventAsServer(); } }
public void OnDuelRequested(Agent requesterAgent) { this._requesters.Add(new Tuple <Agent, MissionTime>(requesterAgent, MissionTime.Now + MissionTime.Seconds(3f))); switch (this.PlayerType) { case MissionRepresentativeBase.PlayerTypes.Bot: this._missionMultiplayerDuel.DuelRequestAccepted(requesterAgent, this.ControlledAgent); break; case MissionRepresentativeBase.PlayerTypes.Client: if (this.IsMine) { Action duelRequestedEvent = this.OnDuelRequestedEvent; if (duelRequestedEvent == null) { break; } duelRequestedEvent(); break; } GameNetwork.BeginModuleEventAsServer(this.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new NetworkMessages.FromServer.DuelRequest(requesterAgent, this.ControlledAgent)); GameNetwork.EndModuleEventAsServer(); break; case MissionRepresentativeBase.PlayerTypes.Server: Action duelRequestedEvent1 = this.OnDuelRequestedEvent; if (duelRequestedEvent1 == null) { break; } duelRequestedEvent1(); break; default: throw new ArgumentOutOfRangeException(); } }
private void SendNotificationToTeam( Team team, MultiplayerGameNotificationsComponent.MultiplayerNotificationEnum message, int param1 = -1, int param2 = -1) { NetworkCommunicator myPeer = GameNetwork.MyPeer; MissionPeer missionPeer = myPeer != null?myPeer.GetComponent <MissionPeer>() : (MissionPeer)null; if (!GameNetwork.IsDedicatedServer && (missionPeer?.Team != null && missionPeer.Team.IsEnemyOf(team))) { this.ShowNotification(message, param1, param2); } foreach (MissionPeer peer in VirtualPlayer.Peers <MissionPeer>()) { if (peer.Team != null && !peer.IsMine && !peer.Team.IsEnemyOf(team)) { GameNetwork.BeginModuleEventAsServer(peer.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new NotificationMessage((int)message, param1, param2)); GameNetwork.EndModuleEventAsServer(); } } }
protected override void HandleLateNewClientAfterSynchronized(NetworkCommunicator networkPeer) { networkPeer.GetComponent <MissionPeer>(); foreach (MissionScoreboardComponent.MissionScoreboardSide side in this._sides) { if (side != null && !networkPeer.IsServerPeer) { if (side.BotScores.IsAnyValid) { GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new NetworkMessages.FromServer.BotData(side.Side, side.BotScores.KillCount, side.BotScores.AssistCount, side.BotScores.DeathCount, side.BotScores.AliveCount)); GameNetwork.EndModuleEventAsServer(); } if (this._mpGameModeBase != null) { int defenderTeamScore = this._scoreboardSides != MissionScoreboardComponent.ScoreboardSides.OneSide ? this._sides[0].SideScore : 0; GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new NetworkMessages.FromServer.UpdateRoundScores(this._sides[1].SideScore, defenderTeamScore)); GameNetwork.EndModuleEventAsServer(); } } } }
public void OnDuelPreparation(Agent requesterAgent, Agent requesteeAgent) { switch (this.PlayerType) { case MissionRepresentativeBase.PlayerTypes.Client: if (this.IsMine) { Action <Agent, int> prepStartedEvent = this.OnDuelPrepStartedEvent; if (prepStartedEvent != null) { prepStartedEvent(this.ControlledAgent == requesterAgent ? requesteeAgent : requesterAgent, 3); break; } break; } GameNetwork.BeginModuleEventAsServer(this.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new DuelSessionStarted(requesterAgent, requesteeAgent)); GameNetwork.EndModuleEventAsServer(); break; case MissionRepresentativeBase.PlayerTypes.Server: Action <Agent, int> prepStartedEvent1 = this.OnDuelPrepStartedEvent; if (prepStartedEvent1 != null) { prepStartedEvent1(this.ControlledAgent == requesterAgent ? requesteeAgent : requesterAgent, 3); break; } break; } Tuple <Agent, MissionTime> tuple = this._requesters.FirstOrDefault <Tuple <Agent, MissionTime> >((Func <Tuple <Agent, MissionTime>, bool>)(req => req.Item1 == requesterAgent)); if (tuple == null) { return; } this._requesters.Remove(tuple); }
private void OnAgentWentOut(Agent agent, float startTimeInSeconds) { MissionTimer missionTimer = GameNetwork.IsClient ? MissionTimer.CreateSynchedTimerClient(startTimeInSeconds, 10f) : new MissionTimer(10f); if (GameNetwork.IsServer) { this._agentTimers.Add(agent, missionTimer); MissionPeer missionPeer = agent.MissionPeer; NetworkCommunicator communicator = missionPeer != null?missionPeer.GetNetworkPeer() : (NetworkCommunicator)null; if (communicator != null && !communicator.IsServerPeer) { GameNetwork.BeginModuleEventAsServer(communicator); GameNetwork.WriteMessage((GameNetworkMessage) new SetBoundariesState(true, missionTimer.GetStartTime().NumberOfTicks)); GameNetwork.EndModuleEventAsServer(); } } if (this.Mission.MainAgent != agent) { return; } this._mainAgentLeaveTimer = missionTimer; Action <float, float> startTime = this.StartTime; if (startTime != null) { startTime(10f, 0.0f); } MatrixFrame cameraFrame = Mission.Current.GetCameraFrame(); Vec3 position = cameraFrame.origin + cameraFrame.rotation.u; if (Mission.Current.Mode != MissionMode.Battle) { return; } MBSoundEvent.PlaySound(SoundEvent.GetEventIdFromString("event:/alerts/report/out_of_map"), position); }
public int GetGoldGainsFromKillDataAndUpdateFlags( MPPerkObject.MPPerkHandler killerPerkHandler, MPPerkObject.MPPerkHandler assistingHitterPerkHandler, MultiplayerClassDivisions.MPHeroClass victimClass, bool isAssist, bool isRanged) { int num1 = 0; List <KeyValuePair <ushort, int> > goldChangeEventList = new List <KeyValuePair <ushort, int> >(); if (isAssist) { int num2 = 1; int num3 = (killerPerkHandler != null ? killerPerkHandler.GetRewardedGoldOnAssist() : 0) + (assistingHitterPerkHandler != null ? assistingHitterPerkHandler.GetGoldOnAssist() : 0); if (num3 > 0) { num1 += num3; this._currentGoldGains |= GoldGainFlags.PerkBonus; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)2048, num3)); } switch (this.MissionPeer.AssistCount - this._assistCountOnSpawn) { case 1: num1 += 10; this._currentGoldGains |= GoldGainFlags.FirstAssist; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)4, 10)); break; case 2: num1 += 10; this._currentGoldGains |= GoldGainFlags.SecondAssist; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)8, 10)); break; case 3: num1 += 10; this._currentGoldGains |= GoldGainFlags.ThirdAssist; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)16, 10)); break; default: num1 += num2; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)256, num2)); break; } } else { int num2 = 0; if (this.ControlledAgent != null) { num2 = MultiplayerClassDivisions.GetMPHeroClassForCharacter(this.ControlledAgent.Character).TroopCost; int num3 = 2 + Math.Max(0, (victimClass.TroopCost - num2) / 2); num1 += num3; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)128, num3)); } int num4 = killerPerkHandler != null?killerPerkHandler.GetGoldOnKill((float)num2, (float)victimClass.TroopCost) : 0; if (num4 > 0) { num1 += num4; this._currentGoldGains |= GoldGainFlags.PerkBonus; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)2048, num4)); } switch (this.MissionPeer.KillCount - this._killCountOnSpawn) { case 5: num1 += 20; this._currentGoldGains |= GoldGainFlags.FifthKill; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)32, 20)); break; case 10: num1 += 30; this._currentGoldGains |= GoldGainFlags.TenthKill; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)64, 30)); break; } if (isRanged && !this._currentGoldGains.HasAnyFlag <GoldGainFlags>(GoldGainFlags.FirstRangedKill)) { num1 += 10; this._currentGoldGains |= GoldGainFlags.FirstRangedKill; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)1, 10)); } if (!isRanged && !this._currentGoldGains.HasAnyFlag <GoldGainFlags>(GoldGainFlags.FirstMeleeKill)) { num1 += 10; this._currentGoldGains |= GoldGainFlags.FirstMeleeKill; goldChangeEventList.Add(new KeyValuePair <ushort, int>((ushort)2, 10)); } } int num5 = 0; if (this.MissionPeer.Team == Mission.Current.Teams.Attacker) { num5 = MultiplayerOptions.OptionType.GoldGainChangePercentageTeam1.GetIntValue(); } else if (this.MissionPeer.Team == Mission.Current.Teams.Defender) { num5 = MultiplayerOptions.OptionType.GoldGainChangePercentageTeam2.GetIntValue(); } if (num5 != 0 && (num1 > 0 || goldChangeEventList.Count > 0)) { num1 = 0; float num2 = (float)(1.0 + (double)num5 * 0.00999999977648258); for (int index = 0; index < goldChangeEventList.Count; ++index) { int num3 = (int)((double)goldChangeEventList[index].Value * (double)num2); goldChangeEventList[index] = new KeyValuePair <ushort, int>(goldChangeEventList[index].Key, num3); num1 += num3; } } if (goldChangeEventList.Count > 0 && !this.Peer.Communicator.IsServerPeer && this.Peer.Communicator.IsConnectionActive) { GameNetwork.BeginModuleEventAsServer(this.Peer); GameNetwork.WriteMessage((GameNetworkMessage) new TDMGoldGain(goldChangeEventList)); GameNetwork.EndModuleEventAsServer(); } return(num1); }
public override void OnUdpNetworkHandlerTick(float dt) { if (!GameNetwork.IsServer) { return; } float time = MBCommon.GetTime(MBCommon.TimeType.Mission); foreach (NetworkCommunicator networkPeer in GameNetwork.NetworkPeers) { if (networkPeer.IsSynchronized) { while (this._peerData.Count <= networkPeer.Index) { this._peerData.Add(new NetworkStatusReplicationComponent.NetworkStatusData()); } double pingInMilliseconds = networkPeer.RefreshAndGetAveragePingInMilliseconds(); NetworkStatusReplicationComponent.NetworkStatusData networkStatusData = this._peerData[networkPeer.Index]; bool flag = (double)networkStatusData.NextPingForceSendTime <= (double)time; if (flag || (double)networkStatusData.NextPingTrySendTime <= (double)time) { int ping = pingInMilliseconds.Round(); if (flag || networkStatusData.LastSentPingValue != ping) { networkStatusData.LastSentPingValue = ping; networkStatusData.NextPingForceSendTime = time + 10f + MBRandom.RandomFloatRanged(1.5f, 2.5f); GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new PingReplication(networkPeer, ping)); GameNetwork.EndBroadcastModuleEventUnreliable(GameNetwork.EventBroadcastFlags.None); } networkStatusData.NextPingTrySendTime = time + MBRandom.RandomFloatRanged(1.5f, 2.5f); } if (!networkPeer.IsServerPeer && (double)networkStatusData.NextLossTrySendTime <= (double)time) { networkStatusData.NextLossTrySendTime = time + MBRandom.RandomFloatRanged(1.5f, 2.5f); int averageLossPercent = (int)networkPeer.RefreshAndGetAverageLossPercent(); if (networkStatusData.LastSentLossValue != averageLossPercent) { networkStatusData.LastSentLossValue = averageLossPercent; GameNetwork.BeginModuleEventAsServer(networkPeer); GameNetwork.WriteMessage((GameNetworkMessage) new LossReplicationMessage(averageLossPercent)); GameNetwork.EndModuleEventAsServer(); } } } } if ((double)this._nextPerformanceStateTrySendTime > (double)time) { return; } this._nextPerformanceStateTrySendTime = time + MBRandom.RandomFloatRanged(1.5f, 2.5f); ServerPerformanceState performanceState = this.GetServerPerformanceState(); if (performanceState == this._lastSentPerformanceState) { return; } this._lastSentPerformanceState = performanceState; GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new ServerPerformanceStateReplicationMessage(performanceState)); GameNetwork.EndBroadcastModuleEventUnreliable(GameNetwork.EventBroadcastFlags.None); }
public void SynchronizeToPeer(NetworkCommunicator peer) { GameNetwork.BeginModuleEventAsServer(peer); GameNetwork.WriteMessage((GameNetworkMessage) new FlagRaisingStatus(this.Flag.Progress, this.Flag.Direction, this.Flag.Speed)); GameNetwork.EndModuleEventAsServer(); }