// 21013 private void RecvAuthentication_Denied(int packet_id, PacketReader pr) { int errCode = pr.ReadInt8(); string reason = pr.ReadString(); DGTRemote.GetInstance().ReceiveAuthenticationDeinied(reason); }
// 21011 private void RecvRegister_Failed(int packet_id, PacketReader pr) { int errCode = pr.ReadInt8(); string reason = pr.ReadString(); DGTRemote.GetInstance().ReceiveRegisterFailed(reason); }
private void OnTriggerStay2D(Collider2D col) { if (col.CompareTag("ItemDrop")) { //CollectItemToInventory(col.gameObject); DGTRemote.GetInstance().RequestGetOnlineItem(col.GetComponent <Item>().GetOnlineID(), col.GetComponent <Item>().GetItemId()); } }
void UpdatePosition() { position_x = player.gameObject.transform.position.x; position_y = player.gameObject.transform.position.y; if (ControlFreak2.CF2Input.GetAxis("Horizontal") != 0.00f || ControlFreak2.CF2Input.GetAxis("Vertical") != 0.00f) { DGTRemote.GetInstance().RequestMovementPlayer(position_x, position_y); } }
// 20000 private void RecvError(int packet_id, PacketReader pr) { DGTRemote.GetInstance().Logout(); Popup.Instance.showPopup("Disconnected from server", pr.ReadString()); /*Popup.Instance.btnOK.onClick.AddListener(() => { * DGTRemote.GetInstance().Logout(); * });*/ }
// 22204 private void RecvOnlineMonsterReward(int packet_id, PacketReader pr) { int monsterID = pr.ReadUInt32(); int expReceive = pr.ReadUInt32(); bool isKiller = pr.ReadInt8() == 0 ? false : true; //Debug.Log("Receive reward from killing monster [" + monsterID + "] EXP : " + expReceive +" killer : " + isKiller); DGTRemote.GetInstance().ReceiveOnlineMonsterReward(expReceive, isKiller, monsterID); }
public void CheckDataBeforeSending() { if (this.fbName != null && this.fbDisplay != null) { Popup.Instance.HideLoading(); Debug.Log("Data facebook ready"); DGTRemote.GetInstance().RequestAuthenticationFacebook(fbId, fbToken); } }
void OnApplicationQuit() { if (this.inWorld) { Debug.Log("Exit world"); ExitOnlineWorld(); } Debug.Log("Disconnect Server"); DGTRemote.GetInstance().Disconnect(); //OnApplicationQuit }
public GameObject SpawnPlayer(float posx, float posy) { if (DGTRemote.GetInstance().Connected()) { GameObject player = Instantiate(Player, new Vector3(posx, posy, 1), Quaternion.identity); count++; return(player); } return(null); }
void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //Finished loading scene SceneManager.sceneLoaded -= OnSceneLoaded; LoadingScreen.Instance.CloseLoading(); PlayerStatus.Instance.gameObject.GetComponent <Rigidbody2D>().simulated = true; PlayerStatus.Instance.onStatusChangeHandler += () => { //if status change then send to server DGTRemote.GetInstance().RequestSendPlayerStatusData(PlayerStatus.Instance); }; }
public IEnumerator PingTest() { int i = 0; while (true) { DGTRemote.GetInstance().TryPing(i); i++; yield return(new WaitForSeconds(3)); } }
public void UseItem(int index) { Debug.Log("Use item in index : " + index); if (!Item.ReferenceEquals(slots[index], null)) { Item oldEquipment = null; if (slots[index].IsEquipable()) { Item.ItemEquipment equipmentData = slots[index].GetItemEquipment(); PlayerStatus ps = PlayerStatus.Instance; if (equipmentData.head) { oldEquipment = ItemManager.GetItemEquipmentBodyByEquipmentValue(ps.head, ps.gender, ps.job); ps.head = equipmentData.equipmentValue; DGTRemote.GetInstance().RequestChangeEquipment(1, ps.head); } else if (equipmentData.body) { oldEquipment = ItemManager.GetItemEquipmentBodyByEquipmentValue(ps.body, ps.gender, ps.job); ps.body = equipmentData.equipmentValue; DGTRemote.GetInstance().RequestChangeEquipment(2, ps.body); } else if (equipmentData.weapon) { oldEquipment = ItemManager.GetItemEquipmentBodyByEquipmentValue(ps.weapon, ps.gender, ps.job); ps.weapon = equipmentData.equipmentValue; DGTRemote.GetInstance().RequestChangeEquipment(3, ps.weapon); } } else { Item.ItemEffect effect = slots[index].GetItemEffect(); NotificationSystem.Instance.AddNotification("คุณได้ใช้ไอเท็ม " + slots[index].GetItemName()); if (effect.GetEffectType() == (int)Item.ItemEffect.EffectId.POSITIVE) { PlayerStatus.Instance.AddHP(effect.GetEffectValue()); } } // remove item from inventory if (slots[index].IsStackable()) { DecreaseItemFromInventory(index); } else { DeleteItemFromInventory(index); } if (oldEquipment) { CollectItemToInventory(oldEquipment); } } }
private void warpPlayerToTargetScene() { SceneManager.LoadScene(sceneName, LoadSceneMode.Single); player.GetComponent <PlayerStatus>().currentMap = sceneName; player.transform.position = positionOnNextScene; OnlinePlayerController.Instance.ClearOnlinePlayer(); OnlineMonsterController.Instance.ClearOnlineMonster(); OnlineItemControl.Instance.ClearOnlineItem(); DGTRemote.GetInstance().RequestPlayerChangeMap(sceneName, positionOnNextScene); NotificationSystem.Instance.ClearNotification(); fs.onFadeOutCompleteHandler -= warpPlayerToTargetScene; }
// 22024 private void RecvMultiplayerControl(int packet_id, PacketReader pr) { Debug.Log("Receive Online Player Control"); int dataNumber = pr.ReadInt16(); for (int i = 0; i < dataNumber; i++) { DGTRemote.GetInstance().ReceiveOnlinePlayerData(pr.ReadUInt32(), new Vector2(pr.ReadFloat(), pr.ReadFloat()), //read Position x,y new Vector2(pr.ReadFloat(), pr.ReadFloat()), //read Velocity x,y pr.ReadFloat(), pr.ReadUInt8()); //read scaleX } }
// 22202 private void RecvOnlineMonsterControl(int packet_id, PacketReader pr) { Debug.Log("Receive Online Monster Control"); int dataAmount = pr.ReadInt8(); for (int i = 0; i < dataAmount; i++) { int ID = pr.ReadUInt32(); int HP = pr.ReadUInt32(); Vector2 position = new Vector2(pr.ReadFloat(), pr.ReadFloat()); DGTRemote.GetInstance().ReceiveOnlineMonsterControl(ID, HP, position); } }
//Overload public void DecreaseItemFromInventory(int index, int amount) { slots[index].DecreaseStack(amount); if (slots[index].GetItemStack() <= 0) { DeleteItemFromInventory(index); } else { DGTRemote.GetInstance().RequestInventoryDecreaseItem(slots[index].GetItemId(), amount); UpdateSlotsWindows(); } }
public void TrackingMonster(int monsterID) { if (monsterID == this.targetID) { currentTotal += 1; if (type != 3) { DGTRemote.GetInstance().RequestSendUpdateQuest(questID, currentTotal); } NotificationSystem.Instance.AddNotification("[เควส] กำจัด " + targetName + " " + currentTotal + "/" + total); Debug.Log("Monster kill : " + currentTotal + "/" + total); CheckDone(); } }
// 21012 private void RecvAuthentication_Grant(int packet_id, PacketReader pr) { Debug.Log("RecvAuthentication_Grant"); DGTRemote.GetInstance().ReceiveAuthenticationGrant(); /*int uid = pr.ReadUInt32(); * int color = pr.ReadUInt8(); * int highestLevel = pr.ReadUInt16(); * int highestCheckpoint= pr.ReadUInt16(); * GameObject player = GameObject.FindGameObjectWithTag("Player"); * Debug.Log("Get Data From Server- UID : " + uid + " Color :" + color);*/ /* for work when start gameplay * DGTRemote.GetInstance().RequestEnterWorld(player.transform.position, dinoColor); * DGTRemote.GetInstance().StartSendingData();*/ }
// 22023 private void RecvMultiplayerConnect(int packet_id, PacketReader pr) { int uid = pr.ReadUInt32(); string name = pr.ReadString(); Vector2 position = new Vector2(pr.ReadFloat(), pr.ReadFloat()); string gender = pr.ReadString(); string job = pr.ReadString(); int HP = pr.ReadUInt32(); int SP = pr.ReadUInt32(); int level = pr.ReadUInt32(); string equipmentHead = pr.ReadString(); string equipmentBody = pr.ReadString(); string equipmentWeapon = pr.ReadString(); DGTRemote.GetInstance().ReceiveOnlinePlayerConnect(uid, name, position, gender, job, HP, SP, level, equipmentHead, equipmentBody, equipmentWeapon); }
// 21017 private void RecvCharacterCreateSuccess(int packet_id, PacketReader pr) { string name = pr.ReadString(); PlayerData.Character character = new PlayerData.Character(name); // Status string gender = pr.ReadString(); string job = pr.ReadString(); int level = pr.ReadInt8(); int exp = pr.ReadInt32(); int hp = pr.ReadInt32(); int sp = pr.ReadInt32(); int maxEXP = pr.ReadInt32(); int maxHp = pr.ReadInt32(); int maxSp = pr.ReadInt32(); int atk = pr.ReadInt32(); int def = pr.ReadInt32(); character.SetStatus(gender, job, level, exp, hp, sp, maxEXP, maxHp, maxSp, atk, def); // Equipment string headEquipment = pr.ReadString(); string bodyEquipment = pr.ReadString(); string weaponEquipment = pr.ReadString(); character.SetEquipment(headEquipment, bodyEquipment, weaponEquipment); // Location string currentMap = pr.ReadString(); float positionX = pr.ReadFloat(); float positionY = pr.ReadFloat(); character.SetLocation(currentMap, positionX, positionY); // Inventory int money = pr.ReadInt32(); character.SetMoney(money); /*Debug.Log("Character name : " + name); * Debug.Log("Job : " + job + ", Lvl." + level + " EXP." + exp); * Debug.Log("HP : " + hp + "/" + maxHp + ", SP : " + sp +"/"+maxSp ); * Debug.Log("Attack : " + atk + " , Defense : " + def); * Debug.Log("[Equipment] Head : " + headEquipment + ", Body : "+bodyEquipment+", Weapon : "+weaponEquipment); * Debug.Log("[Location] Map : " + currentMap + " X : " + positionX + " Y : " + positionY); * Debug.Log("Inventory"); * Debug.Log("Gold : " + gold); * Debug.Log("Item [" + itemAmount + "]");*/ DGTRemote.GetInstance().ReceiveCharacterCreated(character); }
/// <summary> /// Collect item with defined mode (addByCode) /// </summary> /// <param name="itemGameObject">Item GameObject</param> /// <param name="addByCode">Is add by code</param> public void CollectItemToInventory(GameObject itemGameObject, bool addByCode) { Item i = itemGameObject.GetComponent <Item>(); int indexOfItemInInventory = getSlotIndexFromItemId(i.GetItemId()); if (i.IsStackable() && indexOfItemInInventory > -1) { Debug.Log("Increase stack to item Id : " + i.GetItemId()); slots[indexOfItemInInventory].IncreaseStack(); // increase stack to item that already in inventory DGTRemote.GetInstance().RequestInventoryIncreaseItem(i.GetItemId(), 1); if (!addByCode) { Destroy(itemGameObject); } NotificationSystem.Instance.AddNotification("คุณได้รับไอเท็ม " + i.GetItemName() + " เพิ่ม"); UpdateSlotsWindows(); return; } else { int indexFree = getFreeFirstSlot(); //หาช่องว่างใน Inventory if (indexFree > -1) { i.SetIndex(indexFree); slots[indexFree] = i; // Add item to first empty slot DGTRemote.GetInstance().RequestInventoryAddItem(i.GetItemId(), 1); //Add item to UI Slots for when player click to read detail Item itemAdded = slotsInventoryUI[indexFree].AddComponent <Item>(); Item.CopyItem(itemAdded, i); if (!addByCode) { Destroy(itemGameObject); } if (slots[indexFree].IsStackable()) { slots[indexFree].SetItemStack(1); } //notification you got item blah blah as new Debug.Log("คุณได้รับไอเท็ม " + slots[indexFree].GetItemName()); NotificationSystem.Instance.AddNotification("คุณได้รับไอเท็ม " + slots[indexFree].GetItemName()); UpdateSlotsWindows(); return; } } // Can't collect item maybe full inventory }
public IEnumerator ConnectToServer() { string host = "139.59.127.218"; // string host = "localhost"; // string host = "192.168.1.3"; int port = 3456; DGTPacket.Config pc = new DGTPacket.Config(host, port); DGTRemote.resetGameState(); DGTRemote gamestate = DGTRemote.GetInstance(); gamestate.Connect(pc.host, pc.port); gamestate.ProcessEvents(); yield return(new WaitForSeconds(0.1f)); for (int i = 0; i < 10; i++) { if (gamestate.Connected()) { break; } if (gamestate.ConnectFailed()) { break; } gamestate.ProcessEvents(); yield return(new WaitForSeconds(i * 0.1f)); } if (gamestate.Connected()) { Debug.Log("Connected Finish"); // send login gamestate.RequestLogin(); gamestate.mainController = this; // SceneManager.LoadScene("PlayScene"); } else { yield return(new WaitForSeconds(5f)); Debug.Log("Cannot connect"); } // StartCoroutine(PingTest()); yield break; }
public bool successQuest(Quest q) { if (!checkNull(q)) { if (processList.Exists(qs => qs.questID == q.questID) && !successList.Exists(qs => qs.questID == q.questID)) { NotificationSystem.Instance.AddNotification("[เควส] ส่ง " + q.questTitle + " เรียบร้อยแล้ว"); q.RewardToPlayer(); processList.Remove(q); successList.Add(q); DGTRemote.GetInstance().RequestSendSuccessQuest(q.questID); return(true); } } return(false); }
public bool acceptQuest(Quest q) { if (!checkNull(q)) { if (processList.Exists(qs => qs.questID == q.questID) || successList.Exists(qs => qs.questID == q.questID)) { return(false); } NotificationSystem.Instance.AddNotification("[เควส] รับเควส " + q.questTitle + " มาแล้ว"); processList.Add(q); getQuestFromProcess(q).startQuest(); if (q.qcon.type != 3) { DGTRemote.GetInstance().RequestSendAcceptQuest(q.questID); } return(true); } return(false); }
public void checkName() { if (string.IsNullOrEmpty(playerName.text)) { Popup.Instance.showPopup("การสร้างตัวละคร", "กรุณาใส่ชื่อตัวละคร"); } else if (string.IsNullOrEmpty(gender)) { Popup.Instance.showPopup("การสร้างตัวละคร", "กรุณาเลือกเพศตัวละคร"); } else if (string.IsNullOrEmpty(job)) { Popup.Instance.showPopup("การสร้างตัวละคร", "กรุณาเลือกอาชีพตัวละคร"); } else { DGTRemote.GetInstance().checkCharacterName(playerName.text); btnCreate.interactable = false; } }
// 22000 private void RecvOnlineRealtimeControl(int packet_id, PacketReader pr) { // Player int dataAmount = pr.ReadInt16(); for (int i = 0; i < dataAmount; i++) { DGTRemote.GetInstance().ReceiveOnlinePlayerData(pr.ReadUInt32(), new Vector2(pr.ReadFloat(), pr.ReadFloat()), //read Position x,y new Vector2(pr.ReadFloat(), pr.ReadFloat()), //read Velocity x,y pr.ReadFloat(), pr.ReadUInt8()); //read scaleX } // Monster dataAmount = pr.ReadInt8(); for (int i = 0; i < dataAmount; i++) { int ID = pr.ReadUInt32(); int HP = pr.ReadUInt32(); Vector2 position = new Vector2(pr.ReadFloat(), pr.ReadFloat()); DGTRemote.GetInstance().ReceiveOnlineMonsterControl(ID, HP, position); } // Monster Hurt dataAmount = pr.ReadInt8(); for (int i = 0; i < dataAmount; i++) { int ID = pr.ReadUInt32(); int damage = pr.ReadUInt32(); int hpLeft = pr.ReadUInt32(); int knockbackDirection = pr.ReadInt8(); DGTRemote.GetInstance().ReceiveOnlineMonsterHurt(ID, damage, hpLeft, knockbackDirection); } // Change Equipment dataAmount = pr.ReadInt8(); for (int i = 0; i < dataAmount; i++) { int UID = pr.ReadUInt32(); int part = pr.ReadInt8(); string value = pr.ReadString(); DGTRemote.GetInstance().ReceiveOnlinePlayerChangeEquipment(UID, part, value); } }
public IEnumerator ConnectToServer() { DGTPacket.Config pc = new DGTPacket.Config("localhost", 3456); DGTRemote.resetGameState(); DGTRemote gamestate = DGTRemote.GetInstance(); gamestate.Connect(pc.host, pc.port); gamestate.ProcessEvents(); yield return(new WaitForSeconds(0.1f)); for (int i = 0; i < 10; i++) { if (gamestate.Connected()) { break; } if (gamestate.ConnectFailed()) { break; } gamestate.ProcessEvents(); yield return(new WaitForSeconds(i * 0.1f)); } if (gamestate.Connected()) { Debug.Log("Login Finish"); // send login gamestate.RequestLogin(); gamestate.mainController = this; } else { yield return(new WaitForSeconds(5f)); Debug.Log("Cannot connect"); } // StartCoroutine(PingTest()); yield break; }
public IEnumerator ConnectToServer(string ipaddress, int port) { DGTPacket.Config pc = new DGTPacket.Config(ipaddress, port); //connect to server IP,port DGTRemote.resetGameState(); DGTRemote gamestate = DGTRemote.GetInstance(); gamestate.Connect(pc.host, pc.port); //IP host, port to serve gamestate.ProcessEvents(); //Process Event yield return(new WaitForSeconds(0.1f)); for (int i = 0; i < 10; i++) { if (gamestate.Connected()) { break; } if (gamestate.ConnectFailed()) { break; } gamestate.ProcessEvents(); yield return(new WaitForSeconds(i * 0.1f)); } if (gamestate.Connected()) { Text status = GameObject.Find("s1_status").GetComponent <Text>(); status.text = "Online"; status.color = Color.green; gamestate.mainController = this; } else { yield return(new WaitForSeconds(5f)); Debug.Log("Cannot connect"); } //StartCoroutine(PingTest()); yield break; }
void Update() { DGTRemote.GetInstance().ProcessEvents(); }
public void Logout() { DGTRemote.GetInstance().Logout(); }