public void DisableAgent() { if (sender != null) { pathStatus = NavMeshPathStatus.PathInvalid; ServerSend.ActivatePlayerMovement(sender.playerCharacter.id, sender.playerInstance.transform.position); player = null; sender = null; agent.enabled = false; } }
private void OnTriggerEnter(Collider other) { if (other.name.Equals("Sphere")) { int otherPlayerId = other.GetComponentInParent <Player>().id; if (otherPlayerId != id) { bool isOnShip = GameServer.clients[otherPlayerId].player.data.is_on_ship; /*if (isOnShip) * { * ServerSend.DestroyPlayerCharacter(id, otherPlayerId); * }*/ ServerSend.ActivateShip(id, otherPlayerId); ServerSend.Stats(otherPlayerId, id); ServerSend.Buffs(otherPlayerId, id); } } else if (other.name.Equals("PlayerSphere")) { int otherPlayerId = other.GetComponentInParent <PlayerCharacter>().id; if (otherPlayerId != id) { ServerSend.ActivatePlayerCharacter(id, otherPlayerId); ServerSend.Stats(otherPlayerId, id); ServerSend.Buffs(otherPlayerId, id); Player player = GameServer.clients[otherPlayerId].player; if (player.playerMovement.agent.enabled) { ServerSend.DeactivatePlayerMovement(otherPlayerId, player.playerInstance.transform.position); } else { ServerSend.ActivatePlayerMovement(otherPlayerId, player.playerInstance.transform.position); } } } else if (other.tag.Equals("Resource")) { gatheringEnabled = true; currentResource = other.gameObject; } else if (other.tag.Equals("Dock")) { dock = other.gameObject; isOnDock = true; } else if (other.tag.Equals("CraftingSpot")) { craftingEnabled = true; craftingSpot = other.GetComponent <CraftingSpot>(); } else if (other.tag == "Trader") { tradingEnabled = true; trader = other.gameObject.GetComponent <Trader>(); } else if (other.tag == "TradeBroker") { tradeBrokerEnabled = true; } else if (other.tag == "Weapon") { PlayerAttack.OnPlayerAttack(this, other); } else if (other.name.Equals("NPCSphere")) { int npcId = other.GetComponentInParent <NPC>().id; ServerSend.NPCStats(npcId, id); ServerSend.ActivateNPC(id, npcId); } else if (other.name.Equals("DamageCollider")) { NPC npc = other.GetComponentInParent <NPC>(); DamageColliderInfo info = other.GetComponent <DamageColliderInfo>(); NPCAttack.OnNPCAttack(info, npc, this); } }
private void LateUpdate() { if (player != null) { elapsed += Time.deltaTime; if (elapsed > 0.2f) { elapsed -= 0.2f; bool ok = NavMesh.CalculatePath(sender.playerInstance.transform.position, player.playerInstance.transform.position, NavMesh.AllAreas, path); pathStatus = path.status; if (pathStatus == NavMeshPathStatus.PathComplete) { agent.enabled = true; agent.SetPath(path); ServerSend.DeactivatePlayerMovement(sender.playerCharacter.id, sender.playerInstance.transform.position); } else { pathStatus = NavMeshPathStatus.PathInvalid; ServerSend.ActivatePlayerMovement(sender.playerCharacter.id, sender.playerInstance.transform.position); player = null; sender = null; agent.enabled = false; } } /*if (agent.pathStatus == NavMeshPathStatus.PathComplete && !agent.hasPath) * { * agent.enabled = false; * agent.enabled = true; * agent.SetDestination(player.playerInstance.transform.position); * }*/ if (agent.pathStatus == NavMeshPathStatus.PathComplete && agent.hasPath) { Vector3 lookPos; Quaternion targetRot; agent.updatePosition = false; agent.updateRotation = false; lookPos = player.playerInstance.transform.position - this.transform.position; lookPos.y = 0; targetRot = Quaternion.LookRotation(lookPos); this.transform.rotation = targetRot;//Quaternion.Slerp(transform.rotation, targetRot, Time.deltaTime * turnSpeed); this.transform.position = agent.nextPosition; //controller.Move(desVelocity.normalized * walkSpeed * Time.deltaTime); //agent.velocity = controller.velocity; if (Vector3.Distance(transform.position, player.playerInstance.transform.position) > 1) { ServerSend.PlayerCharacterPosition(sender.id, sender.playerInstance.transform.position, sender.playerInstance.transform.rotation, sender.playerCharacter.pirate.transform.rotation, false); } if (Vector3.Distance(transform.position, player.playerInstance.transform.position) < 1) { pathStatus = NavMeshPathStatus.PathInvalid; ServerSend.SendTradeRequest(player, sender); ServerSend.ActivatePlayerMovement(sender.playerCharacter.id, sender.playerInstance.transform.position); player = null; sender = null; agent.enabled = false; } } } }
private void OnTriggerEnter(Collider other) { if (other.tag.Equals("CannonBall")) { Player player = other.gameObject.GetComponent <CannonBall>().player; ShipNPC npc = other.gameObject.GetComponent <CannonBall>().npc; Vector3 tempPos = other.transform.position - new Vector3(0f, 0.5f, 0f); if (player == null) { TakeDamage(npc); } else { TakeDamage(player); } Debug.Log("Hit by " + other.name); other.gameObject.SetActive(false); } else if (other.name.Equals("Sphere")) { int otherPlayerId = other.GetComponentInParent <Player>().id; if (otherPlayerId != id) { ServerSend.Stats(otherPlayerId, id); ServerSend.Buffs(otherPlayerId, id); CannonController cannonController = other.GetComponentInParent <CannonController>(); Quaternion leftRotation = cannonController.L_Cannon_1.transform.localRotation; Quaternion rightRotation = cannonController.R_Cannon_1.transform.localRotation; ServerSend.CannonRotate(otherPlayerId, id, leftRotation, "Left"); ServerSend.CannonRotate(otherPlayerId, id, rightRotation, "Right"); if (data.is_on_ship) { ServerSend.ActivateShip(id, otherPlayerId); } /*bool isOnShip = GameServer.clients[otherPlayerId].player.data.is_on_ship; * if (isOnShip) * ServerSend.DestroyPlayerCharacter(id, otherPlayerId);*/ } } else if (other.name.Equals("PlayerSphere")) { int otherPlayerId = other.GetComponentInParent <PlayerCharacter>().id; if (otherPlayerId != id) { /*GameObject playerCharacter = GameServer.clients[otherPlayerId].player.playerInstance; * * Vector3 position = playerCharacter.transform.position;*/ /*bool isOnShip = GameServer.clients[otherPlayerId].player.data.is_on_ship; * if (!isOnShip) * {*/ //ServerSend.InstantiatePlayerCharacter(id, otherPlayerId, position, playerCharacter.transform.eulerAngles.y); //}*/ if (data.is_on_ship) { ServerSend.ActivatePlayerCharacter(id, otherPlayerId); Player player = GameServer.clients[otherPlayerId].player; if (player.playerMovement.agent.enabled) { ServerSend.DeactivatePlayerMovement(otherPlayerId, player.playerInstance.transform.position); } else { ServerSend.ActivatePlayerMovement(otherPlayerId, player.playerInstance.transform.position); } } ServerSend.Stats(otherPlayerId, id); ServerSend.Buffs(otherPlayerId, id); } } else if (other.name.Equals("NPCSphere")) { if (data.is_on_ship) { int npcId = other.GetComponentInParent <NPC>().id; ServerSend.NPCStats(npcId, id); ServerSend.ActivateNPC(id, npcId); } } else if (other.tag.Equals("Dock")) { dock = other.gameObject; isOnDock = true; } }