コード例 #1
0
 public void SendTilePacket(MahjongTile tile, bool players, bool spectators)
 {
     foreach (var mobile in GetInGameMobiles(players, spectators))
     {
         mobile.NetState.SendMahjongTileInfo(tile, mobile);
     }
 }
コード例 #2
0
    public void PopOneTile(bool front = true)
    {
        MahjongTile tile = _wall [0];

        _wall.Remove(tile);
        MahjongTile.Destroy(tile);
    }
コード例 #3
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    public int SetupStack(MahjongPile pile, int offset, int num)
    {
        MahjongTile        tile  = null;
        List <MahjongTile> stack = pile.GetRange(offset, num);

        _pile = pile;
        // 0 2 4 ...
        // 1 3 5 ...
        for (int i = 0; i < stack.Count; ++i)
        {
            tile = stack [i];

            tile.transform.parent = null;

            tile.Direction = MahjongTile.Face.PLANE_NEGTIVE;
            float angle = Vector3.Angle(Vector3.right, _direction);
            if (_direction == Vector3.forward)
            {
                angle = 270f;
            }
            //Debug.Log (_angle + "," + _direction + "," + _stackPosition);
            tile.transform.Rotate(Vector3.up, angle, Space.Self);
            tile.transform.parent = StackLocator;

            int row = i / 2;
            int col = i % 2;

            tile.transform.localPosition = row * _direction * MahjongTile.Width + col * Vector3.up * MahjongTile.Thickness;
        }

        return(num);
    }
コード例 #4
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    public virtual bool Draw(TileDef def)
    {
        Debug.Log(gameObject.name + " draw -> " + def.ToString());

        _drawTile = MahjongTile.Create(def);

        _drawTile.transform.parent = null;

        _drawTile.Direction = MahjongTile.Face.STAND_POSITIVE;
        _angle = Vector3.Angle(Vector3.right, _direction);
        //Debug.Log (angle + "    " + Vector3.right + "," + _direction);
        // unity3d bug from vector3.right to vector3.forward == 90 ?
        if (_direction == Vector3.forward)
        {
            _angle = 270f;
        }

        _drawTile.transform.Rotate(Vector3.forward, _angle, Space.Self);
        _drawTile.transform.parent = PocketLocator;
        Vector3 newPos = (PocketLocator.childCount - 1 + 0.2f) * _direction * MahjongTile.Width;

        _drawTile.Draw(newPos);

        _sortPocketList.Add(_drawTile);
        _proxy.Draw(def);

        return(true);
    }
コード例 #5
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    private void destroyChildren(Transform locator)
    {
        MahjongTile tile = null;

        while (locator.childCount > 0)
        {
            tile = locator.GetChild(0).GetComponent <MahjongTile> ();
            tile.Despawn();
        }
    }
コード例 #6
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    public void ResetPocketList(bool lastGap = false)
    {
        TileDef     def  = null;
        MahjongTile tile = null;

        destroyChildren(PocketLocator);

        if (_direction == Vector3.right)
        {
            //self
            _angle = 0f;
        }
        else if (_direction == Vector3.forward)
        {
            //right
            _angle = -270f;
        }
        else if (_direction == Vector3.left)
        {
            //front
            _angle = -180;
        }
        else if (_direction == -Vector3.forward)
        {
            //left
            _angle = -90f;
        }

        if (_sortPocketList == null)
        {
            _sortPocketList = new List <MahjongTile> ();
        }
        else
        {
            _sortPocketList.Clear();
        }

        Proxy.PocketList.Sort(TileDef.Comparison);
        for (int i = 0; i < Proxy.PocketList.Count; ++i)
        {
            def            = _proxy.PocketList [i];
            tile           = MahjongTile.Create(def);
            tile.Direction = MahjongTile.Face.PLANE_POSITIVE;
            tile.transform.Rotate(Vector3.right, -90f, Space.Self);
            tile.transform.Rotate(-Vector3.forward, _angle, Space.Self);             //local space forward
            tile.transform.parent        = PocketLocator;
            tile.transform.localPosition = i * _direction * MahjongTile.Width;
            _sortPocketList.Add(tile);
        }

        if (lastGap)
        {
            tile.transform.localPosition = (Proxy.PocketList.Count - 0.8f) * _direction * MahjongTile.Width;
        }
    }
