Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Sandbox.Game;
  4. using Sandbox.Game.Entities;
  5. using Sandbox.ModAPI;
  6. using Sandbox.ModAPI.Contracts;
  7. using VRage.Game;
  8. using VRage.Game.Components;
  9. using VRage.Game.ModAPI;
  10. using VRage.Utils;
  11. using VRageMath;
  12. using System.Linq;
  13.  
  14. namespace Klime.AxebeardBranch
  15. {
  16.     public class AxebeardBranch : CargoFindDestination
  17.     {
  18.         [MySessionComponentDescriptor(MyUpdateOrder.NoUpdate)]
  19.         public class Klime : ReceiveChat
  20.         {
  21.             public override void BeforeStart()
  22.             {
  23.                 MyAPIGateway.Utilities.MessageEntered += MessageEntered;
  24.             }
  25.  
  26.             private void MessageEntered(string message_text, ref bool sendToOthers)
  27.             {
  28.                 if (MyAPIGateway.Session.IsServer && message_text == "/roll")
  29.                 {
  30.                     IMyPlayer player = MyAPIGateway.Session.Player;
  31.                     if (player != null && player.Character != null)
  32.                     {
  33.                         FindDestination();
  34.                     }
  35.  
  36.                 }
  37.             }
  38.             protected void UnloadData()
  39.             {
  40.                 MyAPIGateway.Utilities.MessageEntered -= MessageEntered;
  41.             }
  42.         }
  43.  
  44.         public class AxebeardBranch : FindDestination
  45.         {
  46.             Random rnd = new Random();
  47.             int chance = rnd.Next(0, 100);
  48.             int chanceStation = 70; // chance destination is a station
  49.             int chanceEasyDest = 50; // space > space or planet > planet contracts
  50.             bool easyContract = false; //did we get an easy contract?
  51.             int resetTime = 3600; //time to allow new contract to possibly generate on same contract block    
  52.             bool startOnPlanet = false; //is the contract block on a planet?
  53.             bool destFound = false; // was a contract successfully created?
  54.  
  55.             chance = rnd.Next(0, 100);
  56.             if (chance<chanceEasyDest) //should this be an easy contract?
  57.             {
  58.                 sendToOthers = false;
  59.                 MyVisualScriptLogicProvider.SendChatMessage("Easy contract!");
  60.                 easyContract = true;
  61.             }
  62.             chance = rnd.Next(0, 100);
  63.             ////////////////////////////////Generate contract////////////////////////////////////////////////////////////////////////////////////////////////
  64.             if ((chance<chanceStation) && (!easyContract)) //station and NOT easy
  65.             {
  66.                 //if suitable destination found: destFound =
  67.                 ////////////////////////////Find all stations with contract blocks///////////////////////////////////////////////////////////////////////////
  68.                 HashSet<IMyEntity> _startUpEnts = new HashSet<IMyEntity>();
  69.                 MyAPIGateway.Entities.GetEntities(_startUpEnts);
  70.                 HashSet<string> UniqueStations = new HashSet<string>();
  71.  
  72.                 foreach (var entity in _startUpEnts)
  73.                 {
  74.                     var grid = entity as MyCubeGrid;
  75.                     if (grid?.Physics?.IsStatic == true)
  76.                     {
  77.                         if (grid.BigOwners.Count == 0) return;
  78.                         var Relationship = MyIDModule.GetRelationPlayerBlock(grid.BigOwners.FirstOrDefault(), player.IdentityId, MyOwnershipShareModeEnum.Faction);
  79.                         var ownerID = grid.BigOwners[0];
  80.                        
  81.                         if (grid != null && grid.BigOwners.Count > 0)
  82.                           {
  83.                             var owners = grid.BigOwners.Count > 0 ? grid.BigOwners : grid.SmallOwners;
  84.                             ownerID = owners.Count > 0 ? owners[0] : 0;
  85.                           }
  86.  
  87.                             if (Relationship == MyRelationsBetweenPlayerAndBlock.NoOwnership)
  88.                             Relationship = MyRelationsBetweenPlayerAndBlock.Neutral;
  89.                        
  90.                         ////////////////////////////////////////////////Get friendly/neutral stations//////////////////////////////////////////////////////////////////////
  91.                        
  92.                         MatrixD player_worldmatrix = player.Character.WorldMatrix;
  93.                         Vector3D playerpos = player_worldmatrix.Translation;
  94.  
  95.                         if ((Relationship != MyRelationsBetweenPlayerAndBlock.Enemies) && (Vector3D.Distance(grid.WorldMatrix.Translation, playerpos) > 3000)) ; //only get stations at least 3km away
  96.                         {
  97.                             //check if name already exists, if not, add it to list
  98.                             string stationName = grid.DisplayName;
  99.                             if (UniqueStations.Add(stationName)) ;
  100.                             {
  101.                                 sendToOthers = false;
  102.                                 string stationfound = "Possible destination: " + stationName;
  103.                                 MyVisualScriptLogicProvider.SendChatMessage(stationfound);
  104.                                 destFound = true;
  105.                             }
  106.                         }
  107.                     }
  108.                 }
  109.                 _startUpEnts.Clear();
  110.                 UniqueStations.Clear();
  111.             }
  112.             //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  113.             if (!destFound) //if no contract has been made up to this point...
  114.             {
  115.                 //random contract
  116.                 if (easyContract)
  117.                 {
  118.                     sendToOthers = false;
  119.                     MyVisualScriptLogicProvider.SendChatMessage("Easy contract 2!");
  120.                     //Easy contract - space to space or planet to planet
  121.                 }
  122.                 sendToOthers = false;
  123.                 MyVisualScriptLogicProvider.SendChatMessage("Random contract!");
  124.             }
  125.  
  126.  
  127.         }
  128.        
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement