1404 lines
52 KiB
C#
1404 lines
52 KiB
C#
using NaughtyAttributes;
|
|
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Rendering.Universal;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.VFX;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Net.NetworkInformation;
|
|
using UnityEngine.Rendering;
|
|
using Util;
|
|
|
|
public class Client : MonoBehaviour
|
|
{
|
|
public static Client Instance { get; private set; }
|
|
public static bool LocalPlayerLoggedIn = false;
|
|
private PlayerManager playerManager;
|
|
private NPCManager npcManager;
|
|
|
|
public static bool NoClipped = false;
|
|
[SerializeField] private Camera noClipCameraPrefab;
|
|
private Camera currentNoClipCam;
|
|
|
|
public Terrain[] activeTerrains;
|
|
|
|
[SerializeField, Required] private GameObject UIObjects;
|
|
public GameObject PostProcessingObject;
|
|
|
|
public Volume PostProcessingMain;
|
|
public Volume PostProcessingMashroom;
|
|
|
|
public Material SkyMain;
|
|
public Material SkyMashroom;
|
|
|
|
|
|
public static bool AllowNPCGizmos = true;
|
|
|
|
public enum MAPS
|
|
{
|
|
SiegeWorldsMap,
|
|
StarBlindWave
|
|
};
|
|
|
|
[BoxGroup("Select the map you would like to load into.")]
|
|
public MAPS MapSelection;
|
|
|
|
[BoxGroup("Select the map you would like to load into.")] [SerializeField]
|
|
private Sprite siegeWorldsMapIcon;
|
|
[SerializeField] private List<Sprite> MapIcons;
|
|
[SerializeField] private List<string> MapNames;
|
|
|
|
|
|
private GameObject PortalVFX_Object;
|
|
public const float WATER_HEIGHT = 22.0f;
|
|
public const float MAX_WATER_DEPTH = 12.2f;
|
|
[SerializeField] ForwardRendererData urpData;
|
|
|
|
private List<string> playerNamesInInstance = new List<string>();
|
|
[System.NonSerialized] public List<FractionalCryptoDrop> DroppedCryptoInInstance = new List<FractionalCryptoDrop>();
|
|
|
|
#region Inventory Array Allocations
|
|
|
|
private static int[] inventoryIDs = new int[24];
|
|
private static int[] inventoryAmounts = new int[24];
|
|
public static int[] equiptmentIDs = new int[6];
|
|
|
|
#endregion
|
|
|
|
#region GroundItemsStruct
|
|
|
|
//unused right now
|
|
struct GroundItemState
|
|
{
|
|
public int Id;
|
|
public Vector2Int Position;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public bool UnderWaterEffectEnabled
|
|
{
|
|
get => urpData.rendererFeatures[0].isActive;
|
|
set
|
|
{
|
|
//Underwater audio Effects
|
|
SettingsMenu.Instance.sfxMixer.SetFloat("Distortion", value ? 0 : -80);
|
|
SettingsMenu.Instance.sfxMixer.SetFloat("LowPass", value ? 0 : -80);
|
|
urpData.rendererFeatures[0].SetActive(value); //rendererFeatures[0] is the BLIT effect.
|
|
urpData.SetDirty();
|
|
}
|
|
}
|
|
|
|
public void ToggleBlit(bool isOn)
|
|
{
|
|
//Debug.Log($"Function Fired! IsOn: {isOn}");
|
|
urpData.rendererFeatures[0].SetActive(isOn); //rendererFeatures[0] is the BLIT effect.
|
|
urpData.SetDirty();
|
|
|
|
//Debug.Log($"is Blit on? {urpData.rendererFeatures[0].isActive}");
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
//this should be called when you exit playmode.
|
|
#if UNITY_EDITOR
|
|
urpData.rendererFeatures[0].SetActive(false);
|
|
urpData.SetDirty();
|
|
#endif
|
|
|
|
}
|
|
|
|
public bool CheckIfPlayerIsUnderWater()
|
|
{
|
|
return Player.Instance.cameraController.playerCam.transform.position.y <= WATER_HEIGHT;
|
|
}
|
|
|
|
[System.NonSerialized] public Color32 SelectablesColor = new Color32(255, 18, 0, 255);
|
|
|
|
[System.NonSerialized] public int bloodID = Shader.PropertyToID("BloodColour");
|
|
[System.NonSerialized] public Vector4 RedBloodColour = new Vector4(0.75f, 0f, 0f, 1f);
|
|
[System.NonSerialized] public Vector4 GreenBloodColour = new Vector4(0.14f, 1.427f, 0f, 1f);
|
|
[System.NonSerialized] public Vector4 BrownBloodColour = new Vector4(0.07f, 0.01f, 0, 1.0f);
|
|
[System.NonSerialized] public Vector4 GreyBloodColour = new Vector4(0.19f, 0.19f, 0.19f, 1f);
|
|
[System.NonSerialized] public float colourIntensityModifier = 3.5f;
|
|
[System.NonSerialized] public string myUsername;
|
|
[System.NonSerialized] public string myPassword;
|
|
[System.NonSerialized] public string myServerIp;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
|
|
|
|
Instantiate(UIObjects);
|
|
|
|
string sceneName = "World";
|
|
if (MapSelection == MAPS.SiegeWorldsMap)
|
|
{
|
|
sceneName = "SiegeWorldsMap";
|
|
}
|
|
|
|
if (!SceneManager.GetSceneByName(sceneName).isLoaded)
|
|
{
|
|
SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
|
|
}
|
|
//if (!SceneManager.GetSceneByName("UI").isLoaded)
|
|
//{
|
|
// SceneManager.LoadScene("UI", LoadSceneMode.Additive);
|
|
//}
|
|
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
private void Start()
|
|
{
|
|
//RenderSettings.fogMode = FogMode.ExponentialSquared;
|
|
//RenderSettings.fogDensity = 0.010f;
|
|
//RenderSettings.fogColor = new Color(0.8f, 0.8f, 0.8f);
|
|
//RenderSettings.fog = true;
|
|
//halloween
|
|
//RenderSettings.fogDensity = 0.03f;
|
|
//RenderSettings.fogColor = new Color(0.92f, 0.90f, 0.95f);
|
|
|
|
npcManager = gameObject.AddComponent<NPCManager>();
|
|
playerManager = gameObject.AddComponent<PlayerManager>();
|
|
gameObject.AddComponent<GroundItemManager>();
|
|
|
|
|
|
mainPlayer = CreatePlayer(-1, "mainPlayer");
|
|
mainPlayer.SetActive(true);
|
|
|
|
UIManager.Instance.displayLoginScreen();
|
|
|
|
//can now call GISocket.Instance
|
|
GISocket socket = new GISocket(false);
|
|
|
|
PortalVFX_Object = GameObject.Find("Portal_VFX");
|
|
activeTerrains = Terrain.activeTerrains;
|
|
|
|
|
|
}
|
|
|
|
public NPCManager GetNPCManager() => npcManager;
|
|
|
|
|
|
public void SetMapNameAndImage(TMP_Text mapNameText, Image image)
|
|
{
|
|
//this function is used for the pre-game canvas to set the correct mapImage and name for the menu.
|
|
mapNameText.text = "Siege Worlds";
|
|
image.sprite = siegeWorldsMapIcon;
|
|
}
|
|
public void SetMapNameAndImage(TMP_Text mapNameText, Image image,string mapname,Sprite mapimage)
|
|
{
|
|
mapNameText.text = mapname;
|
|
image.sprite = mapimage;
|
|
|
|
}
|
|
|
|
bool tempbool = false;
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
#if UNITY_EDITOR
|
|
EditorToggleHideHUD();
|
|
#endif
|
|
|
|
GISocket.Instance.Update();
|
|
parsePacket();
|
|
if (GISocket.Instance.isClosed() && !UIManager.Instance.loginScreen)
|
|
{
|
|
UIManager.Instance.displayLoginScreen();
|
|
Cursor.visible = true;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Onlogout();
|
|
}
|
|
|
|
////this needs to be removed at some point. its a shit band-aid. and needs to be set appropiately
|
|
if (Player.Instance.GetInputHandler().UsingGamePad && !UIManager.Instance.OnScreenKeyboardGO.activeInHierarchy)
|
|
{
|
|
UIManager.Instance.ChatBox.UsingChatBox = false;
|
|
}
|
|
|
|
if (Player.Instance.GetInputHandler().ChatKeyPressed)
|
|
{
|
|
Player.Instance.GetInputHandler().ChatKeyPressed = false;
|
|
if (!UIManager.Instance.loginScreen && !UIManager.Instance.Inventory.activeSelf)
|
|
{
|
|
if (Player.Instance.GetInputHandler().UsingGamePad)
|
|
{
|
|
HandleOnScreenKeyboardChatting();
|
|
}
|
|
|
|
|
|
if (!UIManager.Instance.ChatBox.UsingChatBox)
|
|
{
|
|
if (!Player.Instance.GetInputHandler().UsingGamePad)
|
|
{
|
|
UIManager.Instance.ChatInputField.interactable = true;
|
|
}
|
|
|
|
EventSystem.current.SetSelectedGameObject(UIManager.Instance.ChatInputField.gameObject, null);
|
|
UIManager.Instance.ChatBox.UsingChatBox = true;
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.ChatBox.UsingChatBox = false;
|
|
if (UIManager.Instance.ChatInputField.text != "" &&
|
|
UIManager.Instance.ChatInputField.text.Length < 250)
|
|
{
|
|
if (Player.Instance.GetInputHandler().UsingGamePad)
|
|
{
|
|
StartCoroutine(OnScreenKeyboard.Instance.CloseKeyboardRoutine());
|
|
UIManager.Instance.ChatBox.UsingChatBox = false;
|
|
}
|
|
else
|
|
{
|
|
PacketManager.sendChatMessage(UIManager.Instance.ChatInputField.text);
|
|
}
|
|
}
|
|
|
|
UIManager.Instance.ChatInputField.text = "";
|
|
UIManager.Instance.ChatInputField.interactable = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void HandleOnScreenKeyboardChatting()
|
|
{
|
|
if (UIManager.Instance.OnScreenKeyboardGO.activeInHierarchy)
|
|
{
|
|
StartCoroutine(OnScreenKeyboard.Instance.CloseKeyboardRoutine());
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.showInterface("OnScreenKeyboard");
|
|
}
|
|
|
|
OnScreenKeyboard.Instance.currentInputField = UIManager.Instance.ChatInputField;
|
|
OnScreenKeyboard.Instance.isPassWordField =
|
|
UIManager.Instance.ChatInputField.contentType == TMP_InputField.ContentType.Password;
|
|
}
|
|
|
|
private void EditorToggleHideHUD()
|
|
{
|
|
//in editor only or NoClipped to hide UI for screenshots when needed.
|
|
if (Input.GetKeyDown(KeyCode.H) && UIManager.Instance.ChatInputField.interactable == false)
|
|
{
|
|
var playerHUD = UIManager.Instance.getInterface<GameObject>("PlayerCanvas");
|
|
var chatBox = UIManager.Instance.getInterface<GameObject>("ChatBox");
|
|
var quickInv = UIManager.Instance.getInterface<GameObject>("QuickInventoryAccess");
|
|
playerHUD.SetActive(!playerHUD.activeSelf);
|
|
chatBox.SetActive(!chatBox.activeSelf);
|
|
quickInv.SetActive(!quickInv.activeSelf);
|
|
tempbool = !tempbool;
|
|
Player.Instance.OnlyCastPlayerShadows(tempbool);
|
|
}
|
|
}
|
|
|
|
int lastPacketId = -1;
|
|
|
|
private bool parsePacket()
|
|
{
|
|
if (GISocket.Instance == null)
|
|
return false;
|
|
|
|
if (GISocket.Instance.isClosed())
|
|
return false;
|
|
|
|
|
|
|
|
try
|
|
{
|
|
GISocket socketStream = GISocket.Instance;
|
|
int i = socketStream.available();
|
|
if (i == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (pktSize == -1)
|
|
{
|
|
if (i >= 4)
|
|
{
|
|
byte[] size = new byte[4];
|
|
socketStream.readInputStream(ref size, 4);
|
|
|
|
// Decode packet size in big-endian order
|
|
pktSize = (size[0] & 0xFF) << 24 |
|
|
(size[1] & 0xFF) << 16 |
|
|
(size[2] & 0xFF) << 8 |
|
|
(size[3] & 0xFF);
|
|
|
|
|
|
|
|
//Debug.Log("packet size " + pktSize);
|
|
|
|
pktSize -= 4; // Adjust size if needed
|
|
i -= 4; // Reduce i as before
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (pktSize > 0)
|
|
{
|
|
if (i >= pktSize)
|
|
{
|
|
//Debug.Log("packet size " + pktSize);
|
|
byte[] payload = new byte[pktSize];
|
|
socketStream.readInputStream(ref payload, pktSize);
|
|
pktSize = -1;
|
|
Packet p = new Packet(payload);
|
|
processPacket(p);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pktSize = -1;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
//GISocket.Instance.close();
|
|
//Debug.Log("last pkt: " + lastPacketId);
|
|
GISocket.Instance.flush();
|
|
Debug.LogException(e);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void dropClient()
|
|
{
|
|
//lets print a message to the user, to tell them that connection is trying to be re-established
|
|
//for not debug.log
|
|
Debug.Log("Connection Lost... Attempting to reestablish.");
|
|
|
|
GISocket.Instance.connect(myServerIp);
|
|
PacketManager.sendLoginRequest(myUsername, myPassword);
|
|
}
|
|
|
|
public void processPacket(Packet p)
|
|
{
|
|
while (p.hasNext())
|
|
{
|
|
int packetId = p.getType();
|
|
//print packet id
|
|
//Debug.Log("packet id: " + packetId);
|
|
|
|
switch (packetId)
|
|
{
|
|
case MessageID.Login:
|
|
{
|
|
Debug.Log("login response");
|
|
|
|
int loginResult = p.readByte();
|
|
this.playerId = p.readShort();
|
|
this.playerRights = p.readInt();
|
|
|
|
TMP_InputField passwordField = GameObject.Find("passwordInputField").GetComponent<TMP_InputField>();
|
|
TMP_InputField usernameField = GameObject.Find("usernameInputField").GetComponent<TMP_InputField>();
|
|
|
|
UIManager.Instance.hideInterface("EndOfGameCanvas");
|
|
//here we should set player up in the game
|
|
if (loginResult == 0)
|
|
{
|
|
// clear fields (username will reinsert itself if toggle selected (for relog prevents someone sleuthing onto your account
|
|
if (PlayerPreferences.GetRememberUsername() == 0)
|
|
{
|
|
usernameField.text = "";
|
|
}
|
|
|
|
if (PlayerPreferences.GetRememberPassword() == 0)
|
|
{
|
|
passwordField.text = "";
|
|
}
|
|
|
|
//close interface
|
|
UIManager.Instance.closeLoginScreen();
|
|
UIManager.Instance.hideInterface("LoginScreen");
|
|
|
|
Player.Instance.updatePlayer = true;
|
|
UIManager.Instance.ChatBox.UsingChatBox = false;
|
|
AudioManager.Instance.playSong("BackgroundSound_Ambient", true);
|
|
|
|
LocalPlayerLoggedIn = true;
|
|
|
|
onLogin();
|
|
}
|
|
else if (loginResult == 1)
|
|
{
|
|
UIManager.Instance.LoginMessage.text = "Invalid Username or Password.";
|
|
}
|
|
else if (loginResult == 2)
|
|
{
|
|
UIManager.Instance.LoginMessage.text =
|
|
"Siege Worlds has been updated. Please check for available Updates.";
|
|
//open url
|
|
Application.OpenURL("https://www.siegeworlds.com/download.php");
|
|
}
|
|
else if (loginResult == 3)
|
|
{
|
|
UIManager.Instance.LoginMessage.text = "Account is already logged in.";
|
|
}
|
|
else if (loginResult == 4)
|
|
{
|
|
UIManager.Instance.LoginMessage.text = "You are banned from siege worlds.";
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.LoginMessage.text = "Error connecting to server.";
|
|
}
|
|
lastPacketId = MessageID.Login;
|
|
break;
|
|
}
|
|
|
|
case MessageID.NPCUpdate:
|
|
{
|
|
int entityId = p.readShort();
|
|
int flags = p.readInt();
|
|
int entityType = p.readByte();
|
|
float x = p.readFloat();
|
|
float z = p.readFloat();
|
|
int deltaMultiplier = p.readByte();
|
|
float face = p.readFloat();
|
|
float normalizedHealth = p.readFloat();
|
|
//Debug.Log("INSIDE PACKET 2 - id: " + entityId + ", x: " + x + ", z: " + z);
|
|
npcManager.processEntityUpdate(entityId, flags, entityType, x, z, deltaMultiplier, face, normalizedHealth);
|
|
lastPacketId = MessageID.NPCUpdate;
|
|
break;
|
|
}
|
|
|
|
case MessageID.ChatMessage:
|
|
{
|
|
int npcId = p.readInt();
|
|
int playerRank = p.readInt();
|
|
string name = p.readString();
|
|
string message = p.readString();
|
|
|
|
if (name != "")
|
|
{
|
|
PopSpeechBubble(npcId, Player.Instance.GetID(), message);
|
|
}
|
|
|
|
UIManager.Instance.getInterface<GameObject>("ChatBox").GetComponent<ChatBox>()
|
|
.SendMessageToChat(playerRank, name, message);
|
|
lastPacketId = MessageID.ChatMessage;
|
|
break;
|
|
}
|
|
|
|
case MessageID.Logout:
|
|
{
|
|
int key = p.readInt();
|
|
if (key == Config.LOGOUT_KEY)
|
|
{
|
|
//this doesnt get ran, at all.
|
|
GISocket.Instance.close();
|
|
}
|
|
lastPacketId = MessageID.Logout;
|
|
break;
|
|
}
|
|
|
|
case MessageID.OpenInterface:
|
|
{
|
|
string interfaceName = p.readLongString();
|
|
int hideOrShow = p.readInt();
|
|
|
|
if (interfaceName.ToLower().Equals("inventory"))
|
|
{
|
|
if (hideOrShow == 0)
|
|
InventoryManager.Instance.hideInventory();
|
|
else
|
|
InventoryManager.Instance.showInventory();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (hideOrShow == 0)
|
|
{
|
|
UIManager.Instance.hideInterface(interfaceName);
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.showInterface(interfaceName);
|
|
}
|
|
}
|
|
|
|
lastPacketId = MessageID.OpenInterface;
|
|
break;
|
|
}
|
|
|
|
|
|
case MessageID.SendFrame:
|
|
{
|
|
string frame = p.readLongString();
|
|
string msg = p.readLongString();
|
|
GameObject g = GameObject.Find(frame);
|
|
|
|
//update the point ui elements because they might not be active at time of setting
|
|
|
|
InventoryManager.Instance.updatePointUIElement(frame, msg);
|
|
if (frame == "spade_text")
|
|
{
|
|
Debug.Log("Spade text recieved with value " + msg.ToString());
|
|
}
|
|
if (frame.Equals("url"))
|
|
{
|
|
Application.OpenURL(msg);
|
|
return;
|
|
}
|
|
if (g != null)
|
|
{
|
|
if (g.name.StartsWith("Stat_Box_"))
|
|
{
|
|
TMP_Text statText = g.transform.GetChild(2).GetComponent<TMP_Text>();
|
|
statText.SetText(msg);
|
|
}
|
|
else if (g.TryGetComponent(out Text t))
|
|
{
|
|
t.text = msg;
|
|
}
|
|
else if (g.TryGetComponent(out TMP_Text tmp))
|
|
{
|
|
tmp.SetText(msg);
|
|
}
|
|
else if (g.TryGetComponent(out Image i))
|
|
{
|
|
i.sprite = OnDemandLoader.Load<Sprite>("Sprites/" + msg);
|
|
}
|
|
}
|
|
lastPacketId = MessageID.SendFrame;
|
|
break;
|
|
}
|
|
|
|
case MessageID.NPCAnimation:
|
|
{
|
|
int npcId = p.readShort();
|
|
string anim = p.readString();
|
|
npcManager?.AnimationUpdate(npcId, anim);
|
|
lastPacketId = MessageID.NPCAnimation;
|
|
break;
|
|
}
|
|
|
|
case MessageID.PlayerProjectile:
|
|
{
|
|
int entity = p.readInt();
|
|
float dx = p.readFloat();
|
|
float dy = p.readFloat();
|
|
float dz = p.readFloat();
|
|
string projectile = p.readString();
|
|
//Debug.Log("projectile request: " + projectile + " entity id " + entity);
|
|
playerManager?.ProcessProjectileUpdate(entity, new Vector3(dx, dy, dz), projectile);
|
|
lastPacketId = MessageID.PlayerProjectile;
|
|
break;
|
|
}
|
|
|
|
case MessageID.AppearanceUpdate:
|
|
{
|
|
int entity = p.readInt();
|
|
string skin = p.readString();
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
equiptmentIDs[i] = p.readInt();
|
|
}
|
|
|
|
playerManager.ProcessAppearenceUpdate(entity, skin, equiptmentIDs[0]);
|
|
if (entity == -1)
|
|
{
|
|
InventoryManager.Instance.updateEquipment(equiptmentIDs, new int[] { 1, 1, 1, 1, 1, 1 });
|
|
}
|
|
lastPacketId = MessageID.AppearanceUpdate;
|
|
break;
|
|
}
|
|
|
|
case MessageID.Sound:
|
|
{
|
|
string sound = p.readLongString();
|
|
bool is3d = p.readByte() == 1;
|
|
|
|
if (is3d)
|
|
{
|
|
float x = p.readFloat();
|
|
float y = p.readFloat();
|
|
float z = p.readFloat();
|
|
AudioManager.Instance.playSound3D(sound, new Vector3(x, y, z));
|
|
}
|
|
else
|
|
{
|
|
AudioManager.Instance.playSound(sound);
|
|
}
|
|
lastPacketId = MessageID.Sound;
|
|
break;
|
|
}
|
|
|
|
case MessageID.Graphics:
|
|
{
|
|
string name = p.readLongString();
|
|
float x = p.readFloat();
|
|
float y = p.readFloat();
|
|
float z = p.readFloat();
|
|
int parent = p.readInt();
|
|
GameObject g = OnDemandLoader.Load<GameObject>("gfx/" + name);
|
|
if (g != null)
|
|
{
|
|
GameObject instance = Instantiate(g);
|
|
instance.transform.position = new Vector3(x, y, z);
|
|
|
|
if (instance.transform.TryGetComponent(out FractionalCryptoDrop cryptoDrop))
|
|
{
|
|
cryptoDrop.targetPlayer = Player.Instance.PlayerEntity;
|
|
DroppedCryptoInInstance.Add(cryptoDrop);
|
|
}
|
|
|
|
if (parent != -1)
|
|
{
|
|
if (parent < 3194)
|
|
{
|
|
PlayerEntity playerEntity = PlayerManager.Instance.GetPlayer(parent);
|
|
if (playerEntity != null)
|
|
{
|
|
instance.transform.parent = playerEntity.transform;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
lastPacketId = MessageID.Graphics;
|
|
break;
|
|
}
|
|
|
|
case MessageID.MainPlayerUpdate:
|
|
{
|
|
float reloadTime = p.readFloat();
|
|
float reloadSpeedMultiplier = p.readFloat();
|
|
int rocketAmmo = p.readByte();
|
|
int ammo = p.readInt();
|
|
int health = p.readInt();
|
|
string animation = p.readString();
|
|
int score = p.readInt();
|
|
int damage = p.readInt();
|
|
Player.Instance.mainPlayerUpdate(reloadTime, reloadSpeedMultiplier, rocketAmmo, ammo, health,
|
|
animation, score, damage);
|
|
lastPacketId = MessageID.MainPlayerUpdate;
|
|
break;
|
|
}
|
|
|
|
case MessageID.UpdateInventory:
|
|
{
|
|
for (int i = 0; i < 24; i++)
|
|
{
|
|
inventoryIDs[i] = p.readInt();
|
|
}
|
|
|
|
for (int i = 0; i < 24; i++)
|
|
{
|
|
inventoryAmounts[i] = p.readInt();
|
|
}
|
|
|
|
InventoryManager.Instance.updateInventory(inventoryIDs, inventoryAmounts);
|
|
lastPacketId = MessageID.UpdateInventory;
|
|
break;
|
|
}
|
|
|
|
case MessageID.UpdateGroundItems:
|
|
{
|
|
int count = p.readInt();
|
|
int[] itemIds = new int[count];
|
|
int[] x = new int[count];
|
|
int[] z = new int[count];
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
itemIds[i] = p.readInt();
|
|
x[i] = p.readInt();
|
|
z[i] = p.readInt();
|
|
}
|
|
|
|
GroundItemManager.Instance.UpdateGroundItems(count, itemIds, x, z);
|
|
lastPacketId = MessageID.UpdateGroundItems;
|
|
break;
|
|
}
|
|
|
|
case MessageID.UpdateRemotePlayer:
|
|
{
|
|
int entityId = p.readInt();
|
|
float x = p.readFloat();
|
|
float y = p.readFloat();
|
|
float z = p.readFloat();
|
|
float rotationY = p.readFloat();
|
|
float lookAngle = p.readFloat();
|
|
int hitPoints = p.readInt();
|
|
string name = p.readString();
|
|
float animX = p.readFloat();
|
|
float animZ = p.readFloat();
|
|
float magnitude = p.readFloat();
|
|
int flags = p.readByte();
|
|
string forceAnim = p.readString();
|
|
string voiceID = p.readString();
|
|
playerManager.ProcessUpdate(entityId, x, y, z, rotationY, lookAngle, hitPoints, name, animX, animZ,
|
|
magnitude, flags, forceAnim, voiceID);
|
|
lastPacketId = MessageID.UpdateRemotePlayer;
|
|
break;
|
|
}
|
|
|
|
|
|
case MessageID.EnemyProjectile:
|
|
{
|
|
int entity = p.readInt();
|
|
int targetPlayerId = p.readInt();
|
|
string projectile = p.readString();
|
|
npcManager?.ProcessProjectileUpdate(entity, targetPlayerId, projectile);
|
|
lastPacketId = MessageID.EnemyProjectile;
|
|
break;
|
|
}
|
|
|
|
case MessageID.RenderSettings:
|
|
{
|
|
float ambientLightIntensity = p.readFloat();
|
|
float ar = p.readFloat();
|
|
float ag = p.readFloat();
|
|
float ab = p.readFloat();
|
|
float directionalLightIntensity = p.readFloat();
|
|
float dr = p.readFloat();
|
|
float dg = p.readFloat();
|
|
float db = p.readFloat();
|
|
float fogDensity = p.readFloat();
|
|
float fr = p.readFloat();
|
|
float fg = p.readFloat();
|
|
float fb = p.readFloat();
|
|
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
|
|
RenderSettings.ambientSkyColor = new Color(ar, ag, ab);
|
|
RenderSettings.fog = true;
|
|
|
|
// RenderSettings.ambientIntensity = ambientLightIntensity;
|
|
//RenderSettings.ambientLight = new Color(ar, ag, ab);
|
|
Light light = GameObject.Find("Light")?.GetComponent<Light>();
|
|
if (light)
|
|
{
|
|
light.intensity = directionalLightIntensity;
|
|
light.color = new Color(dr, dg, db);
|
|
}
|
|
|
|
RenderSettings.fogDensity = fogDensity;
|
|
RenderSettings.fogColor = new Color(fr, fg, fb);
|
|
|
|
|
|
|
|
Camera.main.backgroundColor = RenderSettings.fogColor;
|
|
lastPacketId = MessageID.RenderSettings;
|
|
break;
|
|
}
|
|
|
|
case MessageID.Knockback:
|
|
{
|
|
float angle = p.readFloat();
|
|
float knockbackForceMultipler = p.readFloat();
|
|
Player.Instance.knockbackTimer = Time.time;
|
|
Player.Instance.knockbackAngle = angle;
|
|
|
|
Player.Instance.knockbackForceMultiplier = knockbackForceMultipler;
|
|
lastPacketId = MessageID.Knockback;
|
|
break;
|
|
}
|
|
|
|
case MessageID.PlayerPing:
|
|
{
|
|
float x = p.readFloat();
|
|
float y = p.readFloat();
|
|
float z = p.readFloat();
|
|
string parent = p.readString();
|
|
GameObject marker = Instantiate(OnDemandLoader.Load<GameObject>("gfx/marker"));
|
|
GameObject parentObject = GameObject.Find(parent);
|
|
|
|
if (parentObject != null)
|
|
{
|
|
// Debug.Log($"parent object {parent}");
|
|
marker.transform.position = parentObject.transform.position + new Vector3(0, 2.0f, 0);
|
|
marker.transform.parent = parentObject.transform;
|
|
}
|
|
else
|
|
{
|
|
marker.transform.position = new Vector3(x, y, z);
|
|
}
|
|
lastPacketId = MessageID.PlayerPing;
|
|
break;
|
|
}
|
|
|
|
case MessageID.ForceRemoveEntity:
|
|
{
|
|
int entityId = p.readShort();
|
|
|
|
if (entityId >= 3194)
|
|
{
|
|
NPCManager.Instance.RemoveNPCWithID(entityId - 3194);
|
|
}
|
|
else
|
|
{
|
|
PlayerManager.Instance.RemovePlayerWithID(entityId);
|
|
}
|
|
lastPacketId = MessageID.ForceRemoveEntity;
|
|
break;
|
|
}
|
|
|
|
case MessageID.SpectatePlayer:
|
|
int playerId = p.readInt();
|
|
Player.Instance.spectatePlayer(playerId);
|
|
lastPacketId = MessageID.SpectatePlayer;
|
|
break;
|
|
case MessageID.DeathCamera:
|
|
{
|
|
int show = p.readByte();
|
|
if (show == 1)
|
|
{
|
|
Player.Instance.BeginDeathCamera();
|
|
}
|
|
else
|
|
{
|
|
Player.Instance.CancelDeathCamera();
|
|
}
|
|
lastPacketId = MessageID.DeathCamera;
|
|
break;
|
|
}
|
|
|
|
case MessageID.CameraShake:
|
|
{
|
|
float mag = p.readFloat();
|
|
float roughness = p.readFloat();
|
|
float fadeIn = p.readFloat();
|
|
float fadeOut = p.readFloat();
|
|
EZCameraShake.CameraShaker.Instance.ShakeOnce(mag, roughness, fadeIn, fadeOut);
|
|
lastPacketId = MessageID.CameraShake;
|
|
break;
|
|
}
|
|
case MessageID.FanFair:
|
|
{
|
|
string message = p.readString();
|
|
Debug.Log(message);
|
|
UIManager.Instance.fanfairMessageQueue.Enqueue(message);
|
|
lastPacketId = MessageID.FanFair;
|
|
break;
|
|
}
|
|
|
|
case MessageID.BloodSplat:
|
|
{
|
|
float rotation = p.readFloat();
|
|
int npcID = p.readInt();
|
|
int npcType = p.readInt();
|
|
int scale = p.readInt();
|
|
int hitShield = p.readInt();
|
|
string effectName = "vfx_Blood";
|
|
Vector4 bloodColour = RedBloodColour * colourIntensityModifier;
|
|
;
|
|
switch (npcType)
|
|
{
|
|
case 11:
|
|
case 10:
|
|
case 8:
|
|
bloodColour = GreenBloodColour * colourIntensityModifier;
|
|
break;
|
|
case 3:
|
|
effectName = hitShield == 1 ? "HitEffect_Sparks" : "vfx_Blood";
|
|
bloodColour = hitShield == 1 ? GreenBloodColour : RedBloodColour * colourIntensityModifier;
|
|
break;
|
|
}
|
|
|
|
Vector3 spawnPosition = GetNPCManager().GetNPC(npcID).transform.position;
|
|
spawnPosition.y += 2.0f;
|
|
|
|
GameObject bloodObject =
|
|
NetworkPooler.Instance.PooledInstantiate(effectName, spawnPosition, Quaternion.identity);
|
|
bloodObject.transform.forward = new Vector3(0, 0, rotation * -1.0f);
|
|
|
|
if (bloodObject == null) return;
|
|
|
|
VisualEffect bloodEffect = bloodObject.GetComponentInChildren<VisualEffect>();
|
|
|
|
if (bloodEffect != null)
|
|
{
|
|
float calculatedDamage = scale > 0f && scale < 250f ? scale : 40f;
|
|
bloodEffect.SetVector4(bloodID, bloodColour);
|
|
bloodEffect.SetFloat("Rate", calculatedDamage);
|
|
}
|
|
|
|
|
|
//blood needs 5 seconds. sparks only need 1 second.
|
|
NetworkPooler.Instance.PooledDestroy(effectName, bloodObject, bloodEffect == null ? 1.0f : 5.0f);
|
|
lastPacketId = MessageID.BloodSplat;
|
|
break;
|
|
}
|
|
|
|
case MessageID.UpdateBankVault:
|
|
{
|
|
int[] ids = new int[25];
|
|
int[] amounts = new int[25];
|
|
for (int i = 0; i < 25; i++)
|
|
{
|
|
ids[i] = p.readInt();
|
|
}
|
|
|
|
for (int i = 0; i < 25; i++)
|
|
{
|
|
amounts[i] = p.readInt();
|
|
}
|
|
|
|
InventoryManager.Instance.updateBankVault(ids, amounts);
|
|
lastPacketId = MessageID.UpdateBankVault;
|
|
break;
|
|
}
|
|
|
|
|
|
case MessageID.CreateGameRoom:
|
|
{
|
|
UIManager.Instance.DeleteGameRoomButtons();
|
|
int roomCount = p.readInt();
|
|
|
|
for (int i = 0; i < roomCount; i++)
|
|
{
|
|
int gameType = p.readInt();
|
|
int players = p.readInt();
|
|
string owner = p.readString();
|
|
|
|
Transform gameTypeParent = null;
|
|
|
|
if (gameType == 0)
|
|
{
|
|
gameTypeParent = UIManager.Instance.DuoInstanceParent;
|
|
}
|
|
else if (gameType == 1)
|
|
{
|
|
gameTypeParent = UIManager.Instance.SquadInstanceParent;
|
|
}
|
|
|
|
GameRoomButton roomButtonPrefab =
|
|
OnDemandLoader.Load<GameRoomButton>("Prefabs/interfaces/GameInstance_Button");
|
|
GameRoomButton instantiatedRoomButton = Instantiate(roomButtonPrefab, Vector3.zero,
|
|
Quaternion.identity, gameTypeParent);
|
|
instantiatedRoomButton.AssignButtonInfo(owner, players, gameType == 0 ? 2 : 4);
|
|
}
|
|
lastPacketId = MessageID.CreateGameRoom;
|
|
break;
|
|
}
|
|
|
|
case MessageID.EnterLobby:
|
|
{
|
|
if (PortalVFX_Object != null)
|
|
{
|
|
PortalVFX_Object.SetActive(false);
|
|
//PortalVFX_Object.SetActive(true);
|
|
}
|
|
|
|
Player.Instance.InSoloInstance = false;
|
|
Player.Instance.updatePlayer = true;
|
|
UIManager.Instance.SetUIForJoiningLobby();
|
|
|
|
foreach (FractionalCryptoDrop cryptoDrop in DroppedCryptoInInstance)
|
|
{
|
|
Destroy(cryptoDrop.gameObject);
|
|
}
|
|
|
|
DroppedCryptoInInstance.Clear();
|
|
lastPacketId = MessageID.EnterLobby;
|
|
break;
|
|
}
|
|
|
|
case MessageID.CharacterSelectionStats:
|
|
{
|
|
string characterName = p.readString();
|
|
float maxHealth = p.readFloat();
|
|
float reloadSpeedMultiplier = p.readFloat();
|
|
float damageReduction = p.readFloat();
|
|
float damageReductionScale = 1f + (1f - damageReduction);
|
|
float walkSpeed = p.readFloat();
|
|
float runSpeed = p.readFloat();
|
|
float movementMultiplier = p.readFloat();
|
|
float damageMultiplier = p.readFloat();
|
|
|
|
PreGameManager characterStats = PreGameManager.Instance;
|
|
Player localPlayer = Player.Instance;
|
|
|
|
Debug.Log( $"{characterName}");
|
|
characterStats.SetCharacterName(characterName);
|
|
characterStats.SetMaxHealthStat(maxHealth);
|
|
characterStats.SetReloadSpeedStat(reloadSpeedMultiplier);
|
|
characterStats.SetDamageReductionStat(damageReductionScale);
|
|
characterStats.SetMoveSpeedStat(movementMultiplier, runSpeed);
|
|
characterStats.SetDamageStat(damageMultiplier);
|
|
|
|
localPlayer.playerController.WalkSpeed = walkSpeed;
|
|
localPlayer.playerController.RunSpeed = runSpeed;
|
|
localPlayer.playerController.MaxRunSpeed = runSpeed;
|
|
localPlayer.playerController.MaxWalkSpeed = walkSpeed;
|
|
localPlayer.MaxHitPoints = (int)maxHealth;
|
|
lastPacketId = MessageID.CharacterSelectionStats;
|
|
break;
|
|
}
|
|
|
|
case MessageID.VictoryScreenTextColour:
|
|
{
|
|
int colourIndex = p.readInt();
|
|
UIManager.Instance.VictoryText.color = colourIndex == 0 ? Color.red : Color.green;
|
|
UIManager.Instance.victoryScreenAudioClip = colourIndex == 0 ? "SW_Defeat" : "SW_Victory";
|
|
lastPacketId = MessageID.VictoryScreenTextColour;
|
|
break;
|
|
}
|
|
|
|
case MessageID.UnderWaterTimer:
|
|
{
|
|
int maxDuration = p.readInt();
|
|
UIManager.Instance.UnderWaterSystem.gameObject.SetActive(true);
|
|
UIManager.Instance.UnderWaterSystem.MaxDuration = maxDuration;
|
|
lastPacketId = MessageID.UnderWaterTimer;
|
|
break;
|
|
}
|
|
|
|
case MessageID.InitNPC:
|
|
{
|
|
int entityId = p.readInt();
|
|
int weaponId = p.readInt();
|
|
float moveSpeed = p.readFloat();
|
|
float scale = p.readFloat();
|
|
float h = p.readFloat();
|
|
float s = p.readFloat();
|
|
float v = p.readFloat();
|
|
NPCManager.Instance.InitializeNpc(entityId, weaponId, moveSpeed, scale, h, s, v);
|
|
lastPacketId = MessageID.InitNPC;
|
|
break;
|
|
}
|
|
|
|
case MessageID.VoiceChat:
|
|
{
|
|
int joining = p.readInt(); //1 = join, 0 leave
|
|
if (joining == 1)
|
|
{
|
|
string channelName = p.readString();
|
|
try
|
|
{
|
|
//VOIPClient.Connect(VOIPClient.Host, VOIPClient.Port, VOIPClient.noDelay);
|
|
// GetReceiptTrigger().RoomName = channelName;
|
|
//GetBroadcastTrigger().RoomName = channelName;
|
|
//myVoiceRoom = channelName;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e.StackTrace);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// VOIPDisconnect();
|
|
// myVoiceRoom = "";
|
|
}
|
|
lastPacketId = MessageID.VoiceChat;
|
|
break;
|
|
}
|
|
|
|
case MessageID.WeaponReloadSound:
|
|
{
|
|
string sound = p.readLongString();
|
|
float reloadSpeed = p.readFloat();
|
|
AudioManager.Instance.playSound(sound, reloadSpeed);
|
|
lastPacketId = MessageID.WeaponReloadSound;
|
|
break;
|
|
}
|
|
|
|
case MessageID.InGameInstance:
|
|
{
|
|
int joined = p.readInt();
|
|
bool isInGameInstance = joined == 1;
|
|
UIManager.Instance.InGameInstance(isInGameInstance);
|
|
lastPacketId = MessageID.InGameInstance;
|
|
break;
|
|
}
|
|
case MessageID.GameInstanceStats:
|
|
{
|
|
InGameStatsController inGameStatsController = UIManager.Instance.InGameStatsController;
|
|
foreach (Transform stat in inGameStatsController.PlayerStatsParent.transform)
|
|
{
|
|
Destroy(stat.gameObject);
|
|
}
|
|
|
|
int playersInInstance = p.readInt();
|
|
int currentWave = p.readInt();
|
|
int livesRemaining = p.readInt();
|
|
|
|
inGameStatsController.SetData(livesRemaining, currentWave);
|
|
for (int i = 0; i < playersInInstance; i++)
|
|
{
|
|
string playerName = p.readString();
|
|
int playerDamage = p.readInt();
|
|
int playerHeadshots = p.readInt();
|
|
int playerKills = p.readInt();
|
|
|
|
InGameStats stats = Instantiate(inGameStatsController.InGameStatsPrefab,
|
|
inGameStatsController.PlayerStatsParent);
|
|
stats.SetData(playerName, playerDamage, playerHeadshots, playerKills);
|
|
}
|
|
lastPacketId = MessageID.GameInstanceStats;
|
|
break;
|
|
}
|
|
|
|
case MessageID.NoClip:
|
|
{
|
|
int noClip = p.readInt();
|
|
bool isNoClip = noClip == 1;
|
|
NoClipped = isNoClip;
|
|
if (isNoClip)
|
|
{
|
|
Transform firstPersonPlayerCam = Player.Instance.GetPlayerFirstPersonCamera().transform;
|
|
currentNoClipCam = Instantiate(noClipCameraPrefab, firstPersonPlayerCam.position,
|
|
firstPersonPlayerCam.transform.rotation);
|
|
}
|
|
else
|
|
{
|
|
if (currentNoClipCam != null)
|
|
{
|
|
Destroy(currentNoClipCam.gameObject);
|
|
}
|
|
}
|
|
|
|
CrosshairManager.Instance.EnableCrosshair(!isNoClip);
|
|
var playerHUD = UIManager.Instance.getInterface<GameObject>("PlayerCanvas");
|
|
var chatBox = UIManager.Instance.getInterface<GameObject>("ChatBox");
|
|
var quickInv = UIManager.Instance.getInterface<GameObject>("QuickInventoryAccess");
|
|
playerHUD.SetActive(!isNoClip);
|
|
//chatBox.SetActive(!isNoClip);
|
|
quickInv.SetActive(!isNoClip);
|
|
lastPacketId = MessageID.NoClip;
|
|
break;
|
|
}
|
|
case MessageID.SellListingExchange:
|
|
{
|
|
int size = p.readInt();
|
|
int[] itemIDs = new int[size];
|
|
int[] amounts = new int[size];
|
|
int[] prices = new int[size];
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
itemIDs[i] = p.readInt();
|
|
amounts[i] = p.readInt();
|
|
prices[i] = p.readInt();
|
|
}
|
|
UIManager.Instance.WeaponExchangeController.UpdateSellItems(itemIDs, amounts, prices);
|
|
lastPacketId = MessageID.SellListingExchange;
|
|
break;
|
|
}
|
|
case MessageID.BuyListingExchange:
|
|
{
|
|
int size = p.readInt();
|
|
int[] itemIDs = new int[size];
|
|
int[] amounts = new int[size];
|
|
int[] prices = new int[size];
|
|
string[] sellerNames = new string[size];
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
itemIDs[i] = p.readInt();
|
|
amounts[i] = p.readInt();
|
|
prices[i] = p.readInt();
|
|
sellerNames[i] = p.readString();
|
|
}
|
|
UIManager.Instance.WeaponExchangeController.UpdateBuyItems(itemIDs, amounts, prices, sellerNames);
|
|
lastPacketId = MessageID.BuyListingExchange;
|
|
break;
|
|
}
|
|
case MessageID.LoadScene:
|
|
{
|
|
string sceneName = p.readString();
|
|
|
|
/*string[] unloadScenes = new string[] { "sw_large", "sw_simple" };
|
|
|
|
for (int i = 0; i < unloadScenes.Length; i++) {
|
|
if (SceneManager.GetSceneByName(unloadScenes[i]).isLoaded)
|
|
SceneManager.UnloadSceneAsync(unloadScenes[i]);
|
|
}
|
|
|
|
SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
|
|
Resources.UnloadUnusedAssets();*/
|
|
|
|
}
|
|
break;
|
|
case MessageID.OpenPrizeChest:
|
|
{
|
|
int[] items = new int[40];
|
|
for (int i = 0; i < 40; i++)
|
|
{
|
|
items[i] = p.readInt();
|
|
}
|
|
PrizeChest.Instance.openChest(items);
|
|
lastPacketId = MessageID.OpenPrizeChest;
|
|
}
|
|
break;
|
|
case MessageID.SetButtonEnabled:
|
|
{
|
|
string buttonName = p.readString();
|
|
bool enabled = p.readInt() == 1;
|
|
|
|
//print the data
|
|
Debug.Log("button name: " + buttonName + " enabled: " + enabled);
|
|
GameObject g = GameObject.Find(buttonName);
|
|
if (g != null)
|
|
{
|
|
if (g.TryGetComponent(out Image i))
|
|
{
|
|
i.color = enabled ? new Color(0.227f, 0.227f, 0.2274f) : new Color(0.5f, 0.0707f, 0.0707f);
|
|
}
|
|
}
|
|
|
|
lastPacketId = MessageID.SetButtonEnabled;
|
|
}
|
|
break;
|
|
case MessageID.ForgingData:
|
|
{
|
|
int siegePassTier = p.readInt();
|
|
ForgeController.siegePassTier = siegePassTier;
|
|
for (int i = 0; i < 7; i++)
|
|
{
|
|
ForgeController.oreCounts[i] = p.readInt();
|
|
GameObject g = GameObject.Find("ore_count_" + i);
|
|
//get the textmesh component if it exists
|
|
if (g != null)
|
|
{
|
|
if (g.TryGetComponent(out TextMeshProUGUI t))
|
|
{
|
|
t.text = ForgeController.oreCounts[i].ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public String getMacAddress()
|
|
{
|
|
string macAddresses = string.Empty;
|
|
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
|
{
|
|
if (nic.OperationalStatus == OperationalStatus.Up)
|
|
{
|
|
macAddresses += nic.GetPhysicalAddress().ToString();
|
|
break;
|
|
}
|
|
}
|
|
return macAddresses;
|
|
}
|
|
|
|
private void PopSpeechBubble(int npcId, int playerId, string message)
|
|
{
|
|
ChatBubble chatbubble = FindSpeechBubble(npcId, playerId);
|
|
if (chatbubble != null)
|
|
{
|
|
chatbubble.DisplayMessage(message);
|
|
}
|
|
}
|
|
|
|
private ChatBubble FindSpeechBubble(int npcId, int playerId)
|
|
{
|
|
if (npcId == playerId)
|
|
{
|
|
return Player.Instance.ChatBubble;
|
|
}
|
|
else
|
|
{
|
|
var allEntityId = FindObjectsOfType<PlayerEntity>();
|
|
for (int i = 0; i < allEntityId.Length; i++)
|
|
{
|
|
if (allEntityId[i].GetID() == npcId)
|
|
{
|
|
return allEntityId[i].ChatBubble;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private GameObject CreatePlayer(int id, string playerName)
|
|
{
|
|
GameObject playerPrefab = OnDemandLoader.Load<GameObject>("Prefabs/Player/Player");
|
|
GameObject playerObject = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);
|
|
Player player = playerObject.AddComponent<Player>();
|
|
if (id == -1)
|
|
{
|
|
player.PlayerEntity.volumeMain = PostProcessingMain;
|
|
player.PlayerEntity.volumeMashroom = PostProcessingMashroom;
|
|
player.PlayerEntity.skyMain = SkyMain;
|
|
player.PlayerEntity.skyMashroom = SkyMashroom;
|
|
}
|
|
|
|
//move player to the world scene.
|
|
//we are doing this because Occlusion culling is baked on the world map. player must be in this scene to use it.
|
|
// SceneManager.MoveGameObjectToScene(playerObject, SceneManager.GetSceneByName("sw_simple"));
|
|
//SceneManager.SetActiveScene(SceneManager.GetSceneByName("sw_simple"));
|
|
|
|
player.setId(id);
|
|
player.setPlayerName(playerName);
|
|
playerObject.name = "Player_" + playerName + "_id_" + id;
|
|
|
|
return playerObject;
|
|
}
|
|
|
|
public void onLogin()
|
|
{
|
|
UIManager.Instance.waveTextController.ResetWaveText();
|
|
}
|
|
|
|
|
|
public void Onlogout()
|
|
{
|
|
if (PlayerPrefs.GetInt("LoginMusic") == 0)
|
|
AudioManager.Instance.playSong("main_theme", true);
|
|
else
|
|
AudioManager.Instance.playSong("", true);
|
|
|
|
LocalPlayerLoggedIn = false;
|
|
}
|
|
|
|
void OnApplicationQuit()
|
|
{
|
|
if (!GISocket.Instance.closed)
|
|
{
|
|
PacketManager.sendLogoutPacket();
|
|
GISocket.Instance.close();
|
|
}
|
|
}
|
|
|
|
public void pushOutStreamCR()
|
|
{
|
|
|
|
StartCoroutine(PushOutStream());
|
|
|
|
|
|
|
|
}
|
|
|
|
//write a coroutine to wait 1 second then push the outstream
|
|
public IEnumerator PushOutStream()
|
|
{
|
|
|
|
while (!LocalPlayerLoggedIn)
|
|
{
|
|
yield return new WaitForSeconds(1);
|
|
PacketManager.sendLoginRequest(myUsername, myPassword);
|
|
}
|
|
//exit the coroutine
|
|
yield break;
|
|
}
|
|
|
|
[System.NonSerialized] public GameObject mainPlayer;
|
|
[System.NonSerialized] public int playerId;
|
|
[System.NonSerialized] public int playerRights;
|
|
private int pktSize = -1;
|
|
} |