コード例 #7
0
    public void RebuildStack(int a, int b, int count, int drawFront, int drawBehind)
    {
        _wall.Clear();
        MahjongTile    tile = null;
        List <TileDef> list = _proxy.RebuildStack(a, b, count, drawFront, drawBehind);

        for (int i = 0; i < list.Count; ++i)
        {
            tile = MahjongTile.Create(list [i]);
            _wall.Add(tile);
        }
    }
コード例 #8
0
    public static MahjongTile Create(TileDef def)
    {
        if (!TileDef.IsValid(def.Value))
        {
            Debug.LogError("tile : " + def.Value + " is not a valid tile");
            return(null);
        }

        Transform inst = null;

        MahjongTile._Pool = PoolManager.Pools ["mahjongres"];

        int point = def.GetPoint();

        switch (def.GetKind())
        {
        case TileDef.Kind.CRAK:
            inst = MahjongTile._Pool.Spawn("Crak_" + point);
            break;

        case TileDef.Kind.BAM:
            inst = MahjongTile._Pool.Spawn("Bam_" + point);
            break;

        case TileDef.Kind.DOT:
            inst = MahjongTile._Pool.Spawn("Dot_" + point);
            break;

        default:
            Debug.LogError("UnValid kind : " + def.GetKind());
            return(null);
        }

        inst.gameObject.SetActive(true);
        inst.transform.parent   = null;
        inst.transform.rotation = Quaternion.identity;
        inst.transform.position = Vector3.one * 9999f;

        MahjongTile tile = inst.gameObject.GetComponent <MahjongTile> () ?? inst.gameObject.AddComponent <MahjongTile> ();

        tile._def       = def;
        tile.ClickCount = 0;

        BoxCollider collider = inst.gameObject.AddComponent <BoxCollider> ();

        collider.center = Vector3.zero;
        collider.size   = ColliderSize;

        return(tile);
    }
コード例 #9
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    public MahjongTile FindMahjongTileFromPocketList(TileDef def)
    {
        MahjongTile tile = null;

        for (int i = 0; i < _sortPocketList.Count; ++i)
        {
            tile = _sortPocketList [i];
            if (tile.Def.Value == def.Value)
            {
                return(tile);
            }
        }
        return(null);
    }
コード例 #10
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
 //play self pocket mahjongtile
 public virtual bool Play(MahjongTile tile)
 {
     if (((odao.scmahjong.NetworkPlayer)_proxy).Play(tile.Def))
     {
         _playIndex = _sortPocketList.IndexOf(tile);
         if (_playIndex >= 0)
         {
             _sortPocketList.Remove(tile);
             placePlayed(tile);
             return(true);
         }
     }
     Debug.LogError("!!!!ErrorPlay Specify tile");
     return(false);
 }
コード例 #11
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    public void ResetPlayList()
    {
        TileDef     def  = null;
        MahjongTile tile = null;

        destroyChildren(PlayLocator);

        for (int i = 0; i < Proxy.PlayList.Count; ++i)
        {
            def = Proxy.PlayList [i];
            if (TileDef.IsValid(def.Value))
            {
                tile = MahjongTile.Create(def);
                if (tile != null)
                {
                    placePlayed(tile, false);
                }
            }
        }
    }
