/// <summary> /// Обработчик события регистрации урона от игрока игроку /// </summary> /// <param name="targetPlayer">Жертва</param> /// <param name="attackerPlayer">Фгрессор</param> internal void OnDamage(IMyPlayer targetPlayer, IMyPlayer attackerPlayer) { ///лагает ((( ///скорее всего изза постоянного обновления контрактов при нанесении урона try { LoadContracts(); lock (ContractStorage) { ///проверяем есть ли в заказах игрок-жертва if (ContractStorage.BountedPlayers.Where(x => x.SteamID == targetPlayer.SteamUserId).Count() > 0) { ContractStorage.BountedPlayers.Where(x => x.SteamID == targetPlayer.SteamUserId).ForEach(x => { ///проверяем есть ли активные контракты на жертву if (x.Contracts.Count > 0) { x.Contracts.ForEach(y => { ///если агрессор - владелец контракта на жертву - проверяяем на эксплойты if (y.HunterSteamID == attackerPlayer.SteamUserId) { ///если взял сам на себя контракт и атаковал сам себя (урон об воксели/структуры взял под дистанционное управление свою турель и выстрелил в себя) if (targetPlayer.SteamUserId == attackerPlayer.SteamUserId) { ///отменяем контракт if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, attackerPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } } else if (MyVisualScriptLogicProvider.GetPlayersFactionTag(targetPlayer.IdentityId) == null) { ///заглушка от фарма ///Игрок жертва должен находиться во фракции, если нет - отменяем контракт if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, attackerPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } } else if (MyVisualScriptLogicProvider.GetPlayersFactionTag(attackerPlayer.IdentityId) == null) { ///Игрок агрессор также должен находиться во фракции, если нет - удаляем контракт if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, targetPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } } else if (MyVisualScriptLogicProvider.GetPlayersFactionTag(targetPlayer.IdentityId) == MyVisualScriptLogicProvider.GetPlayersFactionTag(attackerPlayer.IdentityId)) { ///если охотник и жертва состоят в одной фракции - отменяем контракт ///Защита от договорного фарма if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, attackerPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } } //Фракции должны находиться друг с другом в состоянии войны //не работает функция, возвращает null вне зависимости от статусов фракций по отношению друк к другу ((( //else if (!MyVisualScriptLogicProvider.AreFactionsEnemies(MyVisualScriptLogicProvider.GetPlayersFactionTag(targetPlayer.IdentityId), MyVisualScriptLogicProvider.GetPlayersFactionTag(attackerPlayer.IdentityId))) //{ // Log.Info($"activator faction !enemy bountedPlayer faction"); // if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, attackerPlayer.IdentityId)) // { // Log.Info($"contract removed sucess"); // } // else // { // Log.Info($"contract removed failed"); // } //} else { ///если проверки пройдены - завершаем контракт и выплачиваем ревард if (MyAPIGateway.ContractSystem.TryFinishCustomContract(y.contract_id)) { Log.Info("contract finish sucess"); } } } }); } }); } ///если жертва наносит урон по охотнику else if (ContractStorage.BountedPlayers.Where(x => x.SteamID == attackerPlayer.SteamUserId).Count() > 0) { ContractStorage.BountedPlayers.Where(x => x.SteamID == attackerPlayer.SteamUserId).ForEach(x => { if (x.Contracts.Count > 0) { x.Contracts.ForEach(y => { if (y.HunterSteamID == targetPlayer.SteamUserId) { //те же самые проверки на эксплойты if (targetPlayer.SteamUserId == attackerPlayer.SteamUserId) { if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, targetPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } } else if (MyVisualScriptLogicProvider.GetPlayersFactionTag(targetPlayer.IdentityId) == null) { //Log.Info($"activator not in faction"); if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, targetPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } } else if (MyVisualScriptLogicProvider.GetPlayersFactionTag(attackerPlayer.IdentityId) == null) { //Log.Info($"activator not in faction"); if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, targetPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } }//если аттакер без фракции) else if (MyVisualScriptLogicProvider.GetPlayersFactionTag(targetPlayer.IdentityId) == MyVisualScriptLogicProvider.GetPlayersFactionTag(attackerPlayer.IdentityId)) { Log.Info($"activator faction = bountedPlayer faction"); if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, targetPlayer.IdentityId)) { Log.Info($"contract removed sucess"); } return; } //else if (!MyVisualScriptLogicProvider.AreFactionsEnemies(MyVisualScriptLogicProvider.GetPlayersFactionTag(targetPlayer.IdentityId), MyVisualScriptLogicProvider.GetPlayersFactionTag(attackerPlayer.IdentityId))) //{ // Log.Info($"activator faction !enemy bountedPlayer faction"); // if (MyAPIGateway.ContractSystem.TryAbandonCustomContract(y.contract_id, targetPlayer.IdentityId)) // { // Log.Info($"contract removed sucess"); // } // else // { // Log.Info($"contract removed failed"); // } //} else { ///если все проверки пройдены - завершаем контракт выплачиваем вознаграждение if (MyAPIGateway.ContractSystem.TryFailCustomContract(y.contract_id)) { Log.Info("contract failed sucess"); } } } }); } }); } } } catch (Exception e) { Log.Error(e.Message); Log.Error(e.StackTrace); } }