public void HandleRequest(IZoneRequest request) { using (var scope = Db.CreateTransaction()) { var sourceEid = request.Data.GetOrDefault <long>(k.source); var targetEid = request.Data.GetOrDefault <long>(k.target); var character = request.Session.Character; var sourceUnit = request.Zone.GetUnitOrThrow(sourceEid); var targetUnit = request.Zone.GetUnitOrThrow(targetEid); var sourceNode = sourceUnit.ThrowIfNotType <IPBSObject>(ErrorCodes.DefinitionNotSupported); sourceNode.ConnectionHandler.NetworkNodes.Any(n => n.IsReinforced()).ThrowIfTrue(ErrorCodes.NetworkHasReinforcedNode); var targetNode = targetUnit.ThrowIfNotType <IPBSObject>(ErrorCodes.DefinitionNotSupported); sourceNode.ConnectionHandler.BreakConnection(targetNode, character); Transaction.Current.OnCommited(() => { sourceNode.SendNodeUpdate(); PBSHelper.WritePBSLog(PBSLogType.disconnected, sourceUnit.Eid, sourceUnit.Definition, sourceUnit.Owner, character.Id, otherNodeEid: targetUnit.Eid, otherNodeDefinition: targetUnit.Definition, zoneId: request.Zone.Id); }); Message.Builder.FromRequest(request).WithOk().Send(); scope.Complete(); } }
private void LogWrite(PBSLogType logType) { var zone = _pbsUnit.Zone; if (zone != null) { PBSHelper.WritePBSLog(logType, _pbsUnit.Eid, _pbsUnit.Definition, _pbsUnit.Owner, zoneId: zone.Id); } }
private void OnConstructionLevelChanged() { var zone = _pbsUnit.Zone; if (zone == null) { return; } var currentLevel = ConstructionLevelCurrent; if (currentLevel <= 0) { //object got deconstructed, remove from zone, add capsule to loot if (_contructionLootDropped) { return; } _contructionLootDropped = true; using (var scope = Db.CreateTransaction()) { LootContainer.Create() .AddLoot(PBSHelper.GetCapsuleDefinitionByPBSObject(_pbsUnit), 1) .AddLoot(PBSHelper.GetConstructionAmmoLootOnDeconstruct(_pbsUnit)) .BuildAndAddToZone(zone, _pbsUnit.CurrentPosition); var dockingBase = _pbsUnit as PBSDockingBase; if (dockingBase != null) { Logger.DebugInfo("dropping loot from base"); PBSHelper.DropLootToZoneFromBaseItems(zone, dockingBase, false); } _pbsUnit.RemoveFromZone(); Logger.Info("pbs node got deconstructed. " + _pbsUnit.Eid + " " + _pbsUnit.ED.Name + " owner:" + _pbsUnit.Owner); PBSHelper.WritePBSLog(PBSLogType.deconstructed, _pbsUnit.Eid, _pbsUnit.Definition, _pbsUnit.Owner, zoneId: zone.Id); scope.Complete(); } return; } if (!IsFullyConstructed) { return; } SetToDeconstruct(); //felepult, mostmar lehet lebontani is vagy barmi PBSHelper.WritePBSLog(PBSLogType.constructed, _pbsUnit.Eid, _pbsUnit.Definition, _pbsUnit.Owner, zoneId: zone.Id); SendNodeUpdate(); }
public void HandleRequest(IZoneRequest request) { using (var scope = Db.CreateTransaction()) { var sourceEid = request.Data.GetOrDefault <long>(k.eid); var character = request.Session.Character; var state = request.Data.GetOrDefault <int>(k.state) == 1; var sourceUnit = request.Zone.GetUnitOrThrow(sourceEid); var sourceNode = (sourceUnit as IPBSObject).ThrowIfNull(ErrorCodes.DefinitionNotSupported); sourceNode.IsFullyConstructed().ThrowIfFalse(ErrorCodes.ObjectNotFullyConstructed); sourceNode.CheckAccessAndThrowIfFailed(character); if (PBSHelper.IsOfflineOnReinforce(sourceUnit)) { //ezeket nem lehet kapcsolgatni ha reinforceban vannak sourceNode.ReinforceHandler.CurrentState.IsReinforced.ThrowIfTrue(ErrorCodes.NotPossibleDuringReinforce); } if (sourceNode.OnlineStatus != state) { if (state) { //be akarunk valamit kapcsolni //ez a node akkor mehet csak onlineba ha nem rothadt ki alatta a mineral mar 1x var energyWell = sourceUnit as PBSEnergyWell; energyWell?.IsDepleted.ThrowIfTrue(ErrorCodes.EnergyWellDepleted); } sourceNode.SetOnlineStatus(state, true); sourceUnit.Save(); Transaction.Current.OnCommited(() => { sourceNode.SendNodeUpdate(); var logType = state ? PBSLogType.online : PBSLogType.offline; PBSHelper.WritePBSLog(logType, sourceEid, sourceUnit.Definition, sourceUnit.Owner, character.Id, background: false, zoneId: request.Zone.Id); }); } Message.Builder.FromRequest(request).WithOk().Send(); scope.Complete(); } }
public void HandleRequest(IZoneRequest request) { using (var scope = Db.CreateTransaction()) { var sourceEid = request.Data.GetOrDefault <long>(k.source); var targetEid = request.Data.GetOrDefault <long>(k.target); var character = request.Session.Character; var sourceUnit = request.Zone.GetUnitOrThrow(sourceEid); var targetUnit = request.Zone.GetUnitOrThrow(targetEid);; if (sourceUnit is IPBSObject sourceNode && targetUnit is IPBSObject targetNode) { try { sourceNode.ConnectionHandler.MakeConnection(targetNode, character); PBSHelper.WritePBSLog(PBSLogType.connected, sourceUnit.Eid, sourceUnit.Definition, sourceUnit.Owner, character.Id, otherNodeEid: targetUnit.Eid, otherNodeDefinition: targetUnit.Definition, zoneId: request.Zone.Id, background: false); Transaction.Current.OnCommited(() => sourceNode.SendNodeUpdate()); } catch (PerpetuumException gex) { if (gex.error != ErrorCodes.DockingBaseExistsInNetwork) { throw; } foreach (var node in targetNode.ConnectionHandler.NetworkNodes.OfType <Unit>()) { node.Owner = targetUnit.Owner; } throw; } } Message.Builder.FromRequest(request).WithOk().Send(); scope.Complete(); } }
protected override void PBSActiveObjectAction(IZone zone) { if (IsDepleted) { return; //kifogyott alola a mineral } _lastCoreUsed = 0; // van-e reaktor a networkbe akinek hianyzik egy toltes var reactors = ConnectionHandler.NetworkNodes.OfType <PBSReactor>().Where(r => (r.CoreMax - r.Core) > CoreTransferred && r.OnlineStatus).ToList(); if (reactors.Count == 0) { return; //no reactor to feed } var mineralLayer = zone.Terrain.GetMaterialLayer(MaterialType.EnergyMineral) as MineralLayer; if (mineralLayer == null) { Logger.Error("mineral not found on zone " + MaterialType.EnergyMineral + " zoneID:" + zone.Configuration.Id); return; } //egy ciklusra mennyit banyaszik ebbol a fajtabol //ennyit akar maximum kiszedni a sok csempebol var extractedMaterials = ExtractWithinRange(mineralLayer, CurrentPosition, WorkRange, (uint)CoreTransferred); if (extractedMaterials.Count <= 0) { //nemtom, barmi, le is kapcsolhatja magat _wasMineralCollected = false; IsDepleted = true; //mineral got depleted Logger.Info("energy well got depleted " + this); SetOnlineStatus(false, false); PBSHelper.WritePBSLog(PBSLogType.wellDepleted, Eid, Definition, Owner, zoneId: zone.Configuration.Id); return; } //juhe volt mineral, pakoljunk coret a network reactorjaiba var sumCollected = extractedMaterials.Sum(i => (double)i.Quantity); Logger.Info(sumCollected + " mineral was drilled by " + ED.Name); sumCollected *= TransferEfficiency; Logger.Info(sumCollected + " core will be distributed "); var amountPerReactor = sumCollected / reactors.Count; Logger.Info(reactors.Count + " reactors. per node amount: " + amountPerReactor); foreach (var pbsReactor in reactors) { pbsReactor.CoreFromEnergyWell((int)amountPerReactor); } //output _lastCoreUsed = sumCollected; _wasMineralCollected = true; }
private void DoEnter() { var pbsUnitObject = ReinforceHandler._pbsUnit; var zone = pbsUnitObject.Zone; if (zone == null) { return; } //ettol van rajta a grafikai effekt pbsUnitObject.States.Reinforced = true; pbsUnitObject.DynamicProperties.Set(k.isReinforced, 1); //if already set by the init, then we skip this part if (_reinforceEnd.Equals(default(DateTime))) { Logger.Info(" fresh reinforce start for " + pbsUnitObject); var killer = _reinforceStartedBy?.Id; //sql log PBSHelper.WritePBSLog(PBSLogType.reinforceStart, pbsUnitObject.Eid, pbsUnitObject.Definition, pbsUnitObject.Owner, zoneId: zone.Configuration.Id, killerCharacterId: killer); var oldCounter = ReinforceHandler.ReinforceCounter; //elveszunk egy lehetoseget ReinforceHandler.DecreaseReinforceCounter(); var newCounter = ReinforceHandler.ReinforceCounter; //kozoljuk, h mikor lesz a kovetkezo reinforce increase ReinforceHandler.SetNextReinforceCounterIncreaseFromNow(VULNERABLE_LENGTH_MINUTES + REINFORCE_LENGTH_MINUTES); Logger.Info("reinforce counter from:" + oldCounter + " to:" + newCounter + " " + pbsUnitObject.ED.Name); var networkNodes = pbsUnitObject.ConnectionHandler.NetworkNodes.ToArray(); if (networkNodes.Length > 1) { //ez egy networkben levo node //ez a bazis a networkben var pbsDockingBase = networkNodes.FirstOrDefault(o => o is PBSDockingBase); if (pbsDockingBase != null) { //van bazis a networkben //abban van a napi offset beallitva if (!pbsDockingBase.Equals(pbsUnitObject)) { //not myself ReinforceHandler._offsetHoursWithinDay = pbsDockingBase.ReinforceHandler.ReinforceOffsetHours; //transfer the daily offset from the base Logger.Info("daily offset was transferred from base to:" + pbsUnitObject.ED.Name + " " + pbsUnitObject.Name); } //search for the first reinforced node foreach (var networkNode in networkNodes) { if (networkNode.Equals(pbsUnitObject)) { continue; } if (!networkNode.ReinforceHandler.CurrentState.IsReinforced) { continue; } //ebben a nodeban van, hogy mikor lesz vege a reinforcenak var tmpEnd = networkNode.ReinforceHandler.GetReinforceDetails(); if (!tmpEnd.Equals(default(DateTime)) && DateTime.Now < tmpEnd) { _reinforceEnd = tmpEnd; Logger.Info(" "); Logger.Info(" reinforceEnd:" + _reinforceEnd); Logger.Info("reinforce timer transferred to:" + pbsUnitObject); GoOfflineOnReinforce(pbsUnitObject); return; } } } } //ez az ag amikor egyedul van a networkben a node amit megtamadtak //vagy nem volt node ami meghatarozta volna az ertekeket _reinforceEnd = CalculateReinforceEnd(); Logger.Info("reinforceEnd:" + _reinforceEnd); Logger.Info("node switches to reinforced: " + pbsUnitObject.Name + " " + pbsUnitObject.Eid + " " + pbsUnitObject.ED.Name); } else { Logger.Info("ACTIVE REINFORCE STATE: skipping inital round, this is a server restart " + pbsUnitObject.Eid + " " + pbsUnitObject.Name); } GoOfflineOnReinforce(pbsUnitObject); }
private void DoSummon(IZone zone) { Logger.Info("DoSummon starts on zone:" + zone.Id + " " + this); if (DeployerPlayer == null) { Logger.Error("no deployer player " + this); return; } var corporation = DeployerPlayer.Character.GetPrivateCorporation(); if (corporation == null) { Logger.Error("no private corporation was found. Deployer character: " + DeployerPlayer.Character); DeployerPlayer.Character.SendErrorMessage(new Command("pbsDeployItem"), ErrorCodes.PrivateCorporationAllowedOnly); return; } var centerTile = CurrentPosition.Center; PBSDockingBase dockingBase; using (var scope = Db.CreateTransaction()) { try { var deployableItem = (Unit)_entityServices.Factory.CreateWithRandomEID(TargetPBSNodeDefault); var zoneStorage = zone.Configuration.GetStorage(); zoneStorage.AddChild(deployableItem); SetStartCore(deployableItem); dockingBase = deployableItem as PBSDockingBase; if (dockingBase != null) { PBSHelper.CreatePBSDockingBase(dockingBase); } deployableItem.Owner = corporation.Eid; deployableItem.Orientation = FastRandom.NextInt(0, 3) * 0.25; deployableItem.CurrentPosition = CurrentPosition.Center; if (deployableItem is PBSTurret turret) { // csak a turret kell, gyerekek nem Repository.Insert(turret); } else { // itt mindent insertalunk deployableItem.Save(); } Logger.Info("node saved to sql " + deployableItem); Logger.Info("pbs insert start in zoneuser entities: " + deployableItem); zone.UnitService.AddUserUnit(deployableItem, centerTile); Logger.Info("pbs log starting " + deployableItem); PBSHelper.WritePBSLog(PBSLogType.deployed, deployableItem.Eid, deployableItem.Definition, deployableItem.Owner, DeployerPlayer.Character.Id, background: false, zoneId: zone.Id); Transaction.Current.OnCompleted((completed) => { if (!completed) { Logger.Error("DoSummon rollback " + this); return; } Logger.Info("starting zone enter: " + deployableItem); deployableItem.AddToZone(zone, centerTile); Logger.Info("added to zone " + deployableItem); dockingBase?.OnDockingBaseDeployed(); //draw terrain stuff PBSHelper.OnPBSObjectDeployed(zone, deployableItem, true, true, true); Logger.Info("terrain stuff done, sending update. " + deployableItem); //send update ((IPBSObject)deployableItem).SendNodeUpdate(); zone.CreateBeam(BeamType.red_20sec, builder => builder.WithPosition(CurrentPosition.Center) .WithState(BeamState.Hit) .WithDuration(15000)); Logger.Info("pbs node successfully deployed."); _successfulSummon = true; }); scope.Complete(); } catch (Exception ex) { Logger.Exception(ex); } } }