Exemple #1
0
 override public Matchstate Execute(Matchstate state)
 {
     unit = new Bopper.Unit(unitType, player_id, coord, layer);
     state.units.Add(unit);
     ViewMaster.deployListeners?.Invoke(unit, ToString());           // we don't need to know about anything about any view(s). Views don't need to know anything about Commands
     return(state);
 }
Exemple #2
0
        /// <summary>
        /// Execute DEPLOY command, adding unit to the state and calling view.DeployUnit.
        /// Note that Execute and Undo are called just by clicking lines in the log. Each "command" log line is tied to a command.  The command persists with the log line. When the
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        override public Matchstate Execute(Matchstate state)
        {
            Debug.Log($"CommandDeploy({ToString()})");
            unit = new Bopper.Unit(unitType, player_id, coord, layer, name);
            if (unit == null)
            {
                throw new Exception($"UNIT IS NULL");
            }

            Debug.Assert(unit.data != null, "UNIT DATA IS NULL");
            if (unit.data == null)
            {
                throw new Exception($"unit.name={unit.name}, unit.data={unit.data.name}: UNIT DATA IS NULL");
            }

            Debug.Assert(unit.data.counterPrefab != null, $"unit.data.name={unit.data.name} does not have a counterPrefab");
            if (unit.data == null || unit.data.counterPrefab == null)
            {
                throw new Exception($"unit.data.name={unit.data.name} str={unit.data.strength} does not have a counterPrefab");
            }
            Debug.Log($"{unit} utype={unit.data.unitType}");
            //index = state.units.Count;
            state.units.Add(unit);
            //state.SetStatus(CommandStatus.Type.Deploy, unit.id);
            //state.SetStatus($"DEPLOY {unit.name} in hex {unit.coord}");
            //view.Display(this);                                               // we can have only one view. Right now it must be Bopper.View.Unity.GameView. Views need to know about Commands
            ViewMaster.deployListeners?.Invoke(unit, ToString());               // we don't need to know about anything about any view(s). Views don't need to know anything about Commands
            return(state);
        }
Exemple #3
0
        void DisplayUndeploy(Bopper.Unit unit)
        {
            Debug.Log($"View.UndeployUnit({unit.id})"); //todo
            HexCoordinates hcoord = HexCoordinates.FromRivets(unit.coord);

            //idToUnit[unit.id] = counter;
            hexGrid.DestroyUnitInCell(hcoord, unit.id);

            //SetAnimation(counter.GetComponent<Animation>());
            //SetStatusMessage(message);
        }
Exemple #4
0
        void DisplayDeploy(Bopper.Unit unit, string message)
        {
            Debug.Log($"GameView.DisplayDeploy({unit.name}, {message})");
            HexCoordinates hcoord  = HexCoordinates.FromRivets(unit.coord);
            Unit           counter = hexGrid.CreateUnitInCell(hcoord, unit.id, unit.data, unit.player_id == 1, unit.layer);

            idToUnit[unit.id] = counter;

            counter.GetComponent <Animator>().SetBool(0, true);
            StartAnimator(counter.GetComponent <Animator>(), "Flashing");
            SetStatusMessage(message);
        }
Exemple #5
0
        void DisplayUnmove(Bopper.Unit unit, int coord, int layer)
        {
            HexCoordinates startHcoord = HexCoordinates.FromRivets(coord);
            HexCoordinates destHcoord  = HexCoordinates.FromRivets(unit.coord);

            Unit counter = idToUnit[unit.id];

            Debug.Log($"I'm going to move unit from {startHcoord}({coord}) to {destHcoord}({unit.coord})");
            hexGrid.RemoveUnitInCell(startHcoord, unit.id);
            hexGrid.AddUnitToCell(destHcoord, counter, layer);

            StopAnimator();
            SetStatusMessage();
        }
Exemple #6
0
        /// <summary>
        /// Execute DEPLOY command, adding unit to the state and calling view.DeployUnit.
        /// Note that Execute and Undo are called just by clicking lines in the log. Each "command" log line is tied to a command.  The command persists with the log line. When the
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        override public Matchstate Execute(Matchstate state)
        {
            Debug.Log(ToString());
            unit = state.findUnit(player_id, unit_name);

            Debug.Log($"Move: unit={unit}");
            prevCoord = unit.coord;
            prevLayer = unit.layer;

            prevCoord  = unit.coord;
            unit.coord = coord;
            unit.layer = layer;
            ViewMaster.moveListeners?.Invoke(unit, prevCoord, prevLayer, ToString());    // we don't need to know about anything about any view(s). Views don't need to know anything about Commands

            return(state);
        }
Exemple #7
0
        void DisplayMove(Bopper.Unit unit, int prevCoord, int prevLayer, string message)
        {
            StopAnimator(); // this was supposed to fix stacking problem but it didn't

            HexCoordinates startHcoord = HexCoordinates.FromRivets(prevCoord);
            HexCoordinates destHcoord  = HexCoordinates.FromRivets(unit.coord);

            Unit counter = idToUnit[unit.id];

            Vector3 startPos = hexGrid.HexCoordinatesToPosition(startHcoord);
            Vector3 endPos   = hexGrid.HexCoordinatesToPosition(destHcoord);

            hexGrid.RemoveUnitInCell(startHcoord, unit.id);
            hexGrid.AddUnitToCell(destHcoord, counter, unit.layer);
            endPos = counter.transform.position;
            Debug.Log($"DisplayMove: endPos is {endPos}");
            //counter.transform.position = startPos; // try to prevent flash

            counter.GetComponent <MoveCommandAnimation>().Init(startPos, endPos);
            StartAnimator(counter.GetComponent <Animator>(), "Moving");
            SetStatusMessage(message);
        }