protected LOSResult GetLineOfSight(Unit target) { Debug.Assert(ParentRobot != null, "ParentRobot != null"); var visibility = ParentRobot.GetVisibility(target); return(visibility?.GetLineOfSight(IsCategory(CategoryFlags.cf_missiles)) ?? LOSResult.None); }
protected override void OnAction() { var amount = armorRepairAmount.Value; OnRepair(ParentRobot, amount); ParentRobot.SpreadAssistThreatToNpcs(ParentRobot, new Threat(ThreatType.Support, amount)); }
private void DoExtractMinerals(IZone zone) { var terrainLock = GetLock().ThrowIfNotType <TerrainLock>(ErrorCodes.InvalidLockType); var ammo = GetAmmo() as MiningAmmo; if (ammo == null) { return; } var materialInfo = _materialHelper.GetMaterialInfo(ammo.MaterialType); CheckEnablerEffect(materialInfo); var mineralLayer = zone.Terrain.GetMineralLayerOrThrow(materialInfo.Type); var materialAmount = materialInfo.Amount * _miningAmountModifier.Value; var extractedMaterials = Extract(mineralLayer, terrainLock.Location, (uint)materialAmount); extractedMaterials.Count.ThrowIfEqual(0, ErrorCodes.NoMineralOnTile); extractedMaterials.AddRange(_rareMaterialHandler.GenerateRareMaterials(materialInfo.EntityDefault.Definition)); CreateBeam(terrainLock.Location, BeamState.AlignToTerrain); using (var scope = Db.CreateTransaction()) { Debug.Assert(ParentRobot != null, "ParentRobot != null"); var container = ParentRobot.GetContainer(); Debug.Assert(container != null, "container != null"); container.EnlistTransaction(); var player = ParentRobot as Player; Debug.Assert(player != null, "player != null"); foreach (var material in extractedMaterials) { var item = (Item)Factory.CreateWithRandomEID(material.Definition); item.Owner = Owner; item.Quantity = material.Quantity; container.AddItem(item, true); var drilledMineralDefinition = material.Definition; var drilledQuantity = material.Quantity; player.MissionHandler.EnqueueMissionEventInfo(new DrillMineralEventInfo(player, drilledMineralDefinition, drilledQuantity, terrainLock.Location)); player.Zone?.MiningLogHandler.EnqueueMiningLog(drilledMineralDefinition, drilledQuantity); } //save container container.Save(); OnGathererMaterial(zone, player); Transaction.Current.OnCommited(() => container.SendUpdateToOwnerAsync()); scope.Complete(); } }
private void DoConstruct() { var unitLock = GetLock().ThrowIfNotType <UnitLock>(ErrorCodes.InvalidLockType); var pbsObject = (unitLock.Target as IPBSObject).ThrowIfNull(ErrorCodes.DefinitionNotSupported); //itt epit vagy unepit var ammo = GetAmmo(); var constructionAmount = ammo.GetPropertyModifier(AggregateField.construction_charge_amount); if (constructionAmount.Value < 0) { //deconstructhoz access kell pbsObject.CheckAccessAndThrowIfFailed(ParentRobot.GetCharacter()); pbsObject.ReinforceHandler.CurrentState.IsReinforced.ThrowIfTrue(ErrorCodes.NotPossibleDuringReinforce); var dockingBase = pbsObject as PBSDockingBase; dockingBase?.IsDeconstructAllowed().ThrowIfError(); pbsObject.OnlineStatus.ThrowIfTrue(ErrorCodes.NotPossibleOnOnlineNode); } pbsObject.ModifyConstructionLevel((int)constructionAmount.Value).ThrowIfError(); CreateBeam(unitLock.Target, BeamState.AlignToTerrain); }
public void ApplyRobotPropertyModifiers(ref ItemPropertyModifier modifier) { var modifiers = PropertyModifiers.GetOrEmpty(modifier.Field); foreach (var m in modifiers) { ParentRobot?.GetPropertyModifier(m).Modify(ref modifier); } }
private void DoHarvesting(IZone zone) { var terrainLock = GetLock().ThrowIfNotType <TerrainLock>(ErrorCodes.InvalidLockType); CreateBeam(terrainLock.Location, BeamState.AlignToTerrain); using (var scope = Db.CreateTransaction()) { using (new TerrainUpdateMonitor(zone)) { var plantInfo = zone.Terrain.Plants.GetValue(terrainLock.Location); var amountModifier = _harverstingAmountModifier.GetValueByPlantType(plantInfo.type); IPlantHarvester plantHarvester = _plantHarvesterFactory(zone, amountModifier); var harvestedPlants = plantHarvester.HarvestPlant(terrainLock.Location); Debug.Assert(ParentRobot != null, "ParentRobot != null"); var container = ParentRobot.GetContainer(); Debug.Assert(container != null, "container != null"); container.EnlistTransaction(); var player = ParentRobot as Player; Debug.Assert(player != null, "player != null"); foreach (var extractedMaterial in harvestedPlants) { var item = (Item)Factory.CreateWithRandomEID(extractedMaterial.Definition); item.Owner = Owner; item.Quantity = extractedMaterial.Quantity; container.AddItem(item, true); player.MissionHandler.EnqueueMissionEventInfo(new HarvestPlantEventInfo(player, extractedMaterial.Definition, extractedMaterial.Quantity, terrainLock.Location)); } //everything went ok, save container container.Save(); OnGathererMaterial(zone, player); Transaction.Current.OnCommited(() => container.SendUpdateToOwnerAsync()); scope.Complete(); } } }
protected Lock GetLock() { var currentLock = Lock.ThrowIfNull(ErrorCodes.LockTargetNotFound); currentLock.State.ThrowIfNotEqual(LockState.Locked, ErrorCodes.LockIsInProgress); var unitLockTarget = currentLock as UnitLock; if (unitLockTarget != null) { IsInRange(unitLockTarget.Target.CurrentPosition).ThrowIfFalse(ErrorCodes.TargetOutOfRange); var parentPlayer = ParentRobot as Player; if (ED.AttributeFlags.OffensiveModule) { if ((parentPlayer != null)) { // pvp ellenorzes (unitLockTarget.Target as Player)?.CheckPvp().ThrowIfError(); } Debug.Assert(ParentRobot != null, "ParentRobot != null"); ParentRobot.OnAggression(unitLockTarget.Target); } else if ((parentPlayer != null) && (unitLockTarget.Target is Player) && ED.AttributeFlags.PvpSupport) { parentPlayer.OnPvpSupport(unitLockTarget.Target); } } else { var terrainLockTarget = currentLock as TerrainLock; if (terrainLockTarget != null) { IsInRange(terrainLockTarget.Location).ThrowIfFalse(ErrorCodes.TargetOutOfRange); } } return(currentLock); }
public bool CheckUniqueModule(Module module) { if (ParentRobot == null) { return(true); } CategoryFlags uniqueCategoryFlag; if (!module.ED.CategoryFlags.IsUniqueCategoryFlags(out uniqueCategoryFlag)) { return(true); } if (ParentRobot.FindModuleByCategoryFlag(uniqueCategoryFlag) != null) { return(false); } return(true); }
protected double ModifyValueByOptimalRange(Unit target, double value) { Debug.Assert(ParentRobot != null, "ParentRobot != null"); var distance = ParentRobot.GetDistance(target); if (distance <= OptimalRange) { return(value); } if (distance > OptimalRange + Falloff) { return(0.0); } var x = (distance - OptimalRange) / Falloff; var m = Math.Cos(x * Math.PI) / 2 + 0.5; return(value * m); }
protected override void OnApplyingEffect(Unit target) { ParentRobot.SpreadAssistThreatToNpcs(ParentRobot, new Threat(ThreatType.Buff, Threat.SENSOR_BOOSTER)); base.OnApplyingEffect(target); }
private bool IsInRange(Position position) { Debug.Assert(ParentRobot != null, "ParentRobot != null"); return(!IsRanged || ParentRobot.IsInRangeOf3D(position, OptimalRange + Falloff)); }