Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Addon;
- using ns0;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Runtime.CompilerServices;
- using System.Timers;
- namespace MapEdit
- {
- public class MapEdit : CPlugin
- {
- public enum DoorDirection
- {
- Up,
- Left,
- Right,
- Down
- }
- [CompilerGenerated]
- private sealed class Class4
- {
- public List<Entity> list_0;
- public Class2 class2_0;
- }
- [CompilerGenerated]
- private sealed class Class5
- {
- public HudElem hudElem_0;
- }
- [CompilerGenerated]
- private sealed class Class6
- {
- public Entity entity_0;
- }
- [CompilerGenerated]
- private sealed class Class7
- {
- public MapEdit.Class6 class6_0;
- public MapEdit.Class5 class5_0;
- public MapEdit.Class4 class4_0;
- public Timer timer_0;
- public Timer timer_1;
- public MapEdit mapEdit_0;
- public void method_0(object sender, ElapsedEventArgs e)
- {
- if (this.class4_0.class2_0.open && this.class6_0.entity_0.get_OriginZ() - 100f >= this.class4_0.class2_0.Bottom.Z)
- {
- Entity expr_4F = this.class6_0.entity_0;
- expr_4F.set_OriginZ(expr_4F.get_OriginZ() - 100f);
- Class10.smethod_14(this.class6_0.entity_0, Class10.smethod_12());
- }
- this.timer_0.Enabled = false;
- }
- public void method_1(object sender, ElapsedEventArgs e)
- {
- if (this.class4_0.class2_0.open)
- {
- this.class4_0.class2_0.open = false;
- this.class4_0.class2_0.openTime.Stop();
- this.class4_0.class2_0.Openingclient = null;
- this.mapEdit_0.dictionary_0[this.class4_0.list_0] = this.class4_0.class2_0;
- this.class5_0.hudElem_0.SetString("");
- this.class4_0.class2_0.closeTime.Reset();
- this.class4_0.class2_0.closeTime.Start();
- }
- this.timer_1.Enabled = false;
- }
- }
- [CompilerGenerated]
- private sealed class Class8
- {
- public MapEdit mapEdit_0;
- public ServerClient serverClient_0;
- }
- [CompilerGenerated]
- private sealed class Class9
- {
- public MapEdit.Class8 class8_0;
- public Timer timer_0;
- public void method_0(object sender, ElapsedEventArgs e)
- {
- int weapon = this.class8_0.mapEdit_0.GetWeapon("defaultweapon_mp");
- this.class8_0.serverClient_0.Other.set_WeaponSlot3(weapon);
- this.class8_0.mapEdit_0.iPrintLnBold("^2Your default weapon is to repair^6 doors", this.class8_0.serverClient_0);
- this.timer_0.Enabled = false;
- }
- }
- private int int_0;
- private List<Entity> list_0 = new List<Entity>();
- private Dictionary<List<Entity>, Class2> dictionary_0 = new Dictionary<List<Entity>, Class2>();
- private Dictionary<int, Stopwatch> dictionary_1 = new Dictionary<int, Stopwatch>();
- private Dictionary<int, int> dictionary_2 = new Dictionary<int, int>();
- public override void OnPrecache()
- {
- if (base.GetDvar("mapname") == "mp_underground")
- {
- this.int_0 = Class10.smethod_9("explosions/spark_fall_runner_mp");
- }
- base.OnPrecache();
- }
- public static Vector subract(Vector left, Vector right)
- {
- return new Vector(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
- }
- public static Vector multi(Vector vector, float factor)
- {
- return new Vector(vector.X * factor, vector.Y * factor, vector.Z * factor);
- }
- public static Vector plus(Vector left, Vector right)
- {
- return new Vector(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
- }
- public Entity spawnCrate(Vector test)
- {
- Entity entity = base.SpawnModel("script_model", "com_plasticcase_friendly", test);
- Class10.smethod_14(entity, Class10.smethod_12());
- return entity;
- }
- public Entity spawnCrate(Vector test, Vector angles)
- {
- Entity entity = base.SpawnModel("script_model", "com_plasticcase_friendly", test);
- Class10.smethod_14(entity, Class10.smethod_12());
- if (!(base.GetServerCFG("MapEdit", "angles", "false") == "true"))
- {
- }
- Class10.smethod_7(entity, angles);
- return entity;
- }
- public static double Distance(Vector vec1, Vector vec2)
- {
- return Math.Sqrt(Math.Pow((double)(vec1.X - vec2.X), 2.0) + Math.Pow((double)(vec1.Y - vec2.Y), 2.0) + Math.Pow((double)(vec1.Z - vec2.Z), 2.0));
- }
- public static double Distance(Vector vec1, List<Entity> entities)
- {
- List<double> list = new List<double>();
- foreach (Entity current in entities)
- {
- list.Add(Math.Sqrt(Math.Pow((double)(vec1.X - current.get_OriginX()), 2.0) + Math.Pow((double)(vec1.Y - current.get_OriginY()), 2.0) + Math.Pow((double)(vec1.Z - current.get_OriginZ()), 2.0)));
- }
- list.Sort();
- return list.ToArray()[0];
- }
- public static Vector VectorToAngles(Vector vec1, Vector vec2)
- {
- float num = vec1.X - vec2.X;
- float num2 = vec1.Z - vec2.Z;
- float num3 = (float)Math.Pow((double)num, 2.0);
- float num4 = (float)Math.Pow((double)num2, 2.0);
- float num5 = num3 + num4;
- float arg_62_0 = (float)Math.Acos((double)(num3 + num4 - num5) / 2.0 * (double)num * (double)num2);
- float num6 = vec1.Y - vec2.Y;
- float num7 = (float)Math.Pow((double)num6, 2.0);
- float num8 = num7 + num4;
- float arg_AB_0 = (float)Math.Acos((double)(num7 + num4 - num8) / 2.0 * (double)num6 * (double)num2);
- return null;
- }
- public void CreateRandomWeaponBox(Vector SpawnPoint)
- {
- this.spawnCrate(SpawnPoint);
- }
- public void createfloor(Vector corner1, Vector corner2)
- {
- float num = corner1.X - corner2.X;
- if (num < 0f)
- {
- num *= -1f;
- }
- float num2 = corner1.Y - corner2.Y;
- if (num2 < 0f)
- {
- num2 *= -1f;
- }
- int num3 = (int)Math.Round((double)(num / 50f), 0);
- int num4 = (int)Math.Round((double)(num2 / 30f), 0);
- Vector vector = MapEdit.subract(corner2, corner1);
- Vector vector2 = new Vector(vector.X / (float)num3, vector.Y / (float)num4, 0f);
- for (int i = 0; i < num3; i++)
- {
- for (int j = 0; j < num4; j++)
- {
- this.spawnCrate(MapEdit.plus(MapEdit.plus(corner1, MapEdit.multi(new Vector(vector2.X, 0f, 0f), (float)i)), MapEdit.multi(new Vector(0f, vector2.Y, 0f), (float)j)));
- }
- }
- }
- public override void OnPlayerDisconnect(ServerClient Client)
- {
- this.dictionary_2.Remove(Client.get_ClientNum());
- base.OnPlayerDisconnect(Client);
- }
- public static Vector minus(Vector left, Vector right)
- {
- return new Vector(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
- }
- public float DistanceTo(Vector other, Vector first)
- {
- Vector vec = MapEdit.minus(other, first);
- return this.Length(vec);
- }
- public float Length(Vector vec)
- {
- return (float)Math.Sqrt((double)(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z));
- }
- public void CreateRamp(Vector top, Vector bottom)
- {
- float num = this.DistanceTo(bottom, top);
- int num2 = (int)Math.Ceiling((double)(num / 30f));
- Vector vector = new Vector((top.X - bottom.X) / (float)num2, (top.Y - bottom.Y) / (float)num2, (top.Z - bottom.Z) / (float)num2);
- Vector vector2 = MapEdit.VectorToAngles(MapEdit.minus(top, bottom));
- Vector angles = new Vector(vector2.Z, vector2.Y + 90f, vector2.X);
- for (int i = 0; i <= num2; i++)
- {
- this.spawnCrate(MapEdit.plus(bottom, new Vector(vector.X * (float)i, vector.Y * (float)i, vector.Z * (float)i)), angles);
- }
- }
- public void CreateWall(Vector top, Vector bottom)
- {
- int arg_1A_0 = (int)Math.Round((double)(MapEdit.minus(top, bottom).Z / 30f), 0);
- float num = this.DistanceTo(bottom, top);
- int num2 = (int)Math.Ceiling((double)(num / 30f));
- Vector vector = MapEdit.VectorToAngles(MapEdit.minus(top, bottom));
- vector = new Vector(vector.X, vector.Y, 90f);
- Vector vector2 = new Vector((top.X - bottom.X) / (float)num2, (top.Y - bottom.Y) / (float)num2, (top.Z - bottom.Z) / (float)num2);
- for (int i = (int)top.Z; i <= (int)bottom.Z; i += 30)
- {
- for (int j = 0; j <= num2; j++)
- {
- Vector vector3 = MapEdit.plus(bottom, new Vector(vector2.X * (float)j, vector2.Y * (float)j, 0f));
- vector3.Z = (float)i;
- this.spawnCrate(vector3, vector);
- }
- }
- }
- public void CreateDoor(Vector top, Vector bottom)
- {
- int arg_1A_0 = (int)Math.Round((double)(MapEdit.minus(top, bottom).Z / 30f), 0);
- float num = this.DistanceTo(bottom, top);
- int num2 = (int)Math.Ceiling((double)(num / 30f));
- List<Entity> list = new List<Entity>();
- Vector vector = MapEdit.VectorToAngles(MapEdit.minus(top, bottom));
- vector = new Vector(vector.X, vector.Y, 90f);
- Vector vector2 = new Vector((top.X - bottom.X) / (float)num2, (top.Y - bottom.Y) / (float)num2, (top.Z - bottom.Z) / (float)num2);
- for (int i = (int)top.Z; i <= (int)bottom.Z; i += 30)
- {
- for (int j = 0; j <= num2; j++)
- {
- Vector vector3 = MapEdit.plus(bottom, new Vector(vector2.X * (float)j, vector2.Y * (float)j, 0f));
- vector3.Z = (float)i;
- list.Add(this.spawnCrate(vector3, vector));
- }
- }
- Class2 @class = new Class2();
- @class.open = false;
- if (bottom.Z > top.Z)
- {
- @class.Bottom = top;
- @class.Top = bottom;
- }
- else
- {
- @class.Bottom = bottom;
- @class.Top = top;
- }
- @class.Openingclient = null;
- @class.openTime = new Stopwatch();
- @class.closeTime = new Stopwatch();
- @class.closeTime.Start();
- @class.Health = 100.0;
- this.dictionary_0.Add(list, @class);
- }
- public override void OnPlayerConnect(ServerClient Client)
- {
- this.CreateHudForDoor(Client);
- base.OnPlayerConnect(Client);
- }
- public override void OnPreMapChange()
- {
- this.dictionary_2.Clear();
- this.dictionary_0.Clear();
- base.OnPreMapChange();
- }
- public override void OnMapChange()
- {
- if (base.GetClients() != null)
- {
- foreach (ServerClient current in base.GetClients())
- {
- this.CreateHudForDoor(current);
- }
- }
- base.OnMapChange();
- }
- public void CreateHudForDoor(ServerClient Client)
- {
- HudElem hudElem = base.CreateNewHudElem();
- hudElem.set_Type(1);
- hudElem.set_ShowToEnt(Client.get_ClientNum());
- hudElem.set_HideInMenu(true);
- hudElem.set_Font(0);
- hudElem.set_FontScale(1.5f);
- hudElem.set_PointType(120);
- hudElem.set_OriginY(180f);
- hudElem.set_OriginX(-100f);
- hudElem.SetString("");
- this.dictionary_2.Add(Client.get_ClientNum(), hudElem.get_HudElementNum());
- }
- private KeyValuePair<List<Entity>, Class2> method_0(Dictionary<List<Entity>, Class2> dictionary_3, int int_1)
- {
- int num = 0;
- foreach (KeyValuePair<List<Entity>, Class2> current in dictionary_3)
- {
- if (num == int_1)
- {
- return current;
- }
- num++;
- }
- throw new Exception("Nothing found with key");
- }
- private Vector method_1(Vector vector_0, float float_0)
- {
- return new Vector(vector_0.X / float_0, vector_0.Y / float_0, vector_0.Z / float_0);
- }
- public override ChatType OnSay(string Message, ServerClient Client, bool Teamchat)
- {
- if (Message == "!house")
- {
- float num = Client.get_OriginX() + 200f;
- float num2 = Client.get_OriginX() - 200f;
- float num3 = Client.get_OriginY() + 200f;
- float num4 = Client.get_OriginY() - 200f;
- float num5 = Client.get_OriginZ() + 200f;
- this.createfloor(new Vector(num, num3, Client.get_OriginZ()), new Vector(num2, num4, Client.get_OriginZ()));
- this.CreateWall(new Vector(num, num3, Client.get_OriginZ()), new Vector(num2, num3, num5));
- this.CreateWall(new Vector(num, num3, Client.get_OriginZ()), new Vector(num, num4, num5));
- this.CreateWall(new Vector(num2, num4, Client.get_OriginZ()), new Vector(num2, num3, num5));
- this.CreateWall(new Vector(num2, num4, Client.get_OriginZ()), new Vector(num, num4, num5));
- this.createfloor(new Vector(num, num3, num5), new Vector(num2, num4, num5));
- }
- return base.OnSay(Message, Client, Teamchat);
- }
- public override void OnAddonFrame()
- {
- for (int i = 0; i < this.dictionary_0.Count; i++)
- {
- MapEdit.Class4 @class = new MapEdit.Class4();
- @class.list_0 = this.method_0(this.dictionary_0, i).Key;
- @class.class2_0 = this.dictionary_0[@class.list_0];
- if (base.GetClients() != null)
- {
- foreach (ServerClient current in base.GetClients())
- {
- MapEdit.Class5 class2 = new MapEdit.Class5();
- class2.hudElem_0 = base.GetHudElement(this.dictionary_2[current.get_ClientNum()]);
- if (@class.class2_0.Health <= 0.0)
- {
- foreach (Entity current2 in @class.list_0)
- {
- Class10.smethod_14(current2, 0);
- current2.Delete();
- i--;
- this.dictionary_0.Remove(@class.list_0);
- }
- foreach (ServerClient current3 in base.GetClients())
- {
- HudElem hudElement = base.GetHudElement(this.dictionary_2[current3.get_ClientNum()]);
- hudElement.SetString("");
- }
- break;
- }
- float num = (float)MapEdit.Distance(new Vector(current.get_OriginX(), current.get_OriginY(), current.get_OriginZ()), @class.list_0);
- if (current.get_Team() == 2)
- {
- if (current.Other.get_CurrentWeapon() != base.GetWeapon("defaultweapon_mp"))
- {
- if (num <= 250f && !@class.class2_0.open && @class.class2_0.closeTime.Elapsed.Seconds > 2)
- {
- try
- {
- class2.hudElem_0.SetString("Press ^3Activate^7 to ^1open Door");
- if (current.Other.ButtonPressed(Buttons.Activate) && !@class.class2_0.open)
- {
- class2.hudElem_0.SetString("Press ^3Activate^7 to ^1close Door");
- @class.class2_0.open = true;
- @class.class2_0.Openingclient = new int?(current.get_ClientNum());
- @class.class2_0.closeTime.Reset();
- @class.class2_0.closeTime.Stop();
- using (List<Entity>.Enumerator enumerator2 = @class.list_0.GetEnumerator())
- {
- while (enumerator2.MoveNext())
- {
- MapEdit.Class6 class3 = new MapEdit.Class6();
- class3.entity_0 = enumerator2.Current;
- MapEdit.Class7 class4 = new MapEdit.Class7();
- class4.class6_0 = class3;
- class4.class5_0 = class2;
- class4.class4_0 = @class;
- class4.mapEdit_0 = this;
- Entity expr_225 = class3.entity_0;
- expr_225.set_OriginZ(expr_225.get_OriginZ() + 100f);
- Class10.smethod_14(class3.entity_0, 0);
- @class.class2_0.openTime.Reset();
- @class.class2_0.openTime.Start();
- class4.timer_0 = new Timer(5000.0);
- class4.timer_0.Elapsed += new ElapsedEventHandler(class4.method_0);
- class4.timer_0.Start();
- class4.timer_1 = new Timer(6000.0);
- class4.timer_1.Elapsed += new ElapsedEventHandler(class4.method_1);
- class4.timer_1.Start();
- }
- }
- }
- goto IL_353;
- }
- catch (Exception ex)
- {
- base.ServerPrint(ex.ToString());
- goto IL_353;
- }
- goto IL_306;
- }
- goto IL_306;
- IL_353:
- if (num <= 250f && current.Other.ButtonPressed(Buttons.Activate) && @class.class2_0.open && @class.class2_0.Openingclient == current.get_ClientNum() && @class.class2_0.openTime.Elapsed.Seconds > 2)
- {
- @class.class2_0.open = false;
- @class.class2_0.openTime.Reset();
- @class.class2_0.Openingclient = null;
- @class.class2_0.closeTime.Reset();
- @class.class2_0.closeTime.Start();
- foreach (Entity current2 in @class.list_0)
- {
- if (current2.get_OriginZ() - 100f >= @class.class2_0.Bottom.Z)
- {
- Entity expr_459 = current2;
- expr_459.set_OriginZ(expr_459.get_OriginZ() - 100f);
- Class10.smethod_14(current2, Class10.smethod_12());
- }
- }
- class2.hudElem_0.SetString("");
- goto IL_8B5;
- }
- goto IL_8B5;
- IL_306:
- if (num > 250f || !(@class.class2_0.Openingclient == current.get_ClientNum()))
- {
- class2.hudElem_0.SetString("");
- goto IL_353;
- }
- goto IL_353;
- }
- else
- {
- if (num <= 100f && !@class.class2_0.open)
- {
- try
- {
- class2.hudElem_0.SetString("Press ^3Activate^7 to ^1repair Door.Current health: " + @class.class2_0.Health);
- if (current.Other.ButtonPressed(Buttons.Activate))
- {
- if (base.GetDvar("mapname") == "mp_underground")
- {
- Class10.smethod_10(this.int_0, this.method_1(MapEdit.plus(@class.class2_0.Bottom, @class.class2_0.Top), 2f), null, null);
- Class10.smethod_10(this.int_0, @class.class2_0.Top, null, null);
- Class10.smethod_10(this.int_0, @class.class2_0.Bottom, null, null);
- Class10.smethod_10(this.int_0, new Vector(@class.class2_0.Top.X, @class.class2_0.Top.Y, @class.class2_0.Bottom.Z), null, null);
- Class10.smethod_10(this.int_0, new Vector(@class.class2_0.Bottom.X, @class.class2_0.Bottom.Y, @class.class2_0.Top.Z), null, null);
- }
- @class.class2_0.Health += 1.0;
- }
- goto IL_8B5;
- }
- catch
- {
- goto IL_8B5;
- }
- }
- class2.hudElem_0.SetString("");
- }
- }
- else
- {
- if (num <= 100f && !@class.class2_0.open && @class.class2_0.Health > 0.0)
- {
- try
- {
- class2.hudElem_0.SetString("Press ^3Melee^7 to ^1break open Door");
- if (current.Other.ButtonPressed(Buttons.Knife))
- {
- if (!this.dictionary_1.ContainsKey(current.get_ClientNum()))
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- this.dictionary_1.Add(current.get_ClientNum(), stopwatch);
- }
- if (this.dictionary_1[current.get_ClientNum()].ElapsedMilliseconds > 1500L)
- {
- int num2 = 90;
- int num3 = 50;
- int num4 = 30;
- Random random = new Random();
- if (current.get_Stance() == 0)
- {
- if (random.Next(100) < num2)
- {
- @class.class2_0.Health -= 20.0;
- base.iPrintLnBold("Health remaining " + @class.class2_0.Health.ToString(), current);
- }
- else
- {
- base.iPrintLnBold("Missed, try again!", current);
- }
- }
- if (current.get_Stance() == 2)
- {
- if (random.Next(100) < num3)
- {
- @class.class2_0.Health -= 10.0;
- base.iPrintLnBold("Health remaining " + @class.class2_0.Health.ToString(), current);
- }
- else
- {
- base.iPrintLnBold("Missed, try again!", current);
- }
- }
- if (current.get_Stance() == 1)
- {
- if (random.Next(100) < num4)
- {
- @class.class2_0.Health -= 10.0;
- base.iPrintLnBold("Health remaining " + @class.class2_0.Health.ToString(), current);
- }
- else
- {
- base.iPrintLnBold("Missed, try again!", current);
- }
- }
- this.dictionary_1[current.get_ClientNum()].Reset();
- this.dictionary_1[current.get_ClientNum()].Start();
- }
- else
- {
- base.iPrintLnBold("You must wait before knifing again", current);
- }
- }
- goto IL_8B5;
- }
- catch
- {
- goto IL_8B5;
- }
- }
- class2.hudElem_0.SetString("");
- }
- IL_8B5:
- this.dictionary_0[@class.list_0] = @class.class2_0;
- }
- }
- }
- }
- public static Vector VectorToAngles(Vector value1)
- {
- float num;
- float num2;
- if (value1.Y == 0f && value1.X == 0f)
- {
- num = 0f;
- if (value1.Z > 0f)
- {
- num2 = 90f;
- }
- else
- {
- num2 = 270f;
- }
- }
- else
- {
- if (value1.X == 1f)
- {
- num = (float)(Math.Atan2((double)value1.Y, (double)value1.X) * 180.0 / 3.1415926535897931);
- }
- else
- {
- if (value1.Y > 0f)
- {
- num = 90f;
- }
- else
- {
- num = 270f;
- }
- }
- if (num < 0f)
- {
- num += 360f;
- }
- float num3 = (float)Math.Sqrt((double)(value1.X * value1.X + value1.Y * value1.Y));
- num2 = (float)(Math.Atan2((double)value1.Z, (double)num3) * 180.0 / 3.1415926535897931);
- if (num2 < 0f)
- {
- num2 += 360f;
- }
- }
- return new Vector(-num2, num, 0f);
- }
- public Vector Normalize(Vector vec)
- {
- float num = this.Length(vec);
- if (num > 0f)
- {
- float num2 = 1f / num;
- vec.X *= num2;
- vec.Y *= num2;
- vec.Z *= num2;
- }
- return vec;
- }
- public override void OnPlayerSpawned(ServerClient Client)
- {
- MapEdit.Class8 @class = new MapEdit.Class8();
- @class.serverClient_0 = Client;
- @class.mapEdit_0 = this;
- if (@class.serverClient_0.get_Team() == 2)
- {
- MapEdit.Class9 class2 = new MapEdit.Class9();
- class2.class8_0 = @class;
- class2.timer_0 = new Timer(100.0);
- class2.timer_0.Elapsed += new ElapsedEventHandler(class2.method_0);
- class2.timer_0.Start();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement