protected virtual void CollectObjectData(BaseGameObjectData baseData, ObjectVisibility visibility) { Debug.Assert(visibility != ObjectVisibility.None); baseData.ObjectID = this.ObjectID; baseData.CreationTime = this.CreationTime; baseData.CreationTick = this.CreationTick; baseData.Properties = SerializeProperties(). Where(kvp => (PropertyVisibilities.GetPropertyVisibility(kvp.Key) & visibility) != 0). Select(kvp => new KeyValuePair <PropertyID, object>(kvp.Key, kvp.Value)). ToArray(); }
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(); } }