If you want to use this you must complete the missing things, I also have bootybox, cargobox and CTBbeacon classes but not going to share them.
The luck factor (what you will earn) is predefined on creating or recreation, the amount you will receive is defined on collection, you can make it like first luck factor so that will make the collection faster.
Note that sql parts are outdated and not fit your database.
If you are going to use this, you can throw me some credits at least.
Code:
using System;
using System.Data;
using System.Threading.Tasks;
using Game.Managers;
namespace Game.Collectables
{
class BonusBox : ICollectable
{
private enum Rewards
{
Uridium = 75,
//%25 chance
Ammunition = 20,
// %20
//Energy = 49, todo
//Jackpott = 40,
todo
Credits = 75
//%55
}
public string RemovePacket { get; set; }
public int X { get; set; }
public int Y { get; set; }
public bool Collected { get; set; }
private readonly string _id;
private readonly int _type;
private const string Uri = "uridium";
private const string Cre = "credits";
private const string Gg = "energy";
private const string Jpt = "jackpott";
private const string Ammo = "ammo";
private readonly int[] _boxUri = { 150, 300, 250, 200 };
private readonly int[] _boxCre = { 1000, 2500, 5000, 10000 };
private readonly int[] _boxAmmo = { 25, 50, 100, 10 };
private readonly Random _random;
private readonly Map _currentMap;
private int _luck;
public BonusBox(string id, ushort mapid, int type, Map map)
{
_id = id;
_type = type;
_random = new Random(int.Parse(Program.Random.Next(100) + id + mapid));//omg so pro preventing not to be same Randoms LOL
X = _random.Next(5, 180) * 100;
Y = _random.Next(5, 128) * 100;
_currentMap = map;
_luck = _random.Next(0, 100);
RemovePacket = "0|2|" + _id;
}
private async void Recreate()
{
foreach( var pair in _currentMap.GetUsersByBox(_id))
{
pair.Send("0|2|" + _id);
}
await Task.Delay(500);
_luck = _random.Next(0, 100);
X = _random.Next(5, 180) * 100;
Y = _random.Next(5, 128) * 100;
Collected = false;
}
public void Collect(uint userId)
{
var user = _currentMap.GetUser(userId);
if (!user.BoxesInRange.Contains(_id) || Collected || Distance.Get(X, user.Ship.X, Y, user.Ship.Y) > 200) return;
Collected = true;
if (_luck >= (int) Rewards.Uridium)
{
Update(Uri, userId);
}
//else if (_luck >= (int) Rewards.Ammunition)
//{
// Update(Ammo, userId); // disabled
//}
else if (_luck <= (int) Rewards.Credits)
{
Update(Cre, userId);
}
Recreate();
}
public string CreatePacket()
{
return "0|c|" + _id + "| " + _type + "|" + X + "|" + Y;
}
private void Update(string type, uint userId)
{
var randomyz = _random.Next(0, 4);
var user = _currentMap.GetUser(userId);
switch (type)
{
case Uri:
using (var dbClient = Program.QueryManager.Get())
{
var data = (DataTable)dbClient.query("SELECT uri FROM server_1_players WHERE playerID=" + userId);
if (data.Rows.Count != 1) return;
var uri = Convert.ToInt32(data.Rows[0]["uri"]);
var reward = _boxUri[randomyz];
uri += reward;
dbClient.query("UPDATE server_1_players SET uri = '" + uri + "' WHERE playerID = '" + userId +
"'");
user.Ship.Uri = uri;
user.Send("0|LM|ST|URI|" + reward + "|" + uri);
}
break;
case Cre:
using (var dbClient = Program.QueryManager.Get())
{
var data =
(DataTable)dbClient.query("SELECT credits FROM server_1_players WHERE playerID=" + userId);
if (data.Rows.Count != 1) return;
var cre = Convert.ToInt32(data.Rows[0]["credits"]);
var reward = _boxCre[randomyz];
cre += reward;
dbClient.query("UPDATE server_1_players SET credits = '" + cre + "' WHERE playerID = '" + userId + "'");
user.Ship.Credits = cre;
user.Send("0|LM|ST|CRE|" + reward + "|" + cre);
}
break;
//ammo needs a redo
}
}
public void Dispose()
{
//not need for bonusboxes, they are used again and again
}
}
}






