public void Awake() { _characterComponent = GetComponent <CharacterComponent>(); _network = GetComponent <NetworkOwnershipComponent>(); _viewRPC = FindReplicationViewForComponent <CharacterTargetingComponent>(); }
// is the passed in game object locally controlled public static bool IsGameObjectLocallyOwned(GameObject obj, NetworkOwnershipComponent ownershipCompPassedIn = null) { if (PlayerManager.IsPlayer(obj)) { return(PlayerManager.IsLocalPlayer(obj)); // players are local on there local machine } // everything barring players are local to the host return(Replication.IsHost); }
public override void Awake() { base.Awake(); enemyController = mDMono.transform.GetComponent <EnemyController>(); // _fsm = enemyController.GetComponent<PlayMakerFSM>(); _network = enemyController.GetComponent <NetworkOwnershipComponent>(); enemyController.TargetingComponent = enemyController.GetComponent <CharacterTargetingComponent>(); _conditionComponent = enemyController.GetComponent <ConditionComponent>(); }
private void MoveToPosition(Vector3 position) { if (mDMono != null && !NetworkOwnershipComponent.IsGameObjectLocallyOwned(mDMono.gameObject, _network)) { return; } if (enemyController != null && enemyController.TargetingComponent != null) { enemyController.TargetingComponent.SetMovementTargetNoRPC(position); } }
// see which player is best suited to own this enemy private static PlayerController CalculateBestOwner(EnemyController enemy, NetworkOwnershipComponent netOwner) { CharacterTargetingComponent enemyTargeting = enemy.gameObject.GetComponent <CharacterTargetingComponent>(); PlayerController closestPlayer = null; float distToClosestPlayerSqr = float.MaxValue; for (int controller = 0; controller < PlayerManager.sPlayerControllers.Count; ++controller) { PlayerController pc = PlayerManager.sPlayerControllers[controller]; if (pc.gameObject.GetComponent <CharacterTargetingComponent>().AttackTarget == enemy.gameObject) // if this enemy is this player's attack target, then we should be owned by this player { return(pc); } float distToPlayerSqr = GameUtils.GetDistSqXZ(pc.transform.position, enemy.transform.position); if (distToPlayerSqr < distToClosestPlayerSqr) { distToClosestPlayerSqr = distToPlayerSqr; closestPlayer = pc; } } if (null != enemyTargeting.AttackTarget && PlayerManager.IsPlayer(enemyTargeting.AttackTarget)) { return(enemyTargeting.AttackTarget.GetComponent <PlayerController>()); // if this player is this enemies attack target, then we should be owned by this player } if (!netOwner.IsOwner(closestPlayer.ReplicationPlayer)) // if the closest player is not our current owner, we may want to change owners { EB.Sparx.Player sparxPlayer = netOwner.GetOwner(); if (sparxPlayer == null) { return(closestPlayer); } PlayerController currentOwner = PlayerManager.GetPlayerController(sparxPlayer); float distFromCurrentOwnerSqr = GameUtils.GetDistSqXZ(currentOwner.transform.position, enemy.transform.position); // these distances are arbitrary, but are designed so that dithering between different owners should not occur const float RequiredDistFromCurrentOwnerSqr = 12f * 12f; const float RequiredDistToNewOwnerSqr = 5f * 5f; if (distFromCurrentOwnerSqr > RequiredDistFromCurrentOwnerSqr && // if we are far enough away from our current owner distToClosestPlayerSqr < RequiredDistToNewOwnerSqr) // we are close enough to our potential new owner { return(closestPlayer); } } return(null); }
public void SetMovementTarget(Vector3 target, bool isNull = false, bool shouldIssueCommand = true, bool isNeedShowReticle = true, bool force = false) { if (!force) { if (!NetworkOwnershipComponent.IsGameObjectLocallyOwned(gameObject, _network)) { return; } } if (force) { EB.Debug.Log("Start SetMovementTarget by transfer dart"); } if (!isNull) { bool isValidNewTarget = !_movementTarget.HasValue; if (_movementTarget.HasValue) { Vector3 toTarget = target - _movementTarget.Value; isValidNewTarget = toTarget.sqrMagnitude > MinDistForNewMovementTargetSq; } if (isValidNewTarget) { SetMoveTargetRPC(target, shouldIssueCommand); // Hotfix_LT.Messenger.Raise<Vector3>(Hotfix_LT.EventName.PlayerMoveSyncManagerMove, target); //GlobalUtils.CallStaticHotfix("Hotfix_LT.MessengerAdapter", "PlayerMoveSyncManagerMove", target); if (_viewRPC != null) { _viewRPC.RPC("SetMoveTargetRPC", EB.RPCMode.Others, target, shouldIssueCommand); } } } else { ClearMoveTargetRPC(); // Hotfix_LT.Messenger.Raise<Vector3>(Hotfix_LT.EventName.PlayerMoveSyncManagerMove, gameObject.transform.position); //GlobalUtils.CallStaticHotfix("Hotfix_LT.MessengerAdapter", "PlayerMoveSyncManagerMove", gameObject.transform.position); if (_viewRPC != null) { _viewRPC.RPC("ClearMoveTargetRPC", EB.RPCMode.Others); } } if (isNeedShowReticle && OnMovementTargetChangeRequest != null) { OnMovementTargetChangeRequest(target, isNull); } }
/// <summary> /// �������ڵ��Ѿ�����Ŀ�ĵ�ֹͣ�ƶ� ����Ҫ����������Ϣ /// </summary> /// <param name="shouldIssueCommand"></param> public void StopMoveInDestination(bool shouldIssueCommand = true) { if (!NetworkOwnershipComponent.IsGameObjectLocallyOwned(gameObject, _network)) { return; } ClearMoveTargetRPC(); if (_viewRPC != null) { _viewRPC.RPC("ClearMoveTargetRPC", EB.RPCMode.Others); } if (OnMovementTargetChangeRequest != null) { OnMovementTargetChangeRequest(Vector3.zero, true); } }
// look each frame at who should be owner of what private static void TryTransferOwnership() { for (int i = 0; i < _networkOwnershipComponents.Count; ++i) { NetworkOwnershipComponent netOwner = _networkOwnershipComponents[i]; if (!netOwner.IsOwnershipTransferAllowed) { continue; // we don't want to change who owns this object right now } EnemyController enemy = netOwner.gameObject.GetComponent <EnemyController>(); if (null != enemy) { PlayerController bestOwner = CalculateBestOwner(enemy, netOwner); if (null != bestOwner && !netOwner.IsOwner(bestOwner.ReplicationPlayer)) // if the best owner is not the current owner { netOwner.ChangeOwner(bestOwner.ReplicationPlayer); } } } }
public void SetAttackTarget(GameObject target, bool shouldIssueCommand = true) { if (/*(GameStateManager.Instance.State != eGameState.Overworld) &&*/ !NetworkOwnershipComponent.IsGameObjectLocallyOwned(gameObject, _network)) { return; } if (target != null) { SetMovementTargetNoRPC(Vector3.zero, true); SetAttackTargetFromRPC(target, shouldIssueCommand); } else { ClearAttackTargetRPC(); if (_viewRPC != null) { _viewRPC.RPC("ClearAttackTargetRPC", EB.RPCMode.Others); } } }
public static void Unregister(NetworkOwnershipComponent component) { _networkOwnershipComponents.Remove(component); }
public static void Register(NetworkOwnershipComponent component) { _networkOwnershipComponents.Add(component); }