コード例 #1
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);
        }