Example #1
0
 public void moveAuto(Map.position pos)
 {
     JFPackage.PAG_WALK wakl = new JFPackage.PAG_WALK(playerID(), pos._x, pos._z, (byte)Map.Direction.LEFT);
     NetMgr.getSingleton().sendMsg(wakl);
     setPerMoveState();
     SetMove(pos);
 }
Example #2
0
    public void CreateBlock(Map.position pos, byte block)
    {
        GameObject obj = ResMgr.getSingleton().getBlock();

        obj.transform.position = Map.getWorldPos(pos);
        obj.transform.name     = "bolck" + pos._x + ":" + pos._z;
        obj.transform.parent   = PlayerSys.getSingleton().getIsland();
    }
Example #3
0
 public void moveRight()
 {
     Map.position pos = Map.getCellPos(player.transform.position);
     pos += Map.Direction2Position[(int)Map.Direction.RIGHT];
     JFPackage.PAG_WALK wakl = new JFPackage.PAG_WALK(playerID(), pos._x, pos._z, (byte)Map.Direction.RIGHT);
     NetMgr.getSingleton().sendMsg(wakl);
     setPerMoveState();
     SetMove(pos);
 }
Example #4
0
 public void NotifyPos(Map.position pos)
 {
     setAfterMoveState();
     if (needMoveTo != pos)
     {
         needMoveTo = pos;
         //toPos = Map.getWorldPos(needMoveTo);
     }
 }
Example #5
0
 public virtual void Init(int id, Map.position pos)
 {
     if (this.gameObject.GetComponent <controller>() == null)
     {
         ctl        = this.gameObject.AddComponent <controller>();
         ctl.player = this.gameObject;
         ctl.Init();
     }
     _id = id;
     this.transform.position = Map.getWorldPos(pos);
 }
Example #6
0
    public void NotifyJumpInMap(string playerId, Map.position pos)
    {
        if (!Contain(playerId))
        {
            GameDebug.LogError("jump in map error" + playerId);
            return;
        }

        Creature c = _viewList[playerId];

        c.transform.position = Map.getWorldPos(pos);
    }
Example #7
0
File: AI.cs Project: kspine/mmorpg
    public void     AutoMove()
    {
        Player hero = PlayerSys.getSingleton().getHero();

        if (pathNode.Count != 0 && curPosIndex < pathNode.Count)
        {
            if (hero.ctl.state == 0)
            {
                Map.position pos = pathNode[curPosIndex++];
                //GameDebug.Log("Pos:("+pos._x+":"+pos._z+")");
                hero.ctl.moveAuto(pos);
            }
        }
        //if(curPosIndex>=pathNode.Count)
        //	reset();
    }
Example #8
0
 public void SetMove(Map.position pos)
 {
     setMoveState();
     if (pos != needMoveTo)
     {
         if (Mathf.Abs(pos._x - needMoveTo._x) > 5 ||
             Mathf.Abs(pos._z - needMoveTo._z) > 5)
         {
             //GameDebug.LogError("this is error on server....");
         }
         f          = 0;
         needMoveTo = pos;
         fromPos    = player.transform.position;
         toPos      = Map.getWorldPos(needMoveTo);
     }
 }
Example #9
0
    public void NotifyAdd(short type, string playerId, Map.position pos, int hp, string name)
    {
        if (Contain(playerId))
        {
            GameDebug.LogError("add type" + type + ":" + playerId);
            return;
        }
        if ((int)MAPOBJ.HERO == type)
        {
            _viewList.Add(playerId, this);
            return;
        }
        Creature c = PlayerSys.getSingleton().createCreature(type, int.Parse(playerId), pos, hp, name);

        _viewList.Add(c.ID.ToString(), c);
    }
Example #10
0
    public static Map.position pickIsland(Map.position pos)
    {
        if (Input.GetMouseButtonUp(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.tag == "island")
                {
                    return(Map.getCellPos(hit.transform.position));
                }
            }
        }
        return(pos);
    }
