public override void _Ready() { _team = (Team)GetNode("Team"); _team.CurrentTeamCode = _defaultTeamCode; _captureTeamCode = _team.CurrentTeamCode; _unitDisplayLabel = ((Label)(GetNode("UnitDisplay/Name"))); _unitDisplay = (UnitDisplay)GetNode("UnitDisplay"); _collisionShape = (CollisionShape2D)GetNode("CollisionShape2D"); _rng = new RandomNumberGenerator(); _rng.Randomize(); _base = (Sprite)GetNode("Base"); _boundry = (Sprite)GetNode("Boundry"); _timer = (Timer)GetNode("CaptureTimer"); agentsEntered = new Godot.Collections.Array(); for (int index = 0; index < Enum.GetNames(typeof(Team.TeamCode)).Length; index++) { agentsEntered.Add(0); } // Update unit display SetCaptureBaseTeam(_team.CurrentTeamCode); }
private void checkIsBaseCaptured() { int currentMajorityTeam = _calculateBaseMajority(); // Only start counting if: // New majority team is different from current base team // New majority team is not neutral if (currentMajorityTeam != (int)_team.CurrentTeamCode && currentMajorityTeam != (int)Team.TeamCode.NEUTRAL) { // If is different from current working in progress capture team if ((int)_captureTeamCode != currentMajorityTeam) { // Restart counter as previous timer is for different capture team _counter = 0; updateUnitDisplay(); // Set to the new capture team _captureTeamCode = (Team.TeamCode)currentMajorityTeam; _timer.Start(); } } else { // Reset back to current captured team _captureTeamCode = _team.CurrentTeamCode; _counter = _timeToCaptureBase; updateUnitDisplay(); _timer.Stop(); } }
public void SetCaptureBaseTeam(Team.TeamCode team) { _team.CurrentTeamCode = team; _base.Modulate = _team.getTeamColor(_team.CurrentTeamCode); _boundry.Modulate = _team.getTeamColor(_team.CurrentTeamCode); _unitDisplayLabel.Text = Name + " (" + _team.CurrentTeamCode + ")"; _counter = _timeToCaptureBase; EmitSignal(nameof(BaseTeamChangeSignal), this); }
public void Initialize(Team.TeamCode teamCode) { _teamCode = teamCode; TextureRect textureRect = (TextureRect)GetNode("TextrectTeam"); textureRect.Modulate = Team.TeamColor[(int)_teamCode]; Label labelTeamName = (Label)GetNode("LabelTeamName"); labelTeamName.Text = "" + _teamCode; }
private void _populatePlayerTeams() { playerTeams.Connect("item_selected", this, "_playerTeamSelected"); for (int index = 0; index < (int)(Team.TeamCode.NEUTRAL); index++) { Team.TeamCode team = (Team.TeamCode)index; playerTeams.AddItem("" + team); _populateTeamSettings(team); } // Pre Select the 0 index playerTeams.Select(0); _playerTeamSelected(0); }
private void _cratePlayer(int netId, Team.TeamCode team, String unitName, String displayName) { String playerId = _agentPlayerPrefix + netId; // Already generated if (spawnPlayers.ContainsKey(playerId)) { return; } // If observer is setup, clean it up if (HasNode(_agentObserverPrefix + observerCounter)) { GetNode(_agentObserverPrefix + observerCounter).QueueFree(); observerCounter++; } // Load the scene and create an instance Player agent = (Player)(TeamMapAIs[(int)team].CreateUnit(unitName, displayName, false)); // If this actor does not belong to the server, change the network master accordingly if (netId != 1) { agent.SetNetworkMaster(netId); } // If this actor is the current client controlled, add camera and attach HUD if (netId == network.gamestateNetworkPlayer.net_id) { // Attach camera agent.SetHUD(_hud, _inventoryManager); agent.SetCameraRemotePath(_camera2D); // Set player marker _miniMap.SetPlayer(agent); } else { // Add as normal agent marker _miniMap.AddAgent(agent); } spawnPlayers.Add(playerId, agent); EmitSignal(nameof(PlayerCreateSignal)); }
private void _populateTeamSettings(Team.TeamCode team) { TeamSettingPanel teamSettingPanel = (TeamSettingPanel)GetNode("CanvasLayer/PanelHost/PanelTeamSetting").Duplicate(); _gridcontainerTeamManagement.AddChild(teamSettingPanel); teamSettingPanel.Initialize(team); teamSettingPanel.Show(); TeamMapAISetting teamMapAISetting = new TeamMapAISetting(); teamMapAISetting.TeamCode = team; teamMapAISetting.Budget = teamSettingPanel.GetTeamBudget(); teamMapAISetting.AutoSpawnMember = teamSettingPanel.GetTeamAutoSpawnMember(); _teamMapAISettings.Add(teamMapAISetting); }
private void _addBotOnNetwork(String botId) { Team.TeamCode team = (Team.TeamCode) int.Parse(botId.Split(";")[0]); String unitName = botId.Split(";")[1]; if (!SpawnBots.ContainsKey(unitName)) { bool enableAI = false; if (GetTree().IsNetworkServer()) { enableAI = true; } Agent agent = TeamMapAIs[(int)team].CreateUnit(unitName, unitName, enableAI); SpawnBots.Add(unitName, agent); // Add agent marker to minimap _miniMap.AddAgent(agent); } }
// Update and generate a game state snapshot private void _updateState() { // If not on the server, bail if (!GetTree().IsNetworkServer()) { return; } // Initialize the "high level" snapshot Snapshot snapshot = new Snapshot(); snapshot.signature = snapshotSignature; Godot.Collections.Array <String> removeSpawnPlayers = new Godot.Collections.Array <String>(); foreach (KeyValuePair <int, NetworkPlayer> networkPlayer in network.networkPlayers) { String playerId = _agentPlayerPrefix + networkPlayer.Value.net_id; // Node may not being created yet if (!spawnPlayers.ContainsKey(playerId)) { // Ideally should give a warning that a player node wasn't found continue; } Agent playerNode = spawnPlayers[playerId]; if (playerNode == null || !IsInstanceValid(playerNode)) { // Ideally should give a warning that a player node wasn't found continue; } Vector2 pPosition = playerNode.Position; float pRotation = playerNode.Rotation; // Only update if player is not dead yet if (playerNode.getHealth() > 0) { // Check if there is any input for this player. In that case, update the state if (GameStates.playerInputs.ContainsKey(networkPlayer.Key) && GameStates.playerInputs[networkPlayer.Key].Count > 0) { int rightWeapon = 0; int leftWeapon = 0; // Calculate the delta float delta = GameStates.updateDelta / (float)(GameStates.playerInputs[networkPlayer.Key].Count); foreach (KeyValuePair <int, GameStates.PlayerInput> input in GameStates.playerInputs[networkPlayer.Key]) { Vector2 moveDir = Vector2.Zero; moveDir.y -= input.Value.Up; moveDir.y += input.Value.Down; moveDir.x -= input.Value.Left; moveDir.x += input.Value.Right; playerNode.changeWeapon(input.Value.RightWeaponIndex, Weapon.WeaponOrder.Right); playerNode.changeWeapon(input.Value.LeftWeaponIndex, Weapon.WeaponOrder.Left); if (!_waitingPeriod) { rightWeapon = input.Value.RightWeaponAction; leftWeapon = input.Value.LeftWeaponAction; } playerNode.Fire(Weapon.WeaponOrder.Right, rightWeapon); playerNode.Fire(Weapon.WeaponOrder.Left, leftWeapon); playerNode.RotateToward(input.Value.MousePosition, delta); playerNode.MoveToward(moveDir, delta); } // Cleanup the input vector GameStates.playerInputs[networkPlayer.Key].Clear(); GameStates.playerInputs.Remove(networkPlayer.Key); ClientData clientData = new ClientData(); clientData.Id = networkPlayer.Key + ""; clientData.Position = playerNode.Position; clientData.Rotation = playerNode.Rotation; clientData.RightWeapon = rightWeapon; clientData.LeftWeapon = leftWeapon; clientData.RightWeaponIndex = playerNode.GetCurrentWeaponIndex(Weapon.WeaponOrder.Right); clientData.LeftWeaponIndex = playerNode.GetCurrentWeaponIndex(Weapon.WeaponOrder.Left); clientData.Health = playerNode.getHealth(); snapshot.playerData.Add(networkPlayer.Key, clientData); } } else { removeSpawnPlayers.Insert(0, playerId); } } // Clean the input GameStates.playerInputs.Clear(); foreach (String spawnPlayerId in removeSpawnPlayers) { // Respawn dead player if that team still allow new unit Team.TeamCode teamCode = spawnPlayers[spawnPlayerId].GetCurrentTeam(); String displayName = spawnPlayers[spawnPlayerId].GetDisplayName(); _removeUnitOnNetwork(spawnPlayerId); // Respawn if that team still allow new unit if (TeamMapAIs[(int)teamCode].isNewUnitAllow()) { _spawnPlayer(spawnPlayerId.Replace(_agentPlayerPrefix, "") + ";" + (int)teamCode + ";" + _agentPlayerPrefix + _agentPlayerCounter + ";" + displayName); _agentPlayerCounter++; } } Godot.Collections.Array <String> removeSpawnBots = new Godot.Collections.Array <String>(); foreach (Agent agent in SpawnBots.Values) { // Locate the bot node Agent enemyNode = (Agent)TeamMapAIs[(int)agent.GetCurrentTeam()].GetUnit(agent.Name); if (enemyNode == null || !IsInstanceValid(enemyNode)) { // Ideally should give a warning that a bot node wasn't found continue; } int rightWeapon = (int)GameStates.PlayerInput.InputAction.NOT_TRIGGER; int leftWeapon = (int)GameStates.PlayerInput.InputAction.NOT_TRIGGER; if (!_waitingPeriod) { rightWeapon = enemyNode.RightWeaponAction; leftWeapon = enemyNode.LeftWeaponAction; } enemyNode.Fire(Weapon.WeaponOrder.Right, rightWeapon); enemyNode.Fire(Weapon.WeaponOrder.Left, leftWeapon); if (enemyNode.getHealth() > 0) { // Build bot_data entry ClientData clientData = new ClientData(); clientData.Id = enemyNode.Name; clientData.Position = enemyNode.GlobalPosition; clientData.Rotation = enemyNode.GlobalRotation; clientData.Health = enemyNode.getHealth(); clientData.RightWeapon = rightWeapon; clientData.LeftWeapon = leftWeapon; clientData.RightWeaponIndex = enemyNode.GetCurrentWeaponIndex(Weapon.WeaponOrder.Right); clientData.LeftWeaponIndex = enemyNode.GetCurrentWeaponIndex(Weapon.WeaponOrder.Left); // Append into the snapshot snapshot.botData.Add(enemyNode.Name, clientData); // This logic is necessary to notify the AI that reload is pick up, so can continue with next state if (rightWeapon == (int)GameStates.PlayerInput.InputAction.RELOAD) { enemyNode.RightWeaponAction = (int)GameStates.PlayerInput.InputAction.NOT_TRIGGER; } if (leftWeapon == (int)GameStates.PlayerInput.InputAction.RELOAD) { enemyNode.LeftWeaponAction = (int)GameStates.PlayerInput.InputAction.NOT_TRIGGER; } } else { removeSpawnBots.Insert(0, enemyNode.Name); } } foreach (String spawnBotId in removeSpawnBots) { _removeUnitOnNetwork(spawnBotId); } if (removeSpawnBots.Count > 0) { _syncBots(); } // Encode and broadcast the snapshot - if there is at least one connected client if (network.networkPlayers.Count > 1) { encodeSnapshot(snapshot); } // Make sure the next update will have the correct snapshot signature snapshotSignature += 1; }
private String validateGameResult() { String message = ""; Team.TeamCode winTeam = Team.TeamCode.NEUTRAL; int teamCounter = 0; // If it is time, choose the winer team as if (internalTimer != 0) { foreach (TeamMapAI currentAI in TeamMapAIs) { if (currentAI.isNewUnitAllow() || currentAI.GetUnitsContainer().GetChildren().Count != 0) { winTeam = currentAI.GetCurrentTeam(); teamCounter = 1; } } } else { int largestUnitCount = -1; foreach (TeamMapAI currentAI in TeamMapAIs) { if (currentAI.isNewUnitAllow()) { // If current unit count is 0 and no longer can generate new unit if (currentAI.isNewUnitAllow()) { if (currentAI.GetUnitsContainer().GetChildren().Count >= largestUnitCount) { largestUnitCount = currentAI.GetUnitsContainer().GetChildren().Count; winTeam = currentAI.GetCurrentTeam(); teamCounter++; } } } } } if (teamCounter == 1) { message = "Winning Team is " + winTeam; if (network.gamestateNetworkPlayer.team == (int)winTeam) { message = "You Win!;" + message; } else { message = "You Lost;" + message; } } else { message = "It Is a Tie; There are more than one team reach equal amount of winning condition"; } // Record elaspse time int elapseTime = MaxGameTime - internalTimer; int hour = elapseTime / 3600; int minutes = (elapseTime % 3600) / 60; int seconds = (elapseTime % 3600) % 60; message = message + ";" + formatTwoDigits(hour) + ":" + formatTwoDigits(minutes) + ":" + formatTwoDigits(seconds); return(message); }
public void SetCurrentTeam(Team.TeamCode inputTeamCode) { _team.CurrentTeamCode = inputTeamCode; _setUnitDisplay(); }
public void Initialize(GameWorld gameWorld, InventoryManager inventoryManager, Godot.Collections.Array bases, Team.TeamCode team, PathFinding pathFinding) { _inventoryManager = inventoryManager; _bases = bases; _team.CurrentTeamCode = team; _gameWorld = gameWorld; _pathFinding = pathFinding; _advancedTimer.Start(); CheckForCapturableBase(); }