public void OnUpdateHandler() { if (LoadingFinished) { if (DateTime.Now.Subtract(_minuteAnnounce).TotalMinutes >= 1) { // Уровень пользователя try { var characters = ContextFactory.Instance.Character.Where(x => x.Online); foreach (var character in characters) { character.PlayMinutes++; // Уровень за 4 часа пребывания в игре if (character.PlayMinutes % 240 == 0) { character.Level = character.PlayMinutes / 240; try { var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.shared.sendChatMessageToPlayer(currentPlayer, "~g~[СЕРВЕР]: ~w~ Поздравляем! Теперь вы достигли " + character.Level + " уровня."); } catch (Exception e) { EntityManager.Log(e, "Уровень за 4 часа пребывания в игре."); } } // Зарплата за час пребывания в игре if (character.PlayMinutes % 60 == 0) { var isTaxiVehicle = ContextFactory.Instance.Vehicle.FirstOrDefault(x => x.CharacterId == character.Id); var money = 0; if (character.JobId == JobsIdNonDataBase.TaxiDriver && isTaxiVehicle != null) { money += WorkPay.TaxiDriver; // TaxiDrivers } if (character.JobId == JobsIdNonDataBase.Unemployer) { money += WorkPay.Unemployer; // Unemployers } money += PayDayMoney.GetPayDaYMoney(character.ActiveGroupID); character.Cash += money; try { var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.shared.sendChatMessageToPlayer(currentPlayer, "~g~[СЕРВЕР]: ~w~ Вы получили деньги: " + money + "$."); API.shared.triggerClientEvent(currentPlayer, "update_money_display", character.Cash); } catch (Exception e) { EntityManager.Log(e, "Зарплата. Отображение полученных денег."); } } } ContextFactory.Instance.SaveChanges(); } catch (Exception e) { EntityManager.Log(e, "Уровень пользователя"); } // Капт сектора try { var tick = 0; var startCapting = ContextFactory.Instance.Caption.First(x => x.Id == 1); if (startCapting.Sector != "0;0") { API.sendChatMessageToAll("~r~Начался капт сектора: " + startCapting.Sector); var sector = startCapting.Sector.Split(';'); tick += 1; if (tick == 3) { var getAttackGroup = ContextFactory.Instance.Group.FirstOrDefault(x => x.Id == startCapting.GangAttack * 100); if (getAttackGroup == null) { return; } var groupAttackType = (GroupType)Enum.Parse(typeof(GroupType), getAttackGroup.Type.ToString()); var getDefendGroup = ContextFactory.Instance.Group.FirstOrDefault(x => x.Id == startCapting.GangDefend * 100); if (getDefendGroup == null) { return; } var groupDefendType = (GroupType)Enum.Parse(typeof(GroupType), getDefendGroup.Type.ToString()); if (startCapting.FragsAttack > startCapting.FragsDefend /*|| * startCapting.FragsAttack == 0 && startCapting.FragsDefend == 0*/) { GroupController.SetGangSectorData(Convert.ToInt32(sector[0]), Convert.ToInt32(sector[1]), startCapting.GangAttack); API.shared.sendChatMessageToAll( "Банда: " + EntityManager.GetDisplayName(groupAttackType) + "захватила у банды: \n" + EntityManager.GetDisplayName(groupDefendType) + "сектор: " + startCapting.Sector); } else if (startCapting.FragsAttack < startCapting.FragsDefend) { GroupController.SetGangSectorData(Convert.ToInt32(sector[0]), Convert.ToInt32(sector[1]), startCapting.GangDefend); API.shared.sendChatMessageToAll( "Банда: " + EntityManager.GetDisplayName(groupAttackType) + "не смогла захватить у банды: \n" + EntityManager.GetDisplayName(groupDefendType) + "сектор: " + startCapting.Sector); } GroupController.SetDefaultCaption(1); } } } catch (Exception e) { EntityManager.Log(e, "Капт сектора"); } // Тестовая зона (ежеминутный тик) try { } catch (Exception e) { EntityManager.Log(e, "Тестовая зона (ежеминутный тик)"); } _minuteAnnounce = DateTime.Now; } if (DateTime.Now.Subtract(_hourAnnounce).TotalMinutes >= 60) { // Начисление зарплаты в банк банд каждый час по количеству квадратов. try { var numInc = 0; for (var i = 1300; i <= 1700; i += 100) { var currentGang = ContextFactory.Instance.Group.First(x => x.Id == i); var numOfSectors = GroupController.GetCountOfGangsSectors(); var money = numOfSectors[numInc] * 50; currentGang.MoneyBank += money; ContextFactory.Instance.SaveChanges(); numInc++; } } catch (Exception e) { EntityManager.Log(e, "Начисление зарплаты за квадраты банд"); } // Начисление зарплаты в за каждый бизнес. Пока 10К за любую заправку. try { var characters = ContextFactory.Instance.Character.Where(x => x.Online).ToList(); ContextFactory.Instance.SaveChanges(); foreach (var character in characters) { var jobs = ContextFactory.Instance.Job.Where(y => y.CharacterId == character.Id).ToList(); foreach (var job in jobs) { character.Cash += job.Cost; ContextFactory.Instance.SaveChanges(); try { var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.shared.sendChatMessageToPlayer(currentPlayer, "~g~[СЕРВЕР]: ~w~ Вы получили за " + job.Id + " бизнес: " + job.Cost + "$."); API.shared.triggerClientEvent(currentPlayer, "update_money_display", character.Cash); } catch (Exception e) { EntityManager.Log(e, "Начисление зарплаты в за каждый бизнес (внутренний цикл)"); } } } } catch (Exception e) { EntityManager.Log(e, "Начисление зарплаты в за каждый бизнес"); } _hourAnnounce = DateTime.Now; } // List of players if (DateTime.Now.Subtract(_mLastTick).TotalMilliseconds >= 500) { var changedNames = new List <string>(); var players = API.getAllPlayers(); foreach (var player in players) { string lastName = player.getData("playerlist_lastname"); if (lastName == null) { player.setData("playerlist_lastname", player.name); continue; } if (lastName != player.name) { player.setData("playerlist_lastname", player.name); var characterToList = ContextFactory.Instance.Character.FirstOrDefault(x => x.SocialClub == player.socialClubName); if (characterToList == null) { return; } var dic = new Dictionary <string, object> { ["userName"] = characterToList.Name, ["userID"] = characterToList.Id, ["socialClubName"] = player.socialClubName, ["newName"] = player.name }; changedNames.Add(API.toJson(dic)); } } if (changedNames.Count > 0) { API.triggerClientEventForAll("playerlist_changednames", changedNames); } _mLastTick = DateTime.Now; } } }
public void OnUpdateHandler() { if (LoadingFinished) { // 1 MINUTES EVENTS: if (DateTime.Now.Subtract(_minuteAnnounce).TotalMinutes >= 1) { // Уровень пользователя try { var characters = ContextFactory.Instance.Character.Where(x => x.Online).ToList(); var governmentBase = ContextFactory.Instance.Group.FirstOrDefault(x => x.Id == 1100); foreach (var character in characters) { character.PlayMinutes++; // Уровень за 4 часа пребывания в игре if (character.PlayMinutes % 240 == 0) { character.Level = character.PlayMinutes / 240; try { var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.shared.sendChatMessageToPlayer(currentPlayer, "~g~[СЕРВЕР]: ~w~ Поздравляем! Теперь вы достигли " + character.Level + " уровня."); EntityManager.Success("Игрок " + character.Name + " достиг уровня: " + character.Level); } catch (Exception e) { EntityManager.Log(e, "Уровень за 4 часа пребывания в игре."); } } // Зарплата за час пребывания в игре if (character.PlayMinutes % 60 == 0) { var taxes = ContextFactory.Instance.Taxes.FirstOrDefault(x => x.Id == 1); var isTaxiVehicle = ContextFactory.Instance.Vehicle.FirstOrDefault(x => x.CharacterId == character.Id); var money = 0; var taxesMoney = 0; if (character.JobId == JobsIdNonDataBase.TaxiDriver && isTaxiVehicle != null) { money += WorkPay.TaxiDriver; // TaxiDrivers } if (character.JobId == JobsIdNonDataBase.Unemployer) { money += WorkPay.Unemployer; // Unemployers } money += PayDayMoney.GetPayDaYMoney(character.ActiveGroupID); if (taxes != null) { if (governmentBase != null) { taxesMoney = money * taxes.PersonalIncomeTax / 100; governmentBase.MoneyBank += taxesMoney; } money = money - money * taxes.PersonalIncomeTax / 100; } character.Cash += money; try { var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.shared.sendChatMessageToPlayer(currentPlayer, "~g~[СЕРВЕР]: ~w~ Вы получили деньги: " + money + "$."); API.shared.sendChatMessageToPlayer(currentPlayer, "~y~[СЕРВЕР]: ~w~ Вы заплатили налогов: " + taxesMoney + "$."); API.shared.triggerClientEvent(currentPlayer, "update_money_display", character.Cash); EntityManager.Success("Игрок " + character.Name + " получил зарплату: " + money + "$"); } catch (Exception e) { EntityManager.Log(e, "Зарплата. Отображение полученных денег."); } } } ContextFactory.Instance.SaveChangesAsync(); } catch (Exception e) { EntityManager.Log(e, "Уровень пользователя"); } // Капт сектора try { var startCapting = ContextFactory.Instance.Caption.FirstOrDefault(x => x.Id == 1); if (startCapting == null) { return; } if (startCapting.Sector != "0;0") { if (_tick == 0) { API.sendChatMessageToAll("~s~Начался ~g~капт ~s~сектора: ~g~" + startCapting.Sector); } else { API.sendChatMessageToAll("~s~Идет ~g~капт ~s~сектора: ~g~" + startCapting.Sector + " ~s~|~g~ " + _tick + " ~s~минут"); } var sector = startCapting.Sector.Split(';'); GroupController.SetGangSectorData(Convert.ToInt32(sector[0]), Convert.ToInt32(sector[1]), 111); if (_tick == 10) { var getAttackGroup = ContextFactory.Instance.Group.FirstOrDefault(x => x.Id == startCapting.GangAttack * 100); if (getAttackGroup == null) { return; } var groupAttackType = (GroupType)Enum.Parse(typeof(GroupType), getAttackGroup.Type.ToString()); ContextFactory.Instance.SaveChangesAsync(); var getDefendGroup = ContextFactory.Instance.Group.FirstOrDefault(x => x.Id == startCapting.GangDefend * 100); if (getDefendGroup == null) { return; } var groupDefendType = (GroupType)Enum.Parse(typeof(GroupType), getDefendGroup.Type.ToString()); string message; ContextFactory.Instance.SaveChangesAsync(); if (startCapting.FragsAttack > startCapting.FragsDefend) { GroupController.SetGangSectorData(Convert.ToInt32(sector[0]), Convert.ToInt32(sector[1]), startCapting.GangAttack); message = "Банда: ~g~" + EntityManager.GetDisplayName(groupAttackType) + "~g~захватила ~s~у банды: \n~g~" + EntityManager.GetDisplayName(groupDefendType) + "~s~сектор: ~g~" + startCapting.Sector; API.shared.sendChatMessageToAll(message); EntityManager.Success(message); } else if (startCapting.FragsAttack <= startCapting.FragsDefend) { GroupController.SetGangSectorData(Convert.ToInt32(sector[0]), Convert.ToInt32(sector[1]), startCapting.GangDefend); message = "Банда: ~g~" + EntityManager.GetDisplayName(groupAttackType) + "~r~не смогла захватить ~s~у банды: \n~g~" + EntityManager.GetDisplayName(groupDefendType) + "~s~сектор: ~g~" + startCapting.Sector; API.shared.sendChatMessageToAll(message); EntityManager.Success(message); } GroupController.SetDefaultCaption(1); _tick = 0; } _tick++; } } catch (Exception e) { EntityManager.Log(e, "Капт сектора"); } // PRISON: try { var characters = ContextFactory.Instance.Character.Where(x => x.PrisonTime != 0).ToList(); foreach (var character in characters) { character.PrisonTime--; if (character.PrisonTime != 0) { var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.freezePlayer(currentPlayer, true); API.sendNotificationToPlayer(currentPlayer, "~g~Вам осталось сидеть в тюрьме еще " + character.PrisonTime + " мин."); } if (character.IsPrisoned && character.PrisonTime == 0) { var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); character.PrisonTime = 0; character.IsPrisoned = false; API.freezePlayer(currentPlayer, false); API.setEntityPosition(currentPlayer, new Vector3(432.43, -981.47, 30.71)); } ContextFactory.Instance.SaveChangesAsync(); } } catch (Exception e) { EntityManager.Log(e, "PRISON DEBUG"); } // WRITE PLAYER POS FOR AFK: try { var players = API.getAllPlayers(); foreach (var player in players) { player.setData("AFKPOSITION", player.position); player.setData("AFKROTATION", player.rotation); } } catch (Exception e) { EntityManager.Log(e, "AFK WRITE POSITION"); } // Тестовая зона (ежеминутный тик) try { } catch (Exception e) { EntityManager.Log(e, "Тестовая зона (ежеминутный тик)"); } _minuteAnnounce = DateTime.Now; } // 60 MINUTES EVENTS: if (DateTime.Now.Subtract(_hourAnnounce).TotalMinutes >= 60) { // Начисление зарплаты в банк банд каждый час по количеству квадратов. try { var numInc = 0; for (var i = 1300; i <= 1700; i += 100) { var currentGang = ContextFactory.Instance.Group.First(x => x.Id == i); var numOfSectors = GroupController.GetCountOfGangsSectors(); var money = numOfSectors[numInc] * 50; currentGang.MoneyBank += money; ContextFactory.Instance.SaveChangesAsync(); numInc++; EntityManager.Success("Начислено " + money + "$ банде: " + currentGang.Name); } } catch (Exception e) { EntityManager.Log(e, "Начисление зарплаты за квадраты банд"); } // Начисление зарплаты за каждый бизнес. try { var characters = ContextFactory.Instance.Character.Where(x => x.Online).ToList(); var governmentBase = ContextFactory.Instance.Group.FirstOrDefault(x => x.Id == 1100); foreach (var character in characters) { var jobs = ContextFactory.Instance.Job.Where(y => y.CharacterId == character.Id).ToList(); var taxes = ContextFactory.Instance.Taxes.FirstOrDefault(x => x.Id == 1); var characterHouses = ContextFactory.Instance.Property.Where(x => x.CharacterId == character.Id).ToList(); if (characterHouses != null) { var taxesForHouses = ContextFactory.Instance.Taxes.FirstOrDefault(x => x.Id == 1); if (taxesForHouses != null) { foreach (var house in characterHouses) { var taxesMoney = house.Stock * TaxesByType.GetHouseClass(taxesForHouses, house.Stock) / 100; character.Cash -= taxesMoney; ContextFactory.Instance.SaveChangesAsync(); var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.shared.sendChatMessageToPlayer(currentPlayer, "~y~[СЕРВЕР]: ~w~ Вы заплатили за дом номер " + house.PropertyID + " налогов: " + taxesMoney + "$."); API.shared.triggerClientEvent(currentPlayer, "update_money_display", character.Cash); } } } foreach (var job in jobs) { var taxesMoney = 0; if (taxes != null) { if (governmentBase != null) { taxesMoney = job.Cost * taxes.PersonalIncomeTax / 100; governmentBase.MoneyBank += taxesMoney; } } job.Cost = job.Cost - taxesMoney; character.Cash += job.Cost; ContextFactory.Instance.SaveChanges(); var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); if (currentPlayer == null) { continue; } API.shared.sendChatMessageToPlayer(currentPlayer, "~g~[СЕРВЕР]: ~w~ Вы получили за " + job.Id + " бизнес: " + job.Cost + "$."); API.shared.sendChatMessageToPlayer(currentPlayer, "~y~[СЕРВЕР]: ~w~ Вы заплатили налогов за " + job.Id + " бизнес: " + taxesMoney + "$."); API.shared.triggerClientEvent(currentPlayer, "update_money_display", character.Cash); EntityManager.Success("Начислено " + job.Cost + "$ владельцу бизнеса: " + character.Name); } } } catch (Exception e) { EntityManager.Log(e, "Начисление зарплаты в за каждый бизнес"); } // Наркотическая ломка. try { var characters = ContextFactory.Instance.Character.Where(x => x.Online).ToList(); foreach (var character in characters) { if (character.NarcoDep > 3000) { // TODO: ANIMATION OF THIS var currentPlayer = API.shared.getAllPlayers() .FirstOrDefault(x => x.socialClubName == character.SocialClub); API.playPlayerAnimation(currentPlayer, 1, "mp_basejump", "base_jump_spot"); API.sendNotificationToPlayer(currentPlayer, "~r~У вас наркотическая ломка!"); } } ContextFactory.Instance.SaveChangesAsync(); } catch (Exception e) { EntityManager.Log(e, "Наркотическая ломка"); } _hourAnnounce = DateTime.Now; } // AFK KICK: if (DateTime.Now.Subtract(_afkAnnounce).TotalMinutes >= 15) { var players = API.getAllPlayers(); foreach (var player in players) { Vector3 playerPos = player.getData("AFKPOSITION"); if (playerPos == null) { continue; } Vector3 playerRot = player.getData("AFKROTATION"); if (playerRot == null) { continue; } if (playerPos != player.position && playerRot != player.rotation) { continue; } API.sendNotificationToPlayer(player, "~r~Вас кикнули с сервера за АФК"); API.kickPlayer(player, "AFK"); } _afkAnnounce = DateTime.Now; } // LIST OF PLAYERS: if (DateTime.Now.Subtract(_mLastTick).TotalMilliseconds >= 100) { var changedNames = new List <string>(); var players = API.getAllPlayers(); foreach (var player in players) { string lastName = player.getData("playerlist_lastname"); if (lastName == null) { player.setData("playerlist_lastname", player.name); continue; } if (lastName != player.name) { player.setData("playerlist_lastname", player.name); var characterToList = ContextFactory.Instance.Character.FirstOrDefault(x => x.SocialClub == player.socialClubName); if (characterToList == null) { return; } var dic = new Dictionary <string, object> { ["userName"] = characterToList.Name, ["userID"] = characterToList.OID, ["socialClubName"] = player.socialClubName, ["newName"] = player.name }; changedNames.Add(API.toJson(dic)); } } if (changedNames.Count > 0) { API.triggerClientEventForAll("playerlist_changednames", changedNames); } _mLastTick = DateTime.Now; } // HEAL | VOICE: if (DateTime.Now.Subtract(_secHeal).TotalSeconds >= 1) { //string bigSql = ""; var players = API.getAllPlayers(); foreach (var player in players) { if (player.getData("ISLOGINSUCCES") == true) { try { var pos = API.getEntityPosition(player); var vehicleNumber = -1; if (player.isInVehicle) { vehicleNumber = API.getEntityData(player.vehicle, "vehicle_number"); } var character = ContextFactory.Instance.Character.FirstOrDefault( x => x.SocialClub == player.socialClubName); character.X = pos.X; character.Y = pos.Y; character.Z = pos.Z; character.player_vehicle = vehicleNumber; character.button_voice = player.getData("BUTTON_VOICE"); ContextFactory.Instance.SaveChangesAsync(); /* * big_sql = big_sql + * "UPDATE `godfather`.`character` SET `X` = '" + pos.X + * "', `Y` = '" + pos.Y + "', Z = '" + pos.Z + * "', `player_vehicle` = " + vehicle_number + * ", `button_voice` = " + player.getData("BUTTON_VOICE") + * " WHERE `character`.`SocialClub` = '" + player.socialClubName + "';";*/ } catch (Exception e) { EntityManager.Log(e, "Голосовая связь"); } } if (player.getData("NEEDHEAL") == true) { if (player.health == 100) { player.setData("NEEDHEAL", false); continue; } player.health++; } } //if (big_sql != "") mysql_query(big_sql); _secHeal = DateTime.Now; } } }