61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using GTANetworkAPI;
|
|
using Newtonsoft.Json;
|
|
using ReallifeGamemode.Database.Entities;
|
|
using ReallifeGamemode.Database.Models;
|
|
using ReallifeGamemode.Server.Extensions;
|
|
using ReallifeGamemode.Server.Managers;
|
|
using ReallifeGamemode.Server.Services;
|
|
|
|
namespace ReallifeGamemode.Server.Shop.Ammunation
|
|
{
|
|
public class Ammunation
|
|
{
|
|
public Vector3 vector { get; set; }
|
|
public List<Weapon> weaponList = new List<Weapon>();
|
|
|
|
public Ammunation(Vector3 position)
|
|
{
|
|
this.vector = position;
|
|
LoadWeapons();
|
|
}
|
|
|
|
public void LoadWeapons()
|
|
{
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
weaponList = dbContext.Weapons.ToList().FindAll(w => w.AmmunationActive == true);
|
|
}
|
|
}
|
|
public void LoadShopNUI(Player client)
|
|
{
|
|
|
|
List<Weapon> shopWeapons = weaponList.ToList();
|
|
client.TriggerEvent("AmmunationShop:LoadNativeUI", JsonConvert.SerializeObject(shopWeapons));
|
|
}
|
|
|
|
[RemoteEvent("CLIENT:Ammunation_BuyWeapon")]
|
|
public void AmmunationBuyWeapoon(Player player, WeaponHash weaponmodel, int ammo , int price)
|
|
{
|
|
player.SendChatMessage("JO IS ANGEKOMMEN" + weaponmodel + " " + ammo + " " + price);
|
|
using (var dbContext = new DatabaseContext())
|
|
{
|
|
User user = player.GetUser(dbContext);
|
|
|
|
if (user.Handmoney < price)
|
|
{
|
|
player.SendNotification("Du hast nicht genügend Geld bei dir");
|
|
return;
|
|
}
|
|
user.Handmoney -= price;
|
|
dbContext.SaveChanges();
|
|
player.GiveWeapon((WeaponHash)weaponmodel, ammo);
|
|
//client.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney);
|
|
}
|
|
}
|
|
}
|
|
}
|