Pārlūkot izejas kodu

禁止购买物品,允许购买物品测试OK

tanghai 13 gadi atpakaļ
vecāks
revīzija
86b4f8e4e0

+ 8 - 0
CSharp/App/Modules/Robot/CommonDefines.cs

@@ -0,0 +1,8 @@
+
+namespace Modules.Robot
+{
+	public static class BuffId
+	{
+		public const int BUFF_FORBIDDEN_PLAYER_BUY_ITEM = 660100;
+	}
+}

+ 2 - 0
CSharp/App/Modules/Robot/Robot.csproj

@@ -68,6 +68,7 @@
     <Reference Include="System.Security" />
     <Reference Include="System.Xaml" />
     <Reference Include="System.Xml" />
+    <Reference Include="System.Xml.Linq" />
     <Reference Include="UIAutomationProvider" />
     <Reference Include="UIAutomationTypes" />
     <Reference Include="WindowsBase" />
@@ -81,6 +82,7 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="CommonDefines.cs" />
     <Compile Include="Robot.cs" />
     <Compile Include="RobotModule.cs" />
     <Compile Include="RobotViewModel.cs" />

+ 1 - 1
CSharp/App/Modules/Robot/RobotView.xaml

@@ -59,7 +59,7 @@
 								<TabItem Header="GM">
 									<Canvas>
 										<Button Name="btnForbiddenBuy" Content="禁止交易" Canvas.Left="11" Canvas.Top="10" Width="75" Click="btnForbiddenBuy_Click"/>
-										<Button Content="允许交易" Canvas.Left="11" Canvas.Top="38" Width="75"/>
+										<Button Name="btnAllowBuy" Content="允许交易" Canvas.Left="11" Canvas.Top="38" Width="75" Click="btnAllowBuy_Click" />
 									</Canvas>
 								</TabItem>
 							</TabControl>

+ 5 - 0
CSharp/App/Modules/Robot/RobotView.xaml.cs

@@ -51,5 +51,10 @@ namespace Modules.Robot
 		{
 			this.ViewModel.ForbiddenBuy();
 		}
+
+		private void btnAllowBuy_Click(object sender, RoutedEventArgs e)
+		{
+			this.ViewModel.AllowBuy();
+		}
 	}
 }

+ 95 - 60
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -19,22 +19,20 @@ namespace Modules.Robot
 	[Export(contractType: typeof (RobotViewModel)),
 		PartCreationPolicy(creationPolicy: CreationPolicy.Shared)]
 	internal sealed class RobotViewModel: NotificationObject, IDisposable
