예제 #1
0
파일: Mob.cs 프로젝트: GrindFest/GrindFest
        private void OnEnterZone(EnterZonePayload payload)
        {
            var transform = this.Components.Get<TransformComponent>();
            var visual = this.Components.Get<Visual>();
            var attributes = this.Components.Get<AttributeContainer>();
            var tagged = this.Components.Get<Tagged>();

            ServerMobCreatePacket packet = new ServerMobCreatePacket();
            packet.Name = tagged.Name;
            packet.Sprite = visual.Sprite;
            packet.Id = Zoned.Id;
            packet.Position = transform.Position;

            packet.Attributes = new System.Collections.Generic.List<AttributeKeyValue>();

            foreach (ActorAttribute item in attributes.Attributes)
            {
                if (!item.Template.IsComputed)
                {
                    packet.Attributes.Add(new AttributeKeyValue(item.Template.AttributeId, item.Value));
                }
            }

            if (payload.Zoned == this.Zoned) // Its me who entered the zone
            {
                this.Zoned.Broadcast(packet); // Send my info to everyone
            }
            else // Someone else entered the zone
            {
                payload.Zoned.Send(packet); // Send my info to him
            }
        }
예제 #2
0
        public override void OnGameObjectAdded(GameObject gameObject)
        {
            base.OnGameObjectAdded(gameObject);

            // Assign id when this components comes into world
            if (gameObject.Components.Contains<Zoned>()) // Zoned system is interested only in zoned components TODO: this should be handled in GameSystem
            {
                var zoned = gameObject.Components.Get<Zoned>();
                zoned.Id = _lastId++;

                var payload = new EnterZonePayload(zoned);

                zoned.SendMessage(payload);

                foreach (var otherZoned in this.Zoneds)
                {
                    if (otherZoned != zoned)
                    {
                        otherZoned.SendMessage(payload);
                    }
                }
            }
        }