Example #11
0
 public override void Init(int id, Map.position pos)
 {
     base.Init(id, pos);
     _viewList  = new Dictionary <string, Creature>();
     _delayList = new List <delayAttr>();
     _ai        = new AI();
     _ai.Init();
     mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
     if (null == mainCamera)
     {
         GameDebug.LogError("Error not find MainCamera tag");
     }
     cameraX.x = 0;
     cameraX.y = 8;
     cameraX.z = -10;
     _island   = Map.invalidPos;
 }
Example #12
0
 public void NotifyMove(string playerId, Map.position pos)
 {
     if (Contain(playerId))
     {
         //GameDebug.LogError("other move:"+pos._dir);
         Creature player = _viewList[playerId];
         player.ctl.SetMove(pos);
     }
     else if (int.Parse(playerId) == PlayerSys.getSingleton().getHero().ID)
     {
         PlayerSys.getSingleton().getControl().NotifyPos(pos);
     }
     else
     {
         GameDebug.LogError("playerid not find" + playerId);
     }
 }
Example #13
0
    public Player createHero(int playerId, Map.position pos, int hp, string name)
    {
        GameObject obj = ResMgr.getSingleton().getCube();

        if (obj.GetComponent <Player>() == null)
        {
            obj.AddComponent <Player>();
        }

        _hero = obj.GetComponent <Player>();
        _hero.Init(playerId, pos);

        Init(_hero);
        //_hero.gameObject.GetComponent<Renderer>().material = ResMgr.getSingleton().getmat();
        _hero.chgColor("hero");
        _hero._name = name;
        _hero.hp    = hp;
        _hero.NotifyAdd(0, playerId.ToString(), pos, hp, name);
        return(_hero);
    }
Example #14
0
    public Creature createCreature(int type, int playerId, Map.position pos, int hp, string name)
    {
        GameObject obj = null;

        if ((int)Creature.MAPOBJ.HERO == type ||
            (int)Creature.MAPOBJ.OTHERPLAYER == type ||
            (int)Creature.MAPOBJ.DYNCBLOCK == type)
        {
            obj = ResMgr.getSingleton().getCube();
        }
        else
        {
            obj = ResMgr.getSingleton().getMaster();
        }
        obj.transform.position = Map.getWorldPos(pos);
        if (obj.GetComponent <Creature>() == null)
        {
            obj.AddComponent <Creature>();
        }

        Creature c = obj.GetComponent <Creature>();

        c.Init(playerId, pos);
        c.hp    = hp;
        c._name = name;
        if (type == (int)Creature.MAPOBJ.MASTERBOSS)        // boss
        {
            c.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
        }
        else if (type == (int)Creature.MAPOBJ.MASTER2)
        {
            c.transform.localScale = new Vector3(1.2f, 1.2f, 1.2f);
        }
        else if (type == (int)Creature.MAPOBJ.DYNCBLOCK)
        {
            c.chgColor("green");
        }
        c.transform.name = c._name + c.ID;
        return(c);
    }
