private void TakeDamage(ShipNPC npc) { if (data.sunk) { return; } bool crit = false; float damage = 0f; float randValue = UnityEngine.Random.value; if (randValue < npc.crit_chance / 100) { crit = true; damage = npc.attack * (100 / (100 + defence)) * 2; health -= damage; } else { damage = npc.attack * (100 / (100 + defence)); health -= damage; } ServerSend.TakeDamage(id, transform.position, damage, "ship", crit); if (group != null) { ServerSend.GroupMembers(group.groupId); } }
public void NPCPosition(ShipNPC npc, float visibilityRadius) { //using (Packet _packet = new Packet((int)ServerPackets.playerPosition)) //{ Packet _packet = new Packet((int)ServerPackets.npcPosition); _packet.Write(npc.id); _packet.Write(npc.transform.position); _packet.Write(npc.transform.localRotation); SendTCPDataRadius(_packet, npc.transform.position, visibilityRadius); //} }
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; } }
// Start is called before the first frame update void Start() { AIscript = gameObject.GetComponent <ShipNPC>(); }
private void CreateNpcShip(NetIncomingMessage incmsg, bool b) { if (b) { string name = null; int id = incmsg.ReadInt32(); bool isRefreshing = false; for (int i1 = 0; i1 < world.ships.Count; i1++) { if (world.ships[i1].id == id) { isRefreshing = true; } } if (!isRefreshing) { Vector2 pos = new Vector2(incmsg.ReadSingle(), incmsg.ReadSingle()); int xpos = incmsg.ReadInt32(), ypos = incmsg.ReadInt32(); ShipType st = (ShipType)incmsg.ReadByte(); Faction f = (Faction)incmsg.ReadByte(); switch (f) { case Faction.Civilian: name = "<Bot> Engi"; break; case Faction.Enemy: name = "<Bot> Saimon"; break; case Faction.Human: name = "<Bot> Human"; break; } int[] components = { incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte() }; ShipNPC s = new ShipNPC(pos, pos, f, st, components, world, 0, 0); s.shipName = name; s.id = id; s.jumpX = xpos; s.jumpY = ypos; int gunNum = incmsg.ReadByte(); GunSlot[] gs = new GunSlot[gunNum]; for (int i = 0; i < gunNum; i++) { gs[i] = new GunSlot((GunType)incmsg.ReadByte(), s); } s.AddGuns(gs); world.shipsNpc.Add(s); } } else { string name = null; int id = incmsg.ReadInt32(); bool isRefreshing = false; for (int i1 = 0; i1 < world.ships.Count; i1++) { if (world.ships[i1].id == id) { isRefreshing = true; } } if (!isRefreshing) { Vector2 pos = new Vector2(incmsg.ReadSingle(), incmsg.ReadSingle()); float rot = incmsg.ReadSingle(); ShipType st = (ShipType)incmsg.ReadByte(); Faction f = (Faction)incmsg.ReadByte(); switch (f) { case Faction.Civilian: name = "<Bot> Engi"; break; case Faction.Enemy: name = "<Bot> Saimon"; break; case Faction.Human: name = "<Bot> Human"; break; } int[] components = { incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte() }; ShipNPC s = new ShipNPC(pos, pos, f, st, components, world, 0, 0); s.shipName = name; s.id = id; s.isJumping = false; int gunNum = incmsg.ReadByte(); GunSlot[] gs = new GunSlot[gunNum]; for (int i = 0; i < gunNum; i++) { gs[i] = new GunSlot((GunType)incmsg.ReadByte(), s); } s.AddGuns(gs); world.shipsNpc.Add(s); } } }