コード例 #1
0
ファイル: Side.cs プロジェクト: ice0001/Cubes-in-Space
 public void TakeSide(LaunchPacket info, int team)
 {
     if (timeToBeTaken < 0 || // if there is no time to be taken
         info.GameTimeETA < timeToBeTaken && timeLastTaken + LOCKINTERVAL < info.GameTimeETA)//if eta is less then the current time to be taken and we can take it becuase its not locked
     {
         timeToBeTaken = info.GameTimeETA;
         Debug.Log("TAke at: " + timeToBeTaken);
         currentTeamClaim = team;
     }
 }
コード例 #2
0
    public void ReceiveLaunchData(LaunchPacket launchMessage)
    {
        Avatar avatarScript = this.GetComponent<Avatar>();
        double deltaTime = launchMessage.LocalGameTime - TimeManager.Instance.ClientTimeStamp;
        Debug.Log("CubeID: " + launchMessage.CubeID);
        Debug.Log("SideID: " + launchMessage.SideID);
        avatarScript.TargetPosition = launchMessage.LaunchDestination;
        GameObject side = GameManager.Instance.GetSide(launchMessage.CubeID, launchMessage.SideID);
        side.GetComponent<Side>().TakeSide(launchMessage, avatarScript.team, false);

        //Debug.Log(this.transform.position)		this.transform.LookAt(launchMessage.LaunchDestination);
    }
コード例 #3
0
ファイル: Side.cs プロジェクト: eric-kansas/Cubes-in-Space
    public void TakeSide(LaunchPacket info, int team, bool isPlayer = false)
    {
        //owned by same team

        if (info.Paint)
        {
            if (timeToBeTaken < 0 || // if there is no time to be taken
            info.GameTimeETA < timeToBeTaken && timeLastTaken + LOCKINTERVAL < info.GameTimeETA)//if eta is less then the current time to be taken and we can take it becuase its not locked
            {
                willPaint = true;
            }
        }

        timeToBeTaken = info.GameTimeETA;
        currentTeamClaim = team;
        _isPlayer = isPlayer;
    }
