private static int ModifyFactor(int baseValue, float factor) { if (baseValue == 0) { return(0); } if (!MBMath.ApproximatelyEquals(factor, 0.0f)) { baseValue = (double)factor <= 1.0 ? MathF.Floor(factor * (float)baseValue) : MathF.Ceiling(factor * (float)baseValue); } return(baseValue); }
protected internal override void OnTick(float dt) { base.OnTick(dt); if (GameNetwork.IsServer && !this._stopUpdating) { if (Mission.Current == null || Mission.Current.AttackerTeam == null || Mission.Current.DefenderTeam == null) { return; } int defendingSideCount = this.DefendingSideCount; int attackingSideCount = this.AttackingSideCount; this._status = attackingSideCount <= 0 || defendingSideCount != 0 ? (attackingSideCount <= 0 || defendingSideCount <= 0 ? (attackingSideCount != 0 || defendingSideCount <= 0 ? CaptureTheFlagCapturePointSiege.FlagStatusEnum.NoAttackersAndDefenders : CaptureTheFlagCapturePointSiege.FlagStatusEnum.DefendersOnly) : CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersAndDefenders) : CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersOnly; if (this._status != CaptureTheFlagCapturePointSiege.FlagStatusEnum.None) { float num = 0.0f; bool flag1 = false; bool flag2 = this._prevStatus != this._status; if (flag2) { this._flagSyncTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission)); } switch (this._status) { case CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersOnly: num = dt / this.FlagRaiseTime; this.Flag.Direction = CaptureTheFlagFlagDirection.Up; this.Flag.Speed = this.FlagRaiseTime; break; case CaptureTheFlagCapturePointSiege.FlagStatusEnum.DefendersOnly: num = -dt / this.FlagLowerTime; this.Flag.Direction = CaptureTheFlagFlagDirection.Down; this.Flag.Speed = this.FlagLowerTime; break; case CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersAndDefenders: num = 0.0f; this.Flag.Direction = CaptureTheFlagFlagDirection.Static; break; case CaptureTheFlagCapturePointSiege.FlagStatusEnum.NoAttackersAndDefenders: num = -dt / this.FlagLowerTime; this.Flag.Direction = CaptureTheFlagFlagDirection.Down; this.Flag.Speed = this.FlagLowerTime; break; } this.Flag.Progress += num; if (flag1 || (double)this.Flag.Progress >= 1.0) { this.OnRaised(); flag2 = true; this._stopUpdating = true; this.Flag.Direction = CaptureTheFlagFlagDirection.Static; } this.Flag.Progress = MBMath.ClampFloat(this.Flag.Progress, 0.0f, 1f); if (this.Flag.Direction == CaptureTheFlagFlagDirection.Up || this.Flag.Direction == CaptureTheFlagFlagDirection.Down) { flag2 = flag2 || this._flagSyncTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)); } if (flag2) { GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new FlagRaisingStatus(this.Flag.Progress, this.Flag.Direction, this.Flag.Speed)); GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.AddToMissionRecord); } MatrixFrame globalFrame = this.Flag.FlagHolder.GameEntity.GetGlobalFrame(); globalFrame.origin.z = MBMath.Lerp(this.Flag.FlagBottomBoundary.GetGlobalFrame().origin.z, this.Flag.FlagTopBoundary.GetGlobalFrame().origin.z, 1f - this.Flag.Progress); this.Flag.FlagHolder.GameEntity.SetGlobalFrame(globalFrame); } this._prevStatus = this._status; } if (!GameNetwork.IsClientOrReplay || !this.Flag.UpdateFlag) { return; } MatrixFrame globalFrame1 = this.Flag.FlagHolder.GameEntity.GetGlobalFrame(); globalFrame1.origin.z = MBMath.Lerp(this.Flag.FlagBottomBoundary.GetGlobalFrame().origin.z, this.Flag.FlagTopBoundary.GetGlobalFrame().origin.z, 1f - this.Flag.Progress); this.Flag.FlagHolder.GameEntity.SetGlobalFrame(globalFrame1); if (!MBMath.ApproximatelyEquals(this.Flag.Speed, 0.0f) && this.Flag.Direction != CaptureTheFlagFlagDirection.None && this.Flag.Direction != CaptureTheFlagFlagDirection.Static) { this.Flag.Progress += (float)((this.Flag.Direction == CaptureTheFlagFlagDirection.Up ? 1.0 : (this.Flag.Direction == CaptureTheFlagFlagDirection.Down ? -1.0 : 0.0)) * ((double)dt / (double)this.Flag.Speed)); } else { this.Flag.UpdateFlag = false; } this.Flag.Progress = MBMath.ClampFloat(this.Flag.Progress, 0.0f, 1f); }