public void TriggerGameModelSelected(Player p, AbstractGameModel gm)
 {
     if (OnGameModelSelected != null)
     {
         OnGameModelSelected(p, gm);
     }
 }
Esempio n. 2
0
        protected void ProcessGameModelSelected(Player p, AbstractGameModel gm)
        {
            if (null == m_xtw)
            {
                return;
            }

            if (!(gm is AbstractGameAsset || gm is BuyPoint))
            {
                return;
            }

            lock (this)
            {
                RecordEventStart(SelectedElement);
                RecordPlayerReference(p);
                if (gm is AbstractGameAsset)
                {
                    RecordGameAssetReference(gm as AbstractGameAsset);
                }
                else
                {
                    RecordBuyPointReference(gm as BuyPoint);
                }
                RecordEventEnd();
            }
        }
Esempio n. 3
0
        public SceneObjectGroup ReplaceSceneObjectFromInventoryItem(
            string itemName, AbstractGameModel gm, UUID ownerUuid)
        {
            RootPart.ParentGroup.Scene.DeleteSceneObject(RootPart.ParentGroup, false);
            SceneObjectGroup so = RezSceneObjectFromInventoryItem(itemName, gm, ownerUuid, RootPart.AbsolutePosition);

            // This should be pushed down into RezSceneObjectFromInventoryItem(), but other callers rely on the
            // scene object maintaining its original name for identification purposes (e.g. crops).
            so.Name = gm.Name;

            m_rootPart = so.RootPart;
            so.ScheduleGroupForFullUpdate();

            return(so);
        }
Esempio n. 4
0
        /// <summary>
        /// Get the game model that the player last selected in-world.
        /// </summary>
        /// <param name="playerId"></param>
        /// <param name="wait">If true, then wait for a player selection (no wait will occur if the player has already
        /// previously selected something that hasn't been fetched).  If false, then always return the last selected
        /// item</param>
        /// <returns></returns>
        public AbstractGameModel GetLastSelected(UUID playerId, bool wait)
        {
//            m_log.InfoFormat("[WATER WARS]: Received last selected request from {0}, wait {1}", playerId, wait);

            AbstractGameModel lastSelected = null;

            lock (m_lastSelected)
            {
                // If we receive a selection request for a non-player (e.g. an observer) then create their selection
                // queue dynamically.  We don't yet do this for players since they may perform a selection before
                // fetching it (this could probably be resolved by also creating dynamically upon set if no selection
                // has been set up for the user id
                if (!m_lastSelected.ContainsKey(playerId))
                {
//                    m_log.InfoFormat("[WATER WARS]: Received last selected request from non-player {0}", playerId);
                    m_lastSelected[playerId]            = AbstractGameAsset.None;
                    m_lastSelectedSyncObjects[playerId] = new Object();
                }
            }

            if (wait)
            {
                Object o = m_lastSelectedSyncObjects[playerId];

                lock (o)
                    Monitor.Wait(o);
            }

            lock (m_lastSelected)
                lastSelected = m_lastSelected[playerId];

//            m_log.InfoFormat(
//                "[WATER WARS]: Returning last selected [{0}] type {1} for {2}",
//                lastSelected.Name, lastSelected.Type, playerId);

//            if (lastSelected is AbstractGameAsset)
//                m_log.InfoFormat("[WATER WARS]: Returning last selected [{0}] has game state {1}", lastSelected, ((AbstractGameAsset)lastSelected).Game.State);

            return(lastSelected);
        }
