Example #1
0
    public override bool OnEntry(SkillArgs args)
    {
        if (!base.OnEntry(args))
        {
            return(false);
        }

        ChessEntity attack   = GetTarget(args, damageTarget);
        ChessEntity beAttack = GetTarget(args, beDamageTarget);

        if (attack == null || beAttack == null)
        {
            return(false);
        }

        int damage = (int)attack.chessObj.chess_attack;

        damage -= (int)beAttack.chessObj.chess_defense;

        if (damage <= 0)
        {
            damage = 1;
        }

        beAttack.BeAttack(damage);

        return(true);
    }
Example #2
0
 public void OnReset()
 {
     Owner     = null;
     Sender    = null;
     FlowIndex = -1;
     Index     = -1;
 }
Example #3
0
    protected void SetIndexPath(int index_x, int index_z)
    {
        if (index_x < 0 || index_x > 8 || index_z < 0 || index_z > 9)
        {
            return;
        }

        ChessEntity entity = ChessManager.Instance.FindChessByIndex(index_x, index_z);

        if (entity == this)
        {
            return;
        }

        if (entity != null)
        {
            if (entity.chessObj.chess_owner_player != chessObj.chess_owner_player)
            {
                entity.SetCanAttackClick();
            }
        }
        else
        {
            ChessPathManager.SetPathIndex(index_x, index_z);
        }
    }
    public void OnAttackChess(int attackChess, int beAttackChess)
    {
        InputManager.ClearSelectChess();

        ChessEntity attack   = ChessManager.FindEntityByID(attackChess);
        ChessEntity beAttack = ChessManager.FindEntityByID(beAttackChess);

        if (attack == null || beAttack == null)
        {
            return;
        }

        Vector3 selfPos     = attack.transform.localPosition;
        Vector3 beAttackpos = new Vector3(ChessEntity.ChessInterval * (int)beAttack.chessObj.chess_index_x, 0, ChessEntity.ChessInterval * (int)beAttack.chessObj.chess_index_z);

        // 刚开始不能直接移动到要攻击的棋子旁边
        Vector3 pos = (beAttackpos - selfPos).normalized;

        pos *= Vector3.Distance(beAttackpos, selfPos) - ChessEntity.ChessInterval;
        pos += selfPos;
        attack.MoveTo(pos);

        // 开始释放技能
        attack.Target   = beAttack;
        beAttack.Target = attack;

        attack.UseNormalSkill();

        currentAttackChess = attack;

        fightMainUIPanel.SetStateInfoString("战斗中...");
    }
Example #5
0
    public static void ClearSelectChess()
    {
        if (SelectChess != null)
        {
            SelectChess.UnSelect();
        }

        SelectChess = null;
    }
    public void Exit()
    {
        GameEventManager.UnregisterEvent(GameEventTypes.KillChess, OnKillChessEvent);

        KBEngine.Event.deregisterOut("OnStartRound", this, "OnStartRound");
        KBEngine.Event.deregisterOut("AttackChess", this, "OnAttackChess");
        KBEngine.Event.deregisterOut("OnExitFb", this, "OnExitFb");

        currentAttackChess = null;
    }
Example #7
0
    public static void AddEntity(ChessEntity entity)
    {
#if UNITY_EDITOR
        if (chessMap.ContainsKey(entity.ID))
        {
            Debug.LogErrorFormat("Add chess {0} already exists", entity.ID);
            Debug.Break();
        }
#endif

        chessMap.Add(entity.ID, entity);
    }
    public void RemoveChessInfo(ChessEntity chess)
    {
        if (m_infos.ContainsKey(chess))
        {
            GComponent info = m_infos[chess];

            m_infos.Remove(chess);

            info.RemoveFromParent();

            info.Dispose();
        }
    }
Example #9
0
    public void OnChessMove(int chess_id, int index_x, int index_z)
    {
        InputManager.ClearSelectChess();

        ChessEntity chess = chessMap.ContainsKey(chess_id) ? chessMap[chess_id] : null;

        if (chess == null || !chess.Ready)
        {
            return;
        }

        chess.MoveTo(index_x, index_z);
    }