コード例 #4
0
        public IHttpActionResult GetLaunchPacket(string deviceIdentifier = null)
        {
            var site = MobileHelper.GetCurrentApplicationSite();
            var additionalSettings = site?.AdditionalSettings.FromJsonOrNull <AdditionalSiteSettings>();
            var rockContext        = new Rock.Data.RockContext();
            var person             = GetPerson(rockContext);
            var deviceData         = Request.GetHeader("X-Rock-DeviceData").FromJsonOrNull <DeviceData>();

            if (additionalSettings == null || !additionalSettings.LastDeploymentDate.HasValue)
            {
                return(NotFound());
            }

            var launchPacket = new LaunchPacket
            {
                LatestVersionId     = ( int )(additionalSettings.LastDeploymentDate.Value.ToJavascriptMilliseconds() / 1000),
                IsSiteAdministrator = site.IsAuthorized(Authorization.EDIT, person)
            };

            if (deviceData.DeviceType == DeviceType.Phone)
            {
                launchPacket.LatestVersionSettingsUrl = additionalSettings.PhoneUpdatePackageUrl;
            }
            else if (deviceData.DeviceType == DeviceType.Tablet)
            {
                launchPacket.LatestVersionSettingsUrl = additionalSettings.TabletUpdatePackageUrl;
            }
            else
            {
                return(NotFound());
            }

            if (person != null)
            {
                var principal = ControllerContext.Request.GetUserPrincipal();

                launchPacket.CurrentPerson           = MobileHelper.GetMobilePerson(person, site);
                launchPacket.CurrentPerson.AuthToken = MobileHelper.GetAuthenticationToken(principal.Identity.Name);
            }

            //
            // Get or create the personal device.
            //
            if (deviceIdentifier.IsNotNullOrWhiteSpace())
            {
                var mobileDeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSONAL_DEVICE_TYPE_MOBILE).Id;
                var personalDeviceService   = new PersonalDeviceService(rockContext);
                var personalDevice          = personalDeviceService.Queryable()
                                              .AsNoTracking()
                                              .Where(a => a.DeviceUniqueIdentifier == deviceIdentifier && a.PersonalDeviceTypeValueId == mobileDeviceTypeValueId)
                                              .FirstOrDefault();

                if (personalDevice == null)
                {
                    personalDevice = new PersonalDevice
                    {
                        DeviceUniqueIdentifier    = deviceIdentifier,
                        PersonalDeviceTypeValueId = mobileDeviceTypeValueId,
                        PlatformValueId           = deviceData.DevicePlatform.GetDevicePlatformValueId(),
                        PersonAliasId             = person?.PrimaryAliasId,
                        NotificationsEnabled      = true
                    };

                    personalDeviceService.Add(personalDevice);
                    rockContext.SaveChanges();
                }

                launchPacket.PersonalDeviceGuid = personalDevice.Guid;
            }

            return(Ok(launchPacket));
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: ice0001/Cubes-in-Space
    // Update is called once per frame
    void Update()
    {
        // variable for the raycast info
        RaycastHit hit;
        bool didHit = false;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 1000))
        {
            Vector3 distanceVector = hit.point - transform.position;
            float distance = distanceVector.magnitude;
            GameObject targetObject = hit.transform.gameObject; //the side of the cube we hit

            //draw some stuff the the screen
            if (targetObject.CompareTag("Paintable"))
            {
                guiText.material.color = new Color(color.r, color.g, color.b);
                guiText.text = "Distance: " + Mathf.Round(distance);

                parentCube = targetObject.transform.parent.gameObject;
                pCubeScript = parentCube.GetComponent<Cube>();
                owners = new List<int>();
                for (int i = 0; i < 6; i++)
                {
                    Side tempSide = pCubeScript.Sides[i].GetComponent<Side>();
                    owners.Add(tempSide.teamOwnedBy);
                }
                myGUI.updateColors(true, owners);
            }
            else
            {
                guiText.material.color = new Color(255, 255, 255);
                guiText.text = "Distance: " + Mathf.Round(distance);
                myGUI.updateColors(false);
            }
            didHit = true;
        }

        //check for click on plane
        if (Input.GetMouseButtonDown(0) && didHit && !isFlying)
        {
            //our target is where we clicked
            targetPosition = hit.point;
            normal = hit.normal;
            targetObjectSide = hit.transform.gameObject; //the side of the cube we hit
            isFlying = true;

            mouseLook.enabled = false;
            mouseFollow.enabled = true;
            mouseFollow.startLocation = gameObject.transform.position;
            mouseFollow.targetLocation = targetPosition;
            mouseFollow.targetNormal = hit.normal;
            mouseFollow.reset();

            Vector3 holderPosition = transform.position;
            Vector3 distanceVector = targetPosition - holderPosition;
            int counter = 0;

            while(distanceVector.magnitude >= 5)
            {
                holderPosition += (distanceVector.normalized * moveSpeed * .0001f);
                distanceVector = targetPosition - holderPosition;
                counter++;
            }

            double calcETA = counter * .0001f * 1000;
            calcETA += TimeManager.Instance.ClientTimeStamp;
            //Debug.Log("calcETA: " + calcETA);
            //*********SEND DATA ABOUT CLICK***********//
            LaunchPacket launchMessage;
            if (targetObjectSide.name.Contains("Cube"))
            {
                int cubeID = targetObjectSide.transform.parent.GetComponent<Cube>().id;
                int sideID = targetObjectSide.GetComponent<Side>().id;
                launchMessage = new LaunchPacket(this.transform.position, targetPosition, TimeManager.Instance.ClientTimeStamp, calcETA,cubeID,sideID);
                GameObject side = GameManager.Instance.GetSide(launchMessage.CubeID, launchMessage.SideID);
                side.GetComponent<Side>().TakeSide(launchMessage, GameValues.teamNum);
            }
            else
            {
                launchMessage = new LaunchPacket(this.transform.position, targetPosition, TimeManager.Instance.ClientTimeStamp, calcETA, -1, -1);
            }

            sender.SendLaunchOnRequest(launchMessage);
        }

        if(isFlying){

            //calculate the distance to target
            Vector3 distanceVector = targetPosition - transform.position;
            float distance = distanceVector.magnitude;

            if (distance >= 5)
            {
                //move towards the target slowly
                transform.position += (distanceVector.normalized * moveSpeed * Time.deltaTime);
                //player.transform.position = Vector3.Lerp(player.transform.position, targetPosition, Time.deltaTime * moveSpeed);
            }
            else
            {
                //we've hit, color the cube our color
                if (targetObjectSide.name != "arena" && targetObjectSide.name != "icosahedron" && targetObjectSide.name != "icosahedronframe")
                {
                    GameObject cube = targetObjectSide.transform.parent.gameObject;
                    Cube theCube = cube.GetComponent<Cube>();

                    //theCube.setSideColor(targetObjectSide, color);
                }
                //upon arrival, turn around
                transform.position = targetPosition;

                //slow these down somehow
                transform.forward = normal;
                mouseLook.setLookingDir(transform.localEulerAngles);

                //set camera

                StartCoroutine("CameraSwitch",1.0f);

                //Camera.main.ScreenPointToRay(-normal);
                //Debug.Log("normal: " + hit.normal);
            }
        }//end isFlying
    }
