Esempio n. 1
0
        public ActionResult RemoveDocument(Guid Id, Guid OrganisationId)
        {
            Document document = db.Documents.Find(Id);

            if (null == document)
            {
                ControllerMessage.Error(this, "Document not found");
                return(RedirectToAction("details", new { Id = OrganisationId }));
            }

            var uploadPath = Server.MapPath(SystemSettings.GetStringValue("DocumentPath"));
            var fileName   = uploadPath + document.Name;
            var exist      = System.IO.File.Exists(fileName);

            if (exist)
            {
                Organisation o = db.Organisations.Find(OrganisationId);
                if (null == o)
                {
                    ControllerMessage.Error(this, "Invalid request");
                    return(RedirectToAction("index"));
                }

                System.IO.File.Delete(fileName);
                o.Documents.Remove(document);
                db.Documents.Remove(document);

                db.SaveChanges();
                ControllerMessage.Success(this, "Document deleted!");
            }

            return(RedirectToAction("details", new { id = OrganisationId }));
        }
 public void Send(ControllerMessage message)
 {
     if (listners.ContainsKey(message.Header))
     {
         listners[message.Header].Send(message);
     }
 }
Esempio n. 3
0
 protected void Send(ControllerMessage msg)
 {
     if (parentController != null)
     {
         Receive(msg);
     }
 }
Esempio n. 4
0
    /// <summary>
    /// Handles the go action (message) -- A button hit from the controller
    /// </summary>
    private void HandleGoAction(ControllerMessage msg)
    {
        if (this.ControllerIndex == msg.ControllerSource)
        {
			ApplyForwardThrust(k_thrust);
        }
    }