Example #10
0
    public void ChessCreate(Chess chess)
    {
        GameObject entityGameObject = new GameObject();

        System.Type chessType = GetEntityTypeByConfigID((int)chess.chess_id);
        if (chessType == null)
        {
            return;
        }

        ChessEntity chessEntity = entityGameObject.AddComponent(chessType) as ChessEntity;

        chessEntity.InitChess(chess);
    }
Example #11
0
    public static void RemoveEntity(int objID)
    {
#if UNITY_EDITOR
        if (!chessMap.ContainsKey(objID))
        {
            Debug.LogErrorFormat("Remote entity {0} but does not exist.", objID);
            Debug.Break();
        }
#endif

        ChessEntity entity = null;
        if (chessMap.TryGetValue(objID, out entity))
        {
            entity.OnRemove();
            chessMap.Remove(entity.ID);
        }
    }
    public void ShowChessInfo(ChessEntity chess)
    {
        GComponent info = (GComponent)UIPackage.CreateObject("ChessInfo", "ChessInfoItem");

        if (info == null)
        {
            Debug.LogError("show chess info error.");
            return;
        }
        this.AddChild(info);

        GTextField name = info.GetChild("name").asTextField;

        name.text = chess.chessCfg.Name;

        m_infos.Add(chess, info);
    }
Example #13
0
    public override bool OnEntry(SkillArgs args)
    {
        if (!base.OnEntry(args))
        {
            return(false);
        }

        ChessEntity target = GetTarget(args);

        if (target == null)
        {
            return(false);
        }

        target.PlayAction(actionName);

        return(true);
    }
Example #14
0
    public override bool OnEntry(SkillArgs args)
    {
        if (!base.OnEntry(args))
        {
            return(false);
        }

        ChessEntity target = GetTarget(args);

        if (target == null)
        {
            return(false);
        }

        AudioManager.PlayAudio(musicId, target.transform);

        return(true);
    }
    public override void ShowEmit(params object[] args)
    {
        base.ShowEmit(args);

        ChessEntity chess = args[0] as ChessEntity;

        if (chess == null)
        {
            OnCompleted();
            return;
        }

        nameText.text = chess.chessCfg.Name;

        this.container.gameObject.transform.parent = chess.transform;
        //EmitNumberManager.AddChild(this);

        this.container.gameObject.SetActive(true);
    }
Example #16
0
    private void OnKillChessEvent(GameEventTypes eventType, object[] args)
    {
        ChessEntity attack   = args[0] as ChessEntity;
        ChessEntity beAttack = args[1] as ChessEntity;

        if (attack == null || beAttack == null)
        {
            return;
        }

        if (beAttack.GetChessType() == ChessType.ChessTypeJiang)
        {
            fightMainUIPanel.SetStateInfoString("");

            Account account = KBEngine.KBEngineApp.app.player() as Account;
            if ((int)beAttack.chessObj.chess_owner_player == account.CampType)
            {
                GUIManager.Open <FightLostUIPanel>("Fight", "FightLostUIPanel");
            }
            else
            {
                GUIManager.Open <FightWinUIPanel>("Fight", "FightWinUIPanel");
            }
        }
        else
        {
            Account account = KBEngine.KBEngineApp.app.player() as Account;
            account.baseCall("KillChess", beAttack.chessObj.id);

            if (currentAttackChess != null && currentAttackChess == attack)
            {
                currentAttackChess.MoveTo((int)beAttack.chessObj.chess_index_x, (int)beAttack.chessObj.chess_index_z);
            }
        }

        currentAttackChess = null;
    }
Example #17
0
    void Update()
    {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.B))
        {
            Account account = KBEngine.KBEngineApp.app.player() as Account;
            if (account == null)
            {
                return;
            }

            account.baseCall("TestChessEntity", 1);
        }
