예제 #1
0
        private void LoadEntity(XElement element, IMap map)
        {
            var X = float.Parse(element.Attribute("X").Value, CultureInfo.InvariantCulture);
            var Y = float.Parse(element.Attribute("Y").Value, CultureInfo.InvariantCulture);

            var dir = Direction.South;

            if (element.Attribute("direction") != null)
            {
                dir = (Direction)Enum.Parse(typeof(Direction), element.Attribute("direction").Value, true);
            }

            string  prototype = element.Attribute("template").Value;
            IEntity entity;

            try
            {
                entity = entityManager.ForceSpawnEntityAt(prototype, new LocalCoordinates(X, Y, 1, map.Index));
            }
            catch (UnknownPrototypeException)
            {
                Logger.Error($"Unknown prototype '{prototype}'!");
                return;
            }
            var nameElement = element.Attribute("name");

            if (nameElement != null)
            {
                entity.Name = nameElement.Value;
            }
            entity.GetComponent <IServerTransformComponent>().Rotation = dir.ToAngle();
        }
        /// <summary>
        /// Spawns the players entity.
        /// </summary>
        /// <param name="session"></param>
        public void SpawnPlayerMob(IPlayerSession session)
        {
            //TODO: There's probably a much better place to do this.
            IEntity entity = _entityManager.ForceSpawnEntityAt("HumanMob", new Vector2(0, 0));

            session.AttachToEntity(entity);
        }
예제 #3
0
        /// <summary>
        /// Spawns the players entity.
        /// </summary>
        /// <param name="session"></param>
        public void SpawnPlayerMob(IPlayerSession session)
        {
            // TODO: There's probably a much better place to do this.
            var prototype = "HumanMob";

            if (_prototypeManager.HasIndex <EntityPrototype>("HumanMob_Content"))
            {
                prototype = "HumanMob_Content";
            }
            IEntity entity = _entityManager.ForceSpawnEntityAt(prototype, new Vector2(0, 0), 1); //TODO: Fix this

            session.AttachToEntity(entity);
        }
예제 #4
0
        /// <summary>
        ///     Spawns the players entity.
        /// </summary>
        /// <param name="session"></param>
        public void SpawnPlayerMob(IPlayerSession session)
        {
            var entity = _entityManager.ForceSpawnEntityAt(PlayerPrototypeName, FallbackSpawnPoint);

            session.AttachToEntity(entity);
        }
예제 #5
0
        /// <summary>
        /// Spawns the players entity.
        /// </summary>
        /// <param name="session"></param>
        public void SpawnPlayerMob(IPlayerSession session)
        {
            IEntity entity = _entityManager.ForceSpawnEntityAt(PlayerPrototypeName, new Vector2(0, 0), 1); //TODO: Fix this

            session.AttachToEntity(entity);
        }
예제 #6
0
        void TryStartStructureConstruction(GridCoordinates loc, string prototypeName, Angle angle, int ack)
        {
            var prototype = _prototypeManager.Index <ConstructionPrototype>(prototypeName);

            var transform = Owner.Transform;

            if (!loc.InRange(_mapManager, transform.GridPosition, InteractionSystem.INTERACTION_RANGE))
            {
                return;
            }

            if (prototype.Stages.Count < 2)
            {
                throw new InvalidOperationException($"Prototype '{prototypeName}' does not have enough stages.");
            }

            var stage0 = prototype.Stages[0];

            if (!(stage0.Forward is ConstructionStepMaterial matStep))
            {
                throw new NotImplementedException();
            }

            // Try to find the stack with the material in the user's hand.
            var hands      = Owner.GetComponent <HandsComponent>();
            var activeHand = hands.GetActiveHand?.Owner;

            if (activeHand == null)
            {
                return;
            }

            if (!activeHand.TryGetComponent(out StackComponent stack) || !ConstructionComponent.MaterialStackValidFor(matStep, stack))
            {
                return;
            }

            if (!stack.Use(matStep.Amount))
            {
                return;
            }

            // OK WE'RE GOOD CONSTRUCTION STARTED.
            _entitySystemManager.GetEntitySystem <AudioSystem>().Play("/Audio/items/deconstruct.ogg", loc);
            if (prototype.Stages.Count == 2)
            {
                // Exactly 2 stages, so don't make an intermediate frame.
                var ent = _serverEntityManager.ForceSpawnEntityAt(prototype.Result, loc);
                ent.Transform.LocalRotation = angle;
            }
            else
            {
                var frame        = _serverEntityManager.ForceSpawnEntityAt("structureconstructionframe", loc);
                var construction = frame.GetComponent <ConstructionComponent>();
                construction.Init(prototype);
                frame.Transform.LocalRotation = angle;
            }

            var msg = new AckStructureConstructionMessage(ack);

            SendNetworkMessage(msg);
        }