Ejemplo n.º 1
0
        protected override void Send(GameObject target)
        {
            var toMovePlanes = new List <int>();

            for (var i = 0; i < Island.transform.childCount; ++i)
            {
                var ship     = Island.transform.GetChild(i).gameObject;
                var shipData = ship.GetComponent <ShipData>(); // possibly cachable
                if (shipData == null)
                {
                    continue;                   // skip non ship gameobjects
                }
                if (shipData.PlayerData.uid == Game.Shared.ClientUid)
                {
                    toMovePlanes.Add(shipData.uid);
                }
            }
            ;

            Deselect();

            Debug.Log("request move-units: " + PackageFactory.CreateMoveUnitMessage(target.GetComponent <IslandData>().Uid, toMovePlanes.ToArray()));

            var json = PackageFactory.CreateMoveUnitMessage(target.GetComponent <IslandData>().Uid, toMovePlanes.ToArray());

            SocketHandler.EmitNow("move-unit", json);

            Move(json);
        }
        /**
         * a += i1
         * b += i2
         *
         * (b-a) * t + a
         * t = [0...1]
         */
        private static void Send()
        {
            if (!Game.IsRunning())
            {
                return;
            }

            for (var i = 0; i < _selected.Count - 1; ++i)
            {
                //Debug.Log("send " + _selected[i] + " to " + _selected[_selected.Count - 1]);

                var source      = Registry.Islands[_selected[i]];
                var destination = Registry.Islands[_selected[_selected.Count - 1]];

                var toMovePlanes = new List <int>();

                foreach (var pair in Registry.Ships)
                {
                    // UnityEngine.Debug.Log("bla: " + (source.transform == Registry.Instance.Ships[pair.Key].transform.parent));
                    if (source.transform == Registry.Ships[pair.Key].transform.parent)
                    {
                        var plane = Registry.Ships[pair.Key];

                        // only move if you own it
                        if (plane.GetComponent <ShipData>().PlayerData.uid != Game.Shared.ClientUid)
                        {
                            continue;
                        }

                        if (plane.GetComponent <ShipData>().uid != pair.Key)
                        {
                            Debug.Log("WARNING! ship id != registry id on move-units");
                        }

                        // add to move-unit list
                        toMovePlanes.Add(pair.Key);
                    }
                }
                if (toMovePlanes.Count > 0)
                {
                    SocketHandler.Emit("move-unit", PackageFactory.CreateMoveUnitMessage(destination.GetComponent <IslandData>().Uid, toMovePlanes.ToArray()));
                }
            }
        }