Example #15
0
    public static int processMsg(List <JFPackage.IPackage> pages, System.Action <bool> cb)
    {
        try
        {
            //if(pages.Count!=0)
            //	GameDebug.LogError("before Pages count"+pages.Count);
            for (int i = 0; i < pages.Count; ++i)
            {
                JFPackage.IPackage pag = pages[i];
                NetMgr.getSingleton().perfact(pag.ID);
                if (pag.ID == (uint)JFPackage.MSG_ID.LISTKILL)
                {
                    JFPackage.PAG_ListKill kill = (JFPackage.PAG_ListKill)pag;
                    GameDebug.Log("recv list of killed:" + kill._cnt);
                    List <JFPackage.killBeKilledData> listStruct = new List <JFPackage.killBeKilledData>();
                    JFTools.bytesToArrayStruct(kill._inner, kill._cnt, listStruct);
                    foreach (var v in listStruct)
                    {
                        GameDebug.Log("Array Info: " +
                                      " id:" + v._id +
                                      " beKilled:" + v._beKilled +
                                      " killed:" + v._killed +
                                      " name:" + StringEncoding.GetString(v._name));
                    }
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.NOTIFY)
                {
                    JFPackage.PAG_Notify no = (JFPackage.PAG_Notify)pag;
                    GameDebug.Log("NotifyMessage:" + StringEncoding.GetString(no._attack) + "杀死了" + StringEncoding.GetString(no._target));
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.REGIST)
                {
                    JFPackage.PAG_REGIST reg = (JFPackage.PAG_REGIST)pag;
                    GameDebug.Log(StringEncoding.GetString(reg._name) + ":" + StringEncoding.GetString(reg._pwd));
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.MAPINFO)
                {
                    JFPackage.PAG_MAPINF mapInof = (JFPackage.PAG_MAPINF)pag;
                    Hero.NotifyMapInfo(mapInof._x, mapInof._z, mapInof._block);
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.JUMPINMAP)
                {
                    JFPackage.PAG_JUMPINMAP jim = (JFPackage.PAG_JUMPINMAP)pag;
                    PlayerSys.getSingleton().getHero().NotifyJumpInMap(jim._id.ToString(), new Map.position(jim._x, jim._z));
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.ATTR)
                {
                    JFPackage.PAG_ATTR attr = (JFPackage.PAG_ATTR)pag;
                    if (Hero != null)
                    {
                        Hero.AttrInit(attr._id.ToString(), attr._maxHp, attr._maxMp, attr._hp, attr._mp, attr._def, attr._maxShiled, attr._shiled);
                    }
                    else
                    {
                        GameDebug.LogError("hero is null");
                    }
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.ATTRCHG)
                {
                    JFPackage.PAG_ATTRCHG attr = (JFPackage.PAG_ATTRCHG)pag;
                    int action = attr._action;
                    if (Hero.ID != attr._targetID)
                    {
                        Hero.NotifyFight(attr._attackID, attr._targetID, attr._action);
                    }

                    if (attr._delay <= 0)
                    {
                        Hero.NotifyAttrChg(attr._targetID.ToString(), attr._type, attr._num);
                    }
                    else
                    {
                        Hero.NotifyAttrChgDelay(attr._targetID.ToString(), attr._type, attr._num, attr._delay);
                    }
                    GameDebug.Log(attr._attackID + " fight " + attr._targetID + ":" + ((Player.ENUM_SKILL_TYPE)attr._action).ToString() + ":" + ((Creature.ENUM_ATTR)attr._type).ToString() + ":" + attr._num);
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.Error)
                {
                    JFPackage.PAG_ERROR error = (JFPackage.PAG_ERROR)pag;
                    GameDebug.LogError("msg Error:" + ((JFPackage.MSG_ID)error._theMsgid).ToString() + ":" + ((JFPackage.ERROR_CODE)error._errorCode).ToString());
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.REGIST)
                {
                    JFPackage.PAG_REGIST reg = (JFPackage.PAG_REGIST)pag;
                    GameDebug.Log("Register Success!!!" + reg._name + ":" + reg._pwd);
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.DELETE)
                {
                    JFPackage.PAG_DELETE del = (JFPackage.PAG_DELETE)pag;
                    PlayerSys.getSingleton().getHero().NotifyRemove(del._id.ToString());
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.CREATE)
                {
                    JFPackage.PAG_CREATE create = (JFPackage.PAG_CREATE)pag;
                    Map.position         pos    = new Map.position(create._x, create._z);
                    pos._dir = create._dir;
                    CreateSize++;
                    //GameDebug.Log("CreateSize:"+CreateSize+":("+create._x+":"+create._z+")");
                    string name = StringEncoding.GetString(create._name);
                    if (create._type == 0)                     // hero
                    {
                        PlayerSys.getSingleton().createHero(create._id, pos, 0, name);
                    }
                    else                     // others player
                    {
                        PlayerSys.getSingleton().getHero().NotifyAdd(create._type, create._id.ToString(), pos, 0, name);
                    }
                }
                else if ((uint)JFPackage.MSG_ID.WALK == pag.ID)
                {
                    JFPackage.PAG_WALK walk = (JFPackage.PAG_WALK)pag;
                    Map.position       pos  = new Map.position(walk._x, walk._z);
                    pos._dir = (int)walk._dir;
                    PlayerSys.getSingleton().getHero().NotifyMove(walk._id.ToString(), pos);
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.FIGHT)
                {
                    JFPackage.PAG_FIGHT fight = (JFPackage.PAG_FIGHT)pag;
                    Player hero = PlayerSys.getSingleton().getHero();
                    if (fight._action == 8)
                    {
                        GameDebug.Log("BOSS 召唤了卫兵,请小心.");
                    }
                    //if(fight._id != PlayerSys.getSingleton().getHero().ID)
                    {
                        PlayerSys.getSingleton().getHero().NotifyFight(fight._id, fight._target, fight._action);
                    }
                    //else
                    {
                        //	hero.fight(fight._action,PlayerSys.getSingleton().getControl().curPos);
                    }
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.CONNECTED)
                {
                    //short id = 0;
                    //PlayerSys.getSingleton().createHero(id,new Map.position(0,0));
                }
                else if (pag.ID == (uint)JFPackage.MSG_ID.TEST_STRING)
                {
                    JFPackage.PAG_STRING pag64 = (JFPackage.PAG_STRING)pag;
                    GameDebug.Log("recv 1000:" + StringEncoding.GetString(pag64.content));
                }
                else if ((uint)JFPackage.MSG_ID.TEST_STRUCTURE == pag.ID)
                {
                    JFPackage.PAG_STRUCTURE inner = (JFPackage.PAG_STRUCTURE)pag;

                    // * Funck 内存对齐,字符串长度问题。byte[] 中如果有0的话,转成string,长度有问题。
                    string desc = StringEncoding.GetString(inner.dest);
                    string name = StringEncoding.GetString(inner.name);
                    string sex5 = StringEncoding.GetString(inner.sex5);
                    GameDebug.Log("recv 1001:" + name + ":" + desc + ":" + sex5);
                }
                else if ((uint)JFPackage.MSG_ID.TEST_ARRAY == pag.ID)
                {
                    JFPackage.PAG_ARRAY array = (JFPackage.PAG_ARRAY)pag;
                    GameDebug.Log("recv 1002:" + array._cnt);
                    List <JFPackage.PAG_ArrayInner> listStruct = new List <JFPackage.PAG_ArrayInner>();
                    JFTools.bytesToArrayStruct(array._inner, array._cnt, listStruct);
                    foreach (var v in listStruct)
                    {
                        GameDebug.Log("Array Info: " +
                                      " name:" + StringEncoding.GetString(v.name) +
                                      " dest:" + StringEncoding.GetString(v.dest) +
                                      " sex5:" + StringEncoding.GetString(v.sex5));
                    }
                }
                else
                {
                    GameDebug.LogError("PAG ID Not FIND!!!" + pag.ID);
                }
            }

            if (pages.Count != 0)
            {
                ProcessNumTotal += pages.Count;
                //Debug.Log("processMsg call , Num pages process :"+ProcessNumTotal);
            }
        }
        catch (System.Exception e)
        {
            GameDebug.LogError("MSGProcess Error:" + pages.Count + ":" + e);
            pages.Clear();
            return(-1);
        }

        if (pages.Count != 0)
        {
            //GameDebug.LogError("after Pages count"+pages.Count);
            pages.Clear();
        }
        return(0);
    }