-	{
+	{
+		private string errorInfo = "";
 		private int findTypeIndex;
 		private string account = "";
-		private string findType = "";
+		private string findType = "egametang@163.com";
 		private string name = "";
 		private string guid = "";
 		private bool isGMEnable;
 		private Visibility dockPanelVisiable = Visibility.Hidden;
 		private readonly BossClient.BossClient bossClient = new BossClient.BossClient();
 		private readonly ObservableCollection<ServerViewModel> serverInfos = 
-			new ObservableCollection<ServerViewModel>();
-
-		public readonly Dictionary<ushort, Action<byte[]>> messageHandlers =
-			new Dictionary<ushort, Action<byte[]>>();
-
-		private string errorInfo = "";
+			new ObservableCollection<ServerViewModel>();
+
+		private readonly DataCenterEntities entities = new DataCenterEntities();
 
 		public IMessageChannel IMessageChannel { get; set; }
 
@@ -201,6 +199,7 @@ namespace Modules.Robot
 
 		private void Disposing(bool disposing)
 		{
+			this.entities.Dispose();
 			this.bossClient.Dispose();
 		}
 
@@ -258,44 +257,41 @@ namespace Modules.Robot
 
 		public void Find()
 		{
-			using (var entitys = new DataCenterEntities())
+			t_character result = null;
+			switch (this.FindTypeIndex)
 			{
-				t_character result = null;
-				switch (this.FindTypeIndex)
-				{
-					case 0:
-					{
-						result = entitys.t_character.FirstOrDefault(
-							c => c.account == this.FindType);
-						break;
-					}
-					case 1:
-					{
-						result = entitys.t_character.FirstOrDefault(
-							c => c.character_name == this.FindType);
-						break;
-					}
-					case 2:
-					{
-						var findGuid = Decimal.Parse(this.FindType);
-						result = entitys.t_character.FirstOrDefault(
-							c => c.character_guid == findGuid);
-						break;
-					}
+				case 0:
+				{
+					result = entities.t_character.FirstOrDefault(
+						c => c.account == this.FindType);
+					break;
 				}
-			
-				if (result == null)
+				case 1:
+				{
+					result = entities.t_character.FirstOrDefault(
+						c => c.character_name == this.FindType);
+					break;
+				}
+				case 2:
 				{
-					this.ErrorInfo = "没有找到该玩家!";
-					return;
+					var findGuid = Decimal.Parse(this.FindType);
+					result = entities.t_character.FirstOrDefault(
+						c => c.character_guid == findGuid);
+					break;
 				}
-				
-				this.Account = result.account;
-				this.Name = result.character_name;
-				this.Guid = result.character_guid.ToString(CultureInfo.InvariantCulture);
-				this.IsGMEnable = true;
-				this.ErrorInfo = "查询成功";
 			}
+			
+			if (result == null)
+			{
+				this.ErrorInfo = "没有找到该玩家!";
+				return;
+			}
+			
+			this.Account = result.account;
+			this.Name = result.character_name;
+			this.Guid = result.character_guid.ToString(CultureInfo.InvariantCulture);
+			this.IsGMEnable = true;
+			this.ErrorInfo = "查询成功";
 		}
 
 		public async void ForbiddenBuy()
@@ -305,34 +301,73 @@ namespace Modules.Robot
 				this.ErrorInfo = "请先指定玩家";
 				return;
 			}
-			this.SendCommand(string.Format("forbidden_buy_item {0} 600", guid));
+			this.SendCommand(string.Format("forbidden_buy_item {0} {1}", guid, int.MaxValue));
 			var smsgBossCommandResponse = await RecvMessage<SMSG_Boss_Command_Response>();
 			if (smsgBossCommandResponse.ErrorCode == ErrorCode.RESPONSE_SUCCESS)
 			{
 				this.ErrorInfo = "禁止交易成功";
 				return;
 			}
-			if (smsgBossCommandResponse.ErrorCode == ErrorCode.BOSS_PLAYER_NOT_FOUND)
-			{
-				using (var entitys = new DataCenterEntities())
+			if (smsgBossCommandResponse.ErrorCode == ErrorCode.BOSS_PLAYER_NOT_FOUND)
+			{
+				decimal character_guid = decimal.Parse(this.Guid);
+				var removeBuffs = entities.t_city_buff.Where(
+					c => c.buff_id == BuffId.BUFF_FORBIDDEN_PLAYER_BUY_ITEM && 
+						c.character_guid == character_guid);
+				foreach (var removeBuff in removeBuffs)
+				{
+					entities.t_city_buff.Remove(removeBuff);
+				}
+				var newBuff = new t_city_buff
 				{
-					var newBuff = new t_city_buff
-					{
-						buff_guid = RandomHelper.RandUInt64(),
-						buff_id = 660100,
-						buff_time = 0,
-						buff_values = "{}".ToByteArray(),
-						character_guid = decimal.Parse(this.Guid),
-						create_time = DateTime.Now,
-						modify_time = DateTime.Now,
-						stack = 1
-					};
-					entitys.t_city_buff.Add(newBuff);
-					entitys.SaveChanges();
-				}
-				this.ErrorInfo = "禁止交易成功";
+					buff_guid = RandomHelper.RandUInt64(),
+					buff_id = BuffId.BUFF_FORBIDDEN_PLAYER_BUY_ITEM,
+					buff_time = 0,
+					buff_values = "{}".ToByteArray(),
+					character_guid = decimal.Parse(this.Guid),
+					create_time = DateTime.Now,
+					modify_time = DateTime.Now,
+					stack = 1
+				};
+				entities.t_city_buff.Add(newBuff);
+				entities.SaveChanges();
+
+				this.ErrorInfo = "禁止交易成功";
+				return;
 			}
 			this.ErrorInfo = smsgBossCommandResponse.ErrorCode.ToString();
 		}
+
+		public async void AllowBuy()
+		{
+			if (this.Guid == "")
+			{
+				this.ErrorInfo = "请先指定玩家";
+				return;
+			}
+			this.SendCommand(string.Format("forbidden_buy_item {0} 0", guid));
+			var smsgBossCommandResponse = await RecvMessage<SMSG_Boss_Command_Response>();
+			if (smsgBossCommandResponse.ErrorCode == ErrorCode.RESPONSE_SUCCESS)
+			{
+				this.ErrorInfo = "允许交易成功";
+				return;
+			}
+			if (smsgBossCommandResponse.ErrorCode == ErrorCode.BOSS_PLAYER_NOT_FOUND)
+			{
+				decimal character_guid = decimal.Parse(this.Guid);
+				var removeBuffs = entities.t_city_buff.Where(
+					c => c.buff_id == BuffId.BUFF_FORBIDDEN_PLAYER_BUY_ITEM &&
+						c.character_guid == character_guid);
+				foreach (var removeBuff in removeBuffs)
+				{
+					entities.t_city_buff.Remove(removeBuff);
+				}
+				entities.SaveChanges();
+
+				this.ErrorInfo = "允许交易成功";
+				return;
+			}
+			this.ErrorInfo = smsgBossCommandResponse.ErrorCode.ToString();
+		}
 	}
 }