コード例 #1
0
ファイル: ChangeHandler.cs プロジェクト: tomba/dwarrowdelf
        public override void HandleWorldChange(Change change)
        {
            var changeMsg = new ChangeMessage() { ChangeData = change.ToChangeData() };

            Send(changeMsg);

            if (change is ObjectCreatedChange)
            {
                var c = (ObjectCreatedChange)change;
                var newObject = c.Object;
                newObject.SendTo(m_player, ObjectVisibility.All);
            }
        }
コード例 #2
0
ファイル: VisionTrackerLOS.cs プロジェクト: tomba/dwarrowdelf
        void OnWorldChanged(Change change)
        {
            if (change is ObjectMoveChange)
            {
                var c = (ObjectMoveChange)change;
                var mo = (MovableObject)c.Object;

                if ((c.Source == m_environment && EventIsNear(c.SourceLocation)) ||
                    (c.Destination == m_environment && EventIsNear(c.DestinationLocation)))
                    HandleNewTerrainsAndObjects();
            }
            else if (change is ObjectMoveLocationChange)
            {
                var c = (ObjectMoveLocationChange)change;
                var mo = (MovableObject)c.Object;

                if (mo.Environment == m_environment && (EventIsNear(c.SourceLocation) || EventIsNear(c.DestinationLocation)))
                    HandleNewTerrainsAndObjects();
            }
            else if (change is MapChange)
            {
                var c = (MapChange)change;

                if (c.Environment == m_environment && EventIsNear(c.Location))
                    HandleNewTerrainsAndObjects();
            }
        }
コード例 #3
0
ファイル: ChangeHandler.cs プロジェクト: tomba/dwarrowdelf
        public override void HandleWorldChange(Change change)
        {
            // can the player see the change?
            if (!CanSeeChange(change))
                return;

            // Send object data for an object that comes to the environment
            if (change is ObjectMoveChange)
            {
                var c = (ObjectMoveChange)change;
                var dst = c.Destination as EnvironmentObject;

                if (dst != null && c.Source != c.Destination &&
                    (dst.VisibilityMode == VisibilityMode.AllVisible || dst.VisibilityMode == VisibilityMode.GlobalFOV))
                {
                    var newObject = c.Object;
                    var vis = m_player.GetObjectVisibility(newObject);
                    Debug.Assert(vis != ObjectVisibility.None);
                    newObject.SendTo(m_player, vis);
                }
            }

            // When an item is equipped by a non-controllable, the item isn't known to the client.
            // Thus we need to send the data of the item here, before sending the property change message.
            // XXX should there be some kind of "visibility-changed" event?
            if (change is PropertyChange)
            {
                var c = (PropertyChange)change;

                if (c.PropertyID == PropertyID.IsEquipped)
                {
                    var item = (ItemObject)c.Object;

                    if (item.IsEquipped)
                    {
                        var equipper = (LivingObject)item.Container;

                        if (m_player.IsController(equipper) == false)
                            item.SendTo(m_player, ObjectVisibility.Public);
                    }
                }
            }

            var changeMsg = new ChangeMessage() { ChangeData = change.ToChangeData() };

            Send(changeMsg);
        }
コード例 #4
0
ファイル: ChangeHandler.cs プロジェクト: tomba/dwarrowdelf
 public abstract void HandleWorldChange(Change change);
コード例 #5
0
ファイル: World.cs プロジェクト: tomba/dwarrowdelf
 public void AddChange(Change change)
 {
     VerifyAccess();
     if (WorldChanged != null)
         WorldChanged(change);
 }
