public static void spawnPlayer(cPositionData pos) { if (GameObject.Find(pos.SessionID) == null) { GameObject player = GameObject.Find("Avatar"); GameObject cube = GameObject.Instantiate(player); cube.name = pos.SessionID; cube.transform.position = new Vector3(pos.x, pos.y, pos.z); } }
private void HandleLoginAnswer(PacketHeader packetHeader, Connection connection, cPositionData incomingObject) { if (incomingObject != null) { Globals.SessionID = incomingObject.SessionID; Globals.PlayerPosition = incomingObject; UpdatePlayerTarget.SessionID = Globals.SessionID; UpdatePlayerTarget.con = Globals.con; } else { Application.Quit(); } }
public static cPositionData genPosDataFromGameObject(GameObject avatar) { cPositionData currpos = new cPositionData(); currpos.SessionID = Globals.SessionID; currpos.x = avatar.transform.position.x; currpos.y = avatar.transform.position.y; currpos.z = avatar.transform.position.z; currpos.rx = avatar.transform.rotation.z; currpos.ry = avatar.transform.rotation.y; currpos.rz = avatar.transform.rotation.z; currpos.rw = avatar.transform.rotation.w; currpos.target = UpdatePlayerTarget.playerTarget; return(currpos); }
public static void CheckInputAndCast(cPositionData pos, GameObject avatar) { foreach (Data.Spells.Spell spell in pos.character.Spells.Values) { if (Input.GetKeyDown(spell.Hotkey)) { String hotkey = spell.Hotkey; if ((Globals.Cooldowns.ContainsKey(spell.Name) && Globals.Cooldowns[spell.Name].Cooldown_Left <= 0) || !Globals.Cooldowns.ContainsKey(spell.Name) && !Globals.casting) { Debug.Log(UpdatePlayerTarget.playerTarget); if (UpdatePlayerTarget.playerTarget != null) { GameObject target = GameObject.Find(UpdatePlayerTarget.playerTarget); GameObject s = GameObject.Find(spell.SourceObject); GameObject e = GameObject.Find(spell.TargetObject); Vector3 posNewAvatar = avatar.transform.position; posNewAvatar.y += (float)1; Vector3 posNewTarget = target.transform.position; posNewTarget.y += (float)1; s.transform.position = posNewAvatar; e.transform.position = posNewTarget; Globals.bolVisible = true; Globals.casting = true; boltThread = new System.Threading.Thread(endBoltThrd); boltThread.Start(); Globals.castingAudioEffectMuted = false; avatar.GetComponent <Animator>().runtimeAnimatorController = GameObject.Instantiate((RuntimeAnimatorController)Resources.Load("Anim1")); if (UpdatePlayerTarget.playerTarget != null) { Data.Actions.Fight.cAttack attack = new Data.Actions.Fight.cAttack(); attack.IDPlayer = Globals.SessionID; attack.TargetID = UpdatePlayerTarget.playerTarget; Spell retS = null; foreach (Spell sp in Globals.PlayerPosition.character.Spells.Values) { if (sp.Hotkey == hotkey) { retS = sp; } } attack.Spell = retS; GameObject SpellSlot = GameObject.Find("Slot " + hotkey); if (SpellSlot) { SpaceD_Cooldown cd = SpellSlot.GetComponent <SpaceD_Cooldown>(); cd.StartCooldown(retS.Cooldown); } Globals.con.SendObject("AttackTargetPlayer", attack); } } } } GameObject bolt = GameObject.Find(spell.MainObject); bolt.GetComponent <AudioSource>().mute = Globals.castingAudioEffectMuted; if (Globals.bolVisible == false && Globals.casting) { avatar.GetComponent <Animator>().runtimeAnimatorController = GameObject.Instantiate((RuntimeAnimatorController)Resources.Load("Invector_BasicLocomotionLITE")); GameObject s = GameObject.Find(spell.SourceObject); GameObject e = GameObject.Find(spell.TargetObject); s.transform.position = Vector3.one; e.transform.position = Vector3.one; Globals.casting = false; } } }
public static Vector3 posToVector3(cPositionData pos) { Vector3 v = new Vector3(pos.x, pos.y, pos.z); return(v); }
void Update() { //Is player logged in? if (Globals.SessionID != "" && Globals.SessionID != null && !Globals.dead) { GameObject avatar = GameObject.Find("vThirdPersonController"); cPositionData pos = Globals.PlayerPosition; //----Global stuff----- if (Globals.loadWorldData) { Globals.loadWorldData = false; LoadSaveWorldData.LoadWorldData(Globals.wd); } if (Globals.mute) { GameObject avatar2 = GameObject.Find("FANTASY_WOLF"); AudioSource s = avatar2.GetComponent <AudioSource>(); s.mute = true; } if (Globals.dead) { Destroy(avatar); } //----Key Input--- if (Input.GetKeyUp("space")) { //Change Level //Globals.con.SendObject("ChangeWorld", new String[] { "1", Globals.SessionID }); } //toggle inventory if (Input.GetKeyUp(KeyCode.I)) { Globals._Inventory.SetActive(!Globals._Inventory.active); } if (Input.GetKeyUp("escape")) { if (UpdatePlayerTarget.playerTarget != null) { Globals.con.SendObject <string>("CancelTarget", Globals.SessionID); } } //Lock/unlock mouse/movement if (Input.GetMouseButton(1)) { if (Cursor.visible == true) { Cursor.visible = false; GWTools.lockMouse(); } /* * //Cancel targeting * if (UpdatePlayerTarget.playerTarget != null) * { * Globals.con.SendObject<string>("CancelTarget", Globals.SessionID); * } * else//Lock/unlock cursor * { * if (Cursor.visible == false) * { * Cursor.visible = true; * GWTools.unlockMouse(); * } * else * { * Cursor.visible = false; * GWTools.lockMouse(); * } * }*/ } else { if (Cursor.visible == false) { Cursor.visible = true; GWTools.unlockMouse(); } } //-------Data update functions---------- //Inventory InventoryData.UpdateInventory(); GameObject inv = GameObject.Find("Inventory"); if (inv != null) { Inventory inv_sc = inv.GetComponent <Inventory>(); for (int i = 0; i < inv_sc.items.Count; i++) { GameObject goItem = (GameObject)inv_sc.items[i]; Item scItem = goItem.GetComponent <Item>(); bool found = false; foreach (Data.Items.Item itmEqu in Globals.PlayerPosition.character.equipment.Values) { Debug.Log(itmEqu.ItemID); if (itmEqu.ItemID == scItem.item_dat.ItemID) { found = true; } } if (found) { scItem.textColor = Color.yellow; } else { scItem.textColor = Color.white; } scItem.inventoryTexture = Resources.Load <Texture2D>("Icon_Sword"); inv.GetComponent <Inventory>().items[i] = goItem; } } foreach (Data.Items.Item itm in Globals.Loot.Values) { if (!GameObject.Find(itm.ItemID)) { GameObject newObj = GameObject.Instantiate(GameObject.Find("DragMe")); newObj.name = itm.ItemID; newObj.transform.position = new Vector3(itm.x, Terrain.activeTerrain.SampleHeight(new Vector3(itm.x, 0, itm.z)), itm.z); GameObject defaultObj = GameObject.Instantiate(GameObject.Find("default")); newObj.AddChild(defaultObj); } } //Spell Casting SpellData.CheckInputAndCast(pos, avatar); //Attacking Enemys - Statemachine for attacking enemies EnemysData.AttackingEnemys(); //Spawn new Players/Enemys EnemysData.SpawnEnemys(); PlayersData.SpawnPlayers(); //Destroy obsolete Players/Enemys EnemysData.RemoveEnemys(); PlayersData.RemovePlayers(); //------Position update-------------- //Get current position cPositionData currpos = GWTools.genPosDataFromGameObject(avatar); //Send current position to server Globals.con.SendObject("GlobalPositionUpdate", currpos); //Update players and enemys positions GlobalPositionsUpdate.updateAvatarPositions(); GlobalPositionsUpdate.updateEnemyPositions(); } }