private GameObject CreateShipGroup(ClientShip targetShip, string targetShipResPath, float shipWrapRadius) { GameObject group = new GameObject(); group.transform.SetParent(DeploySceneManager.Instance.PlayerGridDrawer.GridInstance.transform); //约定组名为目标舰船在数据索引值,记录之,方便传给战斗布阵单元的坐标 group.name = PlayerSys.GetPlayerShipList().IndexOf(targetShip).ToString(); // 初始化阵形 BattleSys.SetFormation(true, targetShip); //成组上阵,组中舰船的数量 int groupMemberCount = targetShip.Reference.stack ? targetShip.Reference.stack_num : 1; BoxCollider tempCollider = null; for (int i = 0; i < groupMemberCount; i++) { Vector3 pos = targetShip.FormationList == null ? Vector3.zero : targetShip.FormationList[i]; GameObject member = CreateShip(targetShipResPath, group.transform, GridDrawer.OffsetByWrapRadius(pos, shipWrapRadius)); if (tempCollider == null) { tempCollider = member.GetComponent <BoxCollider>(); } Destroy(member.GetComponent <BoxCollider>()); DestoryTrailEffect(member); } //添加tag,用于点选式布阵的碰撞检测 group.tag = "ShipModel"; return(group); }
// Use this for initialization void Start() { // 注册服务器错误消息函数 //Register ( ProtoID.S2CSystem, OnS2CSystem ); // 初始化各个模块网络消息 PlayerSys.RegisterMsg(); }
protected override void OnShow(params object[] args) { AudioManager.Instance.PlayMusic = true; PlayerSys.ResetPlayerInfo(); EnableLoginCameraAnimation(); EnableShipAnimation(); StartCoroutine(ShakeCameraAtFocusTime()); }
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(); }
public static PlayerSys getSingleton() { if (_ins == null) { _ins = new PlayerSys(); } return(_ins); }
public void disConnect() { if (_net != null) { _net.Closed(); if (PlayerSys.getSingleton().getHero() != null) { PlayerSys.getSingleton().getHero().NotifyRemove("all"); } _net = null; } }
// Update is called once per frame void Update() { t -= Time.deltaTime; if (t <= 0) { Creature c = PlayerSys.getSingleton().getHero().getCreature(_id); if (c != null && false == c.isDead()) { c.chgColor(_beforeColor); } this.enabled = false; } }
void OnEnable() { Creature c = PlayerSys.getSingleton().getHero().getCreature(_id); if (c != null && false == c.isDead()) { _beforeColor = c.color; c.chgColor("area"); t = 1.0f; } else { this.enabled = false; } }
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); }
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(); }
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); } }
/// <summary> /// 记录布阵情况(索引,对应世界坐标) /// </summary> public void RecordDeployInfo() { Transform formationRoot = DeploySceneManager.Instance.PlayerGridDrawer.GridInstance.transform; for (int i = 0; i < formationRoot.childCount; i++) { Transform t = formationRoot.transform.GetChild(i); int index = int.Parse(t.name); //Debug.Log( string.Format( "<color=green>RecordDeployInfo, index : {0}, position : {1}</color>", index, t.position ) ); ClientShip cs = PlayerSys.GetPlayerShipList()[index]; if (cs == null) { Debugger.LogError("RecordDeployInfo Failed! At index : " + index); return; } PlayerSys.Formation(index, t.position + new Vector3(cs.Reference.vol % GridDrawer.GRID_SPACE_UNIT_SIZE, 0f, cs.Reference.vol % GridDrawer.GRID_SPACE_UNIT_SIZE));//纠正偏移 } }
public void AutoFight(float t) { autoFightTime += t; if (autoFightTime <= 1.5f) { return; } autoFightTime = 0; Player hero = PlayerSys.getSingleton().getHero(); Creature master = hero.getMater(3.0f); if (master != null && master.hp > 0) { hero.chgTraget(master); JFPackage.PAG_FIGHT fightMSG = new JFPackage.PAG_FIGHT(hero.ID, -1, (short)Player.ENUM_SKILL_TYPE.SKILL_TRAIL); fightMSG._target = master.ID; NetMgr.getSingleton().sendMsg(fightMSG); } }
public static void SendMsg(int id, ProtoMessage msg) { if (msgBuffList.Count >= 3) { Debug.Log("消息队列缓冲已满"); return; } proto.MessageHead head = new proto.MessageHead(); head.pid = id; head.msgid = SerialNumber; if (id != ProtoID.C2SLogin) { head.session_id = SessionId; head.gid = PlayerSys.GetSN(); if (head.session_id == 0) { Debug.Log("Send Msg error: Have not session_id"); return; } } else { SerialNumber = 1; head.msgid = SerialNumber; msgBuffList.Clear(); } byte headSize = ( byte )head.ByteSize(); short msgSize = ( short )msg.ByteSize(); // 总包大小 System.Int64 allSize = (System.Int64)(headSize + msgSize + NetMsg.MsgSendHeadSize); byte[] sendBuf = new byte[allSize]; // 写包头 sendBuf[0] = ( byte )( uint )(allSize & 0xff); sendBuf[1] = ( byte )( uint )((allSize >> 8) & 0xff); sendBuf[2] = ( byte )( uint )((allSize >> 16) & 0xff); sendBuf[3] = ( byte )( uint )((allSize >> 32) & 0xff); sendBuf[4] = headSize; // 转换为2进制 head.Serialize(ProtoHeadBuf, 0); msg.Serialize(ProtoDataBuf, 0); System.Buffer.BlockCopy(ProtoHeadBuf, 0, sendBuf, NetMsg.MsgSendHeadSize, headSize); System.Buffer.BlockCopy(ProtoDataBuf, 0, sendBuf, NetMsg.MsgSendHeadSize + headSize, msgSize); // 心跳包不阻塞玩家输入 if (id != ProtoID.C2SHeartBeat && id != ProtoID.C2SSetCustomSetting) { NetworkIndicator.Instance.StartActivityIndicator(); } msgBuffList.Add(sendBuf); if (msgBuffList.Count == 1) { Instance.StartCoroutine(OnPost(msgBuffList[0])); } SerialNumber++; }
int playerID() { return((int)PlayerSys.getSingleton().getHero().ID); }
/// <summary> /// 生成玩家可布阵舰船的视图列表 /// </summary> private void GeneratePlayerShipListView() { List <ClientShip> dataList = PlayerSys.GetPlayerShipList(); //哈希结构,键--舰船ID,值--拥有该ID的舰船集合 Dictionary <int, List <int> > hash = new Dictionary <int, List <int> >(); for (int index = 0; index < dataList.Count; index++) { int key = dataList[index].Reference.id; if (!hash.ContainsKey(key)) { hash.Add(key, new List <int>()); } hash[key].Add(index); } foreach (var id in hash) { string log = ""; foreach (var item in id.Value) { log += string.Format("{0}, ", item); } //Debug.Log( string.Format( "<color=yellow>[ID{0}] : {1}</color>", id.Key, log) ); } UnitUIElementList_ = new List <DeployUnitUIElement>(); foreach (var item in hash) { GameObject scrollItem = Global.CreateUI("deployitem", ScrollViewRoot.gameObject); scrollItem.name = item.Key.ToString(); DeployUnitUIElement view = scrollItem.AddComponent <DeployUnitUIElement>(); view.SyncEnergy += SyncEnergy; proto.UnitReference unit = GlobalConfig.GetUnitReference(item.Key); view.ShipName = unit.name; view.WrapPointCount = unit.warp_cost; view.IconName = unit.iconfile; view.Level = 10;//舰船成长,暂时没得 foreach (var v in item.Value) { view.ReadyDeployIndexQueue.Enqueue(v); } view.UnitCount = item.Value.Count; UnitUIElementList_.Add(view); } foreach (var item in UnitUIElementList_) { bool cannotDeployThisType = item.WrapPointCount > CurrRemainEnergy_; if (cannotDeployThisType) { item.SetDragAbility(false); } else { if (item.ReadyDeployIndexQueue.Count == 0) { continue; } item.SetDragAbility(true); } } }
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); }
void OnPlayClick() { PlayerSys.Login(); }