Esempio n. 5
0
        // GET: Admin/ManageOrganisation/Details/5
        public ActionResult Details(Guid id)
        {
            try
            {
                var organisation = db.Organisations.Find(id);
                if (null == organisation)
                {
                    ControllerMessage.Error(this, "Invalid organisation!");
                    return(RedirectToAction("index"));
                }

                MOrganisationViewModel ViewModel = new MOrganisationViewModel();
                ViewModel.Row        = organisation;
                ViewModel.StatusForm = new StatusForm
                {
                    Id     = id,
                    Status = organisation.Status
                };
                ViewModel.OrganisationStatus = new SelectList(db.OrganisationStatus, "Id", "Name");
                return(View(ViewModel));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                ControllerMessage.Error(this, "System error! Contact us if this is persistance");
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 6
0
        public ActionResult ManageDocument(DocumentModel documentModel, HttpPostedFileBase file)
        {
            try
            {
                // Verify that the user selected a file
                if (file != null && file.ContentLength > 0)
                {
                    // extract only the fielname
                    documentModel.DocumentFileName = Path.GetFileName(file.FileName);
                    // TODO: need to define destination
                    using (var reader = new BinaryReader(file.InputStream))
                    {
                        documentModel.DocumentFile = reader.ReadBytes(file.ContentLength);
                    }
                }

                ContentClientProcessor.SaveDocument(documentModel);
                TempData["Message"] = new ControllerMessage {
                    Message = "Document saved successfully.", MessageType = ControllerMessageType.Info
                };
                return(RedirectToAction("Documents", new { Id = documentModel.DocumentLibraryId }));
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
            return(View(documentModel));
        }
Esempio n. 7
0
 public JsonResult ControllerMessage(string deviceId, string func, int interval, int intervalUnit, string data)
 {
     try
     {
         ControllerMessage message = new ControllerMessage();
         if (_context.ControllerMessage.Count() != 0)
         {
             message.Id = _context.ControllerMessage.Max(x => x.Id) + 1;
         }
         else
         {
             message.Id = 1;
         }
         var userId   = HttpContext.Session.GetInt32("UserId");
         var userName = _context.UserInfo.Where(x => x.Id.Equals(userId)).SingleOrDefault().UserName;
         message.UserName     = userName;
         message.DeviceInfo   = deviceId;
         message.Func         = func;
         message.Interval     = interval;
         message.IntervalUnit = intervalUnit;
         message.Data         = data;
         message.Time         = DateTime.Now;
         _context.Add(message);
         _context.SaveChanges();
         return(Json(1));
     }
     catch
     {
         return(Json(-1));
     }
 }
Esempio n. 8
0
        public ActionResult Create(RoleViewModel ViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var role = new IdentityRole();
                    role.Name = ViewModel.RoleForm.Name;
                    roleManager.Create(role);

                    ControllerMessage.Success(this, "Role: " + role.Name + " created!");
                    return(RedirectToAction("Index"));
                }

                ControllerMessage.Error(this, "Invalid submission!");
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                ControllerMessage.Error(this, SystemSettings.GetStringValue("SystemError"));
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 9
0
        public UIElement GetEditView(IIngredientSubject subject, DishEditDTO dishEditDTO)
        {
            IngredientListViewModel ingredientListViewModel = new IngredientListViewModel(factory, subject);
            RecipeAddViewModel      recipeAddViewModel      = new RecipeAddViewModel(factory, this, ingredientListViewModel);

            recipeAddViewModel.MustSelectDish = false;

            DishEditViewModel viewModel = new DishEditViewModel(dishEditDTO, recipeAddViewModel);
            DishEditView      view      = new DishEditView(viewModel);

            viewModel.DishSaveRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.Update(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };
            viewModel.DishSaveRecipesRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.UpdateRecipes(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };
            viewModel.DishDeleteRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.Delete(e.Data.OldName);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                        RaiseDishDeletedEvent(e.Data.OldName);
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };

            return(view);
        }
Esempio n. 10
0
    void applycontrols(ControllerMessage msg)
    {
        Debug.Log(msg.Payload);
        //Debug.Log(s);
        if (msg.Payload.GetField("left").ToString() == "true")
        {
            Debug.Log("Press Left");
            Move(-1);
        }
        else
        {
            //Debug.Log("Call move 0");
            Move(0);
        }

        if (msg.Payload.GetField("right").ToString() == "true")
        {
            Debug.Log("Press Right");
            Move(1);
        }
        else
        {
            //Debug.Log("Call move 0");
            Move(0);
        }

        if (msg.Payload.GetField("up").ToString() == "true")
        {
            Debug.Log("Press Up");
            RotateLeft();
        }
        if (msg.Payload.GetField("down").ToString() == "true")
        {
            Debug.Log("Press Down");
            RotateRight();
        }
        if (msg.Payload.GetField("shoot").ToString() == "true")
        {
            if (bulletPower <= maxbulletpower)
            {
                bulletPower += Time.deltaTime;
            }
            FireBullet();
            bulletPower = 0;
            Debug.Log("Shots fired");
        }
        if (msg.Payload.GetField("jump").ToString() == "true")
        {
            if ((fuel > 0))
            {
                GetComponent <Rigidbody2D>().AddForce(new Vector2(0, jumpforce));

                fuel--;
            }
            Debug.Log("Flying");
        }
    }
Esempio n. 11
0
 public override void Receive(ControllerMessage msg)
 {
     if (msg is Msg_UnitHit)
     {
         Msg_UnitHit unitHit = msg as Msg_UnitHit;
         Debug.Log(unitHit.unit.gameObject.ToString());
         KillUnit(unitHit.unit.unitId);
     }
 }
Esempio n. 12
0
        private Message MovePlayer(Tile player, ControllerMessage message)
        {
            if (player.IsActive)
            {
                var destination = InputMap.Transform(message.Body, player.Location, 1);
                return(player.BuildMoveMessage(destination));
            }

            return(null);
        }
Esempio n. 13
0
	void Move(ControllerMessage msg) {
		if (msg.ControllerSource == playerIndex) {
			if (msg.Payload.HasField("angle")) {
				string rawAngle = msg.Payload.GetField("angle").ToString ();
				angle = float.Parse (rawAngle);
			}
			
			string rawForce = msg.Payload.GetField ("force").ToString ();
			force = Mathf.Clamp(float.Parse (rawForce), 0, 1.0f);
		}
	}
Esempio n. 14
0
        //protected void AddTempData<T>(string key, T data) where T : class
        //{
        //  TempData.Put<T>(key, data);
        //}

        //protected T GetTempData<T>(string key, bool isRequired = true) where T : class
        //{
        //  T data = TempData.Get<T>(key);

        //  if (isRequired && data == null)
        //  {
        //    throw new CjExpInvalidOperationException("Cannot find data");
        //  }

        //  return data;
        //}

        protected void SetControllerMessage(ControllerMessageType messageType, string message)
        {
            var msg = new ControllerMessage
            {
                Message = GetControllerText(message),
                ControllerMessageType = messageType,
                MessageDateTime       = DateTime.Now
            };

            TempData.AddTempData(controllerMessageKey, msg);
        }
Esempio n. 15
0
    public void UpdateHHOnPoints()
    {
        JSONObject jo = new JSONObject();

        jo.AddField("playerId", playerId);
        jo.AddField("points", myPoints);
        ControllerMessage cm = new ControllerMessage(0, 1, "score", jo);

        //sender.SendToListeners("score", "playerId", playerId, "points", myPoints.ToString(), 1);
        sender.SendToListeners(cm);
    }
Esempio n. 16
0
	private void HandleDisconnect(ControllerMessage msg) 
	{
		if (this.gameObject) {
			int controlID = msg.ControllerSource;
			if (playerDB [controlID]) {
				//BCMessenger.DestroyObject (playerDB [controlID]);
				//Destroy (playerDB[controlID]);
				this.gameObject.SetActive(false);
			}
		}
	} 
Esempio n. 17
0
 void HandleRotate_ControllerInput(ControllerMessage msg)
 {
     if (msg.Payload.HasField("direction")) {
         string direction_value_raw = msg.Payload.GetField("direction").ToString();
         if (!String.IsNullOrEmpty(direction_value_raw)) {
             print(direction_value_raw);
         }
     } else {
         print("direction field not present");
     }
 }
    void HandleMoveDirection(ControllerMessage msg)
    {
        if (playerIndex == msg.ControllerSource) {
            if (msg.Payload.HasField ("move_axis")) {
                float.TryParse (msg.Payload.GetField ("axisX").ToString (), out axisX);
                float.TryParse (msg.Payload.GetField ("axisY").ToString (), out axisY);
            }
        }

        if (!GameManager.Instance.canPlayerMove)
            axisX = axisY = 0;
    }
Esempio n. 19
0
 /// <summary>
 /// Forwards messages to the controllers... listens for any "controller" messages (msgs > 0)
 /// and sends them.
 /// </summary>
 private void RouteControllerMessages(ControllerMessage msg)
 {
     // just messages for controllers... (-1 dest is for ALL)
     if ((msg.ControllerDest > 0) || (msg.ControllerDest < 0))
     {
         JSONObject json = msg.Payload;
         json.AddField("type", msg.Name);
         json.AddField ("controller_dest", msg.ControllerDest.ToString());
         //Debug.Log ("Game Message Sent: " + json.ToString ());
         BCLibProvider.Instance.BladeCast_Game_SendMessage (json);
     }
 }
Esempio n. 20
0
 /// <summary>
 /// Create a new Contract to be sent to the pipe
 /// </summary>
 public static ControllerContract Create(string id, string name, bool isUsbConnected, bool isBluetoothConnected, int batteryValue, ControllerMessage message = ControllerMessage.NONE, bool isIconVisible = false)
 {
     return new ControllerContract
     {
         Message = message,
         Id = id,
         Name = name,
         IsUsbConnected = isUsbConnected,
         IsBluetoothConnected = isBluetoothConnected,
         BatteryValue = batteryValue,
         IsIconVisible = isIconVisible
     };
 }
Esempio n. 21
0
 void HandleD_ControllerInput(ControllerMessage msg)
 {
     if(msg.ControllerSource != remote_id)
     {
         return;
     }
     string str_state = msg.Payload.GetField("state").ToString();
     int tmp;
     if(int.TryParse(str_state, out tmp)) {
         d_down = tmp;
     }
     //print ("d"+tmp);
 }
Esempio n. 22
0
	private void HandleConnect(ControllerMessage msg) 
	{
		int controlID = msg.ControllerSource;

		if (controlID > playerDB.Length) 
		{
			return;
		}
		if (playerDB [controlID])
		{
			Instantiate (playerDB[controlID], new Vector3 (0f, 5f, 0f), Quaternion.identity);
		}
	}
Esempio n. 23
0
        private void OnMenuUpdate(MenuDTO menu, MenuViewModel viewModel)
        {
            using (IMenuController controller = factory.CreateMenuController())
            {
                ControllerMessage controllerMessage = controller.UpdateMenu(menu);
                if (!controllerMessage.IsSuccess)
                {
                    MessageBox.Show(controllerMessage.Message);
                }

                Notify();
            }
        }
Esempio n. 24
0
 void SaveJson(ControllerMessage msg)
 {
     if (isSavingJson)
     {
         Debug.Log("saving a message");
         recentJsons.Add(msg.Payload);
     }
     if (recentJsons.Count > 100)
     {
         Debug.LogError("done saving message");
         isSavingJson = false;
         StartCoroutine(ReplayToPlayer());
     }
 }
Esempio n. 25
0
    void Move(ControllerMessage msg)
    {
        if (msg.ControllerSource == playerIndex)
        {
            if (msg.Payload.HasField("angle"))
            {
                string rawAngle = msg.Payload.GetField("angle").ToString();
                angle = float.Parse(rawAngle);
            }

            string rawForce = msg.Payload.GetField("force").ToString();
            force = Mathf.Clamp(float.Parse(rawForce), 0, 1.0f);
        }
    }
Esempio n. 26
0
        public void CanUpdatePlayerLocation()
        {
            var model = new Model(_level, _mobs, behaviourModel);
            var originalPlayerLocation = model.Mobiles.WithName("player").Location;
            var message = new ControllerMessage {
                Body = "down", Header = "player"
            };

            model.InputBuffer.Send(message);
            var newPlayerLocation = model.Mobiles.Tiles.FirstOrDefault(p => p.Name == "player").Location;

            Assert.AreNotEqual(originalPlayerLocation, newPlayerLocation);
            Assert.AreEqual(originalPlayerLocation.Y + 1, newPlayerLocation.Y);
        }
Esempio n. 27
0
    public void Jump(ControllerMessage msg)
    {
        //Debug.Log ("got jump listen event");
        //Debug.Log (msg.ControllerSource.ToString () + ", is the contrl source, the playerid match?: " + msg.Payload.GetField ("playerId").str + ":" + playerId);

        if (msg.ControllerSource == playerIndex && msg.Payload.GetField("playerId").str.Equals(playerId))
        {
            //Debug.Log ("match");
            if (msg.Payload.HasField("jump") && !isJumping)
            {
                StartCoroutine(JumpWithCoolDown());
            }
        }
    }
Esempio n. 28
0
 // GET: Admin/ManageOrganisation
 public ActionResult Index()
 {
     try
     {
         MOrganisationViewModel ViewModel = new MOrganisationViewModel();
         ViewModel.Organisations = db.Organisations.ToList();
         return(View(ViewModel));
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         ControllerMessage.Error(this, "System error! Contact us if this is persistance");
         return(RedirectToAction("Index"));
     }
 }
Esempio n. 29
0
 // GET: Admin/Resource
 public ActionResult Index()
 {
     try
     {
         ResourceViewModel ViewModel = new ResourceViewModel();
         ViewModel.Resources = db.Resources.ToList();
         return(View(ViewModel));
     }
     catch (Exception e)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(e);
         ControllerMessage.Error(this, SystemSettings.GetStringValue("SystemError"));
         return(RedirectToAction("Index", "Dashboard"));
     }
 }
    void HandleControllerRegister(ControllerMessage msg)
    {
        int controllerIndex = msg.ControllerSource;
        if (controllerIndex > 4) {
            print ("Too many controllers - bugger off");
            return;
        }
        playerList [controllerIndex - 1].transform.position = list [controllerIndex - 1];

        playerList [controllerIndex - 1].SetActive (true);

        GameManager.Instance.UpdateConnectedPlayerList (controllerIndex - 1);

        PlayerMovement plMove = playerList [controllerIndex - 1].GetComponent<PlayerMovement> ();
        plMove.Reposition ();
    }
Esempio n. 31
0
 private void OnDelete(StockEditDTO stockEditDTO, StockEditViewModel viewModel)
 {
     using (IStockController controller = factory.CreateStockController())
     {
         ControllerMessage controllerMessage = controller.Delete(stockEditDTO.OldStockNo);
         if (controllerMessage.IsSuccess)
         {
             Notify();
             viewModel.Clear();
         }
         else
         {
             MessageBox.Show(controllerMessage.Message);
         }
     }
 }
Esempio n. 32
0
 public ActionResult ResetPassword(string uname, string token)
 {
     try
     {
         string            password          = SecurityClientProcessor.ResetPassword(uname, token);
         ControllerMessage controllerMessage = new ControllerMessage {
             MessageType = ControllerMessageType.Info, Message = "Your will receive a new password in your email shortly."
         };
         ViewBag.Message = controllerMessage;
     }
     catch (Exception ex)
     {
         HandleError(ex);
     }
     return(View());
 }
Esempio n. 33
0
 private void OnSave(StockEditDTO stockEditDTO)
 {
     using (IStockController controller = factory.CreateStockController())
     {
         ControllerMessage controllerMessage = controller.Update(stockEditDTO);
         if (controllerMessage.IsSuccess)
         {
             stockEditDTO.OldStockNo = stockEditDTO.NewStockNo;
             Notify();
         }
         else
         {
             MessageBox.Show(controllerMessage.Message);
         }
     }
 }
Esempio n. 34
0
 private void OnAdd(int stockNo, StockAddViewModel viewModel)
 {
     using (IStockController controller = factory.CreateStockController())
     {
         ControllerMessage controllerMessage = controller.Add(stockNo);
         if (controllerMessage.IsSuccess)
         {
             viewModel.StockNo = String.Empty;
             Notify();
         }
         else
         {
             MessageBox.Show(controllerMessage.Message);
         }
     }
 }
Esempio n. 35
0
    public IEnumerator ReplayToPlayer()
    {
        //disable players for a little
        sender.SendToListeners("disabled", "playerId", theNonPlayerId, 1);              //immune player


        foreach (Player ply in playerList)
        {
            if (ply.playerId != theNonPlayerId)
            {
                ply.listener.Remove(ply.movementListener);
                ply.listener.Remove(ply.jumpingListener);
            }
        }


        foreach (JSONObject jo in recentJsons)
        {
            foreach (Player ply in playerList)
            {
                if (ply.playerId != theNonPlayerId)
                {
                    ControllerMessage cm = new ControllerMessage(1, 0, jo.GetField("type").str, jo);
                    if (jo.GetField("type").str == "move")
                    {
                        ply.Move(cm);
                    }
                    else if (jo.GetField("type").str == "jump")
                    {
                        ply.Jump(cm);
                    }
                }
            }
            yield return(new WaitForSeconds(0.01f));
        }

        //send re-enable message to players
        sender.SendToListeners("enabled", "playerId", theNonPlayerId, 1);
        foreach (Player ply in playerList)
        {
            if (ply.playerId != theNonPlayerId)
            {
                ply.listener.Add(ply.movementListener);
                ply.listener.Add(ply.jumpingListener);
            }
        }
    }
        private void OnDelete(IngredientEditDTO ingredientEditDTO, IngredientEditViewModel viewModel)
        {
            using (IIngredientController controller = factory.CreateIngredientController())
            {
                ControllerMessage controllerMessage = controller.Delete(ingredientEditDTO.OldName);

                if (controllerMessage.IsSuccess)
                {
                    Notify();
                    viewModel.Clear();
                }
                else
                {
                    MessageBox.Show(controllerMessage.Message);
                }
            }
        }
        private void OnSave(IngredientEditDTO ingredientEditDTO)
        {
            using (IIngredientController controller = factory.CreateIngredientController())
            {
                ControllerMessage controllerMessage = controller.Update(ingredientEditDTO);

                if (controllerMessage.IsSuccess)
                {
                    ingredientEditDTO.OldName = ingredientEditDTO.NewName;
                    Notify();
                }
                else
                {
                    MessageBox.Show(controllerMessage.Message);
                }
            }
        }
Esempio n. 38
0
 private void ResolveGameMessage(ControllerMessage inputMessage)
 {
     switch (inputMessage.Body)
     {
     case (GameConstants.REWIND):
         if (_turns.Any())
         {
             var turn = _turns.Pop();
             while (turn.Any())
             {
                 _messageHandler.Resolve(turn.Pop().Invert());
             }
             EndTurn();
         }
         break;
     }
 }
Esempio n. 39
0
	public void Move(ControllerMessage msg) {

		if (msg.ControllerSource == playerIndex && msg.Payload.GetField("playerId").str.Equals(playerId)) {
			if (msg.Payload.HasField("direction")) {
				//Debug.Log ("got direction: " + msg.Payload.GetField ("direction").i.ToString());
				int direction = msg.Payload.GetField ("direction").i;
				//rb.AddForce((Vector3.right * (float)direction ) / 10.0f);
				transform.position = transform.position + ((Vector3.right * (float)direction ) / 10000.0f);


				//Debug.Log("direction string: " + msg.Payload.GetField("direction").ToString ());

			}

			//Debug.Log ("did not get angle, fields: " + msg.Payload.ToString ());
		}
	}
Esempio n. 40
0
        private void Edit(DishEditDTO dishEditDTO, IIngredientSubject subject)
        {
            IngredientListViewModel ingredientListViewModel = new IngredientListViewModel(factory, subject);
            RecipeAddViewModel      recipeAddViewModel      = new RecipeAddViewModel(factory, this, ingredientListViewModel);

            recipeAddViewModel.MustSelectDish = false;

            DishEditViewModel viewModel = new DishEditViewModel(dishEditDTO, recipeAddViewModel);
            DishEditView      view      = new DishEditView(viewModel);
            Window            window    = WindowFactory.CreateByContentsSize(view);

            window.MinWidth = view.MinWidth;

            viewModel.DishSaveRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.Update(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };
            viewModel.DishSaveRecipesRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.UpdateRecipes(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };

            window.Show();
        }
Esempio n. 41
0
        private void OnAdd(string categoryName, CategoryAddViewModel viewModel)
        {
            using (ICategoryController controller = factory.CreateCategoryController())
            {
                ControllerMessage controllerMessage = controller.Add(categoryName);

                if (controllerMessage.IsSuccess)
                {
                    viewModel.Name = String.Empty;
                    Notify();
                }
                else
                {
                    MessageBox.Show(controllerMessage.Message);
                }
            }
        }
Esempio n. 42
0
	void Fire(ControllerMessage msg) {
        if (msg.ControllerSource == playerIndex)
        {
            if (Time.time - fireTimer >= 1 / fireRate)
            {
                fireTimer = Time.time;

                Collider collider = GetComponent<Collider>();
                float height = collider.bounds.size.y + 0.25f;

                Vector2 firePosition = transform.position + (transform.up * (height / 2));
                GameObject bullet = (GameObject)Instantiate(bulletPrefab, firePosition, transform.rotation);

                bullet.GetComponent<Rigidbody>().velocity = rb.velocity;
            }
        }
	}
Esempio n. 43
0
    void HandleRotate_ControllerInput(ControllerMessage msg)
    {
        if(msg.ControllerSource != remote_id)
        {
            return;
        }

        if (msg.Payload.HasField ("angle")) {
            string angle_value_raw = msg.Payload.GetField("angle").ToString();
            float angle_value_parsed;
            if(float.TryParse(angle_value_raw, out angle_value_parsed)) {
                weapon_script.AimAtDirection(-Mathf.Rad2Deg*angle_value_parsed);
                //weapon_script.SimpleRotate(-Mathf.Rad2Deg*angle_value_parsed*0.01f);
            }
        } else {
            print ("angle field did not exist");
        }
        //print(msg.ControllerSource);
    }
Esempio n. 44
0
    void HandleRotate_ControllerMovement(ControllerMessage msg)
    {
        if (msg.Payload.HasField ("movement") && msg.Payload.HasField ("player") && msg.Payload.GetField ("player").ToString () [1] == '2') {
            string direction = msg.Payload.GetField("movement").ToString();
            direction = direction.Substring(1,direction.Length-2);
            print(msg.Payload.GetField("player").ToString()[1]);
            switch (direction) {
            case "Up":
                    transform.position = new Vector3 (transform.position.x, 0, transform.position.z + 0.1f); break;
            case "Down":
                transform.position = new Vector3 (transform.position.x, 0, transform.position.z - 0.1f);break;
            case "Left":
                transform.position = new Vector3 (transform.position.x - 0.1f, 0, transform.position.z); break;
            case "Right":
                transform.position = new Vector3 (transform.position.x + 0.1f, 0, transform.position.z); break;
            }

        } else if (msg.Payload.GetField ("player").ToString () [1] == '1') {
        } else {
            print ("angle or movement did not exist");
        }
    }
Esempio n. 45
0
    void positionHandler(ControllerMessage msg)
    {
        if (currentlyColliding == true) {
            return;
        } else if (currentlyColliding == false) {

            float x = float.Parse (msg.Payload.GetField ("x-coordinate").ToString ());
            float y = float.Parse (msg.Payload.GetField ("y-coordinate").ToString ());

            Vector3 newPos = Camera.main.ViewportToWorldPoint (new Vector3 (x, 1 - y, -1));
        //			Debug.Log (newPos);

            newPos.z = -1;

            if (ctlrNum == msg.ControllerSource) {

                transform.position = newPos;
        //				Debug.Log ("X POSITION: " + x);
        //				Debug.Log ("Y POSITION: " + y);
            }
        }
    }
Esempio n. 46
0
	void SaveJson(ControllerMessage msg) {
		if (isSavingJson) {
			Debug.Log ("saving a message");
			recentJsons.Add (msg.Payload);
		}
		if (recentJsons.Count > 100) {
			Debug.LogError ("done saving message");
			isSavingJson = false;
			StartCoroutine (ReplayToPlayer ());
		}
	}
Esempio n. 47
0
    public void HandleControllerRegister(ControllerMessage msg)
    {
        Debug.Log ("New connected player "+msg.ControllerSource);

        //ADD player
        AddRobot("RobotPlayer",(int)Random.Range(0,num_weapon_available-0.01f)
                 ,(int)Random.Range(0,num_engine_available-0.01f),1,msg.ControllerSource);
    }
Esempio n. 48
0
	void SpawnAPlayer(ControllerMessage msg) {
		Debug.Log ("connect detected by game manager, its controller source is: " + msg.ControllerSource.ToString());
		if (msg.ControllerSource == Player.playerIndex) {
			Debug.Log ("thign");
			if (msg.Payload.HasField ("playerId") && !playersRegistered.Contains(msg.Payload.GetField ("playerId").str)) {
				playersRegistered.Add (msg.Payload.GetField ("playerId").str);

				GameObject newPlayer = Instantiate (playerPrefab) as GameObject;
				newPlayer.GetComponent<Player> ().playerId = msg.Payload.GetField ("playerId").str;
				newPlayer.name = msg.Payload.GetField ("playerName").str;
				newPlayer.transform.GetChild (0).GetChild (0).GetComponent<Text> ().text = newPlayer.name;
				playerList.Add (newPlayer.GetComponent<Player> ());
			}
		}
	}
 public void Send(ControllerMessage message)
 {
     if(listners.ContainsKey(message.Header))
         listners[message.Header].Send(message);
 }
Esempio n. 50
0
    private void OnMessage(int deviceID, JToken data)
    {
        var targetPlayer = _players.FirstOrDefault(p => p.DeviceID == deviceID);

        if (targetPlayer != null)
        {
            var message = new ControllerMessage(data);

            if (message.ActionName == "convince")
            {
                targetPlayer.Convince();
            }
            else if (message.ActionName == "destroy")
            {
                targetPlayer.Destroy();
            }
            else if (message.ActionName == "joystick-left")
            {
                targetPlayer.Move(message.JoystickPosition);
            }
        }
    }
Esempio n. 51
0
		public void OnGameMessage (ControllerMessage msg)
		{
			UpdateSafeList ();
			foreach (Listener listener in m_ListenersSafe.FindAll(bcListener => ((msg.ControllerDest < 0) || (bcListener.m_ControllerIndex < 0) ||
			                                                                 	(bcListener.m_ControllerIndex == msg.ControllerDest)) &&
			                                                  				 	((bcListener.m_MessageType == "*") || (bcListener.m_MessageType == msg.Name)) )) {    
				this.gameObject.BroadcastMessage (listener.m_Handler, msg, SendMessageOptions.RequireReceiver);
			}
			UpdateSafeList ();
		}
Esempio n. 52
0
 private void ResolveGameMessage(ControllerMessage inputMessage)
 {
     switch (inputMessage.Body)
     {
         case (GameConstants.REWIND):
             if (_turns.Any())
             {
                 var turn = _turns.Pop();
                 while(turn.Any())
                     _messageHandler.Resolve(turn.Pop().Invert());
                 EndTurn();
             }
         break;
     }
 }
Esempio n. 53
0
        private void ResolvePlayerInput(ControllerMessage inputMessage)
        {
            var player = Mobiles.WithName(GameConstants.PLAYER);
            player.OnUpdate = p =>  MovePlayer(p,inputMessage);

            var turn = new Stack<Message>();

            foreach (var message in Mobiles.GetActiveTiles().GetUpdates())
            {
                var action = ResolveAction(message);
                if (!action.IsValid) continue;
                foreach (var data in action.FrameData)
                {
                    _messageHandler.Resolve(data);
                    turn.Push(data);
                }
                EndTurn();
            }
            _turns.Push(turn);
        }
Esempio n. 54
0
    void startHandler(ControllerMessage msg)
    {
        int ctlrNum = msg.ControllerSource;
        playerReadyCount ++;

        if (playerReadyCount == 4) {
            playersReadyInitializeGame();
        }
    }
Esempio n. 55
0
        private Message MovePlayer(Tile player, ControllerMessage message)
        {
            if (player.IsActive)
            {
                var destination = InputMap.Transform(message.Body, player.Location, 1);
                return player.BuildMoveMessage(destination);
            }

            return null;
        }
Esempio n. 56
0
	public void Jump(ControllerMessage msg) {
		//Debug.Log ("got jump listen event");
		//Debug.Log (msg.ControllerSource.ToString () + ", is the contrl source, the playerid match?: " + msg.Payload.GetField ("playerId").str + ":" + playerId);

		if (msg.ControllerSource == playerIndex && msg.Payload.GetField("playerId").str.Equals(playerId))
		{
			//Debug.Log ("match");
			if (msg.Payload.HasField("jump") && !isJumping) {
				
				StartCoroutine (JumpWithCoolDown ());
			}
		}
	}
Esempio n. 57
0
	public void Attack(ControllerMessage msg) {
		Debug.Log ("got attack listen event");
		if (msg.ControllerSource == playerIndex && msg.Payload.GetField("playerId").str.Equals(playerId))
        {
            //hit someone
			if (msg.Payload.HasField("attack")) {
				Debug.Log ("doing an attack!");

				//eventually kill this
				//rb.AddForce(Vector3.right * 20.0f);

				ShootAttackVector (Vector3.right * 5.0f);	//should throw raycast to the sprite's forward direction
				ShootAttackVector (Vector3.right * -5.0f);	//should throw raycast to the sprite's forward direction




			}
        }
	}
Esempio n. 58
0
	public void UpdateHHOnPoints() {
		JSONObject jo = new JSONObject ();
		jo.AddField ("playerId", playerId);
		jo.AddField ("points", myPoints);
		ControllerMessage cm = new ControllerMessage (0, 1, "score", jo);
		//sender.SendToListeners("score", "playerId", playerId, "points", myPoints.ToString(), 1);
		sender.SendToListeners(cm);

	}
Esempio n. 59
0
	public IEnumerator ReplayToPlayer() {
		//disable players for a little
		sender.SendToListeners("disabled", "playerId", theNonPlayerId, 1);	//immune player


		foreach (Player ply in playerList) {
			if (ply.playerId != theNonPlayerId) {
				ply.listener.Remove (ply.movementListener);
				ply.listener.Remove (ply.jumpingListener);
			}
		}


		foreach(JSONObject jo in recentJsons) {
			foreach (Player ply in playerList) {
				if (ply.playerId != theNonPlayerId) {
					ControllerMessage cm = new ControllerMessage (1, 0, jo.GetField ("type").str, jo);
					if (jo.GetField ("type").str == "move") {
						ply.Move (cm);
					} else if (jo.GetField ("type").str == "jump") {
						ply.Jump (cm);
					}
				}
			}
			yield return new WaitForSeconds(0.01f);
		}

		//send re-enable message to players
		sender.SendToListeners ("enabled", "playerId", theNonPlayerId, 1);
		foreach (Player ply in playerList) {
			if (ply.playerId != theNonPlayerId) {
				ply.listener.Add (ply.movementListener);
				ply.listener.Add (ply.jumpingListener);
			}
		}


	}
Esempio n. 60
0
 /// <summary>
 /// Handles the new connection message
 /// </summary>
 private void HandleNewConnection(ControllerMessage msg)
 {
     Debug.Log ("New Connection: " + msg.ControllerSource);
 }