コード例 #6
0
    // Copies another NetworkTransform to itself
    public void Load(LaunchPacket launchMessage)
    {
        //Message type
        this.type = launchMessage.type;

        //cube hit id
        this.sideID = launchMessage.cubeID;

        //side hit id
        this.sideID = launchMessage.sideID;

        // Launch Position
        this.launchPosition = launchMessage.launchPosition;

        // Launch Destination
        this.launchDestination = launchMessage.launchDestination;

        //Local Game Time
        this.localGameTime = launchMessage.localGameTime;

        //Local Game Time
        this.gameTimeETA = launchMessage.gameTimeETA;
    }
コード例 #7
0
    // Check if this transform is different from given one with specified accuracy
    public bool IsDifferent(LaunchPacket transform, float accuracy)
    {
        float posDif = Vector3.Distance(this.LaunchPosition, transform.LaunchPosition);

        return (posDif>accuracy /*|| angDif > accuracy*/);
    }
コード例 #8
0
    // Creating NetworkTransform from Unity transform
    public static LaunchPacket InstantiatePacket(Vector3 Pos)
    {
        LaunchPacket trans = new LaunchPacket();

           // trans.launchPosition = transform.position;
        //trans.angleRotation = transform.localEulerAngles;

        return trans;
    }
コード例 #9
0
    // Creating NetworkTransform from SFS object
    public static LaunchPacket FromSFSObject(ISFSObject data)
    {
        LaunchPacket launchMessage = new LaunchPacket();

        ISFSObject launchData = data.GetSFSObject("launchMessage");

        launchMessage.type = launchData.GetUtfString("messageType");

        //cube hit id
        launchMessage.cubeID = launchData.GetInt("cubeID");

        //side hit id
        launchMessage.sideID = launchData.GetInt("sideID");

        //get launch pos
        float sx = launchData.GetFloat("sx");
        float sy = launchData.GetFloat("sy");
        float sz = launchData.GetFloat("sz");

        //set lauch pos in object
        launchMessage.launchPosition = new Vector3(sx, sy, sz);

        //get launch destination
        float ex = launchData.GetFloat("ex");
        float ey = launchData.GetFloat("ey");
        float ez = launchData.GetFloat("ez");

        //set lauch pos in object
        launchMessage.launchDestination = new Vector3(ex, ey, ez);

        //get & set senders local game time
        launchMessage.localGameTime = launchData.GetDouble("localGameTime");

        //get & set senders local game time
        launchMessage.gameTimeETA = launchData.GetDouble("gameTimeETA");

        return launchMessage;
    }
コード例 #10
0
 // Clone itself
 public static LaunchPacket Clone(LaunchPacket ntransform)
 {
     LaunchPacket trans = new LaunchPacket();
     trans.Load(ntransform);
     return trans;
 }
コード例 #11
0
ファイル: GameManager.cs プロジェクト: ice0001/Cubes-in-Space
    //send out a launch message to all other players that you are moving somewhere
    public void SendLaunchMessage(LaunchPacket launchMessage)
    {
        Debug.Log("Sending Launch Message");
        ISFSObject data = new SFSObject();
        data.GetSFSObject("launchMessage");

        data = launchMessage.ToSFSObject(data);
        smartFox.Send(new ObjectMessageRequest(data));
    }
