예제 #1
0
    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();
        }
    }