public List<GameMessage> GetMessageList(uint actorID) { var messageList = new List<GameMessage>(); int count = _attributeValues.Count; if (count == 1) { AttributeSetValueMessage msg = new AttributeSetValueMessage(); var e = _attributeValues.GetEnumerator(); if (!e.MoveNext()) throw new Exception("Expected value in enumerator."); var keyid = e.Current.Key; var value = e.Current.Value; int id = keyid.Id; msg.ActorID = actorID; msg.Field1 = new Fields.NetAttributeKeyValue(); msg.Field1.Field0 = keyid.Key; // FIXME: need to rework NetAttributeKeyValue, and maybe rename GameAttribute to NetAttribute? msg.Field1.Attribute = GameAttribute.Attributes[id]; // FIXME if (msg.Field1.Attribute.IsInteger) msg.Field1.Int = value.Value; else msg.Field1.Float = value.ValueF; messageList.Add(msg); } else { var e = _attributeValues.GetEnumerator(); // FIXME: probably need to rework AttributesSetValues as well a bit if (count >= 15) { for (; count >= 15; count -= 15) { AttributesSetValuesMessage msg = new AttributesSetValuesMessage(); msg.ActorID = actorID; msg.atKeyVals = new Fields.NetAttributeKeyValue[15]; for (int i = 0; i < 15; i++) msg.atKeyVals[i] = new Fields.NetAttributeKeyValue(); for(int i = 0;i < 15;i++) { if (!e.MoveNext()) throw new Exception("Expected values in enumerator."); var kv = msg.atKeyVals[i]; var keyid = e.Current.Key; var id = keyid.Id; var value = e.Current.Value; kv.Field0 = keyid.Key; kv.Attribute = GameAttribute.Attributes[id]; if (kv.Attribute.IsInteger) kv.Int = value.Value; else kv.Float = value.ValueF; } messageList.Add(msg); } } if (count > 0) { AttributesSetValuesMessage msg = new AttributesSetValuesMessage(); msg.ActorID = actorID; msg.atKeyVals = new Fields.NetAttributeKeyValue[count]; for (int i = 0; i < count; i++) { if (!e.MoveNext()) throw new Exception("Expected values in enumerator."); var kv = new Fields.NetAttributeKeyValue(); msg.atKeyVals[i] = kv; var keyid = e.Current.Key; var id = keyid.Id; var value = e.Current.Value; kv.Field0 = keyid.Key; kv.Attribute = GameAttribute.Attributes[id]; if (kv.Attribute.IsInteger) kv.Int = value.Value; else kv.Float = value.ValueF; } messageList.Add(msg); } } return messageList; }
private List<GameMessage> GetMessageListFromEnumerator(IEnumerator<KeyId> e, int count, bool level) { var messageList = new List<GameMessage>(); if (count == 0) return messageList; if (count == 1) { AttributeSetValueMessage msg = new AttributeSetValueMessage(); if (!e.MoveNext()) throw new Exception("Expected value in enumerator."); var keyid = e.Current; var value = _attributeValues[keyid]; int id = keyid.Id; msg.ActorID = _parent.DynamicID; msg.Field1 = new Mooege.Net.GS.Message.Fields.NetAttributeKeyValue(); msg.Field1.Field0 = keyid.Key; // FIXME: need to rework NetAttributeKeyValue, and maybe rename GameAttribute to NetAttribute? msg.Field1.Attribute = GameAttribute.Attributes[id]; // FIXME if (msg.Field1.Attribute.IsInteger) msg.Field1.Int = value.Value; else msg.Field1.Float = value.ValueF; messageList.Add(msg); } else { // FIXME: probably need to rework AttributesSetValues as well a bit if (count >= 15) { for (; count >= 15; count -= 15) { AttributesSetValuesMessage msg = new AttributesSetValuesMessage(); msg.ActorID = _parent.DynamicID; msg.atKeyVals = new Mooege.Net.GS.Message.Fields.NetAttributeKeyValue[15]; for (int i = 0; i < 15; i++) msg.atKeyVals[i] = new Mooege.Net.GS.Message.Fields.NetAttributeKeyValue(); for (int i = 0; i < 15; i++) { KeyId keyid; if (!e.MoveNext()) { if (level) { keyid = new KeyId { Id = GameAttribute.Level.Id }; level = false; } else { throw new Exception("Expected values in enumerator."); } } else { keyid = e.Current; } var kv = msg.atKeyVals[i]; if (level && keyid.Id == GameAttribute.Level.Id) { i--; continue; } var value = _attributeValues[keyid]; var id = keyid.Id; kv.Field0 = keyid.Key; kv.Attribute = GameAttribute.Attributes[id]; if (kv.Attribute.IsInteger) kv.Int = value.Value; else kv.Float = value.ValueF; } messageList.Add(msg); } } if (count > 0) { AttributesSetValuesMessage msg = new AttributesSetValuesMessage(); msg.ActorID = _parent.DynamicID; msg.atKeyVals = new Mooege.Net.GS.Message.Fields.NetAttributeKeyValue[count]; for (int i = 0; i < count; i++) { KeyId keyid; if (!e.MoveNext()) { if (level) { keyid = new KeyId { Id = GameAttribute.Level.Id }; level = false; } else { throw new Exception("Expected values in enumerator."); } } else { keyid = e.Current; } var kv = new Mooege.Net.GS.Message.Fields.NetAttributeKeyValue(); msg.atKeyVals[i] = kv; if (level && keyid.Id == GameAttribute.Level.Id) { i--; continue; } var value = _attributeValues[keyid]; var id = keyid.Id; kv.Field0 = keyid.Key; kv.Attribute = GameAttribute.Attributes[id]; if (kv.Attribute.IsInteger) kv.Int = value.Value; else kv.Float = value.ValueF; } messageList.Add(msg); } } return messageList; }
public void SendMessage(GameClient client, int actorId) { int count = _attributeValues.Count; if (_attributeValues.Count == 1) { AttributeSetValueMessage msg = new AttributeSetValueMessage(); msg.Id = (int)Opcodes.AttributeSetValueMessage; var e = _attributeValues.GetEnumerator(); if (!e.MoveNext()) throw new Exception("Expected value in enumerator."); var keyid = e.Current.Key; var value = e.Current.Value; int id = keyid.Id; msg.Field0 = actorId; msg.Field1 = new Fields.NetAttributeKeyValue(); msg.Field1.Field0 = keyid.Key; // FIXME: need to rework NetAttributeKeyValue, and maybe rename GameAttribute to NetAttribute? msg.Field1.Attribute = GameAttribute.Attributes[id]; // FIXME if (msg.Field1.Attribute.IsInteger) msg.Field1.Int = value.Value; else msg.Field1.Float = value.ValueF; client.SendMessage(msg); } else { AttributesSetValuesMessage msg = new AttributesSetValuesMessage(); msg.Id = (int)Opcodes.AttributesSetValuesMessage; msg.Field0 = actorId; var e = _attributeValues.GetEnumerator(); // FIXME: probably need to rework AttributesSetValues as well a bit if (count >= 15) { msg.atKeyVals = new Fields.NetAttributeKeyValue[15]; for (int i = 0; i < 15; i++) msg.atKeyVals[i] = new Fields.NetAttributeKeyValue(); for (; count >= 15; count -= 15) { for(int i = 0;i < 15;i++) { if (!e.MoveNext()) throw new Exception("Expected values in enumerator."); var kv = msg.atKeyVals[i]; var keyid = e.Current.Key; var id = keyid.Id; var value = e.Current.Value; kv.Field0 = keyid.Key; kv.Attribute = GameAttribute.Attributes[id]; if (kv.Attribute.IsInteger) kv.Int = value.Value; else kv.Float = value.ValueF; } client.SendMessage(msg); } } if (count > 0) { msg.atKeyVals = new Fields.NetAttributeKeyValue[count]; for (int i = 0; i < count; i++) { if (!e.MoveNext()) throw new Exception("Expected values in enumerator."); var kv = new Fields.NetAttributeKeyValue(); msg.atKeyVals[i] = kv; var keyid = e.Current.Key; var id = keyid.Id; var value = e.Current.Value; kv.Field0 = keyid.Key; kv.Attribute = GameAttribute.Attributes[id]; if (kv.Attribute.IsInteger) kv.Int = value.Value; else kv.Float = value.ValueF; } client.SendMessage(msg); } } }