Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using BattleCore.Events;
- using BattleCorePsyOps;
- using System.IO;
- namespace BattleZone
- {
- public class GreenControl
- {
- ShortChat msg = new ShortChat();
- private List<int> _ActiveGreenIndex = new List<int>();
- private List<CustomGreen> _GreenMasterList = new List<CustomGreen>();
- private string _toggleGreenz = "*objset ";
- private Queue<EventArgs> _CommandUpdates = new Queue<EventArgs>();
- private bool _needUpdateLvz = false;
- private byte _ActiveGreens = 0;
- private Random ran = new Random();
- public void Test()
- {
- turnRandomGreenOn();
- }
- public Queue<EventArgs> ActiveGreenList
- {
- get
- {
- Queue<EventArgs> reply = new Queue<EventArgs>();
- for (int i = 0; i < _ActiveGreenIndex.Count; i += 1)
- {
- int index = _ActiveGreenIndex[i];
- reply.Enqueue(msg.arena("GreenID[" + index + "] Active time left[ " + (DateTime.Now -_GreenMasterList[index].TimeStamp).Seconds + " ]"));
- }
- if (reply.Count > 0)
- return reply;
- return null;
- }
- }
- private void RegisterGreen(ushort LvzStartIndex, ushort x, ushort y, byte radius)
- {
- _GreenMasterList.Add(new CustomGreen(LvzStartIndex, x, y, radius));
- }
- public Queue<EventArgs> UpdateGreenGfx
- {
- get{
- for (int i = 0; i < _ActiveGreenIndex.Count; i += 1)
- {
- int index = _ActiveGreenIndex[i];
- if (_GreenMasterList[index].GreenExpired)
- turnGreenOff(i,index);
- }
- if (_ActiveGreenIndex.Count < _ActiveGreens)
- turnRandomGreenOn();
- if (_needUpdateLvz)
- {
- _CommandUpdates.Enqueue(msg.pub(_toggleGreenz));
- _toggleGreenz = "*objset ";
- _needUpdateLvz = false;
- }
- if (_CommandUpdates.Count > 0)
- return _CommandUpdates;
- return null;
- }
- }
- private void turnGreenOff(int GIndex, int index)
- {
- _GreenMasterList[index].Active = false;
- _toggleGreenz += "-" + (_GreenMasterList[index].LvzID + GetPrizeID(_GreenMasterList[index].Type)) + ",";
- _ActiveGreenIndex.RemoveAt(GIndex);
- _needUpdateLvz = true;
- }
- private void turnRandomGreenOn()
- {
- bool searching = true;
- while (searching)
- {
- if (_ActiveGreenIndex.Count >= _GreenMasterList.Count)
- searching = false;
- int index = ran.Next(0, 100);
- if (!_GreenMasterList[index].Active)
- {
- turnGreenOn(index, ran.Next(0, 11));
- searching = false;
- }
- }
- }
- private void turnGreenOn(int index, int PrizeIndex)
- {
- _GreenMasterList[index].Active = true;
- _GreenMasterList[index].Type = PrizeLvzIDList[PrizeIndex];
- _ActiveGreenIndex.Add(index);
- _toggleGreenz += "+" + (_GreenMasterList[index].LvzID + GetPrizeID(_GreenMasterList[index].Type)) + ",";
- _GreenMasterList[index].SetTimeStamp();
- _GreenMasterList[index].SetAliveTime((byte)(ran.Next(20,100)));
- _needUpdateLvz = true;
- }
- public void CheckGreenRegions(PlayerPositionEvent p)
- {
- if (_ActiveGreenIndex.Count > 0)
- for (int i = 0; i < _ActiveGreenIndex.Count; i += 1)
- if (InHotSpot(p, _GreenMasterList[_ActiveGreenIndex[i]].HotSpot))
- {
- int index = _ActiveGreenIndex[i];
- turnGreenOff(i,index);
- _CommandUpdates.Enqueue(msg.pm(p.PlayerName, "*prize #" + ((byte)_GreenMasterList[index].Type + 0)));
- return;
- }
- }
- private bool InHotSpot(PlayerPositionEvent Player, ushort[] HotSpot)
- {
- if (Player.MapPositionX > HotSpot[0] && Player.MapPositionX < HotSpot[2]
- && Player.MapPositionY > HotSpot[1] && Player.MapPositionY < HotSpot[3])
- return true;
- return false;
- }
- private PrizeType[] PrizeLvzIDList = new PrizeType[12]
- {
- PrizeType.FullCharge, PrizeType.EngineShutDown, PrizeType.Super, PrizeType.Shields,
- PrizeType.Repel, PrizeType.Burst, PrizeType.Decoy, PrizeType.Thor,
- PrizeType.Multi, PrizeType.Brick, PrizeType.Rocket, PrizeType.Portal,
- };
- private int GetPrizeID(PrizeType prize)
- {
- for (int i = 0; i < PrizeLvzIDList.Length; i += 1)
- if (prize == PrizeLvzIDList[i]) return i;
- return 0;
- }
- private class CustomGreen
- {
- public CustomGreen(ushort LvzID, ushort xCoord, ushort yCoord, byte Radius)
- {
- this._LvzID = LvzID;
- this._HotSpot = new ushort[4]
- {
- (ushort)(xCoord - Radius),
- (ushort)(yCoord - Radius),
- (ushort)(xCoord + Radius),
- (ushort)(yCoord + Radius)
- };
- }
- private ushort _LvzID;
- public ushort LvzID
- { get { return _LvzID; } }
- private bool _Active = false;
- public bool Active
- {
- get { return _Active; }
- set { _Active = value; }
- }
- private byte _AliveTime = 10;
- private DateTime _TimeStamp = DateTime.Now;
- public DateTime TimeStamp { get { return _TimeStamp; } }
- public void SetAliveTime(byte AliveTime)
- { _AliveTime = AliveTime; }
- public void SetTimeStamp()
- { _TimeStamp = DateTime.Now; }
- public bool GreenExpired
- {
- get
- {
- if ((DateTime.Now - _TimeStamp).Seconds >= _AliveTime)
- return true;
- return false;
- }
- }
- private PrizeType _Type = PrizeType.FullCharge;
- public PrizeType Type
- {
- get { return _Type; }
- set { _Type = value; }
- }
- private ushort[] _HotSpot = new ushort[4];
- public ushort[] HotSpot { get { return _HotSpot; } }
- }
- private Queue<EventArgs> _cfgPrintOut = new Queue<EventArgs>();
- public Queue<EventArgs> CfgPrintout
- { get { return _cfgPrintOut; } }
- public void LoadCFG(string BotName)
- {
- if (File.Exists(BotName + "/customgreens.cfg"))
- {
- try
- {
- //Opening appropriate file
- StreamReader SR = File.OpenText(BotName + "/customgreens.cfg");
- //used to read each line
- string S;
- int AmountOfPrizes = 12;
- bool MakeIni = false;
- string Lvzfilename = "";
- string[] iniSettings = new string[12];
- int[] LvzDimensions = new int[12];
- int DimIndex = 0;
- int IniIndex = 0;
- ushort[] GreenArea = new ushort[4];
- int RowCol = 0;
- Queue<string> SavedIni = new Queue<string>();
- while ((S = SR.ReadLine()) != null)
- {
- if (!S.StartsWith(";"))
- {
- string[] data = S.Trim().Split(':');
- if (S.StartsWith("createini:"))
- {
- if (data[1].ToLower().Equals("yes"))
- MakeIni = true;
- _cfgPrintOut.Enqueue(msg.arena("MakeIni set to [" + MakeIni + "]"));
- }
- else if (S.StartsWith("lvzfilename:"))
- Lvzfilename = data[1];
- else if (S.StartsWith("FileInfo:"))
- iniSettings[IniIndex++] = S;
- else if (S.StartsWith("Prize:"))
- {
- LvzDimensions[DimIndex++] = int.Parse(data[2]);
- }
- else if (S.StartsWith("spawnarea:"))
- {
- GreenArea[0] = (ushort)(int.Parse(data[1]) * 16);
- GreenArea[1] = (ushort)(int.Parse(data[2]) * 16);
- GreenArea[2] = (ushort)(int.Parse(data[3]) * 16);
- GreenArea[3] = (ushort)(int.Parse(data[4]) * 16);
- RowCol = int.Parse(data[5]);
- }
- }
- }
- // Closing file
- SR.Close();
- int xGap = (int)Math.Floor((double)((GreenArea[2] - GreenArea[0]) / RowCol));
- int yGap = (int)Math.Floor((double)((GreenArea[3] - GreenArea[1]) / RowCol));
- int NextX = GreenArea[0];
- int NextY = GreenArea[1];
- SavedIni.Enqueue("Outfile=" + Lvzfilename);
- for (int i = 0; i < AmountOfPrizes; i += 1)
- {
- SavedIni.Enqueue("File=" + iniSettings[i].Split(':')[1]);
- }
- SavedIni.Enqueue("[objectimages]");
- for (int i = 0; i < AmountOfPrizes; i += 1)
- {
- SavedIni.Enqueue("IMAGE" + i + "=" + iniSettings[i].Split(':')[1] + "," + iniSettings[i].Split(':')[2]);
- }
- SavedIni.Enqueue("[mapobjects]");
- int IDCount = 0;
- for (int i = 0; i < RowCol; i += 1)
- {
- int xCoor = NextX;
- NextX += xGap;
- for (int j = 0; j < RowCol; j += 1)
- {
- if (NextY > GreenArea[3])
- NextY = GreenArea[1];
- int yCoor = NextY;
- NextY += yGap;
- // ---------------Create the greens in here--------------- \\
- RegisterGreen((ushort)IDCount, (ushort)xCoor, (ushort)yCoor, 32);
- for (int k = 0; k < AmountOfPrizes; k += 1)
- {
- SavedIni.Enqueue((xCoor - LvzDimensions[k]/2) + "," + (yCoor - LvzDimensions[k]/2) + ",IMAGE" + k + ",AfterShips,ServerControlled,0," + IDCount++);
- }
- }
- }
- _cfgPrintOut.Enqueue(msg.arena("Greens created: [" + _GreenMasterList.Count + "]."));
- if (MakeIni)
- {
- //CustomGreenLVZ
- using (StreamWriter sw = new StreamWriter("lvz/customgreens/CustomGreenLVZ.ini"))
- {
- while (SavedIni.Count > 0)
- sw.WriteLine(SavedIni.Dequeue());
- }
- _cfgPrintOut.Enqueue(msg.arena("Ini successfuly created."));
- return;
- }
- else
- _cfgPrintOut.Enqueue(msg.arena("Create Ini: Off. Ini not created."));
- return;
- }
- catch (Exception ex) { _cfgPrintOut.Enqueue(msg.arena("Error:" + ex)); return;}
- }
- _cfgPrintOut.Enqueue(msg.arena("File not found: Ini not created."));
- }
- }
- public enum PrizeType
- {
- FullCharge = 13,
- EngineShutDown = 13,
- Super = 17,
- Shields = 18,
- Repel = 21,
- Burst = 22,
- Decoy = 23,
- Thor = 24,
- Multi = 25,
- Brick = 26,
- Rocket = 27,
- Portal = 28
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment