protected override void Create() {
			// 初始化下單物件,Contracts.UserSpecified 可指定規模,OrderExit.FromAll 可一次全平
			BUY = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.UserSpecified, EOrderAction.Buy, OrderExit.FromAll));
			SELL = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.UserSpecified, EOrderAction.SellShort, OrderExit.FromAll));
			BUY_C = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell, OrderExit.FromAll));
			SELL_C = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.BuyToCover, OrderExit.FromAll));

			__cKD = new KD(this);
		}
Example #2
0
    /// <summary>
    /// Facebook score api callback to load the 30 first facebook friends by score.
    /// After that is made the Firebase load to get KD values by player.
    /// </summary>
    /// <param name="result">callback result.</param>
    void ScoreAndKDCallback(IResult result)
    {
        _facebookPlayers = new List <Player> ();

        if (result.ResultDictionary.ContainsKey("data"))
        {
            IDictionary <string, object> data = result.ResultDictionary;
            List <object> listObj             = (List <object>)data ["data"];

            if (_reference == null)
            {
                FirebaseApp.DefaultInstance.SetEditorDatabaseUrl(UtilBehaviour.FIREBASE_REALTIME_DATABASE_PATH);
                _reference = FirebaseDatabase.DefaultInstance.RootReference;
            }

            _reference.Child(UtilBehaviour.ROOT).Child(_localPlayer._id).Child(UtilBehaviour.GROUP).GetValueAsync().ContinueWith(task => {
                if (task.IsFaulted)
                {
                    _facebookPlayersObserver.OnError();
                }
                else if (task.IsCompleted)
                {
                    DataSnapshot snapshot = task.Result;

                    foreach (object obj in listObj)
                    {
                        var entry = (Dictionary <string, object>)obj;
                        var user  = (Dictionary <string, object>)entry ["user"];

                        string id     = user ["id"].ToString();
                        string name   = user ["name"].ToString();
                        int highscore = Int32.Parse(entry ["score"].ToString());
                        int k         = 0, d = 0;

                        if (snapshot.Child(id).Value != null)
                        {
                            k = Int32.Parse(snapshot.Child(id).Child("K").Value.ToString());
                            d = Int32.Parse(snapshot.Child(id).Child("D").Value.ToString());
                        }

                        KD kd = null;
                        if (_localPlayer._id != id)
                        {
                            kd = new KD(k, d);
                        }

                        Player friendPlayer = new Player(id, name, highscore, kd);
                        _facebookPlayers.Add(friendPlayer);
                    }

                    _facebookPlayersObserver.OnNotify();
                }
            });
        }
    }
Example #3
0
    /// <summary>
    /// Save on Firebase database the new KD. Two request are made to save values by player who was destroyed.
    /// KD values are key-value below a ID player. That ID is the same use on Facebook Api, so the player need to be logged.
    /// ID Player (local player)
    ///    - KD
    ///        - ID player (player who destroyed local player)
    ///             - K : value
    ///             - D : value
    ///
    /// </summary>
    /// <param name="id">Player id</param>
    public void SaveNewKD(string id)
    {
        if (!FB.IsLoggedIn)
        {
            return;
        }

        if (_reference == null)
        {
            FirebaseApp.DefaultInstance.SetEditorDatabaseUrl(UtilBehaviour.FIREBASE_REALTIME_DATABASE_PATH);
            _reference = FirebaseDatabase.DefaultInstance.RootReference;
        }


        //Load KD values by foe id
        _reference.Child(UtilBehaviour.ROOT).Child(_localPlayer._id).Child(UtilBehaviour.GROUP).Child(id).GetValueAsync().ContinueWith(task => {
            if (task.IsFaulted)
            {
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;

                if (snapshot.Value != null)
                {
                    int k = Int32.Parse(snapshot.Child("K").Value.ToString());
                    int d = Int32.Parse(snapshot.Child("D").Value.ToString());

                    k += 1;

                    //Save new KD to player who destroyed the local player
                    KD playerKill = new KD(k, d);
                    string json   = JsonUtility.ToJson(playerKill);
                    _reference.Child(UtilBehaviour.ROOT).Child(_localPlayer._id).Child(UtilBehaviour.GROUP).Child(id).SetRawJsonValueAsync(json);

                    //Save new KD to local player
                    KD playerDead = new KD(d, k);
                    string json2  = JsonUtility.ToJson(playerDead);
                    _reference.Child(UtilBehaviour.ROOT).Child(id).Child(UtilBehaviour.GROUP).Child(_localPlayer._id).SetRawJsonValueAsync(json2);
                }
                else
                {
                    //First interaction between two player
                    KD initialKill = new KD(1, 0);
                    string json    = JsonUtility.ToJson(initialKill);
                    _reference.Child(UtilBehaviour.ROOT).Child(_localPlayer._id).Child(UtilBehaviour.GROUP).Child(id).SetRawJsonValueAsync(json);

                    KD initialDead = new KD(0, 1);
                    string json2   = JsonUtility.ToJson(initialDead);
                    _reference.Child(UtilBehaviour.ROOT).Child(id).Child(UtilBehaviour.GROUP).Child(_localPlayer._id).SetRawJsonValueAsync(json2);
                }
            }
        });
    }
