public void SelectCharacter(Client sender, params object[] args) { if (Guid.TryParse(args[0].ToString(), out Guid userGuid) && int.TryParse(args[1].ToString(), out int accountId) && int.TryParse(args[2].ToString(), out int characterIndex)) { if (EntityHelper.GetAccounts().All(account => account.DbModel.Id != accountId)) { RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (AccountsRepository accountsRepository = new AccountsRepository(ctx)) using (CharactersRepository charactersRepository = new CharactersRepository(ctx)) { AccountModel accountModel = accountsRepository.Get(accountId); AccountEntity accountEntity = new AccountEntity(accountModel, sender); accountEntity.Login(userGuid); int characterId = accountEntity.DbModel.Characters.Where(character => character.IsAlive).ToList()[characterIndex].Id; CharacterModel characterModel = charactersRepository.Get(characterId); CharacterEntity characterEntity = new CharacterEntity(accountEntity, characterModel); accountEntity.SelectCharacter(characterEntity); } } } else { sender.Kick("Nie udało się zalogować. Skontaktuj się z administratorem."); } }
public void Save() { DbModel.Health = GameVehicle.Health; DbModel.Door1Damage = GameVehicle.IsDoorBroken(1); DbModel.Door2Damage = GameVehicle.IsDoorBroken(2); DbModel.Door3Damage = GameVehicle.IsDoorBroken(3); DbModel.Door4Damage = GameVehicle.IsDoorBroken(4); DbModel.Window1Damage = GameVehicle.IsWindowBroken(1); DbModel.Window2Damage = GameVehicle.IsWindowBroken(2); DbModel.Window3Damage = GameVehicle.IsWindowBroken(3); DbModel.Window4Damage = GameVehicle.IsWindowBroken(4); DbModel.PrimaryColor = GameVehicle.CustomPrimaryColor.ToHex(); DbModel.SecondaryColor = GameVehicle.CustomSecondaryColor.ToHex(); DbModel.EnginePowerMultiplier = GameVehicle.EnginePowerMultiplier; DbModel.NumberPlateStyle = GameVehicle.NumberPlateStyle; DbModel.NumberPlate = GameVehicle.NumberPlate; DbModel.Fuel = GameVehicle.GetSharedData("fuel"); DbModel.FuelConsumption = GameVehicle.GetSharedData("fuelConsumption"); DbModel.Milage = GameVehicle.GetSharedData("milage"); if (_nonDbVehicle) { return; } RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (VehiclesRepository repository = new VehiclesRepository(ctx)) { repository.Update(DbModel); repository.Save(); } }
private void Event_OnClientEventTrigger(Client sender, string eventName, params object[] arguments) { //args[0] to index na liście pozycji if (eventName == "OnPlayerSelectedCrimeBotDiscrict") { AccountEntity player = sender.GetAccountEntity(); if (player.CharacterEntity.OnDutyGroup is CrimeGroup group && group.CanPlayerCallCrimeBot(player)) { if (group.CrimePedEntity != null) { // crime bot already spawned sender.SendChatMessage("~#ffdb00~", "Wybrany abonent ma wyłączony telefon, bądź znajduje się poza zasięgiem, spróbuj później."); return; } RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (CrimeBotsRepository repository = new CrimeBotsRepository(ctx)) { CrimeBotModel crimeBotData = repository.Get(crimeBot => crimeBot.GroupModel.Id == group.Id); CrimeBotPosition position = XmlHelper.GetXmlObjects <CrimeBotPosition>( Path.Combine(Utils.XmlDirectory, "CrimeBotPositions"))[Convert.ToInt32(arguments[0])]; group.CrimePedEntity = new CrimePedEntity(player, group, position.VehiclePosition, crimeBotData.Name, NAPI.Util.PedNameToModel(crimeBotData.PedSkin), position.BotPosition); group.CrimePedEntity.Spawn(); sender.TriggerEvent("DrawCrimeBotComponents", position.BotPosition.Position, 500, 2); } } else { sender.SendChatMessage("~#ffdb00~", "Wybrany abonent ma wyłączony telefon, bądź znajduje się poza zasięgiem, spróbuj później."); } }
public void Save() { if (_nonDbVehicle) { return; } Alt.Log("Zapisuje"); DbModel.Health = GameVehicle.EngineHealth; DbModel.PosX = GameVehicle.Position.X; DbModel.PosY = GameVehicle.Position.Y; DbModel.PosZ = GameVehicle.Position.Z; DbModel.RotPitch = GameVehicle.Rotation.Pitch; DbModel.RotRoll = GameVehicle.Rotation.Roll; DbModel.RotYaw = GameVehicle.Rotation.Yaw; Alt.Log($"{GameVehicle.Rotation.Pitch} {GameVehicle.Rotation.Roll} {GameVehicle.Rotation.Yaw} "); DbModel.R = GameVehicle.PrimaryColorRgb.R; DbModel.G = GameVehicle.PrimaryColorRgb.G; DbModel.B = GameVehicle.PrimaryColorRgb.B; RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.VehicleRepository.Update(DbModel); } }
public VehicleEntity Create() { VehicleDb vehicle = new VehicleDb() { Owner = DbModel.Owner, Model = DbModel.Model, PosX = DbModel.PosX, PosY = DbModel.PosY, PosZ = DbModel.PosZ, R = DbModel.R, G = DbModel.G, B = DbModel.B, State = false, Health = 1000 }; if (!_nonDbVehicle) { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.VehicleRepository.Add(vehicle); } } return(new VehicleEntity(vehicle, _nonDbVehicle)); }
public void Buy(Client sender) { if (DbModel.AutoSaleModel == null) { sender.SendWarning("Ten budynek nie jest na sprzedaż"); return; } using (RoleplayContext ctx = Singletons.RoleplayContextFactory.Create()) { ctx.Attach(DbModel); CharacterEntity character = sender.GetAccountEntity().CharacterEntity; if (!character.HasMoney(DbModel.AutoSaleModel.Cost)) { sender.SendError("Nie posiadasz wystarczającej ilości gotówki"); return; } BuildingMarker.Color = new Color(255, 255, 0); character.RemoveMoney(DbModel.AutoSaleModel.Cost); sender.TriggerEvent(Constant.RemoteEvents.RemoteEvents.CharacterShowShardRequested, "Zakupiono budynek", 5000); NAPI.Player.PlaySoundFrontEnd(sender, "BASE_JUMP_PASSED", "HUD_AWARDS"); DbModel.Character = character.DbModel; ctx.Remove(DbModel.AutoSaleModel); DbModel.AutoSaleModel = null; ctx.SaveChanges(); } }
public static BuildingEntity Create(AccountModel creator, string name, decimal cost, Vector3 internalPosition, Vector3 externalPosition, bool spawnPossible, CharacterModel characterModel = null, GroupModel groupModel = null) { BuildingModel buildingModel = new BuildingModel() { Name = name, CurrentObjectCount = 0, Description = "", EnterCharge = null, InternalDimension = Utils.GetNextFreeDimension(), InternalPickupPositionX = internalPosition.X, InternalPickupPositionY = internalPosition.Y, InternalPickupPositionZ = internalPosition.Z, ExternalPickupPositionX = externalPosition.X, ExternalPickupPositionY = externalPosition.Y, ExternalPickupPositionZ = externalPosition.Z, ItemsInBuilding = new List <ItemModel>(), SpawnPossible = spawnPossible, CreatorId = creator.Id, HasCctv = false, HasSafe = false, MaxObjectCount = 10, Character = characterModel, Group = groupModel }; RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (BuildingsRepository repository = new BuildingsRepository(ctx)) { repository.Insert(buildingModel); repository.Save(); } return(new BuildingEntity(buildingModel)); }
public void SendMessage(CharacterEntity sender, int smartphoneId, int getterNumber, string message) { SmartphoneMessageModel smartphoneMessage = new SmartphoneMessageModel() { GetterNumber = getterNumber, Cellphone = sender.CurrentSmartphone.DbModel, CellphoneId = smartphoneId, Message = message, IsRead = false, Date = DateTime.Now }; SmartphoneMessages.Add(smartphoneMessage); CharacterEntity getter = EntityHelper.GetCharacterBySmartphoneNumber(getterNumber); if (getter != null) { if (getter.CurrentSmartphone != null) { getter.CurrentSmartphone.SmartphoneMessages.Add(smartphoneMessage); } } //Save(); RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unit = new UnitOfWork(ctx)) { unit.SmartphoneMessageRepository.Add(smartphoneMessage); } }
public void OnPlayerDriveThruBoughtHandler(Client sender, params object[] arguments) { decimal money = Convert.ToDecimal(arguments[2]); CharacterEntity character = sender.GetAccountEntity().CharacterEntity; if (!character.HasMoney(money)) { sender.SendInfo("Nie posiadasz wystarczającej ilości gotówki."); return; } character.RemoveMoney(money); AccountEntity player = sender.GetAccountEntity(); ItemModel itemModel = new ItemModel { Name = (string)arguments[0], Character = player.CharacterEntity.DbModel, CreatorId = null, ItemEntityType = ItemEntityType.Food, FirstParameter = (int)arguments[1], }; RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (ItemsRepository repository = new ItemsRepository(ctx)) { repository.Insert(itemModel); repository.Save(); } sender.SendInfo($"Pomyślnie zakupiłeś {itemModel.Name} za ${money}."); }
public static void TuningPlayerVehicle(CharacterEntity sender, CharacterEntity getter, object[] args) { VehicleEntity vehicleToUpgrade = (VehicleEntity)args[0]; ItemModel itemUpgrade = (ItemModel)args[1]; bool IsStunned = (bool)args[2]; Alt.Log($"{IsStunned} isStunned"); byte category = 0; byte variation = 0; if (IsStunned) { itemUpgrade.VehicleUpgradeId = null; itemUpgrade.CharacterId = getter.DbModel.Id; } else { category = (byte)itemUpgrade.SecondParameter; variation = (byte)itemUpgrade.ThirdParameter; itemUpgrade.VehicleUpgradeId = vehicleToUpgrade.DbModel.Id; itemUpgrade.CharacterId = null; } RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unit = new UnitOfWork(ctx)) { unit.ItemRepository.Update(itemUpgrade); } string actionInProgress = IsStunned ? "demontowana" : "montowana"; sender.AccountEntity.Player.SendChatMessageInfo($"Część jest {actionInProgress}, odczekaj chwile..."); Task.Run(async() => { //TODO: zrobić animacje await Task.Delay(6000); await AltAsync.Do(() => { vehicleToUpgrade.GameVehicle.ModKit = 1; if ((TuningType)itemUpgrade.FirstParameter == TuningType.Wheels) { vehicleToUpgrade.GameVehicle.SetWheels(category, variation); } else { vehicleToUpgrade.GameVehicle.SetMod(category, variation); } }); string actionFinished = IsStunned ? "zdemontowana" : "zamontowana"; sender.AccountEntity.Player.SendChatMessageInfo($"Część została {actionFinished}"); }); }
protected virtual void Remove() { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.ItemRepository.Delete(DbModel); } }
public void Save() { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.WarehouseRepository.Update(DbModel); } }
public void AddWorker(WorkerModel worker) { using (RoleplayContext ctx = Singletons.RoleplayContextFactory.Create()) { ctx.Attach(DbModel); DbModel.Workers.Add(worker); ctx.SaveChanges(); } }
public static async Task LoadServerEntity() { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unit = new UnitOfWork(ctx)) { await BuildingEntity.LoadBuildingsAsync(unit); await AtmEntity.LoadAtmsAsync(unit); await BusEntity.LoadBusAsync(unit); await ShopEntity.LoadShopAsync(unit); await GroupEntity.LoadGroupsAsync(unit); await WarehouseOrderEntity.LoadWarehouseOrdersAsync(); } JobEntity courierJob = new JobEntity(new JobEntityModel() { JobName = "Kurier", VehicleModel = AltV.Net.Enums.VehicleModel.Boxville2, RespawnVehicle = true, Position = new Position(26.1626f, -1300.59f, 29.2124f), RespawnVehiclePosition = new Position(36.9495f, -1283.84f, 29.2799f), RespawnVehicleRotation = new Rotation(0, 0, 1.53369f), JobType = JobType.Courier, MaxSalary = 400 }); courierJob.Create(); JobEntity junkerJob = new JobEntity(new JobEntityModel() { JobName = "Śmieciarz", VehicleModel = AltV.Net.Enums.VehicleModel.Trash, RespawnVehicle = true, Position = new Position(500.334f, -652.009f, 24.8989f), RespawnVehiclePosition = new Position(508.286f, -609.771f, 25.1348f), RespawnVehicleRotation = new Rotation(0, 0, 1.63264f), JobType = JobType.Junker, MaxSalary = 400 }); junkerJob.Create(); JobCenterEntity jobCenter = new JobCenterEntity(new JobCenterModel() { Id = 0, Position = new Position(104.73f, -934.075f, 29.8022f), Jobs = EntityHelper.GetJobs() }); jobCenter.Spawn(); }
public void Save() { RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (GroupsRepository repository = new GroupsRepository(ctx)) { repository.Update(DbModel); repository.Save(); } }
public async Task CreateStation(BusStopStation busStopStation) => await AltAsync.Do(() => { DbModel.BusStopStations.Add(busStopStation); RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.BusRepository.Update(DbModel); } });
public void Dispose() { EntityHelper.Remove(this); RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.WarehouseRepository.Delete(DbModel); } }
public void Save() { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.AccountRepository.Update(DbModel); } Alt.Log($"[ACCOUNT-ENTITY]: Zapisałem konto: [{DbModel.Id} | {DbModel.Username}]"); }
public static RoleplayContext GetDatabaseInstance() { if (Database == null) { Database = new RoleplayContextFactory().Create(); Alt.Log($"[MYSQL] Poprawnie stworzono polączenie z bazą danych"); } return(Database); }
public static void LoadBuildings() { RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (BuildingsRepository repository = new BuildingsRepository(ctx)) foreach (BuildingModel building in repository.GetAll()) { new BuildingEntity(building); } }
protected virtual void Delete() { RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (ItemsRepository repository = new ItemsRepository(ctx)) { repository.Delete(DbModel.Id); repository.Save(); } }
public void OnPlayerAddWarehouseItemHandler(Client sender, params object[] arguments) { /* Argumenty * args[0] string nameResult, * args[1] string itemTypeResult, * args[2] int costResult, * args[3] string groupTypeResult, * args[4] int minimalCostResult, * args[5] int weeklyCountResult, * args[6] int firstParameterResult = null, * args[7] int secondParameterResult = null, * args[8] int thirdParameterResult = null */ if (Enum.TryParse(arguments[3].ToString(), out GroupType groupType) && Enum.TryParse(arguments[1].ToString(), out ItemEntityType itemType)) { GroupWarehouseItemModel groupWarehouseItem = new GroupWarehouseItemModel { ItemTemplateModel = new ItemTemplateModel { Name = arguments[0].ToString(), ItemEntityType = itemType, }, Cost = Convert.ToDecimal(arguments[2]), ResetCount = Convert.ToInt32(arguments[5]), GroupType = groupType }; if (arguments[6] != null) { groupWarehouseItem.ItemTemplateModel.FirstParameter = (int)arguments[6]; } if (arguments[7] != null) { groupWarehouseItem.ItemTemplateModel.SecondParameter = (int)arguments[7]; } if (arguments[8] != null) { groupWarehouseItem.ItemTemplateModel.ThirdParameter = (int)arguments[8]; } RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (GroupWarehouseItemsRepository repository = new GroupWarehouseItemsRepository(ctx)) { repository.Insert(groupWarehouseItem); repository.Save(); } sender.SendInfo("Dodawanie przedmiotu zakończyło się pomyślnie."); } else { sender.SendError("Dodawanie przedmiotu zakończone niepowodzeniem."); } }
public static async Task LoadBuildingsAsync(UnitOfWork unit) { RoleplayContext ctx = Singleton.GetDatabaseInstance(); foreach (BuildingModel building in await unit.BuildingRepository.GetAll()) { Alt.Log($"[BUILDING-ENTITY: LOAD]: budynek o ID: {building.Id} został wczytany poprawnie!"); BuildingEntity buildingEntity = new BuildingEntity(building); await buildingEntity.Spawn(); } }
public virtual void Save() { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.ItemRepository.Update(DbModel); } Alt.Log($"[ITEM-ENTITY]: Zapisałem item: [{DbModel.Id} | {DbModel.Name}]"); }
public void Save() { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.BuildingRepository.Update(DbModel); } Alt.Log($"[BUILDING-ENTITY]: Zapisałem budynek: [{DbModel.Id} | {DbModel.Name}]"); // Zrobić zapisów budynków }
public static async Task LoadWarehouseOrdersAsync() { RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { foreach (WarehouseOrderModel order in await unitOfWork.WarehouseRepository.GetAllOrders()) { WarehouseOrderEntity orderEntity = new WarehouseOrderEntity(order); orderEntity.Spawn(); } } }
/// <summary> /// 1 parametr to liczba kontaktów do zapisania, /// 2 to liczba sms możliwych do zapisania, /// 3 to numer telefonu /// 4 to wygląd /// </summary> /// <param name="itemModel"></param> public Cellphone(ItemModel itemModel) : base(itemModel) { RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (TelephoneMessagesRepository messagesRepository = new TelephoneMessagesRepository(ctx)) using (TelephoneContactsRepository contactsRepository = new TelephoneContactsRepository(ctx)) { Messages = new ObservableCollection <TelephoneMessageModel>(messagesRepository.GetAll().Where(m => m.Cellphone.Id == Id)); Contacts = new ObservableCollection <TelephoneContactModel>(contactsRepository.GetAll().Where(m => m.Cellphone.Id == Id)); } Messages.CollectionChanged += Messages_CollectionChanged; Contacts.CollectionChanged += Contacts_CollectionChanged; }
private static void LoadCoreEntities() { //Group loading GroupEntityFactory factory = new GroupEntityFactory(); RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (GroupsRepository repository = new GroupsRepository(ctx)) { foreach (GroupModel group in repository.GetAll()) { factory.Create(group); } } }
public void PutItemToBuilding(Client player, ItemModel itemModel) { using (RoleplayContext ctx = Singletons.RoleplayContextFactory.Create()) { ctx.Attach(DbModel); ctx.Attach(itemModel); DbModel.ItemsInBuilding.Add(itemModel); itemModel.Building = DbModel; itemModel.Character = null; ctx.SaveChanges(); } }
public void Trade(bool bankAccount) { if (Getter.HasEnoughMoney(Money, bankAccount)) { if (_moneyToGroup && Sender.OnDutyGroup == null) { Sender.AccountEntity.Player.SendChatMessageError("Musisz znajdować się na służbie grupy"); return; } if (Item != null) { // TODO: Dorobić /me podaje przedmiot jakiś tam // TODO: Sprawdzić czy usuwa przedmioty z ekwipunku Item.Character = Getter.DbModel; RoleplayContext ctx = Singleton.GetDatabaseInstance(); using (UnitOfWork unitOfWork = new UnitOfWork(ctx)) { unitOfWork.ItemRepository.Update(Item); } Alt.Log($"[OFFER] Gracz {Sender.DbModel.Name} {Sender.DbModel.Surname} przekazał graczowi {Getter.DbModel.Name} {Getter.DbModel.Surname} ITEM: {Item.Name} CENA: {Money}"); } else if (Vehicle != null) { } if (_moneyToGroup) { Sender.OnDutyGroup.AddMoney(Money); } else { Sender.AddMoney(Money, bankAccount); } _action?.Invoke(Sender, Getter, Args); Getter.RemoveMoney(Money, bankAccount); } else { Getter.AccountEntity.Player.SendChatMessageError("Nie masz wystarczająco pieniędzy, aby wykonać tą transakcje"); Sender.AccountEntity.Player.SendChatMessageError("Wymiana została przerwana, gracz nie ma środków na koncie"); } }