Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Meridius_IX's Pirate AI Systems
- double player_detect_range = 20000; //If player is further than this value from drone, it will not execute any behavioral scripting.
- //////////////////////////////////////////////////////
- //Do Not Touch Anything Below Here
- //////////////////////////////////////////////////////
- double player_drone_distance = 0;
- double player_origin_distance = 0;
- double drone_origin_distance = 0;
- IMyRemoteControl remote_control;
- IMyTextPanel face_panel;
- IMyTextPanel rear_panel;
- IMyWarhead warhead;
- IMyRadioAntenna antenna;
- IMyShipConnector connector;
- IMyGyro gyro;
- void Main(string argument){
- Vector3D world_center = new Vector3D(0,0,0);
- Vector3D player_coords = new Vector3D(0,0,0);
- Vector3D drone_coords = new Vector3D(0,0,0);
- Vector3D origin_coords = new Vector3D(0,0,0);
- //Find Remote Control Block(s)
- List<IMyTerminalBlock> remote_control_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(remote_control_list);
- if(remote_control_list.Count != 0){
- for(int i = 0; i < remote_control_list.Count; i++){
- if(remote_control_list[i].IsFunctional == true){
- remote_control = remote_control_list[i] as IMyRemoteControl;
- break;
- }
- }
- }else{
- Echo("No Remote Control Block Found. Script Cannot Execute.");
- return;
- }
- //Check If Drone is NPC Owned
- remote_control.GetNearestPlayer(out player_coords);
- if(player_coords == world_center){
- Echo("Drone is not owned by Hostile NPC. Script Cannot Continue.");
- return;
- }
- drone_coords = remote_control.GetPosition();
- //Get & Set Origin Coords
- if(this.Storage == null || this.Storage == ""){
- this.Storage = drone_coords.ToString();
- origin_coords = drone_coords;
- }else{
- Vector3D.TryParse(this.Storage, out origin_coords);
- }
- //Calculate Distances
- player_drone_distance = MeasureDistance(player_coords, drone_coords);
- player_origin_distance = MeasureDistance(player_coords, origin_coords);
- drone_origin_distance = MeasureDistance(drone_coords, origin_coords);
- if(player_drone_distance > player_detect_range){
- Echo("No Player Detected. Aborting Script Execution.");
- }
- //////////////////////////////////////////////////////
- //Pirate Behavior Start
- //////////////////////////////////////////////////////
- //Setup Lists / Blocks
- List<IMyTerminalBlock> antenna_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(antenna_list);
- face_panel = null;
- face_panel = GridTerminalSystem.GetBlockWithName("LCD Face") as IMyTextPanel;
- rear_panel = GridTerminalSystem.GetBlockWithName("LCD Rear") as IMyTextPanel;
- if(antenna_list.Count != 0){
- for(int i = 0; i < antenna_list.Count; i++){
- if(antenna_list[i].IsFunctional == true){
- antenna = antenna_list[i] as IMyRadioAntenna;
- break;
- }
- }
- }
- //Special Variables
- Random rnd = new Random();
- string [] attacked_msg = {"Why are you trying to hurt me?", "I thought we were friends...", "Did I do something to upset you?", "I only wanted to help you...", "You don't like me anymore?", "Please don't be mad at me..."};
- string [] retreat_msg = {"Oowww!", "That hurts!", "Leave me alone!", "Please stop!", "No more!", "Help me!"};
- int random_msg_index = rnd.Next(0, 6);
- string selected_msg = attacked_msg[random_msg_index];
- string [] button_action = {"ActionDead", "ActionEnemies", "ActionExplode", "ActionGift", "ActionGyro"};
- int [] action_timer = {5, 10, 3, 30, 15};
- int random_action_index = rnd.Next(0, 5);
- string current_mode = "ApproachPlayer";
- int special_timer = 0;
- int previous_block_count = 0;
- int previous_functional_blocks = 0;
- int current_block_count = CheckBlockCount();
- int current_functional_blocks = CheckFunctionalBlockCount();
- bool getting_hacked = HackingDetection();
- //Get-Init CustomData
- if(remote_control.CustomData == ""){
- previous_block_count = current_block_count;
- previous_functional_blocks = current_functional_blocks;
- remote_control.CustomData = current_mode + "\n";
- remote_control.CustomData += special_timer.ToString() + "\n";
- remote_control.CustomData += current_block_count.ToString() + "\n";
- remote_control.CustomData += current_functional_blocks.ToString() + "\n";
- remote_control.CustomData += selected_msg;
- }else{
- string [] data_split = remote_control.CustomData.Split('\n');
- current_mode = data_split[0];
- Int32.TryParse(data_split[1], out special_timer);
- Int32.TryParse(data_split[2], out previous_block_count);
- Int32.TryParse(data_split[3], out previous_functional_blocks);
- selected_msg = data_split[4];
- }
- //Check for Hostility
- bool interruptable_mode = true;
- string [] exception_modes = {"ActionExplode", "Offended", "BeingHacked", "BeingDamaged", "Betrayed", "RetreatExplode"};
- for(int i = 0; i < exception_modes.Length; i++){
- if(current_mode == exception_modes[i]){
- interruptable_mode = false;
- break;
- }
- }
- Vector3D rear_position = new Vector3D(0,0,0);
- double player_rear_distance = 0;
- if(rear_panel != null){
- rear_position = rear_panel.GetPosition();
- player_rear_distance = MeasureDistance(player_coords, rear_position);
- }
- if(face_panel != null){
- if(face_panel.IsFunctional == false){
- interruptable_mode = false;
- BlockActivation("Warheads");
- current_mode = "RetreatExplode";
- }
- }else{
- interruptable_mode = false;
- BlockActivation("Warheads");
- current_mode = "RetreatExplode";
- }
- if(player_rear_distance <= 2 && player_rear_distance != 0 && interruptable_mode == true){
- interruptable_mode = false;
- current_mode = "Offended";
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceMad1", false);
- antenna.CustomName = "HEY!";
- remote_control.ClearWaypoints();
- remote_control.AddWaypoint(player_coords, "Player");
- remote_control.SetAutoPilotEnabled(true);
- special_timer = 16;
- }
- if(getting_hacked == true && interruptable_mode == true){
- selected_msg = attacked_msg[random_msg_index];
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFacePain", false);
- antenna.CustomName = "Ooowwwww!";
- current_mode = "BeingHacked";
- interruptable_mode = false;
- special_timer = 12;
- }
- if(interruptable_mode == true){
- if(current_block_count < previous_block_count || current_functional_blocks < previous_functional_blocks){
- selected_msg = attacked_msg[random_msg_index];
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFacePain", false);
- antenna.CustomName = "Ooowwwww!";
- current_mode = "BeingDamaged";
- interruptable_mode = false;
- special_timer = 12;
- }
- }
- //Mode: ApproachPlayer
- if(current_mode == "ApproachPlayer"){
- remote_control.ClearWaypoints();
- remote_control.AddWaypoint(player_coords, "Player");
- remote_control.SetAutoPilotEnabled(true);
- if(player_drone_distance < 3500){
- remote_control.SetAutoPilotEnabled(false);
- antenna.CustomName = "Hi! I'm here to help! Please don't attack!";
- antenna.ApplyAction("OnOff_On");
- antenna.SetValueBool("EnableBroadCast", true);
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceNormal", false);
- current_mode = "FirstBroadcast";
- special_timer = 300;
- }
- }
- //Mode: FirstBroadcast
- if(current_mode == "FirstBroadcast"){
- if(player_drone_distance < 60){
- antenna.CustomName = "I'll do what I can to help! Just press the button!";
- current_mode = "MeetPlayer";
- }
- }
- //Mode: MeetPlayer
- if(current_mode == "MeetPlayer"){
- if(argument == "ButtonPress"){
- antenna.CustomName = "Ok, here we go!";
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceWorking", false);
- current_mode = "ButtonPress";
- special_timer = 4;
- }
- if(player_drone_distance < 60 && current_mode != "ButtonPress"){
- if(special_timer <= 300 && special_timer >= 241 && current_mode != "ButtonPress"){
- antenna.CustomName = "I'll do what I can to help! Just press the button!";
- }
- if(special_timer <= 240 && special_timer >= 181 && current_mode != "ButtonPress"){
- antenna.CustomName = "The button is below my face panel. Go ahead and press it!";
- }
- if(special_timer <= 180 && special_timer >= 121 && current_mode != "ButtonPress"){
- antenna.CustomName = "I'll do my best if you give me a chance!";
- }
- if(special_timer <= 120 && special_timer >= 61 && current_mode != "ButtonPress"){
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceBored", false);
- antenna.CustomName = "Maybe you don't want my help after all...";
- }
- if(special_timer <= 60 && special_timer >= 6 && current_mode != "ButtonPress"){
- antenna.CustomName = "I'm going to leave soon...";
- }
- if(special_timer <= 5 && current_mode != "ButtonPress"){
- antenna.CustomName = "I get it, you don't want my help. I'll go away...";
- }
- if(special_timer <= 0 && current_mode != "ButtonPress"){
- current_mode = "RetreatExplode";
- }
- }else{
- if(special_timer >= 121){
- antenna.CustomName = "Wait! Come back!";
- }
- }
- special_timer -= 1;
- }
- IMyButtonPanel button_panel = GridTerminalSystem.GetBlockWithName("Button Panel") as IMyButtonPanel;
- if(current_mode == "MeetPlayer"){
- button_panel?.ApplyAction("OnOff_On");
- }else{
- button_panel?.ApplyAction("OnOff_Off");
- }
- //Mode: ButtonPress
- if(current_mode == "ButtonPress"){
- if(special_timer <= 0){
- current_mode = button_action[random_action_index];
- special_timer = action_timer[random_action_index] + 1;
- }
- special_timer -= 1;
- }
- //Mode: ActionGyro
- if(current_mode == "ActionGyro"){
- BlockActivation("Gyros");
- if(special_timer <= 15 && special_timer >= 10){
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceDizzy", false);
- antenna.CustomName = "Whaaa! What's going on!?";
- }
- if(special_timer <= 9 && special_timer >= 4){
- antenna.CustomName = "I can't stop it!";
- }
- if(special_timer <= 3 && special_timer >= 1){
- antenna.CustomName = "I think I'm going to...";
- }
- if(special_timer <= 0){
- BlockActivation("Warheads");
- }
- special_timer -= 1;
- }
- //Mode: ActionExplode
- if(current_mode == "ActionExplode"){
- if(special_timer <= 2 && special_timer >= 1){
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceExplode", false);
- antenna.CustomName = "Umm.. I think I accidentally...";
- }
- if(special_timer <= 0){
- BlockActivation("Warheads");
- }
- special_timer -= 1;
- }
- //Mode: ActionGift
- if(current_mode == "ActionGift"){
- if(special_timer <= 30 && special_timer >= 6){
- BlockActivation("Connectors");
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceHappy", false);
- antenna.CustomName = "I brought you some supplies! I hope you like them!";
- }
- if(special_timer <= 5 && special_timer >= 1){
- antenna.CustomName = "I'm glad I could help! Bye!";
- }
- if(special_timer <= 0){
- current_mode = "RetreatExplode";
- }
- special_timer -= 1;
- }
- //Mode: ActionEnemies
- if(current_mode == "ActionEnemies"){
- if(special_timer <= 10 && special_timer >= 5){
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceWorried", false);
- antenna.CustomName = "Uh oh.. I think I dialed the wrong number...";
- }
- if(special_timer <= 4 && special_timer >= 1){
- antenna.CustomName = "I'm sorry if I caused you any trouble...";
- }
- if(special_timer <= 0){
- current_mode = "RetreatExplode";
- }
- special_timer -= 1;
- }
- //Mode: ActionDead
- if(current_mode == "ActionDead"){
- if(special_timer <= 5 && special_timer >= 3){
- antenna.CustomName = "I'm trying really hard!";
- }
- if(special_timer <= 2 && special_timer >= 1){
- antenna.CustomName = "Almost got it!";
- }
- if(special_timer <= 0){
- antenna.CustomName = ">System.Error //CPU Overload";
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceDead", false);
- IMyTimerBlock timer = GridTerminalSystem.GetBlockWithName("Timer") as IMyTimerBlock;
- timer?.ApplyAction("Stop");
- }
- special_timer -= 1;
- }
- //Mode: Offended
- if(current_mode == "Offended"){
- if(special_timer <= 12 && special_timer >= 6){
- remote_control.SetAutoPilotEnabled(false);
- antenna.CustomName = "You're not supposed to look at my Private Hardware!";
- }
- if(special_timer <= 5 && special_timer >= 1){
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceMad2", false);
- antenna.CustomName = "You're really weird.. I think I should leave.";
- }
- if(special_timer <= 0){
- current_mode = "RetreatExplode";
- }
- special_timer -= 1;
- }
- //Mode: BeingDamaged
- if(current_mode == "BeingDamaged"){
- if(current_block_count == previous_block_count){
- current_mode = "Betrayed";
- }
- }
- //Mode: BeingHacked
- if(current_mode == "BeingHacked"){
- if(getting_hacked == false){
- current_mode = "Betrayed";
- }
- }
- //Mode: Betrayed
- if(current_mode == "Betrayed"){
- if(special_timer <= 10 && special_timer >= 1){
- antenna.CustomName = selected_msg;
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceSad1", false);
- }
- if(special_timer <= 0){
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceSad2", false);
- current_mode = "RetreatExplode";
- }
- special_timer -= 1;
- }
- //Mode: RetreatExplode
- if(current_mode == "RetreatExplode"){
- remote_control.ClearWaypoints();
- remote_control.AddWaypoint(origin_coords, "Origin");
- remote_control.SetAutoPilotEnabled(true);
- if(drone_origin_distance < 150){
- BlockActivation("Warheads");
- }
- if(getting_hacked == true || current_block_count < previous_block_count || current_functional_blocks < previous_functional_blocks){
- face_panel.ClearImagesFromSelection();
- face_panel.AddImageToSelection("CPC-DroneFaceSad2", false);
- antenna.CustomName = retreat_msg[random_msg_index];
- }else{
- antenna.CustomName = "";
- }
- }
- //Set CustomData
- remote_control.CustomData = current_mode + "\n";
- remote_control.CustomData += special_timer.ToString() + "\n";
- remote_control.CustomData += current_block_count.ToString() + "\n";
- remote_control.CustomData += current_functional_blocks.ToString() + "\n";
- remote_control.CustomData += selected_msg;
- //////////////////////////////////////////////////////
- //Pirate Behavior End
- //////////////////////////////////////////////////////
- }
- void BlockActivation(string blocks){
- if(blocks == "Warheads"){
- List<IMyTerminalBlock> warhead_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyWarhead>(warhead_list);
- for(int i = 0; i < warhead_list.Count; i++){
- warhead = warhead_list[i] as IMyWarhead;
- warhead.ApplyAction("Detonate");
- }
- }
- if(blocks == "Connectors"){
- List<IMyTerminalBlock> connector_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyShipConnector>(connector_list);
- for(int i = 0; i < connector_list.Count; i++){
- connector = connector_list[i] as IMyShipConnector;
- connector.ApplyAction("OnOff_On");
- }
- }
- if(blocks == "Gyros"){
- List<IMyTerminalBlock> gyro_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyGyro>(gyro_list);
- for(int i = 0; i < gyro_list.Count; i++){
- gyro = gyro_list[i] as IMyGyro;
- gyro.SetValueBool("Override", true);
- }
- }
- }
- int CheckBlockCount(){
- List<IMyTerminalBlock> all_blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(all_blocks);
- return all_blocks.Count;
- }
- int CheckFunctionalBlockCount(){
- List<IMyTerminalBlock> all_blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(all_blocks);
- int block_counter = 0;
- for(int i = 0; i < all_blocks.Count; i++){
- if(all_blocks[i].IsFunctional == true && all_blocks[i].DisassembleRatio == 1){
- block_counter++;
- }
- }
- return block_counter;
- }
- bool HackingDetection(){
- List<IMyTerminalBlock> all_blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(all_blocks);
- for(int i = 0; i < all_blocks.Count; i++){
- if(all_blocks[i].IsBeingHacked == true){
- return true;
- }
- }
- return false;
- }
- double MeasureDistance(Vector3D point_a, Vector3D point_b){
- double result = Math.Round( Vector3D.Distance( point_a, point_b ), 2 );
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment