MmoDemo ItemProperties question

ktweedy1
ktweedy1 ✭✭
edited September 2010 in DotNet
I'm using Unity with the MmoDemo.

I see the code in WorldEntered strategy for HandleEventItemProperties and HandleEventItemPropertiesSet.

How does Photon know that the item properties changed? There is something I need to call to make changes to and item to be sent to the server?

Also, I don't see an event being thrown to the game object when new properties are set. Is this on purpose? should I be checking the item for changes each update in the game? Is there a problem with having the HandleEventItemPropertiesSet throw calling the game object and throwing an event?

Also, it looks like in the code only the properties that are in those handlers are supported. I need to add more properties setting if I want to have more? Looks like it doesn't just keep the hashtable, but extracts out the values and sets class properties.

Comments

  • The client informs the server about changed properties by calling operation "SetProperties". See "MyItem.SetColor" as example.
    When other MMO demo clients receive the event the event handler "WorldEntered.HandleEventItemPropertiesSet" updates the changed properties accordingly. The properties of the visible items are read and applied to the objects every frame, that's why there is no event. But you certainly can use events if you want to. This is just a demo.
  • In MmoDemo, are item properties getting cached on the server so when someone new enters the game they get the current properties?

    I have my code setting properties and other actors are seeing the changes. But when I load a new actor it seems to only see the inital settings of the item, not the current properties.
  • Yes, they are cached.
    When the client receives the ItemSubscribed event he does also receive a properties revision.
    If the client hasn't seen the item before or the cached revision is outdated he asks for the updated properties with operation GetProperties.
    The Demo shows that with the player text which can be changed is exchanged with properties.
    I don't know why you only see the initial properties, it works for the player text in the demo, doesn't it?
  • I see this. But tha is all handled by the owner of the object, sent at the time it happens. I see all of that.

    What I can't find is on the server, where the item properties get updated. So when a new actor logs in and gets all the items sent to him, gets those current properties. What I see is all the items being sent to the Actor but with the original properties that were used to create the item. I can't find any code on the server that updates the Item's properties on the server. Maybe it is happening in the Item class? But if it is suppose to happen there I don't see the Item properties on the server ever updated.

    So the question is, for a new actor that logs in, does he see the cached, current properties?
  • the code for that is compiled into the photon.socketserver.dll

    class Item:
     public void SetProperties(Hashtable propertiesSet, ArrayList propertiesUnset)
     {
       if (propertiesSet != null)
       {
          foreach (DictionaryEntry entry in propertiesSet)
          {
             this.properties[entry.Key] = entry.Value;
          }
       }
    
       if (propertiesUnset != null)
       {
          foreach (object key in propertiesUnset)
          {
             this.properties.Remove(key);
          }
       }
    
       this.PropertiesRevision++;
     }
    

    As you can see the dictionary is updated accordingly.
    I don't see how it could be possible to receive other properties than the newest.
  • Where does this get called from the MmoDemo code?

    Good to hear that it is suppose to support it. Let me see if i can track down where that is called and make sure i see the item being update. Is it here in the ItemOperationsSetProperties through the item.EventChannel publish?
            private OperationResponse ItemOperationSetProperties(Item item, SetProperties operation)
            {
                MethodReturnValue result = this.CheckAccess(item);
                if (result)
                {
                    var eventInstance = new ItemPropertiesSet
                    {
                        ItemId = item.Id,
                        ItemType = item.Type,
                        PropertiesRevision = item.PropertiesRevision,
                        PropertiesSet = operation.PropertiesSet,
                        PropertiesUnset = operation.PropertiesUnset
                    };
    
                    var message = new ItemEventMessage(item, eventInstance.GetEventData((byte)EventCode.ItemPropertiesSet, operation.OperationRequest.Reliability, Settings.ItemEventChannel));
                    item.EventChannel.Publish(message);
    
                    // no response sent
                    operation.OperationRequest.OnCompleted();
                    return null;
                }
    
                return operation.GetOperationResponse(result);
            }
    
    I see my properties changes coming in. And I see the PropertiesSet event getting published and coming back to the client, but i don't see SetProperties getting called on the item anywere.
  • good find, definitely a bug!
  • fix version:
                if (result)
                {
                    item.SetProperties(operation.PropertiesSet, operation.PropertiesUnset);
                    var eventInstance = new ItemPropertiesSet
    
  • Thanks for the quick update.