Ejemplo n.º 1
0
        private void StartGlobalCooldown(RobberyModel model, bool stores = true)
        {
            foreach (var location in robbableLocations)
            {
                if (location == model)
                {
                    continue;
                }

                if (stores && !location.IsBank)
                {
                    if (location.IsRobbable)
                    {
                        startRobberyCooldown(location, location.CooldownTime / 4);
                    }
                }
                else if (!stores && location.IsBank)
                {
                    if (location.IsRobbable)
                    {
                        startRobberyCooldown(location, location.CooldownTime / 2);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void startRobberyCooldown(RobberyModel location, int cooldownTime = -1)
 {
     location.IsRobbable  = false;
     location.TimesRobbed = 111;
     Task.Factory.StartNew(async() =>
     {
         await BaseScript.Delay(cooldownTime == -1 ? location.CooldownTime : cooldownTime);
         location.IsRobbable    = true;
         location.IsBeingRobbed = false;
         if (!location.InRegisterCooldown)
         {
             location.TimesRobbed        = 0;
             location.InRegisterCooldown = false;
         }
     });
 }
Ejemplo n.º 3
0
 private void endRobbery(RobberyModel bank)
 {
     bank.IsBeingRobbed = false;
     startRobberyCooldown(bank);
     Log.Debug($"End robbery for bank {bank.LocationName}");
 }
Ejemplo n.º 4
0
        private void startRobbery(Session.Session player, RobberyModel location)
        {
            location.IsRobbable    = false;
            location.IsBeingRobbed = true;
            var robberySeconds     = location.TimeToRob / 1000;
            var currentSecond      = 0;
            var isCheckingLocation = false;

            StartGlobalCooldown(location, false);
            Task.Factory.StartNew(async() =>
            {
                while (location.IsBeingRobbed)
                {
                    await BaseScript.Delay(1000);
                    currentSecond++;
                    Log.Debug($"{location.LocationName} remaining time = {robberySeconds - currentSecond} seconds");
                    if (currentSecond >= robberySeconds && !isCheckingLocation && location.IsBeingRobbed)
                    {
                        var robberyPayout = location.Payout;
                        if (!location.IsVault)
                        {
                            Log.ToClient("[Robbery]", $"You got ${robberyPayout} from the teller window", ConstantColours.Blue, player.Source);
                            Server.Get <PaymentHandler>().UpdatePlayerCash(player, robberyPayout, $"teller robbery ({location.LocationName})");
                            player.SetLocalData("Bank.CanRobVault", true);
                            player.TriggerEvent("Bank.ShowVaultMarker", location.LocationName.AddSpacesToCamelCase().Split(' ')[0] + "Vault");
                        }
                        else
                        {
                            var playerInv = new PlayerInventory(player.GetGlobalData("Character.Inventory", ""), player);
                            playerInv.AddItem("DirtyMoney", robberyPayout);
                            Log.ToClient("[Robbery]", $"You got ${robberyPayout} in dirty money from the vault", ConstantColours.Blue, player.Source);
                        }
                        endRobbery(location);
                        return;
                    }
                    else
                    {
#pragma warning disable 4014
                        Task.Factory.StartNew(() =>
#pragma warning restore 4014
                        {
                            if (!isCheckingLocation)
                            {
                                isCheckingLocation = true;

                                /*var currentTick = 0;
                                 * playerLocations[player] = Vector3.Zero;
                                 * player.TriggerEvent("Robbery.UpdateRobberyPosition");
                                 * while (playerLocations[player] == Vector3.Zero)
                                 * {
                                 *  await BaseScript.Delay(0);
                                 *  currentTick++;
                                 *  if (currentTick >= 400)
                                 *  {
                                 *      break;
                                 *  }
                                 * }
                                 *
                                 * if (currentTick >= 400)
                                 * {
                                 *  Log.Verbose($"Robbery on location {location.LocationName} cancelled due to coord request timeout");
                                 *  endRobbery(location);
                                 *  return;
                                 * }*/

                                var playerPos = /*playerLocations[player]await player.GetPosition();*/ player.GetPlayerPosition();
                                var bankPos   = BankLocations.Positions[location.LocationName];
                                if (bankPos.DistanceToSquared(playerPos) > Math.Pow(maxDistance, 2))
                                {
                                    Log.ToClient("[Robbery]", "You moved to far away from the location", ConstantColours.Blue, player.Source);
                                    endRobbery(location);
                                    return;
                                }

                                isCheckingLocation = false;
                            }
                        });
                    }
                }
            });
        }