Example #4
0
    /// <summary>
    /// Sets the scoreboard cell values.
    /// </summary>
    /// <param name="position">Player position.</param>
    /// <param name="image">Facebook picture.</param>
    /// <param name="name">Players name.</param>
    /// <param name="kd">Players Kd.</param>
    /// <param name="highScore">Players High score.</param>
    public void SetValues(int position, Sprite image, string name, KD kd, int highScore)
    {
        transform.localScale = Vector3.one;

        _positionText.text   = position.ToString("00");
        _pictureImage.sprite = image;
        _nameText.text       = name;

        if (kd != null)
        {
            _kText.text = kd._k.ToString();
            _dText.text = kd._d.ToString();
        }

        _highScoreText.text = highScore.ToString();
    }
        void ComboBox1SelectedIndexChanged(object sender, EventArgs e)
        {
            // wczytanie listy wejść do wyboru
            KD kd = comboBox1.SelectedItem as KD;

            comboBox2.Items.Clear();
            comboBox2.Enabled = kd != null;
            if (kd != null)
            {
                int en = kd.Device.KeysCount / 2;
                for (int i = 0; i < en; i++)
                {
                    bool jest = false;
                    for (int j = 0; j < _configuration.Encoders.Length; j++)
                    {
                        if (_configuration.Encoders[j].KeysDevice == kd.Device)
                        {
                            if (_configuration.Encoders[j] == _encoder)
                            {
                                continue;
                            }
                            if (_configuration.Encoders[j].Index == i)
                            {
                                jest = true;
                                break;
                            }
                        }
                    }
                    if (!jest)
                    {
                        comboBox2.Items.Add(new EI()
                        {
                            Index = i
                        });
                    }
                }
            }
        }
		protected override void Create() {
			// 初始化下單物件,Contracts.UserSpecified 可指定規模,OrderExit.FromAll 可一次全平
			多單 = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, EOrderAction.Buy));
			空單 = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, EOrderAction.SellShort));
			多沖 = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell, OrderExit.FromAll));
			空沖 = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.BuyToCover, OrderExit.FromAll));

			__cService = OrderCreator as AbstractOrderService;

			__cTimer = new Timer(1);
			__cTimer.AutoReset = false;
			__cTimer.Elapsed += Timer_onElapsed;
			//__cTimer.Start();

			//bbb = BarsOfData(2);
			cBuilder.AppendLine("[F000]");

			__cKDSum = new VariableSeries<double>(this);

			__cMACD = new MACD(this);
			__cMACD.FastPeriod = 5;
			__cMACD.SlowPeriod = 10;
			__cMACD.MACDPeriod = 10;

			__cKD = new KD(this);
			__cKD.Length = 5;
		}
Example #7
0
 public Player(string id, string name, int highscore, KD kd)
     : this(id, name)
 {
     _highScore = highscore;
     _kd        = kd;
 }
