public bool Send(FCCommand.CMD cmd, OBJECT_ID objectID, FCCommand.STATE state, bool isHost) { bool ret = false; if (state != FCCommand.STATE.RIGHTNOW) { FCCommand ewd = null; if (_deActiveCommandList.Count != 0) { ewd = _deActiveCommandList[0]; _deActiveCommandList.Remove(ewd); } else { ewd = new FCCommand(); } ewd.Set(cmd, objectID, state, isHost); AddCmdToArray(ewd); } else { _fastCommand.Set(cmd, objectID, state, isHost); if (objectID.HandleCommand(ref _fastCommand)) { _fastCommand._objID = null; ret = true; } else { //AddCmdToArray(ewd); // may need to add it to command list } } return(ret); }
protected virtual void FirstInit() { _thisTransform = transform; _thisObject = gameObject; _objectID = new OBJECT_ID(this, FC_OBJECT_TYPE.OBJ_NORMAL); ObjectManager.Instance.SaveObject(_objectID); }
void ReceiveCommand2v(int cmd, Vector3 vParam1, Vector3 vParam2, int networkID, int commandIndex, Vector3 commandPos, PhotonMessageInfo msgInfo) { Debug.Log("[RPC] [receive] command:" + (FCCommand.CMD)cmd + " obj:" + networkID + " from player:" + msgInfo.sender + " delayMS : " + ((int)((PhotonNetwork.time - msgInfo.timestamp) * 1000)).ToString()); //put the command into input command list OBJECT_ID object_ID = ObjectManager.Instance.GetObjectByNetworkID(networkID); if (object_ID == null) { Debug.Log("command target object is not exist: " + networkID); } else { FCCommand ewd = new FCCommand(); ewd.Set((FCCommand.CMD)cmd, object_ID, vParam1, FC_PARAM_TYPE.VECTOR3, vParam2, FC_PARAM_TYPE.VECTOR3, null, FC_PARAM_TYPE.NONE, FCCommand.STATE.RIGHTNOW, false); WriteCommandToCache(object_ID.NetworkId, commandPos, false, commandIndex, ewd); } }
//update sync commands private void UpdateSyncCommands() { if (GameManager.Instance.GameState != EnumGameState.InBattle) { return; } //collect sync commands CollectSyncCommands(); foreach (SyncCommand sc in _syncCommandScripArray) { if (sc != null) { if (sc._myIndex != MatchPlayerManager.Instance.GetPlayerNetworkIndex()) //discard myself? { if ( (!GameManager.Instance.IsMultiplayMode && sc._myPosition != Vector3.zero) || (GameManager.Instance.IsPVPMode && (sc._myPosition != Vector3.zero || sc._myRotation != Vector3.zero)) ) { //pos is effective, use this pos OBJECT_ID player_ID = ObjectManager.Instance.GetObjectByNetworkID(sc._myIndex); if (player_ID != null) { //the bit higher than 8 is the high type if (player_ID.getOnlyObjectType != FC_OBJECT_TYPE.OBJ_AC) { Debug.LogError("I am not a player"); } ActionController ac = player_ID.fcObj as ActionController; //position //if (sc._myLastPosition != sc._myPosition) if (ac.ThisTransform.localPosition != sc._myPosition) { ac._dataSync._position = sc._myPosition; } sc._myLastPosition = sc._myPosition; if (GameManager.Instance.IsPVPMode) { //rotation , eularAngles //if (sc._myLastRotation != sc._myRotation) if (ac.ThisTransform.eulerAngles != sc._myRotation) { ac._dataSync._rotation = sc._myRotation; } sc._myLastRotation = sc._myRotation; } } } } } } }
bool OnMessage(uint MsgID, ushort MsgFlag, OBJECT_ID SenderID, byte[] Data) { CBaseMsgHandler.MsgHandler Handler; if (m_MsgMap.TryGetValue(MsgID, out Handler)) { m_CurMsgSenderID = SenderID; CSmartStruct Packet = new CSmartStruct(Data, 0, (uint)Data.Length, false); Handler(Packet); return(true); } return(false); }
public void Set(CMD cmd, OBJECT_ID objID, object param1, FC_PARAM_TYPE p1Type, STATE state, bool isHost) { _cmd = cmd; _param1 = param1; _param2 = null; _param3 = null; _param1Type = p1Type; _param2Type = FC_PARAM_TYPE.NONE; _param3Type = FC_PARAM_TYPE.NONE; _objID = objID; _state = state; _isHost = isHost; }
//get ac of the player under my control public ActionController GetMyActionController() { int myIndex = MatchPlayerManager.Instance.GetPlayerIndex(); OBJECT_ID objectID = ObjectManager.Instance.GetObjectByNetworkID(myIndex + FCConst.k_network_id_hero_start); if (objectID != null) { ActionController ac = objectID.fcObj as ActionController; Assertion.Check(ac.IsPlayer && ac.IsPlayerSelf, "get a bad ac (not player or under my control)"); return(ac); } return(null); }
public FCCommand(FCCommand ewc) { _cmdIndex = ewc._cmdIndex; _cmd = ewc._cmd; _param1 = ewc._param1; _param2 = ewc._param2; _param3 = ewc._param3; _param1Type = ewc._param1Type; _param2Type = ewc._param2Type; _param3Type = ewc._param3Type; _objID = ewc._objID; _state = ewc._state; _isHost = ewc._isHost; }
// Update is called once per frame void Update() { if (_ac == null) { OBJECT_ID objectID = ObjectManager.Instance.GetObjectByNetworkID(_playerIndex + FCConst.k_network_id_hero_start); if (objectID != null) { _ac = objectID.fcObj as ActionController; _ac._hpChangeMessage += OnHPChanged; _portrait.mainTexture = _ac._avatarController._icon; } } }
//this function should be called when object is dead or is destroyed public void RemoveObject(OBJECT_ID thisObject) { if (_objectsDic.ContainsKey((int)thisObject)) { _objectsDic.Remove((int)thisObject); } if (thisObject.NetworkId != -1) { if (_netObjectsDic.ContainsKey(thisObject.NetworkId)) { _netObjectsDic.Remove(thisObject.NetworkId); } } }
void OnObjectReport(OBJECT_ID ObjectID, byte[] Data) { if (ObjectID != m_Operator.GetObjectID()) { m_TargetID = ObjectID; Logger.Log("Finded{0}", m_TargetID); if (IsActive) { byte[] PingData = new byte[32]; for (int i = 0; i < 100; i++) { CCSTesterMsgCaller MsgCaller = new CCSTesterMsgCaller(m_Operator, m_TargetID); MsgCaller.Ping((uint)System.Environment.TickCount, PingData); } } } }
//a player drop and remain multi-play private void DropClientAt(int playerIndex) { GetMatchPlayerProfile(playerIndex)._isDropped = true; int playerNetworkIndex = playerIndex + FCConst.k_network_id_hero_start; //search for the player and disable it for (int i = 0; i < FCConst.MAX_PLAYERS; i++) { OBJECT_ID object_ID = ObjectManager.Instance.GetObjectByNetworkID(i + FCConst.k_network_id_hero_start); if (object_ID != null) { if (object_ID.NetworkId == playerNetworkIndex) { LevelManager.Singleton.DeactiveHero(i); //remove sync objects break; } } } bool needShowErrorMsg = true; if (GameManager.Instance.IsPVPMode && PvPBattleSummary.Instance != null && PvPBattleSummary.Instance.IsFinish ) { needShowErrorMsg = false; } //show drop player message box in battle if (GameManager.Instance.GameState == EnumGameState.InBattle && needShowErrorMsg) { MatchPlayerProfile profile = GetMatchPlayerProfile(playerIndex); string text = string.Format("{0} has left from our matchmaking", profile._playerInfo.DisplayNickname); MessageController.Instance.AddMessage(2.0f, text); // UIMessageBoxManager.Instance.ShowMessageBox(text, "MessageBox", MB_TYPE.MB_OK, OnClickGoToTownCallback); } }
public List <ActionController> GetEnemyActionController() { int myIndex = MatchPlayerManager.Instance.GetPlayerIndex(); OBJECT_ID objectID = ObjectManager.Instance.GetObjectByNetworkID(myIndex + FCConst.k_network_id_hero_start); List <ActionController> enemyAcList = new List <ActionController>(); foreach (KeyValuePair <int, OBJECT_ID> pre in _netObjectsDic) { if (pre.Value != objectID) { ActionController ac = pre.Value.fcObj as ActionController; if (null != ac) { enemyAcList.Add(ac); } } } return(enemyAcList); }
void ReceiveCommand2q(int cmd, Quaternion qParam1, Quaternion qParam2, int networkID, int commandIndex, Vector3 commandPos, PhotonMessageInfo msgInfo) { //put the command into input command list OBJECT_ID object_ID = ObjectManager.Instance.GetObjectByNetworkID(networkID); if (object_ID == null) { Debug.Log("command target object is not exist: " + networkID); } else { FCCommand ewd = new FCCommand(); ewd.Set((FCCommand.CMD)cmd, object_ID, qParam1, FC_PARAM_TYPE.QUATERNION, qParam2, FC_PARAM_TYPE.QUATERNION, null, FC_PARAM_TYPE.NONE, FCCommand.STATE.RIGHTNOW, false); WriteCommandToCache(object_ID.NetworkId, commandPos, false, commandIndex, ewd); } }
private void sendPvPBattleSummary() { Hashtable payload = new Hashtable(); payload.Add("messageType", "pvp"); payload.Add("op_type", "pvp_end"); Hashtable data = new Hashtable(); for (int i = 0; i < MatchPlayerManager.Instance.GetPlayerCount(); i++) { int[] playerDetials = new int[7]; playerDetials[0] = MultiplayerDataManager.Instance.PvPStatisticsList[i].Kills; playerDetials[1] = MultiplayerDataManager.Instance.PvPStatisticsList[i].Deaths; playerDetials[2] = MultiplayerDataManager.Instance.PvPStatisticsList[i].IsTripleKill ? 1 : 0; playerDetials[3] = MultiplayerDataManager.Instance.PvPStatisticsList[i].FirstBlood ? 1 : 0; OBJECT_ID objectID = ObjectManager.Instance.GetObjectByNetworkID(i + FCConst.k_network_id_hero_start); if (objectID != null) { ActionController ac = objectID.fcObj as ActionController; MultiplayerDataManager.Instance.PvPStatisticsList[i].HealthPoint = Mathf.FloorToInt(ac.HitPointPercents * 100); } playerDetials[4] = MultiplayerDataManager.Instance.PvPStatisticsList[i].HealthPoint; playerDetials[5] = MultiplayerDataManager.Instance.PvPStatisticsList[i].PositionOfKills; // position of current kills playerDetials[6] = MatchPlayerManager.Instance.GetMatchPlayerProfile(i)._isDropped ? 1 : 0; // dropped match //data.Add(MatchPlayerManager.Instance.GetMatchPlayerProfile(i)._playerInfo._id, playerDetials); } string str = FCJson.jsonEncode(data); str = Utils.DesEncrypt(str); payload.Add("data", str); Utils.CustomGameServerMessage(null, OnSendBattleSummary); }
//drop and go to single play, only happens on clients when host drops private void DropToSinglePlay() { //search for other players and disable them int myPlayerID = GetPlayerNetworkIndex(); for (int i = 0; i < FCConst.MAX_PLAYERS; i++) { OBJECT_ID object_ID = ObjectManager.Instance.GetObjectByNetworkID(i + FCConst.k_network_id_hero_start); if (object_ID != null) { if (object_ID.NetworkId != myPlayerID) { LevelManager.Singleton.DeactiveHero(i); } } } //rebuild triggers LevelManager.Singleton.RefreshTriggersViaEnemies(); //remove sync objects bool needShowErrorMsg = true; if (GameManager.Instance.IsPVPMode && PvPBattleSummary.Instance != null && PvPBattleSummary.Instance.IsFinish ) { needShowErrorMsg = false; } if (needShowErrorMsg) { UIMessageBoxManager.Instance.ShowMessageBox("You have disconnected from host and will continue with single palyer mode!", "MessageBox", MB_TYPE.MB_OK, OnClickGoToTownCallback); } }
//send msg to all clients except me public void SendCommandToOthers(FCCommand.CMD cmd, OBJECT_ID objID, Vector3 commandPosition, object param1, FC_PARAM_TYPE p1Type, object param2, FC_PARAM_TYPE p2Type, object param3, FC_PARAM_TYPE p3Type ) { //single player will not send comment to others if (PhotonNetwork.room == null) { return; } Debug.Log("[send] command:" + cmd + " , obj_network_id:" + objID.NetworkId); //build command instance and add into output list FCCommand ewd = new FCCommand(GetNextCommandStreamID(objID.NetworkId)); ewd.Set((FCCommand.CMD)cmd, objID, param1, p1Type, param2, p2Type, param3, p3Type, FCCommand.STATE.RIGHTNOW, false); ewd._commandPosition = commandPosition; if (CheatManager.netDelay > 0) { StartCoroutine(AddCommand(ewd)); } else { _outputCommandList.Add(ewd); } // //_outputCommandList.Add(ewd); }
/*void LateUpdate() * { * if(PhotonNetwork.room == null) return; * * if(!_isLerpEnabled || !_owner.IsClientPlayer) return; * * _owner.ThisTransform.localPosition = Vector3.Lerp( _owner._currPosition , _lerpToPos , SMOOTH * Time.deltaTime); * if( Vector3.Distance(_owner.ThisTransform.localPosition , _lerpToPos) < 0.1f ){ * _isLerpEnabled = false; * } * }*/ public virtual bool HandleCommand(ref FCCommand ewd) { if (PhotonNetwork.room == null) { return(false); } switch (ewd._cmd) { case FCCommand.CMD.CLIENT_MOVE_TO_POINT: { if (ewd._param1Type != FC_PARAM_TYPE.VECTOR3) { Debug.LogError("get a CLIENT_MOVE_TO_POINT but param1 is not a vector3"); } else { _owner._dataSync._position = (Vector3)ewd._param1; return(true); } } break; case FCCommand.CMD.CLIENT_HURT: { if (ewd._param1Type != FC_PARAM_TYPE.VECTOR3 || ewd._param2Type != FC_PARAM_TYPE.VECTOR3) { Debug.LogError("get a CLIENT_HURT but param1 , 2 is not a vector3"); } else { // Vector3 param1 = (Vector3)ewd._param1; // FC_HIT_TYPE eht = (FC_HIT_TYPE)param1.x; // bool isCritical = (param1.y == 0.0 ? false : true); //int realDamage = (int)param1.z; // Vector3 hitDirection = (Vector3)ewd._param2; _owner.SelfMoveAgent.SetPosition(ewd._commandPosition); //_owner.ACHandleHurt(eht , isCritical ,realDamage , hitDirection , true , true , false ); //Debug.Log("Get FCCommand.CMD.CLIENT_HURT !!!!!!!!!!!!! hitDir = " + hitDirection); //CommandManager.Instance.SendFastToSelf(ref ewd); return(true); } } break; case FCCommand.CMD.CLIENT_HURT_HP: { if (ewd._param1Type != FC_PARAM_TYPE.INT || ewd._param2Type != FC_PARAM_TYPE.INT) { Debug.LogError("get a CLIENT_HURT_HP but param1 is not a int"); } else { _owner.ACReduceHP((int)ewd._param1, (int)ewd._param2, false, false, false, false); // _owner._dataSync._hitPoint = (int)ewd._param1; return(true); } } break; case FCCommand.CMD.CLIENT_THREAT: { if ((ewd._param1Type != FC_PARAM_TYPE.INT) || (ewd._param2Type != FC_PARAM_TYPE.INT)) { Debug.LogError("get a CLIENT_THREAT but param is not a int"); } else { //get player objid OBJECT_ID player_ID = ObjectManager.Instance.GetObjectByNetworkID((int)ewd._param2); if (player_ID == null) { Debug.LogError("receive increase threat but bad player"); } //get player AC ActionController target = player_ID.fcObj as ActionController; //increase threat _owner.ACIncreaseThreat((int)ewd._param1, false, target); return(true); } } break; case FCCommand.CMD.CLIENT_LEVELUP: { if (ewd._param1Type != FC_PARAM_TYPE.INT) { Debug.LogError("get a CLIENT_LEVELUP but param is not a int"); } else { //level up _owner.OnLevelUp_FromNet((int)ewd._param1); return(true); } } break; case FCCommand.CMD.CLIENT_CURRSTATE: { if (ewd._param1Type != FC_PARAM_TYPE.INT) { Debug.LogError("get a CLIENT_CURRSTATE_ID but param is not a int"); //}else if (ewd._param2Type != FC_PARAM_TYPE.FLOAT){ // Debug.LogError("get a CLIENT_CURRSTATE_ID but param2 is not float type"); } else { _clientAICurrStateID = (AIAgent.STATE)ewd._param1; //float y = (float)ewd._param2; //Quaternion rotation = Quaternion.Euler(new Vector3(0, y, 0)); //Vector3 v3 = rotation * Vector3.forward; //_owner.ACRotateTo(v3,-1,true,true); return(true); } } break; case FCCommand.CMD.CLIENT_POTION_HP: { if (ewd._param1Type != FC_PARAM_TYPE.FLOAT || ewd._param2Type != FC_PARAM_TYPE.FLOAT) { Debug.LogError("get a CLIENT_POTION_HP but param is not a float"); } else { //increase HP _owner.ACEatPotion((float)ewd._param1, (float)ewd._param2, FCConst.POTION_TIME, FCPotionType.Health); return(true); } } break; case FCCommand.CMD.CLIENT_POTION_ENERGY: { if (ewd._param1Type != FC_PARAM_TYPE.FLOAT || ewd._param2Type != FC_PARAM_TYPE.FLOAT) { Debug.LogError("get a CLIENT_POTION_ENERGY but param is not a float"); } else { //increase EP _owner.ACEatPotion((float)ewd._param1, (float)ewd._param2, FCConst.POTION_TIME, FCPotionType.Mana); return(true); } } break; case FCCommand.CMD.CLIENT_REVIVE: { if (ewd._param1Type != FC_PARAM_TYPE.NONE) { Debug.LogError("get a CLIENT_REVIVE but param is not a float"); } else { //revive now //_owner.GoToRevive(); return(true); } } break; } return(false); }
public void WriteCommandToCache(int netIndex, Vector3 commandPos, bool streamCommand, params object[] args) { OBJECT_ID objectID = ObjectManager.Instance.GetObjectByNetworkID(netIndex); if (objectID == null) { Debug.LogError(string.Format("Object ID is not exist ! netIndex = {0} , isStreamCommand = {1} ", netIndex, streamCommand)); return; } int objID = (int)objectID; ActionController ac = ObjectManager.Instance.GetObjectByNetworkID(netIndex).fcObj as ActionController; //Debug.Log("ac object id = " + ac.ObjectID + ", object ID = " + objID); //if(ac != null && ac.IsPlayer && GameManager.Instance.IsPVPMode) if (GameManager.Instance.IsPVPMode) { int cidx = (int)args[0]; //command stream idx if (streamCommand) { if (ac.AIUse.AIStateAgent.CurrentStateID == AIAgent.STATE.DEAD || ac.AIUse.AIStateAgent.CurrentStateID == AIAgent.STATE.REVIVE) { return; } if (!_commandCmdStreamCache.ContainsKey(objID)) { _commandCmdStreamCache[objID] = new List <FC_COMMAND_NETSTREAM>(); } List <FC_COMMAND_NETSTREAM> cpc = _commandCmdStreamCache[objID]; if ((cpc.Count > 0 && cpc[cpc.Count - 1]._commandIndex < cidx) || cpc.Count == 0) { FC_COMMAND_NETSTREAM ecns = new FC_COMMAND_NETSTREAM((FC_COMMAND_NETSTREAM)args[1]); ecns._commandIndex = cidx; if (ecns._state == AIAgent.STATE.HURT) { ac.AIUse.UpdateNetCommand(AIAgent.COMMAND_DONE_FLAG.IN_HURT_STATE); } //Debug.Log(string.Format("[stream command] _commandIndex:{0} , _currentPosition:{1} , _currentRotation{2} , _state{3}" , // ecns._commandIndex , ecns._currentPosition , ecns._currentRotation ,ecns._state)); cpc.Add(ecns); //Debug.Log("add stream cmd to list : _myRotation = " + ecns._currentRotation + ", cmd idx = " + ecns._commandIndex); } } else { if (!_commandRpcCache.ContainsKey(objID)) { _commandRpcCache[objID] = new List <FCCommand>(); } FCCommand ewc = new FCCommand((FCCommand)args[1]); ewc._cmdIndex = cidx; ewc._commandPosition = commandPos; ewc._isRun = false; ewc._needRunPerFrame = false; ewc._canDrop = false; //Debug.Log(string.Format("[rpc command] _commandIndex:{0} , _currentPosition:{1} , CMD = {2}" , // ewc._cmdIndex , ewc._commandPosition , ewc._cmd )); _commandRpcCache[objID].Add(ewc); if (ewc._cmd == FCCommand.CMD.CLIENT_HURT || ewc._cmd == FCCommand.CMD.ACTION_EOT || ewc._cmd == FCCommand.CMD.ATTACK_WITH_SPEC_CONTS) { //Debug.Log(Time.realtimeSinceStartup); ac.AIUse.UpdateNetCommand(); } //if find rpc command idx < player next command index or current //replace command //pre command may should return to array // all rpc command should have position param } } else { if (!streamCommand) { FCCommand ewc = (FCCommand)args[1]; ewc._cmdIndex = 0; _inputCommandList.Add(ewc); } } }
void OnConcernedObjectLost(OBJECT_ID ObjectID) { }
//this function should only be called in OBJECT_ID set network id property public void SaveNetObject(OBJECT_ID thisObject) { _netObjectsDic[thisObject.NetworkId] = thisObject; }
public void SaveObject(OBJECT_ID thisObject) { _objectsDic[(int)thisObject] = thisObject; }
bool OnPreTranslateMessage(uint MsgID, ushort MsgFlag, OBJECT_ID SenderID, byte[] Data) { return(false); }
bool OnFindObject(OBJECT_ID CallerID) { return(false); }
void OnProxyObjectIPReport(OBJECT_ID ProxyObjectID, uint Port, string IPStr) { }
bool OnSystemMessage(uint MsgID, ushort MsgFlag, OBJECT_ID SenderID, byte[] Data) { return(false); }