|
| 1 | +using Microsoft.Xna.Framework; |
| 2 | +using Newtonsoft.Json; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.IO; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using Terraria; |
| 11 | +using TShockAPI; |
| 12 | +using Z.Expressions; |
| 13 | + |
| 14 | +namespace Deathmatch |
| 15 | +{ |
| 16 | + public class Room |
| 17 | + { |
| 18 | + [JsonProperty("图格坐标x")] |
| 19 | + public int TileX { get; set; } |
| 20 | + [JsonProperty("图格坐标y")] |
| 21 | + public int TileY { get; set; } |
| 22 | + [JsonProperty("长度")] |
| 23 | + public int Width { get; set; } |
| 24 | + [JsonProperty("高度")] |
| 25 | + public int Height { get; set; } |
| 26 | + } |
| 27 | + public class Skill |
| 28 | + { |
| 29 | + //技能名称 弹幕id 图像 生成位置 生成间隔 生成时间间隔 |
| 30 | + //使用冷却时间 使用消耗魔力 触发条件 |
| 31 | + [JsonProperty("技能名称")] |
| 32 | + public string Name { get; set; } = ""; |
| 33 | + [JsonProperty("弹幕id")] |
| 34 | + public int Id { get; set; } = 1; |
| 35 | + [JsonProperty("伤害")] |
| 36 | + public int Damage { get; set; } = 100; |
| 37 | + [JsonProperty("击退")] |
| 38 | + public float KnockBack { get; set; } = 1; |
| 39 | + [JsonProperty("解析式 自变量为x")] |
| 40 | + public string Func { get; set; } = "x^2"; |
| 41 | + //技能触发动作 wasd u-使用物品 p-跳跃 |
| 42 | + [JsonProperty("技能触发动作 wasd-上下左右 p-跳跃 u-使用物品")] |
| 43 | + public string Trigger { get; set; } = ""; |
| 44 | + [JsonProperty("原点位置x偏移量")] |
| 45 | + public int X { get; set; } = 0; |
| 46 | + [JsonProperty("原点位置y偏移量")] |
| 47 | + public int Y { get; set; } = 0; |
| 48 | + [JsonProperty("自变量取值范围0-此值")] |
| 49 | + public int Legnth { get; set; } = 10; |
| 50 | + [JsonProperty("自变量每次增量")] |
| 51 | + public float Step { get; set; } = 0.1f; |
| 52 | + [JsonProperty("时间间隔 ms")] |
| 53 | + public int TimeSpan { get; set; } = 100; |
| 54 | + [JsonProperty("是否以敌方为攻击对象")] |
| 55 | + public bool Trace { get; set; } = false; |
| 56 | + [JsonProperty("技能冷却时间 ms")] |
| 57 | + public int UseSpan { get; set; } = 2000; |
| 58 | + [JsonProperty("技能消耗魔法值")] |
| 59 | + public int Mana { get; set; } = 10; |
| 60 | + public bool Release(TSPlayer user,TSPlayer anamy) |
| 61 | + { |
| 62 | + if (user.TPlayer.statMana < Mana) |
| 63 | + { |
| 64 | + return false; |
| 65 | + } |
| 66 | + Utils.SendTextAboveHead(user.Index, Name, Color.Red); |
| 67 | + user.TPlayer.statMana -= Mana; |
| 68 | + user.SendData(PacketTypes.PlayerMana, "", user.Index); |
| 69 | + for (float i = 0; i < Legnth; i += Step) |
| 70 | + { |
| 71 | + var pos = user.TPlayer.position + new Vector2(X+i, Eval.Execute<float>(Func, new { x = i })+Y); |
| 72 | + Projectile.NewProjectile(null, pos, Trace ? anamy.TPlayer.position - pos : pos - (new Vector2(X, Y) + user.TPlayer.position), Id, Damage, KnockBack); |
| 73 | + Thread.Sleep(TimeSpan); |
| 74 | + } |
| 75 | + return true; |
| 76 | + } |
| 77 | + } |
| 78 | + public class Character |
| 79 | + { |
| 80 | + [JsonProperty("角色名")] |
| 81 | + public string Name { get; set; } |
| 82 | + [JsonProperty("技能")] |
| 83 | + public Skill[] Skills { get; set; } = new Skill[] { new Skill() }; |
| 84 | + } |
| 85 | + public class Config |
| 86 | + { |
| 87 | + [JsonProperty("房间")] |
| 88 | + public Room[] Rooms { get; set; } = new Room[] { new Room() }; |
| 89 | + [JsonProperty("角色")] |
| 90 | + public Character[] Characters { get; set; }=new Character[] { new Character() }; |
| 91 | + private const string path = "tshock/Deathmatch.json"; |
| 92 | + public void Save() |
| 93 | + { |
| 94 | + File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented),Encoding.UTF8); |
| 95 | + } |
| 96 | + public static Config GetConfig() |
| 97 | + { |
| 98 | + if (!File.Exists(path)) |
| 99 | + new Config().Save(); |
| 100 | + return JsonConvert.DeserializeObject<Config>(File.ReadAllText(path)); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments