using CommonAI.Data;
using CommonAI.Zone;
using CommonAI.Zone.Formula;
using CommonAI.Zone.Helper;
using CommonAI.Zone.Instance;
using CommonLang.Vector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace CommonAI.ZoneServer.JSGModule
{
	public class JSGModule
	{
		public static int GetSpaceDiveSize(SceneType sceneType)
		{
			//if (sceneType == CommonAI.Data.SceneType.NCS_MutilCross)
			//{
			//	return 1;
			//}
			//else 
			if (sceneType == CommonAI.Data.SceneType.PickLotus)
			{
				return 20;
			}
			else
			{
				return 10;
			}
		}

		//攻击模式是否对宠物有效
		public static bool IsExpectValidForPet(SkillTemplate.CastTarget type)
		{
			if (type == SkillTemplate.CastTarget.Alias || type == SkillTemplate.CastTarget.PetForMaster || type == SkillTemplate.CastTarget.EveryOne
				|| type == SkillTemplate.CastTarget.AlliesExcludeSelf || type == SkillTemplate.CastTarget.AlliesIncludeSelf || 
				type == SkillTemplate.CastTarget.EveryOneExcludeSelf)
			{
				return true;
			}

			return false;
		}

		public static bool IsEmpty(string str)
		{
			return str == null || str.Length <= 0;
		}

		// 概率,万分之
		public static bool RandomPrecent(int value)
		{
			return GlobalData.gRandom.Next(GlobalData.RATE_BASE) < value;
		}

		public static float GetCurveStartAngleOffect(InstanceUnit launcher, InstanceUnit target, float startAngle, float seekRange)
		{
			if(target == null || launcher == null)
			{
				return startAngle;
			}

			float distance = MathVector.getDistance(launcher.X, launcher.Y, target.X, target.Y);
			if(distance > 7.0f)
			{
				return startAngle;
			}
			else if(distance > 5.0f)
			{
				return startAngle * 0.8f;
			}
			else if(distance > 3.5f)
			{
				return startAngle * 0.5f;
			}
			else if(distance > 2.0f)
			{
				return startAngle * 0.2f;
			}

			return startAngle * 0.1f;
		}

		public static Vector2 GetCurveDefaultTargetPos(InstanceUnit launcher, float seekRange)
		{
			Vector2 targetPos = new Vector2();
			float degree = MathVector.getDegree(launcher.X, launcher.Y);
			targetPos.SetX(launcher.X + (float)(seekRange * Math.Cos(launcher.Direction)));
			targetPos.SetY(launcher.Y + (float)(seekRange * Math.Sin(launcher.Direction)));

			return targetPos;
		}

		public static string GetAttackSourceDes(AttackSource source)
		{
			if(source == null)
			{
				return "";
			}

			return "【attackSN: " + (source.Attack == null ? 0 : source.Attack.SerialNumber) 
				+ ", attackID: " + (source.Attack == null ? 0 : source.Attack.Properties.GetAttackID())
				+ ", spellID: " + (source.FromSpell == null ? 0 : source.FromSpell.ID) + "】";
		}

		public static bool IsActiveSkill(XmdsSkillType skillType)
		{
			return skillType == XmdsSkillType.active || skillType == XmdsSkillType.normalAtk ||
						skillType == XmdsSkillType.petGiveAcitve || skillType == XmdsSkillType.cardSkill;
		}

		public static bool IsPassiveSkill(XmdsSkillType skillType)
		{
			return skillType == XmdsSkillType.passive || skillType == XmdsSkillType.petGivePassive;
		}

	}
}