Пример #1
0
        public override bool Spawn(bool placing = false)
        {
            if (!(data.Has("sourceid", "destid", "sourcechildid", "destchildid")))
            {
                return(false);
            }

            uint sourceid = uint.Parse(data.Get("sourceid"));
            uint destid   = uint.Parse(data.Get("destid"));

            sourcechildid = uint.Parse(data.Get("sourcechildid"));
            destchildid   = uint.Parse(data.Get("destchildid"));

            sourcecont = GetChildContainer(BaseNetworkable.serverEntities.Find(sourceid), sourcechildid);
            destcont   = GetChildContainer(BaseNetworkable.serverEntities.Find(destid), destchildid);

            if (sourcecont == null || destcont == null || sourcecont == destcont)
            {
                return(false);
            }

            sourceContainerIconUrl = Icons.GetContainerIconURL(sourcecont, 100);
            destContainerIconUrl   = Icons.GetContainerIconURL(destcont, 100);

            isWaterPipe     = sourcecont is LiquidContainer;
            destisstartable = IsStartable(destcont);
            flowrate        = flowrates[int.Parse(data.Get("grade", "0"))];
            mode            = (Mode)int.Parse(data.Get("mode", "0"));

            startPosition = sourcecont.CenterPoint() + ContainerOffset.Get(sourcecont);
            endPosition   = destcont.CenterPoint() + ContainerOffset.Get(destcont);

            distance = Vector3.Distance(startPosition, endPosition);
            Quaternion rotation = Quaternion.LookRotation(endPosition - startPosition);

            //isStartable();

            // spawn pillars

            int   segments = (int)Mathf.Ceil(distance / pipesegdist);
            float segspace = (distance - pipesegdist) / (segments - 1);

            startPosition += ((rotation * Vector3.forward) * pipesegdist * 0.5f) + ((rotation * Vector3.down) * 0.7f);

            for (int i = 0; i < segments; i++)
            {
                // create pillar

                BaseEntity ent;

                if (i == 0)
                {
                    // the position thing centers the pipe if there is only one segment
                    ent = GameManager.server.CreateEntity("assets/prefabs/building core/wall.low/wall.low.prefab", (segments == 1) ? (startPosition + ((rotation * Vector3.up) * ((distance - pipesegdist) * 0.5f))) : startPosition, rotation);
                    data.SetTransform(ent.transform);
                    SetMainParent((BaseCombatEntity)ent);
                }
                else
                {
                    ent = GameManager.server.CreateEntity("assets/prefabs/building core/wall.low/wall.low.prefab", Vector3.forward * (segspace * i) + ((i % 2 == 0) ? Vector3.zero : pipefightoffset));
                    //ent = GameManager.server.CreateEntity("assets/prefabs/building core/pillar/pillar.prefab", startPosition);
                }

                ent.enableSaving = false;

                BuildingBlock block = ent.GetComponent <BuildingBlock>();

                if (block != null)
                {
                    block.grounded     = true;
                    block.grade        = (BuildingGrade.Enum) int.Parse(data.Get("grade", "0"));
                    block.enableSaving = false;
                    block.Spawn();
                    block.SetHealthToMax();
                }
                else
                {
                    return(false);
                }


                //((DecayEntity) ent).GetNearbyBuildingBlock();

                if (i != 0)
                {
                    if (placing)                       // placing animation
                    {
                        ent.gameObject.AddComponent <Child>()?.RunDelayed(i * 0.2f, () => {
                            AddChildEntity((BaseCombatEntity)ent);
                            Effect.server.Run("assets/bundled/prefabs/fx/build/promote_wood.prefab", ent.transform.position + (ent.transform.up * (segspace * 0.5f)), Vector3.up);
                        });
                    }
                    else
                    {
                        AddChildEntity((BaseCombatEntity)ent);
                    }
                }

                // xmas lights

                //BaseEntity lights = GameManager.server.CreateEntity("assets/prefabs/misc/xmas/christmas_lights/xmas.lightstring.deployed.prefab", (Vector3.up * pipesegdist * 0.5f) + (Vector3.forward * 0.13f) + (Vector3.up * (segspace * i) + ((i % 2 == 0) ? Vector3.zero : pipefightoffset)), Quaternion.Euler(0, -60, 90));
                //lights.Spawn();
                //AddChildEntity((BaseCombatEntity) lights);
            }

            if (placing)
            {
                SetHealth(GetEntities()[0].MaxHealth());
            }
            else
            {
                SetHealth(data.health);
            }

            return(true);
        }