Example #16
0
 public void Init()
 {
     needMoveTo = Map.getCellPos(player.transform.position);
     SetNormalSate();
 }
Example #17
0
 public static Vector3 getWorldPos(Map.position pos)
 {
     return(new Vector3(pos._x * detl, 0, pos._z * detl));
 }
Example #18
0
    // Update is called once per frame
    void Update()
    {
        _ai.AutoMove();
        _ai.AutoFight(Time.deltaTime);
        DelayAttrAction((short)(Time.deltaTime * 1000));
        cameraMove();
        DrawCritical();
        if (target && target.isDead())
        {
            //chgTraget(null);
        }

        if (Input.GetKeyUp(KeyCode.Alpha9))
        {
            JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, 999);
            fightMSG._target = target.ID;
            NetMgr.getSingleton().sendMsg(fightMSG);
        }

        // norma attack
        if (Input.GetKeyUp(KeyCode.Space) && target != null)
        {
            JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, (short)ENUM_SKILL_TYPE.SKILL_NORMAL);
            fightMSG._target = target.ID;
            NetMgr.getSingleton().sendMsg(fightMSG);
        }

        // magic attack
        if (Input.GetKeyUp(KeyCode.Alpha1) && target != null)
        {
            if (mp >= 10)
            {
                JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, (short)ENUM_SKILL_TYPE.SKILL_TRAIL);
                fightMSG._target = target.ID;
                NetMgr.getSingleton().sendMsg(fightMSG);
            }
            else
            {
                GameDebug.LogError("Use skill:NOT ENOUGH MP.");
            }
        }
        if (Input.GetKeyUp(KeyCode.Alpha2) && target != null)
        {
            if (mp >= 30)
            {
                JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, (short)ENUM_SKILL_TYPE.SKILL_AREA_TARGET);
                fightMSG._target = target.ID;
                NetMgr.getSingleton().sendMsg(fightMSG);
            }
            else
            {
                GameDebug.LogError("Use skill:NOT ENOUGH MP.");
            }
        }
        if (Input.GetKeyUp(KeyCode.Alpha3))
        {
            if (mp >= 30)
            {
                JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, (short)ENUM_SKILL_TYPE.SKILL_AREA_SELF);
                NetMgr.getSingleton().sendMsg(fightMSG);
            }
            else
            {
                GameDebug.LogError("Use skill:NOT ENOUGH MP.");
            }
        }
        if (Input.GetKeyUp(KeyCode.Alpha4))
        {
            if (mp >= 30 && _island != Map.invalidPos)
            {
                JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, (short)ENUM_SKILL_TYPE.SKILL_AREA_ISLAND);
                fightMSG._param01 = (short)_island._x;
                fightMSG._param02 = (short)_island._z;
                NetMgr.getSingleton().sendMsg(fightMSG);
            }
            else
            {
                GameDebug.LogError("Use skill:NOT ENOUGH MP. not click island");
            }
        }
        if (Input.GetKeyUp(KeyCode.Alpha5))
        {
            if (mp >= 50)
            {
                JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, (short)ENUM_SKILL_TYPE.SKILL_SHILED);
                fightMSG._target = ID;
                NetMgr.getSingleton().sendMsg(fightMSG);
            }
            else
            {
                GameDebug.LogError("Use skill: not enough mp");
            }
        }
        if (Input.GetKeyUp(KeyCode.Alpha6))
        {
            if (mp >= 50)
            {
                JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(ID, -1, (short)ENUM_SKILL_TYPE.SKILL_DYNCBLOCK);
                fightMSG._target = ID;
                NetMgr.getSingleton().sendMsg(fightMSG);
            }
            else
            {
                GameDebug.LogError("Use skill: not enough mp");
            }
        }
        // select target
        _island = MousePickUp.pickIsland(_island);
        Creature c = MousePickUp.pick(target);

        chgTraget(c);
    }