/* CLASS STARTS HERE - COPY BELOW INTO THE SCRIPT WINDOW */ #region Data Persistence public static void SaveData() { // clear the file before so that data doesn't get inserted at the end of file Mutex.WaitOne(); // Wait until it is safe to enter. GlobalGame.GetSharedStorage(GetCurrentStorageFileName()).Clear(); string data = OtherData; var menusToSave = PlayerMenuList.Where(m => m.Player != null).ToList(); for (int i = 0; i < menusToSave.Count; i++) { var player = menusToSave[i].Player; var playerData = menusToSave[i].Save(saveOnlyIfActive: false); data += playerData; if (ShowDebugMessages) { DebugLogger.DebugOnlyDialogLog("SAVED DATA FOR PLAYER " + player.Name + ". PLAYER DATA SAVED: [ " + playerData + " ]"); } } GlobalGame.GetSharedStorage(GetCurrentStorageFileName()).SetItem("SaveData", data); IsDataSaved = true; var playersSavedCount = data.Split(';').Count(); DebugLogger.DebugOnlyDialogLog("GAME SAVED " + playersSavedCount + " PLAYERS IN DATABASE"); Mutex.ReleaseMutex(); // GlobalGame.Data = "BEGIN" + "DATA" + data + "ENDDATA"; }
public void CallAirDrop(TPlayer player, int count = 1) { Vector2 pos = player.User.GetPlayer().GetWorldPosition(); if (IsHacking(player.Team)) { TPlayer enemy = GetRandomPlayer(GetEnemyTeam(player.Team), true); if (enemy != null) { pos = enemy.User.GetPlayer().GetWorldPosition(); } else { pos = GetRandomWorldPoint(); } } pos.Y = WorldTop; int offset = 20; pos.X -= offset * (count - 1); for (int i = 0; i < count; i++) { GlobalGame.CreateObject("SupplyCrate00", pos); pos.X += offset; pos.Y += GlobalRandom.Next(-offset, offset); } }
public static Vector2 GetRandomWorldPoint() { Area area = GlobalGame.GetCameraArea(); return(new Vector2(GlobalRandom.Next((int)area.Left, (int)area.Right), GlobalRandom.Next((int)area.Bottom, (int)area.Top))); }
public static void PreWeaponTrackingUpdate() { string[] argArray = new string[WeaponItemNames.Count]; WeaponItemNames.Values.CopyTo(argArray, 0); IObject[] list = GlobalGame.GetObjectsByName(argArray); for (int i = 0; i < list.Length; i++) { IObject obj = list[i]; bool found = false; for (int j = 0; j < WeaponTrackingList.Count; j++) { if (WeaponTrackingList[j].Object == obj) { found = true; break; } } if (found) { continue; } TWeapon weapon = PlayerDropWeaponUpdate(obj.GetWorldPosition(), ((IObjectWeaponItem)obj).WeaponItem); if (weapon == null) { weapon = new TWeapon(((IObjectWeaponItem)obj).WeaponItem); } weapon.Object = obj; WeaponTrackingList.Add(weapon); } }
public bool CallAirstrike(TPlayer player) { int angle = 0; PlayerTeam team = player.Team; if (IsHacking(player.Team)) { team = GetEnemyTeam(player.Team); GlobalGame.RunCommand("MSG AIRSTRIKE HAS BEEN HACKED"); } Vector2 target = GetRandomAirEnemy(team, 2, ref angle); if (target.X == 0 && target.Y == 0) { if (IsHacking(player.Team)) { target = GetRandomWorldPoint(); } else { return(false); } } if (IsJamming(player.Team)) { target.X += GlobalRandom.Next(-99, 100); GlobalGame.RunCommand("MSG PINPOINT STRIKE HAS BEEN JAMMED"); } Vector2 position = GetBeginPointTarget(target, angle); TargetPosition = target; BeginPosition = position; return(true); }
void InitializeGames() { int spotUIIndex = 0; int localGameUIIndex = 1; // first GameUI is global UI SpotUI[] spotUIs = GetComponentsInChildren <SpotUI>(); GameUI[] gameUIs = GetComponentsInChildren <GameUI>(); LocalGame[,] localGames = new LocalGame[3, 3]; for (int boardRow = 0; boardRow < 3; boardRow++) { for (int boardCol = 0; boardCol < 3; boardCol++) { // a grid of spots represents each local board Spot[,] spots = new Spot[3, 3]; for (int spotRow = 0; spotRow < 3; spotRow++) { for (int spotCol = 0; spotCol < 3; spotCol++) { // each spot SpotUI spotUI = spotUIs[spotUIIndex]; Spot spot = new Spot( new Location(spotRow, spotCol), null, true); spotUI.Spot = spot; spots[spotRow, spotCol] = spot; spotUIIndex++; } } // each local game Location loc = new Location(boardRow, boardCol); LocalGame localGame = new LocalGame(spots, true, loc); localGames[boardRow, boardCol] = localGame; gameUIs[localGameUIIndex].Game = localGame; localGameUIIndex++; } } Player p1 = menu ? Settings.NewPlayer(true, true) : Settings.p1; Player p2 = menu ? Settings.NewPlayer(false, true) : Settings.p2; // initialize the global game, its view and its controller GlobalGame game = new GlobalGame(localGames, true, p1, p2, true); if (p1 is AI) { ((AI)p1).Game = game; } if (p2 is AI) { ((AI)p2).Game = game; } GetComponent <GameUI>().Game = game; GetComponent <GameController>().Game = game; globalGame = game; }
public void TogglePause() { var paused = !GlobalGame.Get().currentLevel.GetPause(); GlobalGame.Get().currentLevel.SetPause(paused); pauseMenu.SetActive(paused); }
public void BreakWeapon(bool isExplosion) { IPlayer pl = User.GetPlayer(); if (pl != null && !pl.IsDead) { if (pl.CurrentWeaponDrawn == WeaponItemType.Rifle) { if (GlobalRandom.Next(0, 100) < (int)(WeaponBreakingChance * Armor.BreakWeaponFactor)) { Vector2 pos = pl.GetWorldPosition(); RifleWeaponItem weapon = pl.CurrentPrimaryWeapon; if ((weapon.WeaponItem == WeaponItem.BAZOOKA || weapon.WeaponItem == WeaponItem.GRENADE_LAUNCHER || weapon.WeaponItem == WeaponItem.FLAMETHROWER) && weapon.CurrentAmmo > 0 && (GlobalRandom.Next(0, 100) < WeaponExplosionChance || isExplosion)) { GlobalGame.TriggerExplosion(pos); } pl.RemoveWeaponItemType(WeaponItemType.Rifle); GlobalGame.PlayEffect("CFTXT", pl.GetWorldPosition(), "WEAPON BROKEN"); GlobalGame.CreateObject("MetalDebris00A", pos, (float)rnd.NextDouble()); pos.X += 5; GlobalGame.CreateObject("MetalDebris00B", pos, (float)rnd.NextDouble()); pos.X -= 10; GlobalGame.CreateObject("MetalDebris00C", pos, (float)rnd.NextDouble()); } } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { GlobalGame.Get().currentLevel.PlayerWin(); } }
public void Revive(float hp = 100, bool bleeding = false, bool withPos = false, float x = 0, float y = 0) { Respawn(false); Bleeding = bleeding; IPlayer pl = User.GetPlayer(); Vector2 position; if (!withPos) { position = pl.GetWorldPosition(); } else { position = new Vector2(x, y); } if (pl != null) { pl.Remove(); } pl = GlobalGame.CreatePlayer(position); if (KeepPlayersSkins) { pl.SetProfile(pl.GetUser().GetProfile()); } else { pl.SetProfile(GetSkin()); } pl.SetUser(User); pl.SetTeam(Team); //pl.SetStatusBarsVisible(false); Hp = hp; OnPlayerCreated(); }
public void OnClose() { GlobalGame.SendPackage(new C2S100005() { RoomId = 100000 }); }
/// <summary> /// Returns a deep copy of the given global game /// </summary> /// <param name="globalGame"></param> /// <returns></returns> GlobalGame CopyGlobalGame(GlobalGame globalGame) { if (globalGame == null) { return(null); } LocalGame[,] localGames = new LocalGame[3, 3]; LocalGame activeGame = null; foreach (LocalGame game in globalGame.LocalGames) { localGames[game.Loc.Row, game.Loc.Col] = CopyLocalGame(game); if (game == globalGame.ActiveGame) { activeGame = localGames[game.Loc.Row, game.Loc.Col]; } } return(new GlobalGame( localGames, globalGame.Enabled, globalGame.P1, globalGame.P2, globalGame.P1Turn, activeGame )); }
public void Movement() { if (!EnableMovement || CurrentPath.Count == 0) { StopMovement(); return; } Vector2 position = MainMotor.GetWorldPosition(); if ((position - CurrentPath[CurrentPath.Count - 1]).Length() <= 1 || RailJoint == null) { CurrentPath.RemoveAt(CurrentPath.Count - 1); if (CurrentPath.Count == 0) { StopMovement(); return; } else { StopMovement(false); } RailJoint = (IObjectRailJoint)GlobalGame.CreateObject("RailJoint", position); TargetObject = (IObjectTargetObjectJoint)GlobalGame.CreateObject("TargetObjectJoint", CurrentPath[CurrentPath.Count - 1]); RailAttachment = (IObjectRailAttachmentJoint)GlobalGame.CreateObject("RailAttachmentJoint", position); RailJoint.SetTargetObjectJoint(TargetObject); RailAttachment.SetRailJoint(RailJoint); RailAttachment.SetTargetObject(Hull); RailAttachment.SetMotorEnabled(true); RailAttachment.SetMaxMotorTorque(10); RailAttachment.SetMotorSpeed(Speed); Hull.SetBodyType(BodyType.Dynamic); } }
//functions public void Start() { CapturedBy = 0; CameraPosition = MapPosition; for (int i = 0; i < PointList.Count; i++) { PointList[i].Start(); } if (GlobalRandom.Next(0, 100) <= 20) { WeatherType weather = GlobalGame.GetWeatherType(); if (weather == WeatherType.None) { GlobalGame.SetWeatherType(WeatherType.Rain); return; } if (weather == WeatherType.Rain) { GlobalGame.SetWeatherType(WeatherType.Snow); return; } if (weather == WeatherType.Snow) { GlobalGame.SetWeatherType(WeatherType.None); return; } } }
protected override void Awake() { base.Awake(); _globalGame = FindObjectOfType <GlobalGame>(); _globalGame.AddUnit(this); _numberText.text = $"{number}"; _lastPosition = transform.position; }
public MCTSNode(GlobalGame game, Spot lastMove, MCTSNode parent) { this.game = CopyGlobalGame(game); this.lastMove = lastMove; this.parent = parent; hits = 0; misses = 0; totalTrials = 0; }
public void Handle(object sender, Packet packet) { Log.Info("{0},网关连接成功", GameUser.Instance.UserName); GlobalGame.IsGameStart = true; GlobalGame.SendPackage(new C2S100001() { RoomId = GameUser.Instance.RoomId }); }
//methods public TPlayer(IUser user) { User = user; Body = user.GetPlayer(); Name = User.Name; Team = Body.GetTeam(); StatusDisplay = (IObjectText)GlobalGame.CreateObject("Text"); StatusDisplay.SetTextAlignment(TextAlignment.Middle); }
void Update() { var level = GlobalGame.Get().currentLevel; if (level.IsPlayable()) { level.timeSpent += Time.deltaTime; textComponent.text = Mathf.RoundToInt(level.timeSpent).ToString(); } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { var contact = other.bounds.ClosestPoint(transform.position); Instantiate(explosion, contact, Quaternion.identity); GlobalGame.Get().currentLevel.PlayerDie(); Destroy(other.gameObject); } }
public void FlashbangExplosion() { PlayExplosionVisualEffects(); GlobalGame.PlaySound("Explosion", Position, 1); StunPlayersInRangeNotCoveredByWall(); ThrownWeaponObject.Remove(); ReadyForRemove = true; }
public void SpawnDrone(TPlayer player, int id) { Area area = GlobalGame.GetCameraArea(); float x = GlobalRandom.Next((int)(area.Left + area.Width / 5), (int)(area.Right - area.Width / 5)); float y = area.Top + 10; CreateTurret(id, new Vector2(x, y), player.User.GetPlayer().FacingDirection, player.Team); GlobalGame.PlayEffect("EXP", new Vector2(x, y)); GlobalGame.PlaySound("Explosion", new Vector2(x, y), 1.0f); }
public static void SpawnDrone(int id, PlayerTeam team) { Area area = GlobalGame.GetCameraArea(); float x = GlobalRandom.Next((int)(area.Left + area.Width / 5), (int)(area.Right - area.Width / 5)); float y = area.Top - 10; CreateTurret(id, new Vector2(x, y), 1, team); GlobalGame.PlayEffect("EXP", new Vector2(x, y)); GlobalGame.PlaySound("Explosion", new Vector2(x, y), 1.0f); }
public static int TracePath(Vector2 fromPos, Vector2 toPos, PlayerTeam team, bool fullCheck = false) { int width = 4; float angle = TwoPointAngle(fromPos, toPos); Vector2 diff = toPos - fromPos; float offsetX = (float)Math.Cos(angle) * (width + 8); float offsetY = (float)Math.Sin(angle) * (width + 8); int itCount = (int)Math.Ceiling(diff.X / offsetX); Vector2 currentPos = fromPos; int vision = 0; for (int i = 0; i < itCount; i++) { Area area = new Area(currentPos.Y + width / 2.0f, currentPos.X - width / 2.0f, currentPos.Y - width / 2.0f, currentPos.X + width / 2.0f); IObject[] objList = GlobalGame.GetObjectsByArea(area); for (int j = 0; j < objList.Length; j++) { string name = objList[j].Name; if (name.StartsWith("Bg") || name.StartsWith("FarBg")) { continue; } if (IsPlayer(name)) { TPlayer pl = GetPlayer((IPlayer)objList[j]); if (pl.IsAlive() && !fullCheck) { if (pl.Team == team) { vision = 3; } else { return(vision); } } else { vision = Math.Max(vision, 1); } } else if (VisionObjects.ContainsKey(name)) { vision = Math.Max(vision, VisionObjects[name]); } if (vision >= 3) { return(vision); } } currentPos.X += offsetX; currentPos.Y += offsetY; } return(vision); }
void SpawnGoose() { Vector3 pos = Vector3.zero; GlobalGame.RandomNavMeshPos(ref pos); GameObject obj = Instantiate(GooseObject, GeeseFolder, false); cloneTransforms(obj.transform, GooseObject.transform); obj.transform.position = pos; }
public void PlayerWin() { player.GetComponent <Rigidbody2D> ().velocity = Vector2.zero; // Fix the position of the player on finish. player.GetComponent <Rigidbody2D> ().bodyType = RigidbodyType2D.Static; playerInteractive = false; pauseButton.SetActive(false); winMenu.SetActive(true); // No next level for last level. continueButton.SetActive(GlobalGame.Get().levelIndex != GlobalGame.levels.Length - 1); }
public static void ThrowingUpdate() { IObject[] objects = GlobalGame.GetMissileObjects(); for (int i = 0; i < objects.Length; i++) { if (!AllowedMissile.Contains(objects[i].Name)) { objects[i].TrackAsMissile(false); } } }
public void SpawnSmokeCircle(float radius) { float angle = 0; while (angle < Math.PI * 2) { float y = (float)Math.Sin(angle) * radius; float x = (float)Math.Cos(angle) * radius; GlobalGame.PlayEffect("STM", Position + new Vector2(x, y)); angle++; } }
void FixedUpdate() { if (GlobalGame.Get().currentLevel.IsPlayable() && player != null) { var desired = player.transform.position + offset; var halfHeight = GetComponent <Camera> ().orthographicSize; var halfWidth = halfHeight / Screen.height * Screen.width; desired.x = Mathf.Min(topRight.x + border - halfWidth, Mathf.Max(bottomLeft.x - border + halfWidth, desired.x)); desired.y = Mathf.Min(topRight.y + border - halfHeight, Mathf.Max(bottomLeft.y - border + halfHeight, desired.y)); transform.position = Vector3.SmoothDamp(transform.position, desired, ref velocity, smoothTime); } }
public static void CreateThrownWeapon(WeaponItem item, int id, Vector2 pos) { string name = ""; if (item == WeaponItem.GRENADES) { name = "WpnGrenadesThrown"; } else if (item == WeaponItem.MOLOTOVS) { name = "WpnMolotovsThrown"; } else if (item == WeaponItem.MINES) { name = "WpnMineThrown"; } else if (item == WeaponItem.SHURIKEN) { name = "WpnShurikenThrown"; } IObject[] list = GlobalGame.GetObjectsByName(name); IObject obj = null; float dist = 20; for (int i = 0; i < list.Length; i++) { float currentDist = (list[i].GetWorldPosition() - pos).Length(); if (currentDist < dist) { bool have = false; for (int j = 0; j < ThrownTrackingList.Count; j++) { if (ThrownTrackingList[j].ThrownWeaponObject == list[i]) { have = true; break; } } if (have) { continue; } obj = list[i]; dist = currentDist; } } if (obj == null) { return; } ThrownTrackingList.Add(new TThrownWeapon(obj, id)); }