Esempio n. 1
0
        static public void ChangeConstructionAmount(Constructable target, bool constructing)
        {
            if (Multiplayer.main.blocked)
            {
                return;
            }

            if (buildConstructActive)
            {
                return;
            }

            var res = new ClientBuildConstructChange();

            res.objectGuid     = GuidHelper.Get(target.gameObject);
            res.baseGuid       = GuidHelper.Get(GetNewBase());
            res.moduleGuid     = GuidHelper.Get(GetNewModule());
            res.tech           = CraftData.GetTechType(target.gameObject);
            res.objectPosition = target.gameObject.transform.position;
            res.amount         = target.constructedAmount;
            res.state          = target.constructed;
            res.constructing   = constructing;

            if (res.amount == 0f && constructing)
            {
                return;
            }

            if (res.state || (res.amount == 0f && !constructing) || (res.amount == 1f && constructing) || rateLimiter.Update(0.500f))
            {
                Multiplayer.main.Send(res);
            }
        }
Esempio n. 2
0
        private void Process(ClientBuildConstructChange msg)
        {
            var target = GuidHelper.FindComponent <Constructable>(msg.objectGuid);

            if (target == null)
            {
                Log.Info("Couldn't find constructable: " + msg.tech);
                return;
            }

            Logic.Building.buildConstructActive = true;
            Logic.Building.SetNewModule(null);

            try {
                if (target.constructed)
                {
                    target.SetState(false, false);
                }

                target.constructedAmount = msg.amount;

                if (msg.constructing)
                {
                    target.Construct();
                }
                else
                {
                    target.Deconstruct();
                }

                if (msg.state)
                {
                    target.SetState(true, true);

                    GuidHelper.Set(Logic.Building.GetNewBase(), msg.baseGuid);
                    GuidHelper.Set(Logic.Building.GetNewModule(), msg.moduleGuid);
                }
            } catch (Exception exception) {
                UnityEngine.Debug.LogException(exception);
            }

            Logic.Building.buildConstructActive = false;
        }