Esempio n. 1
0
    // Start is called before the first frame update
    void Start()
    {
        // Tell client to go to ResultScene
        var resultCmd = new GameSetCmd(IsHostWin);

        tosendCmds.Add(resultCmd);

        //get audio manager instance
        audioMgr = audioMgr ?? AudioManager.AudioManager.m_instance;

        Text resultTitleSelf     = GameObject.Find("ResultTitleSelf").GetComponent <Text>();
        Text ResultTitleOpponent = GameObject.Find("ResultTitleOpponent").GetComponent <Text>();

        Text ButtonText = GameObject.Find("ReturnBtn").GetComponentInChildren <Text>();

        // set players' names
        //GameObject.Find("selfName").GetComponent<Text>().text = G_username;
        //GameObject.Find("opponentName").GetComponent<Text>().text = G_opponentName;
        if (G_isHost == IsHostWin)// Current Player wins.
        {
            audioMgr.PlayMusic("victory");

            resultTitleSelf.text     = "You Won!";
            ResultTitleOpponent.text = "";
            ButtonText.text          = "Yeah!";
        }
        else// Current Player loses.
        {
            audioMgr.PlayMusic("lose");

            resultTitleSelf.text     = "You Lost!";
            ResultTitleOpponent.text = "";
            ButtonText.text          = "Alright..";
        }
    }
Esempio n. 2
0
    void ProcessMyCommand()
    {
        for (int i = 0; i < commands.Count; i++)
        {
            Command c1 = commands[i];
            if (c1 == null)
            {
                continue;
            }
            if (c1.processed)
            {
                continue;
            }
            if (c1 is GameSetCmd)
            {
                GameSetCmd c = (GameSetCmd)c1;
                openResultScene(c.isHostWin);
            }
            if (c1 is UnitMovedCmd)
            {
                UnitMovedCmd c         = (UnitMovedCmd)c1;
                var          basicUnit = GetBasicUnit(c.uuid);
                //Debug.Log(c.vx);
                if (basicUnit != null && !basicUnit.MovementLocked && !basicUnit.Locked) // lockdown and waittime check
                {
                    Unit u = GetUnit(c.uuid);
                    u.vx = c.vx;
                    u.vz = c.vz;
                    //schin Remove "ready to roll" emotion when ready.
                    //      this doesn't check if it's really moved for client
                    basicUnit.ExpireEmotion(EmotionType.CD_READY);

                    // Tinaxd update CountdownUI (Host only)
                    // Generate a UnitTimerCommand
                    if (isClient == 0)
                    {
                        UnitTimerCmd utc = new UnitTimerCmd();
                        utc.penalty   = basicUnit.WaitTimePenaltyTime;
                        utc.timerType = UnitTimerCmd.MOVED;
                        utc.uuid      = c.uuid;
                        unitTimerRequests.Add(utc);
                        commands.Add(utc);
                    }
                }
                else
                {
                }
                c.processed = true;
            }
            if (c1 is UnitUpdateCmd)
            {
                UnitUpdateCmd c = (UnitUpdateCmd)c1;
                //Debug.Log(c.vx);
                if (isClient > 0)
                {
                    //TODO if units.isDeadあり
                    //UnitDied()
                    units = c.units;
                }
                c.processed = true;
                c.sent      = true;
            }
            if (c1 is UnitTimerCmd)
            {
                UnitTimerCmd c = (UnitTimerCmd)c1;
                switch (c.timerType)
                {
                case 0:     // MOVED
                    var basicUnit = GetBasicUnit(c.uuid);
                    if (basicUnit != null)
                    {
                        basicUnit.MarkMoved();
                    }
                    // Lockdown ends
                    foreach (var instance in instances)
                    {
                        var bu = instance.basicUnit;
                        if (bu == null)
                        {
                            continue;
                        }
                        if (bu.Owned != basicUnit.Owned)
                        {
                            bu.MovementLocked = false;
                        }
                    }
                    break;

                case 1:     // HOST LOCKDOWN
                    foreach (var instance in instances)
                    {
                        var bu = instance.basicUnit;
                        if (bu == null)
                        {
                            continue;
                        }
                        if (isClient > 0)
                        {
                            if (bu.Owned)
                            {
                                bu.MovementLocked = true;
                            }
                            else
                            {
                                bu.MarkLockdown();
                            }
                        }
                        else
                        {
                            if (bu.Owned)
                            {
                                bu.MarkLockdown();
                            }
                            else
                            {
                                bu.MovementLocked = true;
                            }
                        }
                    }
                    break;

                case 2:     // CLIENT LOCKDOWN
                    foreach (var instance in instances)
                    {
                        var bu = instance.basicUnit;
                        if (bu == null)
                        {
                            continue;
                        }
                        if (isClient > 0)
                        {
                            if (bu.Owned)
                            {
                                bu.MarkLockdown();
                            }
                            else
                            {
                                bu.MovementLocked = true;
                            }
                        }
                        else
                        {
                            if (bu.Owned)
                            {
                                bu.MovementLocked = true;
                            }
                            else
                            {
                                bu.MarkLockdown();
                            }
                        }
                    }
                    break;
                }
                //TODO if c is GameSetCmd
                //SceneManager.LoadScene("Result");
                //clientBattleScene, isHostWin = GameSetCmd.isHostWin
                if (isClient > 0 && (!AutoPlay.isOffline))
                {
                    c.processed = true;
                }
            }
            if (c1 is NewUnitCmd)
            {
                //Debug.Log(GetUnit(((NewUnitCmd)c1).fromUnitId).owner);
                NewUnitCmd c = (NewUnitCmd)c1;
                switch (c.unitType)
                {
                case 2:     // Arrow
                {
                    Unit u = GetUnit(c.fromUnitId);
                    if (u == null)
                    {
                        break;
                    }
                    if (u.projectileReload <= 0)
                    {
                        u.projectileReload = 7;
                        CreateArrow(GetUnit(c.fromUnitId), c.velocity);
                    }
                }
                break;

                case 3:     // Fireball
                {
                    var u = GetUnit(c.fromUnitId);
                    if (u.MP > 25)
                    {
                        u.MP -= 25;
                        CreateFireball(u, c.velocity);
                    }
                }
                break;
                }
                c.processed = true;
            }

            if (c1 is HealingBuffRequestCmd)
            {
                var c = (HealingBuffRequestCmd)c1;
                if (isClient == 0)
                {
                    var requestor = GetUnit(c.RequestorId);
                    var target    = GetUnit(c.TargetId);
                    if (PhysicsSimulator.UnitDistance1(requestor, target) < HealingBuffMaxDistance)
                    {
                        target.buff |= BuffFlag.BUFF_HEALING;
                    }
                    c.processed = true;
                }
                //GetBasicUnit(c.RequestorId).DragMode = DragType.NORMAL;
                //UnityEngine.EventSystems.ExecuteEvents.Execute<IDragAndFireEventHandler>(this.gameObject, null, (x, y) => x.TurnOnDrag());
            }
        }
        List <Command> remains = new List <Command>();

        for (int i = 0; i < commands.Count; i++)
        {
            if (commands[i].sent)
            {
                continue;
            }
            remains.Add(commands[i]);
        }
        commands = remains;
    }