Example #1
0
    private void InitializeRobot(Robot robot, DockController dock)
    {
        RobotController r = boardController.LoadRobot(robot, dock.transform);

        r.isOpponent = dock.Equals(boardController.opponentDock);
        robotControllers.Add(r.id, r);
        r.transform.localPosition = dock.PlaceInBelt();
        r.transform.localRotation = Quaternion.Euler(0, 0, r.isOpponent ? 180 : 0);
    }
Example #2
0
    protected virtual void PlayEvent(GameEvent[] events, int index)
    {
        if (index == events.Length)
        {
            SetupNextTurn();
            return;
        }
        UnityAction Next = () => PlayEvent(events, index + 1);
        GameEvent   e    = events[index];

        if (history[currentHistoryIndex].IsAfter(e.priority))
        {
            history.Add(SerializeState(turnNumber, e.priority));
            currentHistoryIndex++;
        }
        boardController.DiffBattery(e.primaryBatteryCost, e.secondaryBatteryCost);
        if (e is ResolveEvent)
        {
            ResolveEvent re = (ResolveEvent)e;
            uiController.HighlightCommands(re.priority);
            Counter     animationsToPlay = new Counter(re.GetNumResolutions());
            UnityAction callback         = () => {
                animationsToPlay.Decrement();
                if (animationsToPlay.Get() <= 0)
                {
                    Next();
                }
            };
            re.robotIdToSpawn.ForEach(p => {
                RobotController primaryRobot = robotControllers[p.Item1];
                (primaryRobot.isOpponent ? boardController.opponentDock : boardController.myDock).RemoveFromBelt(primaryRobot.transform.localPosition);
                primaryRobot.transform.parent = boardController.transform;
                boardController.PlaceRobot(primaryRobot, p.Item2.Item1, p.Item2.Item2);
                primaryRobot.displaySpawn(callback);
            });
            re.robotIdToMove.ForEach(p => {
                RobotController primaryRobot = robotControllers[p.Item1];
                primaryRobot.displayMove(ToVector(p.Item2), boardController, callback);
            });
            re.robotIdToHealth.ForEach(t => {
                RobotController primaryRobot = robotControllers[t.Item1];
                primaryRobot.displayDamage(t.Item2, callback);
            });
            if (re.myBatteryHit)
            {
                boardController.GetMyBattery().DisplayDamage(callback);
            }
            if (re.opponentBatteryHit)
            {
                boardController.GetOpponentBattery().DisplayDamage(callback);
            }
            re.missedAttacks.ConvertAll(ToVector).ForEach(v => boardController.DisplayMiss(v, callback));
            re.robotIdsBlocked.ForEach(r => robotControllers[r].DisplayBlocked(callback));
        }
        else if (e is SpawnEvent)
        {
            robotControllers[((SpawnEvent)e).robotId].displaySpawnRequest(Next);
        }
        else if (e is MoveEvent)
        {
            robotControllers[((MoveEvent)e).robotId].displayMoveRequest(ToVector(((MoveEvent)e).destinationPos), Next);
        }
        else if (e is AttackEvent)
        {
            ((AttackEvent)e).locs.ConvertAll(ToVector).ForEach(v => robotControllers[((AttackEvent)e).robotId].displayAttack(v, Next));
        }
        else if (e is DeathEvent)
        {
            robotControllers[((DeathEvent)e).robotId].displayDeath(((DeathEvent)e).returnHealth, (RobotController primaryRobot) =>
            {
                boardController.UnplaceRobot(primaryRobot);
                DockController dock                  = !primaryRobot.isOpponent ? boardController.myDock : boardController.opponentDock;
                primaryRobot.transform.parent        = dock.transform;
                primaryRobot.transform.localPosition = dock.PlaceInBelt();
                Next();
            });
        }
        else if (e is EndEvent)
        {
            EndEvent    evt = (EndEvent)e;
            Counter     animationsToPlay = new Counter((evt.primaryLost ? 1 : 0) + (evt.secondaryLost ? 1 : 0));
            UnityAction callback         = () => {
                animationsToPlay.Decrement();
                if (animationsToPlay.Get() <= 0)
                {
                    uiController.robotButtonContainer.SetButtons(false);
                    uiController.statsInterface.Initialize(evt);
                    gameClient.SendEndGameRequest();
                }
            };
            if (evt.primaryLost)
            {
                boardController.GetMyBattery().DisplayEnd(callback);
            }
            if (evt.secondaryLost)
            {
                boardController.GetOpponentBattery().DisplayEnd(callback);
            }
        }
        else
        {
            PlayEvent(events, index + 1);
        }
    }