コード例 #12
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    //random play one tile from network command
    public virtual bool Play(TileDef def)
    {
        MahjongTile tile = null;

        if (((Player)_proxy).Play(def))
        {
            for (int i = 0; i < _sortPocketList.Count; ++i)
            {
                if (_sortPocketList [i].Def.Value == def.Value)
                {
                    _playIndex = i;
                    tile       = _sortPocketList [_playIndex];
                    _sortPocketList.Remove(tile);
                    placePlayed(tile);
                    return(true);
                }
            }
            Debug.Log(_sortPocketList.Count);
            Debug.Log(Proxy.Index + " Play(TileDef def)####################" + _playIndex);
            tile = MahjongTile.Create(def);
            placePlayed(tile);
            _playIndex = Random.Range(0, _sortPocketList.Count);
            tile       = _sortPocketList [_playIndex];
            _sortPocketList.Remove(tile);
            tile.Despawn();
        }
        else
        {
            _proxy.RemovePocketList(1);
            tile = MahjongTile.Create(def);
            placePlayed(tile);
            _playIndex = Random.Range(0, _sortPocketList.Count);
            tile       = _sortPocketList [_playIndex];
            _sortPocketList.Remove(tile);
            tile.Despawn();
        }

        return(false);
    }
コード例 #13
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    protected void placePlayed(MahjongTile tile, bool withSound = true)
    {
        tile.Reset();

        _angle = Vector3.Angle(Vector3.right, _direction);
        if (_direction == Vector3.forward)
        {
            _angle = 270f;
        }

        tile.Direction = MahjongTile.Face.PLANE_POSITIVE;
        tile.transform.Rotate(Vector3.up, _angle, Space.Self);
        Vector3 down = Vector3.Cross(_direction, Vector3.down);

        tile.transform.parent = PlayLocator;
        //Debug.Log (tile.transform.localRotation + "/" + _direction + "/" + _angle);
        int index = PlayLocator.childCount - 1;

        int row = index / 6;
        int col = index % 6;

        Vector3 newpos = col * _direction * MahjongTile.Width + row * down * MahjongTile.Height;

        //Debug.Log (row +":"+col);

        tile.Play(newpos);

        _playedList.Add(tile);

        if (withSound)
        {
            //AudioManager.Instance.PlayPai (((int)tile.ID).ToString ());
            //AudioManager.Instance.PlaySound (AudioManager.Instance.Luo_Pai);
            //TableController.Instance.SetCurrentPlayedTile (tile);
        }
        //close hupaiTips
        UIGameHuPromptController.Instance.Close();
    }
コード例 #14
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    public void SortPocketListAfterPlay()
    {
        Debug.Log("!!!!SortPocketListAfterPlay");
        if (PocketLocator.childCount <= 0)
        {
            Debug.Log("nopockets");
            return;
        }

        //updatePocketPosition();
        if (_playIndex == -1)
        {
            Debug.LogError("errororoororororoor");
        }
        // before play, pockets count == n
        // after play, pockets count == n - 1
        // played index caculated before play
        if (_playIndex == PocketLocator.childCount)
        {
            _drawTile  = null;
            _playIndex = -1;
            Debug.Log("play last one");
            return;
        }

        MahjongTile iter        = null;
        int         insertIndex = -1;

        if (_drawTile != null)
        {
            for (int i = 0; i < _sortPocketList.Count; ++i)
            {
                iter            = _sortPocketList [i];
                iter.ClickCount = 0;
                if (TileDef.Comparison(_drawTile.Def, iter.Def) <= 0)
                {
                    insertIndex = i;
                    break;
                }
            }
            Debug.Log("!!!!_drawTile " + _drawTile + " " + Proxy.Index + " sort after play " + insertIndex + "####" + _playIndex);
        }

        if (insertIndex == -1 && _playIndex >= 0)
        {
            for (int i = _playIndex; i < _sortPocketList.Count; ++i)
            {
                Vector3 pos = i * _direction * MahjongTile.Width;
                _sortPocketList [i].Moveto(pos, true);
            }
            Debug.Log("!!!!return" + Proxy.Index + " sort after play " + insertIndex + "####" + _playIndex);
            return;
        }

        Debug.Log(Proxy.Index + " sort after play " + insertIndex + "####" + _playIndex);

        if (insertIndex > _playIndex)
        {
            for (int i = _playIndex; i < insertIndex; ++i)
            {
                Vector3 pos = i * _direction * MahjongTile.Width;
                _sortPocketList [i].ClickCount = 0;
                _sortPocketList [i].Moveto(pos, true);
            }
        }
        else if (insertIndex < _playIndex)
        {
            for (int i = insertIndex; i < _playIndex; ++i)
            {
                Vector3 pos = (i + 1) * _direction * MahjongTile.Width;
                _sortPocketList [i].ClickCount = 0;
                _sortPocketList [i].Moveto(pos, true);
            }
        }

        Vector3 insertPosition = insertIndex * _direction * MahjongTile.Width;

        _sortPocketList.Remove(_drawTile);
        _sortPocketList.Insert(insertIndex, _drawTile);
        if (insertIndex < _sortPocketList.Count - 1)
        {
            _drawTile.Insert(insertPosition, true);
        }
        else
        {
            _drawTile.Moveto(insertPosition, true);
        }

        _drawTile  = null;
        _playIndex = -1;
        Debug.Log(Proxy.Index + "playindex -1 @@@");
    }
