public void Raise(TurretHelper turretHelper) { for (int i = this._listeners.Count - 1; i >= 0; --i) { this._listeners[i].OnEventRaised(turretHelper); } }
public void DestroyBuildBar(TurretHelper turret) { if (this._buildBars.ContainsKey(turret)) { GameObject.Destroy(this._buildBars[turret].gameObject); this._buildBars.Remove(turret); } }
public void CreateBuildBar(TurretHelper turret) { BuildBar tmp = GameObject.Instantiate(this._buildBarPrefab, this.transform); tmp.name = turret.name + " Build Bar"; tmp.Turret = turret.GetComponent <TurretBuilder>(); this._buildBars.Add(turret, tmp); }
public string Execute(List <string> message, Lobby lobby) { var type = message[1]; var id = Int32.Parse(message[2]); var userGarage = _api.Garage.GetGarageFromId(lobby.User.UserId); if (type == "h") { var hull = HullHelper.GetHelper().GetHullFromId(id); if (hull is null) { return("error;Указан неверный Id корпуса;"); } if (!(userGarage.Hulls.Any(h => h.Id == hull.Id && h.Level == hull.Level))) { return("error;У вас нет в гараже этого корпуса;"); } userGarage.CurrentHull = hull; } else if (type == "t") { var turret = TurretHelper.GetHelper().GetTurretFromId(id); if (turret is null) { return("error;Указан неверный Id башни;"); } if (!(userGarage.Turrets.Any(t => t.Id == turret.Id && t.Level == turret.Level))) { return("error;У вас нет в гараже этой башни;"); } userGarage.CurrentTurret = turret; } else if (type == "c") { IColormap color; try { color = ColormapHelper.GetHelper().Colormaps[id]; }catch (Exception e) { return("error;Указан неизвесный Id краски;"); } if (!(userGarage.Colormaps.Any(c => c.Id == color.Id))) { return("error;У вас нет краски в гараже."); } userGarage.CurrentColormap = ColormapHelper.GetHelper().Colormaps[id]; } _api.Garage.SetGarage(userGarage); return($"sett;{lobby.User.Nickname};{lobby.Garage.Crystalls};{HullHelper.GetHelper().GetCurrentHull(userGarage.CurrentHull)};{TurretHelper.GetHelper().GetCurrentTurret(userGarage.CurrentTurret)};{userGarage.CurrentColormap.Id};"); //throw new NotImplementedException(); }
public void Start() { Console.WriteLine("Old Tanks Server 2019 by Fooxboy"); Logger.Info("Запуск сервера..."); HullHelper.GetHelper().InitHulls(); TurretHelper.GetHelper().InitTurrets(); ColormapHelper.GetHelper().InitColormaps(); NumericHelper.GetHelper().InitNumerics(); var listener = new SocketConnectListener(_ip, _port, Logger); listener.NewConnectEvent += NewConnect; }
private void SpawnTurret(TurretSettings turretSettings, Vector3 position) { TurretHelper turret = GameObject.Instantiate(turretSettings.TurretPrefab, this._enemyTurretContainer); turret.transform.position = position; turret.enabled = false; turret.gameObject.layer = this._enemyTeamLayer; turret.GetComponent <EnemyTurret>().enabled = true; turret.GetComponent <AcquireTarget>().SetTargetLayer(this._playerTeamLayer); turret.Spawner = this; this._remainingTurrets.Add(turret); }
public bool forceProjectileBarrelAlignment; // align projectiles with barrel, even // if the barrel is misaligned with the // latest plan. void Start() { GameManager.Instance.RegisterTurret(this); _projectileKinematics = launchProjectile.GetComponent <ProjectileKinematics>(); _planners = TurretHelper.SortPlanners( GetComponents <TrajectoryPlannerBase>()); _pitchMotorControl = GetComponentInChildren <PitchMotorControl>(); _yawMotorControl = GetComponentInChildren <YawMotorControl>(); _barrelRecoil = GetComponentInChildren <BarrelRecoil>(); _aimForwardAxis = launchTransform.forward; }
private void Update() { this._tmpTurret.transform.position = this.GetMouseScenePosition(); if (Input.GetButtonDown("Place Turret") && this._tmpTurret.CanPlace()) { this._tmpTurret.gameObject.layer = this._playerTeamLayer; this._tmpTurret.SetBuilding(true); this._stopPlacingEvent.Raise(this._tmpTurretSettings); this._tmpTurret.TurretBuilder.SetTurretToBuild(this._tmpTurret, this._tmpTurretSettings); this._tmpTurret.TurretBuilder.enabled = true; this._tmpTurret = null; this.enabled = false; // No updates necessary so we disable the component } }
public void StartPlacingTurret(TurretSettings turretSettings) { if (this.Building) { return; } if (this._tmpTurret != null) { GameObject.Destroy(this._tmpTurret); } this.enabled = true; this._tmpTurretSettings = turretSettings; this._tmpTurret = GameObject.Instantiate(turretSettings.TurretPrefab, this._turretsContainer); this._tmpTurret.TurretPlacer = this; this._tmpTurret.transform.position = this.GetMouseScenePosition(); }
void FixedUpdate() { remainingReloadTime = Mathf.Max(remainingReloadTime - Time.deltaTime, 0.0f); UpdateTrackedPositionsAndVelocities(); // get the latest plan for the latest data bool planIsReadyForLaunch; Vector3 absoluteProjectileVelocity = TurretHelper.UpdatePlan( _planners, _projectileKinematics, launchTransform.position, _velocity, _targetPosition, _targetVelocity, remainingReloadTime, ref _plannedFlightTime, out planIsReadyForLaunch); // output debug widgets if requested if (drawDebugTrajectoryPlan) { Trajectory3D trajectory3D = new Trajectory3D( _projectileKinematics.Projectile3D, launchTransform.position + _velocity * remainingReloadTime, absoluteProjectileVelocity); TurretHelper.DebugDrawLastTrajectory(trajectory3D, _plannedFlightTime); } // if a plan has been found, update the turret's aim bool hasPlan = absoluteProjectileVelocity.sqrMagnitude > 0; Vector3 relativeProjectileVelocity = absoluteProjectileVelocity - _velocity; if (hasPlan) { UpdateTurretAim(relativeProjectileVelocity); // if the plan and aim is good enough, and there's no more remaining // weapon reload time, then launch. bool stillImprovingAimAccuracy = UpdateTurretOrientation(); if (canLaunch && planIsReadyForLaunch && !stillImprovingAimAccuracy && Vector3.Dot(relativeProjectileVelocity, launchTransform.forward) > 0) { Launch(relativeProjectileVelocity); } } }
public void SetTurretToBuild(TurretHelper turret, TurretSettings turretSettings) { this._turret = turret; this._turretSettings = turretSettings; }
public string Execute(List <string> message, Lobby lobby) { var type = message[1]; var itemId = Int32.Parse(message[2]); var count = type == "n"? Int32.Parse(message[3]): 0; var userRank = RankHelper.GetHelper().GetRankFromScore(lobby.Garage.Score); var garage = lobby.Garage; if (type == "h") { var hull = HullHelper.GetHelper().GetHullFromId(itemId); if (hull.Prices[Convert.ToInt32(hull.Level.Value)] > lobby.Garage.Crystalls) { return("error;У вас недостаточно кристалов;"); } if (hull.Ranks[Convert.ToInt32(hull.Level.Value)] > userRank) { return("error;У вас слишком маленькое звание."); } if (garage.Hulls.Any(h => h.Id == hull.Id && h.Level == hull.Level)) { return("error;У вас уже куплен этот корпус"); } if (garage.Hulls.Any(h => h.Id == hull.Id)) { var hullBuy = garage.Hulls.Single(h => h.Id == hull.Id); garage.Hulls.Remove(hullBuy); } garage.Hulls.Add(hull); garage.Crystalls -= hull.Prices[(Convert.ToInt32(hull.Level.Value))]; } else if (type == "t") { var turret = TurretHelper.GetHelper().GetTurretFromId(itemId); if (turret.Prices[Convert.ToInt32(turret.Level.Value)] > garage.Crystalls) { return("error;У вас недостаточно кристалов;"); } if (turret.Ranks[Convert.ToInt32(turret.Level.Value)] > userRank) { return("error;У вас слишком маленькое звание."); } if (garage.Turrets.Any(t => t.Id == turret.Id && t.Level == turret.Level)) { return("error;У вас уже куплена эта башня"); } if (garage.Turrets.Any(t => t.Id == turret.Id)) { var turretBuy = garage.Turrets.Single(t => t.Id == turret.Id); garage.Turrets.Remove(turretBuy); } garage.Turrets.Add(turret); garage.Crystalls -= turret.Prices[(Convert.ToInt32(turret.Level.Value))]; } else if (type == "c") { var colormap = ColormapHelper.GetHelper().Colormaps[itemId]; if (colormap.Price > garage.Crystalls) { return("error;У вас недостаточно кристалов;"); } if (colormap.Rank > userRank) { return("error;У вас слишком маленькое звание."); } if (garage.Colormaps.Any(c => c.Id == colormap.Id)) { return("error;У вас уже куплен эта краска"); } garage.Colormaps.Add(colormap); garage.Crystalls -= colormap.Price; } else if (type == "n") { if (itemId > NumericHelper.GetHelper().Numerics.Count - 1) { return("error;id слишком большое;"); } var numeric = NumericHelper.GetHelper().Numerics[itemId]; var price = numeric.Price * count; if (garage.Crystalls < price) { return("error;У Вас недостатточно кристаллов.;"); } if (userRank < numeric.Rank) { return("error;У вас слишком маленькое звание;"); } for (var i = 0; i > count; i++) { garage.Numerics.Add(numeric); } } _api.Garage.SetGarage(garage); var garStr = GarageHelper.GetHelper().GetGarageString(lobby.Garage); lobby.Send(garStr); return($"sett;{lobby.User.Nickname};{garage.Crystalls};{garage.Score};{HullHelper.GetHelper().GetCurrentHull(garage.CurrentHull)};{TurretHelper.GetHelper().GetCurrentTurret(garage.CurrentTurret)};{garage.CurrentColormap.Id};"); }
public void NotifyDestroy(TurretHelper turret) { this._remainingTurrets.Remove(turret); }
public void OnEventRaised(TurretHelper turretHelper) { this._response.Invoke(turretHelper); }
public string Execute(List <string> message, Lobby lobby) { var itemId = long.Parse(message[1]); var type = message[2]; var garage = lobby.Garage; var userRank = RankHelper.GetHelper().GetRankFromScore(garage.Score); if (type == "hull") { var hull = HullHelper.GetHelper().Hulls.Single(h => h.Id == itemId); if (garage.Hulls.Any(h => h.Id == hull.Id)) { var hullUser = garage.Hulls.Single(h => h.Id == hull.Id); var isCurrent = garage.CurrentHull.Id == hull.Id ? 1 : 0; if (hullUser.Level == 3) { return($"gi;h;{itemId};8;{isCurrent};"); } if (garage.Crystalls >= hull.Prices[0] && userRank >= hull.Ranks[0]) { return($"gi;h;{itemId};4;{hull.Prices[Convert.ToInt32(hullUser.Level + 1)]};{isCurrent};"); } if (garage.Crystalls < hull.Prices[0] && userRank >= hull.Ranks[0]) { return($"gi;h;{itemId};5;{hull.Prices[Convert.ToInt32(hullUser.Level + 1)]};{isCurrent};"); } if (garage.Crystalls >= hull.Prices[0] && userRank < hull.Ranks[0]) { return($"gi;h;{itemId};6;{hull.Prices[Convert.ToInt32(hullUser.Level + 1)]};{isCurrent};{hull.Ranks[Convert.ToInt32(hullUser.Level + 1)]}"); } if (garage.Crystalls < hull.Prices[0] && userRank < hull.Ranks[0]) { return($"gi;h;{itemId};7;{hull.Prices[Convert.ToInt32(hullUser.Level + 1)]};{isCurrent};{hull.Ranks[Convert.ToInt32(hullUser.Level + 1)]}"); } } else { if (garage.Crystalls >= hull.Prices[0] && userRank >= hull.Ranks[0]) { return($"gi;h;{itemId};0;{hull.Prices[0]}"); } if (garage.Crystalls < hull.Prices[0] && userRank >= hull.Ranks[0]) { return($"gi;h;{itemId};1;{hull.Prices[0]}"); } if (garage.Crystalls >= hull.Prices[0] && userRank < hull.Ranks[0]) { return($"gi;h;{itemId};2;{hull.Prices[0]};{hull.Ranks[0]}"); } if (garage.Crystalls < hull.Prices[0] && userRank < hull.Ranks[0]) { return($"gi;h;{itemId};3;{hull.Prices[0]};{hull.Ranks[0]}"); } } } if (type == "turret") { var turret = TurretHelper.GetHelper().Turrets.Single(t => t.Id == itemId); if (garage.Turrets.Any(t => t.Id == turret.Id)) { var turretUser = garage.Turrets.Single(t => t.Id == turret.Id); var isCurrent = garage.CurrentTurret.Id == turret.Id ? 1 : 0; if (turretUser.Level == 3) { return($"gi;t;{itemId};8;{isCurrent};"); } //todo: есть. } else { if (garage.Crystalls >= turret.Prices[0] && userRank >= turret.Ranks[0]) { return($"gi;t;{itemId};0;{turret.Prices[0]}"); } if (garage.Crystalls < turret.Prices[0] && userRank >= turret.Ranks[0]) { return($"gi;t;{itemId};1;{turret.Prices[0]}"); } if (garage.Crystalls >= turret.Prices[0] && userRank < turret.Ranks[0]) { return($"gi;t;{itemId};2;{turret.Prices[0]};{turret.Ranks[0]}"); } if (garage.Crystalls < turret.Prices[0] && userRank < turret.Ranks[0]) { return($"gi;t;{itemId};3;{turret.Prices[0]};{turret.Ranks[0]}"); } } } }