コード例 #6
0
ファイル: ChangeHandler.cs プロジェクト: tomba/dwarrowdelf
        bool CanSeeChange(Change change)
        {
            if (change is TurnStartChange)
            {
                // XXX Maybe this should be sent only if the player sees the Living
                return true;
            }
            else if (change is TurnEndChange)
            {
                // XXX Maybe this should be sent only if the player sees the Living
                return true;
            }
            else if (change is TickStartChange)
            {
                return true;
            }
            else if (change is GameDateChange)
            {
                return true;
            }
            else if (change is ObjectDestructedChange)
            {
                // XXX We should only send this if the player sees the object.
                // And the client should have a cleanup of some kind to remove old objects (which may or may not be destructed)
                return true;
            }
            else if (change is ObjectCreatedChange)
            {
                return false;
            }
            else if (change is ObjectMoveChange)
            {
                var c = (ObjectMoveChange)change;

                if (m_player.IsController(c.Object))
                    return true;

                if (m_player.Sees(c.Source, c.SourceLocation))
                    return true;

                if (m_player.Sees(c.Destination, c.DestinationLocation))
                    return true;

                return false;
            }
            else if (change is ObjectMoveLocationChange)
            {
                var c = (ObjectMoveLocationChange)change;

                if (m_player.IsController(c.Object))
                    return true;

                // XXX
                var env = ((MovableObject)c.Object).Container;

                if (m_player.Sees(env, c.SourceLocation))
                    return true;

                if (m_player.Sees(env, c.DestinationLocation))
                    return true;

                return false;
            }
            else if (change is MapChange)
            {
                var c = (MapChange)change;
                return m_player.Sees(c.Environment, c.Location);
            }
            else if (change is PropertyChange)
            {
                var c = (PropertyChange)change;

                // fast path for controllables
                if (m_player.IsController(c.Object))
                    return true;

                if (c.PropertyID == PropertyID.IsEquipped)
                {
                    // XXX special handling for IsEquipped for now
                    // We see the prop change even if the item is inside a non-controllable

                    var mo = (MovableObject)c.Object;

                    for (MovableObject o = mo; o != null; o = o.Container as MovableObject)
                    {
                        var ov = m_player.GetObjectVisibility(o);
                        if ((ov & ObjectVisibility.Public) != 0)
                            return true;
                    }

                    return false;
                }
                else
                {
                    var vis = PropertyVisibilities.GetPropertyVisibility(c.PropertyID);
                    var ov = m_player.GetObjectVisibility(c.Object);

                    return (ov & vis) != 0;
                }
            }
            else if (change is ActionStartedChange)
            {
                var c = (ActionStartedChange)change;
                return m_player.IsController(c.Object);
            }
            else if (change is ActionProgressChange)
            {
                var c = (ActionProgressChange)change;
                return m_player.IsController(c.Object);
            }
            else if (change is ActionDoneChange)
            {
                var c = (ActionDoneChange)change;
                return m_player.IsController(c.Object);
            }

            else if (change is ObjectChange)
            {
                var c = (ObjectChange)change;

                var vis = m_player.GetObjectVisibility(c.Object);

                return vis != ObjectVisibility.None;
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: Fulborg/dwarrowdelf
        void HandleWorldChange(Change change)
        {
            m_changeHandler.HandleWorldChange(change);

            if (change is TurnEndChange)
                this.IsProceedTurnReplyReceived = false;
        }
コード例 #8
0
ファイル: WorldLogger.cs プロジェクト: tomba/dwarrowdelf
 void HandleChanges(Change change)
 {
     //m_writer.WriteLine(change);
     //m_writer.Flush();
 }
コード例 #9
0
 public abstract void HandleWorldChange(Change change);
コード例 #10
0
        bool CanSeeChange(Change change)
        {
            if (change is TurnStartChange)
            {
                // XXX Maybe this should be sent only if the player sees the Living
                return(true);
            }
            else if (change is TurnEndChange)
            {
                // XXX Maybe this should be sent only if the player sees the Living
                return(true);
            }
            else if (change is TickStartChange)
            {
                return(true);
            }
            else if (change is GameDateChange)
            {
                return(true);
            }
            else if (change is ObjectDestructedChange)
            {
                // XXX We should only send this if the player sees the object.
                // And the client should have a cleanup of some kind to remove old objects (which may or may not be destructed)
                return(true);
            }
            else if (change is ObjectCreatedChange)
            {
                return(false);
            }
            else if (change is ObjectMoveChange)
            {
                var c = (ObjectMoveChange)change;

                if (m_player.IsController(c.Object))
                {
                    return(true);
                }

                if (m_player.Sees(c.Source, c.SourceLocation))
                {
                    return(true);
                }

                if (m_player.Sees(c.Destination, c.DestinationLocation))
                {
                    return(true);
                }

                return(false);
            }
            else if (change is ObjectMoveLocationChange)
            {
                var c = (ObjectMoveLocationChange)change;

                if (m_player.IsController(c.Object))
                {
                    return(true);
                }

                // XXX
                var env = ((MovableObject)c.Object).Container;

                if (m_player.Sees(env, c.SourceLocation))
                {
                    return(true);
                }

                if (m_player.Sees(env, c.DestinationLocation))
                {
                    return(true);
                }

                return(false);
            }
            else if (change is MapChange)
            {
                var c = (MapChange)change;
                return(m_player.Sees(c.Environment, c.Location));
            }
            else if (change is PropertyChange)
            {
                var c = (PropertyChange)change;

                // fast path for controllables
                if (m_player.IsController(c.Object))
                {
                    return(true);
                }

                if (c.PropertyID == PropertyID.IsEquipped)
                {
                    // XXX special handling for IsEquipped for now
                    // We see the prop change even if the item is inside a non-controllable

                    var mo = (MovableObject)c.Object;

                    for (MovableObject o = mo; o != null; o = o.Container as MovableObject)
                    {
                        var ov = m_player.GetObjectVisibility(o);
                        if ((ov & ObjectVisibility.Public) != 0)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }
                else
                {
                    var vis = PropertyVisibilities.GetPropertyVisibility(c.PropertyID);
                    var ov  = m_player.GetObjectVisibility(c.Object);

                    return((ov & vis) != 0);
                }
            }
            else if (change is ActionStartedChange)
            {
                var c = (ActionStartedChange)change;
                return(m_player.IsController(c.Object));
            }
            else if (change is ActionProgressChange)
            {
                var c = (ActionProgressChange)change;
                return(m_player.IsController(c.Object));
            }
            else if (change is ActionDoneChange)
            {
                var c = (ActionDoneChange)change;
                return(m_player.IsController(c.Object));
            }

            else if (change is ObjectChange)
            {
                var c = (ObjectChange)change;

                var vis = m_player.GetObjectVisibility(c.Object);

                return(vis != ObjectVisibility.None);
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #11
0
ファイル: WorldLogger.cs プロジェクト: jaenudin86/dwarrowdelf
 void HandleChanges(Change change)
 {
     //m_writer.WriteLine(change);
     //m_writer.Flush();
 }