Example #8
0
        internal void Spawn()
        {
            KD kd = new KD();

            Log.Info("Spawning a GeoCache");

            // Set additional info for landed
            if (kd.landed)
            {
                Vector3d pos = kd.body.GetWorldSurfacePosition(kd.latitude, kd.longitude, kd.altitude);

                kd.orbit = new Orbit(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, kd.body);
                kd.orbit.UpdateFromStateVectors(pos, kd.body.getRFrmVel(pos), kd.body, Planetarium.GetUniversalTime());
            }
            else
            {
                // Update the reference body in the orbit
                kd.orbit.referenceBody = kd.body;
            }

            uint flightId = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);


            kd.craftPart = PartLoader.getPartInfoByName("geocache");
            // Create part nodes
            ConfigNode[] partNodes = new ConfigNode[1];
            partNodes[0] = ProtoVessel.CreatePartNode(kd.craftPart.name, flightId, null);


            // Create additional nodes
            ConfigNode[] additionalNodes = new ConfigNode[0];
            // Create the config node representation of the ProtoVessel
            ConfigNode protoVesselNode = ProtoVessel.CreateVesselNode(VesselName, VesselType.Probe, kd.orbit, 0, partNodes);

            // Additional seetings for a landed vessel
            if (kd.landed)
            {
                bool splashed = kd.altitude < 0.001 && kd.body.ocean;

                // Add a bit of height for landed
                if (!splashed)
                {
                    kd.altitude += 40.2;
                    Log.Info("Adding 40.2 to altitude");
                }
                //Guid vesselId = vessel.id;

                // Figure out the appropriate rotation
                Vector3d norm          = kd.body.GetRelSurfaceNVector(kd.latitude, kd.longitude);
                double   terrainHeight = 0.0;
                if (kd.body.pqsController != null)
                {
                    terrainHeight = kd.body.pqsController.GetSurfaceHeight(norm) - kd.body.pqsController.radius;
                }

                // Create the config node representation of the ProtoVessel

                protoVesselNode.SetValue("sit", (splashed ? Vessel.Situations.SPLASHED : Vessel.Situations.LANDED).ToString());
                protoVesselNode.SetValue("landed", (!splashed).ToString());
                protoVesselNode.SetValue("splashed", splashed.ToString());
                protoVesselNode.SetValue("lat", kd.latitude);
                protoVesselNode.SetValue("lon", kd.longitude);
                protoVesselNode.SetValue("alt", kd.altitude);
                protoVesselNode.SetValue("landedAt", kd.body.name);

                float lowest = float.MaxValue;
                foreach (Collider collider in kd.craftPart.partPrefab.GetComponentsInChildren <Collider>())
                {
                    if (collider.gameObject.layer != 21 && collider.enabled)
                    {
                        lowest = Mathf.Min(lowest, collider.bounds.min.y);
                    }
                }
                if (Mathf.Approximately(lowest, float.MaxValue))
                {
                    lowest = 0;
                }

                float hgt = kd.craftPart.partPrefab.localRoot.attPos0.y - lowest;
                hgt += 10;
                protoVesselNode.SetValue("hgt", hgt);

                // Set the normal vector relative to the surface
                Quaternion normal   = Quaternion.LookRotation(new Vector3((float)norm.x, (float)norm.y, (float)norm.z));
                Quaternion rotation = Quaternion.identity;
                rotation = rotation * Quaternion.FromToRotation(Vector3.up, Vector3.back);
                Vector3 nrm = (rotation * Vector3.forward);
                protoVesselNode.SetValue("prst", false.ToString());
                protoVesselNode.SetValue("nrm", nrm.x + "," + nrm.y + "," + nrm.z);
            }
            ProtoVessel protoVessel = HighLogic.CurrentGame.AddVessel(protoVesselNode);

            //protoVessel.Load(HighLogic.CurrentGame.flightState);

            protoVessel.vesselName = VesselName;

            vessel = protoVessel.vesselRef;
            if (vessel != null)
            {
                //var mode = OrbitDriver.UpdateMode.UPDATE;
                //vessel.orbitDriver.SetOrbitMode(mode);

                vessel.Load();
                launchPoint = vessel.GetWorldPos3D();
                // Offset the position by 10m in y and z to have it created away from the current vessel
                launchPoint.y += 10;
                launchPoint.z += 10;

                StartCoroutine("SpawnCoRoutine");
            }
        }
Example #9
0
 public override string ToString()
 {
     return($"{Name.PadRight(8, ' ')}{Rating.ToString("0.00").PadLeft(6, ' ')}{RWS.ToString("0.00").PadLeft(7, ' ')}{KD.ToString("0.00").PadLeft(6, ' ')}{ADR.ToString("0.0").PadLeft(7, ' ')}");
 }