PsyOps

GreenControl.css

Nov 2nd, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using BattleCore.Events;
  7. using BattleCorePsyOps;
  8.  
  9. using System.IO;
  10.  
  11. namespace BattleZone
  12. {
  13.     public class GreenControl
  14.     {
  15.         ShortChat msg = new ShortChat();
  16.  
  17.         private List<int> _ActiveGreenIndex = new List<int>();
  18.         private List<CustomGreen> _GreenMasterList = new List<CustomGreen>();
  19.         private string _toggleGreenz = "*objset ";
  20.         private Queue<EventArgs> _CommandUpdates = new Queue<EventArgs>();
  21.         private bool _needUpdateLvz = false;
  22.         private byte _ActiveGreens = 0;
  23.         private Random ran = new Random();
  24.  
  25.         public void Test()
  26.         {
  27.             turnRandomGreenOn();
  28.         }
  29.  
  30.         public Queue<EventArgs> ActiveGreenList
  31.         {
  32.             get
  33.             {
  34.                 Queue<EventArgs> reply = new Queue<EventArgs>();
  35.  
  36.                 for (int i = 0; i < _ActiveGreenIndex.Count; i += 1)
  37.                 {
  38.                     int index = _ActiveGreenIndex[i];
  39.                     reply.Enqueue(msg.arena("GreenID[" + index + "] Active time left[ " + (DateTime.Now -_GreenMasterList[index].TimeStamp).Seconds + " ]"));
  40.                 }
  41.  
  42.                 if (reply.Count > 0)
  43.                     return reply;
  44.                 return null;
  45.             }
  46.         }
  47.  
  48.         private void RegisterGreen(ushort LvzStartIndex, ushort x, ushort y, byte radius)
  49.         {
  50.             _GreenMasterList.Add(new CustomGreen(LvzStartIndex, x, y, radius));
  51.         }
  52.  
  53.         public Queue<EventArgs> UpdateGreenGfx
  54.         {
  55.             get{
  56.                 for (int i = 0; i < _ActiveGreenIndex.Count; i += 1)
  57.                 {
  58.                     int index = _ActiveGreenIndex[i];
  59.                     if (_GreenMasterList[index].GreenExpired)
  60.                         turnGreenOff(i,index);
  61.                 }
  62.  
  63.                 if (_ActiveGreenIndex.Count < _ActiveGreens)
  64.                     turnRandomGreenOn();
  65.  
  66.                 if (_needUpdateLvz)
  67.                 {
  68.                     _CommandUpdates.Enqueue(msg.pub(_toggleGreenz));
  69.                     _toggleGreenz = "*objset ";
  70.                     _needUpdateLvz = false;
  71.                 }
  72.  
  73.                 if (_CommandUpdates.Count > 0)
  74.                     return _CommandUpdates;
  75.  
  76.                 return null;
  77.             }
  78.         }
  79.         private void turnGreenOff(int GIndex, int index)
  80.         {
  81.             _GreenMasterList[index].Active = false;
  82.             _toggleGreenz += "-" + (_GreenMasterList[index].LvzID + GetPrizeID(_GreenMasterList[index].Type)) + ",";
  83.             _ActiveGreenIndex.RemoveAt(GIndex);
  84.             _needUpdateLvz = true;
  85.         }
  86.         private void turnRandomGreenOn()
  87.         {
  88.             bool searching = true;
  89.             while (searching)
  90.             {
  91.                 if (_ActiveGreenIndex.Count >= _GreenMasterList.Count)
  92.                     searching = false;
  93.  
  94.                 int index = ran.Next(0, 100);
  95.  
  96.                 if (!_GreenMasterList[index].Active)
  97.                 {
  98.                     turnGreenOn(index, ran.Next(0, 11));
  99.                     searching = false;
  100.                 }
  101.             }
  102.         }
  103.         private void turnGreenOn(int index, int PrizeIndex)
  104.         {
  105.             _GreenMasterList[index].Active = true;
  106.             _GreenMasterList[index].Type = PrizeLvzIDList[PrizeIndex];
  107.             _ActiveGreenIndex.Add(index);
  108.             _toggleGreenz += "+" + (_GreenMasterList[index].LvzID + GetPrizeID(_GreenMasterList[index].Type)) + ",";
  109.             _GreenMasterList[index].SetTimeStamp();
  110.             _GreenMasterList[index].SetAliveTime((byte)(ran.Next(20,100)));
  111.             _needUpdateLvz = true;
  112.         }
  113.         public void CheckGreenRegions(PlayerPositionEvent p)
  114.         {
  115.             if (_ActiveGreenIndex.Count > 0)
  116.                 for (int i = 0; i < _ActiveGreenIndex.Count; i += 1)
  117.                     if (InHotSpot(p, _GreenMasterList[_ActiveGreenIndex[i]].HotSpot))
  118.                     {
  119.                         int index = _ActiveGreenIndex[i];
  120.                         turnGreenOff(i,index);
  121.                         _CommandUpdates.Enqueue(msg.pm(p.PlayerName, "*prize #" + ((byte)_GreenMasterList[index].Type + 0)));
  122.                         return;
  123.                     }
  124.         }
  125.  
  126.         private bool InHotSpot(PlayerPositionEvent Player, ushort[] HotSpot)
  127.         {
  128.             if (Player.MapPositionX > HotSpot[0] && Player.MapPositionX < HotSpot[2]
  129.                 && Player.MapPositionY > HotSpot[1] && Player.MapPositionY < HotSpot[3])
  130.                 return true;
  131.             return false;
  132.         }
  133.  
  134.         private PrizeType[] PrizeLvzIDList = new PrizeType[12]
  135.         {
  136.             PrizeType.FullCharge,   PrizeType.EngineShutDown, PrizeType.Super,  PrizeType.Shields,
  137.             PrizeType.Repel,        PrizeType.Burst,          PrizeType.Decoy,  PrizeType.Thor,
  138.             PrizeType.Multi,        PrizeType.Brick,          PrizeType.Rocket, PrizeType.Portal,
  139.         };
  140.         private int GetPrizeID(PrizeType prize)
  141.         {
  142.             for (int i = 0; i < PrizeLvzIDList.Length; i += 1)
  143.                 if (prize == PrizeLvzIDList[i]) return i;
  144.             return 0;
  145.         }
  146.  
  147.         private class CustomGreen
  148.         {
  149.             public CustomGreen(ushort LvzID, ushort xCoord, ushort yCoord, byte Radius)
  150.             {
  151.                 this._LvzID = LvzID;
  152.                 this._HotSpot = new ushort[4]
  153.                 {
  154.                     (ushort)(xCoord - Radius),
  155.                     (ushort)(yCoord - Radius),
  156.                     (ushort)(xCoord + Radius),
  157.                     (ushort)(yCoord + Radius)
  158.                 };
  159.             }
  160.             private ushort _LvzID;
  161.             public ushort LvzID
  162.             {    get { return _LvzID; } }
  163.             private bool _Active = false;
  164.             public bool Active
  165.             {
  166.                 get { return _Active; }
  167.                 set { _Active = value; }
  168.             }
  169.             private byte _AliveTime = 10;
  170.             private DateTime _TimeStamp = DateTime.Now;
  171.             public DateTime TimeStamp { get { return _TimeStamp; } }
  172.             public void SetAliveTime(byte AliveTime)
  173.             {    _AliveTime = AliveTime;   }
  174.             public void SetTimeStamp()
  175.             { _TimeStamp = DateTime.Now; }
  176.             public bool GreenExpired
  177.             {
  178.                 get
  179.                 {
  180.                     if ((DateTime.Now - _TimeStamp).Seconds >= _AliveTime)
  181.                         return true;
  182.                     return false;
  183.                 }
  184.             }
  185.             private PrizeType _Type = PrizeType.FullCharge;
  186.             public PrizeType Type
  187.             {
  188.                 get { return _Type; }
  189.                 set { _Type = value; }
  190.             }
  191.             private ushort[] _HotSpot = new ushort[4];
  192.             public ushort[] HotSpot { get { return _HotSpot; } }
  193.         }
  194.         private Queue<EventArgs> _cfgPrintOut = new Queue<EventArgs>();
  195.         public Queue<EventArgs> CfgPrintout
  196.         { get { return _cfgPrintOut; } }
  197.  
  198.         public void LoadCFG(string BotName)
  199.         {
  200.             if (File.Exists(BotName + "/customgreens.cfg"))
  201.             {
  202.                 try
  203.                 {
  204.                     //Opening appropriate file
  205.                     StreamReader SR = File.OpenText(BotName + "/customgreens.cfg");
  206.                     //used to read each line
  207.                     string S;
  208.  
  209.                     int AmountOfPrizes = 12;
  210.  
  211.                     bool MakeIni = false;
  212.                     string Lvzfilename = "";
  213.                     string[] iniSettings = new string[12];
  214.                     int[] LvzDimensions = new int[12];
  215.                     int DimIndex = 0;
  216.                     int IniIndex = 0;
  217.                     ushort[] GreenArea = new ushort[4];
  218.                     int RowCol = 0;
  219.                     Queue<string> SavedIni = new Queue<string>();
  220.  
  221.                     while ((S = SR.ReadLine()) != null)
  222.                     {
  223.                         if (!S.StartsWith(";"))
  224.                         {
  225.                             string[] data = S.Trim().Split(':');
  226.  
  227.                             if (S.StartsWith("createini:"))
  228.                             {
  229.                                 if (data[1].ToLower().Equals("yes"))
  230.                                     MakeIni = true;
  231.                                 _cfgPrintOut.Enqueue(msg.arena("MakeIni set to [" + MakeIni + "]"));
  232.                             }
  233.                             else if (S.StartsWith("lvzfilename:"))
  234.                                 Lvzfilename = data[1];
  235.                             else if (S.StartsWith("FileInfo:"))
  236.                                 iniSettings[IniIndex++] = S;
  237.                             else if (S.StartsWith("Prize:"))
  238.                             {
  239.                                 LvzDimensions[DimIndex++] = int.Parse(data[2]);
  240.                             }
  241.                             else if (S.StartsWith("spawnarea:"))
  242.                             {
  243.                                 GreenArea[0] = (ushort)(int.Parse(data[1]) * 16);
  244.                                 GreenArea[1] = (ushort)(int.Parse(data[2]) * 16);
  245.                                 GreenArea[2] = (ushort)(int.Parse(data[3]) * 16);
  246.                                 GreenArea[3] = (ushort)(int.Parse(data[4]) * 16);
  247.                                 RowCol = int.Parse(data[5]);
  248.                             }
  249.                         }
  250.                     }
  251.  
  252.                     // Closing file
  253.                     SR.Close();
  254.  
  255.  
  256.                     int xGap = (int)Math.Floor((double)((GreenArea[2] - GreenArea[0]) / RowCol));
  257.                     int yGap = (int)Math.Floor((double)((GreenArea[3] - GreenArea[1]) / RowCol));
  258.  
  259.                     int NextX = GreenArea[0];
  260.                     int NextY = GreenArea[1];
  261.  
  262.                     SavedIni.Enqueue("Outfile=" + Lvzfilename);
  263.  
  264.                     for (int i = 0; i < AmountOfPrizes; i += 1)
  265.                     {
  266.                         SavedIni.Enqueue("File=" + iniSettings[i].Split(':')[1]);
  267.                     }
  268.  
  269.                     SavedIni.Enqueue("[objectimages]");
  270.  
  271.                     for (int i = 0; i < AmountOfPrizes; i += 1)
  272.                     {
  273.                         SavedIni.Enqueue("IMAGE" + i + "=" + iniSettings[i].Split(':')[1] + "," + iniSettings[i].Split(':')[2]);
  274.                     }
  275.  
  276.                     SavedIni.Enqueue("[mapobjects]");
  277.  
  278.                     int IDCount = 0;
  279.  
  280.                     for (int i = 0; i < RowCol; i += 1)
  281.                     {
  282.                         int xCoor = NextX;
  283.                         NextX += xGap;
  284.  
  285.                         for (int j = 0; j < RowCol; j += 1)
  286.                         {
  287.                             if (NextY > GreenArea[3])
  288.                                 NextY = GreenArea[1];
  289.  
  290.                             int yCoor = NextY;
  291.                             NextY += yGap;
  292.  
  293.                             // ---------------Create the greens in here--------------- \\
  294.                             RegisterGreen((ushort)IDCount, (ushort)xCoor, (ushort)yCoor, 32);
  295.  
  296.                             for (int k = 0; k < AmountOfPrizes; k += 1)
  297.                             {
  298.                                 SavedIni.Enqueue((xCoor - LvzDimensions[k]/2) + "," + (yCoor - LvzDimensions[k]/2) + ",IMAGE" + k + ",AfterShips,ServerControlled,0," + IDCount++);
  299.                             }
  300.                         }
  301.                     }
  302.                     _cfgPrintOut.Enqueue(msg.arena("Greens created: [" + _GreenMasterList.Count + "]."));
  303.                     if (MakeIni)
  304.                     {
  305.                         //CustomGreenLVZ
  306.                         using (StreamWriter sw = new StreamWriter("lvz/customgreens/CustomGreenLVZ.ini"))
  307.                         {
  308.                             while (SavedIni.Count > 0)
  309.                                 sw.WriteLine(SavedIni.Dequeue());
  310.                         }
  311.  
  312.                         _cfgPrintOut.Enqueue(msg.arena("Ini successfuly created."));
  313.                         return;
  314.                     }
  315.                     else
  316.                         _cfgPrintOut.Enqueue(msg.arena("Create Ini: Off. Ini not created."));
  317.                     return;
  318.                 }
  319.                 catch (Exception ex) { _cfgPrintOut.Enqueue(msg.arena("Error:" + ex)); return;}
  320.             }
  321.             _cfgPrintOut.Enqueue(msg.arena("File not found: Ini not created."));
  322.         }
  323.  
  324.     }
  325.     public enum PrizeType
  326.     {
  327.         FullCharge = 13,
  328.         EngineShutDown = 13,
  329.         Super = 17,
  330.         Shields = 18,
  331.         Repel = 21,
  332.         Burst = 22,
  333.         Decoy = 23,
  334.         Thor = 24,
  335.         Multi = 25,
  336.         Brick = 26,
  337.         Rocket = 27,
  338.         Portal = 28
  339.     }
  340. }
Advertisement
Add Comment
Please, Sign In to add comment