Esempio n. 5
0
        protected void HandleOnRevenueStageEnded(List <AbstractGameAsset> removedAssets)
        {
            lock (m_lastSelected)
            {
                // Use a copy of the last selected dictionary so that we can modify the original as we go along
                Dictionary <UUID, AbstractGameModel> lastSelected
                    = new Dictionary <UUID, AbstractGameModel>(m_lastSelected);

                foreach (UUID playerId in lastSelected.Keys)
                {
                    AbstractGameModel m = lastSelected[playerId];

                    foreach (AbstractGameAsset removedAsset in removedAssets)
                    {
                        if (removedAsset.Uuid == m.Uuid)
                        {
                            SetLastSelected(playerId, removedAsset.Field);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Rez a scene object from a given inventory item.
        /// </summary>
        /// <remarks>
        /// FIXME: In a better world we could just get the owner from AbstractGameModel.  However, various complications
        /// (e.g. the fact that buy points have development rights owners and water rights owners) prevents this
        /// currently.
        /// </remarks>
        /// <param name="itemName"></param>
        /// <param name="gm"></param>
        /// <param name="ownerUuid"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        protected SceneObjectGroup RezSceneObjectFromInventoryItem(
            string itemName, AbstractGameModel gm, UUID ownerUuid, Vector3 pos)
        {
//            m_log.InfoFormat(
//                "[WATER WARS]: Rezzing item {0} corresponding to game model {1} at {2}", itemName, gm.Name, pos);

            TaskInventoryItem item = GetItem(m_itemStoreView, itemName);

            // we're only doing this beforehand so that we can get the rotation (since the existing RezObject() doesn't
            // retain it.  FIXME FIXME FIXME
//            AssetBase objectAsset = m_scene.AssetService.Get(item.AssetID.ToString());
//            string xml = Utils.BytesToString(objectAsset.Data);
//            SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(xml);

            SceneObjectGroup so = m_itemStoreView.RootPart.Inventory.GetRezReadySceneObject(item);

            so.UUID    = gm.Uuid;
            so.OwnerID = ownerUuid;
            m_scene.AddNewSceneObject(so, true, pos, so.GroupRotation, Vector3.Zero);

            return(so);
        }
Esempio n. 7
0
        /// <summary>
        /// Allow a game model to be selected via the webservice, not just from in-world
        /// </summary>
        ///
        /// FIXME: This currently only allows a player to be selected.
        ///
        /// <param name="playerId"></param>
        /// <param name="components"></param>
        /// <returns></returns>
        protected Hashtable HandleSetLastSelected(UUID playerId, string[] components)
        {
//            m_log.InfoFormat(
//                "[WATER WARS]: Handling SetLastSelected for {0}, path [{1}]", playerId, string.Join("/", components));

            Hashtable reply = new Hashtable();

            reply["int_response_code"]   = 200; // 200 OK
            reply["str_response_string"] = "nada";
            reply["content_type"]        = "text/plain";

            if (components[0] != "player")
            {
                return(reply);
            }

            UUID selectedId = UUID.Parse((string)components[1]);

            AbstractGameModel         agm     = null;
            Dictionary <UUID, Player> players = m_controller.Game.Players;

            lock (players)
            {
                if (players.ContainsKey(selectedId))
                {
                    agm = players[selectedId];
                }
            }

            if (null != agm)
            {
                SetLastSelected(playerId, agm);
            }

            // TODO: Error response

            return(reply);
        }
Esempio n. 8
0
        /// <summary>
        /// Set the game object last selected by the player in-world
        /// </summary>
        /// <param name="playerId"></param>
        /// <param name="model"></param>
        public void SetLastSelected(UUID playerId, AbstractGameModel m)
        {
//            m_log.InfoFormat("[WATER WARS]: Setting last selected for {0} to {1} type {2}", playerId, m.Name, m.Type);

            Player p = null;

            lock (m_controller.Game.Players)
                m_controller.Game.Players.TryGetValue(playerId, out p);

//            m_log.InfoFormat(
//                "[WATER WARS]: In SetLastSelected found {0} for uuid {1} when trying to set {2} type {3}",
//                p != null ? p.Name : null, playerId, m.Name, m.Type);

            // XXX: At the moment, we don't serve selections to non-players
            if (null == p)
            {
                return;
            }

            lock (m_lastSelected)
            {
                // Remove our previous change listener
                if (m_lastSelectedChangeDelegates.ContainsKey(playerId))
                {
                    m_lastSelected[playerId].OnChange -= m_lastSelectedChangeDelegates[playerId];
                }

                // Set up a change listener so that any alterations to the model get propogated to the media browser
                // (the view)
                m_lastSelected[playerId] = m;
                m_lastSelectedChangeDelegates[playerId]
                    = delegate(AbstractModel model)
                    {
                    // XXX: Probably not required now that we have stopped listening to state changes and are
                    // firing general change events manually to avoid race conditions and multiple updates.
//                        // If the game is in the revenue state while transitioning from the water state back
//                        // to the build state then ignore any game asset updates.
//                        // The reason for this is that the revenue changes will fire game asset updates, but
//                        // these object updates will not include build owner actions.  While the client is updating and before
//                        // it makes the next long poll, the subsequent start build stage event can fire.  However, this event
//                        // will not be seen by the client and the user will end up with no build actions until they reselect
//                        // the game asset.
//                        if (m_controller.Game.State == GameStateType.Revenue)
//                        {
////                            m_log.InfoFormat(
////                                "[WATER WARS]: Ignoring change of {0} for {1} since state is {2}",
////                                model.Name, playerId, m_controller.Game.State);
//                                return;
//                        }

//                        m_log.InfoFormat(
//                            "[WATER WARS]: Pulsing change of {0} for {1} since state is {2}",
//                            model.Name, playerId, m_controller.Game.State);

                    Object obj = m_lastSelectedSyncObjects[playerId];

                    lock (obj)
                        Monitor.PulseAll(obj);
                    };

                m_controller.EventManager.TriggerGameModelSelected(p, m);
                m.OnChange += m_lastSelectedChangeDelegates[playerId];
            }

            // Pulse anybody waiting since the entire selected object has changed.
            // No need to lock since m_lastSelectedSyncObjects is only set on initialization
            Object o = m_lastSelectedSyncObjects[playerId];

            lock (o)
                Monitor.PulseAll(o);
            //m_lastSelectedResetEvents[playerId].Set();
        }