Exemplo n.º 1
0
        public void Sim1000ms(float dt)
        {
            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("got_object", x, y);

            if (outstanding && message != null)
            {
                outstanding = false;
                // We have a response from the server, finally ya lazy basterd
                if (message["object"] != null &&
                    message["object"].Type == JTokenType.String)
                {
                    GameObject opaque_object = convert_to_gameobject((string)message["object"]);
                    storage.Store(opaque_object); // Note: We are not *adding*
                                                  // we are *storing*
                }
            }
            // Only send when we are enabled
            if (!outstanding && !storage.IsFull() && ztransporter.is_enabled())
            {
                // Send a message to the server asking for an object

                message = Network.make_message("recv_object", x, y);
                Z.net.send_message(message);
                outstanding = true;
            }

            return;
        }
Exemplo n.º 2
0
        #pragma warning restore 0649

        public override void EnergySim200ms(float dt)
        {
            base.EnergySim200ms(dt);
            //this.AssignJoulesAvailable(Math.Min(this.JoulesAvailable, this.WattageRating * dt));

            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("got_joules", x, y);

            if (outstanding && message != null)
            {
                // We got a response from the server, check it out

                // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -SB
                int amount_to_add = (int)message["joules"];
                if (amount_to_add > 0)
                {
                    this.GenerateJoules(amount_to_add, true);
                }
                // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa. -SB
                outstanding = false;
            }
            // Only send a message if we need to, AND the building has not been
            // disabled
            if (!outstanding && ztransporter.is_enabled())
            {
                // Time to make a message to send to the server
                int amount_to_request = (int)(this.Capacity - this.JoulesAvailable);
                if (amount_to_request > 0)
                {
                    message = Network.make_message("recv_joules", x, y);
                    message["max_joules"] = amount_to_request;
                    Z.net.send_message(message);
                    outstanding = true;
                }
            }
        }
Exemplo n.º 3
0
        private PrimaryElement FindSuitableElement()
        {
            PrimaryElement ret = null;
            // Maybe make it buffer an extra message, that might help?

            // better version: grab stuff from our ass, I mean network - BR

            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("got_packet", x, y);

            if (outstanding && message != null)
            {
                outstanding = false;
                // We have a response from the server, finally ya lazy basterd
                if (message["packet"] != null &&
                    message["packet"].Type == JTokenType.Object)
                {
                    JObject mat_packet  = (JObject)message["packet"];
                    JObject germ_packet = null;
                    if (mat_packet["germs"] != null &&
                        mat_packet["germs"].Type == JTokenType.Object)
                    {
                        germ_packet = (JObject)mat_packet["germs"];
                    }
                    if (dave == null)
                    {
                        dave = GasSourceManager.Instance.CreateChunk(
                            (SimHashes)(-1528777920), 0f, 456f,
                            255, 0, this.transform.GetPosition());
                        steve = dave.GetComponent <PrimaryElement>();
                        steve.KeepZeroMassObject = true;
                    }
                    steve.SetElement((SimHashes)((int)mat_packet["element"]));
                    steve.SetMassTemperature((float)mat_packet["mass"],
                                             (float)mat_packet["temperature"]);
                    string reason = conduitType == ConduitType.Liquid
                        ? "Storage.AddLiquid" : "Storage.AddGasChunk";
                    steve.ModifyDiseaseCount(-steve.DiseaseCount, reason);
                    if (germ_packet != null)
                    {
                        steve.AddDisease((byte)germ_packet["id"],
                                         (int)germ_packet["count"],
                                         reason);
                    }

                    message = null;

                    ret = steve;
                }
            }
            // Only ask for goodies when we are enabled
            if (!outstanding && ztransporter.is_enabled())
            {
                // Send a message to the server asking for goodies

                message = Network.make_message("recv_packet", x, y);
                message.Add("phase", this.conduitType == ConduitType.Liquid ?
                            "Liquid" : "Gas");
                Z.net.send_message(message);
                outstanding = true;
            }
            return(ret);
        }