#endif

        if (Input.GetMouseButtonDown(0))
        {
            if (!CanMove)
            {
                return;
            }

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Account account = KBEngine.KBEngineApp.app.player() as Account;
                if (account == null)
                {
                    return;
                }

                int        campType      = account.CampType;
                GameObject hitGameObject = hit.collider.gameObject;

                ChessEntity entity = ChessManager.Instance.FindChessByAvatarModel(hitGameObject);
                if (entity != null)
                {
                    if (SelectChess != null && (int)entity.chessObj.chess_owner_player != campType && entity.CanAttackClick)
                    {
                        // 攻击当前选中的棋子
                        account.baseCall("AttackChess", SelectChess.chessObj.id, entity.chessObj.id, entity.chessObj.chess_index_x, entity.chessObj.chess_index_z);
                    }
                    else if ((int)entity.chessObj.chess_owner_player == campType)
                    {
                        // 显示当前棋子可行走路线
                        ClearSelectChess();

                        SelectChess = entity;
                        SelectChess.BeSelect();
                    }
                    else
                    {
                        ClearSelectChess();
                    }
                }
                else if (SelectChess != null)
                {
                    if (hitGameObject.name.Equals("ChessPath"))
                    {
                        int index_x, index_z = 0;
                        if (ChessPathManager.GetChessPathIndex(hitGameObject, out index_x, out index_z))
                        {
                            // 走到这个格子去
                            account.baseCall("ChessMove", SelectChess.chessObj.id, index_x, index_z);
                        }
                    }
                    else
                    {
                        ClearSelectChess();
                    }
                }
                else
                {
                    ClearSelectChess();
                }
            }
        }
    }
Example #18
0
    public override void ShowChessPath()
    {
        base.ShowChessPath();

        int index_x = (int)chessObj.chess_index_x;
        int index_z = (int)chessObj.chess_index_z;

        bool tempChess = false;

        for (int idx = index_x; idx <= 8; idx++)
        {
            ChessEntity entity = ChessManager.Instance.FindChessByIndex(idx, index_z);
            if (entity == this)
            {
                continue;
            }
            if (entity != null)
            {
                if (!tempChess)
                {
                    tempChess = true;
                }
                else
                {
                    SetIndexPath(idx, index_z);
                    break;
                }
            }
            else
            {
                if (!tempChess)
                {
                    SetIndexPath(idx, index_z);
                }
            }
        }

        tempChess = false;
        for (int idx = index_x; idx >= 0; idx--)
        {
            ChessEntity entity = ChessManager.Instance.FindChessByIndex(idx, index_z);
            if (entity == this)
            {
                continue;
            }
            if (entity != null)
            {
                if (!tempChess)
                {
                    tempChess = true;
                }
                else
                {
                    SetIndexPath(idx, index_z);
                    break;
                }
            }
            else
            {
                if (!tempChess)
                {
                    SetIndexPath(idx, index_z);
                }
            }
        }

        tempChess = false;
        for (int idx = index_z; idx <= 9; idx++)
        {
            ChessEntity entity = ChessManager.Instance.FindChessByIndex(index_x, idx);
            if (entity == this)
            {
                continue;
            }
            if (entity != null)
            {
                if (!tempChess)
                {
                    tempChess = true;
                }
                else
                {
                    SetIndexPath(index_x, idx);
                    break;
                }
            }
            else
            {
                if (!tempChess)
                {
                    SetIndexPath(index_x, idx);
                }
            }
        }

        tempChess = false;
        for (int idx = index_z; idx >= 0; idx--)
        {
            ChessEntity entity = ChessManager.Instance.FindChessByIndex(index_x, idx);
            if (entity == this)
            {
                continue;
            }
            if (entity != null)
            {
                if (!tempChess)
                {
                    tempChess = true;
                }
                else
                {
                    SetIndexPath(index_x, idx);
                    break;
                }
            }
            else
            {
                if (!tempChess)
                {
                    SetIndexPath(index_x, idx);
                }
            }
        }
    }
Example #19
0
    protected bool hasEntity(int index_x, int index_z)
    {
        ChessEntity entity = ChessManager.Instance.FindChessByIndex(index_x, index_z);

        return(entity != null);
    }