forked from PerpetuumOnline/PerpetuumServer
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
499 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Perpetuum.Data; | ||
using Perpetuum.EntityFramework; | ||
using Perpetuum.ExportedTypes; | ||
using Perpetuum.Items; | ||
using Perpetuum.Players; | ||
using Perpetuum.Services.MissionEngine.MissionTargets; | ||
using Perpetuum.Zones; | ||
using Perpetuum.Zones.Beams; | ||
using Perpetuum.Zones.RemoteControl; | ||
using Perpetuum.Zones.Terrains; | ||
using Perpetuum.Zones.Terrains.Materials.Plants; | ||
using Perpetuum.Zones.Terrains.Materials.Plants.Harvesters; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Transactions; | ||
|
||
namespace Perpetuum.Modules | ||
{ | ||
public class LargeHarvesterModule : HarvesterModule | ||
{ | ||
public LargeHarvesterModule(CategoryFlags ammoCategoryFlags, PlantHarvester.Factory plantHarvesterFactory) | ||
: base(ammoCategoryFlags, plantHarvesterFactory) | ||
{ | ||
} | ||
|
||
public override void DoHarvesting(IZone zone) | ||
{ | ||
Position centralTile = ParentRobot.PositionWithHeight.OffsetInDirection(ParentRobot.Direction, 2); | ||
List<Position> mineralPositions = centralTile.GetEightNeighbours(ParentRobot.Zone.Size).ToList(); | ||
mineralPositions.Add(centralTile); | ||
|
||
int emptyTilesCounter = 0; | ||
|
||
// make it parallel | ||
foreach (Position position in mineralPositions) | ||
{ | ||
using (TransactionScope scope = Db.CreateTransaction()) | ||
{ | ||
using (new TerrainUpdateMonitor(zone)) | ||
{ | ||
PlantInfo plantInfo = zone.Terrain.Plants.GetValue(position); | ||
if (plantInfo.type == PlantType.NotDefined || | ||
Zone.Configuration.PlantRules.GetPlantRule(plantInfo.type) == null || | ||
plantInfo.material <= 0) | ||
{ | ||
emptyTilesCounter++; | ||
_ = emptyTilesCounter | ||
.ThrowIfEqual(9, ErrorCodes.NoPlantOnTile); | ||
|
||
continue; | ||
} | ||
|
||
CreateBeam(position, BeamState.AlignToTerrain); | ||
|
||
double amountModifier = _harverstingAmountModifier.GetValueByPlantType(plantInfo.type); | ||
IPlantHarvester plantHarvester = _plantHarvesterFactory(zone, amountModifier); | ||
IEnumerable<ItemInfo> harvestedPlants = plantHarvester.HarvestPlant(position); | ||
|
||
|
||
Debug.Assert(ParentRobot != null, "ParentRobot != null"); | ||
Robots.RobotInventory container = ParentRobot.GetContainer(); | ||
Debug.Assert(container != null, "container != null"); | ||
container.EnlistTransaction(); | ||
Player player = ParentRobot is RemoteControlledCreature remoteControlledCreature && | ||
remoteControlledCreature.CommandRobot is Player ownerPlayer | ||
? ownerPlayer | ||
: ParentRobot as Player; | ||
|
||
Debug.Assert(player != null, "player != null"); | ||
foreach (ItemInfo extractedMaterial in harvestedPlants) | ||
{ | ||
Item item = (Item)Factory.CreateWithRandomEID(extractedMaterial.Definition); | ||
item.Owner = Owner; | ||
item.Quantity = extractedMaterial.Quantity; | ||
container.AddItem(item, true); | ||
int extractedHarvestDefinition = extractedMaterial.Definition; | ||
int extractedQuantity = extractedMaterial.Quantity; | ||
player.MissionHandler.EnqueueMissionEventInfo(new HarvestPlantEventInfo(player, extractedHarvestDefinition, extractedQuantity, position)); | ||
player.Zone?.HarvestLogHandler.EnqueueHarvestLog(extractedHarvestDefinition, extractedQuantity); | ||
} | ||
|
||
container.Save(); | ||
OnGathererMaterial(zone, player, (int)plantInfo.type); | ||
Transaction.Current.OnCommited(() => container.SendUpdateToOwnerAsync()); | ||
scope.Complete(); | ||
} | ||
} | ||
} | ||
|
||
GenerateHeat(EffectType.effect_excavator, 6); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.