Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Sandbox.Game;
- using Sandbox.Game.Entities;
- using Sandbox.ModAPI;
- using Sandbox.ModAPI.Contracts;
- using VRage.Game;
- using VRage.Game.Components;
- using VRage.Game.ModAPI;
- using VRage.Utils;
- using VRageMath;
- using System.Linq;
- namespace Klime.AxebeardBranch
- {
- public class AxebeardBranch : CargoFindDestination
- {
- [MySessionComponentDescriptor(MyUpdateOrder.NoUpdate)]
- public class Klime : ReceiveChat
- {
- public override void BeforeStart()
- {
- MyAPIGateway.Utilities.MessageEntered += MessageEntered;
- }
- private void MessageEntered(string message_text, ref bool sendToOthers)
- {
- if (MyAPIGateway.Session.IsServer && message_text == "/roll")
- {
- IMyPlayer player = MyAPIGateway.Session.Player;
- if (player != null && player.Character != null)
- {
- FindDestination();
- }
- }
- }
- protected void UnloadData()
- {
- MyAPIGateway.Utilities.MessageEntered -= MessageEntered;
- }
- }
- public class AxebeardBranch : FindDestination
- {
- Random rnd = new Random();
- int chance = rnd.Next(0, 100);
- int chanceStation = 70; // chance destination is a station
- int chanceEasyDest = 50; // space > space or planet > planet contracts
- bool easyContract = false; //did we get an easy contract?
- int resetTime = 3600; //time to allow new contract to possibly generate on same contract block
- bool startOnPlanet = false; //is the contract block on a planet?
- bool destFound = false; // was a contract successfully created?
- chance = rnd.Next(0, 100);
- if (chance<chanceEasyDest) //should this be an easy contract?
- {
- sendToOthers = false;
- MyVisualScriptLogicProvider.SendChatMessage("Easy contract!");
- easyContract = true;
- }
- chance = rnd.Next(0, 100);
- ////////////////////////////////Generate contract////////////////////////////////////////////////////////////////////////////////////////////////
- if ((chance<chanceStation) && (!easyContract)) //station and NOT easy
- {
- //if suitable destination found: destFound =
- ////////////////////////////Find all stations with contract blocks///////////////////////////////////////////////////////////////////////////
- HashSet<IMyEntity> _startUpEnts = new HashSet<IMyEntity>();
- MyAPIGateway.Entities.GetEntities(_startUpEnts);
- HashSet<string> UniqueStations = new HashSet<string>();
- foreach (var entity in _startUpEnts)
- {
- var grid = entity as MyCubeGrid;
- if (grid?.Physics?.IsStatic == true)
- {
- if (grid.BigOwners.Count == 0) return;
- var Relationship = MyIDModule.GetRelationPlayerBlock(grid.BigOwners.FirstOrDefault(), player.IdentityId, MyOwnershipShareModeEnum.Faction);
- var ownerID = grid.BigOwners[0];
- if (grid != null && grid.BigOwners.Count > 0)
- {
- var owners = grid.BigOwners.Count > 0 ? grid.BigOwners : grid.SmallOwners;
- ownerID = owners.Count > 0 ? owners[0] : 0;
- }
- if (Relationship == MyRelationsBetweenPlayerAndBlock.NoOwnership)
- Relationship = MyRelationsBetweenPlayerAndBlock.Neutral;
- ////////////////////////////////////////////////Get friendly/neutral stations//////////////////////////////////////////////////////////////////////
- MatrixD player_worldmatrix = player.Character.WorldMatrix;
- Vector3D playerpos = player_worldmatrix.Translation;
- if ((Relationship != MyRelationsBetweenPlayerAndBlock.Enemies) && (Vector3D.Distance(grid.WorldMatrix.Translation, playerpos) > 3000)) ; //only get stations at least 3km away
- {
- //check if name already exists, if not, add it to list
- string stationName = grid.DisplayName;
- if (UniqueStations.Add(stationName)) ;
- {
- sendToOthers = false;
- string stationfound = "Possible destination: " + stationName;
- MyVisualScriptLogicProvider.SendChatMessage(stationfound);
- destFound = true;
- }
- }
- }
- }
- _startUpEnts.Clear();
- UniqueStations.Clear();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if (!destFound) //if no contract has been made up to this point...
- {
- //random contract
- if (easyContract)
- {
- sendToOthers = false;
- MyVisualScriptLogicProvider.SendChatMessage("Easy contract 2!");
- //Easy contract - space to space or planet to planet
- }
- sendToOthers = false;
- MyVisualScriptLogicProvider.SendChatMessage("Random contract!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement