void GotAttack(NetworkMessage netMsg) { AttackMessage attackMessage = netMsg.ReadMessage <AttackMessage>(); VRAR_Tile tile = GameStateManager.getInstance().getCurrentLevel().getTileFromIndexPos(attackMessage.targetTileX, attackMessage.targetTileY); NonPlayer npc = tile.getNPC(); if (npc != null) { //CHeck if we did the attack and show the hitsplat if true if (IsMyId(attackMessage.id)) { UIManager.Instance.SpawnHitSplat(tile.getNPC().GetObject().transform, attackMessage.result); } npc.DecreaseHealth(attackMessage.result); players[attackMessage.id].DoAttackAnim(); } else //if there is no npc check if there is a player { foreach (BasePlayer player in players.Values) { if (player.GetCurrentTile() == tile) { //CHeck if we did the attack and show the hitsplat if true if (IsMyId(attackMessage.id)) { UIManager.Instance.SpawnHitSplat(player.GetObject().transform, attackMessage.result); } //the player died ! move them to their spawn location if (player.DecreaseHealth(attackMessage.result)) { //After a player died we have to go through all the players again and make sure all their positios are ok //first the local player and then the external players TileRenderer.instance.teleportLocalPlayer(GamePlayManagerAR.instance.localPlayer.GetCurrentVec().x, GamePlayManagerAR.instance.localPlayer.GetCurrentVec().y); foreach (BasePlayer moreplayers in players.Values) { if (moreplayers != GamePlayManagerAR.instance.localPlayer) { TileRenderer.instance.teleportExternalPlayer(moreplayers); } } } players[attackMessage.id].DoAttackAnim(); } } } }
//handle the attack that is SendToAll on the server itself void handleAttack(int id, int attackId, int targetTileX, int targetTileY, int result) { VRAR_Tile tile = GameStateManager.instance.getCurrentLevel().getTileFromIndexPos(targetTileX, targetTileY); NonPlayer npc = tile.getNPC(); if (npc != null) { npc.DecreaseHealth(result); } else //if there is no npc check if there is a player { foreach (BasePlayer player in players.Values) { if (player.GetCurrentTile() == tile) { //the player died ! move them to their spawn location player.DecreaseHealth(result); print("hit player but no teleport stuff implemented on server"); /*if (player.DecreaseHealth(result)) * { * //After a player died we have to go through all the players again and make sure all their positios are ok * //first the local player and then the external players * TileRenderer.instance.teleportLocalPlayer(GamePlayManagerAR.instance.localPlayer.GetCurrentVec().x, GamePlayManagerAR.instance.localPlayer.GetCurrentVec().y); * foreach (BasePlayer moreplayers in players.Values) * { * if (moreplayers != GamePlayManagerAR.instance.localPlayer) * { * TileRenderer.instance.teleportExternalPlayer(moreplayers); * } * } * * }*/ } } } }