コード例 #15
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
 public void PlaceWin(MahjongTile tile, bool withSound = true)
 {
     tile.Reset();
     tile.transform.parent = WinLocator;
 }
コード例 #16
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    private bool showPocketList(Transform locator, bool lastGap = true)
    {
        TileDef          def   = null;
        MahjongTile      tile  = null;
        FiniteTimeAction delay = null;
        FiniteTimeAction rb    = null;
        float            angle = 0f;

        if (_direction == Vector3.right)
        {
            //self
            angle = 0f;
        }
        else if (_direction == Vector3.forward)
        {
            //right
            angle = -270f;
        }
        else if (_direction == Vector3.left)
        {
            //front
            angle = -180;
        }
        else if (_direction == -Vector3.forward)
        {
            //left
            angle = -90f;
        }

        for (int i = 0; i < _sortPocketList.Count; ++i)
        {
            tile = _sortPocketList [i];
            tile.transform.parent = null;
            tile.Direction        = MahjongTile.Face.PLANE_NEGTIVE;
            tile.transform.Rotate(Vector3.up, angle, Space.Self);
            tile.transform.parent        = locator;
            tile.transform.localPosition = i * _direction * MahjongTile.Width;
        }

        if (lastGap)
        {
            tile.transform.localPosition = tile.transform.localPosition + _direction * 0.2f * MahjongTile.Width;
        }

        for (int i = 0; i < locator.transform.childCount; ++i)
        {
            tile = locator.transform.GetChild(i).GetComponent <MahjongTile> ();
            List <FiniteTimeAction> list = new List <FiniteTimeAction> ();

            /*
             * if (_DelayShowHand > 0f) {
             *      delay = DelayTime.Create (_DelayShowHand);
             *      list.Add (delay);
             * }
             */
            rb = RotateBy.Create(0.1f, Vector3.right, 180f, Space.Self);
            list.Add(rb);
            ActionManager.Instance.RunAction(tile.gameObject, list);
        }

        return(true);
    }
