private void UpdateState() { int playerIndex = m_gameState.LocalToPlayerIndex(LocalPlayerIndex); long[] selection = m_selection.GetSelection(playerIndex, playerIndex); if (selection.Length == 0) { IsOpen = false; return; } for (int i = 0; i < m_buttons.Length; ++i) { m_buttons[i].gameObject.SetActive(selection.Length > 0); if (i != 12) { HUDControlBehavior hcb = m_buttons[i].GetComponent <HUDControlBehavior>(); hcb.IsDisabled = true; } } if (m_eventSystem.currentSelectedGameObject != null && m_eventSystem.currentSelectedGameObject.GetComponent <HUDControlBehavior>().IsDisabled) { m_eventSystem.SetSelectedGameObjectOnLateUpdate(m_buttons[0].gameObject); } }
private void Unselect(int playerIndex) { long selectedIndex = -1; long[] selection = m_unitSelection.GetSelection(playerIndex, playerIndex); if (selection.Length > 0) { selectedIndex = selection[0]; } VoxelData unitData = FindClosestTo(PlayerIndex, selectedIndex, selection, false); if (unitData != null) { m_unitSelection.Unselect(playerIndex, playerIndex, new[] { unitData.UnitOrAssetIndex }); m_wasSelected.Remove(unitData.UnitOrAssetIndex); } }
private void ReadUnitDescriptors() { int playerIndex = PlayerIndex; m_selectedUnitDescriptors = m_unitSelection.GetSelection(playerIndex, playerIndex) .Select(unitIndex => m_gameState.GetVoxelDataController(playerIndex, unitIndex)) .Where(dc => dc != null) .Select(dc => new SelectionDescriptor(dc.ControlledData.Type, dc.ControlledData.Weight)) .Distinct().ToArray(); }
private void SubmitTaskToClientTaskEngine(TaskTemplateType templateType, params TaskInfo[] defines) { m_playersBot.Init(); int playerIndex = m_gameState.LocalToPlayerIndex(m_localPlayerIndex); IMatchPlayerView playerView = m_gameState.GetPlayerView(playerIndex); long[] selection = m_unitSelection.GetSelection(playerIndex, playerIndex); for (int i = 0; i < selection.Length; ++i) { m_playersBot.SubmitTask(Time.realtimeSinceStartup, playerView.GetUnit(selection[i]), templateType, defines); } }
private void UpdateState() { int playerIndex = m_gameState.LocalToPlayerIndex(LocalPlayerIndex); long[] selection = m_selection.GetSelection(playerIndex, playerIndex); if (selection.Length == 0) { IsOpen = false; return; } m_cancelBtn.gameObject.SetActive(selection.Length > 0); m_attackBtn.gameObject.SetActive(selection.Length > 0); m_moveBtn.gameObject.SetActive(selection.Length > 0); m_autoBtn.gameObject.SetActive(selection.Length > 0); m_bombBtn.gameObject.SetActive(false); m_wallBtn.gameObject.SetActive(false); m_spawnButton.gameObject.SetActive(false); m_growButton.gameObject.SetActive(false); m_diminishButton.gameObject.SetActive(false); m_splitButton.gameObject.SetActive(false); m_split4Button.gameObject.SetActive(false); HUDControlBehavior hcbBomb = m_bombBtn.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbWall = m_wallBtn.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbSpawn = m_spawnButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbGrow = m_growButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbDiminish = m_diminishButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbSplit = m_splitButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbSplit4 = m_split4Button.GetComponent <HUDControlBehavior>(); hcbBomb.IsDisabled = true; hcbWall.IsDisabled = true; hcbSpawn.IsDisabled = true; hcbGrow.IsDisabled = true; hcbDiminish.IsDisabled = true; hcbSplit.IsDisabled = true; hcbSplit4.IsDisabled = true; for (int i = 0; i < selection.Length; ++i) { IVoxelDataController dc = m_gameState.GetVoxelDataController(playerIndex, selection[i]); if (dc != null) { CmdResultCode canBomb = dc.CanConvertImmediate((int)KnownVoxelTypes.Bomb); if (canBomb != CmdResultCode.Fail_NotSupported) { m_bombBtn.gameObject.SetActive(true); if (canBomb == CmdResultCode.Success) { hcbBomb.IsDisabled = false; } } CmdResultCode canGround = dc.CanConvertImmediate((int)KnownVoxelTypes.Ground); if (canGround != CmdResultCode.Fail_NotSupported) { m_wallBtn.gameObject.SetActive(true); if (canGround == CmdResultCode.Success) { hcbWall.IsDisabled = false; } } CmdResultCode canSpawner = dc.CanConvertImmediate((int)KnownVoxelTypes.Spawner); if (canSpawner != CmdResultCode.Fail_NotSupported) { m_spawnButton.gameObject.SetActive(true); if (canSpawner == CmdResultCode.Success) { hcbSpawn.IsDisabled = false; } } CmdResultCode canGrow = dc.CanGrowImmediate(); if (canGrow != CmdResultCode.Fail_NotSupported) { m_growButton.gameObject.SetActive(true); if (canGrow == CmdResultCode.Success) { hcbGrow.IsDisabled = false; } } CmdResultCode canDiminish = dc.CanDiminishImmediate(); if (canDiminish != CmdResultCode.Fail_NotSupported) { m_diminishButton.gameObject.SetActive(true); if (canDiminish == CmdResultCode.Success) { hcbDiminish.IsDisabled = false; } } CmdResultCode canSplit = dc.CanSplitImmediate(); if (canSplit != CmdResultCode.Fail_NotSupported) { m_splitButton.gameObject.SetActive(true); if (canSplit == CmdResultCode.Success) { hcbSplit.IsDisabled = false; } } CmdResultCode canSplit4 = dc.CanSplit4Immediate(); if (canSplit4 != CmdResultCode.Fail_NotSupported) { m_split4Button.gameObject.SetActive(true); if (canSplit4 == CmdResultCode.Success) { hcbSplit4.IsDisabled = false; } } } } if (m_eventSystem.currentSelectedGameObject != null && m_eventSystem.currentSelectedGameObject.GetComponent <HUDControlBehavior>().IsDisabled) { m_eventSystem.SetSelectedGameObjectOnLateUpdate(m_autoBtn.gameObject); } }
private void CreateMovementCmd(bool serverSide, Action <List <Cmd> > callback) { Guid playerId = m_gameState.GetLocalPlayerId(m_localPlayerIndex); int playerIndex = m_gameState.GetPlayerIndex(playerId); long[] selectedUnitIds = m_unitSelection.GetSelection(playerIndex, playerIndex); if (selectedUnitIds.Length > 0) { List <Cmd> commandsToSubmit = new List <Cmd>(); for (int i = 0; i < selectedUnitIds.Length; ++i) { long unitIndex = selectedUnitIds[i]; IVoxelDataController dataController = m_gameState.GetVoxelDataController(playerIndex, unitIndex); MapCell cell = m_map.GetCell(m_cameraController.MapCursor, m_cameraController.Weight, null); int deltaWeight = dataController.ControlledData.Weight - m_cameraController.Weight; while (deltaWeight > 0) { cell = cell.Parent; deltaWeight--; } VoxelData selectedTarget = null; //MapCell selectedTargetCell = null; for (int p = 0; p < m_gameState.PlayersCount; ++p) { long[] targetSelection = m_targetSelection.GetSelection(playerIndex, p); if (targetSelection.Length > 0) { MatchAssetCli asset = m_gameState.GetAsset(p, targetSelection[0]); if (asset != null) { selectedTarget = asset.VoxelData; // selectedTargetCell = asset.Cell; } else { IVoxelDataController dc = m_gameState.GetVoxelDataController(p, targetSelection[0]); selectedTarget = dc.ControlledData; // selectedTargetCell = m_map.GetCell(dc.Coordinate.MapPos, dc.Coordinate.Weight, null); } } } int dataType = dataController.ControlledData.Type; int dataWeight = dataController.ControlledData.Weight; VoxelData beneath = null; if (cell != null) { if (selectedTarget == null) { VoxelData defaultTarget; beneath = cell.GetDefaultTargetFor(dataType, dataWeight, playerIndex, false, out defaultTarget); } else { beneath = cell.GetPreviousFor(selectedTarget, dataType, dataWeight, playerIndex); } } VoxelData closestBeneath = beneath; float minDistance = float.MaxValue; if (closestBeneath == null && cell != null) { MapPos pos = cell.GetPosition(); for (int r = -1; r <= 1; r++) { for (int c = -1; c <= 1; c++) { MapCell neighbourCell = m_map.GetCell(new MapPos(pos.Row + r, pos.Col + c), dataController.ControlledData.Weight, null); if (neighbourCell != null) { VoxelData defaultTarget; VoxelData data = neighbourCell.GetDefaultTargetFor(dataType, dataWeight, playerIndex, false, out defaultTarget); Vector3 worldPoint = m_map.GetWorldPosition(new MapPos(pos.Row + r, pos.Col + c), dataWeight); if (data != null) { worldPoint.y = (data.Altitude + data.Height) * GameConstants.UnitSize; } Vector2 screenPoint = m_cameraController.WorldToScreenPoint(worldPoint); if (m_cameraController.InScreenBounds(screenPoint)) { float distance = (screenPoint - m_cameraController.VirtualMousePosition).magnitude; if (data != null && distance < minDistance) { minDistance = distance; closestBeneath = data; cell = neighbourCell; } } } } } } beneath = closestBeneath; if (beneath != null) { int weight = dataController.ControlledData.Weight; // Vector3 hitPoint = beneath.Weight <= weight ? m_map.GetWorldPosition(m_cameraController.MapCursor, m_cameraController.Weight) : m_cameraController.Cursor; //MapPos mapPos = m_map.GetMapPosition(hitPoint, weight); MapPos mapPos = cell.GetPosition(); int altitude = beneath.Altitude + beneath.Height; if (serverSide) { MovementCmd movementCmd = new MovementCmd(); if (selectedTarget != null) { movementCmd.HasTarget = true; movementCmd.TargetIndex = selectedTarget.UnitOrAssetIndex; movementCmd.TargetPlayerIndex = selectedTarget.Owner; } Coordinate targetCoordinate = new Coordinate(mapPos, weight, altitude); movementCmd.Code = CmdCode.Move; movementCmd.Coordinates = new[] { targetCoordinate }; movementCmd.UnitIndex = unitIndex; commandsToSubmit.Add(movementCmd); } else { Coordinate targetCoordinate = new Coordinate(mapPos, weight, altitude); m_engine.GetPathFinder(m_gameState.LocalToPlayerIndex(LocalPlayerIndex)).Find(unitIndex, -1, dataController.Clone(), new[] { dataController.Coordinate, targetCoordinate }, (unitId, path) => { MovementCmd movementCmd = new MovementCmd(); movementCmd.Code = CmdCode.Move; movementCmd.Coordinates = path; movementCmd.UnitIndex = unitIndex; commandsToSubmit.Add(movementCmd); callback(commandsToSubmit); }, null); } } } if (serverSide) { callback(commandsToSubmit); } } callback(null); }
private void OnCommand(IConsole console, string cmd, params string[] args) { if (cmd == "unitinfo") { int playerIndex = m_gameState.LocalToPlayerIndex(LocalPlayerIndex); long[] selection = m_unitSelection.GetSelection(playerIndex, playerIndex); for (int i = 0; i < selection.Length; ++i) { long unitIndex = selection[i]; IVoxelDataController dataController = m_gameState.GetVoxelDataController(playerIndex, unitIndex); m_console.Echo(string.Format("unit = {0}, type = {1}", unitIndex, dataController.ControlledData.Type)); m_console.Echo(string.Format("coord = {0}", dataController.Coordinate)); m_console.Echo(string.Format("health = {0}", dataController.ControlledData.Health)); m_console.Echo("----------------------------------------------------------------------------"); } } else if (cmd == "playerinfo") { int playerIndex = m_gameState.LocalToPlayerIndex(LocalPlayerIndex); PlayerStats playerStats = m_gameState.GetStats(playerIndex); Player player = m_gameState.GetPlayer(playerIndex); m_console.Echo(string.Format("player index = {0} ", playerIndex)); m_console.Echo(string.Format("player id = {0} ", player.Id)); m_console.Echo(string.Format("player name = {0} ", player.Name)); m_console.Echo(string.Format("bot type = {0} ", player.BotType)); m_console.Echo(string.Format("ctrl units count = {0} ", playerStats.ControllableUnitsCount)); m_console.Echo(string.Format("is in room = {0} ", playerStats.IsInRoom)); var unitsByType = m_gameState.GetUnits(playerIndex).Select(unitIndex => m_gameState.GetVoxelDataController(playerIndex, unitIndex)).GroupBy(unit => unit.ControlledData.Type); foreach (var unitGroup in unitsByType) { m_console.Echo(string.Format("units of type {0} = {1} ", unitGroup.Key, unitGroup.Count())); } m_console.Echo("----------------------------------------------------------------------------"); } else if (cmd == "quit") { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif Application.Quit(); } else { cmd = cmd.ToLower(); cmd = char.ToUpper(cmd[0]) + cmd.Substring(1); if (Enum.GetNames(typeof(PlayerUnitConsoleCmd)).Contains(cmd)) { IPlayerUnitController unitController = Dependencies.GameView.GetUnitController(LocalPlayerIndex); unitController.SubmitConsoleCommand((PlayerUnitConsoleCmd)Enum.Parse(typeof(PlayerUnitConsoleCmd), cmd), args, console); } } }