private void CheckInteractions() { RaycastHit hit; if (!Physics.Raycast(GetRay(), out hit, interactionDistance)) { //turn UI off uiManager.UpdateInteractableText(""); return; } Drink drink = hit.transform.GetComponent <Drink>(); MysteryBox mysteryBox = hit.transform.GetComponent <MysteryBox>(); PackAPunch packAPunch = hit.transform.GetComponent <PackAPunch>(); BuyableWeapons buyable = hit.transform.GetComponent <BuyableWeapons>(); Obstacle obstacle = hit.transform.GetComponent <Obstacle>(); if (buyable != null) { InteractWithBuyable(buyable); } else if (drink != null) { InteractWithDrink(drink); } else if (mysteryBox != null) { InteractWithMysteryBox(mysteryBox); } else if (packAPunch != null) { InteractWithPackAPunch(packAPunch); } else if (obstacle != null) { uiManager.UpdateInteractableText(obstacle.blockedArea + ": $" + obstacle.cost.ToString()); if (CheckInteractionInput() == false) { return; } if (gameManager.points < obstacle.cost) { return; } obstacle.Buy(); gameManager.ConsumePoints(obstacle.cost); } }
private void InteractWithMysteryBox(MysteryBox mysteryBox) { //Turn UI on with drink drinkMame uiManager.UpdateInteractableText("Mystery Box" + ": $" + mysteryBox.cost.ToString()); if (CheckInteractionInput() == false) { return; } if (mysteryBox.inUse == true) { return; } if (gameManager.points < mysteryBox.cost) { return; } mysteryBox.Buy(this); gameManager.ConsumePoints(mysteryBox.cost); }
protected override void HandleRequest() { rand = Query["ignore"] != null ? new Random(int.Parse(Query["ignore"])) : new RRandom(); using (Database db = new Database()) { Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData); if (CheckAccount(acc, db, false)) { if (Query["boxId"] == null) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Box not found</Error>"); return; } MysteryBox box = MysteryBox.GetBox(int.Parse(Query["boxId"])); if (box == null) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Box not found</Error>"); return; } if (box.Sale != null && DateTime.UtcNow <= box.Sale.SaleEnd) { switch (box.Sale.Currency) { case 0: if (acc.Credits < box.Sale.Price) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Not Enough Gold</Error>"); return; } break; case 1: if (acc.Stats.Fame < box.Sale.Price) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Not Enough Fame</Error>"); return; } break; } } else { switch (box.Price.Currency) { case 0: if (acc.Credits < box.Price.Amount) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Not Enough Gold</Error>"); return; } break; case 1: if (acc.Stats.Fame < box.Price.Amount) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Not Enough Fame</Error>"); return; } break; } } MysteryBoxResult res = new MysteryBoxResult { Awards = Utils.GetCommaSepString(GetAwards(box.Contents)) }; if (box.Sale != null && DateTime.UtcNow <= box.Sale.SaleEnd) { res.GoldLeft = box.Sale.Currency == 0 ? db.UpdateCredit(acc, -box.Sale.Price) : db.UpdateFame(acc, -box.Sale.Price); } else { res.GoldLeft = box.Price.Currency == 0 ? db.UpdateCredit(acc, -box.Price.Amount) : db.UpdateFame(acc, -box.Price.Amount); } if (box.Sale != null && DateTime.UtcNow <= box.Sale.SaleEnd) { res.Currency = box.Sale.Currency; } else { res.Currency = box.Price.Currency; } sendMysteryBoxResult(Context.Response.OutputStream, res); int[] gifts = Utils.FromCommaSepString32(res.Awards); foreach (int item in gifts) { acc.Gifts.Add(item); } MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET gifts=@gifts WHERE uuid=@uuid AND password=SHA1(@password);"; cmd.Parameters.AddWithValue("@uuid", Query["guid"]); cmd.Parameters.AddWithValue("@password", Query["password"]); cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString(acc.Gifts.ToArray())); cmd.ExecuteNonQuery(); } else { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Account not found</Error>"); } } }