コード例 #17
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    private IEnumerator initDraw(bool banker)
    {
        _initDrawFinished = false;

        float angle = 0f;

        if (_direction == Vector3.right)
        {
            //self
            angle = 0f;
        }
        else if (_direction == Vector3.forward)
        {
            //right
            angle = -270f;
        }
        else if (_direction == Vector3.left)
        {
            //front
            angle = -180;
        }
        else if (_direction == -Vector3.forward)
        {
            //left
            angle = -90f;
        }

        RotateBy    rb      = null;
        TileDef     def     = null;
        MahjongTile tile    = null;
        Transform   locator = PocketLocator;

        float duration     = 0.1f;
        float waitDuration = 0.3f;

        int index            = 0;
        int drawCountPerTime = 4;

        for (int i = 0; i < 4; ++i)
        {
            if (i == 3)
            {
                drawCountPerTime = 1;
            }

            for (int j = 0; j < drawCountPerTime; ++j)
            {
                //_pile.PopOneTile ();
                def            = _proxy.PocketList [index];
                tile           = MahjongTile.Create(def);
                tile.Direction = MahjongTile.Face.PLANE_NEGTIVE;
                tile.transform.Rotate(Vector3.up, angle, Space.Self);
                tile.transform.parent = locator.transform;

                tile.transform.localPosition = index * _direction * MahjongTile.Width;

                rb = RotateBy.Create(duration, Vector3.right, 90f, Space.Self);
                ActionManager.Instance.RunAction(tile.gameObject, rb);

                //yield return new WaitForSeconds (duration);

                ++index;
            }

            yield return(new WaitForSeconds(waitDuration));
        }

        for (int i = 0; i < locator.childCount; ++i)
        {
            tile = locator.GetChild(i).GetComponent <MahjongTile> ();
            rb   = RotateBy.Create(duration, Vector3.right, -90f, Space.Self);
            ActionManager.Instance.RunAction(tile.gameObject, rb);
        }

        yield return(new WaitForSeconds(waitDuration));

        //_proxy.SortPocketList (TileDef.Comparison);
        _sortPocketList = SortMahjongTile(locator);
        for (int i = 0; i < _sortPocketList.Count; ++i)
        {
            tile = _sortPocketList [i];
            tile.transform.localPosition = i * _direction * MahjongTile.Width;
            rb = RotateBy.Create(duration, Vector3.right, 90f, Space.Self);
            ActionManager.Instance.RunAction(tile.gameObject, rb);
        }

        yield return(new WaitForSeconds(waitDuration));

        if (banker)
        {
            if (_proxy.PocketList.Count == 14)
            {
                def = _proxy.PocketList [13];
                _proxy.RemovePocketList(def, 1);
                Draw(def);
                _drawTile = null;
            }
            else
            {
                def = TileDef.Create();
                Draw(def);
                _drawTile = null;
            }
        }

        _initDrawFinished = true;
    }
コード例 #18
0
ファイル: MahjongPlayer.cs プロジェクト: DeveloperFor/Hall
    // param id is a combo list
    public void Combo(TileDef def, int num, int flipNum = 0, bool withAnimation = true)
    {
        MahjongTile tile     = null;
        Vector3     localPos = Vector3.zero;

        if (ComboLocator.childCount > 0)
        {
            localPos = Vector3.zero - MahjongTile.Width * _direction * ComboLocator.childCount - MahjongTile.Width * _direction * 0.2f;
        }
        else
        {
            localPos = Vector3.zero;
        }

        for (int i = 0; i < num; ++i)
        {
            tile = MahjongTile.Create(def);
            tile.Reset();

            if (i < flipNum)
            {
                tile.Direction = MahjongTile.Face.PLANE_NEGTIVE;

                _angle = Vector3.Angle(Vector3.right, _direction);
                //Debug.Log (_angle + "    " + Vector3.right + "," + _direction);
                // unity3d bug from vector3.right to vector3.forward == 90 ?
                if (_direction == Vector3.forward)
                {
                    _angle = 270f;
                }
                tile.transform.Rotate(Vector3.up, _angle, Space.Self);
            }
            else
            {
                _angle = Vector3.Angle(Vector3.right, _direction);
                //Debug.Log (_angle + "    " + Vector3.right + "," + _direction);
                // unity3d bug from vector3.right to vector3.forward == 90 ?
                if (_direction == Vector3.forward)
                {
                    _angle = 270f;
                }
                tile.transform.Rotate(Vector3.up, _angle, Space.Self);
            }

            //往左偏移的起始位置
            tile.transform.parent        = ComboLocator;
            tile.transform.localPosition = localPos - i * MahjongTile.Width * _direction;

            if (withAnimation)
            {
                //再往左偏移一段位置从起始位置起 然后播放动画
                Vector3 localDstPosition = tile.transform.localPosition;
                tile.transform.localPosition = tile.transform.localPosition - _direction * MahjongTile.Width * 3f;

                ActionBase act = MoveTo.Create(0.2f, localDstPosition, true);
                ActionManager.Instance.RunAction(tile.gameObject, act);
            }
        }

        //Debug.Log (_comboLocator.transform.childCount);
    }
コード例 #19
0
 public static void Destroy(MahjongTile tile)
 {
     tile.Reset();
     _Pool.Despawn(tile.transform);
 }