Beispiel #1
0
        void TryStartItemConstruction(string prototypeName)
        {
            var prototype = _prototypeManager.Index <ConstructionPrototype>(prototypeName);

            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.
            EntitySystem.Get <AudioSystem>().PlayFromEntity("/Audio/items/deconstruct.ogg", Owner);
            if (prototype.Stages.Count == 2)
            {
                // Exactly 2 stages, so don't make an intermediate frame.
                var ent = _serverEntityManager.SpawnEntity(prototype.Result, Owner.Transform.GridPosition);
                hands.PutInHandOrDrop(ent.GetComponent <ItemComponent>());
            }
            else
            {
                //TODO: Make these viable as an item and try putting them in the players hands
                var frame        = _serverEntityManager.SpawnEntity("structureconstructionframe", Owner.Transform.GridPosition);
                var construction = frame.GetComponent <ConstructionComponent>();
                construction.Init(prototype);
            }
        }
Beispiel #2
0
        void TryStartStructureConstruction(GridCoordinates loc, string prototypeName, Angle angle, int ack)
        {
            var prototype = _prototypeManager.Index <ConstructionPrototype>(prototypeName);

            if (!InteractionChecks.InRangeUnobstructed(Owner, loc.ToMap(_mapManager),
                                                       ignoredEnt: Owner, insideBlockerValid: prototype.CanBuildInImpassable))
            {
                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.SpawnEntity(prototype.Result, loc);
                ent.Transform.LocalRotation = angle;
            }
            else
            {
                var frame        = _serverEntityManager.SpawnEntity("structureconstructionframe", loc);
                var construction = frame.GetComponent <ConstructionComponent>();
                construction.Init(prototype);
                frame.Transform.LocalRotation = angle;
            }

            var msg = new AckStructureConstructionMessage(ack);

            SendNetworkMessage(msg);
        }
Beispiel #3
0
        void TryStartStructureConstruction(GridCoordinates loc, string prototypeName, Angle angle, int ack)
        {
            var protoMan  = IoCManager.Resolve <IPrototypeManager>();
            var prototype = protoMan.Index <ConstructionPrototype>(prototypeName);

            var transform = Owner.GetComponent <ITransformComponent>();

            if (!loc.InRange(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.
            var entMgr      = IoCManager.Resolve <IServerEntityManager>();
            var AudioSystem = IoCManager.Resolve <IEntitySystemManager>().GetEntitySystem <AudioSystem>();

            AudioSystem.Play("/Audio/items/deconstruct.ogg", loc);
            if (prototype.Stages.Count == 2)
            {
                // Exactly 2 stages, so don't make an intermediate frame.
                var ent = entMgr.ForceSpawnEntityAt(prototype.Result, loc);
                ent.GetComponent <ITransformComponent>().LocalRotation = angle;
            }
            else
            {
                var frame        = entMgr.ForceSpawnEntityAt("structureconstructionframe", loc);
                var construction = frame.GetComponent <ConstructionComponent>();
                construction.Init(prototype);
                frame.GetComponent <ITransformComponent>().LocalRotation = angle;
            }

            var msg = new AckStructureConstructionMessage(ack);

            SendNetworkMessage(msg);
        }