コード例 #12
0
        public IHttpActionResult GetLaunchPacket(string deviceIdentifier = null, bool?notificationsEnabled = null)
        {
            var site = MobileHelper.GetCurrentApplicationSite();
            var additionalSettings = site?.AdditionalSettings.FromJsonOrNull <AdditionalSiteSettings>();
            var rockContext        = new Rock.Data.RockContext();
            var person             = GetPerson(rockContext);
            var deviceData         = Request.GetHeader("X-Rock-DeviceData").FromJsonOrNull <DeviceData>();

            if (additionalSettings == null || !additionalSettings.LastDeploymentDate.HasValue)
            {
                return(NotFound());
            }

            // Ensure the user login is still active, otherwise log them out.
            var principal = ControllerContext.Request.GetUserPrincipal();

            if (person != null && !principal.Identity.Name.StartsWith("rckipid="))
            {
                var userLogin = new UserLoginService(rockContext).GetByUserName(principal.Identity.Name);

                if (userLogin?.IsConfirmed != true || userLogin?.IsLockedOut == true)
                {
                    person = null;
                }
            }

            var launchPacket = new LaunchPacket
            {
                RockVersion         = Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber(),
                LatestVersionId     = additionalSettings.LastDeploymentVersionId ?? ( int )(additionalSettings.LastDeploymentDate.Value.ToJavascriptMilliseconds() / 1000),
                IsSiteAdministrator = site.IsAuthorized(Rock.Security.Authorization.EDIT, person)
            };

            if (deviceData.DeviceType == DeviceType.Phone)
            {
                launchPacket.LatestVersionSettingsUrl = additionalSettings.PhoneUpdatePackageUrl;
            }
            else if (deviceData.DeviceType == DeviceType.Tablet)
            {
                launchPacket.LatestVersionSettingsUrl = additionalSettings.TabletUpdatePackageUrl;
            }
            else
            {
                return(NotFound());
            }

            if (person != null)
            {
                //var principal = ControllerContext.Request.GetUserPrincipal();

                launchPacket.CurrentPerson           = MobileHelper.GetMobilePerson(person, site);
                launchPacket.CurrentPerson.AuthToken = MobileHelper.GetAuthenticationToken(principal.Identity.Name);

                UserLoginService.UpdateLastLogin(principal.Identity.Name);
            }

            //
            // Get or create the personal device.
            //
            if (deviceIdentifier.IsNotNullOrWhiteSpace())
            {
                var mobileDeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSONAL_DEVICE_TYPE_MOBILE).Id;
                var personalDeviceService   = new PersonalDeviceService(rockContext);
                var personalDevice          = personalDeviceService.Queryable()
                                              .Where(a => a.DeviceUniqueIdentifier == deviceIdentifier && a.PersonalDeviceTypeValueId == mobileDeviceTypeValueId && a.SiteId == site.Id)
                                              .FirstOrDefault();

                if (personalDevice == null)
                {
                    personalDevice = new PersonalDevice
                    {
                        DeviceUniqueIdentifier    = deviceIdentifier,
                        PersonalDeviceTypeValueId = mobileDeviceTypeValueId,
                        SiteId               = site.Id,
                        PlatformValueId      = deviceData.DevicePlatform.GetDevicePlatformValueId(),
                        PersonAliasId        = person?.PrimaryAliasId,
                        NotificationsEnabled = true,
                        Manufacturer         = deviceData.Manufacturer,
                        Model            = deviceData.Model,
                        Name             = deviceData.Name,
                        LastSeenDateTime = RockDateTime.Now
                    };

                    personalDeviceService.Add(personalDevice);
                    rockContext.SaveChanges();
                }
                else
                {
                    // A change is determined as one of the following:
                    // 1) A change in Name, Manufacturer, Model, or NotificationsEnabled.
                    // 2) Device not being active.
                    // 3) Not seen in 24 hours.
                    // 4) Signed in with a different person.
                    var hasDeviceChanged = !personalDevice.IsActive ||
                                           personalDevice.Name != deviceData.Name ||
                                           personalDevice.Manufacturer != deviceData.Manufacturer ||
                                           personalDevice.Model != deviceData.Model ||
                                           personalDevice.NotificationsEnabled != (notificationsEnabled ?? true) ||
                                           !personalDevice.LastSeenDateTime.HasValue ||
                                           personalDevice.LastSeenDateTime.Value.AddDays(1) < RockDateTime.Now ||
                                           (person != null && personalDevice.PersonAliasId != person.PrimaryAliasId);

                    if (hasDeviceChanged)
                    {
                        personalDevice.IsActive         = true;
                        personalDevice.Manufacturer     = deviceData.Manufacturer;
                        personalDevice.Model            = deviceData.Model;
                        personalDevice.Name             = deviceData.Name;
                        personalDevice.LastSeenDateTime = RockDateTime.Now;

                        if (notificationsEnabled.HasValue)
                        {
                            personalDevice.NotificationsEnabled = notificationsEnabled.Value;
                        }

                        // Update the person tied to the device, but never blank it out.
                        if (person != null && personalDevice.PersonAliasId != person.PrimaryAliasId)
                        {
                            personalDevice.PersonAliasId = person.PrimaryAliasId;
                        }

                        rockContext.SaveChanges();
                    }
                }

                launchPacket.PersonalDeviceGuid = personalDevice.Guid;
            }

            return(Ok(launchPacket));
        }
コード例 #13
0
 /*
 void FixedUpdate ()
 {
     if (send) {
         SendLaunchData();
     }
 }
  */
 public void SendLaunchOnRequest(LaunchPacket message)
 {
     Debug.Log (GameManager.Instance.ClientName + " sent transform on request");
     Debug.Log(message.ToString());
     GameManager.Instance.SendLaunchMessage(message);
 }